Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

[web] better class names for semantics #54070

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Jul 24, 2024

A few non-functional clean-ups in semantics:

  • Rename RoleManager to SemanticBehavior.
  • Rename PrimaryRoleManager to SemanticRole.
  • Remove the Role enum. 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. The Role enum was only used for tests, but tests can just use SemanticRole.runtimeType.

New state of the world

After this PR the semantics system has "objects" (class SemanticsObject), "roles" (class SemanticRole), and "behaviors" (class SemanticBehavior).

  • A semantic object is an object attached to the framework-side SemanticNode. It lives as long as the semantic node does, and provides basic functionality that's common across all nodes.
  • A semantic object has exactly one semantic role. This role is determined from the flags set on the semantic node. Flags can change, causing a semantic object to change its role, which is why these are two separate classes. If an object had just one permanent role, we could combine these classes into one (maybe one day we'll do it, as changing roles dynamically is weird, but that needs major changes in the framework).
  • A semantic role may have zero or more semantic behaviors. A behavior supplies a piece of functionality, such as focusability, clickability/tappability, live regions, etc. A behavior can be shared by multiple roles. For example, both Button and Checkable roles use the Tappable behavior. 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
Loading

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jul 24, 2024
@yjbanov yjbanov requested a review from ditman July 24, 2024 18:41
Copy link
Member

@ditman ditman left a 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!

class Checkable extends PrimaryRoleManager {
class Checkable extends SemanticRole {
Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -39,7 +37,7 @@ class Dialog extends PrimaryRoleManager {

void _setDefaultFocus() {
semanticsObject.visitDepthFirstInTraversalOrder((SemanticsObject node) {
final PrimaryRoleManager? roleManager = node.primaryRole;
final SemanticRole? roleManager = node.semanticRole;
Copy link
Member

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 {
Copy link
Member

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"?

Copy link
Contributor Author

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)


PrimaryRole _getPrimaryRoleIdentifier() {
SemanticRoleId _getSemanticRoleId() {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Made it SemanticRoleKind.

Comment on lines -1188 to +1152
DomElement get element => primaryRole!.element;
DomElement get element => semanticRole!.element;
Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

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)

Copy link
Contributor Author

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.

@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 25, 2024
@auto-submit auto-submit bot merged commit 7473782 into flutter:main Jul 25, 2024
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 25, 2024
…ions) (#152305)

Manual roll requested by zra@google.com

flutter/engine@eb8fac2...7473782

2024-07-25 yjbanov@google.com [web] better class names for semantics (flutter/engine#54070)
2024-07-25 jonahwilliams@google.com Disable FlutterMetalLayer by default. (flutter/engine#54095)
2024-07-25 skia-flutter-autoroll@skia.org Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092)
2024-07-25 gspencergoog@users.noreply.github.com Remove incorrect line (flutter/engine#54021)
2024-07-24 zanderso@users.noreply.github.com [et] Better RBE defaults (flutter/engine#54059)
2024-07-24 skia-flutter-autoroll@skia.org Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091)
2024-07-24 jonahwilliams@google.com [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086)
2024-07-24 skia-flutter-autoroll@skia.org 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 jonahwilliams@google.com,rmistry@google.com,zra@google.com 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
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
…ions) (flutter#152305)

Manual roll requested by zra@google.com

flutter/engine@eb8fac2...7473782

2024-07-25 yjbanov@google.com [web] better class names for semantics (flutter/engine#54070)
2024-07-25 jonahwilliams@google.com Disable FlutterMetalLayer by default. (flutter/engine#54095)
2024-07-25 skia-flutter-autoroll@skia.org Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092)
2024-07-25 gspencergoog@users.noreply.github.com Remove incorrect line (flutter/engine#54021)
2024-07-24 zanderso@users.noreply.github.com [et] Better RBE defaults (flutter/engine#54059)
2024-07-24 skia-flutter-autoroll@skia.org Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091)
2024-07-24 jonahwilliams@google.com [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086)
2024-07-24 skia-flutter-autoroll@skia.org 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 jonahwilliams@google.com,rmistry@google.com,zra@google.com 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
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…ions) (flutter#152305)

Manual roll requested by zra@google.com

flutter/engine@eb8fac2...7473782

2024-07-25 yjbanov@google.com [web] better class names for semantics (flutter/engine#54070)
2024-07-25 jonahwilliams@google.com Disable FlutterMetalLayer by default. (flutter/engine#54095)
2024-07-25 skia-flutter-autoroll@skia.org Roll Dart SDK from 0b3c00feefb1 to 693848f200d7 (1 revision) (flutter/engine#54092)
2024-07-25 gspencergoog@users.noreply.github.com Remove incorrect line (flutter/engine#54021)
2024-07-24 zanderso@users.noreply.github.com [et] Better RBE defaults (flutter/engine#54059)
2024-07-24 skia-flutter-autoroll@skia.org Roll Skia from 55ecdde3a5fa to 746d444f3efd (2 revisions) (flutter/engine#54091)
2024-07-24 jonahwilliams@google.com [iOS] Switch to FlutterMetalLayer by default. (flutter/engine#54086)
2024-07-24 skia-flutter-autoroll@skia.org 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 jonahwilliams@google.com,rmistry@google.com,zra@google.com 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants