Chromium Code Reviews| Index: content/renderer/text_input_client_observer.cc |
| diff --git a/content/renderer/text_input_client_observer.cc b/content/renderer/text_input_client_observer.cc |
| index 5ce95ff6093742ac828679019e22a9cbee097912..6eed645fb8d0b6204c939b9b923d862f670ae2f2 100644 |
| --- a/content/renderer/text_input_client_observer.cc |
| +++ b/content/renderer/text_input_client_observer.cc |
| @@ -29,6 +29,8 @@ TextInputClientObserver::~TextInputClientObserver() { |
| bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
| + IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, |
| + OnStringAtPoint) |
| IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, |
| OnCharacterIndexForPoint) |
| IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, |
| @@ -43,6 +45,30 @@ blink::WebView* TextInputClientObserver::webview() { |
| return render_view()->GetWebView(); |
| } |
| +void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { |
|
Andre
2014/02/18 21:35:02
Given a point in view coordinates, find the closes
|
| +#if defined(OS_MACOSX) |
| + blink::WebFrame* frame = webview()->focusedFrame(); |
| + NSAttributedString* string = nil; |
| + gfx::Rect rect; |
| + if (frame) { |
| + blink::WebRange range = frame->rangeForWordAtPoint(point); |
| + int length = range.endOffset() - range.startOffset(); |
| + string = blink::WebSubstringUtil::attributedSubstringInRange( |
| + frame, range.startOffset(), length); |
| + |
| + blink::WebRect web_rect; |
| + frame->firstRectForCharacterRange(range.startOffset(), length, web_rect); |
| + rect = web_rect; |
| + } |
| + scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| + mac::AttributedStringCoder::Encode(string)); |
| + Send(new TextInputClientReplyMsg_GotStringAtPoint(routing_id(), |
| + *encoded.get(), rect)); |
| +#else |
| + NOTIMPLEMENTED(); |
| +#endif |
| +} |
| + |
| void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
| blink::WebPoint web_point(point); |
| size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); |