Initial native keyboard proof of concept. The mojo:keyboard_native service is written in C++ to be platform agnostic (as opposed to the mojo:keyboard service which is currently only a java wrapper around the Android IME). mojo:keyboard_client serves as a client to the mojo:keyboard_native service testing its implementation of the keyboard mojom APIs. R=jamesr@chromium.org Review URL: https://codereview.chromium.org/1139453002
diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 52c3e4e..1a70140 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn
@@ -24,6 +24,7 @@ "//examples/ganesh_app", "//examples/http_handler", "//examples/indirect_service", + "//examples/keyboard_client", "//examples/nesting_app", "//examples/png_viewer", "//examples/recursive_content_handler",
diff --git a/examples/keyboard_client/BUILD.gn b/examples/keyboard_client/BUILD.gn new file mode 100644 index 0000000..f8f7f3b --- /dev/null +++ b/examples/keyboard_client/BUILD.gn
@@ -0,0 +1,17 @@ +# Copyright 2015 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("//mojo/public/mojo_application.gni") + +mojo_native_application("keyboard_client") { + sources = [ + "keyboard_client.cc", + ] + + deps = [ + "//base", + "//mojo/public/cpp/application:standalone", + "//mojo/services/keyboard/public/interfaces", + ] +}
diff --git a/examples/keyboard_client/keyboard_client.cc b/examples/keyboard_client/keyboard_client.cc new file mode 100644 index 0000000..5496138 --- /dev/null +++ b/examples/keyboard_client/keyboard_client.cc
@@ -0,0 +1,62 @@ +// Copyright 2015 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 "base/macros.h" +#include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/cpp/application/application_runner.h" +#include "mojo/services/keyboard/public/interfaces/keyboard.mojom.h" + +namespace examples { + +class KeyboardDelegate : public mojo::ApplicationDelegate, + public keyboard::KeyboardClient { + public: + KeyboardDelegate() : binding_(this) {} + + ~KeyboardDelegate() override {} + + // mojo::ApplicationDelegate implementation. + void Initialize(mojo::ApplicationImpl* app) override { + app->ConnectToService("mojo:keyboard_native", &keyboard_); + keyboard_->ShowByRequest(); + keyboard_->Hide(); + + keyboard::KeyboardClientPtr keyboard_client; + auto request = mojo::GetProxy(&keyboard_client); + binding_.Bind(request.Pass()); + keyboard_->Show(keyboard_client.Pass()); + } + + // keyboard::KeyboardClient implementation. + void CommitCompletion(keyboard::CompletionDataPtr completion) override {} + + void CommitCorrection(keyboard::CorrectionDataPtr correction) override {} + + void CommitText(const mojo::String& text, + int32_t new_cursor_position) override {} + + void DeleteSurroundingText(int32_t before_length, + int32_t after_length) override {} + + void SetComposingRegion(int32_t start, int32_t end) override {} + + void SetComposingText(const mojo::String& text, + int32_t new_cursor_position) override {} + + void SetSelection(int32_t start, int32_t end) override {} + + private: + mojo::Binding<keyboard::KeyboardClient> binding_; + keyboard::KeyboardServicePtr keyboard_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardDelegate); +}; + +} // namespace examples + +MojoResult MojoMain(MojoHandle application_request) { + mojo::ApplicationRunner runner(new examples::KeyboardDelegate); + return runner.Run(application_request); +}
diff --git a/services/BUILD.gn b/services/BUILD.gn index ef45031..c01bf91 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn
@@ -13,6 +13,7 @@ "//services/gles2:lib", "//services/http_server", "//services/icu_data", + "//services/keyboard_native", "//services/kiosk_wm", "//services/native_viewport", "//services/reaper",
diff --git a/services/keyboard_native/BUILD.gn b/services/keyboard_native/BUILD.gn new file mode 100644 index 0000000..c827642 --- /dev/null +++ b/services/keyboard_native/BUILD.gn
@@ -0,0 +1,20 @@ +# Copyright 2015 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("//mojo/public/mojo_application.gni") + +mojo_native_application("keyboard_native") { + sources = [ + "keyboard_service_impl.cc", + "keyboard_service_impl.h", + "main.cc", + ] + + deps = [ + "//base", + "//mojo/public/cpp/application:standalone", + "//mojo/public/cpp/bindings", + "//mojo/services/keyboard/public/interfaces", + ] +}
diff --git a/services/keyboard_native/keyboard_service_impl.cc b/services/keyboard_native/keyboard_service_impl.cc new file mode 100644 index 0000000..d01970f --- /dev/null +++ b/services/keyboard_native/keyboard_service_impl.cc
@@ -0,0 +1,42 @@ +// Copyright 2015 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/keyboard_native/keyboard_service_impl.h" + +namespace keyboard { + +KeyboardServiceImpl::KeyboardServiceImpl( + mojo::InterfaceRequest<KeyboardService> request) + : strong_binding_(this, request.Pass()) { +} + +KeyboardServiceImpl::~KeyboardServiceImpl() { +} + +// KeyboardService implementation. +void KeyboardServiceImpl::Show(KeyboardClientPtr client) { + keyboard::CompletionData completion_data; + completion_data.text = "blah"; + completion_data.label = "blahblah"; + client->CommitCompletion(completion_data.Clone()); + + keyboard::CorrectionData correction_data; + correction_data.old_text = "old text"; + correction_data.new_text = "new text"; + client->CommitCorrection(correction_data.Clone()); + + client->CommitText("", 0); + client->DeleteSurroundingText(0, 0); + client->SetComposingRegion(0, 0); + client->SetComposingText("", 0); + client->SetSelection(0, 1); +} + +void KeyboardServiceImpl::ShowByRequest() { +} + +void KeyboardServiceImpl::Hide() { +} + +} // namespace keyboard
diff --git a/services/keyboard_native/keyboard_service_impl.h b/services/keyboard_native/keyboard_service_impl.h new file mode 100644 index 0000000..5ffbe70 --- /dev/null +++ b/services/keyboard_native/keyboard_service_impl.h
@@ -0,0 +1,28 @@ +// Copyright 2015 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 "base/macros.h" +#include "mojo/public/cpp/bindings/interface_request.h" +#include "mojo/public/cpp/bindings/strong_binding.h" +#include "mojo/services/keyboard/public/interfaces/keyboard.mojom.h" + +namespace keyboard { + +class KeyboardServiceImpl : public KeyboardService { + public: + explicit KeyboardServiceImpl(mojo::InterfaceRequest<KeyboardService> request); + ~KeyboardServiceImpl() override; + + // KeyboardService implementation. + void Show(KeyboardClientPtr client) override; + void ShowByRequest() override; + void Hide() override; + + private: + mojo::StrongBinding<KeyboardService> strong_binding_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); +}; + +} // namespace keyboard
diff --git a/services/keyboard_native/main.cc b/services/keyboard_native/main.cc new file mode 100644 index 0000000..0d08e63 --- /dev/null +++ b/services/keyboard_native/main.cc
@@ -0,0 +1,42 @@ +// Copyright 2015 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/cpp/application/application_connection.h" +#include "mojo/public/cpp/application/application_delegate.h" +#include "mojo/public/cpp/application/application_runner.h" +#include "mojo/public/cpp/application/interface_factory.h" +#include "mojo/public/cpp/bindings/interface_request.h" +#include "services/keyboard_native/keyboard_service_impl.h" + +namespace keyboard { + +class KeyboardServiceDelegate : public mojo::ApplicationDelegate, + public mojo::InterfaceFactory<KeyboardService> { + public: + KeyboardServiceDelegate() {} + ~KeyboardServiceDelegate() override {} + + // ApplicationDelegate implementation. + bool ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) override { + connection->AddService<KeyboardService>(this); + return true; + } + + // InterfaceFactory<KeyboardService> implementation. + void Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<KeyboardService> request) override { + new KeyboardServiceImpl(request.Pass()); + } + + private: + DISALLOW_COPY_AND_ASSIGN(KeyboardServiceDelegate); +}; + +} // namespace keyboard + +MojoResult MojoMain(MojoHandle application_request) { + mojo::ApplicationRunner runner(new keyboard::KeyboardServiceDelegate()); + return runner.Run(application_request); +}