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_impl.h" | 5 #include "components/arc/ime/arc_ime_bridge_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
12 #include "ui/base/ime/composition_text.h" | 12 #include "ui/base/ime/composition_text.h" |
13 #include "ui/base/ime/text_input_type.h" | 13 #include "ui/base/ime/text_input_type.h" |
14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
15 | 15 |
16 namespace arc { | 16 namespace arc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 constexpr int kMinVersionForOnKeyboardsBoundsChanging = 3; | 19 constexpr uint32_t kMinVersionForOnKeyboardsBoundsChanging = 3; |
20 constexpr int kMinVersionForExtendSelectionAndDelete = 4; | 20 constexpr uint32_t kMinVersionForExtendSelectionAndDelete = 4; |
21 | 21 |
22 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { | 22 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { |
23 // The two enum types are similar, but intentionally made not identical. | 23 // The two enum types are similar, but intentionally made not identical. |
24 // We cannot force them to be in sync. If we do, updates in ui::TextInputType | 24 // We cannot force them to be in sync. If we do, updates in ui::TextInputType |
25 // must always be propagated to the arc::mojom::TextInputType mojo definition | 25 // must always be propagated to the arc::mojom::TextInputType mojo definition |
26 // in | 26 // in |
27 // ARC container side, which is in a different repository than Chromium. | 27 // ARC container side, which is in a different repository than Chromium. |
28 // We don't want such dependency. | 28 // We don't want such dependency. |
29 // | 29 // |
30 // That's why we need a lengthy switch statement instead of static_cast | 30 // That's why we need a lengthy switch statement instead of static_cast |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bridge_service_->ime()->RemoveObserver(this); | 87 bridge_service_->ime()->RemoveObserver(this); |
88 } | 88 } |
89 | 89 |
90 void ArcImeBridgeImpl::OnInstanceReady() { | 90 void ArcImeBridgeImpl::OnInstanceReady() { |
91 bridge_service_->ime()->instance()->Init( | 91 bridge_service_->ime()->instance()->Init( |
92 binding_.CreateInterfacePtrAndBind()); | 92 binding_.CreateInterfacePtrAndBind()); |
93 } | 93 } |
94 | 94 |
95 void ArcImeBridgeImpl::SendSetCompositionText( | 95 void ArcImeBridgeImpl::SendSetCompositionText( |
96 const ui::CompositionText& composition) { | 96 const ui::CompositionText& composition) { |
97 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 97 auto* ime_instance = |
98 if (!ime_instance) { | 98 bridge_service_->ime()->GetInstanceForMethod("SetCompositionText"); |
99 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 99 if (!ime_instance) |
100 return; | 100 return; |
101 } | |
102 | 101 |
103 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), | 102 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), |
104 ConvertSegments(composition)); | 103 ConvertSegments(composition)); |
105 } | 104 } |
106 | 105 |
107 void ArcImeBridgeImpl::SendConfirmCompositionText() { | 106 void ArcImeBridgeImpl::SendConfirmCompositionText() { |
108 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 107 auto* ime_instance = |
109 if (!ime_instance) { | 108 bridge_service_->ime()->GetInstanceForMethod("ConfirmCompositionText"); |
110 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 109 if (!ime_instance) |
111 return; | 110 return; |
112 } | |
113 | 111 |
114 ime_instance->ConfirmCompositionText(); | 112 ime_instance->ConfirmCompositionText(); |
115 } | 113 } |
116 | 114 |
117 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { | 115 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { |
118 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 116 auto* ime_instance = |
119 if (!ime_instance) { | 117 bridge_service_->ime()->GetInstanceForMethod("InsertText"); |
120 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 118 if (!ime_instance) |
121 return; | 119 return; |
122 } | |
123 | 120 |
124 ime_instance->InsertText(base::UTF16ToUTF8(text)); | 121 ime_instance->InsertText(base::UTF16ToUTF8(text)); |
125 } | 122 } |
126 | 123 |
127 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( | 124 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( |
128 const gfx::Rect& new_bounds) { | 125 const gfx::Rect& new_bounds) { |
129 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 126 auto* ime_instance = bridge_service_->ime()->GetInstanceForMethod( |
130 if (!ime_instance) { | 127 "OnKeyboardBoundsChanging", kMinVersionForOnKeyboardsBoundsChanging); |
131 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 128 if (!ime_instance) |
132 return; | 129 return; |
133 } | |
134 if (bridge_service_->ime()->version() < | |
135 kMinVersionForOnKeyboardsBoundsChanging) { | |
136 LOG(ERROR) << "ArcImeInstance is too old for OnKeyboardsBoundsChanging."; | |
137 return; | |
138 } | |
139 | 130 |
140 ime_instance->OnKeyboardBoundsChanging(new_bounds); | 131 ime_instance->OnKeyboardBoundsChanging(new_bounds); |
141 } | 132 } |
142 | 133 |
143 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( | 134 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( |
144 size_t before, size_t after) { | 135 size_t before, size_t after) { |
145 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 136 auto* ime_instance = bridge_service_->ime()->GetInstanceForMethod( |
146 if (!ime_instance) { | 137 "ExtendSelectionAndDelete", kMinVersionForExtendSelectionAndDelete); |
147 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 138 if (!ime_instance) |
148 return; | 139 return; |
149 } | |
150 if (bridge_service_->ime()->version() < | |
151 kMinVersionForExtendSelectionAndDelete) { | |
152 LOG(ERROR) << "ArcImeInstance is too old for ExtendSelectionAndDelete."; | |
153 return; | |
154 } | |
155 | 140 |
156 ime_instance->ExtendSelectionAndDelete(before, after); | 141 ime_instance->ExtendSelectionAndDelete(before, after); |
157 } | 142 } |
158 | 143 |
159 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { | 144 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { |
160 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); | 145 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); |
161 } | 146 } |
162 | 147 |
163 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { | 148 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { |
164 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, | 149 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, |
165 rect->right - rect->left, | 150 rect->right - rect->left, |
166 rect->bottom - rect->top)); | 151 rect->bottom - rect->top)); |
167 } | 152 } |
168 | 153 |
169 void ArcImeBridgeImpl::OnCancelComposition() { | 154 void ArcImeBridgeImpl::OnCancelComposition() { |
170 delegate_->OnCancelComposition(); | 155 delegate_->OnCancelComposition(); |
171 } | 156 } |
172 | 157 |
173 void ArcImeBridgeImpl::ShowImeIfNeeded() { | 158 void ArcImeBridgeImpl::ShowImeIfNeeded() { |
174 delegate_->ShowImeIfNeeded(); | 159 delegate_->ShowImeIfNeeded(); |
175 } | 160 } |
176 | 161 |
177 } // namespace arc | 162 } // namespace arc |
OLD | NEW |