From 6e74ee483380f2d8ec77f08ce23f891af9a03933 Mon Sep 17 00:00:00 2001 From: Hannah Jin Date: Mon, 17 Mar 2025 14:19:33 -0700 Subject: [PATCH] [web][a11y]Delete _childContainerElement (#163662) delete _childContainerElement , add the rect compensate and scrolling adjustment to the children ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- .../lib/src/engine/semantics/scrollable.dart | 10 +- .../lib/src/engine/semantics/semantics.dart | 124 +++----- .../lib/web_ui/test/common/matchers.dart | 1 - .../semantics/semantics_multi_view_test.dart | 4 - .../test/engine/semantics/semantics_test.dart | 275 +++++++----------- .../engine/semantics/semantics_text_test.dart | 4 - 6 files changed, 157 insertions(+), 261 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart index 44beba5ae9..08e96af35d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart @@ -70,6 +70,7 @@ class SemanticScrollable extends SemanticRole { final bool doScrollForward = _domScrollPosition > _effectiveNeutralScrollPosition; _neutralizeDomScrollPosition(); semanticsObject.recomputePositionAndSize(); + semanticsObject.updateChildrenPositionAndSize(); final int semanticsId = semanticsObject.id; if (doScrollForward) { @@ -131,6 +132,7 @@ class SemanticScrollable extends SemanticRole { semanticsObject.owner.addOneTimePostUpdateCallback(() { _neutralizeDomScrollPosition(); semanticsObject.recomputePositionAndSize(); + semanticsObject.updateChildrenPositionAndSize(); }); if (_scrollListener == null) { @@ -203,8 +205,8 @@ class SemanticScrollable extends SemanticRole { // Read back because the effective value depends on the amount of content. _effectiveNeutralScrollPosition = element.scrollTop.toInt(); semanticsObject - ..verticalContainerAdjustment = _effectiveNeutralScrollPosition.toDouble() - ..horizontalContainerAdjustment = 0.0; + ..verticalScrollAdjustment = _effectiveNeutralScrollPosition.toDouble() + ..horizontalScrollAdjustment = 0.0; } else { // Place the _scrollOverflowElement at the end of the content and // make sure that when we neutralize the scrolling position, @@ -219,8 +221,8 @@ class SemanticScrollable extends SemanticRole { // Read back because the effective value depends on the amount of content. _effectiveNeutralScrollPosition = element.scrollLeft.toInt(); semanticsObject - ..verticalContainerAdjustment = 0.0 - ..horizontalContainerAdjustment = _effectiveNeutralScrollPosition.toDouble(); + ..verticalScrollAdjustment = 0.0 + ..horizontalScrollAdjustment = _effectiveNeutralScrollPosition.toDouble(); } } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart index 4e23e4baf6..a2c3aae0ab 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart @@ -1358,33 +1358,6 @@ class SemanticsObject { /// The dom element of this semantics object. DomElement get element => semanticRole!.element; - /// Returns the HTML element that contains the HTML elements of direct - /// children of this object. - /// - /// The element is created lazily. When the child list is empty this element - /// is not created. This is necessary for "aria-label" to function correctly. - /// The browser will ignore the [label] of HTML element that contain child - /// elements. - DomElement? getOrCreateChildContainer() { - if (_childContainerElement == null) { - _childContainerElement = createDomElement('flt-semantics-container'); - _childContainerElement!.style - ..position = 'absolute' - // Ignore pointer events on child container so that platform views - // behind it can be reached. - ..pointerEvents = 'none'; - element.append(_childContainerElement!); - } - return _childContainerElement; - } - - /// The element that contains the elements belonging to the child semantics - /// nodes. - /// - /// This element is used to correct for [_rect] offsets. It is only non-`null` - /// when there are non-zero children (i.e. when [hasChildren] is `true`). - DomElement? _childContainerElement; - /// The parent of this semantics object. /// /// This value is not final until the tree is finalized. It is not safe to @@ -1682,22 +1655,15 @@ class SemanticsObject { // Trivial case: remove all children. if (_childrenInHitTestOrder == null || _childrenInHitTestOrder!.isEmpty) { if (_currentChildrenInRenderOrder == null || _currentChildrenInRenderOrder!.isEmpty) { - // A container element must not have been created when child list is empty. - assert(_childContainerElement == null); _currentChildrenInRenderOrder = null; return; } - // A container element must have been created when child list is not empty. - assert(_childContainerElement != null); - // Remove all children from this semantics object. final int len = _currentChildrenInRenderOrder!.length; for (int i = 0; i < len; i++) { owner._detachObject(_currentChildrenInRenderOrder![i].id); } - _childContainerElement!.remove(); - _childContainerElement = null; _currentChildrenInRenderOrder = null; return; } @@ -1706,7 +1672,6 @@ class SemanticsObject { final Int32List childrenInTraversalOrder = _childrenInTraversalOrder!; final Int32List childrenInHitTestOrder = _childrenInHitTestOrder!; final int childCount = childrenInHitTestOrder.length; - final DomElement? containerElement = getOrCreateChildContainer(); assert(childrenInTraversalOrder.length == childrenInHitTestOrder.length); @@ -1738,7 +1703,7 @@ class SemanticsObject { // Trivial case: previous list was empty => just populate the container. if (_currentChildrenInRenderOrder == null || _currentChildrenInRenderOrder!.isEmpty) { for (final SemanticsObject child in childrenInRenderOrder) { - containerElement!.append(child.element); + element.append(child.element); owner._attachObject(parent: this, child: child); } _currentChildrenInRenderOrder = childrenInRenderOrder; @@ -1822,9 +1787,9 @@ class SemanticsObject { final SemanticsObject child = childrenInRenderOrder[i]; if (!stationaryIds.contains(child.id)) { if (refNode == null) { - containerElement!.append(child.element); + element.append(child.element); } else { - containerElement!.insertBefore(child.element, refNode); + element.insertBefore(child.element, refNode); } owner._attachObject(parent: this, child: child); } else { @@ -1990,10 +1955,6 @@ class SemanticsObject { // Reparent element. if (previousElement != element) { - final DomElement? container = _childContainerElement; - if (container != null) { - element.append(container); - } final DomElement? parent = previousElement?.parent; if (parent != null) { parent.insertBefore(element, previousElement); @@ -2079,60 +2040,74 @@ class SemanticsObject { /// Indicates whether the node is currently expanded. bool get isExpanded => hasFlag(ui.SemanticsFlag.isExpanded); - /// Role-specific adjustment of the vertical position of the child container. + /// Role-specific adjustment of the vertical position of the children. /// /// This is used, for example, by the [SemanticScrollable] to compensate for the /// `scrollTop` offset in the DOM. /// /// This field must not be null. - double verticalContainerAdjustment = 0.0; + double verticalScrollAdjustment = 0.0; - /// Role-specific adjustment of the horizontal position of the child - /// container. + /// Role-specific adjustment of the horizontal position of children. /// /// This is used, for example, by the [SemanticScrollable] to compensate for the /// `scrollLeft` offset in the DOM. /// /// This field must not be null. - double horizontalContainerAdjustment = 0.0; + double horizontalScrollAdjustment = 0.0; + + double verticalAdjustmentFromParent = 0.0; + double horizontalAdjustmentFromParent = 0.0; /// Computes the size and position of [element] and, if this element - /// [hasChildren], of [getOrCreateChildContainer]. + /// [hasChildren], computes the parent adjustment for each child. void recomputePositionAndSize() { element.style ..width = '${_rect!.width}px' ..height = '${_rect!.height}px'; - final DomElement? containerElement = hasChildren ? getOrCreateChildContainer() : null; - final bool hasZeroRectOffset = _rect!.top == 0.0 && _rect!.left == 0.0; final Float32List? transform = _transform; final bool hasIdentityTransform = transform == null || isIdentityFloat32ListTransform(transform); + // If this node has children, we need to compensate for the parent's rect and + // pass down the scroll adjustments. + if (hasChildren) { + final double translateX = -_rect!.left + horizontalScrollAdjustment; + final double translateY = -_rect!.top + verticalScrollAdjustment; + + for (final childIndex in _childrenInTraversalOrder!) { + final child = owner._semanticsTree[childIndex]; + if (child == null) { + continue; + } + child.horizontalAdjustmentFromParent = translateX; + child.verticalAdjustmentFromParent = translateY; + } + } + if (hasZeroRectOffset && hasIdentityTransform && - verticalContainerAdjustment == 0.0 && - horizontalContainerAdjustment == 0.0) { + verticalAdjustmentFromParent == 0.0 && + horizontalAdjustmentFromParent == 0.0) { _clearSemanticElementTransform(element); - if (containerElement != null) { - _clearSemanticElementTransform(containerElement); - } return; } late Matrix4 effectiveTransform; bool effectiveTransformIsIdentity = true; - if (!hasZeroRectOffset) { + + final double left = _rect!.left + horizontalAdjustmentFromParent; + final double top = _rect!.top + verticalAdjustmentFromParent; + + if (left != 0.0 || top != 0.0) { if (transform == null) { - final double left = _rect!.left; - final double top = _rect!.top; effectiveTransform = Matrix4.translationValues(left, top, 0.0); - effectiveTransformIsIdentity = left == 0.0 && top == 0.0; + effectiveTransformIsIdentity = false; } else { // Clone to avoid mutating _transform. - effectiveTransform = - Matrix4.fromFloat32List(transform).clone()..translate(_rect!.left, _rect!.top); + effectiveTransform = Matrix4.fromFloat32List(transform).clone()..translate(left, top); effectiveTransformIsIdentity = effectiveTransform.isIdentity(); } } else if (!hasIdentityTransform) { @@ -2147,19 +2122,16 @@ class SemanticsObject { } else { _clearSemanticElementTransform(element); } + } - if (containerElement != null) { - if (!hasZeroRectOffset || - verticalContainerAdjustment != 0.0 || - horizontalContainerAdjustment != 0.0) { - final double translateX = -_rect!.left + horizontalContainerAdjustment; - final double translateY = -_rect!.top + verticalContainerAdjustment; - containerElement.style - ..top = '${translateY}px' - ..left = '${translateX}px'; - } else { - _clearSemanticElementTransform(containerElement); + /// Computes the size and position of children. + void updateChildrenPositionAndSize() { + for (final childIndex in _childrenInTraversalOrder!) { + final child = owner._semanticsTree[childIndex]; + if (child == null) { + continue; } + child.recomputePositionAndSize(); } } @@ -2719,7 +2691,7 @@ class EngineSemanticsOwner { removals.add(node); } else { assert(node._parent == parent); - assert(node.element.parentNode == parent._childContainerElement); + assert(node.element.parentNode == parent.element); } return true; }); @@ -2828,6 +2800,9 @@ class EngineSemanticsOwner { final SemanticsObject object = _semanticsTree[nodeUpdate.id]!; object.updateChildren(); object._dirtyFields = 0; + + object.recomputePositionAndSize(); + object.updateChildrenPositionAndSize(); } final SemanticsObject root = _semanticsTree[0]!; @@ -2863,9 +2838,6 @@ AFTER: $description // Dirty fields should be cleared after the tree has been finalized. assert(object._dirtyFields == 0); - // Make sure a child container is created only when there are children. - assert(object._childContainerElement == null || object.hasChildren); - // Ensure child ID list is consistent with the parent-child // relationship of the semantics tree. if (object._childrenInTraversalOrder != null) { diff --git a/engine/src/flutter/lib/web_ui/test/common/matchers.dart b/engine/src/flutter/lib/web_ui/test/common/matchers.dart index 7537b40cfd..e12d1a9025 100644 --- a/engine/src/flutter/lib/web_ui/test/common/matchers.dart +++ b/engine/src/flutter/lib/web_ui/test/common/matchers.dart @@ -274,7 +274,6 @@ class HtmlPatternMatcher extends Matcher { static bool _areTagsEqual(html.Element a, html.Element b) { const Map synonyms = { 'sem': 'flt-semantics', - 'sem-c': 'flt-semantics-container', 'sem-img': 'flt-semantics-img', 'sem-tf': 'flt-semantics-text-field', }; diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_multi_view_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_multi_view_test.dart index 676c41d8b2..8fce7b62e9 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_multi_view_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_multi_view_test.dart @@ -99,15 +99,11 @@ Future testMain() async { // Test that each view renders its own semantics tree. expectSemanticsTree(view1.semantics, ''' - - '''); expectSemanticsTree(view2.semantics, ''' - - '''); diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart index ce9d9db01a..ba593ca8d6 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -158,10 +158,8 @@ void _testSemanticRole() { tester.expectSemantics(''' - - '''); tester.updateNode( @@ -175,10 +173,8 @@ void _testSemanticRole() { tester.expectSemantics(''' - - '''); tester.updateNode( @@ -193,11 +189,9 @@ void _testSemanticRole() { tester.expectSemantics(''' - - '''); }); } @@ -520,9 +514,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - Hello - '''); // Update @@ -530,9 +522,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - World - '''); // Remove @@ -540,9 +530,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - - '''); semantics().semanticsEnabled = false; @@ -563,9 +551,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - Hello - '''); // Update @@ -578,9 +564,7 @@ void _testEngineSemanticsOwner() { expect(tree[1]!.element.tagName.toLowerCase(), 'a'); expectSemanticsTree(owner(), ''' - Hello - '''); expect(existingParent, tree[1]!.element.parent); @@ -602,9 +586,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - tooltip - '''); // Update @@ -612,9 +594,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - tooltip\nHello - '''); // Remove @@ -622,9 +602,7 @@ void _testEngineSemanticsOwner() { expectSemanticsTree(owner(), ''' - - '''); semantics().semanticsEnabled = false; @@ -849,7 +827,7 @@ void _testHeader() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' -
+
'''); semantics().semanticsEnabled = false; @@ -956,7 +934,7 @@ label hint'''); } void _testContainer() { - test('container node has no transform when there is no rect offset', () async { + test('child node has no transform when there is no rect offset', () async { semantics() ..debugOverrideTimestampFunction(() => _testTime) ..semanticsEnabled = true; @@ -973,35 +951,30 @@ void _testContainer() { updateNode(builder, id: 1, transform: Matrix4.identity().toFloat64(), rect: zeroOffsetRect); owner().updateSemantics(builder.build()); - expectSemanticsTree(owner(), ''' - - - - -'''); + expectSemanticsTree(owner(), ''''''); final DomElement parentElement = owner().semanticsHost.querySelector('flt-semantics')!; - final DomElement container = owner().semanticsHost.querySelector('flt-semantics-container')!; + final DomElement childElement = owner().semanticsHost.querySelector('#flt-semantic-node-1')!; if (isMacOrIOS) { expect(parentElement.style.top, '0px'); expect(parentElement.style.left, '0px'); - expect(container.style.top, '0px'); - expect(container.style.left, '0px'); + expect(childElement.style.top, '0px'); + expect(childElement.style.left, '0px'); } else { expect(parentElement.style.top, ''); expect(parentElement.style.left, ''); - expect(container.style.top, ''); - expect(container.style.left, ''); + expect(childElement.style.top, ''); + expect(childElement.style.left, ''); } expect(parentElement.style.transform, ''); expect(parentElement.style.transformOrigin, ''); - expect(container.style.transform, ''); - expect(container.style.transformOrigin, ''); + expect(childElement.style.transform, ''); + expect(childElement.style.transformOrigin, ''); semantics().semanticsEnabled = false; }); - test('container node compensates for rect offset', () async { + test('child node transform compensates for parent rect offset', () async { semantics() ..debugOverrideTimestampFunction(() => _testTime) ..semanticsEnabled = true; @@ -1018,19 +991,14 @@ void _testContainer() { builder, id: 1, transform: Matrix4.identity().toFloat64(), - rect: const ui.Rect.fromLTRB(10, 10, 20, 20), + rect: const ui.Rect.fromLTRB(0, 0, 5, 5), ); owner().updateSemantics(builder.build()); - expectSemanticsTree(owner(), ''' - - - - -'''); + expectSemanticsTree(owner(), ''''''); final DomElement parentElement = owner().semanticsHost.querySelector('flt-semantics')!; - final DomElement container = owner().semanticsHost.querySelector('flt-semantics-container')!; + final DomElement childElement = owner().semanticsHost.querySelector('#flt-semantic-node-1')!; expect(parentElement.style.transform, 'matrix(1, 0, 0, 1, 10, 10)'); if (isSafari) { @@ -1039,63 +1007,103 @@ void _testContainer() { parentElement.style.transformOrigin, anyOf(contains('0px 0px 0px'), contains('0px 0px')), ); + expect( + childElement.style.transformOrigin, + anyOf(contains('0px 0px 0px'), contains('0px 0px')), + ); } else { expect(parentElement.style.transformOrigin, '0px 0px 0px'); + expect(childElement.style.transformOrigin, '0px 0px 0px'); } - expect(container.style.top, '-10px'); - expect(container.style.left, '-10px'); + expect(childElement.style.transform, 'matrix(1, 0, 0, 1, -10, -10)'); + expect(childElement.style.left == '0px' || childElement.style.left == '', isTrue); + expect(childElement.style.top == '0px' || childElement.style.top == '', isTrue); + semantics().semanticsEnabled = false; }); - test('0 offsets are not removed for voiceover', () async { - semantics() - ..debugOverrideTimestampFunction(() => _testTime) - ..semanticsEnabled = true; + test( + 'child node transform compensates for parent rect offset when parent rect changed', + () async { + semantics() + ..debugOverrideTimestampFunction(() => _testTime) + ..semanticsEnabled = true; - final ui.SemanticsUpdateBuilder builder = ui.SemanticsUpdateBuilder(); - updateNode( - builder, - transform: Matrix4.identity().toFloat64(), - rect: const ui.Rect.fromLTRB(0, 0, 20, 20), - childrenInHitTestOrder: Int32List.fromList([1]), - childrenInTraversalOrder: Int32List.fromList([1]), - ); - updateNode( - builder, - id: 1, - transform: Matrix4.identity().toFloat64(), - rect: const ui.Rect.fromLTRB(10, 10, 20, 20), - ); + final ui.SemanticsUpdateBuilder builder = ui.SemanticsUpdateBuilder(); + updateNode( + builder, + transform: Matrix4.identity().toFloat64(), + rect: const ui.Rect.fromLTRB(10, 10, 20, 20), + childrenInHitTestOrder: Int32List.fromList([1]), + childrenInTraversalOrder: Int32List.fromList([1]), + ); + updateNode( + builder, + id: 1, + transform: Matrix4.identity().toFloat64(), + rect: const ui.Rect.fromLTRB(0, 0, 5, 5), + ); - owner().updateSemantics(builder.build()); - expectSemanticsTree(owner(), ''' - - - - -'''); + owner().updateSemantics(builder.build()); + expectSemanticsTree(owner(), ''''''); - final DomElement parentElement = owner().semanticsHost.querySelector('flt-semantics')!; - final DomElement container = owner().semanticsHost.querySelector('flt-semantics-container')!; + final DomElement parentElement = owner().semanticsHost.querySelector('flt-semantics')!; + final DomElement childElement = owner().semanticsHost.querySelector('#flt-semantic-node-1')!; - if (isMacOrIOS) { - expect(parentElement.style.top, '0px'); - expect(parentElement.style.left, '0px'); - expect(container.style.top, '0px'); - expect(container.style.left, '0px'); - } else { - expect(parentElement.style.top, ''); - expect(parentElement.style.left, ''); - expect(container.style.top, ''); - expect(container.style.left, ''); - } - expect(parentElement.style.transform, ''); - expect(parentElement.style.transformOrigin, ''); - expect(container.style.transform, ''); - expect(container.style.transformOrigin, ''); + expect(parentElement.style.transform, 'matrix(1, 0, 0, 1, 10, 10)'); + if (isSafari) { + // macOS 13 returns different values than macOS 12. + expect( + parentElement.style.transformOrigin, + anyOf(contains('0px 0px 0px'), contains('0px 0px')), + ); + expect( + childElement.style.transformOrigin, + anyOf(contains('0px 0px 0px'), contains('0px 0px')), + ); + } else { + expect(parentElement.style.transformOrigin, '0px 0px 0px'); + expect(childElement.style.transformOrigin, '0px 0px 0px'); + } + expect(childElement.style.transform, 'matrix(1, 0, 0, 1, -10, -10)'); + expect(childElement.style.left == '0px' || childElement.style.left == '', isTrue); + expect(childElement.style.top == '0px' || childElement.style.top == '', isTrue); - semantics().semanticsEnabled = false; - }); + final ui.SemanticsUpdateBuilder builder2 = ui.SemanticsUpdateBuilder(); + + updateNode( + builder2, + transform: Matrix4.identity().toFloat64(), + rect: const ui.Rect.fromLTRB(33, 33, 20, 20), + childrenInHitTestOrder: Int32List.fromList([1]), + childrenInTraversalOrder: Int32List.fromList([1]), + ); + + owner().updateSemantics(builder2.build()); + expectSemanticsTree(owner(), ''''''); + + expect(parentElement.style.transform, 'matrix(1, 0, 0, 1, 33, 33)'); + if (isSafari) { + // macOS 13 returns different values than macOS 12. + expect( + parentElement.style.transformOrigin, + anyOf(contains('0px 0px 0px'), contains('0px 0px')), + ); + expect( + childElement.style.transformOrigin, + anyOf(contains('0px 0px 0px'), contains('0px 0px')), + ); + } else { + expect(parentElement.style.transformOrigin, '0px 0px 0px'); + expect(childElement.style.transformOrigin, '0px 0px 0px'); + } + expect(childElement.style.transform, 'matrix(1, 0, 0, 1, -33, -33)'); + expect(childElement.style.left == '0px' || childElement.style.left == '', isTrue); + expect(childElement.style.top == '0px' || childElement.style.top == '', isTrue); + + semantics().semanticsEnabled = false; + }, + ); test('renders in traversal order, hit-tests in reverse z-index order', () async { semantics() @@ -1118,12 +1126,10 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); } @@ -1138,12 +1144,10 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); } @@ -1158,12 +1162,10 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); } @@ -1178,12 +1180,10 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); } @@ -1207,10 +1207,8 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); final DomElement root = owner().semanticsHost.querySelector('#flt-semantic-node-0')!; @@ -1243,10 +1241,8 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); final DomElement root = owner().semanticsHost.querySelector('#flt-semantic-node-0')!; @@ -1254,7 +1250,6 @@ void _testContainer() { semantics().semanticsEnabled = false; }); - test('container can be opaque if it is a text field', () async { semantics() ..debugOverrideTimestampFunction(() => _testTime) @@ -1274,10 +1269,8 @@ void _testContainer() { expectSemanticsTree(owner(), ''' - - '''); final DomElement root = owner().semanticsHost.querySelector('#flt-semantic-node-0')!; @@ -1318,20 +1311,14 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - - - - - '''); expect( @@ -1358,15 +1345,11 @@ void _testContainer() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - - - '''); expect(owner().debugSemanticsTree!.keys.toList(), unorderedEquals([0, 1, 3, 4, 6])); @@ -1452,9 +1435,7 @@ void _testVerticalScrolling() { expectSemanticsTree(owner(), ''' - - '''); final DomElement scrollable = findScrollable(owner()); @@ -1508,11 +1489,9 @@ void _testVerticalScrolling() { expectSemanticsTree(owner(), ''' - - '''); final DomElement scrollable = owner().debugSemanticsTree![0]!.element; @@ -1589,11 +1568,9 @@ void _testVerticalScrolling() { expectSemanticsTree(owner(), ''' - - '''); final DomElement scrollable = owner().debugSemanticsTree![0]!.element; @@ -1679,9 +1656,7 @@ void _testHorizontalScrolling() { expectSemanticsTree(owner(), ''' - - '''); final DomElement scrollable = findScrollable(owner()); @@ -1735,11 +1710,9 @@ void _testHorizontalScrolling() { expectSemanticsTree(owner(), ''' - - '''); final DomElement scrollable = findScrollable(owner()); @@ -2294,10 +2267,8 @@ void _testCheckables() { expectSemanticsTree(owner(), ''' - - '''); @@ -2395,11 +2366,9 @@ void _testSelectables() { expectSemanticsTree(owner(), ''' - - '''); @@ -2424,11 +2393,9 @@ void _testSelectables() { expectSemanticsTree(owner(), ''' - - '''); @@ -2493,11 +2460,9 @@ void _testExpandables() { expectSemanticsTree(owner(), ''' - - '''); @@ -2522,11 +2487,9 @@ void _testExpandables() { expectSemanticsTree(owner(), ''' - - '''); @@ -2780,9 +2743,7 @@ void _testTappable() { expectSemanticsTree(owner(), ''' - - '''); @@ -2873,9 +2834,7 @@ void _testImage() { expectSemanticsTree(owner(), ''' - - '''); semantics().semanticsEnabled = false; @@ -2925,9 +2884,7 @@ void _testImage() { expectSemanticsTree(owner(), ''' - - '''); semantics().semanticsEnabled = false; @@ -3144,11 +3101,9 @@ void _testPlatformView() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - - '''); final DomElement root = owner().semanticsHost.querySelector('#flt-semantic-node-0')!; @@ -3242,7 +3197,7 @@ void _testGroup() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - + '''); semantics().semanticsEnabled = false; @@ -3274,7 +3229,7 @@ void _testRoute() { owner().updateSemantics(builder.build()); expectSemanticsTree(owner(), ''' - + '''); expect(owner().debugSemanticsTree![0]!.semanticRole?.kind, EngineSemanticsRole.route); @@ -3313,7 +3268,7 @@ void _testRoute() { // But still sets the dialog role. expectSemanticsTree(owner(), ''' - + '''); expect(owner().debugSemanticsTree![0]!.semanticRole?.kind, EngineSemanticsRole.route); @@ -3345,13 +3300,9 @@ void _testRoute() { expectSemanticsTree(owner(), ''' - - $label - - '''); } @@ -3411,13 +3362,9 @@ void _testRoute() { expectSemanticsTree(owner(), ''' - - Hello - - '''); @@ -3594,16 +3541,12 @@ void _testRoute() { tester.expectSemantics(''' - - Heading Click me! - - '''); final DomElement span = owner().debugSemanticsTree![2]!.element.querySelectorAll('span').single; @@ -3703,13 +3646,9 @@ void _testDialogs() { expectSemanticsTree(owner(), ''' - - $label - - '''); } @@ -3868,9 +3807,7 @@ void _testFocusable() { expectSemanticsTree(owner(), ''' - focusable text - '''); @@ -4261,11 +4198,9 @@ void _testRequirable() { expectSemanticsTree(owner(), ''' - - '''); @@ -4290,11 +4225,9 @@ void _testRequirable() { expectSemanticsTree(owner(), ''' - - '''); @@ -4305,11 +4238,9 @@ void _testRequirable() { expectSemanticsTree(owner(), ''' - - '''); diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_text_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_text_test.dart index ccb7aec643..12cb5619f8 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_text_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_text_test.dart @@ -110,9 +110,7 @@ Future testMain() async { expectSemanticsTree(owner(), ''' - I am a child - '''); semantics().semanticsEnabled = false; @@ -159,9 +157,7 @@ Future testMain() async { expectSemanticsTree(owner(), ''' - I am a child - '''); }