mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Keyboard service implementation for iOS
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# 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.
|
||||
|
||||
if (is_ios) {
|
||||
source_set("keyboard") {
|
||||
sources = [
|
||||
"ios/keyboard_service_impl.h",
|
||||
"ios/keyboard_service_impl.mm",
|
||||
]
|
||||
deps = [
|
||||
"//base:base",
|
||||
"//mojo/common",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/services/keyboard/public/interfaces",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
group("keyboard") {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H_
|
||||
#define SKY_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "mojo/public/cpp/application/interface_factory.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "mojo/services/keyboard/public/interfaces/keyboard.mojom.h"
|
||||
|
||||
#if __OBJC__
|
||||
@class KeyboardClient;
|
||||
#else // __OBJC__
|
||||
class KeyboardClient;
|
||||
#endif // __OBJC__
|
||||
|
||||
namespace sky {
|
||||
namespace services {
|
||||
namespace keyboard {
|
||||
|
||||
class KeyboardServiceImpl : public ::keyboard::KeyboardService {
|
||||
public:
|
||||
explicit KeyboardServiceImpl(
|
||||
mojo::InterfaceRequest<::keyboard::KeyboardService> request);
|
||||
virtual ~KeyboardServiceImpl() override;
|
||||
virtual void Show(::keyboard::KeyboardClientPtr client,
|
||||
::keyboard::KeyboardType type) override;
|
||||
virtual void ShowByRequest() override;
|
||||
virtual void Hide() override;
|
||||
|
||||
private:
|
||||
mojo::StrongBinding<::keyboard::KeyboardService> binding_;
|
||||
KeyboardClient* client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl);
|
||||
};
|
||||
|
||||
class KeyboardServiceFactory
|
||||
: public mojo::InterfaceFactory<::keyboard::KeyboardService> {
|
||||
public:
|
||||
void Create(
|
||||
mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<::keyboard::KeyboardService> request) override;
|
||||
};
|
||||
|
||||
} // namespace keyboard
|
||||
} // namespace services
|
||||
} // namespace sky
|
||||
|
||||
#endif /* defined(SKY_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H__) *
|
||||
@@ -0,0 +1,117 @@
|
||||
// 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 "sky/services/keyboard/ios/keyboard_service_impl.h"
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
static inline UIKeyboardType ToUIKeyboardType(::keyboard::KeyboardType type) {
|
||||
switch (type) {
|
||||
case ::keyboard::KEYBOARD_TYPE_TEXT:
|
||||
return UIKeyboardTypeDefault;
|
||||
case ::keyboard::KEYBOARD_TYPE_NUMBER:
|
||||
return UIKeyboardTypeDecimalPad;
|
||||
case ::keyboard::KEYBOARD_TYPE_PHONE:
|
||||
return UIKeyboardTypePhonePad;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return UIKeyboardTypeDefault;
|
||||
}
|
||||
|
||||
@interface KeyboardClient : UIView<UIKeyInput>
|
||||
|
||||
- (void)show:(::keyboard::KeyboardClientPtr)client;
|
||||
- (void)hide;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KeyboardClient {
|
||||
::keyboard::KeyboardClientPtr _client;
|
||||
}
|
||||
|
||||
@synthesize keyboardType = _keyboardType;
|
||||
|
||||
- (UITextAutocorrectionType)autocorrectionType {
|
||||
return UITextAutocorrectionTypeNo;
|
||||
}
|
||||
|
||||
- (void)show:(::keyboard::KeyboardClientPtr)client {
|
||||
_client = client.Pass();
|
||||
|
||||
NSAssert([UIApplication sharedApplication].keyWindow != nullptr,
|
||||
@"The application must have a key window since the keyboard client "
|
||||
@"must be part of the responder chain to function");
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:self];
|
||||
[self becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)hide {
|
||||
[self resignFirstResponder];
|
||||
[self removeFromSuperview];
|
||||
_client = nullptr;
|
||||
}
|
||||
|
||||
#pragma mark - UIResponder Overrides
|
||||
|
||||
- (BOOL)canBecomeFirstResponder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - UIKey Input Overrides
|
||||
|
||||
- (BOOL)hasText {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)insertText:(NSString*)text {
|
||||
if (_client == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
_client->CommitText(text.UTF8String, text.length);
|
||||
}
|
||||
|
||||
- (void)deleteBackward {
|
||||
if (_client == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
_client->DeleteSurroundingText(1, 0);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace sky {
|
||||
namespace services {
|
||||
namespace keyboard {
|
||||
|
||||
KeyboardServiceImpl::KeyboardServiceImpl(
|
||||
mojo::InterfaceRequest<::keyboard::KeyboardService> request)
|
||||
: binding_(this, request.Pass()), client_([[KeyboardClient alloc] init]) {}
|
||||
|
||||
KeyboardServiceImpl::~KeyboardServiceImpl() {
|
||||
[client_ release];
|
||||
}
|
||||
|
||||
void KeyboardServiceImpl::Show(::keyboard::KeyboardClientPtr client,
|
||||
::keyboard::KeyboardType type) {
|
||||
client_.keyboardType = ToUIKeyboardType(type);
|
||||
[client_ show:client.Pass()];
|
||||
}
|
||||
|
||||
void KeyboardServiceImpl::ShowByRequest() {}
|
||||
|
||||
void KeyboardServiceImpl::Hide() {
|
||||
[client_ hide];
|
||||
}
|
||||
|
||||
void KeyboardServiceFactory::Create(
|
||||
mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<::keyboard::KeyboardService> request) {
|
||||
new KeyboardServiceImpl(request.Pass());
|
||||
}
|
||||
|
||||
} // namespace keyboard
|
||||
} // namespace services
|
||||
} // namespace sky
|
||||
@@ -199,6 +199,7 @@ if (is_android) {
|
||||
deps = common_deps + [
|
||||
":common",
|
||||
"//sky/services/ns_net",
|
||||
"//sky/services/keyboard",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
#include "sky/engine/wtf/Assertions.h"
|
||||
#include "sky/services/ns_net/network_service_impl.h"
|
||||
#include "sky/services/keyboard/ios/keyboard_service_impl.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#if !TARGET_OS_IPHONE
|
||||
#include "sky/shell/testing/test_runner.h"
|
||||
@@ -21,18 +22,22 @@ namespace shell {
|
||||
class PlatformServiceProvider : public mojo::ServiceProvider {
|
||||
public:
|
||||
PlatformServiceProvider(mojo::InterfaceRequest<mojo::ServiceProvider> request)
|
||||
: binding_(this, request.Pass()) {}
|
||||
: binding_(this, request.Pass()) {}
|
||||
|
||||
void ConnectToService(const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) override {
|
||||
if (service_name == mojo::NetworkService::Name_) {
|
||||
network_.Create(nullptr,
|
||||
mojo::MakeRequest<mojo::NetworkService>(client_handle.Pass()));
|
||||
network_.Create(nullptr, mojo::MakeRequest<mojo::NetworkService>(
|
||||
client_handle.Pass()));
|
||||
}
|
||||
if (service_name == ::keyboard::KeyboardService::Name_) {
|
||||
keyboard_.Create(nullptr, mojo::MakeRequest<::keyboard::KeyboardService>(
|
||||
client_handle.Pass()));
|
||||
}
|
||||
#if !TARGET_OS_IPHONE
|
||||
if (service_name == TestHarness::Name_) {
|
||||
TestRunner::Shared().Create(nullptr,
|
||||
mojo::MakeRequest<TestHarness>(client_handle.Pass()));
|
||||
TestRunner::Shared().Create(
|
||||
nullptr, mojo::MakeRequest<TestHarness>(client_handle.Pass()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -40,6 +45,7 @@ class PlatformServiceProvider : public mojo::ServiceProvider {
|
||||
private:
|
||||
mojo::StrongBinding<mojo::ServiceProvider> binding_;
|
||||
mojo::NetworkServiceFactory network_;
|
||||
sky::services::keyboard::KeyboardServiceFactory keyboard_;
|
||||
};
|
||||
|
||||
static void CreatePlatformServiceProvider(
|
||||
|
||||
Reference in New Issue
Block a user