Skip to content

[a11y] Semanctis flag refactor step 1: engine part - #167421

Merged
hannah-hyj merged 4 commits into
flutter:masterfrom
hannah-hyj:semanticflags-dartui
Apr 22, 2025
Merged

hannah-hyj merged 4 commits into
flutter:masterfrom
hannah-hyj:semanticflags-dartui

Conversation

@hannah-hyj

@hannah-hyj hannah-hyj commented Apr 18, 2025 •

Copy link
Copy Markdown
Member

issue: #166101

step 1: Add struct SemanticsFlags in semantics_node.h and class SemanticsFlags in dart:ui, it's still a bitmask in embedder and framework.

TODO:
Other parts will be in other following PRs

  • Embedder
    add a struct FlutterSemanticsFlags
    add FlutterSemanticsFlags* to FlutterSemanticsNode2

  • web engine
    use the new class

  • SemanticsUpdateBuilder.updateNode
    pass a list of bools instead of bitmask

  • Framework
    use the SemanticsFlags class instead of bitmask

  • flutter_tester
    use the SemanticsFlags class instead of bitmask

  • apicheck_test.dart
    Add this test back

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@hannah-hyj
hannah-hyj requested a review from a team as a code owner April 18, 2025 22:07
@github-actions github-actions Bot added platform-android Android applications specifically platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) platform-fuchsia Fuchsia code specifically team-ios Owned by iOS platform team labels Apr 18, 2025
@hannah-hyj hannah-hyj changed the title [a11y] Semanctis flag refactor: engine part [a11y] Semanctis flag refactor step 1: engine part Apr 18, 2025
@hannah-hyj
hannah-hyj force-pushed the semanticflags-dartui branch 2 times, most recently from b7b8485 to 9558f31 Compare April 19, 2025 17:51
@github-actions github-actions Bot added the platform-web Web applications specifically label Apr 21, 2025
@hannah-hyj
hannah-hyj force-pushed the semanticflags-dartui branch from 1fb5399 to 8a0d539 Compare April 21, 2025 04:20

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just some comments

String toString() => 'SemanticsFlag.$name';
}

/// Semantics flags.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this doc string is not useful.

});

/// SemanticsFlags with everything default to false.
static const SemanticsFlags none = SemanticsFlags();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
static const SemanticsFlags none = SemanticsFlags();
static const SemanticsFlags kNone = SemanticsFlags();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We use none for SemanticsRole, SemanticsInputType, and SemanticsValidationResult. Why deviate here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is a constant object we usually prefix with k See(SemanticsConfiguration._kEmptyConfig).
SemanticsInputType and SemanticsValidationResult.none is an actual enum

}

/// Semantics flags.
class SemanticsFlags {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mark as immutable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@immutable is an annotation from package:meta. We cannot use it in the engine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah i forgot this is in web engine


/// Semantics flags.
class SemanticsFlags {
/// All flags default to `false` unless specified.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: the first paragraph of a constructor dartdoc should say what it does, such as "Creates a set of semantics flags that describe various states of a widget". The nuances of arguments usually goes into a separate paragraph.

this.isRequired = false,
});

/// SemanticsFlags with everything default to false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: consider rephrasing, such as "The set of semantics flags with every flag set to false" (the word "default" implies a starting value that you can change later, but SemanticsFlags.none guaranteed that every flag is set to false and it cannot be changed)

/// {@macro dart.ui.semantics.isRequired}
final bool isRequired;

/// Merges the flags from this object with [other].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: It's unclear what "merges" implies. Consider expanding, e.g. "Combines two sets of flags, such that if a flag it set to true in any of the two sets, the resulting set contains that flag set to true."

String toString() => 'SemanticsFlag.$name';
}

/// Semantics flags.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't include the dartdocs in the web copies of the dart:ui API (this way they don't get stale).

This comment applies here and below.

}
}

int64_t flagsToInt64(flutter::SemanticsFlags flags) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since is doesn't make sense for flags to have a sign, should we use an unsigned type, e.g. uint64_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we will read it on java side using buffer.getLong(); and it seems there's no unsigned long in java. So I think it's ok to just use int64 here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

makes sense to me

};
}

FlutterSemanticsFlag SemanticsFlagtoInt(const SemanticsFlags& flags) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The spelling/camel-casing seems off. Should this be SemanticsFlagsToInt?


int32_t id = 0;
int32_t flags = 0;
SemanticsFlags flags{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you've initialized the default values of everything in SemanticsFlag struct you can just write this as SemanticsFlags flags

@jonahwilliams jonahwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Update semantics.dart

lint

Update semantics.dart

lint

Update apicheck_test.dart

fix tests

SemanticsFlags updates

SemanticsFlags updates

lint

Update semantics_update_builder.cc

1
Update platform_view_android_delegate.cc

lint

fix tests

Update semantics.dart
@hannah-hyj
hannah-hyj force-pushed the semanticflags-dartui branch from 05dff38 to 75c8fe8 Compare April 22, 2025 17:50
@hannah-hyj hannah-hyj added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 22, 2025
@hannah-hyj
hannah-hyj added this pull request to the merge queue Apr 22, 2025
Merged via the queue into flutter:master with commit 46144a2 Apr 22, 2025
@hannah-hyj
hannah-hyj deleted the semanticflags-dartui branch April 22, 2025 22:51
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) engine flutter/engine related. See also e: labels. platform-android Android applications specifically platform-fuchsia Fuchsia code specifically platform-ios iOS applications specifically platform-web Web applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants