Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/renderer_host/text_input_client_message_filter.mm

Issue 6289009: [Mac] Implement the system dictionary popup by implementing NSTextInput methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jam@ comments Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "content/browser/browser_thread.h"
13 #include "ipc/ipc_message_macros.h"
14 #include "ui/gfx/rect.h"
15
16 TextInputClientMessageFilter::TextInputClientMessageFilter(int child_id)
17 : BrowserMessageFilter(),
18 child_process_id_(child_id) {
19 }
20
21 TextInputClientMessageFilter::~TextInputClientMessageFilter() {
22 }
23
24 void TextInputClientMessageFilter::OverrideThreadForMessage(
25 const IPC::Message& msg,
26 BrowserThread::ID* thread) {
27 if (msg.type() == TextInputClientViewHostMsg_ImeCompositionRangeChanged::ID)
28 *thread = BrowserThread::UI;
29 }
30
31 bool TextInputClientMessageFilter::OnMessageReceived(
32 const IPC::Message& message,
33 bool* message_was_ok) {
34 bool handled = true;
35 IPC_BEGIN_MESSAGE_MAP_EX(TextInputClientMessageFilter, message,
36 *message_was_ok)
37 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotCharacterIndexForPoint,
38 OnGotCharacterIndexForPoint)
39 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotFirstRectForRange,
40 OnGotFirstRectForRange)
41 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotStringForRange,
42 OnGotStringFromRange)
43 IPC_MESSAGE_HANDLER(TextInputClientViewHostMsg_ImeCompositionRangeChanged,
44 OnImeCompositionRangeChanged)
45 IPC_MESSAGE_UNHANDLED(handled = false)
46 IPC_END_MESSAGE_MAP_EX()
47 return handled;
48 }
49
50 void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(uint index) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
jam 2011/02/25 19:15:15 please don't add these dchecks, they don't add muc
Robert Sesek 2011/03/18 21:33:16 Removed all the DCHECKs.
52 TextInputClientMac* service = TextInputClientMac::GetInstance();
53 service->SetCharacterIndexAndSignal(index);
54 }
55
56 void TextInputClientMessageFilter::OnGotFirstRectForRange(
57 const gfx::Rect& rect) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
59 CGRect cgrect(rect.ToCGRect());
60 TextInputClientMac* service = TextInputClientMac::GetInstance();
61 service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect()));
62 }
63
64 void TextInputClientMessageFilter::OnGotStringFromRange(
65 const string16& string) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
67 TextInputClientMac* service = TextInputClientMac::GetInstance();
68 if (!string.length()) {
69 service->SetSubstringAndSignal(nil);
70 } else {
71 NSData* data = [NSData dataWithBytes:string.data()
72 length:string.length()];
73 NSAttributedString* string = [NSUnarchiver unarchiveObjectWithData:data];
74 service->SetSubstringAndSignal(string);
75 }
76 }
77
78 void TextInputClientMessageFilter::OnImeCompositionRangeChanged(
79 const IPC::Message& msg,
80 int start,
81 int end) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 RenderViewHost* rvh =
84 RenderViewHost::FromID(child_process_id_, msg.routing_id());
85 if (!rvh) {
86 return;
87 }
88 rvh->view()->ImeCompositionRangeChanged(start, end);
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698