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/WebRect.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 14 #include "ui/gfx/rect.h" |
| 15 |
| 16 TextInputClientObserver::TextInputClientObserver(RenderView* render_view) |
| 17 : RenderViewObserver(render_view) { |
| 18 } |
| 19 |
| 20 TextInputClientObserver::~TextInputClientObserver() { |
| 21 } |
| 22 |
| 23 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
| 24 bool handled = true; |
| 25 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
| 26 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, |
| 27 OnCharacterIndexForPoint) |
| 28 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, |
| 29 OnFirstRectForCharacterRange) |
| 30 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) |
| 31 IPC_MESSAGE_UNHANDLED(handled = false) |
| 32 IPC_END_MESSAGE_MAP() |
| 33 return handled; |
| 34 } |
| 35 |
| 36 WebKit::WebView* TextInputClientObserver::webview() { |
| 37 return render_view()->webview(); |
| 38 } |
| 39 |
| 40 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
| 41 WebKit::WebTextHelper helper(webview()->mainFrame()); |
| 42 uint index = helper.characterIndexForPoint(point.x(), point.y()); |
| 43 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), |
| 44 index)); |
| 45 } |
| 46 |
| 47 void TextInputClientObserver::OnFirstRectForCharacterRange(uint location, |
| 48 uint length) { |
| 49 WebKit::WebTextHelper helper(webview()->mainFrame()); |
| 50 gfx::Rect rect(helper.firstRectForRange(location, length)); |
| 51 Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect)); |
| 52 } |
| 53 |
| 54 void TextInputClientObserver::OnStringForRange(uint location, uint length) { |
| 55 WebKit::WebTextHelper helper(webview()->mainFrame()); |
| 56 WebKit::WebString webstring(helper.substringInRange(location, length)); |
| 57 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), webstring)); |
| 58 } |
OLD | NEW |