| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/arc/arc_bridge_service.h" | 9 #include "components/arc/arc_bridge_service.h" |
| 10 #include "ui/base/ime/composition_text.h" | 10 #include "ui/base/ime/composition_text.h" |
| 11 #include "ui/base/ime/text_input_type.h" | 11 #include "ui/base/ime/text_input_type.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 | 13 |
| 14 namespace arc { | 14 namespace arc { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 constexpr int kMinVersionForOnKeyboardsBoundsChanging = 3; | 17 constexpr int kMinVersionForOnKeyboardsBoundsChanging = 3; |
| 18 constexpr int kMinVersionForExtendSelectionAndDelete = 4; |
| 18 | 19 |
| 19 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { | 20 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { |
| 20 // The two enum types are similar, but intentionally made not identical. | 21 // The two enum types are similar, but intentionally made not identical. |
| 21 // We cannot force them to be in sync. If we do, updates in ui::TextInputType | 22 // We cannot force them to be in sync. If we do, updates in ui::TextInputType |
| 22 // must always be propagated to the arc::mojom::TextInputType mojo definition | 23 // must always be propagated to the arc::mojom::TextInputType mojo definition |
| 23 // in | 24 // in |
| 24 // ARC container side, which is in a different repository than Chromium. | 25 // ARC container side, which is in a different repository than Chromium. |
| 25 // We don't want such dependency. | 26 // We don't want such dependency. |
| 26 // | 27 // |
| 27 // That's why we need a lengthy switch statement instead of static_cast | 28 // That's why we need a lengthy switch statement instead of static_cast |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 129 } |
| 129 if (bridge_service_->ime_version() < | 130 if (bridge_service_->ime_version() < |
| 130 kMinVersionForOnKeyboardsBoundsChanging) { | 131 kMinVersionForOnKeyboardsBoundsChanging) { |
| 131 LOG(ERROR) << "ArcImeInstance is too old for OnKeyboardsBoundsChanging."; | 132 LOG(ERROR) << "ArcImeInstance is too old for OnKeyboardsBoundsChanging."; |
| 132 return; | 133 return; |
| 133 } | 134 } |
| 134 | 135 |
| 135 ime_instance->OnKeyboardBoundsChanging(new_bounds); | 136 ime_instance->OnKeyboardBoundsChanging(new_bounds); |
| 136 } | 137 } |
| 137 | 138 |
| 139 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( |
| 140 uint32_t before, uint32_t after) { |
| 141 mojom::ImeInstance* ime_instance = bridge_service_->ime_instance(); |
| 142 if (!ime_instance) { |
| 143 LOG(ERROR) << "ArcImeInstance method called before being ready."; |
| 144 return; |
| 145 } |
| 146 if (bridge_service_->ime_version() < |
| 147 kMinVersionForExtendSelectionAndDelete) { |
| 148 LOG(ERROR) << "ArcImeInstance is too old for ExtendSelectionAndDelete."; |
| 149 return; |
| 150 } |
| 151 |
| 152 ime_instance->ExtendSelectionAndDelete(before, after); |
| 153 } |
| 154 |
| 138 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { | 155 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { |
| 139 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); | 156 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); |
| 140 } | 157 } |
| 141 | 158 |
| 142 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { | 159 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { |
| 143 delegate_->OnCursorRectChanged(gfx::Rect( | 160 delegate_->OnCursorRectChanged(gfx::Rect( |
| 144 rect->left, | 161 rect->left, |
| 145 rect->top, | 162 rect->top, |
| 146 rect->right - rect->left, | 163 rect->right - rect->left, |
| 147 rect->bottom - rect->top)); | 164 rect->bottom - rect->top)); |
| 148 } | 165 } |
| 149 | 166 |
| 150 void ArcImeBridgeImpl::OnCancelComposition() { | 167 void ArcImeBridgeImpl::OnCancelComposition() { |
| 151 delegate_->OnCancelComposition(); | 168 delegate_->OnCancelComposition(); |
| 152 } | 169 } |
| 153 | 170 |
| 154 void ArcImeBridgeImpl::ShowImeIfNeeded() { | 171 void ArcImeBridgeImpl::ShowImeIfNeeded() { |
| 155 delegate_->ShowImeIfNeeded(); | 172 delegate_->ShowImeIfNeeded(); |
| 156 } | 173 } |
| 157 | 174 |
| 158 } // namespace arc | 175 } // namespace arc |
| OLD | NEW |