From 4f300e618f6b2be16243c3604afa3353b3f9334d Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 24 Oct 2019 19:42:32 -0700 Subject: [PATCH] Expose platform view ID on embedder semantics node (#13345) This exposes platform_view_id on the embedder API's FlutterSemanticNode. In bd0f9085e5bdbac74cc6e611f758768f15ad5415 (#8055), platformViewId was added to SemanticsNode. This field is non-zero when the SemanticsNode represents a platform view and is typically used by embedders as a means of identifying locations where a platform view's 'native' accessibility tree should be injected into the platform-specific accessibility tree constructed by the embedder. Due to the intended use of this field, the Flutter framework is meant to enforce that this node has a child count of zero. --- shell/platform/embedder/embedder.cc | 1 + shell/platform/embedder/embedder.h | 13 ++++++++----- shell/platform/embedder/fixtures/main.dart | 1 + .../embedder/tests/embedder_a11y_unittests.cc | 6 ++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index ecf27cd6586e6..b277c56ee7a5e 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -737,6 +737,7 @@ FlutterEngineResult FlutterEngineInitialize(size_t version, &node.childrenInHitTestOrder[0], node.customAccessibilityActions.size(), &node.customAccessibilityActions[0], + node.platformViewId, }; ptr(&embedder_node, user_data); } diff --git a/shell/platform/embedder/embedder.h b/shell/platform/embedder/embedder.h index aaa2440e5397f..1d1b3795292ee 100644 --- a/shell/platform/embedder/embedder.h +++ b/shell/platform/embedder/embedder.h @@ -458,6 +458,11 @@ typedef struct { double bottom; } FlutterRect; +/// The identifier of the platform view. This identifier is specified by the +/// application when a platform view is added to the scene via the +/// `SceneBuilder.addPlatformView` call. +typedef int64_t FlutterPlatformViewIdentifier; + /// `FlutterSemanticsNode` ID used as a sentinel to signal the end of a batch of /// semantics node updates. FLUTTER_EXPORT @@ -529,6 +534,9 @@ typedef struct { /// Array of `FlutterSemanticsCustomAction` IDs associated with this node. /// Has length `custom_accessibility_actions_count`. const int32_t* custom_accessibility_actions; + /// Identifier of the platform view associated with this semantics node, or + /// zero if none. + FlutterPlatformViewIdentifier platform_view_id; } FlutterSemanticsNode; /// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a @@ -653,11 +661,6 @@ typedef struct { VoidCallback destruction_callback; } FlutterSoftwareBackingStore; -/// The identifier of the platform view. This identifier is specified by the -/// application when a platform view is added to the scene via the -/// `SceneBuilder.addPlatformView` call. -typedef int64_t FlutterPlatformViewIdentifier; - typedef struct { /// The size of this struct. Must be sizeof(FlutterPlatformView). size_t struct_size; diff --git a/shell/platform/embedder/fixtures/main.dart b/shell/platform/embedder/fixtures/main.dart index 04c0e8c7dcadc..abfcea4b85256 100644 --- a/shell/platform/embedder/fixtures/main.dart +++ b/shell/platform/embedder/fixtures/main.dart @@ -130,6 +130,7 @@ void a11y_main() async { // ignore: non_constant_identifier_names rect: Rect.fromLTRB(40.0, 40.0, 80.0, 80.0), transform: kTestTransform, additionalActions: Int32List.fromList([21]), + platformViewId: 0x3f3, ) ..updateCustomAction( id: 21, diff --git a/shell/platform/embedder/tests/embedder_a11y_unittests.cc b/shell/platform/embedder/tests/embedder_a11y_unittests.cc index 091069c8ed1fd..e00cd4b5ea70b 100644 --- a/shell/platform/embedder/tests/embedder_a11y_unittests.cc +++ b/shell/platform/embedder/tests/embedder_a11y_unittests.cc @@ -134,6 +134,12 @@ TEST_F(Embedder11yTest, A11yTreeIsConsistent) { ASSERT_EQ(7.0, node->transform.pers0); ASSERT_EQ(8.0, node->transform.pers1); ASSERT_EQ(9.0, node->transform.pers2); + + if (node->id == 128) { + ASSERT_EQ(0x3f3, node->platform_view_id); + } else { + ASSERT_EQ(0, node->platform_view_id); + } } });