-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] better class names for semantics #54070
Conversation
ditman
left a comment
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.
I understand the SemanticObject is the glue that controls the rest, but there's a lot of magic that is happening in semantic object (checking type, need for updates, etc...) that probably should be delegated to the SemanticRole that it's wrapping? Isn't the _getSemanticRoleId() method a little bit weird, or having an updateSelf that grows potentially unbounded (at least linearly with the types of semantics?)
That's probably a bigger refactor. The renaming LGTM other than what we've discussed!
| /// [ui.SemanticsFlag.isInMutuallyExclusiveGroup], [ui.SemanticsFlag.isToggled], | ||
| /// [ui.SemanticsFlag.hasToggledState] | ||
| class Checkable extends PrimaryRoleManager { | ||
| class Checkable extends SemanticRole { |
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.
| void _setDefaultFocus() { | ||
| semanticsObject.visitDepthFirstInTraversalOrder((SemanticsObject node) { | ||
| final PrimaryRoleManager? roleManager = node.primaryRole; | ||
| final SemanticRole? roleManager = node.semanticRole; |
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.
Consider doing a pass renaming these roleManager names. They don't map very well to what they contain anymore, now that the "Manager" name is going away from this class hierarchy.
| : 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 { |
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.
I understand that Image clashes with other 47 classes in the engine, but... should all the extends SemanticRole be SomethingSomethingSemanticRole, just for consistency of everything inside "engine/semantics"?
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.
Done (using the Semantic* prefix)
| SemanticRole? semanticRole; | ||
|
|
||
| PrimaryRole _getPrimaryRoleIdentifier() { | ||
| SemanticRoleId _getSemanticRoleId() { |
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.
Should this be a SemanticRole.kind that every SemanticRole needs to override?
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.
Done. Made it SemanticRoleKind.
| DomElement get element => primaryRole!.element; | ||
| DomElement get element => semanticRole!.element; |
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.
The class SemanticObject looks a little bit too complicated, shouldn't each SemanticRole/Behavior know how to update and identify itself? Is this class doing too much, does it need love? Is it needed?
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.
SemanticRole can change, but a SemanticObject is persistent for the entire lifecycle of the node. So for now we need both. However, we can revisit who's responsible for what, since both objects are 1:1 with the node. For now, I'm keeping this PR to non-functional changes only, just renames and deletion of dead code.
| } | ||
|
|
||
| PrimaryRoleManager _createPrimaryRole(PrimaryRole role) { | ||
| SemanticRole _createSemanticRole(SemanticRoleId role) { |
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 probably only used from within the class, but this probably should be factory (or at least static)? (Even though it needs "this" to build itself, ouch)
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.
Can't be static. It uses this. But we could revisit this. Maybe sealed classes can help clean this up.
…ions) (#152305) Manual roll requested by [email protected] flutter/engine@eb8fac2...7473782 2024-07-25 [email protected] [web] better class names for semantics (flutter/engine#54070) 2024-07-25 [email protected] Disable FlutterMetalLayer by default. (flutter/engine#54095) 2024-07-25 [email protected] Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092) 2024-07-25 [email protected] Remove incorrect line (flutter/engine#54021) 2024-07-24 [email protected] [et] Better RBE defaults (flutter/engine#54059) 2024-07-24 [email protected] Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091) 2024-07-24 [email protected] [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086) 2024-07-24 [email protected] Roll Skia from 54d1434637a1 to 55ecdde3a5fa (3 revisions) (flutter/engine#54089) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ions) (flutter#152305) Manual roll requested by [email protected] flutter/engine@eb8fac2...7473782 2024-07-25 [email protected] [web] better class names for semantics (flutter/engine#54070) 2024-07-25 [email protected] Disable FlutterMetalLayer by default. (flutter/engine#54095) 2024-07-25 [email protected] Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092) 2024-07-25 [email protected] Remove incorrect line (flutter/engine#54021) 2024-07-24 [email protected] [et] Better RBE defaults (flutter/engine#54059) 2024-07-24 [email protected] Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091) 2024-07-24 [email protected] [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086) 2024-07-24 [email protected] Roll Skia from 54d1434637a1 to 55ecdde3a5fa (3 revisions) (flutter/engine#54089) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ions) (flutter#152305) Manual roll requested by [email protected] flutter/engine@eb8fac2...7473782 2024-07-25 [email protected] [web] better class names for semantics (flutter/engine#54070) 2024-07-25 [email protected] Disable FlutterMetalLayer by default. (flutter/engine#54095) 2024-07-25 [email protected] Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092) 2024-07-25 [email protected] Remove incorrect line (flutter/engine#54021) 2024-07-24 [email protected] [et] Better RBE defaults (flutter/engine#54059) 2024-07-24 [email protected] Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091) 2024-07-24 [email protected] [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086) 2024-07-24 [email protected] Roll Skia from 54d1434637a1 to 55ecdde3a5fa (3 revisions) (flutter/engine#54089) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
A few non-functional clean-ups in semantics:
RoleManagertoSemanticBehavior.PrimaryRoleManagertoSemanticRole.Roleenum. Move the enum docs into the respective classes.Why?
Previous naming was confusing. It's not clear what the difference is between a "role manager" and a "primary role manager". The word "manager" is a meaningless addition; the
Semantic*prefix is much more meaningful. TheRoleenum was only used for tests, but tests can just useSemanticRole.runtimeType.New state of the world
After this PR the semantics system has "objects" (class
SemanticsObject), "roles" (classSemanticRole), and "behaviors" (classSemanticBehavior).SemanticNode. It lives as long as the semantic node does, and provides basic functionality that's common across all nodes.ButtonandCheckableroles use theTappablebehavior. This is why there's a many-to-many relationship between roles and behaviors.Or in entity relationship terms:
--- title: Semantic object relationships --- erDiagram SemanticsNode ||--|| SemanticsObject : managed-by SemanticsObject ||--o{ SemanticRole : has-a SemanticRole }o--o{ SemanticBehavior : has