Commit d54af36b authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Add SendKeyEvent() to ImeHost interface.

It will be used by the proxy IME to send a key event to the host IME.
Chrome returns whether it's consumed by the host IME. Android will let
an ARC app handle the event if it's not consumed by the host IME.

Bug: b:148193316
Change-Id: I72dcb63d0853cd87baab5f3ab911e704628e2edf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2273038Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785623}
parent 8d5514e9
......@@ -5,9 +5,11 @@
#ifndef COMPONENTS_ARC_IME_ARC_IME_BRIDGE_H_
#define COMPONENTS_ARC_IME_ARC_IME_BRIDGE_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/events/event.h"
namespace gfx {
class Range;
......@@ -29,6 +31,8 @@ class ArcImeBridge {
// Received IPCs are deserialized and passed to this delegate.
class Delegate {
public:
using KeyEventDoneCallback = base::OnceCallback<void(bool)>;
virtual void OnTextInputTypeChanged(ui::TextInputType type,
bool is_personalized_learning_allowed,
int flags) = 0;
......@@ -43,6 +47,8 @@ class ArcImeBridge {
const gfx::Range& selection_range,
bool is_screen_coordinates) = 0;
virtual bool ShouldEnableKeyEventForwarding() = 0;
virtual void SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
KeyEventDoneCallback callback) = 0;
};
// Serializes and sends IME related requests through IPCs.
......
......@@ -159,4 +159,9 @@ void ArcImeBridgeImpl::ShouldEnableKeyEventForwarding(
std::move(callback).Run(delegate_->ShouldEnableKeyEventForwarding());
}
void ArcImeBridgeImpl::SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
SendKeyEventCallback callback) {
delegate_->SendKeyEvent(std::move(key_event), std::move(callback));
}
} // namespace arc
......@@ -54,6 +54,8 @@ class ArcImeBridgeImpl : public ArcImeBridge, public mojom::ImeHost {
void RequestHideImeDeprecated() override;
void ShouldEnableKeyEventForwarding(
ShouldEnableKeyEventForwardingCallback callback) override;
void SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
SendKeyEventCallback callback) override;
private:
Delegate* const delegate_;
......
......@@ -392,6 +392,16 @@ bool ArcImeService::ShouldEnableKeyEventForwarding() {
chromeos::features::kArcPreImeKeyEventSupport);
}
void ArcImeService::SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
KeyEventDoneCallback callback) {
ui::InputMethod* const input_method = GetInputMethod();
if (input_method)
ignore_result(input_method->DispatchKeyEvent(key_event.get()));
// TODO(yhanada): Wait the host IME for handling the event and return the
// correct result.
std::move(callback).Run(true);
}
////////////////////////////////////////////////////////////////////////////////
// Overridden from ash::KeyboardControllerObserver
void ArcImeService::OnKeyboardAppearanceChanged(
......
......@@ -102,6 +102,8 @@ class ArcImeService : public KeyedService,
const gfx::Range& selection_range,
bool is_screen_coordinates) override;
bool ShouldEnableKeyEventForwarding() override;
void SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
KeyEventDoneCallback callback) override;
// Overridden from ash::KeyboardControllerObserver.
void OnKeyboardAppearanceChanged(
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 14
// Next MinVersion: 15
module arc.mojom;
......@@ -56,7 +56,7 @@ struct KeyEventData {
bool is_capslock_on;
};
// Next method ID: 7
// Next method ID: 8
interface ImeHost {
// Notifies Chrome that the text input focus is changed.
// Each bit of the bitmask |flags| corresponds to TEXT_INPUT_FLAG_*.
......@@ -108,6 +108,10 @@ interface ImeHost {
// Asks Chrome whether the proxy IME should send a key event to the host IME.
[MinVersion=13] ShouldEnableKeyEventForwarding@6() => (bool should_forward);
// Sends a key event to Chrome to pass it to the Chrome OS IME.
[MinVersion=14] SendKeyEvent@7(KeyEventData key_event_data)
=> (bool is_consumed);
};
// Next method ID: 8
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment