提交 5d34f5aa 编写于 作者: K Kris Giesing

Add support for IME on mojo/Linux

上级 87f5c34e
......@@ -19,7 +19,7 @@
vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': '13824e0387395335e4c9fa54873a540ef21d6096',
'mojo_sdk_revision': '40b28d5dc1ebd9f1416e3b0be9bddca2d59c48ac',
'mojo_devtools_revision': '49879d78ce4486e10c2214a101d9b2e82794b2f4',
'skia_revision': '87ed6be0e4ea8b0a88915045f697d0fd734ed6f5',
......
......@@ -9,4 +9,10 @@ mojom("interfaces") {
sources = [
"keyboard.mojom",
]
import_dirs = [ get_path_info("../../", "abspath") ]
deps = [
"../../native_viewport/interfaces",
]
}
......@@ -5,6 +5,8 @@
[DartPackage="mojo_services"]
module keyboard;
import "native_viewport/interfaces/native_viewport.mojom";
struct CompletionData {
int64 id;
int32 position;
......@@ -49,3 +51,9 @@ interface KeyboardService {
SetText(string text);
SetSelection(int32 start, int32 end);
};
interface KeyboardServiceFactory {
CreateKeyboardService(
mojo.NativeViewportEventDispatcher& keyEventDispatcher,
KeyboardService& serviceRequest);
};
......@@ -34,7 +34,6 @@ interface NativeViewport {
Close();
SetSize(Size size);
SetEventDispatcher(NativeViewportEventDispatcher dispatcher);
SetKeyEventDispatcher(NativeViewportEventDispatcher dispatcher);
// Requests a ContextProvider capable of producing contexts that draw to
// this native viewport.
......
......@@ -31,6 +31,7 @@ mojo_native_application("mojo") {
"//mojo/services/asset_bundle/interfaces",
"//mojo/services/content_handler/interfaces",
"//mojo/services/gpu/interfaces",
"//mojo/services/keyboard/interfaces",
"//mojo/services/native_viewport/interfaces",
"//mojo/services/service_registry/interfaces",
"//services/asset_bundle:lib",
......
......@@ -57,6 +57,9 @@ PlatformViewMojo::~PlatformViewMojo() {
void PlatformViewMojo::Init(mojo::Shell* shell) {
mojo::ConnectToService(shell, "mojo:native_viewport_service", &viewport_);
// Grab the application connector so that we can connect to services later
shell->CreateApplicationConnector(GetProxy(&connector_));
mojo::NativeViewportEventDispatcherPtr ptr;
dispatcher_binding_.Bind(GetProxy(&ptr));
viewport_->SetEventDispatcher(ptr.Pass());
......@@ -85,13 +88,19 @@ void PlatformViewMojo::Init(mojo::Shell* shell) {
base::Bind(&RasterizerMojo::OnContextProviderAvailable,
rasterizer->GetWeakPtr(), base::Passed(&context_provider_info))));
ConnectToEngine(mojo::GetProxy(&sky_engine_));
ConnectToEngine(GetProxy(&sky_engine_));
}
void PlatformViewMojo::Run(const mojo::String& url,
ServicesDataPtr services,
mojo::asset_bundle::AssetBundlePtr bundle) {
mojo::ServiceProviderPtr services_provided_by_embedder;
service_provider_.Bind(GetProxy(&services_provided_by_embedder));
service_provider_.AddService<keyboard::KeyboardService>(this);
services->services_provided_by_embedder = services_provided_by_embedder.Pass();
sky_engine_->SetServices(services.Pass());
sky_engine_->RunFromAssetBundle(url, bundle.Pass());
}
......@@ -140,6 +149,12 @@ void PlatformViewMojo::OnEvent(mojo::EventPtr event,
sky_engine_->OnPointerPacket(packet.Pass());
break;
}
case mojo::EventType::KEY_PRESSED:
case mojo::EventType::KEY_RELEASED:
if (key_event_dispatcher_) {
key_event_dispatcher_->OnEvent(event.Pass(), callback);
return; // key_event_dispatcher_ will invoke callback
}
default:
break;
}
......@@ -147,5 +162,26 @@ void PlatformViewMojo::OnEvent(mojo::EventPtr event,
callback.Run();
}
void PlatformViewMojo::Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<keyboard::KeyboardService> request) {
mojo::ServiceProviderPtr keyboard_service_provider;
connector_->ConnectToApplication(
"mojo:keyboard",
GetProxy(&keyboard_service_provider),
nullptr);
#if defined(OS_LINUX)
keyboard::KeyboardServiceFactoryPtr factory;
mojo::ConnectToService(keyboard_service_provider.get(), &factory);
factory->CreateKeyboardService(GetProxy(&key_event_dispatcher_), request.Pass());
#else
keyboard_service_provider->ConnectToService(
keyboard::KeyboardService::Name_,
request.PassMessagePipe());
#endif
}
} // namespace shell
} // namespace sky
......@@ -5,10 +5,12 @@
#ifndef SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_
#define SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
#include "mojo/services/keyboard/interfaces/keyboard.mojom.h"
#include "mojo/services/native_viewport/interfaces/native_viewport.mojom.h"
#include "sky/shell/platform_view.h"
......@@ -16,7 +18,8 @@ namespace sky {
namespace shell {
class PlatformViewMojo : public PlatformView,
public mojo::NativeViewportEventDispatcher {
public mojo::NativeViewportEventDispatcher,
public mojo::InterfaceFactory<::keyboard::KeyboardService> {
public:
explicit PlatformViewMojo(const Config& config);
~PlatformViewMojo() override;
......@@ -34,11 +37,22 @@ class PlatformViewMojo : public PlatformView,
void OnEvent(mojo::EventPtr event,
const mojo::Callback<void()>& callback) override;
// |mojo::InterfaceFactory<mojo::asset_bundle::AssetUnpacker>| implementation:
void Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<::keyboard::KeyboardService>) override;
mojo::ApplicationConnectorPtr connector_;
mojo::NativeViewportPtr viewport_;
mojo::Binding<NativeViewportEventDispatcher> dispatcher_binding_;
sky::SkyEnginePtr sky_engine_;
mojo::ServiceProviderImpl service_provider_;
mojo::NativeViewportEventDispatcherPtr key_event_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewMojo);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册