| 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 ui::TextInputType ConvertTextInputType(arc::TextInputType ipc_type) { | 17 ui::TextInputType ConvertTextInputType(arc::mojom::TextInputType ipc_type) { |
| 18 // The two enum types are similar, but intentionally made not identical. | 18 // The two enum types are similar, but intentionally made not identical. |
| 19 // We cannot force them to be in sync. If we do, updates in ui::TextInputType | 19 // We cannot force them to be in sync. If we do, updates in ui::TextInputType |
| 20 // must always be propagated to the arc::TextInputType mojo definition in | 20 // must always be propagated to the arc::mojom::TextInputType mojo definition |
| 21 // in |
| 21 // ARC container side, which is in a different repository than Chromium. | 22 // ARC container side, which is in a different repository than Chromium. |
| 22 // We don't want such dependency. | 23 // We don't want such dependency. |
| 23 // | 24 // |
| 24 // That's why we need a lengthy switch statement instead of static_cast | 25 // That's why we need a lengthy switch statement instead of static_cast |
| 25 // guarded by a static assert on the two enums to be in sync. | 26 // guarded by a static assert on the two enums to be in sync. |
| 26 switch (ipc_type) { | 27 switch (ipc_type) { |
| 27 case arc::TextInputType::NONE: | 28 case arc::mojom::TextInputType::NONE: |
| 28 return ui::TEXT_INPUT_TYPE_NONE; | 29 return ui::TEXT_INPUT_TYPE_NONE; |
| 29 case arc::TextInputType::TEXT: | 30 case arc::mojom::TextInputType::TEXT: |
| 30 return ui::TEXT_INPUT_TYPE_TEXT; | 31 return ui::TEXT_INPUT_TYPE_TEXT; |
| 31 case arc::TextInputType::PASSWORD: | 32 case arc::mojom::TextInputType::PASSWORD: |
| 32 return ui::TEXT_INPUT_TYPE_PASSWORD; | 33 return ui::TEXT_INPUT_TYPE_PASSWORD; |
| 33 case arc::TextInputType::SEARCH: | 34 case arc::mojom::TextInputType::SEARCH: |
| 34 return ui::TEXT_INPUT_TYPE_SEARCH; | 35 return ui::TEXT_INPUT_TYPE_SEARCH; |
| 35 case arc::TextInputType::EMAIL: | 36 case arc::mojom::TextInputType::EMAIL: |
| 36 return ui::TEXT_INPUT_TYPE_EMAIL; | 37 return ui::TEXT_INPUT_TYPE_EMAIL; |
| 37 case arc::TextInputType::NUMBER: | 38 case arc::mojom::TextInputType::NUMBER: |
| 38 return ui::TEXT_INPUT_TYPE_NUMBER; | 39 return ui::TEXT_INPUT_TYPE_NUMBER; |
| 39 case arc::TextInputType::TELEPHONE: | 40 case arc::mojom::TextInputType::TELEPHONE: |
| 40 return ui::TEXT_INPUT_TYPE_TELEPHONE; | 41 return ui::TEXT_INPUT_TYPE_TELEPHONE; |
| 41 case arc::TextInputType::URL: | 42 case arc::mojom::TextInputType::URL: |
| 42 return ui::TEXT_INPUT_TYPE_URL; | 43 return ui::TEXT_INPUT_TYPE_URL; |
| 43 case arc::TextInputType::DATE: | 44 case arc::mojom::TextInputType::DATE: |
| 44 return ui::TEXT_INPUT_TYPE_DATE; | 45 return ui::TEXT_INPUT_TYPE_DATE; |
| 45 case arc::TextInputType::TIME: | 46 case arc::mojom::TextInputType::TIME: |
| 46 return ui::TEXT_INPUT_TYPE_TIME; | 47 return ui::TEXT_INPUT_TYPE_TIME; |
| 47 case arc::TextInputType::DATETIME: | 48 case arc::mojom::TextInputType::DATETIME: |
| 48 return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; | 49 return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; |
| 49 default: | 50 default: |
| 50 return ui::TEXT_INPUT_TYPE_TEXT; | 51 return ui::TEXT_INPUT_TYPE_TEXT; |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 | 54 |
| 54 mojo::Array<arc::CompositionSegmentPtr> ConvertSegments( | 55 mojo::Array<arc::mojom::CompositionSegmentPtr> ConvertSegments( |
| 55 const ui::CompositionText& composition) { | 56 const ui::CompositionText& composition) { |
| 56 mojo::Array<arc::CompositionSegmentPtr> segments = | 57 mojo::Array<arc::mojom::CompositionSegmentPtr> segments = |
| 57 mojo::Array<arc::CompositionSegmentPtr>::New(0); | 58 mojo::Array<arc::mojom::CompositionSegmentPtr>::New(0); |
| 58 for (const ui::CompositionUnderline& underline : composition.underlines) { | 59 for (const ui::CompositionUnderline& underline : composition.underlines) { |
| 59 arc::CompositionSegmentPtr segment = arc::CompositionSegment::New(); | 60 arc::mojom::CompositionSegmentPtr segment = |
| 61 arc::mojom::CompositionSegment::New(); |
| 60 segment->start_offset = underline.start_offset; | 62 segment->start_offset = underline.start_offset; |
| 61 segment->end_offset = underline.end_offset; | 63 segment->end_offset = underline.end_offset; |
| 62 segment->emphasized = (underline.thick || | 64 segment->emphasized = (underline.thick || |
| 63 (composition.selection.start() == underline.start_offset && | 65 (composition.selection.start() == underline.start_offset && |
| 64 composition.selection.end() == underline.end_offset)); | 66 composition.selection.end() == underline.end_offset)); |
| 65 segments.push_back(std::move(segment)); | 67 segments.push_back(std::move(segment)); |
| 66 } | 68 } |
| 67 return segments; | 69 return segments; |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace | 72 } // namespace |
| 71 | 73 |
| 72 ArcImeBridgeImpl::ArcImeBridgeImpl(Delegate* delegate, | 74 ArcImeBridgeImpl::ArcImeBridgeImpl(Delegate* delegate, |
| 73 ArcBridgeService* bridge_service) | 75 ArcBridgeService* bridge_service) |
| 74 : binding_(this), delegate_(delegate), bridge_service_(bridge_service) { | 76 : binding_(this), delegate_(delegate), bridge_service_(bridge_service) { |
| 75 bridge_service_->AddObserver(this); | 77 bridge_service_->AddObserver(this); |
| 76 } | 78 } |
| 77 | 79 |
| 78 ArcImeBridgeImpl::~ArcImeBridgeImpl() { | 80 ArcImeBridgeImpl::~ArcImeBridgeImpl() { |
| 79 bridge_service_->RemoveObserver(this); | 81 bridge_service_->RemoveObserver(this); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void ArcImeBridgeImpl::OnImeInstanceReady() { | 84 void ArcImeBridgeImpl::OnImeInstanceReady() { |
| 83 bridge_service_->ime_instance()->Init(binding_.CreateInterfacePtrAndBind()); | 85 bridge_service_->ime_instance()->Init(binding_.CreateInterfacePtrAndBind()); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ArcImeBridgeImpl::SendSetCompositionText( | 88 void ArcImeBridgeImpl::SendSetCompositionText( |
| 87 const ui::CompositionText& composition) { | 89 const ui::CompositionText& composition) { |
| 88 ImeInstance* ime_instance = bridge_service_->ime_instance(); | 90 mojom::ImeInstance* ime_instance = bridge_service_->ime_instance(); |
| 89 if (!ime_instance) { | 91 if (!ime_instance) { |
| 90 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 92 LOG(ERROR) << "ArcImeInstance method called before being ready."; |
| 91 return; | 93 return; |
| 92 } | 94 } |
| 93 | 95 |
| 94 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), | 96 ime_instance->SetCompositionText(base::UTF16ToUTF8(composition.text), |
| 95 ConvertSegments(composition)); | 97 ConvertSegments(composition)); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void ArcImeBridgeImpl::SendConfirmCompositionText() { | 100 void ArcImeBridgeImpl::SendConfirmCompositionText() { |
| 99 ImeInstance* ime_instance = bridge_service_->ime_instance(); | 101 mojom::ImeInstance* ime_instance = bridge_service_->ime_instance(); |
| 100 if (!ime_instance) { | 102 if (!ime_instance) { |
| 101 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 103 LOG(ERROR) << "ArcImeInstance method called before being ready."; |
| 102 return; | 104 return; |
| 103 } | 105 } |
| 104 | 106 |
| 105 ime_instance->ConfirmCompositionText(); | 107 ime_instance->ConfirmCompositionText(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { | 110 void ArcImeBridgeImpl::SendInsertText(const base::string16& text) { |
| 109 ImeInstance* ime_instance = bridge_service_->ime_instance(); | 111 mojom::ImeInstance* ime_instance = bridge_service_->ime_instance(); |
| 110 if (!ime_instance) { | 112 if (!ime_instance) { |
| 111 LOG(ERROR) << "ArcImeInstance method called before being ready."; | 113 LOG(ERROR) << "ArcImeInstance method called before being ready."; |
| 112 return; | 114 return; |
| 113 } | 115 } |
| 114 | 116 |
| 115 ime_instance->InsertText(base::UTF16ToUTF8(text)); | 117 ime_instance->InsertText(base::UTF16ToUTF8(text)); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::TextInputType type) { | 120 void ArcImeBridgeImpl::OnTextInputTypeChanged(arc::mojom::TextInputType type) { |
| 119 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); | 121 delegate_->OnTextInputTypeChanged(ConvertTextInputType(type)); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void ArcImeBridgeImpl::OnCursorRectChanged(arc::CursorRectPtr rect) { | 124 void ArcImeBridgeImpl::OnCursorRectChanged(arc::mojom::CursorRectPtr rect) { |
| 123 delegate_->OnCursorRectChanged(gfx::Rect( | 125 delegate_->OnCursorRectChanged(gfx::Rect( |
| 124 rect->left, | 126 rect->left, |
| 125 rect->top, | 127 rect->top, |
| 126 rect->right - rect->left, | 128 rect->right - rect->left, |
| 127 rect->bottom - rect->top)); | 129 rect->bottom - rect->top)); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void ArcImeBridgeImpl::OnCancelComposition() { | 132 void ArcImeBridgeImpl::OnCancelComposition() { |
| 131 delegate_->OnCancelComposition(); | 133 delegate_->OnCancelComposition(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 } // namespace arc | 136 } // namespace arc |
| OLD | NEW |