Chromium Code Reviews| 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 kMinInstanceVersion = 0; |
|
Yusuke Sato
2016/09/16 23:58:48
You didn't introduce version zero checks for BT, s
Luis Héctor Chávez
2016/09/17 00:30:53
Added version zero checks for BT.
Yusuke Sato
2016/09/17 01:38:56
Ok, so I think you're saying that we should always
| |
| 20 constexpr int kMinVersionForExtendSelectionAndDelete = 4; | 20 constexpr uint32_t kMinVersionForOnKeyboardsBoundsChanging = 3; |
| 21 constexpr uint32_t kMinVersionForExtendSelectionAndDelete = 4; | |
| 21 | 22 |
| 22 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { | 23 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { |
| 23 // The two enum types are similar, but intentionally made not identical. | 24 // 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 | 25 // 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 | 26 // must always be propagated to the arc::mojom::TextInputType mojo definition |
| 26 // in | 27 // in |
| 27 // ARC container side, which is in a different repository than Chromium. | 28 // ARC container side, which is in a different repository than Chromium. |
| 28 // We don't want such dependency. | 29 // We don't want such dependency. |
| 29 // | 30 // |
| 30 // That's why we need a lengthy switch statement instead of static_cast | 31 // 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); | 88 bridge_service_->ime()->RemoveObserver(this); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void ArcImeBridgeImpl::OnInstanceReady() { | 91 void ArcImeBridgeImpl::OnInstanceReady() { |
| 91 bridge_service_->ime()->instance()->Init( | 92 bridge_service_->ime()->instance()->Init( |
| 92 binding_.CreateInterfacePtrAndBind()); | 93 binding_.CreateInterfacePtrAndBind()); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void ArcImeBridgeImpl::SendSetCompositionText( | 96 void ArcImeBridgeImpl::SendSetCompositionText( |
| 96 const ui::CompositionText& composition) { | 97 const ui::CompositionText& composition) { |
| 97 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 98 auto* ime_instance = bridge_service_->ime()->GetInstanceForVersion( |
| 98 if (!ime_instance) { | 99 kMinInstanceVersion, "SetCompositionText"); |
| 99 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 100 if (!ime_instance) |
| 100 return; | 101 return; |
| 101 } | |
| 102 | 102 |
| 103 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), | 103 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), |
| 104 ConvertSegments(composition)); | 104 ConvertSegments(composition)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ArcImeBridgeImpl::SendConfirmCompositionText() { | 107 void ArcImeBridgeImpl::SendConfirmCompositionText() { |
| 108 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 108 auto* ime_instance = bridge_service_->ime()->GetInstanceForVersion( |
| 109 if (!ime_instance) { | 109 kMinInstanceVersion, "ConfirmCompositionText"); |
| 110 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 110 if (!ime_instance) |
| 111 return; | 111 return; |
| 112 } | |
| 113 | 112 |
| 114 ime_instance->ConfirmCompositionText(); | 113 ime_instance->ConfirmCompositionText(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { | 116 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { |
| 118 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 117 auto* ime_instance = bridge_service_->ime()->GetInstanceForVersion( |
| 119 if (!ime_instance) { | 118 kMinInstanceVersion, "SendInsertText"); |
|
Yusuke Sato
2016/09/16 23:58:48
s/Send// ?
Luis Héctor Chávez
2016/09/17 00:30:53
Done.
| |
| 120 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 119 if (!ime_instance) |
| 121 return; | 120 return; |
| 122 } | |
| 123 | 121 |
| 124 ime_instance->InsertText(base::UTF16ToUTF8(text)); | 122 ime_instance->InsertText(base::UTF16ToUTF8(text)); |
| 125 } | 123 } |
| 126 | 124 |
| 127 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( | 125 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( |
| 128 const gfx::Rect& new_bounds) { | 126 const gfx::Rect& new_bounds) { |
| 129 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 127 auto* ime_instance = bridge_service_->ime()->GetInstanceForVersion( |
| 130 if (!ime_instance) { | 128 kMinVersionForOnKeyboardsBoundsChanging, "OnKeyboardBoundsChanging"); |
| 131 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 129 if (!ime_instance) |
| 132 return; | 130 return; |
| 133 } | |
| 134 if (bridge_service_->ime()->version() < | |
| 135 kMinVersionForOnKeyboardsBoundsChanging) { | |
| 136 LOG(ERROR) << "ArcImeInstance is too old for OnKeyboardsBoundsChanging."; | |
| 137 return; | |
| 138 } | |
| 139 | 131 |
| 140 ime_instance->OnKeyboardBoundsChanging(new_bounds); | 132 ime_instance->OnKeyboardBoundsChanging(new_bounds); |
| 141 } | 133 } |
| 142 | 134 |
| 143 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( | 135 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( |
| 144 size_t before, size_t after) { | 136 size_t before, size_t after) { |
| 145 mojom::ImeInstance* ime_instance = bridge_service_->ime()->instance(); | 137 auto* ime_instance = bridge_service_->ime()->GetInstanceForVersion( |
| 146 if (!ime_instance) { | 138 kMinVersionForExtendSelectionAndDelete, "ExtendSelectionAndDelete"); |
| 147 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 139 if (!ime_instance) |
| 148 return; | 140 return; |
| 149 } | |
| 150 if (bridge_service_->ime()->version() < | |
| 151 kMinVersionForExtendSelectionAndDelete) { | |
| 152 LOG(ERROR) << "ArcImeInstance is too old for ExtendSelectionAndDelete."; | |
| 153 return; | |
| 154 } | |
| 155 | 141 |
| 156 ime_instance->ExtendSelectionAndDelete(before, after); | 142 ime_instance->ExtendSelectionAndDelete(before, after); |
| 157 } | 143 } |
| 158 | 144 |
| 159 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { | 145 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { |
| 160 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); | 146 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); |
| 161 } | 147 } |
| 162 | 148 |
| 163 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { | 149 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { |
| 164 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, | 150 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, |
| 165 rect->right - rect->left, | 151 rect->right - rect->left, |
| 166 rect->bottom - rect->top)); | 152 rect->bottom - rect->top)); |
| 167 } | 153 } |
| 168 | 154 |
| 169 void ArcImeBridgeImpl::OnCancelComposition() { | 155 void ArcImeBridgeImpl::OnCancelComposition() { |
| 170 delegate_->OnCancelComposition(); | 156 delegate_->OnCancelComposition(); |
| 171 } | 157 } |
| 172 | 158 |
| 173 void ArcImeBridgeImpl::ShowImeIfNeeded() { | 159 void ArcImeBridgeImpl::ShowImeIfNeeded() { |
| 174 delegate_->ShowImeIfNeeded(); | 160 delegate_->ShowImeIfNeeded(); |
| 175 } | 161 } |
| 176 | 162 |
| 177 } // namespace arc | 163 } // namespace arc |
| OLD | NEW |