| 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/input_method_bridge_chromeos.h" | 5 #include "chrome/browser/ui/views/ime_driver/input_method_bridge_chromeos.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/ui/views/ime_driver/remote_text_input_client.h" | 8 #include "chrome/browser/ui/views/ime_driver/remote_text_input_client.h" |
| 9 | 9 |
| 10 InputMethodBridge::InputMethodBridge(ui::mojom::TextInputClientPtr client) | 10 InputMethodBridge::InputMethodBridge( |
| 11 : client_(base::MakeUnique<RemoteTextInputClient>(std::move(client))), | 11 std::unique_ptr<RemoteTextInputClient> client) |
| 12 : client_(std::move(client)), |
| 12 input_method_chromeos_( | 13 input_method_chromeos_( |
| 13 base::MakeUnique<ui::InputMethodChromeOS>(nullptr)) { | 14 base::MakeUnique<ui::InputMethodChromeOS>(nullptr)) { |
| 14 input_method_chromeos_->SetFocusedTextInputClient(client_.get()); | 15 input_method_chromeos_->SetFocusedTextInputClient(client_.get()); |
| 15 } | 16 } |
| 16 | 17 |
| 17 InputMethodBridge::~InputMethodBridge() {} | 18 InputMethodBridge::~InputMethodBridge() {} |
| 18 | 19 |
| 19 void InputMethodBridge::OnTextInputTypeChanged( | 20 void InputMethodBridge::OnTextInputTypeChanged( |
| 20 ui::TextInputType text_input_type) { | 21 ui::TextInputType text_input_type) { |
| 22 client_->SetTextInputType(text_input_type); |
| 21 input_method_chromeos_->OnTextInputTypeChanged(client_.get()); | 23 input_method_chromeos_->OnTextInputTypeChanged(client_.get()); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void InputMethodBridge::OnCaretBoundsChanged(const gfx::Rect& caret_bounds) { | 26 void InputMethodBridge::OnCaretBoundsChanged(const gfx::Rect& caret_bounds) { |
| 27 client_->SetCaretBounds(caret_bounds); |
| 25 input_method_chromeos_->OnCaretBoundsChanged(client_.get()); | 28 input_method_chromeos_->OnCaretBoundsChanged(client_.get()); |
| 26 } | 29 } |
| 27 | 30 |
| 28 void InputMethodBridge::ProcessKeyEvent( | 31 void InputMethodBridge::ProcessKeyEvent( |
| 29 std::unique_ptr<ui::Event> event, | 32 std::unique_ptr<ui::Event> event, |
| 30 const ProcessKeyEventCallback& callback) { | 33 const ProcessKeyEventCallback& callback) { |
| 31 DCHECK(event->IsKeyEvent()); | 34 DCHECK(event->IsKeyEvent()); |
| 32 ui::KeyEvent* key_event = event->AsKeyEvent(); | 35 ui::KeyEvent* key_event = event->AsKeyEvent(); |
| 33 if (!key_event->is_char()) { | 36 if (!key_event->is_char()) { |
| 34 input_method_chromeos_->DispatchKeyEvent( | 37 input_method_chromeos_->DispatchKeyEvent( |
| 35 key_event, base::MakeUnique<base::Callback<void(bool)>>(callback)); | 38 key_event, base::MakeUnique<base::Callback<void(bool)>>(callback)); |
| 36 } else { | 39 } else { |
| 37 // On Linux (include ChromeOS), the mus emulates the WM_CHAR generation | 40 // On Linux (include ChromeOS), the mus emulates the WM_CHAR generation |
| 38 // behaviour of Windows. But for ChromeOS, we don't expect those char | 41 // behaviour of Windows. But for ChromeOS, we don't expect those char |
| 39 // events, so we filter them out. | 42 // events, so we filter them out. |
| 40 const bool handled = true; | 43 const bool handled = true; |
| 41 callback.Run(handled); | 44 callback.Run(handled); |
| 42 } | 45 } |
| 43 } | 46 } |
| 44 | 47 |
| 45 void InputMethodBridge::CancelComposition() { | 48 void InputMethodBridge::CancelComposition() { |
| 46 input_method_chromeos_->CancelComposition(client_.get()); | 49 input_method_chromeos_->CancelComposition(client_.get()); |
| 47 } | 50 } |
| OLD | NEW |