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 "components/arc/ime/arc_ime_bridge.h" | 5 #include "components/arc/ime/arc_ime_bridge.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/arc/ime/arc_ime_ipc_host_impl.h" | 8 #include "components/arc/ime/arc_ime_ipc_host_impl.h" |
9 #include "ui/aura/client/focus_client.h" | 9 #include "ui/aura/client/focus_client.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
32 // ArcImeBridge main implementation: | 32 // ArcImeBridge main implementation: |
33 | 33 |
34 ArcImeBridge::ArcImeBridge(ArcBridgeService* bridge_service) | 34 ArcImeBridge::ArcImeBridge(ArcBridgeService* bridge_service) |
35 : ArcService(bridge_service), | 35 : ArcService(bridge_service), |
36 ipc_host_(new ArcImeIpcHostImpl(this, bridge_service)), | 36 ipc_host_(new ArcImeIpcHostImpl(this, bridge_service)), |
37 ime_type_(ui::TEXT_INPUT_TYPE_NONE), | 37 ime_type_(ui::TEXT_INPUT_TYPE_NONE), |
38 has_composition_text_(false) { | 38 has_composition_text_(false), |
39 test_input_method_(nullptr) { | |
39 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 40 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
40 if (env) | 41 if (env) |
41 env->AddObserver(this); | 42 env->AddObserver(this); |
42 } | 43 } |
43 | 44 |
44 ArcImeBridge::~ArcImeBridge() { | 45 ArcImeBridge::~ArcImeBridge() { |
45 ui::InputMethod* const input_method = GetInputMethod(); | 46 ui::InputMethod* const input_method = GetInputMethod(); |
46 if (input_method) | 47 if (input_method) |
47 input_method->DetachTextInputClient(this); | 48 input_method->DetachTextInputClient(this); |
48 | 49 |
49 for (aura::Window* window : arc_windows_.windows()) | 50 for (aura::Window* window : arc_windows_.windows()) |
50 window->RemoveObserver(this); | 51 window->RemoveObserver(this); |
51 for (aura::Window* root : observing_root_windows_.windows()) | 52 for (aura::Window* root : observing_root_windows_.windows()) |
52 aura::client::GetFocusClient(root)->RemoveObserver(this); | 53 aura::client::GetFocusClient(root)->RemoveObserver(this); |
53 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 54 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
54 if (env) | 55 if (env) |
55 env->RemoveObserver(this); | 56 env->RemoveObserver(this); |
56 } | 57 } |
57 | 58 |
58 void ArcImeBridge::SetIpcHostForTesting( | 59 void ArcImeBridge::SetIpcHostForTesting( |
59 scoped_ptr<ArcImeIpcHost> test_ipc_host) { | 60 scoped_ptr<ArcImeIpcHost> test_ipc_host) { |
60 ipc_host_ = std::move(test_ipc_host); | 61 ipc_host_ = std::move(test_ipc_host); |
61 } | 62 } |
62 | 63 |
64 void ArcImeBridge::SetInputMethodForTesting( | |
65 ui::InputMethod* test_input_method) { | |
66 test_input_method_ = test_input_method; | |
67 } | |
68 | |
63 ui::InputMethod* ArcImeBridge::GetInputMethod() { | 69 ui::InputMethod* ArcImeBridge::GetInputMethod() { |
70 if (test_input_method_) | |
71 return test_input_method_; | |
64 if (!focused_arc_window_.has_windows()) | 72 if (!focused_arc_window_.has_windows()) |
65 return nullptr; | 73 return nullptr; |
66 return focused_arc_window_.windows().front()->GetHost()->GetInputMethod(); | 74 return focused_arc_window_.windows().front()->GetHost()->GetInputMethod(); |
67 } | 75 } |
68 | 76 |
69 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
70 // Overridden from aura::EnvObserver: | 78 // Overridden from aura::EnvObserver: |
71 | 79 |
72 void ArcImeBridge::OnWindowInitialized(aura::Window* new_window) { | 80 void ArcImeBridge::OnWindowInitialized(aura::Window* new_window) { |
73 if (IsArcWindow(new_window)) { | 81 if (IsArcWindow(new_window)) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 115 |
108 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
109 // Overridden from arc::ArcImeIpcHost::Delegate | 117 // Overridden from arc::ArcImeIpcHost::Delegate |
110 | 118 |
111 void ArcImeBridge::OnTextInputTypeChanged(ui::TextInputType type) { | 119 void ArcImeBridge::OnTextInputTypeChanged(ui::TextInputType type) { |
112 if (ime_type_ == type) | 120 if (ime_type_ == type) |
113 return; | 121 return; |
114 ime_type_ = type; | 122 ime_type_ = type; |
115 | 123 |
116 ui::InputMethod* const input_method = GetInputMethod(); | 124 ui::InputMethod* const input_method = GetInputMethod(); |
117 if (input_method) | 125 if (input_method) { |
118 input_method->OnTextInputTypeChanged(this); | 126 input_method->OnTextInputTypeChanged(this); |
127 if (input_method->GetTextInputClient() == this && | |
hidehiko
2016/01/26 08:05:53
IMHO, this should work, and practically cover most
kinaba
2016/01/26 08:28:59
You're right. Added the TODO comment as suggested.
| |
128 ime_type_ != ui::TEXT_INPUT_TYPE_NONE) { | |
129 input_method->ShowImeIfNeeded(); | |
130 } | |
131 } | |
119 } | 132 } |
120 | 133 |
121 void ArcImeBridge::OnCursorRectChanged(const gfx::Rect& rect) { | 134 void ArcImeBridge::OnCursorRectChanged(const gfx::Rect& rect) { |
122 if (cursor_rect_ == rect) | 135 if (cursor_rect_ == rect) |
123 return; | 136 return; |
124 cursor_rect_ = rect; | 137 cursor_rect_ = rect; |
125 | 138 |
126 ui::InputMethod* const input_method = GetInputMethod(); | 139 ui::InputMethod* const input_method = GetInputMethod(); |
127 if (input_method) | 140 if (input_method) |
128 input_method->OnCaretBoundsChanged(this); | 141 input_method->OnCaretBoundsChanged(this); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 bool ArcImeBridge::ChangeTextDirectionAndLayoutAlignment( | 238 bool ArcImeBridge::ChangeTextDirectionAndLayoutAlignment( |
226 base::i18n::TextDirection direction) { | 239 base::i18n::TextDirection direction) { |
227 return false; | 240 return false; |
228 } | 241 } |
229 | 242 |
230 bool ArcImeBridge::IsEditCommandEnabled(int command_id) { | 243 bool ArcImeBridge::IsEditCommandEnabled(int command_id) { |
231 return false; | 244 return false; |
232 } | 245 } |
233 | 246 |
234 } // namespace arc | 247 } // namespace arc |
OLD | NEW |