forked from firka/flutter
fix editable placement in a11y mode (flutter/engine#14581)
This commit is contained in:
@@ -4,6 +4,70 @@
|
||||
|
||||
part of engine;
|
||||
|
||||
/// Text editing used by accesibility mode.
|
||||
///
|
||||
/// [SemanticsTextEditingStrategy] assumes the caller will own the creation,
|
||||
/// insertion and disposal of the DOM element. Due to this
|
||||
/// [initializeElementPlacement], [initializeTextEditing] and
|
||||
/// [disable] strategies are handled differently.
|
||||
///
|
||||
/// This class is still responsible for hooking up the DOM element with the
|
||||
/// [HybridTextEditing] instance so that changes are communicated to Flutter.
|
||||
class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
/// Creates a [SemanticsTextEditingStrategy] that eagerly instantiates
|
||||
/// [domElement] so the caller can insert it before calling
|
||||
/// [SemanticsTextEditingStrategy.enable].
|
||||
SemanticsTextEditingStrategy(
|
||||
HybridTextEditing owner, html.HtmlElement domElement)
|
||||
: super(owner) {
|
||||
// Make sure the DOM element is of a type that we support for text editing.
|
||||
// TODO(yjbanov): move into initializer list when https://github.com/dart-lang/sdk/issues/37881 is fixed.
|
||||
assert((domElement is html.InputElement) ||
|
||||
(domElement is html.TextAreaElement));
|
||||
super.domElement = domElement;
|
||||
}
|
||||
|
||||
@override
|
||||
void disable() {
|
||||
// We don't want to remove the DOM element because the caller is responsible
|
||||
// for that.
|
||||
//
|
||||
// Remove focus from the editable element to cause the keyboard to hide.
|
||||
// Otherwise, the keyboard stays on screen even when the user navigates to
|
||||
// a different screen (e.g. by hitting the "back" button).
|
||||
domElement.blur();
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeElementPlacement() {
|
||||
// Element placement is done by [TextField].
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeTextEditing(InputConfiguration inputConfig,
|
||||
{_OnChangeCallback onChange, _OnActionCallback onAction}) {
|
||||
// In accesibilty mode, the user of this class is supposed to insert the
|
||||
// [domElement] on their own. Let's make sure they did.
|
||||
assert(domElement != null);
|
||||
assert(html.document.body.contains(domElement));
|
||||
|
||||
isEnabled = true;
|
||||
_inputConfiguration = inputConfig;
|
||||
_onChange = onChange;
|
||||
_onAction = onAction;
|
||||
|
||||
domElement.focus();
|
||||
}
|
||||
|
||||
@override
|
||||
void setEditingState(EditingState editingState) {
|
||||
super.setEditingState(editingState);
|
||||
|
||||
// Refocus after setting editing state.
|
||||
domElement.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/// Manages semantics objects that represent editable text fields.
|
||||
///
|
||||
/// This role is implemented via a content-editable HTML element. This role does
|
||||
@@ -19,15 +83,15 @@ class TextField extends RoleManager {
|
||||
semanticsObject.hasFlag(ui.SemanticsFlag.isMultiline)
|
||||
? html.TextAreaElement()
|
||||
: html.InputElement();
|
||||
persistentTextEditingElement = PersistentTextEditingElement(
|
||||
textEditingElement = SemanticsTextEditingStrategy(
|
||||
textEditing,
|
||||
editableDomElement,
|
||||
);
|
||||
_setupDomElement();
|
||||
}
|
||||
|
||||
PersistentTextEditingElement persistentTextEditingElement;
|
||||
html.Element get _textFieldElement => persistentTextEditingElement.domElement;
|
||||
SemanticsTextEditingStrategy textEditingElement;
|
||||
html.Element get _textFieldElement => textEditingElement.domElement;
|
||||
|
||||
void _setupDomElement() {
|
||||
// On iOS, even though the semantic text field is transparent, the cursor
|
||||
@@ -61,6 +125,7 @@ class TextField extends RoleManager {
|
||||
switch (browserEngine) {
|
||||
case BrowserEngine.blink:
|
||||
case BrowserEngine.edge:
|
||||
case BrowserEngine.ie11:
|
||||
case BrowserEngine.firefox:
|
||||
case BrowserEngine.ie11:
|
||||
case BrowserEngine.unknown:
|
||||
@@ -82,7 +147,7 @@ class TextField extends RoleManager {
|
||||
return;
|
||||
}
|
||||
|
||||
textEditing.useCustomEditableElement(persistentTextEditingElement);
|
||||
textEditing.useCustomEditableElement(textEditingElement);
|
||||
ui.window
|
||||
.onSemanticsAction(semanticsObject.id, ui.SemanticsAction.tap, null);
|
||||
});
|
||||
@@ -98,7 +163,7 @@ class TextField extends RoleManager {
|
||||
num lastTouchStartOffsetY;
|
||||
|
||||
_textFieldElement.addEventListener('touchstart', (html.Event event) {
|
||||
textEditing.useCustomEditableElement(persistentTextEditingElement);
|
||||
textEditing.useCustomEditableElement(textEditingElement);
|
||||
final html.TouchEvent touchEvent = event;
|
||||
lastTouchStartOffsetX = touchEvent.changedTouches.last.client.x;
|
||||
lastTouchStartOffsetY = touchEvent.changedTouches.last.client.y;
|
||||
|
||||
@@ -71,7 +71,7 @@ class EditingState {
|
||||
/// Flutter Framework can send the [selectionBase] and [selectionExtent] as
|
||||
/// -1, if so 0 assigned to the [baseOffset] and [extentOffset]. -1 is not a
|
||||
/// valid selection range for input DOM elements.
|
||||
factory EditingState.fromFlutter(Map<String, dynamic> flutterEditingState) {
|
||||
factory EditingState.fromFrameworkMessage(Map<String, dynamic> flutterEditingState) {
|
||||
final int selectionBase = flutterEditingState['selectionBase'];
|
||||
final int selectionExtent = flutterEditingState['selectionExtent'];
|
||||
final String text = flutterEditingState['text'];
|
||||
@@ -105,7 +105,7 @@ class EditingState {
|
||||
}
|
||||
}
|
||||
|
||||
/// The counterpart of [EditingState.fromFlutter]. It generates a Map that
|
||||
/// The counterpart of [EditingState.fromFrameworkMessage]. It generates a Map that
|
||||
/// can be sent to Flutter.
|
||||
// TODO(mdebbar): Should we get `selectionAffinity` and other properties from flutter's editing state?
|
||||
Map<String, dynamic> toFlutter() => <String, dynamic>{
|
||||
@@ -183,7 +183,7 @@ class InputConfiguration {
|
||||
@required this.autocorrect,
|
||||
});
|
||||
|
||||
InputConfiguration.fromFlutter(Map<String, dynamic> flutterInputConfiguration)
|
||||
InputConfiguration.fromFrameworkMessage(Map<String, dynamic> flutterInputConfiguration)
|
||||
: inputType = EngineInputType.fromName(
|
||||
flutterInputConfiguration['inputType']['name']),
|
||||
inputAction = flutterInputConfiguration['inputAction'],
|
||||
@@ -212,12 +212,10 @@ class InputConfiguration {
|
||||
typedef _OnChangeCallback = void Function(EditingState editingState);
|
||||
typedef _OnActionCallback = void Function(String inputAction);
|
||||
|
||||
/// Interface defining the template for text editing strategies.
|
||||
/// Provides HTML DOM functionality for editable text.
|
||||
///
|
||||
/// The algorithms will be picked in the runtime depending on the concrete
|
||||
/// class implementing the interface.
|
||||
///
|
||||
/// These algorithms is expected to differ by operating system and/or browser.
|
||||
/// A concrete implementation is picked at runtime based on the current
|
||||
/// operating system, web browser, and accessibility mode.
|
||||
abstract class TextEditingStrategy {
|
||||
void initializeTextEditing(
|
||||
InputConfiguration inputConfig, {
|
||||
@@ -225,14 +223,14 @@ abstract class TextEditingStrategy {
|
||||
@required _OnActionCallback onAction,
|
||||
});
|
||||
|
||||
/// Place the DOM element to its initial position.
|
||||
/// Sets the initial placement of the DOM element on the UI.
|
||||
///
|
||||
/// It will be located exactly in the same place with the editable widgets,
|
||||
/// however it's contents and cursor will be invisible.
|
||||
/// The element must be located exactly in the same place with the editable
|
||||
/// widget. However, its contents and cursor will be invisible.
|
||||
///
|
||||
/// Users can interact with the element and use the functionalities of the
|
||||
/// right-click menu. Such as copy,paste, cut, select, translate...
|
||||
void initializeElementPosition();
|
||||
/// Users can interact with the element and use the functionality of the
|
||||
/// right-click menu, such as copy, paste, cut, select, translate, etc.
|
||||
void initializeElementPlacement();
|
||||
|
||||
/// Register event listeners to the DOM element.
|
||||
///
|
||||
@@ -243,7 +241,7 @@ abstract class TextEditingStrategy {
|
||||
///
|
||||
/// The position will be updated everytime Flutter Framework sends
|
||||
/// 'TextInput.setEditableSizeAndTransform' message.
|
||||
void updateElementPosition(_GeometricInfo geometricInfo);
|
||||
void updateElementPlacement(EditableTextGeometry geometry);
|
||||
|
||||
/// Set editing state of the element.
|
||||
///
|
||||
@@ -253,7 +251,7 @@ abstract class TextEditingStrategy {
|
||||
void setEditingState(EditingState editingState);
|
||||
|
||||
/// Set style to the native DOM element used for text editing.
|
||||
void updateElementStyle(_EditingStyle style);
|
||||
void updateElementStyle(EditableTextStyle style);
|
||||
|
||||
/// Disables the element so it's no longer used for text editing.
|
||||
///
|
||||
@@ -261,11 +259,27 @@ abstract class TextEditingStrategy {
|
||||
void disable();
|
||||
}
|
||||
|
||||
/// A [TextEditingStrategy] that places its [domElement] assuming no
|
||||
/// prior transform or sizing is applied to it.
|
||||
///
|
||||
/// This implementation is used by text editables when semantics is not
|
||||
/// enabled. With semantics enabled the placement is provided by the semantics
|
||||
/// tree.
|
||||
class GloballyPositionedTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
GloballyPositionedTextEditingStrategy(HybridTextEditing owner) : super(owner);
|
||||
|
||||
@override
|
||||
void placeElement() {
|
||||
super.placeElement();
|
||||
_geometry?.applyToDomElement(domElement);
|
||||
}
|
||||
}
|
||||
|
||||
/// Class implementing the default editing strategies for text editing.
|
||||
///
|
||||
/// This class uses a DOM element to provide text editing capabilities.
|
||||
///
|
||||
/// The backing DOM element could be one of:
|
||||
/// The backing DOM element could be one of:
|
||||
///
|
||||
/// 1. `<input>`.
|
||||
/// 2. `<textarea>`.
|
||||
@@ -274,12 +288,15 @@ abstract class TextEditingStrategy {
|
||||
/// This class includes all the default behaviour for an editing element as
|
||||
/// well as the common properties such as [domElement].
|
||||
///
|
||||
/// Strategies written for different formfactor's/browser's should extend this
|
||||
/// class instead of extending the interface [TextEditingStrategy].
|
||||
/// Strategies written for different form factors and browsers should extend
|
||||
/// this class instead of extending the interface [TextEditingStrategy]. In
|
||||
/// particular, a concrete implementation is expected to override
|
||||
/// [placeElement] that places the DOM element accordingly. The default
|
||||
/// implementation of [placeElement] does not position the element.
|
||||
///
|
||||
/// Unless a formfactor/browser requires specific implementation for a specific
|
||||
/// strategy the methods in this class should be used.
|
||||
class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
final HybridTextEditing owner;
|
||||
|
||||
DefaultTextEditingStrategy(this.owner);
|
||||
@@ -292,10 +309,10 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
EditingState _lastEditingState;
|
||||
|
||||
/// Styles associated with the editable text.
|
||||
_EditingStyle _style;
|
||||
EditableTextStyle _style;
|
||||
|
||||
/// Size and transform of the editable text on the page.
|
||||
_GeometricInfo _geometricInfo;
|
||||
EditableTextGeometry _geometry;
|
||||
|
||||
_OnChangeCallback _onChange;
|
||||
_OnActionCallback _onAction;
|
||||
@@ -321,7 +338,7 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
|
||||
_setStaticStyleAttributes(domElement);
|
||||
_style?.applyToDomElement(domElement);
|
||||
initializeElementPosition();
|
||||
initializeElementPlacement();
|
||||
domRenderer.glassPaneElement.append(domElement);
|
||||
|
||||
isEnabled = true;
|
||||
@@ -331,8 +348,8 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeElementPosition() {
|
||||
positionElement();
|
||||
void initializeElementPlacement() {
|
||||
placeElement();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -373,16 +390,16 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
}
|
||||
|
||||
@override
|
||||
void updateElementPosition(_GeometricInfo geometricInfo) {
|
||||
_geometricInfo = geometricInfo;
|
||||
void updateElementPlacement(EditableTextGeometry geometry) {
|
||||
_geometry = geometry;
|
||||
if (isEnabled) {
|
||||
positionElement();
|
||||
placeElement();
|
||||
}
|
||||
}
|
||||
|
||||
@mustCallSuper
|
||||
@override
|
||||
void updateElementStyle(_EditingStyle style) {
|
||||
void updateElementStyle(EditableTextStyle style) {
|
||||
_style = style;
|
||||
if (isEnabled) {
|
||||
_style.applyToDomElement(domElement);
|
||||
@@ -396,7 +413,7 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
isEnabled = false;
|
||||
_lastEditingState = null;
|
||||
_style = null;
|
||||
_geometricInfo = null;
|
||||
_geometry = null;
|
||||
|
||||
for (int i = 0; i < _subscriptions.length; i++) {
|
||||
_subscriptions[i].cancel();
|
||||
@@ -416,8 +433,10 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
_lastEditingState.applyToDomElement(domElement);
|
||||
}
|
||||
|
||||
void positionElement() {
|
||||
_geometricInfo?.applyToDomElement(domElement);
|
||||
/// Puts the DOM element used for text editing on the UI at the appropriate
|
||||
/// location and sizes it accordingly.
|
||||
@mustCallSuper
|
||||
void placeElement() {
|
||||
domElement.focus();
|
||||
}
|
||||
|
||||
@@ -476,7 +495,7 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
/// In iOS, the virtual keyboard might shifts the screen up to make input
|
||||
/// visible depending on the location of the focused input element.
|
||||
///
|
||||
/// Due to this [initializeElementPosition] and [updateElementPosition]
|
||||
/// Due to this [initializeElementPlacement] and [updateElementPlacement]
|
||||
/// strategies are different.
|
||||
///
|
||||
/// [disable] is also different since the [_positionInputElementTimer]
|
||||
@@ -484,7 +503,7 @@ class DefaultTextEditingStrategy implements TextEditingStrategy {
|
||||
///
|
||||
/// inputmodeAttribute needs to be set for mobile devices. Due to this
|
||||
/// [initializeTextEditing] is different.
|
||||
class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
class IOSTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
|
||||
IOSTextEditingStrategy(HybridTextEditing owner) : super(owner);
|
||||
|
||||
/// Timer that times when to set the location of the input text.
|
||||
@@ -500,7 +519,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
/// in iOS is set to correct place, 100ms after focus. We use this timer for
|
||||
/// timing this delay.
|
||||
Timer _positionInputElementTimer;
|
||||
static const Duration _delayBeforePositioning =
|
||||
static const Duration _delayBeforePlacement =
|
||||
const Duration(milliseconds: 100);
|
||||
|
||||
/// Whether or not the input element can be positioned at this point in time.
|
||||
@@ -512,7 +531,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
///
|
||||
/// See:
|
||||
///
|
||||
/// * [_delayBeforePositioning] which controls how long to wait before
|
||||
/// * [_delayBeforePlacement] which controls how long to wait before
|
||||
/// positioning the input field.
|
||||
bool _canPosition = true;
|
||||
|
||||
@@ -528,7 +547,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeElementPosition() {
|
||||
void initializeElementPlacement() {
|
||||
/// Position the element outside of the page before focusing on it. This is
|
||||
/// useful for not triggering a scroll when iOS virtual keyboard is
|
||||
/// coming up.
|
||||
@@ -549,7 +568,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
// Position the DOM element after it is focused.
|
||||
_subscriptions.add(domElement.onFocus.listen((_) {
|
||||
// Cancel previous timer if exists.
|
||||
_schedulePositioning();
|
||||
_schedulePlacement();
|
||||
}));
|
||||
|
||||
_addTapListener();
|
||||
@@ -565,10 +584,10 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
}
|
||||
|
||||
@override
|
||||
void updateElementPosition(_GeometricInfo geometricInfo) {
|
||||
_geometricInfo = geometricInfo;
|
||||
void updateElementPlacement(EditableTextGeometry geometry) {
|
||||
_geometry = geometry;
|
||||
if (isEnabled && _canPosition) {
|
||||
positionElement();
|
||||
placeElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +614,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
/// In order to prevent this shift, on a `click` event the position of the
|
||||
/// element is again set somewhere outside of the page and
|
||||
/// [_positionInputElementTimer] timer is restarted. The element will be
|
||||
/// placed to its correct position after [_delayBeforePositioning].
|
||||
/// placed to its correct position after [_delayBeforePlacement].
|
||||
void _addTapListener() {
|
||||
_subscriptions.add(domElement.onClick.listen((_) {
|
||||
// Check if the element is already positioned. If not this does not fall
|
||||
@@ -603,19 +622,19 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
// via keyboard` journey.
|
||||
if (_canPosition) {
|
||||
// Re-place the element somewhere outside of the screen.
|
||||
initializeElementPosition();
|
||||
initializeElementPlacement();
|
||||
|
||||
// Re-configure the timer to place the element.
|
||||
_schedulePositioning();
|
||||
_schedulePlacement();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void _schedulePositioning() {
|
||||
void _schedulePlacement() {
|
||||
_positionInputElementTimer?.cancel();
|
||||
_positionInputElementTimer = Timer(_delayBeforePositioning, () {
|
||||
_positionInputElementTimer = Timer(_delayBeforePlacement, () {
|
||||
_canPosition = true;
|
||||
positionElement();
|
||||
placeElement();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -627,7 +646,7 @@ class IOSTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
///
|
||||
/// Keyboard acts differently than other devices. [addEventHandlers] handles
|
||||
/// this case as an extra.
|
||||
class AndroidTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
class AndroidTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
|
||||
AndroidTextEditingStrategy(HybridTextEditing owner) : super(owner);
|
||||
|
||||
@override
|
||||
@@ -668,7 +687,7 @@ class AndroidTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
///
|
||||
/// Selections are different in Firefox. [addEventHandlers] strategy is
|
||||
/// impelemented diefferently in Firefox.
|
||||
class FirefoxTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
class FirefoxTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
|
||||
FirefoxTextEditingStrategy(HybridTextEditing owner) : super(owner);
|
||||
|
||||
@override
|
||||
@@ -724,67 +743,96 @@ class FirefoxTextEditingStrategy extends DefaultTextEditingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
/// Text editing used by accesibilty mode.
|
||||
/// Translates the message-based communication between the framework and the
|
||||
/// engine [implementation].
|
||||
///
|
||||
/// [PersistentTextEditingElement] assumes the caller will own the creation,
|
||||
/// insertion and disposal of the DOM element. Due to this
|
||||
/// [initializeElementPosition], [initializeTextEditing] and
|
||||
/// [disable] strategies are handled differently.
|
||||
///
|
||||
/// This class is still responsible for hooking up the DOM element with the
|
||||
/// [HybridTextEditing] instance so that changes are communicated to Flutter.
|
||||
class PersistentTextEditingElement extends DefaultTextEditingStrategy {
|
||||
/// Creates a [PersistentTextEditingElement] that eagerly instantiates
|
||||
/// [domElement] so the caller can insert it before calling
|
||||
/// [PersistentTextEditingElement.enable].
|
||||
PersistentTextEditingElement(
|
||||
HybridTextEditing owner, html.HtmlElement domElement)
|
||||
: super(owner) {
|
||||
// Make sure the DOM element is of a type that we support for text editing.
|
||||
// TODO(yjbanov): move into initializer list when https://github.com/dart-lang/sdk/issues/37881 is fixed.
|
||||
assert((domElement is html.InputElement) ||
|
||||
(domElement is html.TextAreaElement));
|
||||
super.domElement = domElement;
|
||||
/// This class is meant to be used as a singleton.
|
||||
class TextEditingChannel {
|
||||
TextEditingChannel(this.implementation);
|
||||
|
||||
/// Supplies the implementation that responds to the channel messages.
|
||||
final HybridTextEditing implementation;
|
||||
|
||||
/// Handles "flutter/textinput" platform messages received from the framework.
|
||||
void handleTextInput(ByteData data) {
|
||||
final MethodCall call = const JSONMethodCodec().decodeMethodCall(data);
|
||||
switch (call.method) {
|
||||
case 'TextInput.setClient':
|
||||
implementation.setClient(
|
||||
call.arguments[0],
|
||||
InputConfiguration.fromFrameworkMessage(call.arguments[1]),
|
||||
);
|
||||
break;
|
||||
|
||||
case 'TextInput.setEditingState':
|
||||
implementation.setEditingState(EditingState.fromFrameworkMessage(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.show':
|
||||
implementation.show();
|
||||
break;
|
||||
|
||||
case 'TextInput.setEditableSizeAndTransform':
|
||||
implementation.setEditableSizeAndTransform(EditableTextGeometry.fromFrameworkMessage(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.setStyle':
|
||||
implementation.setStyle(EditableTextStyle.fromFrameworkMessage(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.clearClient':
|
||||
implementation.clearClient();
|
||||
break;
|
||||
|
||||
case 'TextInput.hide':
|
||||
implementation.hide();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw StateError('Unsupported method call on the flutter/textinput channel: ${call.method}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void disable() {
|
||||
// We don't want to remove the DOM element because the caller is responsible
|
||||
// for that.
|
||||
//
|
||||
// Remove focus from the editable element to cause the keyboard to hide.
|
||||
// Otherwise, the keyboard stays on screen even when the user navigates to
|
||||
// a different screen (e.g. by hitting the "back" button).
|
||||
domElement.blur();
|
||||
/// Sends the 'TextInputClient.updateEditingState' message to the framework.
|
||||
void updateEditingState(int clientId, EditingState editingState) {
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall('TextInputClient.updateEditingState', <dynamic>[
|
||||
clientId,
|
||||
editingState.toFlutter(),
|
||||
]),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeElementPosition() {
|
||||
// No-op
|
||||
/// Sends the 'TextInputClient.performAction' message to the framework.
|
||||
void performAction(int clientId, String inputAction) {
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
'TextInputClient.performAction',
|
||||
<dynamic>[clientId, inputAction],
|
||||
),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initializeTextEditing(InputConfiguration inputConfig,
|
||||
{_OnChangeCallback onChange, _OnActionCallback onAction}) {
|
||||
// In accesibilty mode, the user of this class is supposed to insert the
|
||||
// [domElement] on their own. Let's make sure they did.
|
||||
assert(domElement != null);
|
||||
assert(html.document.body.contains(domElement));
|
||||
|
||||
isEnabled = true;
|
||||
_inputConfiguration = inputConfig;
|
||||
_onChange = onChange;
|
||||
_onAction = onAction;
|
||||
|
||||
domElement.focus();
|
||||
}
|
||||
|
||||
@override
|
||||
void setEditingState(EditingState editingState) {
|
||||
super.setEditingState(editingState);
|
||||
|
||||
// Refocus after setting editing state.
|
||||
domElement.focus();
|
||||
/// Sends the 'TextInputClient.onConnectionClosed' message to the framework.
|
||||
void onConnectionClosed(int clientId) {
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
'TextInputClient.onConnectionClosed',
|
||||
<dynamic>[clientId],
|
||||
),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,13 +848,6 @@ final HybridTextEditing textEditing = HybridTextEditing();
|
||||
/// - HTML's contentEditable feature handles typing and text changes.
|
||||
/// - HTML's selection API handles selection changes and cursor movements.
|
||||
class HybridTextEditing {
|
||||
/// The text editing stategy used. It can change depending on the
|
||||
/// formfactor/browser.
|
||||
///
|
||||
/// It uses an HTML element to manage editing state when a custom element is
|
||||
/// not provided via [useCustomEditableElement]
|
||||
DefaultTextEditingStrategy _defaultEditingElement;
|
||||
|
||||
/// Private constructor so this class can be a singleton.
|
||||
///
|
||||
/// The constructor also decides which text editing strategy to use depending
|
||||
@@ -821,10 +862,20 @@ class HybridTextEditing {
|
||||
} else if (browserEngine == BrowserEngine.firefox) {
|
||||
this._defaultEditingElement = FirefoxTextEditingStrategy(this);
|
||||
} else {
|
||||
this._defaultEditingElement = DefaultTextEditingStrategy(this);
|
||||
this._defaultEditingElement = GloballyPositionedTextEditingStrategy(this);
|
||||
}
|
||||
channel = TextEditingChannel(this);
|
||||
}
|
||||
|
||||
TextEditingChannel channel;
|
||||
|
||||
/// The text editing stategy used. It can change depending on the
|
||||
/// formfactor/browser.
|
||||
///
|
||||
/// It uses an HTML element to manage editing state when a custom element is
|
||||
/// not provided via [useCustomEditableElement]
|
||||
DefaultTextEditingStrategy _defaultEditingElement;
|
||||
|
||||
/// The HTML element used to manage editing state.
|
||||
///
|
||||
/// This field is populated using [useCustomEditableElement]. If `null` the
|
||||
@@ -838,6 +889,52 @@ class HybridTextEditing {
|
||||
return _defaultEditingElement;
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.setClient' message.
|
||||
void setClient(int clientId, InputConfiguration configuration) {
|
||||
final bool clientIdChanged = _clientId != null && _clientId != clientId;
|
||||
if (clientIdChanged && isEditing) {
|
||||
stopEditing();
|
||||
}
|
||||
_clientId = clientId;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.setEditingState' message.
|
||||
void setEditingState(EditingState state) {
|
||||
editingElement
|
||||
.setEditingState(state);
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.show' message.
|
||||
void show() {
|
||||
if (!isEditing) {
|
||||
_startEditing();
|
||||
}
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.setEditableSizeAndTransform' message.
|
||||
void setEditableSizeAndTransform(EditableTextGeometry geometry) {
|
||||
editingElement.updateElementPlacement(geometry);
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.setStyle' message.
|
||||
void setStyle(EditableTextStyle style) {
|
||||
editingElement.updateElementStyle(style);
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.clearClient' message.
|
||||
void clearClient() {
|
||||
// We do not distinguish between "clearClient" and "hide" on the Web.
|
||||
hide();
|
||||
}
|
||||
|
||||
/// Responds to the 'TextInput.hide' message.
|
||||
void hide() {
|
||||
if (isEditing) {
|
||||
stopEditing();
|
||||
}
|
||||
}
|
||||
|
||||
/// A CSS class name used to identify all elements used for text editing.
|
||||
@visibleForTesting
|
||||
static const String textEditingClass = 'flt-text-editing';
|
||||
@@ -874,57 +971,17 @@ class HybridTextEditing {
|
||||
|
||||
InputConfiguration _configuration;
|
||||
|
||||
/// All "flutter/textinput" platform messages should be sent to this method.
|
||||
void handleTextInput(ByteData data) {
|
||||
final MethodCall call = const JSONMethodCodec().decodeMethodCall(data);
|
||||
switch (call.method) {
|
||||
case 'TextInput.setClient':
|
||||
final bool clientIdChanged =
|
||||
_clientId != null && _clientId != call.arguments[0];
|
||||
if (clientIdChanged && isEditing) {
|
||||
stopEditing();
|
||||
}
|
||||
_clientId = call.arguments[0];
|
||||
_configuration = InputConfiguration.fromFlutter(call.arguments[1]);
|
||||
break;
|
||||
|
||||
case 'TextInput.setEditingState':
|
||||
editingElement
|
||||
.setEditingState(EditingState.fromFlutter(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.show':
|
||||
if (!isEditing) {
|
||||
_startEditing();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'TextInput.setEditableSizeAndTransform':
|
||||
editingElement
|
||||
.updateElementPosition(_GeometricInfo.fromFlutter(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.setStyle':
|
||||
editingElement
|
||||
.updateElementStyle(_EditingStyle.fromFlutter(call.arguments));
|
||||
break;
|
||||
|
||||
case 'TextInput.clearClient':
|
||||
case 'TextInput.hide':
|
||||
if (isEditing) {
|
||||
stopEditing();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _startEditing() {
|
||||
assert(!isEditing);
|
||||
isEditing = true;
|
||||
editingElement.enable(
|
||||
_configuration,
|
||||
onChange: _syncEditingStateToFlutter,
|
||||
onAction: _sendInputActionToFlutter,
|
||||
onChange: (EditingState editingState) {
|
||||
channel.updateEditingState(_clientId, editingState);
|
||||
},
|
||||
onAction: (String inputAction) {
|
||||
channel.performAction(_clientId, inputAction);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -934,47 +991,10 @@ class HybridTextEditing {
|
||||
editingElement.disable();
|
||||
}
|
||||
|
||||
void _syncEditingStateToFlutter(EditingState editingState) {
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall('TextInputClient.updateEditingState', <dynamic>[
|
||||
_clientId,
|
||||
editingState.toFlutter(),
|
||||
]),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
}
|
||||
|
||||
void _sendInputActionToFlutter(String inputAction) {
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
'TextInputClient.performAction',
|
||||
<dynamic>[_clientId, inputAction],
|
||||
),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
}
|
||||
|
||||
void sendTextConnectionClosedToFrameworkIfAny() {
|
||||
if (isEditing) {
|
||||
stopEditing();
|
||||
ui.window.onPlatformMessage(
|
||||
'flutter/textinput',
|
||||
const JSONMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
'TextInputClient.onConnectionClosed',
|
||||
<dynamic>[
|
||||
_clientId,
|
||||
],
|
||||
),
|
||||
),
|
||||
_emptyCallback,
|
||||
);
|
||||
channel.onConnectionClosed(_clientId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -982,8 +1002,8 @@ class HybridTextEditing {
|
||||
/// Information on the font and alignment of a text editing element.
|
||||
///
|
||||
/// This information is received via TextInput.setStyle message.
|
||||
class _EditingStyle {
|
||||
_EditingStyle({
|
||||
class EditableTextStyle {
|
||||
EditableTextStyle({
|
||||
@required this.textDirection,
|
||||
@required this.fontSize,
|
||||
@required this.textAlign,
|
||||
@@ -991,7 +1011,7 @@ class _EditingStyle {
|
||||
@required this.fontWeight,
|
||||
});
|
||||
|
||||
factory _EditingStyle.fromFlutter(Map<String, dynamic> flutterStyle) {
|
||||
factory EditableTextStyle.fromFrameworkMessage(Map<String, dynamic> flutterStyle) {
|
||||
assert(flutterStyle.containsKey('fontSize'));
|
||||
assert(flutterStyle.containsKey('fontFamily'));
|
||||
assert(flutterStyle.containsKey('textAlignIndex'));
|
||||
@@ -1009,7 +1029,7 @@ class _EditingStyle {
|
||||
// Also convert [textAlignIndex] and [textDirectionIndex] to their
|
||||
// corresponding enum values in [ui.TextAlign] and [ui.TextDirection]
|
||||
// respectively.
|
||||
return _EditingStyle(
|
||||
return EditableTextStyle(
|
||||
fontSize: flutterStyle['fontSize'],
|
||||
fontFamily: flutterStyle['fontFamily'],
|
||||
textAlign: ui.TextAlign.values[textAlignIndex],
|
||||
@@ -1037,40 +1057,58 @@ class _EditingStyle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Information on the location and size of the editing element.
|
||||
/// Describes the location and size of the editing element on the screen.
|
||||
///
|
||||
/// This information is received via "TextInput.setEditableSizeAndTransform"
|
||||
/// message. Framework currently sends this information on paint.
|
||||
class _GeometricInfo {
|
||||
_GeometricInfo({
|
||||
/// message from the framework.
|
||||
@immutable
|
||||
class EditableTextGeometry {
|
||||
EditableTextGeometry({
|
||||
@required this.width,
|
||||
@required this.height,
|
||||
@required this.transform,
|
||||
@required this.globalTransform,
|
||||
});
|
||||
|
||||
factory _GeometricInfo.fromFlutter(
|
||||
Map<String, dynamic> flutterMap,
|
||||
/// Parses the geometry from a message sent by the framework.
|
||||
factory EditableTextGeometry.fromFrameworkMessage(
|
||||
Map<String, dynamic> encodedGeometry,
|
||||
) {
|
||||
assert(flutterMap.containsKey('width'));
|
||||
assert(flutterMap.containsKey('height'));
|
||||
assert(flutterMap.containsKey('transform'));
|
||||
assert(encodedGeometry.containsKey('width'));
|
||||
assert(encodedGeometry.containsKey('height'));
|
||||
assert(encodedGeometry.containsKey('transform'));
|
||||
|
||||
final List<double> transformList =
|
||||
List<double>.from(flutterMap['transform']);
|
||||
return _GeometricInfo(
|
||||
width: flutterMap['width'],
|
||||
height: flutterMap['height'],
|
||||
transform: Float64List.fromList(transformList),
|
||||
List<double>.from(encodedGeometry['transform']);
|
||||
return EditableTextGeometry(
|
||||
width: encodedGeometry['width'],
|
||||
height: encodedGeometry['height'],
|
||||
globalTransform: Float64List.fromList(transformList),
|
||||
);
|
||||
}
|
||||
|
||||
/// The width of the editable in local coordinates, i.e. before applying [globalTransform].
|
||||
final double width;
|
||||
|
||||
/// The height of the editable in local coordinates, i.e. before applying [globalTransform].
|
||||
final double height;
|
||||
final Float64List transform;
|
||||
|
||||
String get cssTransform => float64ListToCssTransform(transform);
|
||||
/// The aggregate transform rooted at the global (screen) coordinate system
|
||||
/// that places and sizes the editable.
|
||||
///
|
||||
/// For correct sizing this transform must be applied to the [width] and
|
||||
/// [height] fields.
|
||||
final Float64List globalTransform;
|
||||
|
||||
/// Applies this geometry to the DOM element.
|
||||
///
|
||||
/// This assumes that the parent of the [domElement] has identity transform
|
||||
/// applied to it (i.e. the default). If the parent has a non-identity
|
||||
/// transform applied, this method will misplace the [domElement]. For
|
||||
/// example, if the editable DOM element is nested inside the semantics
|
||||
/// tree the semantics tree provides the placement parameters, in which
|
||||
/// case this method should not be used.
|
||||
void applyToDomElement(html.HtmlElement domElement) {
|
||||
final String cssTransform = float64ListToCssTransform(globalTransform);
|
||||
domElement.style
|
||||
..width = '${width}px'
|
||||
..height = '${height}px'
|
||||
|
||||
@@ -155,7 +155,7 @@ class EngineWindow extends ui.Window {
|
||||
break;
|
||||
|
||||
case 'flutter/textinput':
|
||||
textEditing.handleTextInput(data);
|
||||
textEditing.channel.handleTextInput(data);
|
||||
return;
|
||||
|
||||
case 'flutter/platform_views':
|
||||
|
||||
@@ -57,9 +57,13 @@ void main() {
|
||||
lastInputAction = null;
|
||||
});
|
||||
|
||||
group('$DefaultTextEditingStrategy', () {
|
||||
group('$GloballyPositionedTextEditingStrategy', () {
|
||||
HybridTextEditing testTextEditing;
|
||||
|
||||
setUp(() {
|
||||
editingElement = DefaultTextEditingStrategy(HybridTextEditing());
|
||||
testTextEditing = HybridTextEditing();
|
||||
editingElement = GloballyPositionedTextEditingStrategy(testTextEditing);
|
||||
testTextEditing.useCustomEditableElement(editingElement);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -334,13 +338,41 @@ void main() {
|
||||
// And default behavior of keyboard event shouldn't have been prevented.
|
||||
expect(event.defaultPrevented, isFalse);
|
||||
});
|
||||
|
||||
test('globally positions and sizes its DOM element', () {
|
||||
editingElement.enable(
|
||||
singlelineConfig,
|
||||
onChange: trackEditingState,
|
||||
onAction: trackInputAction,
|
||||
);
|
||||
expect(editingElement.isEnabled, isTrue);
|
||||
|
||||
// No geometry should be set until setEditableSizeAndTransform is called.
|
||||
expect(editingElement.domElement.style.transform, '');
|
||||
expect(editingElement.domElement.style.width, '');
|
||||
expect(editingElement.domElement.style.height, '');
|
||||
|
||||
testTextEditing.setEditableSizeAndTransform(EditableTextGeometry(
|
||||
width: 13,
|
||||
height: 12,
|
||||
globalTransform: Matrix4.translationValues(14, 15, 0).storage,
|
||||
));
|
||||
|
||||
// setEditableSizeAndTransform calls placeElement, so expecting geometry to be applied.
|
||||
expect(editingElement.domElement.style.transform, 'translate(14px, 15px)');
|
||||
expect(editingElement.domElement.style.width, '13px');
|
||||
expect(editingElement.domElement.style.height, '12px');
|
||||
});
|
||||
});
|
||||
|
||||
group('$PersistentTextEditingElement', () {
|
||||
group('$SemanticsTextEditingStrategy', () {
|
||||
InputElement testInputElement;
|
||||
HybridTextEditing testTextEditing;
|
||||
|
||||
setUp(() {
|
||||
testInputElement = InputElement();
|
||||
testTextEditing = HybridTextEditing();
|
||||
editingElement = GloballyPositionedTextEditingStrategy(testTextEditing);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -352,14 +384,14 @@ void main() {
|
||||
// A regular <span> shouldn't be accepted.
|
||||
final HtmlElement span = SpanElement();
|
||||
expect(
|
||||
() => PersistentTextEditingElement(HybridTextEditing(), span),
|
||||
() => SemanticsTextEditingStrategy(HybridTextEditing(), span),
|
||||
throwsAssertionError,
|
||||
);
|
||||
});
|
||||
|
||||
test('Does not re-acquire focus', () {
|
||||
editingElement =
|
||||
PersistentTextEditingElement(HybridTextEditing(), testInputElement);
|
||||
SemanticsTextEditingStrategy(HybridTextEditing(), testInputElement);
|
||||
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
@@ -380,7 +412,7 @@ void main() {
|
||||
|
||||
test('Does not dispose and recreate dom elements in persistent mode', () {
|
||||
editingElement =
|
||||
PersistentTextEditingElement(HybridTextEditing(), testInputElement);
|
||||
SemanticsTextEditingStrategy(HybridTextEditing(), testInputElement);
|
||||
|
||||
// The DOM element should've been eagerly created.
|
||||
expect(testInputElement, isNotNull);
|
||||
@@ -417,7 +449,7 @@ void main() {
|
||||
|
||||
test('Refocuses when setting editing state', () {
|
||||
editingElement =
|
||||
PersistentTextEditingElement(HybridTextEditing(), testInputElement);
|
||||
SemanticsTextEditingStrategy(HybridTextEditing(), testInputElement);
|
||||
|
||||
document.body.append(testInputElement);
|
||||
editingElement.enable(
|
||||
@@ -440,7 +472,7 @@ void main() {
|
||||
test('Works in multi-line mode', () {
|
||||
final TextAreaElement textarea = TextAreaElement();
|
||||
editingElement =
|
||||
PersistentTextEditingElement(HybridTextEditing(), textarea);
|
||||
SemanticsTextEditingStrategy(HybridTextEditing(), textarea);
|
||||
|
||||
expect(editingElement.domElement, textarea);
|
||||
expect(document.activeElement, document.body);
|
||||
@@ -479,6 +511,28 @@ void main() {
|
||||
// But the textarea loses focus.
|
||||
expect(document.activeElement, document.body);
|
||||
});
|
||||
|
||||
test('Does not position or size its DOM element', () {
|
||||
editingElement.enable(
|
||||
singlelineConfig,
|
||||
onChange: trackEditingState,
|
||||
onAction: trackInputAction,
|
||||
);
|
||||
testTextEditing.setEditableSizeAndTransform(EditableTextGeometry(
|
||||
height: 12,
|
||||
width: 13,
|
||||
globalTransform: Matrix4.translationValues(14, 15, 0).storage,
|
||||
));
|
||||
|
||||
void checkPlacementIsEmpty() {
|
||||
expect(editingElement.domElement.style.transform, '');
|
||||
expect(editingElement.domElement.style.width, '');
|
||||
expect(editingElement.domElement.style.height, '');
|
||||
}
|
||||
checkPlacementIsEmpty();
|
||||
editingElement.placeElement();
|
||||
checkPlacementIsEmpty();
|
||||
});
|
||||
});
|
||||
|
||||
group('$HybridTextEditing', () {
|
||||
@@ -487,6 +541,11 @@ void main() {
|
||||
|
||||
int clientId = 0;
|
||||
|
||||
/// Emulates sending of a message by the framework to the engine.
|
||||
void sendFrameworkMessage(dynamic message) {
|
||||
textEditing.channel.handleTextInput(message);
|
||||
}
|
||||
|
||||
/// Sends the necessary platform messages to activate a text field and show
|
||||
/// the keyboard.
|
||||
///
|
||||
@@ -499,20 +558,20 @@ void main() {
|
||||
createFlutterConfig(inputType, inputAction: inputAction),
|
||||
],
|
||||
);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
return clientId;
|
||||
}
|
||||
|
||||
void hideKeyboard() {
|
||||
const MethodCall hide = MethodCall('TextInput.hide');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(hide));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(hide));
|
||||
|
||||
const MethodCall clearClient = MethodCall('TextInput.clearClient');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(clearClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
|
||||
}
|
||||
|
||||
String getEditingInputMode() {
|
||||
@@ -536,13 +595,13 @@ void main() {
|
||||
test('setClient, show, setEditingState, hide', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
// Editing shouldn't have started yet.
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
checkInputEditingState(textEditing.editingElement.domElement, '', 0, 0);
|
||||
|
||||
@@ -552,13 +611,13 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
checkInputEditingState(
|
||||
textEditing.editingElement.domElement, 'abcd', 2, 3);
|
||||
|
||||
const MethodCall hide = MethodCall('TextInput.hide');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(hide));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(hide));
|
||||
|
||||
// Text editing should've stopped.
|
||||
expect(document.activeElement, document.body);
|
||||
@@ -570,7 +629,7 @@ void main() {
|
||||
test('setClient, setEditingState, show, clearClient', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -578,19 +637,19 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
// Editing shouldn't have started yet.
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
checkInputEditingState(
|
||||
textEditing.editingElement.domElement, 'abcd', 2, 3);
|
||||
|
||||
const MethodCall clearClient = MethodCall('TextInput.clearClient');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(clearClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
|
||||
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
@@ -601,7 +660,7 @@ void main() {
|
||||
test('close connection on blur', () async {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -609,13 +668,13 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
// Editing shouldn't have started yet.
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
checkInputEditingState(
|
||||
textEditing.editingElement.domElement, 'abcd', 2, 3);
|
||||
@@ -638,7 +697,7 @@ void main() {
|
||||
test('setClient, setEditingState, show, setClient', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -646,20 +705,20 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
// Editing shouldn't have started yet.
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
checkInputEditingState(
|
||||
textEditing.editingElement.domElement, 'abcd', 2, 3);
|
||||
|
||||
final MethodCall setClient2 = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[567, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient2));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient2));
|
||||
|
||||
// Receiving another client via setClient should stop editing, hence
|
||||
// should remove the previous active element.
|
||||
@@ -674,7 +733,7 @@ void main() {
|
||||
test('setClient, setEditingState, show, setEditingState, clearClient', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState1 =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -682,10 +741,10 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState1));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState1));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
const MethodCall setEditingState2 =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -693,14 +752,14 @@ void main() {
|
||||
'selectionBase': 0,
|
||||
'selectionExtent': 2,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState2));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState2));
|
||||
|
||||
// The second [setEditingState] should override the first one.
|
||||
checkInputEditingState(
|
||||
textEditing.editingElement.domElement, 'xyz', 0, 2);
|
||||
|
||||
const MethodCall clearClient = MethodCall('TextInput.clearClient');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(clearClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
|
||||
|
||||
// Confirm that [HybridTextEditing] didn't send any messages.
|
||||
expect(spy.messages, isEmpty);
|
||||
@@ -711,16 +770,16 @@ void main() {
|
||||
() {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
final MethodCall setSizeAndTransform =
|
||||
configureSetSizeAndTransformMethodCall(150, 50,
|
||||
Matrix4.translationValues(10.0, 20.0, 30.0).storage.toList());
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setSizeAndTransform));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setSizeAndTransform));
|
||||
|
||||
final MethodCall setStyle =
|
||||
configureSetStyleMethodCall(12, 'sans-serif', 4, 4, 1);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setStyle));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setStyle));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -728,10 +787,10 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
final HtmlElement domElement = textEditing.editingElement.domElement;
|
||||
|
||||
@@ -748,7 +807,7 @@ void main() {
|
||||
'500 12px sans-serif');
|
||||
|
||||
const MethodCall clearClient = MethodCall('TextInput.clearClient');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(clearClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
|
||||
|
||||
// Confirm that [HybridTextEditing] didn't send any messages.
|
||||
expect(spy.messages, isEmpty);
|
||||
@@ -759,10 +818,10 @@ void main() {
|
||||
() {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
final MethodCall setSizeAndTransform =
|
||||
configureSetSizeAndTransformMethodCall(
|
||||
@@ -773,12 +832,11 @@ void main() {
|
||||
20.0,
|
||||
30.0,
|
||||
).storage.toList());
|
||||
textEditing
|
||||
.handleTextInput(codec.encodeMethodCall(setSizeAndTransform));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setSizeAndTransform));
|
||||
|
||||
final MethodCall setStyle =
|
||||
configureSetStyleMethodCall(12, 'sans-serif', 4, 4, 1);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setStyle));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setStyle));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -786,7 +844,7 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
final HtmlElement domElement = textEditing.editingElement.domElement;
|
||||
|
||||
@@ -808,23 +866,23 @@ void main() {
|
||||
);
|
||||
|
||||
const MethodCall clearClient = MethodCall('TextInput.clearClient');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(clearClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
|
||||
},
|
||||
);
|
||||
|
||||
test('input font set succesfully with null fontWeightIndex', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
final MethodCall setSizeAndTransform =
|
||||
configureSetSizeAndTransformMethodCall(150, 50,
|
||||
Matrix4.translationValues(10.0, 20.0, 30.0).storage.toList());
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setSizeAndTransform));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setSizeAndTransform));
|
||||
|
||||
final MethodCall setStyle = configureSetStyleMethodCall(
|
||||
12, 'sans-serif', 4, null /* fontWeightIndex */, 1);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setStyle));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setStyle));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -832,10 +890,10 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
final HtmlElement domElement = textEditing.editingElement.domElement;
|
||||
|
||||
@@ -859,7 +917,7 @@ void main() {
|
||||
() {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState1 =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -867,10 +925,10 @@ void main() {
|
||||
'selectionBase': 1,
|
||||
'selectionExtent': 2,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState1));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState1));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
// Check if the selection range is correct.
|
||||
checkInputEditingState(
|
||||
@@ -882,7 +940,7 @@ void main() {
|
||||
'selectionBase': -1,
|
||||
'selectionExtent': -1,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState2));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState2));
|
||||
|
||||
// The negative offset values are applied to the dom element as 0.
|
||||
checkInputEditingState(
|
||||
@@ -894,7 +952,7 @@ void main() {
|
||||
test('Syncs the editing state back to Flutter', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterSinglelineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState =
|
||||
MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
@@ -902,10 +960,10 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
final InputElement input = textEditing.editingElement.domElement;
|
||||
|
||||
@@ -954,13 +1012,13 @@ void main() {
|
||||
test('Multi-line mode also works', () {
|
||||
final MethodCall setClient = MethodCall(
|
||||
'TextInput.setClient', <dynamic>[123, flutterMultilineConfig]);
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setClient));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
// Editing shouldn't have started yet.
|
||||
expect(document.activeElement, document.body);
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(show));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
|
||||
final TextAreaElement textarea = textEditing.editingElement.domElement;
|
||||
checkTextAreaEditingState(textarea, '', 0, 0);
|
||||
@@ -972,7 +1030,7 @@ void main() {
|
||||
'selectionBase': 2,
|
||||
'selectionExtent': 3,
|
||||
});
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(setEditingState));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState));
|
||||
checkTextAreaEditingState(textarea, 'foo\nbar', 2, 3);
|
||||
|
||||
// Sends the changes back to Flutter.
|
||||
@@ -1000,7 +1058,7 @@ void main() {
|
||||
);
|
||||
|
||||
const MethodCall hide = MethodCall('TextInput.hide');
|
||||
textEditing.handleTextInput(codec.encodeMethodCall(hide));
|
||||
sendFrameworkMessage(codec.encodeMethodCall(hide));
|
||||
|
||||
// Text editing should've stopped.
|
||||
expect(document.activeElement, document.body);
|
||||
@@ -1116,7 +1174,7 @@ void main() {
|
||||
EditingState _editingState;
|
||||
|
||||
setUp(() {
|
||||
editingElement = DefaultTextEditingStrategy(HybridTextEditing());
|
||||
editingElement = GloballyPositionedTextEditingStrategy(HybridTextEditing());
|
||||
editingElement.enable(
|
||||
singlelineConfig,
|
||||
onChange: trackEditingState,
|
||||
|
||||
Reference in New Issue
Block a user