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
consistent naming of concrete role types
  • Loading branch information
yjbanov committed Jul 25, 2024
commit 29a8c768a0e1420461fb5868b3a7400cb9d33b03
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/checkable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ _CheckableKind _checkableKindFromSemanticsFlag(
/// See also [ui.SemanticsFlag.hasCheckedState], [ui.SemanticsFlag.isChecked],
/// [ui.SemanticsFlag.isInMutuallyExclusiveGroup], [ui.SemanticsFlag.isToggled],
/// [ui.SemanticsFlag.hasToggledState]
class Checkable extends SemanticRole {
Checkable(SemanticsObject semanticsObject)
class SemanticCheckable extends SemanticRole {
SemanticCheckable(SemanticsObject semanticsObject)
: _kind = _checkableKindFromSemanticsFlag(semanticsObject),
super.withBasics(
SemanticRoleKind.checkable,
Expand Down
14 changes: 7 additions & 7 deletions lib/web_ui/lib/src/engine/semantics/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '../semantics.dart';
import '../util.dart';

/// Provides accessibility for routes, including dialogs and pop-up menus.
class Dialog extends SemanticRole {
Dialog(SemanticsObject semanticsObject) : super.blank(SemanticRoleKind.dialog, semanticsObject) {
class SemanticDialog extends SemanticRole {
SemanticDialog(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 @@ -97,18 +97,18 @@ class Dialog extends SemanticRole {
}
}

/// Supplies a description for the nearest ancestor [Dialog].
/// Supplies a description for the nearest ancestor [SemanticDialog].
///
/// 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.
/// `scopesRoute`. When both flags are set the node only gets the [SemanticDialog] 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;
SemanticDialog? _dialog;

@override
void update() {
Expand All @@ -126,7 +126,7 @@ class RouteName extends SemanticBehavior {
}

if (semanticsObject.isLabelDirty) {
final Dialog? dialog = _dialog;
final SemanticDialog? dialog = _dialog;
if (dialog != null) {
// Already attached to a dialog, just update the description.
dialog.describeBy(this);
Expand All @@ -149,7 +149,7 @@ class RouteName extends SemanticBehavior {
parent = parent.parent;
}
if (parent != null && parent.semanticRole?.kind == SemanticRoleKind.dialog) {
_dialog = parent.semanticRole! as Dialog;
_dialog = parent.semanticRole! as SemanticDialog;
}
}
}
8 changes: 4 additions & 4 deletions lib/web_ui/lib/src/engine/semantics/focusable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ enum AccessibilityFocusManagerEvent {
///
/// Unlike [Focusable], which implements focus features on [SemanticsObject]s
/// whose [SemanticsObject.element] is directly focusable, this class can help
/// implementing focus features on custom elements. For example, [Incrementable]
/// uses a custom `<input>` tag internally while its root-level element is not
/// focusable. However, it can still use this class to manage the focus of the
/// internal element.
/// implementing focus features on custom elements. For example,
/// [SemanticIncrementable] uses a custom `<input>` tag internally while its
/// root-level element is not focusable. However, it can still use this class to
/// manage the focus of the internal element.
class AccessibilityFocusManager {
/// Creates a focus manager tied to a specific [EngineSemanticsOwner].
AccessibilityFocusManager(this._owner);
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/heading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'semantics.dart';

/// Renders semantics objects as headings with the corresponding
/// level (h1 ... h6).
class Heading extends SemanticRole {
Heading(SemanticsObject semanticsObject)
class SemanticHeading extends SemanticRole {
SemanticHeading(SemanticsObject semanticsObject)
: super.blank(SemanticRoleKind.heading, semanticsObject) {
addFocusManagement();
addLiveRegion();
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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 ImageSemanticRole extends SemanticRole {
ImageSemanticRole(SemanticsObject semanticsObject)
class SemanticImage extends SemanticRole {
SemanticImage(SemanticsObject 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
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/incrementable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import 'semantics.dart';
/// The input element is disabled whenever the gesture mode switches to pointer
/// events. This is to prevent the browser from taking over drag gestures. Drag
/// gestures must be interpreted by the Flutter framework.
class Incrementable extends SemanticRole {
Incrementable(SemanticsObject semanticsObject)
class SemanticIncrementable extends SemanticRole {
SemanticIncrementable(SemanticsObject semanticsObject)
: _focusManager = AccessibilityFocusManager(semanticsObject.owner),
super.blank(SemanticRoleKind.incrementable, semanticsObject) {
// The following generic roles can coexist with incrementables. Generic focus
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import '../dom.dart';
import '../semantics.dart';

/// Provides accessibility for links.
class Link extends SemanticRole {
Link(SemanticsObject semanticsObject) : super.withBasics(
class SemanticLink extends SemanticRole {
SemanticLink(SemanticsObject semanticsObject) : super.withBasics(
SemanticRoleKind.link,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.domText,
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import 'semantics.dart';
/// See also:
/// * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-owns
/// * https://bugs.webkit.org/show_bug.cgi?id=223798
class PlatformViewSemanticRole extends SemanticRole {
PlatformViewSemanticRole(SemanticsObject semanticsObject)
class SemanticPlatformView extends SemanticRole {
SemanticPlatformView(SemanticsObject semanticsObject)
: super.withBasics(
SemanticRoleKind.platformView,
semanticsObject,
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import 'package:ui/ui.dart' as ui;
/// contents is less than the size of the viewport the browser snaps
/// "scrollTop" back to zero. If there is more content than available in the
/// viewport "scrollTop" may take positive values.
class Scrollable extends SemanticRole {
Scrollable(SemanticsObject semanticsObject)
class SemanticScrollable extends SemanticRole {
SemanticScrollable(SemanticsObject semanticsObject)
: super.withBasics(
SemanticRoleKind.scrollable,
semanticsObject,
Expand Down
28 changes: 14 additions & 14 deletions lib/web_ui/lib/src/engine/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ final class GenericRole extends SemanticRole {
/// Provides a piece of functionality to a [SemanticsObject].
///
/// Semantic behaviors can be shared by multiple types of [SemanticRole]s. For
/// example, [Button] and [Checkable] both use the [Tappable] behavior. If a
/// example, [SemanticButton] and [SemanticCheckable] both use the [Tappable] behavior. If a
/// semantic role needs bespoke functionality, it is simpler to implement it
/// directly in the [SemanticRole] implementation.
///
Expand Down Expand Up @@ -1663,16 +1663,16 @@ class SemanticsObject {

SemanticRole _createSemanticRole(SemanticRoleKind role) {
return switch (role) {
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.textField => SemanticTextField(this),
SemanticRoleKind.scrollable => SemanticScrollable(this),
SemanticRoleKind.incrementable => SemanticIncrementable(this),
SemanticRoleKind.button => SemanticButton(this),
SemanticRoleKind.checkable => SemanticCheckable(this),
SemanticRoleKind.dialog => SemanticDialog(this),
SemanticRoleKind.image => SemanticImage(this),
SemanticRoleKind.platformView => SemanticPlatformView(this),
SemanticRoleKind.link => SemanticLink(this),
SemanticRoleKind.heading => SemanticHeading(this),
SemanticRoleKind.generic => GenericRole(this),
};
}
Expand Down Expand Up @@ -1746,7 +1746,7 @@ class SemanticsObject {

/// Role-specific adjustment of the vertical position of the child container.
///
/// This is used, for example, by the [Scrollable] to compensate for the
/// This is used, for example, by the [SemanticScrollable] to compensate for the
/// `scrollTop` offset in the DOM.
///
/// This field must not be null.
Expand All @@ -1755,7 +1755,7 @@ class SemanticsObject {
/// Role-specific adjustment of the horizontal position of the child
/// container.
///
/// This is used, for example, by the [Scrollable] to compensate for the
/// This is used, for example, by the [SemanticScrollable] to compensate for the
/// `scrollLeft` offset in the DOM.
///
/// This field must not be null.
Expand Down Expand Up @@ -2586,7 +2586,7 @@ AFTER: $description

/// Declares that a semantics node will explicitly request focus.
///
/// This prevents others, [Dialog] in particular, from requesting autofocus,
/// This prevents others, [SemanticDialog] in particular, from requesting autofocus,
/// as focus can only be taken by one element. Explicit focus has higher
/// precedence than autofocus.
void willRequestFocus() {
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/tappable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;

/// Sets the "button" ARIA role.
class Button extends SemanticRole {
Button(SemanticsObject semanticsObject) : super.withBasics(
class SemanticButton extends SemanticRole {
SemanticButton(SemanticsObject semanticsObject) : super.withBasics(
SemanticRoleKind.button,
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.domText,
Expand Down
14 changes: 7 additions & 7 deletions lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
/// The text field whose DOM element is currently used for editing.
///
/// If this field is null, no editing takes place.
TextField? activeTextField;
SemanticTextField? activeTextField;

/// Current input configuration supplied by the "flutter/textinput" channel.
InputConfiguration? inputConfig;
Expand All @@ -66,7 +66,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
///
/// This method must be called after [enable] to name sure that [inputConfig],
/// [onChange], and [onAction] are not null.
void activate(TextField textField) {
void activate(SemanticTextField textField) {
assert(
inputConfig != null && onChange != null && onAction != null,
'"enable" should be called before "enableFromSemantics" and initialize input configuration',
Expand All @@ -91,7 +91,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
///
/// Typically at this point the element loses focus (blurs) and stops being
/// used for editing.
void deactivate(TextField textField) {
void deactivate(SemanticTextField textField) {
if (activeTextField == textField) {
disable();
}
Expand Down Expand Up @@ -167,7 +167,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {

@override
void initializeElementPlacement() {
// Element placement is done by [TextField].
// Element placement is done by [SemanticTextField].
}

@override
Expand All @@ -176,7 +176,7 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {

@override
void updateElementPlacement(EditableTextGeometry textGeometry) {
// Element placement is done by [TextField].
// Element placement is done by [SemanticTextField].
}

EditableTextStyle? _queuedStyle;
Expand Down Expand Up @@ -208,8 +208,8 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
/// browser gestures when in pointer mode. In Safari on iOS pointer events are
/// 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(SemanticRoleKind.textField, semanticsObject) {
class SemanticTextField extends SemanticRole {
SemanticTextField(SemanticsObject semanticsObject) : super.blank(SemanticRoleKind.textField, semanticsObject) {
_initializeEditableElement();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/semantics/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ void _testTextField() {


final SemanticsObject node = owner().debugSemanticsTree![0]!;
final TextField textFieldRole = node.semanticRole! as TextField;
final SemanticTextField textFieldRole = node.semanticRole! as SemanticTextField;
final DomHTMLInputElement inputElement = textFieldRole.editableElement as DomHTMLInputElement;

// TODO(yjbanov): this used to attempt to test that value="hello" but the
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/test/engine/semantics/semantics_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ class SemanticsTester {
return owner.debugSemanticsTree![id]!;
}

/// Locates the [TextField] role of the semantics object with the give [id].
TextField getTextField(int id) {
return getSemanticsObject(id).semanticRole! as TextField;
/// Locates the [SemanticTextField] role of the semantics object with the give [id].
SemanticTextField getTextField(int id) {
return getSemanticsObject(id).semanticRole! as SemanticTextField;
}

void expectSemantics(String semanticsHtml) {
Expand Down
16 changes: 8 additions & 8 deletions lib/web_ui/test/engine/semantics/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void testMain() {
value: 'hi',
isFocused: true,
);
final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;

// ensureInitialized() isn't called prior to calling dispose() here.
// Since we are conditionally calling dispose() on our
Expand Down Expand Up @@ -102,7 +102,7 @@ void testMain() {
// make sure it tests the right things:
// https://github.com/flutter/flutter/issues/147200
final SemanticsObject node = owner().debugSemanticsTree![0]!;
final TextField textFieldRole = node.semanticRole! as TextField;
final SemanticTextField textFieldRole = node.semanticRole! as SemanticTextField;
final DomHTMLInputElement inputElement =
textFieldRole.editableElement as DomHTMLInputElement;
expect(inputElement.tagName.toLowerCase(), 'input');
Expand All @@ -114,7 +114,7 @@ void testMain() {
createTextFieldSemantics(isEnabled: false, value: 'hello');
expectSemanticsTree(owner(), '''<sem><input /></sem>''');
final SemanticsObject node = owner().debugSemanticsTree![0]!;
final TextField textFieldRole = node.semanticRole! as TextField;
final SemanticTextField textFieldRole = node.semanticRole! as SemanticTextField;
final DomHTMLInputElement inputElement =
textFieldRole.editableElement as DomHTMLInputElement;
expect(inputElement.tagName.toLowerCase(), 'input');
Expand Down Expand Up @@ -170,7 +170,7 @@ void testMain() {
rect: const ui.Rect.fromLTWH(0, 0, 10, 15),
);

final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;
expect(owner().semanticsHost.ownerDocument?.activeElement,
strategy.domElement);
expect(textField.editableElement, strategy.domElement);
Expand Down Expand Up @@ -238,7 +238,7 @@ void testMain() {
isFocused: true,
rect: const ui.Rect.fromLTWH(0, 0, 10, 15));

final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;
final DomHTMLInputElement editableElement =
textField.editableElement as DomHTMLInputElement;

Expand Down Expand Up @@ -269,7 +269,7 @@ void testMain() {
isFocused: true,
rect: const ui.Rect.fromLTWH(0, 0, 10, 15));

final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;
final DomHTMLInputElement editableElement =
textField.editableElement as DomHTMLInputElement;

Expand Down Expand Up @@ -311,7 +311,7 @@ void testMain() {
isFocused: true,
);

final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;
expect(textField.editableElement, strategy.domElement);
expect(owner().semanticsHost.ownerDocument?.activeElement,
strategy.domElement);
Expand Down Expand Up @@ -347,7 +347,7 @@ void testMain() {
expect(strategy.domElement, isNull);

// It doesn't remove the DOM element.
final TextField textField = textFieldSemantics.semanticRole! as TextField;
final SemanticTextField textField = textFieldSemantics.semanticRole! as SemanticTextField;
expect(owner().semanticsHost.contains(textField.editableElement), isTrue);
// Editing element is not enabled.
expect(strategy.isEnabled, isFalse);
Expand Down