fixes text area transitions both for mobile and desktop (flutter/engine#23256)

* fixes text area transitions both for mobile and desktop

* add a fix for safari desktop

* remove focus related changes

* change text editing a11y tests. enable them in all browsers

* remove unused variables

* remove debug print
This commit is contained in:
nturgut
2020-12-28 11:15:14 -08:00
committed by GitHub
parent f6effe1f31
commit bef022f841
3 changed files with 64 additions and 35 deletions

View File

@@ -582,6 +582,8 @@ class SemanticsObject {
hasAction(ui.SemanticsAction.scrollDown) ||
hasAction(ui.SemanticsAction.scrollUp);
bool get hasFocus => hasFlag(ui.SemanticsFlag.isFocused);
/// Whether this object represents a hotizontally scrollable area.
bool get isHorizontalScrollContainer =>
hasAction(ui.SemanticsAction.scrollLeft) ||

View File

@@ -31,12 +31,44 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
@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.
// for that. However we still want to stop editing, cleanup the handlers.
assert(isEnabled);
isEnabled = false;
_style = null;
_geometry = null;
for (int i = 0; i < _subscriptions.length; i++) {
_subscriptions[i].cancel();
}
_subscriptions.clear();
_lastEditingState = null;
// If the text element still has focus, 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();
if (operatingSystem == OperatingSystem.android ||
operatingSystem == OperatingSystem.iOs) {
domElement.blur();
}
}
@override
void addEventHandlers() {
if (_inputConfiguration.autofillGroup != null) {
_subscriptions
.addAll(_inputConfiguration.autofillGroup!.addInputEventListeners());
}
// Subscribe to text and selection changes.
_subscriptions.add(domElement.onInput.listen(_handleChange));
_subscriptions.add(domElement.onKeyDown.listen(_maybeSendAction));
_subscriptions.add(html.document.onSelectionChange.listen(_handleChange));
preventDefaultForMouseEvents();
}
@override
@@ -55,8 +87,6 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
_inputConfiguration = inputConfig;
_onChange = onChange;
_onAction = onAction;
domElement.focus();
}
@override
@@ -91,7 +121,7 @@ class TextField extends RoleManager {
}
SemanticsTextEditingStrategy? textEditingElement;
html.Element get _textFieldElement => textEditingElement!.domElement;
html.HtmlElement get _textFieldElement => textEditingElement!.domElement;
void _setupDomElement() {
// On iOS, even though the semantic text field is transparent, the cursor
@@ -148,8 +178,8 @@ class TextField extends RoleManager {
}
textEditing.useCustomEditableElement(textEditingElement);
EnginePlatformDispatcher.instance
.invokeOnSemanticsAction(semanticsObject.id, ui.SemanticsAction.tap, null);
EnginePlatformDispatcher.instance.invokeOnSemanticsAction(
semanticsObject.id, ui.SemanticsAction.tap, null);
});
}
@@ -159,6 +189,11 @@ class TextField extends RoleManager {
/// events are present regardless of whether accessibility is enabled or not,
/// this mode is always enabled.
void _initializeForWebkit() {
// Safari for desktop is also initialized as the other browsers.
if (operatingSystem == OperatingSystem.macOs) {
_initializeForBlink();
return;
}
num? lastTouchStartOffsetX;
num? lastTouchStartOffsetY;

View File

@@ -384,7 +384,7 @@ void testMain() {
);
});
test('Re-acquire focus', () {
test('Do not re-acquire focus', () {
editingElement =
SemanticsTextEditingStrategy(HybridTextEditing(), testInputElement);
@@ -398,17 +398,14 @@ void testMain() {
);
expect(document.activeElement, testInputElement);
// The input should refocus after blur.
// The input should not refocus after blur.
editingElement.domElement.blur();
expect(document.activeElement, editingElement.domElement);
expect(document.activeElement, document.body);
editingElement.disable();
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
skip: (browserEngine == BrowserEngine.webkit ||
browserEngine == BrowserEngine.edge ||
browserEngine == BrowserEngine.firefox));
skip: browserEngine == BrowserEngine.edge);
test('Does not dispose and recreate dom elements in persistent mode', () {
editingElement =
@@ -443,17 +440,18 @@ void testMain() {
// It doesn't remove the DOM element.
expect(editingElement.domElement, testInputElement);
expect(document.body.contains(editingElement.domElement), isTrue);
// The textArea does not lose focus.
// Even though this passes on manual tests it does not work on
// Firefox automated unit tests.
if (browserEngine != BrowserEngine.firefox) {
// Editing element is not enabled.
expect(editingElement.isEnabled, isFalse);
// For mobile browsers `blur` is called to close the onscreen keyboard.
if (operatingSystem == OperatingSystem.iOs &&
browserEngine == BrowserEngine.webkit) {
expect(document.activeElement, document.body);
} else {
expect(document.activeElement, editingElement.domElement);
}
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
skip: (browserEngine == BrowserEngine.webkit ||
browserEngine == BrowserEngine.edge));
skip: browserEngine == BrowserEngine.edge);
test('Refocuses when setting editing state', () {
editingElement =
@@ -471,10 +469,8 @@ void testMain() {
editingElement.disable();
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
skip: (browserEngine == BrowserEngine.webkit ||
browserEngine == BrowserEngine.edge));
skip: browserEngine == BrowserEngine.edge);
test('Works in multi-line mode', () {
final TextAreaElement textarea = TextAreaElement();
@@ -504,21 +500,17 @@ void testMain() {
expect(document.activeElement, textarea);
textarea.blur();
// The textArea does not lose focus.
// Even though this passes on manual tests it does not work on
// Firefox automated unit tests.
if (browserEngine != BrowserEngine.firefox) {
expect(document.activeElement, textarea);
}
// The textArea loses focus.
expect(document.activeElement, document.body);
editingElement.disable();
// It doesn't remove the textarea from the DOM.
expect(document.body.contains(editingElement.domElement), isTrue);
// Editing element is not enabled.
expect(editingElement.isEnabled, isFalse);
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
skip: (browserEngine == BrowserEngine.webkit ||
browserEngine == BrowserEngine.edge));
skip: browserEngine == BrowserEngine.edge);
test('Does not position or size its DOM element', () {
editingElement.enable(