OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/text_input_client_observer.h" | |
6 | |
7 #include "chrome/common/text_input_client_messages.h" | |
8 #include "chrome/renderer/render_view.h" | |
9 #include "ipc/ipc_message_macros.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebTextHelper.h" | |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
16 #include "ui/gfx/rect.h" | |
17 | |
18 TextInputClientObserver::TextInputClientObserver(RenderView* render_view) | |
19 : RenderViewObserver(render_view) { | |
20 } | |
21 | |
22 TextInputClientObserver::~TextInputClientObserver() { | |
23 } | |
24 | |
25 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { | |
26 bool handled = true; | |
27 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) | |
28 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, | |
29 OnCharacterIndexForPoint) | |
30 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, | |
31 OnFirstRectForCharacterRange) | |
32 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) | |
33 IPC_MESSAGE_UNHANDLED(handled = false) | |
34 IPC_END_MESSAGE_MAP() | |
35 return handled; | |
36 } | |
37 | |
38 WebKit::WebView* TextInputClientObserver::webview() { | |
39 return render_view()->webview(); | |
40 } | |
41 | |
42 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { | |
43 WebKit::WebPoint web_point(point); | |
44 uint index = webview()->mainFrame()->characterIndexForPoint(web_point); | |
James Su
2011/02/28 19:28:00
webview()->focusedFrame() is used in render_view.c
Robert Sesek
2011/03/18 21:33:16
Should be focusedFrame(). Done.
| |
45 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), | |
46 index)); | |
47 } | |
48 | |
49 void TextInputClientObserver::OnFirstRectForCharacterRange(uint location, | |
50 uint length) { | |
51 WebKit::WebFrame* frame = webview()->mainFrame(); | |
52 WebKit::WebRect web_rect; | |
53 frame->firstRectForCharacterRange(location, length, web_rect); | |
James Su
2011/02/28 19:44:04
Do we need to call frame->view()->contentsToWindow
Robert Sesek
2011/03/18 21:33:16
No, it returns in window coordinates.
| |
54 gfx::Rect rect(web_rect); | |
55 Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect)); | |
56 } | |
57 | |
58 void TextInputClientObserver::OnStringForRange(uint location, uint length) { | |
59 WebKit::WebTextHelper helper(webview()->mainFrame()); | |
60 WebKit::WebString webstring(helper.substringInRange(location, length)); | |
61 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), webstring)); | |
62 } | |
OLD | NEW |