Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: content/renderer/text_input_client_observer.cc

Issue 166903005: mac: Add support for asynchronous dictionary lookup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix 80 columns formatting. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "third_party/WebKit/public/platform/WebFloatQuad.h"
11 #include "third_party/WebKit/public/platform/WebPoint.h" 12 #include "third_party/WebKit/public/platform/WebPoint.h"
12 #include "third_party/WebKit/public/platform/WebRect.h" 13 #include "third_party/WebKit/public/platform/WebRect.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebVector.h"
14 #include "third_party/WebKit/public/web/mac/WebSubstringUtil.h" 16 #include "third_party/WebKit/public/web/mac/WebSubstringUtil.h"
15 #include "third_party/WebKit/public/web/WebFrame.h" 17 #include "third_party/WebKit/public/web/WebFrame.h"
16 #include "third_party/WebKit/public/web/WebView.h" 18 #include "third_party/WebKit/public/web/WebView.h"
17 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
18 20
19 namespace content { 21 namespace content {
20 22
21 TextInputClientObserver::TextInputClientObserver(RenderViewImpl* render_view) 23 TextInputClientObserver::TextInputClientObserver(RenderViewImpl* render_view)
22 : RenderViewObserver(render_view), 24 : RenderViewObserver(render_view),
23 render_view_impl_(render_view) { 25 render_view_impl_(render_view) {
24 } 26 }
25 27
26 TextInputClientObserver::~TextInputClientObserver() { 28 TextInputClientObserver::~TextInputClientObserver() {
27 } 29 }
28 30
29 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { 31 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 32 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) 33 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message)
34 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint,
35 OnStringAtPoint)
32 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, 36 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint,
33 OnCharacterIndexForPoint) 37 OnCharacterIndexForPoint)
34 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, 38 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange,
35 OnFirstRectForCharacterRange) 39 OnFirstRectForCharacterRange)
36 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) 40 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange)
37 IPC_MESSAGE_UNHANDLED(handled = false) 41 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP() 42 IPC_END_MESSAGE_MAP()
39 return handled; 43 return handled;
40 } 44 }
41 45
42 blink::WebView* TextInputClientObserver::webview() { 46 blink::WebView* TextInputClientObserver::webview() {
43 return render_view()->GetWebView(); 47 return render_view()->GetWebView();
44 } 48 }
45 49
50 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) {
51 #if defined(OS_MACOSX)
52 blink::WebPoint baselinePoint;
53 NSAttributedString* string = blink::WebSubstringUtil::attributedWordAtPoint(
54 webview(), point, baselinePoint);
55
56 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
57 mac::AttributedStringCoder::Encode(string));
58 Send(new TextInputClientReplyMsg_GotStringAtPoint(
59 routing_id(), *encoded.get(), baselinePoint));
60 #else
61 NOTIMPLEMENTED();
62 #endif
63 }
64
46 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { 65 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) {
47 blink::WebPoint web_point(point); 66 blink::WebPoint web_point(point);
48 size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); 67 size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point);
49 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), 68 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(),
50 index)); 69 index));
51 } 70 }
52 71
53 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { 72 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) {
54 gfx::Rect rect; 73 gfx::Rect rect;
55 #if defined(ENABLE_PLUGINS) 74 #if defined(ENABLE_PLUGINS)
(...skipping 24 matching lines...) Expand all
80 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( 99 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
81 mac::AttributedStringCoder::Encode(string)); 100 mac::AttributedStringCoder::Encode(string));
82 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), 101 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(),
83 *encoded.get())); 102 *encoded.get()));
84 #else 103 #else
85 NOTIMPLEMENTED(); 104 NOTIMPLEMENTED();
86 #endif 105 #endif
87 } 106 }
88 107
89 } // namespace content 108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698