1 // Copyright (c) 2012 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.
5 #include "content/browser/renderer_host/text_input_client_message_filter.h"
7 #include "base/strings/string16.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/renderer_host/text_input_client_mac.h"
10 #include "content/common/text_input_client_messages.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "ui/gfx/range/range.h"
14 #include "ui/gfx/rect.h"
18 TextInputClientMessageFilter::TextInputClientMessageFilter(int child_id)
19 : BrowserMessageFilter(),
20 child_process_id_(child_id) {
23 bool TextInputClientMessageFilter::OnMessageReceived(
24 const IPC::Message& message,
25 bool* message_was_ok) {
27 IPC_BEGIN_MESSAGE_MAP_EX(TextInputClientMessageFilter, message,
29 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotCharacterIndexForPoint,
30 OnGotCharacterIndexForPoint)
31 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotFirstRectForRange,
32 OnGotFirstRectForRange)
33 IPC_MESSAGE_HANDLER(TextInputClientReplyMsg_GotStringForRange,
35 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP_EX()
40 TextInputClientMessageFilter::~TextInputClientMessageFilter() {}
42 void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(size_t index) {
43 TextInputClientMac* service = TextInputClientMac::GetInstance();
44 // |index| could be WTF::notFound (-1) and its value is different from
45 // NSNotFound so we need to convert it.
46 if (index == static_cast<size_t>(-1)) {
49 service->SetCharacterIndexAndSignal(index);
52 void TextInputClientMessageFilter::OnGotFirstRectForRange(
53 const gfx::Rect& rect) {
54 TextInputClientMac* service = TextInputClientMac::GetInstance();
55 service->SetFirstRectAndSignal(NSRectFromCGRect(rect.ToCGRect()));
58 void TextInputClientMessageFilter::OnGotStringFromRange(
59 const mac::AttributedStringCoder::EncodedString& encoded_string) {
60 TextInputClientMac* service = TextInputClientMac::GetInstance();
61 NSAttributedString* string =
62 mac::AttributedStringCoder::Decode(&encoded_string);
65 service->SetSubstringAndSignal(string);
68 } // namespace content