提交 f1b740c8 编写于 作者: A Adam Barth 提交者: GitHub

Remove editing.mojom (#3152)

Clients have been migrated to the TextInputPlugin.
上级 6aab8f2c
# 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/tools/bindings/mojom.gni")
group("editing") {
public_deps = [
":interfaces",
]
if (is_android || is_ios) {
public_deps += [ ":editing_lib" ]
}
}
mojom("interfaces") {
sources = [
"editing.mojom",
]
}
if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
android_library("editing_lib") {
java_files = [
"src/org/domokit/editing/KeyboardImpl.java",
"src/org/domokit/editing/KeyboardViewState.java",
"src/org/domokit/editing/InputConnectionAdaptor.java",
]
deps = [
"//base:base_java",
"//mojo/public/java:bindings",
"//mojo/public/java:system",
":interfaces_java",
]
}
}
if (is_ios) {
source_set("editing_lib") {
sources = [
"ios/keyboard_impl.h",
"ios/keyboard_impl.mm",
]
deps = [
"//base:base",
"//mojo/public/cpp/bindings:utility",
"//mojo/public/cpp/application",
":interfaces",
]
}
}
// 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.
[DartPackage="sky_services"]
module editing;
enum TextAffinity {
UPSTREAM,
DOWNSTREAM,
};
enum SubmitAction {
DONE,
};
enum KeyboardType {
TEXT,
NUMBER,
PHONE,
DATETIME,
};
struct KeyboardConfiguration {
KeyboardType type = KeyboardType.TEXT;
string? action_label;
};
struct EditingState {
string text;
int32 selection_base;
int32 selection_extent;
TextAffinity selection_affinity = TextAffinity.DOWNSTREAM;
bool selection_is_directional;
int32 composing_base;
int32 composing_extent;
};
interface KeyboardClient {
UpdateEditingState(EditingState state);
Submit(SubmitAction action);
};
[ServiceName="editing::Keyboard"]
interface Keyboard {
SetClient(KeyboardClient client, KeyboardConfiguration configuration);
ClearClient();
SetEditingState(EditingState state);
Show();
Hide();
};
struct ClipboardData {
string text;
};
[ServiceName="editing::Clipboard"]
interface Clipboard {
SetClipboardData(ClipboardData clip);
GetClipboardData(string format) => (ClipboardData? clip);
};
// 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 FLUTTER_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H_
#define FLUTTER_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H_
#include "base/macros.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "flutter/services/editing/editing.mojom.h"
#if __OBJC__
@class KeyboardClient;
#else // __OBJC__
class KeyboardClient;
#endif // __OBJC__
namespace sky {
namespace services {
namespace editing {
class KeyboardImpl : public ::editing::Keyboard {
public:
explicit KeyboardImpl(mojo::InterfaceRequest<::editing::Keyboard> request);
~KeyboardImpl() override;
void SetClient(mojo::InterfaceHandle<::editing::KeyboardClient> client,
::editing::KeyboardConfigurationPtr configuration) override;
void ClearClient() override;
void SetEditingState(::editing::EditingStatePtr state) override;
void Show() override;
void Hide() override;
private:
mojo::StrongBinding<::editing::Keyboard> binding_;
KeyboardClient* client_;
DISALLOW_COPY_AND_ASSIGN(KeyboardImpl);
};
} // namespace editing
} // namespace services
} // namespace sky
#endif /* defined(FLUTTER_SERVICES_KEYBOARD_IOS_KEYBOARD_SERVICE_IMPL_H__) */
// 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 "flutter/services/editing/ios/keyboard_impl.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include <UIKit/UIKit.h>
#include <unicode/utf16.h>
static inline UIKeyboardType ToUIKeyboardType(::editing::KeyboardType type) {
using Type = ::editing::KeyboardType;
switch (type) {
case Type::TEXT:
return UIKeyboardTypeDefault;
case Type::NUMBER:
return UIKeyboardTypeDecimalPad;
case Type::PHONE:
return UIKeyboardTypePhonePad;
default:
break;
}
return UIKeyboardTypeDefault;
}
@interface KeyboardClient : UIView<UIKeyInput>
- (void)setClient:(::editing::KeyboardClientPtr)client;
- (void)setEditingState:(::editing::EditingStatePtr)state;
- (void)show;
- (void)hide;
@end
@implementation KeyboardClient {
::editing::KeyboardClientPtr _client;
::editing::EditingStatePtr _state;
base::string16 _text;
}
@synthesize keyboardType = _keyboardType;
- (UITextAutocorrectionType)autocorrectionType {
return UITextAutocorrectionTypeNo;
}
- (void)setClient:(::editing::KeyboardClientPtr)client {
_client = client.Pass();
}
- (void)setEditingState:(::editing::EditingStatePtr)state {
_state = state.Pass();
_text = base::UTF8ToUTF16(_state->text.To<std::string>());
}
- (void)show {
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];
}
#pragma mark - UIResponder Overrides
- (BOOL)canBecomeFirstResponder {
return YES;
}
#pragma mark - UIKeyInput Overrides
// TODO(abarth): We should implement UITextInput for more features.
- (BOOL)hasText {
return YES;
}
- (void)insertText:(NSString*)text {
int start = std::max(0, std::min(_state->selection_base, _state->selection_extent));
int end = std::max(0, std::max(_state->selection_base, _state->selection_extent));
int len = end - start;
_text.replace(start, len, base::SysNSStringToUTF16(text));
int caret = start + text.length;
_state->selection_base = caret;
_state->selection_extent = caret;
_state->selection_affinity = ::editing::TextAffinity::UPSTREAM;
_state->selection_is_directional = false;
_state->composing_base = 0;
_state->composing_extent = 0;
_state->text = base::UTF16ToUTF8(_text);
_client->UpdateEditingState(_state.Clone());
}
- (void)deleteBackward {
int start = std::max(0, std::min(_state->selection_base, _state->selection_extent));
int end = std::max(0, std::max(_state->selection_base, _state->selection_extent));
int len = end - start;
if (len > 0) {
_text.erase(start, len);
} else if (start > 0) {
start -= 1;
len = 1;
if (start > 0 &&
UTF16_IS_LEAD(_text[start - 1]) &&
UTF16_IS_TRAIL(_text[start])) {
start -= 1;
len += 1;
}
_text.erase(start, len);
}
_state->selection_base = start;
_state->selection_extent = start;
_state->selection_affinity = ::editing::TextAffinity::DOWNSTREAM;
_state->selection_is_directional = false;
_state->composing_base = 0;
_state->composing_extent = 0;
_state->text = base::UTF16ToUTF8(_text);
_client->UpdateEditingState(_state.Clone());
}
@end
namespace sky {
namespace services {
namespace editing {
KeyboardImpl::KeyboardImpl(
mojo::InterfaceRequest<::editing::Keyboard> request)
: binding_(this, request.Pass()), client_([[KeyboardClient alloc] init]) {}
KeyboardImpl::~KeyboardImpl() {
[client_ hide];
[client_ release];
}
void KeyboardImpl::SetClient(mojo::InterfaceHandle<::editing::KeyboardClient> client,
::editing::KeyboardConfigurationPtr config) {
client_.keyboardType = ToUIKeyboardType(config->type);
[client_ setClient: ::editing::KeyboardClientPtr::Create(client.Pass())];
}
void KeyboardImpl::ClearClient() {
// TODO: implement this
}
void KeyboardImpl::SetEditingState(::editing::EditingStatePtr state) {
[client_ setEditingState:state.Pass()];
}
void KeyboardImpl::Show() {
[client_ show];
}
void KeyboardImpl::Hide() {
[client_ hide];
}
} // namespace editing
} // namespace services
} // namespace sky
// 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.
package org.domokit.editing;
import android.text.Editable;
import android.text.Selection;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.KeyEvent;
import android.view.View;
import org.chromium.mojom.editing.EditingState;
import org.chromium.mojom.editing.KeyboardClient;
import org.chromium.mojom.editing.SubmitAction;
/**
* An adaptor between InputConnection and KeyboardClient.
*/
public class InputConnectionAdaptor extends BaseInputConnection {
private KeyboardClient mClient;
private EditingState mOutgoingState;
public InputConnectionAdaptor(View view, KeyboardClient client) {
super(view, true);
assert client != null;
mClient = client;
mOutgoingState = new EditingState();
}
private void updateEditingState() {
Editable content = getEditable();
mOutgoingState.text = content.toString();
mOutgoingState.selectionBase = Selection.getSelectionStart(content);
mOutgoingState.selectionExtent = Selection.getSelectionEnd(content);
mOutgoingState.composingBase = BaseInputConnection.getComposingSpanStart(content);
mOutgoingState.composingExtent = BaseInputConnection.getComposingSpanEnd(content);
mClient.updateEditingState(mOutgoingState);
}
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
boolean result = super.commitText(text, newCursorPosition);
updateEditingState();
return result;
}
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
boolean result = super.deleteSurroundingText(beforeLength, afterLength);
updateEditingState();
return result;
}
@Override
public boolean setComposingRegion(int start, int end) {
boolean result = super.setComposingRegion(start, end);
updateEditingState();
return result;
}
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
boolean result = super.setComposingText(text, newCursorPosition);
updateEditingState();
return result;
}
@Override
public boolean setSelection(int start, int end) {
boolean result = super.setSelection(start, end);
updateEditingState();
return result;
}
@Override
public boolean sendKeyEvent(KeyEvent event) {
boolean result = super.sendKeyEvent(event);
if (event.getAction() == KeyEvent.ACTION_UP) {
// Weird special case. This method is (sometimes) called for the backspace key in 2
// situations:
// 1. There is no selection. In that case, we want to delete the previous character.
// 2. There is a selection. In that case, we want to delete the selection.
// event.getNumber() is 0, and commitText("", 1) will do what we want.
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL &&
mOutgoingState.selectionBase == mOutgoingState.selectionExtent) {
deleteSurroundingText(1, 0);
} else {
String text = event.getNumber() == 0 ? "" : String.valueOf(event.getNumber());
commitText(text, 1);
}
}
return result;
}
@Override
public boolean performEditorAction(int actionCode) {
mClient.submit(SubmitAction.DONE);
return true;
}
}
// 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.
package org.domokit.editing;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojom.editing.EditingState;
import org.chromium.mojom.editing.Keyboard;
import org.chromium.mojom.editing.KeyboardClient;
import org.chromium.mojom.editing.KeyboardConfiguration;
/**
* Android implementation of Keyboard.
*/
public class KeyboardImpl implements Keyboard {
private KeyboardViewState mViewState;
private Context mContext;
public KeyboardImpl(Context context, KeyboardViewState state) {
mContext = context;
mViewState = state;
}
@Override
public void close() {
mViewState.close();
}
@Override
public void onConnectionError(MojoException e) {}
@Override
public void setClient(KeyboardClient client, KeyboardConfiguration configuration) {
mViewState.setClient(client, configuration);
}
@Override
public void clearClient() {
mViewState.close();
}
@Override
public void setEditingState(EditingState state) {
mViewState.setEditingState(state);
}
@Override
public void show() {
InputMethodManager imm =
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mViewState.getView(), 0);
}
@Override
public void hide() {
InputMethodManager imm =
(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mViewState.getView().getApplicationWindowToken(), 0);
}
}
// 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.
package org.domokit.editing;
import android.content.Context;
import android.text.Editable;
import android.text.InputType;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.view.View;
import org.chromium.mojom.editing.EditingState;
import org.chromium.mojom.editing.KeyboardClient;
import org.chromium.mojom.editing.KeyboardConfiguration;
import org.chromium.mojom.editing.KeyboardType;
/**
* Per-View keyboard state.
*/
public class KeyboardViewState {
private View mView;
private KeyboardClient mClient;
private KeyboardConfiguration mConfiguration;
private EditingState mIncomingState;
public KeyboardViewState(View view) {
mView = view;
mClient = null;
}
public void setClient(KeyboardClient client, KeyboardConfiguration configuration) {
if (mClient != null)
mClient.close();
mIncomingState = null;
mClient = client;
mConfiguration = configuration;
InputMethodManager imm =
(InputMethodManager) mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mView);
}
public void setEditingState(EditingState state) {
mIncomingState = state;
InputMethodManager imm =
(InputMethodManager) mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mView);
}
private static int inputTypeFromKeyboardType(int keyboardType) {
if (keyboardType == KeyboardType.DATETIME)
return InputType.TYPE_CLASS_DATETIME;
if (keyboardType == KeyboardType.NUMBER)
return InputType.TYPE_CLASS_NUMBER;
if (keyboardType == KeyboardType.PHONE)
return InputType.TYPE_CLASS_PHONE;
return InputType.TYPE_CLASS_TEXT;
}
public InputConnection createInputConnection(EditorInfo outAttrs) {
if (mClient == null)
return null;
outAttrs.inputType = inputTypeFromKeyboardType(mConfiguration.type);
outAttrs.actionLabel = mConfiguration.actionLabel;
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN;
InputConnectionAdaptor connection = new InputConnectionAdaptor(mView, mClient);
if (mIncomingState != null) {
outAttrs.initialSelStart = mIncomingState.selectionBase;
outAttrs.initialSelEnd = mIncomingState.selectionExtent;
connection.getEditable().append(mIncomingState.text);
connection.setSelection(mIncomingState.selectionBase,
mIncomingState.selectionExtent);
connection.setComposingRegion(mIncomingState.composingBase,
mIncomingState.composingExtent);
} else {
outAttrs.initialSelStart = 0;
outAttrs.initialSelEnd = 0;
}
return connection;
}
public View getView() {
return mView;
}
public void close() {
if (mClient == null)
return;
mClient.close();
mClient = null;
}
}
......@@ -6,7 +6,6 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"input_event.mojom",
"sky_engine.mojom",
]
......
// 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.
[DartPackage="sky_services"]
module sky;
enum EventType {
UNKNOWN,
BACK,
KEY_PRESSED,
KEY_RELEASED,
};
struct KeyData {
int32 key_code;
int32 flags;
int32 scan_code;
int32 meta_state;
};
// TODO(abarth): Should we have a malloc-free way of creating an input event
// message? What we have now could stress out the Android Java GC.
struct InputEvent {
EventType type;
int64 time_stamp;
KeyData? key_data;
};
......@@ -4,7 +4,6 @@
module sky;
import "flutter/services/engine/input_event.mojom";
import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/public/interfaces/application/shell.mojom";
import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom";
......
......@@ -84,8 +84,6 @@ android_library("java") {
deps = [
"//base:base_java",
"//flutter/services/editing:editing_lib",
"//flutter/services/editing:interfaces_java",
"//flutter/services/engine:interfaces_java",
"//flutter/services/platform:interfaces_java",
"//flutter/services/vsync:vsync_lib",
......
......@@ -42,7 +42,6 @@ import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojo.system.Pair;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.mojom.editing.Keyboard;
import org.chromium.mojom.flutter.platform.ApplicationMessages;
import org.chromium.mojom.mojo.ServiceProvider;
import org.chromium.mojom.sky.AppLifecycleState;
......@@ -63,9 +62,6 @@ import io.flutter.plugin.common.ActivityLifecycleListener;
import io.flutter.plugin.editing.TextInputPlugin;
import io.flutter.plugin.platform.PlatformPlugin;
import org.domokit.editing.KeyboardImpl;
import org.domokit.editing.KeyboardViewState;
/**
* An Android view containing a Flutter app.
*/
......@@ -90,7 +86,6 @@ public class FlutterView extends SurfaceView
private HashMap<String, OnMessageListenerAsync> mAsyncOnMessageListeners;
private final SurfaceHolder.Callback mSurfaceCallback;
private final ViewportMetrics mMetrics;
private final KeyboardViewState mKeyboardState;
private final AccessibilityManager mAccessibilityManager;
private BroadcastReceiver discoveryReceiver;
private List<ActivityLifecycleListener> mActivityLifecycleListeners;
......@@ -139,8 +134,6 @@ public class FlutterView extends SurfaceView
};
getHolder().addCallback(mSurfaceCallback);
mKeyboardState = new KeyboardViewState(this);
Core core = CoreImpl.getInstance();
mPlatformServiceProvider = new ServiceProviderImpl(core, this, ServiceRegistry.SHARED);
......@@ -273,10 +266,7 @@ public class FlutterView extends SurfaceView
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection connection = mKeyboardState.createInputConnection(outAttrs);
if (connection == null)
connection = mTextInputPlugin.createInputConnection(this, outAttrs);
return connection;
return mTextInputPlugin.createInputConnection(this, outAttrs);
}
// Must match the PointerChange enum in pointer.dart.
......@@ -463,13 +453,6 @@ public class FlutterView extends SurfaceView
}
private void configureLocalServices(ServiceRegistry registry) {
registry.register(Keyboard.MANAGER.getName(), new ServiceFactory() {
@Override
public Binding connectToService(FlutterView view, Core core, MessagePipeHandle pipe) {
return Keyboard.MANAGER.bind(new KeyboardImpl(view.getContext(), mKeyboardState), pipe);
}
});
registry.register(ApplicationMessages.MANAGER.getName(), new ServiceFactory() {
@Override
public Binding connectToService(FlutterView view, Core core, MessagePipeHandle pipe) {
......
......@@ -21,7 +21,6 @@ source_set("common") {
"//base:i18n",
"//dart/runtime:libdart",
"//flutter/runtime",
"//flutter/services/editing",
"//flutter/services/engine:interfaces",
"//flutter/services/platform",
"//flutter/services/vsync",
......
......@@ -25,13 +25,6 @@ void ViewServiceProvider::ConnectToService(
std::move(client_handle)));
return;
}
#if TARGET_OS_IPHONE
if (service_name == ::editing::Keyboard::Name_) {
new sky::services::editing::KeyboardImpl(
mojo::InterfaceRequest<::editing::Keyboard>(std::move(client_handle)));
return;
}
#endif
}
} // namespace shell
......@@ -13,10 +13,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#if TARGET_OS_IPHONE
#include "flutter/services/editing/ios/keyboard_impl.h"
#endif
namespace shell {
typedef std::function<void(
......
......@@ -52,7 +52,6 @@ shared_library("flutter_framework_dylib") {
"//base:base",
"//dart/runtime:libdart",
"//flutter/lib/ui",
"//flutter/services/editing",
"//flutter/services/engine:interfaces",
"//flutter/services/platform",
"//flutter/services/vsync",
......
/// 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 'package:sky_services/editing/editing.mojom.dart';
export 'package:sky_services/editing/editing.mojom.dart';
/// 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 'package:sky_services/sky/input_event.mojom.dart';
export 'package:sky_services/sky/input_event.mojom.dart';
......@@ -23,7 +23,6 @@ dart_pkg("sky_services") {
deps = [
":copy_sky_services_license",
"//flutter/services/editing:interfaces",
"//flutter/services/platform:interfaces",
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册