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 "base/memory/scoped_ptr.h" |
| 8 #include "chrome/common/text_input_client_messages.h" |
| 9 #include "content/renderer/render_view.h" |
| 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebSubstringUtil.
h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 17 #include "ui/gfx/rect.h" |
| 18 |
| 19 TextInputClientObserver::TextInputClientObserver(RenderView* render_view) |
| 20 : RenderViewObserver(render_view) { |
| 21 } |
| 22 |
| 23 TextInputClientObserver::~TextInputClientObserver() { |
| 24 } |
| 25 |
| 26 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
| 27 bool handled = true; |
| 28 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
| 29 IPC_MESSAGE_HANDLER(TextInputClientMsg_CharacterIndexForPoint, |
| 30 OnCharacterIndexForPoint) |
| 31 IPC_MESSAGE_HANDLER(TextInputClientMsg_FirstRectForCharacterRange, |
| 32 OnFirstRectForCharacterRange) |
| 33 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringForRange, OnStringForRange) |
| 34 IPC_MESSAGE_UNHANDLED(handled = false) |
| 35 IPC_END_MESSAGE_MAP() |
| 36 return handled; |
| 37 } |
| 38 |
| 39 WebKit::WebView* TextInputClientObserver::webview() { |
| 40 return render_view()->webview(); |
| 41 } |
| 42 |
| 43 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
| 44 WebKit::WebPoint web_point(point); |
| 45 size_t index = webview()->focusedFrame()->characterIndexForPoint(web_point); |
| 46 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(), |
| 47 index)); |
| 48 } |
| 49 |
| 50 void TextInputClientObserver::OnFirstRectForCharacterRange(ui::Range range) { |
| 51 WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 52 WebKit::WebRect web_rect; |
| 53 frame->firstRectForCharacterRange(range.start(), range.length(), web_rect); |
| 54 gfx::Rect rect(web_rect); |
| 55 Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect)); |
| 56 } |
| 57 |
| 58 void TextInputClientObserver::OnStringForRange(ui::Range range) { |
| 59 #if defined(OS_MACOSX) |
| 60 NSAttributedString* string = |
| 61 WebKit::WebSubstringUtil::attributedSubstringInRange( |
| 62 webview()->focusedFrame(), range.start(), range.length()); |
| 63 scoped_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| 64 mac::AttributedStringCoder::Encode(string)); |
| 65 Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(), |
| 66 *encoded.get())); |
| 67 #else |
| 68 NOTIMPLEMENTED(); |
| 69 #endif |
| 70 } |
OLD | NEW |