-
Notifications
You must be signed in to change notification settings - Fork 6k
[Embedder API] Add semantic string attributes #44616
[Embedder API] Add semantic string attributes #44616
Conversation
a8229be
to
80c9626
Compare
f9e176a
to
824339e
Compare
This refactors how engine semantic updates are mapped to embedder semantic updates. There are no behavioral changes. Part of flutter/flutter#119970, flutter/flutter#98948 Next PR: #44616 ## Background For flutter/flutter#119970, we will need to update the embedder API to add string attributes to semantic nodes' text values. There are multiple kinds of string attributes, and each text value can have multiple string attributes. This requires gnarly mapping code that's best kept out of `embedder.cc`. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
f67d58b
to
82743fe
Compare
// Indicates the assistive technology should announce out the string character | ||
// by character. | ||
// | ||
// See dart:ui's SpellOutStringAttribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mirrors:
Lines 631 to 639 in 6fb9a09
/// A string attribute that causes the assistive technologies, e.g. VoiceOver, | |
/// to spell out the string character by character. | |
/// | |
/// See also: | |
/// | |
/// * [AttributedString], where the string attributes are used. | |
/// * [LocaleStringAttribute], which causes the assistive technologies to | |
/// treat the string in the specific language. | |
base class SpellOutStringAttribute extends StringAttribute { |
// Indicates the assistive technology should announce the string using the | ||
// specified locale. | ||
// | ||
// See dart:ui's LocaleStringAttribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mirrors:
Lines 662 to 670 in 6fb9a09
/// A string attribute that causes the assistive technologies, e.g. VoiceOver, | |
/// to treat string as a certain language. | |
/// | |
/// See also: | |
/// | |
/// * [AttributedString], where the string attributes are used. | |
/// * [SpellOutStringAttribute], which causes the assistive technologies to | |
/// spell out the string character by character when announcing the string. | |
base class LocaleStringAttribute extends StringAttribute { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now that the first PR is in
f69621a
to
dc9dc1a
Compare
@@ -58,13 +58,23 @@ class EmbedderSemanticsUpdate2 { | |||
std::vector<FlutterSemanticsCustomAction2> actions_; | |||
std::vector<FlutterSemanticsCustomAction2*> action_pointers_; | |||
|
|||
std::vector<std::unique_ptr<std::vector<FlutterStringAttribute*>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am no longer super familiar with this bit of the codebase. But can you conform that the underlying nodes array is never modified after the vector of pointers is constructed? This will invalidate the old pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But can you conform that the underlying nodes array is never modified after the vector of pointers is constructed?
Yup, confirmed. Pointers to T
are captured only if:
T
is owned by astd::unique_ptr<T>
, or...T
is owned by astd::vector<T>
that is fully constructed, or...T
is owned by astd::vector<std::unique_ptr<T>>
. Thestd::unique_ptr
makes the pointer toT
stable even if the vector's data is reallocated.
I mirrored the approach taken for the array of layers:
engine/shell/platform/embedder/embedder_layers.h
Lines 40 to 45 in f1f912c
std::vector<std::unique_ptr<FlutterPlatformView>> platform_views_referenced_; | |
std::vector<std::unique_ptr<FlutterPlatformViewMutation>> | |
mutations_referenced_; | |
std::vector<std::unique_ptr<std::vector<const FlutterPlatformViewMutation*>>> | |
mutations_arrays_referenced_; | |
std::vector<FlutterLayer> presented_layers_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done reviewing yet -- still thinking about the CreateStringAttributes
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - just a few comments/suggestions.
node_string_attributes_; | ||
std::vector<std::unique_ptr<FlutterStringAttribute>> string_attributes_; | ||
std::vector<std::unique_ptr<FlutterLocaleStringAttribute>> locale_attributes_; | ||
std::unique_ptr<FlutterSpellOutStringAttribute> spell_out_attribute_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth adding comments to these for the benefit of future us.
Basically something to the effect that these are buffers for holding temporary embedder-specific objects we create from their internal representation and pass back to the embedder in the semantics update callback in order to manage their lifetimes such that the objects are valid for the duration of the callback, and are automatically cleaned up when the update itself is dealloc'ed after the callback finishes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this comment to both the struct declaration and these field declarations.
switch (attribute->type) { | ||
case StringAttributeType::kLocale: { | ||
std::shared_ptr<flutter::LocaleStringAttribute> locale_attribute = | ||
std::static_pointer_cast<flutter::LocaleStringAttribute>(attribute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright - looking at string_attribute.h:15-16 and string_attribute.h:49-51, I see why where the shared_ptr
s are coming from. I haven't looked into that code do see why they're necessary, but I'll take it on faith that they are :)
auto embedder_locale = std::make_unique<FlutterLocaleStringAttribute>(); | ||
embedder_locale->struct_size = sizeof(FlutterLocaleStringAttribute); | ||
embedder_locale->locale = locale_attribute->locale.c_str(); | ||
locale_attributes_.push_back(std::move(embedder_locale)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write this as:
locale_attributes_.emplace_back({fields, in, declaration, order});
That said, I'd have to look it up; struct initializer support without an explicit constructor may only have been added in C++20. I feel like I may have had the same discussion with knopp recently.
Similar below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, our compiler doesn't compile this without an explicit constructor on the struct :(
…132914) flutter/engine@f4bffdc...2dcfb6c 2023-08-20 [email protected] Roll Skia from e9cf3f1740eb to 4f6b9d08b6d1 (2 revisions) (flutter/engine#44868) 2023-08-20 [email protected] Revert "Implementing TextScaler for nonlinear text scaling" (flutter/engine#44882) 2023-08-18 [email protected] [Embedder API] Add semantic string attributes (flutter/engine#44616) 2023-08-18 [email protected] Implementing TextScaler for nonlinear text scaling (flutter/engine#42062) 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 [email protected],[email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This refactors how engine semantic updates are mapped to embedder semantic updates. There are no behavioral changes. Part of flutter/flutter#119970, flutter/flutter#98948 Next PR: flutter#44616 ## Background For flutter/flutter#119970, we will need to update the embedder API to add string attributes to semantic nodes' text values. There are multiple kinds of string attributes, and each text value can have multiple string attributes. This requires gnarly mapping code that's best kept out of `embedder.cc`. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Flutter's `SemanticNode`s use [`StringAttribute`](https://api.flutter.dev/flutter/dart-ui/StringAttribute-class.html)s to provide additional information on text values for assistive technologies. This exposes the string attributes on the embedder API so that embedders can apply string attributes to their semantics trees. Addresses flutter/flutter#119970 Part of flutter/flutter#98948 Previous pull request: flutter#44553 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Flutter's
SemanticNode
s useStringAttribute
s to provide additional information on text values for assistive technologies. This exposes the string attributes on the embedder API so that embedders can apply string attributes to their semantics trees.Addresses flutter/flutter#119970
Part of flutter/flutter#98948
Previous pull request: #44553
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.