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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/text_input_client_message_filter.mm
diff --git a/chrome/browser/renderer_host/text_input_client_message_filter.mm b/chrome/browser/renderer_host/text_input_client_message_filter.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3822bd788e5e9e6d2cb9a64ee46742b4e1cde3de
--- /dev/null
+++ b/chrome/browser/renderer_host/text_input_client_message_filter.mm
@@ -0,0 +1,89 @@
+// 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/browser/renderer_host/text_input_client_message_filter.h"
+
+#include "base/string16.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/render_widget_host_view.h"
+#include "chrome/browser/renderer_host/text_input_client_mac.h"
+#include "chrome/common/text_input_client_messages.h"
+#include "content/browser/browser_thread.h"
+#include "ipc/ipc_message_macros.h"
+#include "ui/gfx/rect.h"
+
+TextInputClientMessageFilter::TextInputClientMessageFilter(int child_id)
+ : BrowserMessageFilter(),
+ child_process_id_(child_id) {
+}
+
+TextInputClientMessageFilter::~TextInputClientMessageFilter() {
+}
+
+void TextInputClientMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& msg,
+ BrowserThread::ID* thread) {
+ if (msg.type() == TextInputClientViewHostMsg_ImeCompositionRangeChanged::ID)
+ *thread = BrowserThread::UI;
+}
+
+bool TextInputClientMessageFilter::OnMessageReceived(
+ const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(TextInputClientMessageFilter, message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotCharacterIndexForPoint,
+ OnGotCharacterIndexForPoint)
+ IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotFirstRectForRange,
+ OnGotFirstRectForRange)
+ IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotStringForRange,
+ OnGotStringFromRange)
+ IPC_MESSAGE_HANDLER(TextInputClientViewHostMsg_ImeCompositionRangeChanged,
+ OnImeCompositionRangeChanged)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(uint index) {
+ 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.
+ TextInputClientMac* service = TextInputClientMac::GetInstance();
+ service->SetCharacterIndexAndSignal(index);
+}
+
+void TextInputClientMessageFilter::OnGotFirstRectForRange(
+ const gfx::Rect& rect) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ CGRect cgrect(rect.ToCGRect());
+ TextInputClientMac* service = TextInputClientMac::GetInstance();
+ service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect()));
+}
+
+void TextInputClientMessageFilter::OnGotStringFromRange(
+ const string16& string) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ TextInputClientMac* service = TextInputClientMac::GetInstance();
+ if (!string.length()) {
+ service->SetSubstringAndSignal(nil);
+ } else {
+ NSData* data = [NSData dataWithBytes:string.data()
+ length:string.length()];
+ NSAttributedString* string = [NSUnarchiver unarchiveObjectWithData:data];
+ service->SetSubstringAndSignal(string);
+ }
+}
+
+void TextInputClientMessageFilter::OnImeCompositionRangeChanged(
+ const IPC::Message& msg,
+ int start,
+ int end) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ RenderViewHost* rvh =
+ RenderViewHost::FromID(child_process_id_, msg.routing_id());
+ if (!rvh) {
+ return;
+ }
+ rvh->view()->ImeCompositionRangeChanged(start, end);
+}

Powered by Google App Engine
This is Rietveld 408576698