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

Conversation

@swift-kim
Copy link
Contributor

@swift-kim swift-kim commented Mar 30, 2022

The following enum types in embedder.h must match with the corresponding Dart/C++ classes in dart:ui but some values are missing.

  • FlutterAccessibilityFeature
  • FlutterSemanticsAction
  • FlutterSemanticsFlag

The comments say

/// Must match the `AccessibilityFeatures` enum in window.dart.

engine/lib/ui/window.dart

Lines 784 to 785 in 2d29e2f

// When changes are made to this class, the equivalent APIs in each of the
// embedders *must* be updated.

No linked issue because the fix is trivial enough.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

This is missing OnOffSwitchLabelsIndex now.

Can you add a test for this? I think a decent test for this would be something that iterates over the values in flutter::AccessibliityFeatureFlag and this one and makes sure there are the same number of values and that they're equal.

Ideally we'd also have a test that actually uses this feature from the embedder API and makes sure that it's plumbed through to the right spots, but that's quite a bit more effort :)

@swift-kim
Copy link
Contributor Author

This is missing OnOffSwitchLabelsIndex now.

Oh, I was working on the Flutter 2.10 engine codebase and I didn't notice the addition. I'll fix it.

something that iterates over the values in flutter::AccessibliityFeatureFlag

Unfortunately I couldn't find any non-hacky way to iterate over an enum or enum class in C++. Do you have any idea?

@dnfield
Copy link
Contributor

dnfield commented Apr 1, 2022

Hmm. I guess there are weird ways using template metaprogramming but that's ok.

Maybe we could just add something like kFlutterAccessibilityFeatureLast, and have a static_assert(flutter::AccessibilityFeatureFlag::kLast == kFlutterAccessibilityFeatureLast)?

@dnfield
Copy link
Contributor

dnfield commented Apr 1, 2022

(with some kind of comment to keep that value last of course)

@swift-kim
Copy link
Contributor Author

add something like kFlutterAccessibilityFeatureLast

This doesn't seem to be possible because

// - Enum members without explicit values must not be reordered.

and if we set explicit values to kFlutterAccessibilityFeatureLast and AccessibilityFeatureFlag::kLast, then the comparison of the values will be pointless.

By the way I just noticed that there are other enum types (SemanticsAction and SemanticsFlags) which have a similar characteristic to AccessibilityFeature. Should I update them as well or am I still missing something? (If you think broader changes should be made that are not covered by this PR, please don't mind to close this PR and open new one with your changes.)

@dnfield
Copy link
Contributor

dnfield commented Apr 1, 2022

You are of course right.

Updating the other enum types is fine.

@chinmaygarde or @cbracken may have some good idea for some way we could analyze this statically. But I'm starting to suspect it'll be beyond the scope of this PR.

@swift-kim swift-kim changed the title Sync accessibility features of window.dart and embedder.h Sync accessibility flags in embedder.h Apr 1, 2022
@cbracken cbracken self-requested a review April 1, 2022 23:33
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

@swift-kim thanks for the fix.

I agree with @dnfield that keeping these enums in sync is an issue we've hit repeatedly that we really do need some form of a static test for. Despite the comments above the enums in the code, keeping these in sync has been a repeated issue. I've filed flutter/flutter#101217 to track this.

I also agree however that that problem is significantly more complex than this patch and probably out of scope here.

@cbracken
Copy link
Member

cbracken commented Apr 4, 2022

I've got a work-in-progress patch that adds a test for this.

If you'd like to add one more, turns out we're also missing the IsMultiline semantics flag. This would go just after kFlutterSemanticsFlagHasImplicitScrolling and just before kFlutterSemanticsFlagIsReadOnly, around line 212 of embedder.h.

  /// Whether the value of the semantics node is coming from a multi-line text  
  /// field.                                                                        
  ///                                                                               
  /// This is used for text fields to distinguish single-line text fields from  
  /// multi-line ones.                                                              
  kFlutterSemanticsFlagIsMultiline = 1 << 19, 

@swift-kim
Copy link
Contributor Author

@cbracken I also noticed it but thought it had been excluded intentionally because the comments said:

// The Dart API defines the following flag but it isn't used in iOS.
// kIsMultiline = 1 << 19,

// The Dart API defines the following flag but it isn't used in Android.
// IS_MULTILINE(1 << 19);

But I'll add it anyway. Thanks for the catch!

@cbracken cbracken mentioned this pull request Apr 4, 2022
8 tasks
@cbracken
Copy link
Member

cbracken commented Apr 4, 2022

Looks like that field was addded for Flutter web. While it's apparently not used for non-web platforms, I'm surprised it's commented out in the internal enum + the Android enum.

Looks like it was added in #9850. Perhaps @mdebbar and @yjbanov can provide some context. If we know it'll be unused on non-web platforms, perhaps we should avoid exposing it here and I can adapt the test with an exceptions list.

The specific question is whether this is an enum value that we should explicitly avoid exposing in our enums. There are several other enum values that are used on some platforms but not others, but that we add to all enums for consistency. If there's no reason for treating IsMultiline differently, we should probably make it available everywhere.

@yjbanov
Copy link
Contributor

yjbanov commented Apr 4, 2022

Adding kIsMultiline to the native embedder SGTM. It's already part of the dart:ui public API, so it has to be stable.

cbracken added a commit that referenced this pull request Apr 6, 2022
Uncomments the Java Flag.IS_MULTILINE and C++ SemanticsFlag.kIsMultiline
enum values. While these values aren't used in the Android or iOS
embeddings, in practice we maintain the same set of enum values across
all embeddings so as to match the public API defined in dart:ui, found
in lib/ui/semantics/semantics.dart.

This also helps with automated checking that all enums across all
languages are consistent.

This will be added to the embedder API in
#32332.

Issue: flutter/flutter#101217
@cbracken
Copy link
Member

cbracken commented Apr 6, 2022

LGTM. #32408 will add a test for this.

@cbracken cbracken merged commit 5f2b566 into flutter:main Apr 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 6, 2022
swift-kim added a commit to swift-kim/engine that referenced this pull request Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

embedder Related to the embedder API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants