Index: chrome/renderer/text_input_client_observer.cc |
diff --git a/chrome/renderer/text_input_client_observer.cc b/chrome/renderer/text_input_client_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fa9f97e752165036cbd0c03b66f6a2303c17b6f6 |
--- /dev/null |
+++ b/chrome/renderer/text_input_client_observer.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/renderer/text_input_client_observer.h" |
+ |
+#include "chrome/common/text_input_client_messages.h" |
+#include "chrome/renderer/render_view.h" |
+#include "ipc/ipc_message_macros.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebTextHelper.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
+#include "ui/gfx/rect.h" |
+ |
+TextInputClientObserver::TextInputClientObserver(RenderView* render_view) |
+ : RenderViewObserver(render_view) { |
+} |
+ |
+TextInputClientObserver::~TextInputClientObserver() { |
+} |
+ |
+bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
+ IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, |
+ OnCharacterIndexForPoint) |
+ IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, |
+ OnFirstRectForCharacterRange) |
+ IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+WebKit::WebView* TextInputClientObserver::webview() { |
+ return render_view()->webview(); |
+} |
+ |
+void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
+ WebKit::WebPoint web_point(point); |
+ 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.
|
+ Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), |
+ index)); |
+} |
+ |
+void TextInputClientObserver::OnFirstRectForCharacterRange(uint location, |
+ uint length) { |
+ WebKit::WebFrame* frame = webview()->mainFrame(); |
+ WebKit::WebRect web_rect; |
+ 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.
|
+ gfx::Rect rect(web_rect); |
+ Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect)); |
+} |
+ |
+void TextInputClientObserver::OnStringForRange(uint location, uint length) { |
+ WebKit::WebTextHelper helper(webview()->mainFrame()); |
+ WebKit::WebString webstring(helper.substringInRange(location, length)); |
+ Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), webstring)); |
+} |