Skip to content

Commit 3f691f0

Browse files
authored
[web] Fix semantic node order for webkit (#23601)
1 parent a8a7534 commit 3f691f0

File tree

3 files changed

+157
-119
lines changed

3 files changed

+157
-119
lines changed

lib/web_ui/lib/src/engine/semantics/semantics.dart

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -853,25 +853,9 @@ class SemanticsObject {
853853
hasIdentityTransform &&
854854
verticalContainerAdjustment == 0.0 &&
855855
horizontalContainerAdjustment == 0.0) {
856-
if (isDesktop) {
857-
element.style
858-
..removeProperty('transform-origin')
859-
..removeProperty('transform');
860-
} else {
861-
element.style
862-
..removeProperty('top')
863-
..removeProperty('left');
864-
}
856+
_resetElementOffsets(element);
865857
if (containerElement != null) {
866-
if (isDesktop) {
867-
containerElement.style
868-
..removeProperty('transform-origin')
869-
..removeProperty('transform');
870-
} else {
871-
containerElement.style
872-
..removeProperty('top')
873-
..removeProperty('left');
874-
}
858+
_resetElementOffsets(containerElement);
875859
}
876860
return;
877861
}
@@ -905,11 +889,15 @@ class SemanticsObject {
905889
effectiveTransformIsIdentity = false;
906890
}
907891

908-
if (!effectiveTransformIsIdentity) {
892+
if (!effectiveTransformIsIdentity || isMacOrIOS) {
893+
if (effectiveTransformIsIdentity) {
894+
effectiveTransform = Matrix4.identity();
895+
}
909896
if (isDesktop) {
910897
element.style
911898
..transformOrigin = '0 0 0'
912-
..transform = matrix4ToCssTransform(effectiveTransform);
899+
..transform = (effectiveTransformIsIdentity ? 'translate(0px 0px 0px)'
900+
: matrix4ToCssTransform(effectiveTransform));
913901
} else {
914902
// Mobile screen readers observed to have errors while calculating the
915903
// semantics focus borders if css `transform` properties are used.
@@ -927,20 +915,13 @@ class SemanticsObject {
927915
..height = '${rect.height}px';
928916
}
929917
} else {
918+
_resetElementOffsets(element);
930919
// TODO: https://github.com/flutter/flutter/issues/73347
931-
if (isDesktop) {
932-
element.style
933-
..removeProperty('transform-origin')
934-
..removeProperty('transform');
935-
} else {
936-
element.style
937-
..removeProperty('top')
938-
..removeProperty('left');
939-
}
940920
}
941921

942922
if (containerElement != null) {
943923
if (!hasZeroRectOffset ||
924+
isMacOrIOS ||
944925
verticalContainerAdjustment != 0.0 ||
945926
horizontalContainerAdjustment != 0.0) {
946927
final double translateX = -_rect!.left + horizontalContainerAdjustment;
@@ -955,15 +936,33 @@ class SemanticsObject {
955936
..left = '${translateX}px';
956937
}
957938
} else {
958-
if (isDesktop) {
959-
containerElement.style
960-
..removeProperty('transform-origin')
961-
..removeProperty('transform');
962-
} else {
963-
containerElement.style
964-
..removeProperty('top')
965-
..removeProperty('left');
966-
}
939+
_resetElementOffsets(containerElement);
940+
}
941+
}
942+
}
943+
944+
// On Mac OS and iOS, VoiceOver requires left=0 top=0 value to correctly
945+
// handle order. See https://github.com/flutter/flutter/issues/73347.
946+
static void _resetElementOffsets(html.Element element) {
947+
if (isMacOrIOS) {
948+
if (isDesktop) {
949+
element.style
950+
..transformOrigin = '0 0 0'
951+
..transform = 'translate(0px, 0px)';
952+
} else {
953+
element.style
954+
..top = '0px'
955+
..left = '0px';
956+
}
957+
} else {
958+
if (isDesktop) {
959+
element.style
960+
..removeProperty('transform-origin')
961+
..removeProperty('transform');
962+
} else {
963+
element.style
964+
..removeProperty('top')
965+
..removeProperty('left');
967966
}
968967
}
969968
}

lib/web_ui/lib/src/engine/util.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ const Set<String> _genericFontFamilies = <String>{
446446
/// For iOS, default to -apple-system, where it should be available, otherwise
447447
/// default to Arial. BlinkMacSystemFont is used for Chrome on iOS.
448448
final String _fallbackFontFamily =
449-
_isMacOrIOS ? '-apple-system, BlinkMacSystemFont' : 'Arial';
449+
isMacOrIOS ? '-apple-system, BlinkMacSystemFont' : 'Arial';
450450

451-
bool get _isMacOrIOS =>
451+
bool get isMacOrIOS =>
452452
operatingSystem == OperatingSystem.iOs ||
453453
operatingSystem == OperatingSystem.macOs;
454454

@@ -460,7 +460,7 @@ String? canonicalizeFontFamily(String? fontFamily) {
460460
if (_genericFontFamilies.contains(fontFamily)) {
461461
return fontFamily;
462462
}
463-
if (_isMacOrIOS) {
463+
if (isMacOrIOS) {
464464
// Unlike Safari, Chrome on iOS does not correctly fallback to cupertino
465465
// on sans-serif.
466466
// Map to San Francisco Text/Display fonts, use -apple-system,

0 commit comments

Comments
 (0)