| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/arc_bridge_service.h" |
| 13 #include "ui/base/ime/composition_text.h" | 13 #include "ui/base/ime/composition_text.h" |
| 14 #include "ui/base/ime/text_input_type.h" | 14 #include "ui/base/ime/text_input_type.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 | 16 |
| 17 namespace arc { | 17 namespace arc { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 constexpr uint32_t kMinVersionForOnKeyboardsBoundsChanging = 3; | |
| 21 constexpr uint32_t kMinVersionForExtendSelectionAndDelete = 4; | |
| 22 | |
| 23 ui::TextInputType ConvertTextInputType(mojom::TextInputType ipc_type) { | 20 ui::TextInputType ConvertTextInputType(mojom::TextInputType ipc_type) { |
| 24 // The two enum types are similar, but intentionally made not identical. | 21 // The two enum types are similar, but intentionally made not identical. |
| 25 // 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 |
| 26 // must always be propagated to the mojom::TextInputType mojo definition in | 23 // must always be propagated to the mojom::TextInputType mojo definition in |
| 27 // ARC container side, which is in a different repository than Chromium. | 24 // ARC container side, which is in a different repository than Chromium. |
| 28 // We don't want such dependency. | 25 // We don't want such dependency. |
| 29 // | 26 // |
| 30 // That's why we need a lengthy switch statement instead of static_cast | 27 // That's why we need a lengthy switch statement instead of static_cast |
| 31 // guarded by a static assert on the two enums to be in sync. | 28 // guarded by a static assert on the two enums to be in sync. |
| 32 switch (ipc_type) { | 29 switch (ipc_type) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 ArcBridgeService* bridge_service) | 76 ArcBridgeService* bridge_service) |
| 80 : binding_(this), delegate_(delegate), bridge_service_(bridge_service) { | 77 : binding_(this), delegate_(delegate), bridge_service_(bridge_service) { |
| 81 bridge_service_->ime()->AddObserver(this); | 78 bridge_service_->ime()->AddObserver(this); |
| 82 } | 79 } |
| 83 | 80 |
| 84 ArcImeBridgeImpl::~ArcImeBridgeImpl() { | 81 ArcImeBridgeImpl::~ArcImeBridgeImpl() { |
| 85 bridge_service_->ime()->RemoveObserver(this); | 82 bridge_service_->ime()->RemoveObserver(this); |
| 86 } | 83 } |
| 87 | 84 |
| 88 void ArcImeBridgeImpl::OnInstanceReady() { | 85 void ArcImeBridgeImpl::OnInstanceReady() { |
| 89 auto* instance = bridge_service_->ime()->GetInstanceForMethod("Init"); | 86 auto* instance = GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), Init); |
| 90 DCHECK(instance); | 87 DCHECK(instance); |
| 91 instance->Init(binding_.CreateInterfacePtrAndBind()); | 88 instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 92 } | 89 } |
| 93 | 90 |
| 94 void ArcImeBridgeImpl::SendSetCompositionText( | 91 void ArcImeBridgeImpl::SendSetCompositionText( |
| 95 const ui::CompositionText& composition) { | 92 const ui::CompositionText& composition) { |
| 96 auto* ime_instance = | 93 auto* ime_instance = |
| 97 bridge_service_->ime()->GetInstanceForMethod("SetCompositionText"); | 94 GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), SetCompositionText); |
| 98 if (!ime_instance) | 95 if (!ime_instance) |
| 99 return; | 96 return; |
| 100 | 97 |
| 101 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), | 98 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), |
| 102 ConvertSegments(composition)); | 99 ConvertSegments(composition)); |
| 103 } | 100 } |
| 104 | 101 |
| 105 void ArcImeBridgeImpl::SendConfirmCompositionText() { | 102 void ArcImeBridgeImpl::SendConfirmCompositionText() { |
| 106 auto* ime_instance = | 103 auto* ime_instance = |
| 107 bridge_service_->ime()->GetInstanceForMethod("ConfirmCompositionText"); | 104 GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), ConfirmCompositionText); |
| 108 if (!ime_instance) | 105 if (!ime_instance) |
| 109 return; | 106 return; |
| 110 | 107 |
| 111 ime_instance->ConfirmCompositionText(); | 108 ime_instance->ConfirmCompositionText(); |
| 112 } | 109 } |
| 113 | 110 |
| 114 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { | 111 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { |
| 115 auto* ime_instance = | 112 auto* ime_instance = |
| 116 bridge_service_->ime()->GetInstanceForMethod("InsertText"); | 113 GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), InsertText); |
| 117 if (!ime_instance) | 114 if (!ime_instance) |
| 118 return; | 115 return; |
| 119 | 116 |
| 120 ime_instance->InsertText(base::UTF16ToUTF8(text)); | 117 ime_instance->InsertText(base::UTF16ToUTF8(text)); |
| 121 } | 118 } |
| 122 | 119 |
| 123 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( | 120 void ArcImeBridgeImpl::SendOnKeyboardBoundsChanging( |
| 124 const gfx::Rect& new_bounds) { | 121 const gfx::Rect& new_bounds) { |
| 125 auto* ime_instance = bridge_service_->ime()->GetInstanceForMethod( | 122 auto* ime_instance = |
| 126 "OnKeyboardBoundsChanging", kMinVersionForOnKeyboardsBoundsChanging); | 123 GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), OnKeyboardBoundsChanging); |
| 127 if (!ime_instance) | 124 if (!ime_instance) |
| 128 return; | 125 return; |
| 129 | 126 |
| 130 ime_instance->OnKeyboardBoundsChanging(new_bounds); | 127 ime_instance->OnKeyboardBoundsChanging(new_bounds); |
| 131 } | 128 } |
| 132 | 129 |
| 133 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( | 130 void ArcImeBridgeImpl::SendExtendSelectionAndDelete( |
| 134 size_t before, size_t after) { | 131 size_t before, size_t after) { |
| 135 auto* ime_instance = bridge_service_->ime()->GetInstanceForMethod( | 132 auto* ime_instance = |
| 136 "ExtendSelectionAndDelete", kMinVersionForExtendSelectionAndDelete); | 133 GET_INSTANCE_FOR_METHOD(bridge_service_->ime(), ExtendSelectionAndDelete); |
| 137 if (!ime_instance) | 134 if (!ime_instance) |
| 138 return; | 135 return; |
| 139 | 136 |
| 140 ime_instance->ExtendSelectionAndDelete(before, after); | 137 ime_instance->ExtendSelectionAndDelete(before, after); |
| 141 } | 138 } |
| 142 | 139 |
| 143 void ArcImeBridgeImpl::OnTextInputTypeChanged(mojom::TextInputType type) { | 140 void ArcImeBridgeImpl::OnTextInputTypeChanged(mojom::TextInputType type) { |
| 144 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); | 141 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void ArcImeBridgeImpl::OnCursorRectChanged(mojom::CursorRectPtr rect) { | 144 void ArcImeBridgeImpl::OnCursorRectChanged(mojom::CursorRectPtr rect) { |
| 148 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, | 145 delegate_->OnCursorRectChanged(gfx::Rect(rect->left, rect->top, |
| 149 rect->right - rect->left, | 146 rect->right - rect->left, |
| 150 rect->bottom - rect->top)); | 147 rect->bottom - rect->top)); |
| 151 } | 148 } |
| 152 | 149 |
| 153 void ArcImeBridgeImpl::OnCancelComposition() { | 150 void ArcImeBridgeImpl::OnCancelComposition() { |
| 154 delegate_->OnCancelComposition(); | 151 delegate_->OnCancelComposition(); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void ArcImeBridgeImpl::ShowImeIfNeeded() { | 154 void ArcImeBridgeImpl::ShowImeIfNeeded() { |
| 158 delegate_->ShowImeIfNeeded(); | 155 delegate_->ShowImeIfNeeded(); |
| 159 } | 156 } |
| 160 | 157 |
| 161 } // namespace arc | 158 } // namespace arc |
| OLD | NEW |