-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] better class names for semantics #54070
Changes from 4 commits
42cb58e
e939472
0f85a56
06e8909
fea58ea
29a8c76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,10 @@ import '../dom.dart'; | |
| import '../semantics.dart'; | ||
| import '../util.dart'; | ||
|
|
||
| /// Provides accessibility for dialogs. | ||
| /// | ||
| /// See also [Role.dialog]. | ||
| class Dialog extends PrimaryRoleManager { | ||
| Dialog(SemanticsObject semanticsObject) : super.blank(PrimaryRole.dialog, semanticsObject) { | ||
| // The following secondary roles can coexist with dialog. Generic `RouteName` | ||
| /// Provides accessibility for routes, including dialogs and pop-up menus. | ||
| class Dialog extends SemanticRole { | ||
| Dialog(SemanticsObject semanticsObject) : super.blank(SemanticRoleId.dialog, semanticsObject) { | ||
| // The following behaviors can coexist with dialog. Generic `RouteName` | ||
| // and `LabelAndValue` are not used by this role because when the dialog | ||
| // names its own route an `aria-label` is used instead of `aria-describedby`. | ||
| addFocusManagement(); | ||
|
|
@@ -39,7 +37,7 @@ class Dialog extends PrimaryRoleManager { | |
|
|
||
| void _setDefaultFocus() { | ||
| semanticsObject.visitDepthFirstInTraversalOrder((SemanticsObject node) { | ||
| final PrimaryRoleManager? roleManager = node.primaryRole; | ||
| final SemanticRole? roleManager = node.semanticRole; | ||
|
||
| if (roleManager == null) { | ||
| return true; | ||
| } | ||
|
|
@@ -100,11 +98,15 @@ class Dialog extends PrimaryRoleManager { | |
| } | ||
|
|
||
| /// Supplies a description for the nearest ancestor [Dialog]. | ||
| class RouteName extends RoleManager { | ||
| RouteName( | ||
| SemanticsObject semanticsObject, | ||
| PrimaryRoleManager owner, | ||
| ) : super(Role.routeName, semanticsObject, owner); | ||
| /// | ||
| /// This role is assigned to nodes that have `namesRoute` set but not | ||
| /// `scopesRoute`. When both flags are set the node only gets the [Dialog] role. | ||
| /// | ||
| /// If the ancestor dialog is missing, this role has no effect. It is up to the | ||
| /// framework, widget, and app authors to make sure a route name is scoped under | ||
| /// a route. | ||
| class RouteName extends SemanticBehavior { | ||
| RouteName(super.semanticsObject, super.owner); | ||
|
|
||
| Dialog? _dialog; | ||
|
|
||
|
|
@@ -143,11 +145,11 @@ class RouteName extends RoleManager { | |
|
|
||
| void _lookUpNearestAncestorDialog() { | ||
| SemanticsObject? parent = semanticsObject.parent; | ||
| while (parent != null && parent.primaryRole?.role != PrimaryRole.dialog) { | ||
| while (parent != null && parent.semanticRole?.role != SemanticRoleId.dialog) { | ||
| parent = parent.parent; | ||
| } | ||
| if (parent != null && parent.primaryRole?.role == PrimaryRole.dialog) { | ||
| _dialog = parent.primaryRole! as Dialog; | ||
| if (parent != null && parent.semanticRole?.role == SemanticRoleId.dialog) { | ||
| _dialog = parent.semanticRole! as Dialog; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,11 @@ import 'semantics.dart'; | |
| /// Uses aria img role to convey this semantic information to the element. | ||
| /// | ||
| /// Screen-readers takes advantage of "aria-label" to describe the visual. | ||
| class ImageRoleManager extends PrimaryRoleManager { | ||
| ImageRoleManager(SemanticsObject semanticsObject) | ||
| : super.blank(PrimaryRole.image, semanticsObject) { | ||
| // The following secondary roles can coexist with images. `LabelAndValue` is | ||
| // not used because this role manager uses special auxiliary elements to | ||
| class ImageSemanticRole extends SemanticRole { | ||
|
||
| ImageSemanticRole(SemanticsObject semanticsObject) | ||
| : super.blank(SemanticRoleId.image, semanticsObject) { | ||
| // The following behaviors can coexist with images. `LabelAndValue` is | ||
| // not used because this behavior uses special auxiliary elements to | ||
| // supply ARIA labels. | ||
| // TODO(yjbanov): reevaluate usage of aux elements, https://github.com/flutter/flutter/issues/129317 | ||
| addFocusManagement(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed much better. It's a shame that the name of the top-level classes sound like java interfaces (*-able), but the alternative (
CheckableSemanticRole) is probably too verbose?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made all concrete role type names use the
Semantic*prefix. Looks much better now.