OLD | NEW |
| (Empty) |
1 // Copyright 2016 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/ui/views/ime_driver_mus.h" | |
6 | |
7 #include "content/public/browser/browser_thread.h" | |
8 #include "content/public/common/service_manager_connection.h" | |
9 #include "mojo/public/cpp/bindings/strong_binding.h" | |
10 #include "services/service_manager/public/cpp/connector.h" | |
11 #include "services/ui/public/interfaces/constants.mojom.h" | |
12 #include "services/ui/public/interfaces/ime/ime.mojom.h" | |
13 | |
14 namespace { | |
15 | |
16 class InputMethod : public ui::mojom::InputMethod { | |
17 public: | |
18 explicit InputMethod(ui::mojom::TextInputClientPtr client) | |
19 : client_(std::move(client)) {} | |
20 ~InputMethod() override {} | |
21 | |
22 private: | |
23 // ui::mojom::InputMethod: | |
24 void OnTextInputModeChanged( | |
25 ui::mojom::TextInputMode text_input_mode) override {} | |
26 void OnTextInputTypeChanged( | |
27 ui::mojom::TextInputType text_input_type) override {} | |
28 void OnCaretBoundsChanged(const gfx::Rect& caret_bounds) override {} | |
29 void ProcessKeyEvent(std::unique_ptr<ui::Event> key_event, | |
30 const ProcessKeyEventCallback& callback) override { | |
31 DCHECK(key_event->IsKeyEvent()); | |
32 | |
33 if (key_event->AsKeyEvent()->is_char()) { | |
34 client_->InsertChar(std::move(key_event)); | |
35 callback.Run(true); | |
36 } else { | |
37 callback.Run(false); | |
38 } | |
39 } | |
40 void CancelComposition() override {} | |
41 | |
42 ui::mojom::TextInputClientPtr client_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(InputMethod); | |
45 }; | |
46 | |
47 } // namespace | |
48 | |
49 IMEDriver::~IMEDriver() {} | |
50 | |
51 // static | |
52 void IMEDriver::Register() { | |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
54 ui::mojom::IMEDriverPtr ime_driver_ptr; | |
55 mojo::MakeStrongBinding(base::WrapUnique(new IMEDriver), | |
56 GetProxy(&ime_driver_ptr)); | |
57 ui::mojom::IMERegistrarPtr ime_registrar; | |
58 content::ServiceManagerConnection::GetForProcess() | |
59 ->GetConnector() | |
60 ->ConnectToInterface(ui::mojom::kServiceName, &ime_registrar); | |
61 ime_registrar->RegisterDriver(std::move(ime_driver_ptr)); | |
62 } | |
63 | |
64 void IMEDriver::StartSession( | |
65 int32_t session_id, | |
66 ui::mojom::TextInputClientPtr client, | |
67 ui::mojom::InputMethodRequest input_method_request) { | |
68 input_method_bindings_[session_id] = | |
69 base::MakeUnique<mojo::Binding<ui::mojom::InputMethod>>( | |
70 new InputMethod(std::move(client)), std::move(input_method_request)); | |
71 } | |
72 | |
73 IMEDriver::IMEDriver() {} | |
74 | |
75 void IMEDriver::CancelSession(int32_t session_id) { | |
76 input_method_bindings_.erase(session_id); | |
77 } | |
OLD | NEW |