Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
role ID => role kind
  • Loading branch information
yjbanov committed Jul 25, 2024
commit fea58ea7907de84c7bed6a42271c432ddd94f88d
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/checkable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Checkable extends SemanticRole {
Checkable(SemanticsObject semanticsObject)
: _kind = _checkableKindFromSemanticsFlag(semanticsObject),
super.withBasics(
SemanticRoleId.checkable,
SemanticRoleKind.checkable,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
) {
Expand Down
12 changes: 6 additions & 6 deletions lib/web_ui/lib/src/engine/semantics/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../util.dart';

/// Provides accessibility for routes, including dialogs and pop-up menus.
class Dialog extends SemanticRole {
Dialog(SemanticsObject semanticsObject) : super.blank(SemanticRoleId.dialog, semanticsObject) {
Dialog(SemanticsObject semanticsObject) : super.blank(SemanticRoleKind.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`.
Expand Down Expand Up @@ -37,14 +37,14 @@ class Dialog extends SemanticRole {

void _setDefaultFocus() {
semanticsObject.visitDepthFirstInTraversalOrder((SemanticsObject node) {
final SemanticRole? roleManager = node.semanticRole;
if (roleManager == null) {
final SemanticRole? role = node.semanticRole;
if (role == null) {
return true;
}

// If the node does not take focus (e.g. focusing on it does not make
// sense at all). Despair not. Keep looking.
final bool didTakeFocus = roleManager.focusAsRouteDefault();
final bool didTakeFocus = role.focusAsRouteDefault();
return !didTakeFocus;
});
}
Expand Down Expand Up @@ -145,10 +145,10 @@ class RouteName extends SemanticBehavior {

void _lookUpNearestAncestorDialog() {
SemanticsObject? parent = semanticsObject.parent;
while (parent != null && parent.semanticRole?.role != SemanticRoleId.dialog) {
while (parent != null && parent.semanticRole?.kind != SemanticRoleKind.dialog) {
parent = parent.parent;
}
if (parent != null && parent.semanticRole?.role == SemanticRoleId.dialog) {
if (parent != null && parent.semanticRole?.kind == SemanticRoleKind.dialog) {
_dialog = parent.semanticRole! as Dialog;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/heading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'semantics.dart';
/// level (h1 ... h6).
class Heading extends SemanticRole {
Heading(SemanticsObject semanticsObject)
: super.blank(SemanticRoleId.heading, semanticsObject) {
: super.blank(SemanticRoleKind.heading, semanticsObject) {
addFocusManagement();
addLiveRegion();
addRouteName();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'semantics.dart';
/// Screen-readers takes advantage of "aria-label" to describe the visual.
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)

ImageSemanticRole(SemanticsObject semanticsObject)
: super.blank(SemanticRoleId.image, semanticsObject) {
: super.blank(SemanticRoleKind.image, semanticsObject) {
// The following behaviors can coexist with images. `LabelAndValue` is
// not used because this behavior uses special auxiliary elements to
// supply ARIA labels.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/incrementable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'semantics.dart';
class Incrementable extends SemanticRole {
Incrementable(SemanticsObject semanticsObject)
: _focusManager = AccessibilityFocusManager(semanticsObject.owner),
super.blank(SemanticRoleId.incrementable, semanticsObject) {
super.blank(SemanticRoleKind.incrementable, semanticsObject) {
// The following generic roles can coexist with incrementables. Generic focus
// management is not used by this role because the root DOM element is not
// the one being focused on, but the internal `<input>` element.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../semantics.dart';
/// Provides accessibility for links.
class Link extends SemanticRole {
Link(SemanticsObject semanticsObject) : super.withBasics(
SemanticRoleId.link,
SemanticRoleKind.link,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.domText,
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'semantics.dart';
class PlatformViewSemanticRole extends SemanticRole {
PlatformViewSemanticRole(SemanticsObject semanticsObject)
: super.withBasics(
SemanticRoleId.platformView,
SemanticRoleKind.platformView,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import 'package:ui/ui.dart' as ui;
class Scrollable extends SemanticRole {
Scrollable(SemanticsObject semanticsObject)
: super.withBasics(
SemanticRoleId.scrollable,
SemanticRoleKind.scrollable,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
) {
Expand Down
66 changes: 33 additions & 33 deletions lib/web_ui/lib/src/engine/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class SemanticsNodeUpdate {
///
/// Each value corresponds to the most specific role a semantics node plays in
/// the semantics tree.
enum SemanticRoleId {
enum SemanticRoleKind {
/// Supports incrementing and/or decrementing its value.
incrementable,

Expand Down Expand Up @@ -414,7 +414,7 @@ abstract class SemanticRole {
///
/// If `labelRepresentation` is true, configures the [LabelAndValue] role with
/// [LabelAndValue.labelRepresentation] set to true.
SemanticRole.withBasics(this.role, this.semanticsObject, { required LabelRepresentation preferredLabelRepresentation }) {
SemanticRole.withBasics(this.kind, this.semanticsObject, { required LabelRepresentation preferredLabelRepresentation }) {
element = _initElement(createElement(), semanticsObject);
addFocusManagement();
addLiveRegion();
Expand All @@ -427,14 +427,14 @@ abstract class SemanticRole {
/// Use this constructor for highly specialized cases where
/// [SemanticRole.withBasics] does not work, for example when the default focus
/// management intereferes with the widget's functionality.
SemanticRole.blank(this.role, this.semanticsObject) {
SemanticRole.blank(this.kind, this.semanticsObject) {
element = _initElement(createElement(), semanticsObject);
}

late final DomElement element;

/// The role identifier.
final SemanticRoleId role;
/// The kind of the role that this .
final SemanticRoleKind kind;

/// The semantics object managed by this role.
final SemanticsObject semanticsObject;
Expand Down Expand Up @@ -628,7 +628,7 @@ abstract class SemanticRole {
/// A role used when a more specific role couldn't be assigned to the node.
final class GenericRole extends SemanticRole {
GenericRole(SemanticsObject semanticsObject) : super.withBasics(
SemanticRoleId.generic,
SemanticRoleKind.generic,
semanticsObject,
// Prefer sized span because if this is a leaf it is frequently a Text widget.
// But if it turns out to be a container, then LabelAndValue will automatically
Expand Down Expand Up @@ -1634,58 +1634,58 @@ class SemanticsObject {
/// semantics flags and actions.
SemanticRole? semanticRole;

SemanticRoleId _getSemanticRoleId() {
SemanticRoleKind _getSemanticRoleKind() {
// The most specific role should take precedence.
if (isPlatformView) {
return SemanticRoleId.platformView;
return SemanticRoleKind.platformView;
} else if (isHeading) {
return SemanticRoleId.heading;
return SemanticRoleKind.heading;
} else if (isTextField) {
return SemanticRoleId.textField;
return SemanticRoleKind.textField;
} else if (isIncrementable) {
return SemanticRoleId.incrementable;
return SemanticRoleKind.incrementable;
} else if (isVisualOnly) {
return SemanticRoleId.image;
return SemanticRoleKind.image;
} else if (isCheckable) {
return SemanticRoleId.checkable;
return SemanticRoleKind.checkable;
} else if (isButton) {
return SemanticRoleId.button;
return SemanticRoleKind.button;
} else if (isScrollContainer) {
return SemanticRoleId.scrollable;
return SemanticRoleKind.scrollable;
} else if (scopesRoute) {
return SemanticRoleId.dialog;
return SemanticRoleKind.dialog;
} else if (isLink) {
return SemanticRoleId.link;
return SemanticRoleKind.link;
} else {
return SemanticRoleId.generic;
return SemanticRoleKind.generic;
}
}

SemanticRole _createSemanticRole(SemanticRoleId role) {
SemanticRole _createSemanticRole(SemanticRoleKind role) {
return switch (role) {
SemanticRoleId.textField => TextField(this),
SemanticRoleId.scrollable => Scrollable(this),
SemanticRoleId.incrementable => Incrementable(this),
SemanticRoleId.button => Button(this),
SemanticRoleId.checkable => Checkable(this),
SemanticRoleId.dialog => Dialog(this),
SemanticRoleId.image => ImageSemanticRole(this),
SemanticRoleId.platformView => PlatformViewSemanticRole(this),
SemanticRoleId.link => Link(this),
SemanticRoleId.heading => Heading(this),
SemanticRoleId.generic => GenericRole(this),
SemanticRoleKind.textField => TextField(this),
SemanticRoleKind.scrollable => Scrollable(this),
SemanticRoleKind.incrementable => Incrementable(this),
SemanticRoleKind.button => Button(this),
SemanticRoleKind.checkable => Checkable(this),
SemanticRoleKind.dialog => Dialog(this),
SemanticRoleKind.image => ImageSemanticRole(this),
SemanticRoleKind.platformView => PlatformViewSemanticRole(this),
SemanticRoleKind.link => Link(this),
SemanticRoleKind.heading => Heading(this),
SemanticRoleKind.generic => GenericRole(this),
};
}

/// Detects the role that this semantics object corresponds to and asks it to
/// update the DOM.
void _updateRole() {
SemanticRole? currentSemanticRole = semanticRole;
final SemanticRoleId roleId = _getSemanticRoleId();
final SemanticRoleKind kind = _getSemanticRoleKind();
final DomElement? previousElement = semanticRole?.element;

if (currentSemanticRole != null) {
if (currentSemanticRole.role == roleId) {
if (currentSemanticRole.kind == kind) {
// Already has a role assigned and the role is the same as before,
// so simply perform an update.
currentSemanticRole.update();
Expand All @@ -1705,7 +1705,7 @@ class SemanticsObject {
// * (Uncommon) the node changed its role, its previous role was disposed
// of, and now it needs a new one.
if (currentSemanticRole == null) {
currentSemanticRole = _createSemanticRole(roleId);
currentSemanticRole = _createSemanticRole(kind);
semanticRole = currentSemanticRole;
currentSemanticRole.initState();
currentSemanticRole.update();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/tappable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:ui/ui.dart' as ui;
/// Sets the "button" ARIA role.
class Button extends SemanticRole {
Button(SemanticsObject semanticsObject) : super.withBasics(
SemanticRoleId.button,
SemanticRoleKind.button,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.domText,
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
/// used to detect text box invocation. This is because Safari issues touch
/// events even when VoiceOver is enabled.
class TextField extends SemanticRole {
TextField(SemanticsObject semanticsObject) : super.blank(SemanticRoleId.textField, semanticsObject) {
TextField(SemanticsObject semanticsObject) : super.blank(SemanticRoleKind.textField, semanticsObject) {
_initializeEditableElement();
}

Expand Down
Loading