Skip to content

Commit ce667ed

Browse files
authored
Reland role merge (#165330)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> the previous pr causes some issue with mobile platform. The change is in second commit ## 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]. <!-- Links --> [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
1 parent c4d8870 commit ce667ed

File tree

3 files changed

+334
-46
lines changed

3 files changed

+334
-46
lines changed

packages/flutter/lib/src/semantics/semantics.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5575,6 +5575,23 @@ class SemanticsConfiguration {
55755575

55765576
bool _hasFlag(SemanticsFlag flag) => (_flags & flag.index) != 0;
55775577

5578+
bool get _hasExplicitRole {
5579+
if (_role != SemanticsRole.none) {
5580+
return true;
5581+
}
5582+
if (_hasFlag(SemanticsFlag.isTextField) ||
5583+
// In non web platforms, the header is a trait.
5584+
(_hasFlag(SemanticsFlag.isHeader) && kIsWeb) ||
5585+
_hasFlag(SemanticsFlag.isSlider) ||
5586+
_hasFlag(SemanticsFlag.isLink) ||
5587+
_hasFlag(SemanticsFlag.scopesRoute) ||
5588+
_hasFlag(SemanticsFlag.isImage) ||
5589+
_hasFlag(SemanticsFlag.isKeyboardKey)) {
5590+
return true;
5591+
}
5592+
return false;
5593+
}
5594+
55785595
// CONFIGURATION COMBINATION LOGIC
55795596

55805597
/// Whether this configuration is compatible with the provided `other`
@@ -5604,6 +5621,9 @@ class SemanticsConfiguration {
56045621
if (_attributedValue.string.isNotEmpty && other._attributedValue.string.isNotEmpty) {
56055622
return false;
56065623
}
5624+
if (_hasExplicitRole && other._hasExplicitRole) {
5625+
return false;
5626+
}
56075627
return true;
56085628
}
56095629

packages/flutter/test/material/search_test.dart

Lines changed: 111 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,61 @@ void main() {
651651
final bool isCupertino =
652652
debugDefaultTargetPlatformOverride == TargetPlatform.iOS ||
653653
debugDefaultTargetPlatformOverride == TargetPlatform.macOS;
654+
final TestSemantics textField =
655+
kIsWeb
656+
? TestSemantics(
657+
flags: <SemanticsFlag>[
658+
SemanticsFlag.isHeader,
659+
if (!isCupertino) SemanticsFlag.namesRoute,
660+
],
661+
children: <TestSemantics>[
662+
TestSemantics(
663+
id: 9,
664+
flags: <SemanticsFlag>[
665+
SemanticsFlag.isTextField,
666+
SemanticsFlag.hasEnabledState,
667+
SemanticsFlag.isEnabled,
668+
SemanticsFlag.isFocused,
669+
],
670+
actions: <SemanticsAction>[
671+
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
672+
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
673+
SemanticsAction.tap,
674+
SemanticsAction.focus,
675+
SemanticsAction.setSelection,
676+
SemanticsAction.setText,
677+
SemanticsAction.paste,
678+
],
679+
label: 'Search',
680+
textDirection: TextDirection.ltr,
681+
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
682+
),
683+
],
684+
)
685+
: TestSemantics(
686+
id: 9,
687+
flags: <SemanticsFlag>[
688+
SemanticsFlag.isTextField,
689+
SemanticsFlag.hasEnabledState,
690+
SemanticsFlag.isEnabled,
691+
SemanticsFlag.isFocused,
692+
SemanticsFlag.isHeader,
693+
if (!isCupertino) SemanticsFlag.namesRoute,
694+
],
695+
actions: <SemanticsAction>[
696+
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
697+
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
698+
SemanticsAction.tap,
699+
SemanticsAction.focus,
700+
SemanticsAction.setSelection,
701+
SemanticsAction.setText,
702+
SemanticsAction.paste,
703+
],
704+
label: 'Search',
705+
textDirection: TextDirection.ltr,
706+
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
707+
);
708+
654709
return TestSemantics.root(
655710
children: <TestSemantics>[
656711
TestSemantics(
@@ -688,29 +743,7 @@ void main() {
688743
tooltip: 'Back',
689744
textDirection: TextDirection.ltr,
690745
),
691-
TestSemantics(
692-
id: 9,
693-
flags: <SemanticsFlag>[
694-
SemanticsFlag.isTextField,
695-
SemanticsFlag.hasEnabledState,
696-
SemanticsFlag.isEnabled,
697-
SemanticsFlag.isFocused,
698-
SemanticsFlag.isHeader,
699-
if (!isCupertino) SemanticsFlag.namesRoute,
700-
],
701-
actions: <SemanticsAction>[
702-
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
703-
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
704-
SemanticsAction.tap,
705-
SemanticsAction.focus,
706-
SemanticsAction.setSelection,
707-
SemanticsAction.setText,
708-
SemanticsAction.paste,
709-
],
710-
label: 'Search',
711-
textDirection: TextDirection.ltr,
712-
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
713-
),
746+
textField,
714747
TestSemantics(
715748
id: 10,
716749
label: 'Bottom',
@@ -818,6 +851,60 @@ void main() {
818851
final bool isCupertino =
819852
debugDefaultTargetPlatformOverride == TargetPlatform.iOS ||
820853
debugDefaultTargetPlatformOverride == TargetPlatform.macOS;
854+
final TestSemantics textField =
855+
kIsWeb
856+
? TestSemantics(
857+
flags: <SemanticsFlag>[
858+
SemanticsFlag.isHeader,
859+
if (!isCupertino) SemanticsFlag.namesRoute,
860+
],
861+
children: <TestSemantics>[
862+
TestSemantics(
863+
id: 11,
864+
flags: <SemanticsFlag>[
865+
SemanticsFlag.isTextField,
866+
SemanticsFlag.hasEnabledState,
867+
SemanticsFlag.isEnabled,
868+
SemanticsFlag.isFocused,
869+
],
870+
actions: <SemanticsAction>[
871+
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
872+
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
873+
SemanticsAction.tap,
874+
SemanticsAction.focus,
875+
SemanticsAction.setSelection,
876+
SemanticsAction.setText,
877+
SemanticsAction.paste,
878+
],
879+
label: 'Search',
880+
textDirection: TextDirection.ltr,
881+
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
882+
),
883+
],
884+
)
885+
: TestSemantics(
886+
id: 11,
887+
flags: <SemanticsFlag>[
888+
SemanticsFlag.isTextField,
889+
SemanticsFlag.hasEnabledState,
890+
SemanticsFlag.isEnabled,
891+
SemanticsFlag.isFocused,
892+
SemanticsFlag.isHeader,
893+
if (!isCupertino) SemanticsFlag.namesRoute,
894+
],
895+
actions: <SemanticsAction>[
896+
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
897+
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
898+
SemanticsAction.tap,
899+
SemanticsAction.focus,
900+
SemanticsAction.setSelection,
901+
SemanticsAction.setText,
902+
SemanticsAction.paste,
903+
],
904+
label: 'Search',
905+
textDirection: TextDirection.ltr,
906+
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
907+
);
821908
return TestSemantics.root(
822909
children: <TestSemantics>[
823910
TestSemantics(
@@ -852,29 +939,7 @@ void main() {
852939
tooltip: 'Back',
853940
textDirection: TextDirection.ltr,
854941
),
855-
TestSemantics(
856-
id: 11,
857-
flags: <SemanticsFlag>[
858-
SemanticsFlag.isTextField,
859-
SemanticsFlag.hasEnabledState,
860-
SemanticsFlag.isEnabled,
861-
SemanticsFlag.isFocused,
862-
SemanticsFlag.isHeader,
863-
if (!isCupertino) SemanticsFlag.namesRoute,
864-
],
865-
actions: <SemanticsAction>[
866-
if (isDesktop) SemanticsAction.didGainAccessibilityFocus,
867-
if (isDesktop) SemanticsAction.didLoseAccessibilityFocus,
868-
SemanticsAction.tap,
869-
SemanticsAction.focus,
870-
SemanticsAction.setSelection,
871-
SemanticsAction.setText,
872-
SemanticsAction.paste,
873-
],
874-
label: 'Search',
875-
textDirection: TextDirection.ltr,
876-
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
877-
),
942+
textField,
878943
TestSemantics(id: 14, label: 'Bottom', textDirection: TextDirection.ltr),
879944
],
880945
),

0 commit comments

Comments
 (0)