OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/text_input_client_observer.h" | 5 #include "content/renderer/text_input_client_observer.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "content/common/text_input_client_messages.h" | 8 #include "content/common/text_input_client_messages.h" |
9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 : RenderViewObserver(render_view), | 22 : RenderViewObserver(render_view), |
23 render_view_impl_(render_view) { | 23 render_view_impl_(render_view) { |
24 } | 24 } |
25 | 25 |
26 TextInputClientObserver::~TextInputClientObserver() { | 26 TextInputClientObserver::~TextInputClientObserver() { |
27 } | 27 } |
28 | 28 |
29 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { | 29 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
30 bool handled = true; | 30 bool handled = true; |
31 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) | 31 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
32 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, | |
33 OnStringAtPoint) | |
32 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, | 34 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, |
33 OnCharacterIndexForPoint) | 35 OnCharacterIndexForPoint) |
34 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, | 36 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, |
35 OnFirstRectForCharacterRange) | 37 OnFirstRectForCharacterRange) |
36 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) | 38 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) |
37 IPC_MESSAGE_UNHANDLED(handled = false) | 39 IPC_MESSAGE_UNHANDLED(handled = false) |
38 IPC_END_MESSAGE_MAP() | 40 IPC_END_MESSAGE_MAP() |
39 return handled; | 41 return handled; |
40 } | 42 } |
41 | 43 |
42 blink::WebView* TextInputClientObserver::webview() { | 44 blink::WebView* TextInputClientObserver::webview() { |
43 return render_view()->GetWebView(); | 45 return render_view()->GetWebView(); |
44 } | 46 } |
45 | 47 |
48 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { | |
Andre
2014/02/18 21:35:02
Given a point in view coordinates, find the closes
| |
49 #if defined(OS_MACOSX) | |
50 blink::WebFrame* frame = webview()->focusedFrame(); | |
51 NSAttributedString* string = nil; | |
52 gfx::Rect rect; | |
53 if (frame) { | |
54 blink::WebRange range = frame->rangeForWordAtPoint(point); | |
55 int length = range.endOffset() - range.startOffset(); | |
56 string = blink::WebSubstringUtil::attributedSubstringInRange( | |
57 frame, range.startOffset(), length); | |
58 | |
59 blink::WebRect web_rect; | |
60 frame->firstRectForCharacterRange(range.startOffset(), length, web_rect); | |
61 rect = web_rect; | |
62 } | |
63 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | |
64 mac::AttributedStringCoder::Encode(string)); | |
65 Send(new TextInputClientReplyMsg_GotStringAtPoint(routing_id(), | |
66 *encoded.get(), rect)); | |
67 #else | |
68 NOTIMPLEMENTED(); | |
69 #endif | |
70 } | |
71 | |
46 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { | 72 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
47 blink::WebPoint web_point(point); | 73 blink::WebPoint web_point(point); |
48 size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); | 74 size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); |
49 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), | 75 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), |
50 index)); | 76 index)); |
51 } | 77 } |
52 | 78 |
53 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { | 79 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { |
54 gfx::Rect rect; | 80 gfx::Rect rect; |
55 #if defined(ENABLE_PLUGINS) | 81 #if defined(ENABLE_PLUGINS) |
(...skipping 24 matching lines...) Expand all Loading... | |
80 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 106 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
81 mac::AttributedStringCoder::Encode(string)); | 107 mac::AttributedStringCoder::Encode(string)); |
82 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), | 108 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), |
83 *encoded.get())); | 109 *encoded.get())); |
84 #else | 110 #else |
85 NOTIMPLEMENTED(); | 111 NOTIMPLEMENTED(); |
86 #endif | 112 #endif |
87 } | 113 } |
88 | 114 |
89 } // namespace content | 115 } // namespace content |
OLD | NEW |