Skip to content

Commit

Permalink
[Mojo-IMF] Defines/implements mojo interface - ImeEngineClient.
Browse files Browse the repository at this point in the history
 - Makes InputMethodChromeOS as an ImeEngineClient.
 - Hooks up WindowTreeHostMus/WindowTreeClient to connect to ImeEngine.
 - Makes calls from ImeEngine to ImeEngineClient.

Bug: 937167
Change-Id: I0d27ce6e9bc547f4d269cdfe0ef38e8e83673267
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546795
Commit-Queue: Shu Chen <shuchen@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648188}
  • Loading branch information
Shu Chen authored and Commit Bot committed Apr 5, 2019
1 parent 70fd636 commit 6716700
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 51 deletions.
9 changes: 9 additions & 0 deletions ash/ime/ime_engine_factory_registry_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class TestImeEngineClient : public ime::mojom::ImeEngineClient {
}

private:
// ime::mojom::ImeEngineClient:
void CommitText(const std::string& text) override {}
void UpdateCompositionText(const ui::CompositionText& composition,
uint32_t cursor_pos,
bool visible) override {}
void DeleteSurroundingText(int32_t offset, uint32_t length) override {}
void SendKeyEvent(std::unique_ptr<ui::Event> key_event) override {}
void Reconnect() override {}

mojo::Binding<ime::mojom::ImeEngineClient> binding_;

DISALLOW_COPY_AND_ASSIGN(TestImeEngineClient);
Expand Down
19 changes: 10 additions & 9 deletions chrome/browser/chromeos/input_method/input_method_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ class MojoHelper : public ime::mojom::ImeEngine,

private:
void OnConnectionLost() {
// After the connection to |ImeEngineFactoryRegistry| is broken, break the
// connection to the client, so that the client can reconnect through Window
// Service.
engine_binding_.Close();
engine_client_.reset();
// After the connection to |ImeEngineFactoryRegistry| is broken, notifies
// the client to reconnect through Window Service.
if (engine_client_)
engine_client_->Reconnect();
}

InputMethodEngine* engine_;
Expand Down Expand Up @@ -370,7 +369,8 @@ void InputMethodEngine::UpdateComposition(
uint32_t cursor_pos,
bool is_visible) {
if (mojo_helper_->IsConnected()) {
NOTIMPLEMENTED_LOG_ONCE();
mojo_helper_->engine_client()->UpdateCompositionText(
composition_text, cursor_pos, is_visible);
} else {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
Expand All @@ -384,7 +384,7 @@ void InputMethodEngine::CommitTextToInputContext(int context_id,
const std::string& text) {
bool committed = false;
if (mojo_helper_->IsConnected()) {
NOTIMPLEMENTED_LOG_ONCE();
mojo_helper_->engine_client()->CommitText(text);
} else {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
Expand All @@ -407,7 +407,8 @@ void InputMethodEngine::DeleteSurroundingTextToInputContext(
int offset,
size_t number_of_chars) {
if (mojo_helper_->IsConnected()) {
NOTIMPLEMENTED_LOG_ONCE();
mojo_helper_->engine_client()->DeleteSurroundingText(offset,
number_of_chars);
} else {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
Expand All @@ -429,7 +430,7 @@ bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event,

bool sent = false;
if (mojo_helper_->IsConnected()) {
NOTIMPLEMENTED_LOG_ONCE();
mojo_helper_->engine_client()->SendKeyEvent(ui::Event::Clone(*event));
} else {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,22 @@ class TestImeEngineClient : public ime::mojom::ImeEngineClient {
return ptr;
}

bool commit_text_called() const { return commit_text_called_; }

private:
// ime::mojom::ImeEngineClient:
void CommitText(const std::string& text) override {
commit_text_called_ = true;
}
void UpdateCompositionText(const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool visible) override {}
void DeleteSurroundingText(int32_t offset, uint32_t length) override {}
void SendKeyEvent(std::unique_ptr<ui::Event> key_event) override {}
void Reconnect() override {}

mojo::Binding<ime::mojom::ImeEngineClient> binding_;
bool commit_text_called_ = false;

DISALLOW_COPY_AND_ASSIGN(TestImeEngineClient);
};
Expand Down Expand Up @@ -404,6 +418,12 @@ TEST_F(InputMethodEngineTest, TestMojoInteractions) {
false));
engine_ptr.FlushForTesting();
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());

int context = engine_->GetContextIdForTesting();
std::string error;
engine_->CommitText(context, "input", &error);
engine_->FlushForTesting();
EXPECT_TRUE(client.commit_text_called());
}

} // namespace input_method
Expand Down
9 changes: 9 additions & 0 deletions services/ws/window_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ class TestImeEngineClient : public ime::mojom::ImeEngineClient {
}

private:
// ime::mojom::ImeEngineClient:
void CommitText(const std::string& text) override {}
void UpdateCompositionText(const ui::CompositionText& composition,
uint32_t cursor_pos,
bool visible) override {}
void DeleteSurroundingText(int32_t offset, uint32_t length) override {}
void SendKeyEvent(std::unique_ptr<ui::Event> key_event) override {}
void Reconnect() override {}

mojo::Binding<ime::mojom::ImeEngineClient> binding_;

DISALLOW_COPY_AND_ASSIGN(TestImeEngineClient);
Expand Down
6 changes: 6 additions & 0 deletions ui/aura/mus/window_tree_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,12 @@ void WindowTreeClient::OnWindowTreeHostCreated(
drag_drop_controller_.get());
}

void WindowTreeClient::ConnectToImeEngine(
ime::mojom::ImeEngineRequest engine_request,
ime::mojom::ImeEngineClientPtr client) {
tree_->ConnectToImeEngine(std::move(engine_request), std::move(client));
}

void WindowTreeClient::OnTransientChildWindowAdded(Window* parent,
Window* transient_child) {
// TransientWindowClient is a singleton and we allow multiple
Expand Down
2 changes: 2 additions & 0 deletions ui/aura/mus/window_tree_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ class AURA_EXPORT WindowTreeClient
std::unique_ptr<WindowPortMus> CreateWindowPortForTopLevel(
const std::map<std::string, std::vector<uint8_t>>* properties) override;
void OnWindowTreeHostCreated(WindowTreeHostMus* window_tree_host) override;
void ConnectToImeEngine(ime::mojom::ImeEngineRequest engine_request,
ime::mojom::ImeEngineClientPtr client) override;

// client::TransientWindowClientObserver:
void OnTransientChildWindowAdded(Window* parent,
Expand Down
7 changes: 7 additions & 0 deletions ui/aura/mus/window_tree_host_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ void WindowTreeHostMus::SetImeVisibility(bool visible,
WindowPortMus::Get(window())->SetImeVisibility(visible, std::move(state));
}

bool WindowTreeHostMus::ConnectToImeEngine(
ime::mojom::ImeEngineRequest engine_request,
ime::mojom::ImeEngineClientPtr client) {
delegate_->ConnectToImeEngine(std::move(engine_request), std::move(client));
return true;
}

void WindowTreeHostMus::SetBoundsInPixels(
const gfx::Rect& bounds,
const viz::LocalSurfaceIdAllocation& local_surface_id_allocation) {
Expand Down
3 changes: 3 additions & 0 deletions ui/aura/mus/window_tree_host_mus.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/mus/input_method_mus_delegate.h"
#include "ui/aura/window_tree_host_platform.h"
#include "ui/base/ime/mojo/ime.mojom.h"
#include "ui/base/mojo/ui_base_types.mojom.h"

namespace display {
Expand Down Expand Up @@ -118,6 +119,8 @@ class AURA_EXPORT WindowTreeHostMus : public WindowTreeHostPlatform,
void SetTextInputState(ui::mojom::TextInputStatePtr state) override;
void SetImeVisibility(bool visible,
ui::mojom::TextInputStatePtr state) override;
bool ConnectToImeEngine(ime::mojom::ImeEngineRequest engine_request,
ime::mojom::ImeEngineClientPtr client) override;

protected:
// This is in the protected section as SetBounds() is preferred.
Expand Down
6 changes: 6 additions & 0 deletions ui/aura/mus/window_tree_host_mus_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "ui/aura/aura_export.h"
#include "ui/base/ime/mojo/ime.mojom.h"

namespace gfx {
class Rect;
Expand Down Expand Up @@ -75,6 +76,11 @@ class AURA_EXPORT WindowTreeHostMusDelegate {
// created.
virtual void OnWindowTreeHostCreated(WindowTreeHostMus* window_tree_host) = 0;

// Called when a client requests to connect to the active
// ime::mojom::ImeEngine.
virtual void ConnectToImeEngine(ime::mojom::ImeEngineRequest engine_request,
ime::mojom::ImeEngineClientPtr client) = 0;

protected:
virtual ~WindowTreeHostMusDelegate() {}
};
Expand Down
46 changes: 38 additions & 8 deletions ui/base/ime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,54 @@ source_set("text_input_types") {
]
}

jumbo_component("ime") {
output_name = "ui_base_ime"
jumbo_component("ime_types") {
output_name = "ui_base_ime_types"
sources = [
"candidate_window.cc",
"candidate_window.h",
"character_composer.cc",
"character_composer.h",
"composition_text.cc",
"composition_text.h",
"ime_text_span.cc",
"ime_text_span.h",
"infolist_entry.cc",
"infolist_entry.h",
]

defines = [ "IS_UI_BASE_IME_TYPES_IMPL" ]

deps = [
"//base",
"//ui/gfx/range",
]

public_deps = [
":text_input_types",
"//skia",
]

if (is_chromeos || use_ozone) {
sources += [
"character_composer.cc",
"character_composer.h",
]
deps += [
"//ui/events:dom_keycode_converter",
"//ui/events:events",
"//ui/events:events_base",
]
}
}

jumbo_component("ime") {
output_name = "ui_base_ime"
sources = [
"constants.cc",
"constants.h",
"ime_bridge.cc",
"ime_bridge.h",
"ime_candidate_window_handler_interface.h",
"ime_engine_handler_interface.h",
"ime_input_context_handler_interface.h",
"ime_text_span.cc",
"ime_text_span.h",
"infolist_entry.cc",
"infolist_entry.h",
"input_method.h",
"input_method_base.cc",
"input_method_base.h",
Expand All @@ -57,11 +85,13 @@ jumbo_component("ime") {
defines = [ "IS_UI_BASE_IME_IMPL" ]

public_deps = [
":ime_types",
":text_input_types",
"//base",
"//base:i18n",
"//skia",
"//third_party/icu",
"//ui/base/ime/mojo",
"//ui/events",
"//ui/events:dom_keycode_converter",
"//ui/events:events",
Expand Down
6 changes: 3 additions & 3 deletions ui/base/ime/candidate_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
namespace ui {

// CandidateWindow represents the structure of candidates generated from IME.
class COMPONENT_EXPORT(UI_BASE_IME) CandidateWindow {
class COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindow {
public:
enum Orientation {
HORIZONTAL = 0,
VERTICAL = 1,
};

struct COMPONENT_EXPORT(UI_BASE_IME) CandidateWindowProperty {
struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindowProperty {
CandidateWindowProperty();
virtual ~CandidateWindowProperty();
int page_size;
Expand All @@ -41,7 +41,7 @@ class COMPONENT_EXPORT(UI_BASE_IME) CandidateWindow {
};

// Represents a candidate entry.
struct COMPONENT_EXPORT(UI_BASE_IME) Entry {
struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) Entry {
Entry();
Entry(const Entry& other);
virtual ~Entry();
Expand Down
2 changes: 1 addition & 1 deletion ui/base/ime/character_composer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class KeyEvent;

// A class to recognize compose and dead key sequence.
// Outputs composed character.
class COMPONENT_EXPORT(UI_BASE_IME) CharacterComposer {
class COMPONENT_EXPORT(UI_BASE_IME_TYPES) CharacterComposer {
public:
using ComposeBuffer = std::vector<DomKey>;

Expand Down
1 change: 1 addition & 0 deletions ui/base/ime/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jumbo_component("chromeos") {
"//services/ws/public/cpp/input_devices",
"//third_party/icu",
"//ui/base",
"//ui/base/ime/mojo",
"//ui/chromeos/strings",
]
}
Loading

0 comments on commit 6716700

Please sign in to comment.