diff options
author | kinaba <kinaba@chromium.org> | 2016-02-22 16:56:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-23 00:57:08 +0000 |
commit | b476406bdab8633d06ed6de94a34289cbeb74412 (patch) | |
tree | 582b9c5570df364fccba60b3b01523242106dd20 | |
parent | 409e5355ae1269cde51dc5b73b4592bad4e8c2ea (diff) | |
download | chromium_src-b476406bdab8633d06ed6de94a34289cbeb74412.zip chromium_src-b476406bdab8633d06ed6de94a34289cbeb74412.tar.gz chromium_src-b476406bdab8633d06ed6de94a34289cbeb74412.tar.bz2 |
ARC IME: Support CancelComposition.
Applications can request IME to abandon the current composition, for instance
when the app replaced the text content by auto completion.
This CLL adds a Mojo IPC for handling the request and adds Chrome side impl.
BUG=b/26627460
Review URL: https://codereview.chromium.org/1670733003
Cr-Commit-Position: refs/heads/master@{#376879}
-rw-r--r-- | components/arc/common/ime.mojom | 3 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_bridge.cc | 6 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_bridge.h | 1 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_bridge_unittest.cc | 21 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_ipc_host.h | 1 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_ipc_host_impl.cc | 4 | ||||
-rw-r--r-- | components/arc/ime/arc_ime_ipc_host_impl.h | 1 |
7 files changed, 36 insertions, 1 deletions
diff --git a/components/arc/common/ime.mojom b/components/arc/common/ime.mojom index f5fc86a..6af2b88 100644 --- a/components/arc/common/ime.mojom +++ b/components/arc/common/ime.mojom @@ -44,6 +44,9 @@ interface ImeHost { // Notifies Chrome that the cursor poisition has changed. OnCursorRectChanged(CursorRect rect); + + // Notifies Chrome that the current composition is canceled. + [MinVersion=1] OnCancelComposition(); }; interface ImeInstance { diff --git a/components/arc/ime/arc_ime_bridge.cc b/components/arc/ime/arc_ime_bridge.cc index ec7ba5e..e129edf 100644 --- a/components/arc/ime/arc_ime_bridge.cc +++ b/components/arc/ime/arc_ime_bridge.cc @@ -157,6 +157,12 @@ void ArcImeBridge::OnCursorRectChanged(const gfx::Rect& rect) { input_method->OnCaretBoundsChanged(this); } +void ArcImeBridge::OnCancelComposition() { + ui::InputMethod* const input_method = GetInputMethod(); + if (input_method) + input_method->CancelComposition(this); +} + //////////////////////////////////////////////////////////////////////////////// // Oberridden from ui::TextInputClient: diff --git a/components/arc/ime/arc_ime_bridge.h b/components/arc/ime/arc_ime_bridge.h index 1fcfc1b..561eb44 100644 --- a/components/arc/ime/arc_ime_bridge.h +++ b/components/arc/ime/arc_ime_bridge.h @@ -61,6 +61,7 @@ class ArcImeBridge : public ArcService, // Overridden from ArcImeIpcHost::Delegate: void OnTextInputTypeChanged(ui::TextInputType type) override; void OnCursorRectChanged(const gfx::Rect& rect) override; + void OnCancelComposition() override; // Overridden from ui::TextInputClient: void SetCompositionText(const ui::CompositionText& composition) override; diff --git a/components/arc/ime/arc_ime_bridge_unittest.cc b/components/arc/ime/arc_ime_bridge_unittest.cc index bddb887..7cd1614 100644 --- a/components/arc/ime/arc_ime_bridge_unittest.cc +++ b/components/arc/ime/arc_ime_bridge_unittest.cc @@ -29,7 +29,9 @@ class FakeArcImeIpcHost : public ArcImeIpcHost { class FakeInputMethod : public ui::DummyInputMethod { public: - FakeInputMethod() : client_(nullptr), count_show_ime_if_needed_(0) {} + FakeInputMethod() : client_(nullptr), + count_show_ime_if_needed_(0), + count_cancel_composition_(0) {} void SetFocusedTextInputClient(ui::TextInputClient* client) override { client_ = client; @@ -43,13 +45,23 @@ class FakeInputMethod : public ui::DummyInputMethod { count_show_ime_if_needed_++; } + void CancelComposition(const ui::TextInputClient* client) override { + if (client == client_) + count_cancel_composition_++; + } + int count_show_ime_if_needed() const { return count_show_ime_if_needed_; } + int count_cancel_composition() const { + return count_cancel_composition_; + } + private: ui::TextInputClient* client_; int count_show_ime_if_needed_; + int count_cancel_composition_; }; } // namespace @@ -126,4 +138,11 @@ TEST_F(ArcImeBridgeTest, ShowImeIfNeeded) { EXPECT_EQ(2, fake_input_method_->count_show_ime_if_needed()); } +TEST_F(ArcImeBridgeTest, CancelComposition) { + // The bridge should forward the cancel event to the input method. + fake_input_method_->SetFocusedTextInputClient(instance_.get()); + instance_->OnCancelComposition(); + EXPECT_EQ(1, fake_input_method_->count_cancel_composition()); +} + } // namespace arc diff --git a/components/arc/ime/arc_ime_ipc_host.h b/components/arc/ime/arc_ime_ipc_host.h index 24ec506..7f5087c 100644 --- a/components/arc/ime/arc_ime_ipc_host.h +++ b/components/arc/ime/arc_ime_ipc_host.h @@ -30,6 +30,7 @@ class ArcImeIpcHost { public: virtual void OnTextInputTypeChanged(ui::TextInputType type) = 0; virtual void OnCursorRectChanged(const gfx::Rect& rect) = 0; + virtual void OnCancelComposition() = 0; }; // Serializes and sends IME related requests through IPCs. diff --git a/components/arc/ime/arc_ime_ipc_host_impl.cc b/components/arc/ime/arc_ime_ipc_host_impl.cc index 086fc57..9cee03d 100644 --- a/components/arc/ime/arc_ime_ipc_host_impl.cc +++ b/components/arc/ime/arc_ime_ipc_host_impl.cc @@ -127,4 +127,8 @@ void ArcImeIpcHostImpl::OnCursorRectChanged(arc::CursorRectPtr rect) { rect->bottom - rect->top)); } +void ArcImeIpcHostImpl::OnCancelComposition() { + delegate_->OnCancelComposition(); +} + } // namespace arc diff --git a/components/arc/ime/arc_ime_ipc_host_impl.h b/components/arc/ime/arc_ime_ipc_host_impl.h index 04bcc6d..643b32c 100644 --- a/components/arc/ime/arc_ime_ipc_host_impl.h +++ b/components/arc/ime/arc_ime_ipc_host_impl.h @@ -40,6 +40,7 @@ class ArcImeIpcHostImpl : public ArcImeIpcHost, // arc::ImeHost overrides: void OnTextInputTypeChanged(arc::TextInputType type) override; void OnCursorRectChanged(arc::CursorRectPtr rect) override; + void OnCancelComposition() override; private: mojo::Binding<ImeHost> binding_; |