Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {

// Heading support
if (Build.VERSION.SDK_INT >= API_LEVELS.API_28) {
result.setHeading(semanticsNode.hasFlag(Flag.IS_HEADER));
result.setHeading(semanticsNode.headingLevel > 0);
}

// Accessibility Focus
Expand Down Expand Up @@ -2391,6 +2391,9 @@ private static boolean nullableHasAncestor(
// The locale of the content of this node.
@Nullable private String locale;

// The heading level for this node (0 means not a heading).
private int headingLevel;

// The id of the sibling node that is before this node in traversal
// order.
//
Expand Down Expand Up @@ -2516,6 +2519,10 @@ private void log(@NonNull String indent, boolean recursive) {
+ flags
+ "\n"
+ indent
+ " +-- headingLevel="
+ headingLevel
+ "\n"
+ indent
+ " +-- textDirection="
+ textDirection
+ "\n"
Expand Down Expand Up @@ -2591,6 +2598,7 @@ private void updateWith(
linkUrl = getStringFromBuffer(buffer, strings);
locale = getStringFromBuffer(buffer, strings);

headingLevel = buffer.getInt();
textDirection = TextDirection.fromInt(buffer.getInt());

left = buffer.getFloat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void PlatformViewAndroidDelegate::UpdateSemantics(
putStringIntoBuffer(node.linkUrl, buffer_int32, &position, strings);
putStringIntoBuffer(node.locale, buffer_int32, &position, strings);

buffer_int32[position++] = node.headingLevel;
buffer_int32[position++] = node.textDirection;
buffer_float32[position++] = node.rect.left();
buffer_float32[position++] = node.rect.top();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace flutter {
class PlatformViewAndroidDelegate {
public:
static constexpr size_t kBytesPerNode =
51 * sizeof(int32_t); // The # fields in SemanticsNode
52 * sizeof(int32_t); // The # fields in SemanticsNode
static constexpr size_t kBytesPerChild = sizeof(int32_t);
static constexpr size_t kBytesPerCustomAction = sizeof(int32_t);
static constexpr size_t kBytesPerAction = 4 * sizeof(int32_t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
expected_strings.push_back(node0.tooltip);
buffer_int32[position++] = -1; // node0.linkUrl
buffer_int32[position++] = -1; // node0.locale
buffer_int32[position++] = node0.headingLevel;
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down Expand Up @@ -128,6 +129,7 @@ TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLinkUrl) {
buffer_int32[position++] = expected_strings.size(); // node0.linkUrl
expected_strings.push_back(node0.linkUrl);
buffer_int32[position++] = -1; // node0.locale
buffer_int32[position++] = node0.headingLevel;
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down Expand Up @@ -195,6 +197,7 @@ TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLocale) {
buffer_int32[position++] = -1; // node0.linkUrl
buffer_int32[position++] = expected_strings.size();
expected_strings.push_back(node0.locale); // node0.locale
buffer_int32[position++] = node0.headingLevel;
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down Expand Up @@ -289,6 +292,7 @@ TEST(PlatformViewShell,
buffer_int32[position++] = -1; // node0.tooltip
buffer_int32[position++] = -1; // node0.linkUrl
buffer_int32[position++] = -1; // node0.locale
buffer_int32[position++] = node0.headingLevel;
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,36 @@ public void itCanPerformCollapse() {
verify(mockChannel).dispatchSemanticsAction(0, AccessibilityBridge.Action.COLLAPSE);
}

@Config(sdk = API_LEVELS.API_28)
@TargetApi(API_LEVELS.API_28)
@Test
public void itSetsHeadingWhenHeadingLevelIsPositive() {
AccessibilityBridge accessibilityBridge = setUpBridge();

TestSemanticsNode headingNode = new TestSemanticsNode();
headingNode.headingLevel = 2;
headingNode.label = "Level 2 heading";
TestSemanticsUpdate headingUpdate = headingNode.toUpdate();
headingUpdate.sendUpdateToBridge(accessibilityBridge);
AccessibilityNodeInfo headingInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
assertTrue(headingInfo.isHeading());
}

@Config(sdk = API_LEVELS.API_28)
@TargetApi(API_LEVELS.API_28)
@Test
public void itDoesNotSetHeadingWhenHeadingLevelIsZero() {
AccessibilityBridge accessibilityBridge = setUpBridge();

TestSemanticsNode nonHeadingNode = new TestSemanticsNode();
nonHeadingNode.headingLevel = 0;
nonHeadingNode.label = "Not a heading";
TestSemanticsUpdate nonHeadingUpdate = nonHeadingNode.toUpdate();
nonHeadingUpdate.sendUpdateToBridge(accessibilityBridge);
AccessibilityNodeInfo nonHeadingInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
assertFalse(nonHeadingInfo.isHeading());
}

AccessibilityBridge setUpBridge() {
return setUpBridge(null, null, null, null, null, null);
}
Expand Down Expand Up @@ -2402,6 +2432,7 @@ void addAction(AccessibilityBridge.Action action) {
String tooltip = null;
String linkUrl = null;
String locale = null;
int headingLevel = 0;
int textDirection = 0;
float left = 0.0f;
float top = 0.0f;
Expand Down Expand Up @@ -2477,6 +2508,7 @@ protected void addToBuffer(
strings.add(locale);
bytes.putInt(strings.size() - 1);
}
bytes.putInt(headingLevel);
bytes.putInt(textDirection);
bytes.putFloat(left);
bytes.putFloat(top);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ AccessibilityBridge::FromFlutterSemanticsNode(

result.flags = flutter_node.flags2;
result.actions = flutter_node.actions;
result.heading_level = flutter_node.heading_level;
result.text_selection_base = flutter_node.text_selection_base;
result.text_selection_extent = flutter_node.text_selection_extent;
result.scroll_child_count = flutter_node.scroll_child_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class AccessibilityBridge
FlutterTransformation transform;
std::vector<int32_t> children_in_traversal_order;
std::vector<int32_t> custom_accessibility_actions;
int32_t heading_level;
} SemanticsNode;

// See FlutterSemanticsCustomAction in embedder.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ TEST(FlutterPlatformNodeDelegateTest, canUseOwnerBridge) {
std::shared_ptr<TestAccessibilityBridge> bridge =
std::make_shared<TestAccessibilityBridge>();
FlutterSemanticsFlags flags = FlutterSemanticsFlags{0};
FlutterSemanticsNode2 root;
root.id = 0;
FlutterSemanticsNode2 root{sizeof(FlutterSemanticsNode2), 0};
root.label = "root";
root.hint = "";
root.value = "";
root.increased_value = "";
root.decreased_value = "";
root.tooltip = "";
root.heading_level = 0;
root.child_count = 1;
root.flags2 = &flags;
int32_t children[] = {1};
Expand All @@ -235,14 +235,14 @@ TEST(FlutterPlatformNodeDelegateTest, canUseOwnerBridge) {
root.transform = {1, 0, 0, 0, 1, 0, 0, 0, 1};
bridge->AddFlutterSemanticsNodeUpdate(root);

FlutterSemanticsNode2 child1;
child1.id = 1;
FlutterSemanticsNode2 child1{sizeof(FlutterSemanticsNode2), 1};
child1.label = "child 1";
child1.hint = "";
child1.value = "";
child1.increased_value = "";
child1.decreased_value = "";
child1.tooltip = "";
child1.heading_level = 0;
child1.child_count = 0;
child1.flags2 = &flags;
child1.custom_accessibility_actions_count = 0;
Expand Down
8 changes: 8 additions & 0 deletions engine/src/flutter/shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@ typedef struct {
FlutterPlatformViewIdentifier platform_view_id;
/// A textual tooltip attached to the node.
const char* tooltip;
/// The heading level for this node. A value of 0 means the node is not a
/// heading; higher values (1, 2, …) indicate the heading rank, with lower
/// numbers being higher-level headings.
int32_t heading_level;
} FlutterSemanticsNode;

/// A node in the Flutter semantics tree.
Expand Down Expand Up @@ -1697,6 +1701,10 @@ typedef struct {
// The set of semantics flags associated with this node. Prefer to use this
// over `flags__deprecated__`.
FlutterSemanticsFlags* flags2;
/// The heading level for this node. A value of 0 means the node is not a
/// heading; higher values (1, 2, …) indicate the heading rank, with lower
/// numbers being higher-level headings.
int32_t heading_level;
} FlutterSemanticsNode2;

/// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingV3Callbacks) {
ASSERT_EQ(9.0, node->transform.pers2);
ASSERT_EQ(std::strncmp(kTooltip, node->tooltip, sizeof(kTooltip) - 1),
0);
ASSERT_EQ(node->heading_level, 0);

if (node->id == 128) {
ASSERT_EQ(0x3f3, node->platform_view_id);
Expand Down Expand Up @@ -458,6 +459,7 @@ TEST_F(EmbedderA11yTest, A11yTreeIsConsistentUsingV2Callbacks) {
ASSERT_EQ(8.0, node->transform.pers1);
ASSERT_EQ(9.0, node->transform.pers2);
ASSERT_EQ(std::strncmp(kTooltip, node->tooltip, sizeof(kTooltip) - 1), 0);
ASSERT_EQ(node->heading_level, 0);

if (node->id == 128) {
ASSERT_EQ(0x3f3, node->platform_view_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef struct {
const int32_t* custom_accessibility_actions;
FlutterPlatformViewIdentifier platform_view_id;
const char* tooltip;
int32_t heading_level;
} FrozenFlutterSemanticsNode;

// New members must not be added to `FlutterSemanticsCustomAction`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ TEST(EmbedderFrozen, FlutterSemanticsNodeIsFrozen) {
ASSERT_EQ_OFFSET(FlutterSemanticsNode, FrozenFlutterSemanticsNode,
platform_view_id);
ASSERT_EQ_OFFSET(FlutterSemanticsNode, FrozenFlutterSemanticsNode, tooltip);
ASSERT_EQ_OFFSET(FlutterSemanticsNode, FrozenFlutterSemanticsNode,
heading_level);
}

// New members must not be added to `FlutterSemanticsCustomAction`
Expand Down