Chromium Code Reviews| 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/browser/renderer_host/text_input_client_message_filter.h" | |
| 6 | |
| 7 #include "base/string16.h" | |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 9 #include "chrome/browser/renderer_host/render_widget_host_view.h" | |
| 10 #include "chrome/browser/renderer_host/text_input_client_mac.h" | |
| 11 #include "chrome/common/text_input_client_messages.h" | |
| 12 #include "ipc/ipc_message_macros.h" | |
| 13 #include "ui/gfx/rect.h" | |
| 14 | |
| 15 TextInputClientMessageFilter::TextInputClientMessageFilter(int child_id) | |
| 16 : BrowserMessageFilter(), | |
| 17 child_process_id_(child_id) { | |
| 18 } | |
| 19 | |
| 20 TextInputClientMessageFilter::~TextInputClientMessageFilter() { | |
| 21 } | |
| 22 | |
| 23 bool TextInputClientMessageFilter::OnMessageReceived( | |
| 24 const IPC::Message& message, | |
| 25 bool* message_was_ok) { | |
| 26 bool handled = true; | |
| 27 IPC_BEGIN_MESSAGE_MAP_EX(TextInputClientMessageFilter, message, | |
| 28 *message_was_ok) | |
| 29 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotCharacterIndexForPoint, | |
| 30 OnGotCharacterIndexForPoint) | |
| 31 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotFirstRectForRange, | |
| 32 OnGotFirstRectForRange) | |
| 33 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotStringForRange, | |
| 34 OnGotStringFromRange) | |
| 35 IPC_MESSAGE_HANDLER(TextInputClientViewHostMsg_ImeCompositionRangeChanged, | |
| 36 OnImeCompositionRangeChanged) | |
| 37 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 38 IPC_END_MESSAGE_MAP_EX() | |
| 39 return handled; | |
| 40 } | |
| 41 | |
| 42 void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(uint index) { | |
|
jeremy
2011/02/21 09:19:47
Any point in asserting that these methods are call
Robert Sesek
2011/02/24 23:26:52
Not really. MessageFilters get dispatched on the I
| |
| 43 TextInputClientMac* service = TextInputClientMac::GetInstance(); | |
| 44 service->SetCharacterIndexAndSignal(index); | |
| 45 } | |
| 46 | |
| 47 void TextInputClientMessageFilter::OnGotFirstRectForRange( | |
| 48 const gfx::Rect& rect) { | |
| 49 CGRect cgrect(rect.ToCGRect()); | |
| 50 TextInputClientMac* service = TextInputClientMac::GetInstance(); | |
| 51 service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect())); | |
| 52 } | |
| 53 | |
| 54 void TextInputClientMessageFilter::OnGotStringFromRange( | |
| 55 const string16& string) { | |
| 56 TextInputClientMac* service = TextInputClientMac::GetInstance(); | |
| 57 if (!string.length()) { | |
| 58 service->SetSubstringAndSignal(nil); | |
| 59 } else { | |
| 60 NSData* data = [NSData dataWithBytes:string.data() | |
| 61 length:string.length()]; | |
| 62 NSAttributedString* string = [NSUnarchiver unarchiveObjectWithData:data]; | |
| 63 service->SetSubstringAndSignal(string); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void TextInputClientMessageFilter::OnImeCompositionRangeChanged( | |
| 68 const IPC::Message& msg, | |
| 69 int start, | |
| 70 int end) { | |
| 71 RenderViewHost* rvh = | |
| 72 RenderViewHost::FromID(child_process_id_, msg.routing_id()); | |
| 73 if (!rvh) { | |
| 74 return; | |
| 75 } | |
| 76 rvh->view()->ImeCompositionRangeChanged(start, end); | |
| 77 } | |
| OLD | NEW |