| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/ime_driver_mus.h" | 5 #include "chrome/browser/ui/views/ime_driver/ime_driver_mus.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "content/public/common/service_manager_connection.h" | 8 #include "content/public/common/service_manager_connection.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 10 #include "services/service_manager/public/cpp/connector.h" | 10 #include "services/service_manager/public/cpp/connector.h" |
| 11 #include "services/ui/public/interfaces/constants.mojom.h" | 11 #include "services/ui/public/interfaces/constants.mojom.h" |
| 12 #include "services/ui/public/interfaces/ime/ime.mojom.h" | 12 #include "services/ui/public/interfaces/ime/ime.mojom.h" |
| 13 #include "ui/base/ime/ime_bridge.h" |
| 13 | 14 |
| 14 namespace { | 15 #if defined(OS_CHROMEOS) |
| 16 #include "chrome/browser/ui/views/ime_driver/input_method_bridge_chromeos.h" |
| 17 #else |
| 18 #include "chrome/browser/ui/views/ime_driver/simple_input_method.h" |
| 19 #endif // defined(OS_CHROMEOS) |
| 15 | 20 |
| 16 class InputMethod : public ui::mojom::InputMethod { | 21 IMEDriver::IMEDriver() { |
| 17 public: | 22 ui::IMEBridge::Initialize(); |
| 18 explicit InputMethod(ui::mojom::TextInputClientPtr client) | 23 } |
| 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 | 24 |
| 49 IMEDriver::~IMEDriver() {} | 25 IMEDriver::~IMEDriver() {} |
| 50 | 26 |
| 51 // static | 27 // static |
| 52 void IMEDriver::Register() { | 28 void IMEDriver::Register() { |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 54 ui::mojom::IMEDriverPtr ime_driver_ptr; | 30 ui::mojom::IMEDriverPtr ime_driver_ptr; |
| 55 mojo::MakeStrongBinding(base::WrapUnique(new IMEDriver), | 31 mojo::MakeStrongBinding(base::MakeUnique<IMEDriver>(), |
| 56 GetProxy(&ime_driver_ptr)); | 32 GetProxy(&ime_driver_ptr)); |
| 57 ui::mojom::IMERegistrarPtr ime_registrar; | 33 ui::mojom::IMERegistrarPtr ime_registrar; |
| 58 content::ServiceManagerConnection::GetForProcess() | 34 content::ServiceManagerConnection::GetForProcess() |
| 59 ->GetConnector() | 35 ->GetConnector() |
| 60 ->ConnectToInterface(ui::mojom::kServiceName, &ime_registrar); | 36 ->ConnectToInterface(ui::mojom::kServiceName, &ime_registrar); |
| 61 ime_registrar->RegisterDriver(std::move(ime_driver_ptr)); | 37 ime_registrar->RegisterDriver(std::move(ime_driver_ptr)); |
| 62 } | 38 } |
| 63 | 39 |
| 64 void IMEDriver::StartSession( | 40 void IMEDriver::StartSession( |
| 65 int32_t session_id, | 41 int32_t session_id, |
| 66 ui::mojom::TextInputClientPtr client, | 42 ui::mojom::TextInputClientPtr client, |
| 67 ui::mojom::InputMethodRequest input_method_request) { | 43 ui::mojom::InputMethodRequest input_method_request) { |
| 44 #if defined(OS_CHROMEOS) |
| 68 input_method_bindings_[session_id] = | 45 input_method_bindings_[session_id] = |
| 69 base::MakeUnique<mojo::Binding<ui::mojom::InputMethod>>( | 46 base::MakeUnique<mojo::Binding<ui::mojom::InputMethod>>( |
| 70 new InputMethod(std::move(client)), std::move(input_method_request)); | 47 new InputMethodBridge(std::move(client)), |
| 48 std::move(input_method_request)); |
| 49 #else |
| 50 input_method_bindings_[session_id] = |
| 51 base::MakeUnique<mojo::Binding<ui::mojom::InputMethod>>( |
| 52 new SimpleInputMethod()); |
| 53 #endif |
| 71 } | 54 } |
| 72 | 55 |
| 73 IMEDriver::IMEDriver() {} | |
| 74 | |
| 75 void IMEDriver::CancelSession(int32_t session_id) { | 56 void IMEDriver::CancelSession(int32_t session_id) { |
| 76 input_method_bindings_.erase(session_id); | 57 input_method_bindings_.erase(session_id); |
| 77 } | 58 } |
| OLD | NEW |