Skip to content

Commit

Permalink
* Adds the initial version of mojom interfaces for Mus IME.
Browse files Browse the repository at this point in the history
* Implements basic IME driver in services/ui/test_ime. An IME driver is a
service which is responsible for doing the composition logic and generating
composition events. The basic driver replies back key events with an INSERT_CHAR
composition event with the same character code.

BUG=548407

Review-Url: https://codereview.chromium.org/2161773002
Cr-Commit-Position: refs/heads/master@{#408407}
  • Loading branch information
moshayedi authored and Commit bot committed Jul 28, 2016
1 parent 17ac3a7 commit c367749
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 0 deletions.
1 change: 1 addition & 0 deletions services/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group("all") {
testonly = true
deps = [
":ui",
"//services/ui/test_ime",
"//services/ui/test_wm",
]
}
Expand Down
1 change: 1 addition & 0 deletions services/ui/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mojom("interfaces") {
"gpu.mojom",
"gpu_memory_buffer.mojom",
"gpu_service.mojom",
"ime.mojom",
"mus_constants.mojom",
"surface.mojom",
"user_access_manager.mojom",
Expand Down
110 changes: 110 additions & 0 deletions services/ui/public/interfaces/ime.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module ui.mojom;

import "ui/events/mojo/event.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";

struct CompositionEvent {
CompositionEventType type;

// Used when |type| is INSERT_CHAR. See the comments for
// ui::TextInputClient::InsertChar() for more information.
Event? key_event;

// TODO(moshayedi): crbug.com/631524. Add fields required for other types of
// composition event.
};

enum CompositionEventType {
UPDATE,
CONFIRM,
CLEAR,
INSERT_CHAR,
INSERT_TEXT
};

// See comments for ui::TextInputType for more details.
enum TextInputType {
NONE,
TEXT,
PASSWORD,
SEARCH,
EMAIL,
NUMBER,
TELEPHONE,
URL,
DATE,
TIME,
DATETIME,
};

// See comments for ui::TextInputMode for more details.
enum TextInputMode {
DEFAULT,
VERBATIM,
LATIN,
LATIN_NAME,
LATIN_PROSE,
FULL_WIDTH_LATIN,
KANA,
KATAKANA,
NUMERIC,
TEL,
EMAIL,
URL,
};

// A service which provides the IMEDriver interface is responsible for doing
// the composition logic. After starting a session, it receives events from
// the client via the InputMethod interface, and sends composition events to
// the client via the TextInputClient.
interface IMEDriver {
// session_id is unique and generated by Mus.
StartSession(int32 session_id, TextInputClient client,
InputMethod& input_method);
CancelSession(int32 session_id);
};

// Clients use IME using the IMEServer interface which is provided by Mus. Mus
// does minimal processing and mostly just acts as lightweight proxy between
// the client app and the registered IME driver.
interface IMEServer {
StartSession(TextInputClient client,
InputMethod& input_method);
};

// An IME driver register should register itself to Mus using the IMERegistrar
// interface.
interface IMERegistrar {
RegisterDriver(IMEDriver driver);
};

// A client sends updates to the IME driver using the InputMethod interface.
// This interface is provided by IME drivers, and also by Mus as a lightweight
// proxy between IME drivers and clients.
interface InputMethod {
OnTextInputModeChanged(TextInputMode text_input_mode);
OnTextInputTypeChanged(TextInputType text_input_type);

// Client sends |caret_bounds| in focused window coordinates,
// Mus translates it to global coordinates and sends it to IME app.
OnCaretBoundsChanged(gfx.mojom.Rect caret_bounds);

ProcessKeyEvent(ui.mojom.Event key_event);
CancelComposition();
};

// IME drivers send updates to clients using the TextInputClient interface.
interface TextInputClient {
// Corresponds to "input method result" functions of ui::TextInputClient.
OnCompositionEvent(CompositionEvent event);

// TODO(moshayedi): Add functions corresponding to ui::TextInputClient for:
// - Input text confirmation
// - Document content operations
// - Miscellaneous functions
// crbug.com/631527.
};
67 changes: 67 additions & 0 deletions services/ui/test_ime/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//services/shell/public/cpp/service.gni")
import("//services/shell/public/service_manifest.gni")
import("//testing/test.gni")

service("test_ime") {
sources = [
"main.cc",
"test_ime_driver.cc",
"test_ime_driver.h",
]

deps = [
"//base",
"//services/shell/public/cpp",
"//services/ui/public/cpp",
"//services/ui/public/interfaces",
"//ui/gfx/geometry/mojo",
]

data_deps = [
":manifest",
"//services/ui",
]
}

group("tests") {
testonly = true
deps = [
":test_ime_unittests",
]
}

test("test_ime_unittests") {
sources = [
"test_ime_unittest.cc",
]

deps = [
"//base",
"//mojo/common",
"//services/shell/public/cpp:service_test_support",
"//services/shell/public/cpp:sources",
"//services/shell/public/cpp/test:run_all_shelltests",
"//services/ui/public/interfaces",
]

data_deps = [
":test_ime",
":test_manifest",
"//services/ui",
]
}

service_manifest("manifest") {
name = "test_ime"
source = "manifest.json"
}

service_manifest("test_manifest") {
type = "exe"
name = "test_ime_unittests"
source = "test_manifest.json"
}
45 changes: 45 additions & 0 deletions services/ui/test_ime/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/public/c/system/main.h"
#include "services/shell/public/cpp/connector.h"
#include "services/shell/public/cpp/service.h"
#include "services/shell/public/cpp/service_runner.h"
#include "services/ui/test_ime/test_ime_driver.h"

namespace ui {
namespace test {

class TestIME : public shell::Service,
public shell::InterfaceFactory<mojom::IMEDriver> {
public:
TestIME() {}
~TestIME() override {}

private:
// shell::Service:
void OnStart(const shell::Identity& identity) override {}
bool OnConnect(shell::Connection* connection) override {
connection->AddInterface<mojom::IMEDriver>(this);
return true;
}

// shell::InterfaceFactory<mojom::IMEDriver>:
void Create(const shell::Identity& remote_identity,
mojom::IMEDriverRequest request) override {
ime_driver_.reset(new TestIMEDriver(std::move(request)));
}

std::unique_ptr<TestIMEDriver> ime_driver_;

DISALLOW_COPY_AND_ASSIGN(TestIME);
};

} // namespace test
} // namespace ui

MojoResult MojoMain(MojoHandle shell_handle) {
shell::ServiceRunner runner(new ui::test::TestIME);
return runner.Run(shell_handle);
}
10 changes: 10 additions & 0 deletions services/ui/test_ime/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manifest_version": 1,
"name": "mojo:test_ime",
"display_name": "Test IME Driver",
"capabilities": {
"provided": {
"app": [ "ui::mojom::IMEDriver" ]
}
}
}
57 changes: 57 additions & 0 deletions services/ui/test_ime/test_ime_driver.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/ui/test_ime/test_ime_driver.h"

namespace ui {
namespace test {

class TestInputMethod : public mojom::InputMethod {
public:
explicit TestInputMethod(mojom::TextInputClientPtr client)
: client_(std::move(client)) {}
~TestInputMethod() override {}

private:
// mojom::InputMethod:
void OnTextInputModeChanged(mojom::TextInputMode text_input_mode) override {}
void OnTextInputTypeChanged(mojom::TextInputType text_input_type) override {}
void OnCaretBoundsChanged(const gfx::Rect& caret_bounds) override {}
void ProcessKeyEvent(std::unique_ptr<Event> key_event) override {
DCHECK(key_event->IsKeyEvent());
mojom::CompositionEventPtr composition_event =
mojom::CompositionEvent::New();
composition_event->type = mojom::CompositionEventType::INSERT_CHAR;
composition_event->key_event = std::move(key_event);

client_->OnCompositionEvent(std::move(composition_event));
};
void CancelComposition() override {}

mojom::TextInputClientPtr client_;

DISALLOW_COPY_AND_ASSIGN(TestInputMethod);
};

TestIMEDriver::TestIMEDriver(mojom::IMEDriverRequest request)
: driver_binding_(this, std::move(request)) {}

TestIMEDriver::~TestIMEDriver() {}

void TestIMEDriver::StartSession(
int32_t session_id,
mojom::TextInputClientPtr client,
mojom::InputMethodRequest input_method_request) {
input_method_bindings_[session_id].reset(
new mojo::Binding<mojom::InputMethod>(
new TestInputMethod(std::move(client)),
std::move(input_method_request)));
}

void TestIMEDriver::CancelSession(int32_t session_id) {
input_method_bindings_.erase(session_id);
}

} // namespace test
} // namespace ui
39 changes: 39 additions & 0 deletions services/ui/test_ime/test_ime_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_UI_TEST_IME_TEST_IME_DRIVER_H_
#define SERVICES_UI_TEST_IME_TEST_IME_DRIVER_H_

#include <map>

#include "mojo/public/cpp/bindings/binding.h"
#include "services/ui/public/interfaces/ime.mojom.h"

namespace ui {
namespace test {

class TestIMEDriver : public ui::mojom::IMEDriver {
public:
explicit TestIMEDriver(mojom::IMEDriverRequest request);
~TestIMEDriver() override;

private:
// ui::mojom::IMEDriver:
void StartSession(
int32_t session_id,
ui::mojom::TextInputClientPtr client,
ui::mojom::InputMethodRequest input_method_request) override;
void CancelSession(int32_t session_id) override;

mojo::Binding<mojom::IMEDriver> driver_binding_;
std::map<int32_t, std::unique_ptr<mojo::Binding<mojom::InputMethod>>>
input_method_bindings_;

DISALLOW_COPY_AND_ASSIGN(TestIMEDriver);
};

} // namespace test
} // namespace ui

#endif // SERVICES_UI_TEST_IME_TEST_IME_DRIVER_H_
Loading

0 comments on commit c367749

Please sign in to comment.