Skip to content

Commit a534b21

Browse files
authored
Revert "[a11y] Semantics flag refactor step 2: embedder part" (flutter#170498)
Reverts flutter#167738 Reason: I want to make more changes on embedder so some semantics flags will be tristate. To avoid introducing breaking changes, revert the former PR
1 parent 72807f4 commit a534b21

13 files changed

+122
-354
lines changed

engine/src/flutter/shell/platform/common/accessibility_bridge.cc

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -311,42 +311,43 @@ void AccessibilityBridge::ConvertFlutterUpdate(const SemanticsNode& node,
311311

312312
void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
313313
const SemanticsNode& node) {
314-
const FlutterSemanticsFlags* flags = node.flags;
315-
FML_DCHECK(flags) << "SemanticsNode::flags must not be null";
316-
if (flags->is_button) {
314+
FlutterSemanticsFlag flags = node.flags;
315+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsButton) {
317316
node_data.role = ax::mojom::Role::kButton;
318317
return;
319318
}
320-
if (flags->is_text_field && !flags->is_read_only) {
319+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
320+
!(flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly)) {
321321
node_data.role = ax::mojom::Role::kTextField;
322322
return;
323323
}
324-
if (flags->is_header) {
324+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsHeader) {
325325
node_data.role = ax::mojom::Role::kHeader;
326326
return;
327327
}
328-
if (flags->is_image) {
328+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsImage) {
329329
node_data.role = ax::mojom::Role::kImage;
330330
return;
331331
}
332-
if (flags->is_link) {
332+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsLink) {
333333
node_data.role = ax::mojom::Role::kLink;
334334
return;
335335
}
336336

337-
if (flags->is_in_mutually_exclusive_group && flags->has_checked_state) {
337+
if (flags & kFlutterSemanticsFlagIsInMutuallyExclusiveGroup &&
338+
flags & kFlutterSemanticsFlagHasCheckedState) {
338339
node_data.role = ax::mojom::Role::kRadioButton;
339340
return;
340341
}
341-
if (flags->has_checked_state) {
342+
if (flags & kFlutterSemanticsFlagHasCheckedState) {
342343
node_data.role = ax::mojom::Role::kCheckBox;
343344
return;
344345
}
345-
if (flags->has_toggled_state) {
346+
if (flags & kFlutterSemanticsFlagHasToggledState) {
346347
node_data.role = ax::mojom::Role::kSwitch;
347348
return;
348349
}
349-
if (flags->is_slider) {
350+
if (flags & kFlutterSemanticsFlagIsSlider) {
350351
node_data.role = ax::mojom::Role::kSlider;
351352
return;
352353
}
@@ -361,14 +362,17 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
361362

362363
void AccessibilityBridge::SetStateFromFlutterUpdate(ui::AXNodeData& node_data,
363364
const SemanticsNode& node) {
364-
const FlutterSemanticsFlags* flags = node.flags;
365+
FlutterSemanticsFlag flags = node.flags;
365366
FlutterSemanticsAction actions = node.actions;
366-
if (flags->has_expanded_state && flags->is_expanded) {
367+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState &&
368+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsExpanded) {
367369
node_data.AddState(ax::mojom::State::kExpanded);
368-
} else if (flags->has_expanded_state) {
370+
} else if (flags &
371+
FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState) {
369372
node_data.AddState(ax::mojom::State::kCollapsed);
370373
}
371-
if (flags->is_text_field && !flags->is_read_only) {
374+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
375+
(flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly) == 0) {
372376
node_data.AddState(ax::mojom::State::kEditable);
373377
}
374378
if (node_data.role == ax::mojom::Role::kStaticText &&
@@ -431,7 +435,7 @@ void AccessibilityBridge::SetBooleanAttributesFromFlutterUpdate(
431435
ui::AXNodeData& node_data,
432436
const SemanticsNode& node) {
433437
FlutterSemanticsAction actions = node.actions;
434-
const FlutterSemanticsFlags* flags = node.flags;
438+
FlutterSemanticsFlag flags = node.flags;
435439
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kScrollable,
436440
actions & kHasScrollingAction);
437441
node_data.AddBoolAttribute(
@@ -440,10 +444,13 @@ void AccessibilityBridge::SetBooleanAttributesFromFlutterUpdate(
440444
// TODO(chunhtai): figure out if there is a node that does not clip overflow.
441445
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kClipsChildren,
442446
!node.children_in_traversal_order.empty());
443-
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kSelected,
444-
flags->is_selected);
445-
node_data.AddBoolAttribute(ax::mojom::BoolAttribute::kEditableRoot,
446-
flags->is_text_field && !flags->is_read_only);
447+
node_data.AddBoolAttribute(
448+
ax::mojom::BoolAttribute::kSelected,
449+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsSelected);
450+
node_data.AddBoolAttribute(
451+
ax::mojom::BoolAttribute::kEditableRoot,
452+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
453+
(flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly) == 0);
447454
// Mark nodes as line breaking so that screen readers don't
448455
// merge all consecutive objects into one.
449456
// TODO(schectman): When should a node have this attribute set?
@@ -455,13 +462,15 @@ void AccessibilityBridge::SetBooleanAttributesFromFlutterUpdate(
455462
void AccessibilityBridge::SetIntAttributesFromFlutterUpdate(
456463
ui::AXNodeData& node_data,
457464
const SemanticsNode& node) {
458-
const FlutterSemanticsFlags* flags = node.flags;
465+
FlutterSemanticsFlag flags = node.flags;
459466
node_data.AddIntAttribute(ax::mojom::IntAttribute::kTextDirection,
460467
node.text_direction);
461468

462469
int sel_start = node.text_selection_base;
463470
int sel_end = node.text_selection_extent;
464-
if (flags->is_text_field && !flags->is_read_only && !node.value.empty()) {
471+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
472+
(flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly) == 0 &&
473+
!node.value.empty()) {
465474
// By default the text field selection should be at the end.
466475
sel_start = sel_start == -1 ? node.value.length() : sel_start;
467476
sel_end = sel_end == -1 ? node.value.length() : sel_end;
@@ -474,15 +483,18 @@ void AccessibilityBridge::SetIntAttributesFromFlutterUpdate(
474483
node_data.AddIntAttribute(
475484
ax::mojom::IntAttribute::kCheckedState,
476485
static_cast<int32_t>(
477-
flags->is_check_state_mixed ? ax::mojom::CheckedState::kMixed
478-
: flags->is_checked ? ax::mojom::CheckedState::kTrue
479-
: ax::mojom::CheckedState::kFalse));
486+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsCheckStateMixed
487+
? ax::mojom::CheckedState::kMixed
488+
: flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked
489+
? ax::mojom::CheckedState::kTrue
490+
: ax::mojom::CheckedState::kFalse));
480491
} else if (node_data.role == ax::mojom::Role::kSwitch) {
481492
node_data.AddIntAttribute(
482493
ax::mojom::IntAttribute::kCheckedState,
483-
static_cast<int32_t>(flags->is_toggled
484-
? ax::mojom::CheckedState::kTrue
485-
: ax::mojom::CheckedState::kFalse));
494+
static_cast<int32_t>(
495+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsToggled
496+
? ax::mojom::CheckedState::kTrue
497+
: ax::mojom::CheckedState::kFalse));
486498
}
487499
}
488500

@@ -536,12 +548,13 @@ void AccessibilityBridge::SetTooltipFromFlutterUpdate(
536548

537549
void AccessibilityBridge::SetTreeData(const SemanticsNode& node,
538550
ui::AXTreeUpdate& tree_update) {
539-
const FlutterSemanticsFlags* flags = node.flags;
540-
// Set selection of the focused node if:
541-
// 1. this text field has a valid selection
542-
// 2. this text field doesn't have a valid selection but had selection stored
543-
// in the tree.
544-
if (flags->is_text_field && flags->is_focused) {
551+
FlutterSemanticsFlag flags = node.flags;
552+
// Set selection of the focused node if:
553+
// 1. this text field has a valid selection
554+
// 2. this text field doesn't have a valid selection but had selection stored
555+
// in the tree.
556+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
557+
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocused) {
545558
if (node.text_selection_base != -1) {
546559
tree_update.tree_data.sel_anchor_object_id = node.id;
547560
tree_update.tree_data.sel_anchor_offset = node.text_selection_base;
@@ -557,10 +570,13 @@ void AccessibilityBridge::SetTreeData(const SemanticsNode& node,
557570
}
558571
}
559572

560-
if (flags->is_focused && tree_update.tree_data.focus_id != node.id) {
573+
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocused &&
574+
tree_update.tree_data.focus_id != node.id) {
561575
tree_update.tree_data.focus_id = node.id;
562576
tree_update.has_tree_data = true;
563-
} else if (!flags->is_focused && tree_update.tree_data.focus_id == node.id) {
577+
} else if ((flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocused) ==
578+
0 &&
579+
tree_update.tree_data.focus_id == node.id) {
564580
tree_update.tree_data.focus_id = ui::AXNode::kInvalidAXID;
565581
tree_update.has_tree_data = true;
566582
}
@@ -571,10 +587,7 @@ AccessibilityBridge::FromFlutterSemanticsNode(
571587
const FlutterSemanticsNode2& flutter_node) {
572588
SemanticsNode result;
573589
result.id = flutter_node.id;
574-
FML_DCHECK(flutter_node.flags2)
575-
<< "FlutterSemanticsNode2::flags2 must not be null";
576-
577-
result.flags = flutter_node.flags2;
590+
result.flags = flutter_node.flags;
578591
result.actions = flutter_node.actions;
579592
result.text_selection_base = flutter_node.text_selection_base;
580593
result.text_selection_extent = flutter_node.text_selection_extent;

engine/src/flutter/shell/platform/common/accessibility_bridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class AccessibilityBridge
161161
// See FlutterSemanticsNode in embedder.h
162162
typedef struct {
163163
int32_t id;
164-
FlutterSemanticsFlags* flags;
164+
FlutterSemanticsFlag flags;
165165
FlutterSemanticsAction actions;
166166
int32_t text_selection_base;
167167
int32_t text_selection_extent;

engine/src/flutter/shell/platform/common/accessibility_bridge_unittests.cc

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ namespace testing {
1515

1616
using ::testing::Contains;
1717

18-
FlutterSemanticsFlags kEmptyFlags = FlutterSemanticsFlags{};
19-
2018
FlutterSemanticsNode2 CreateSemanticsNode(
2119
int32_t id,
2220
const char* label,
2321
const std::vector<int32_t>* children = nullptr) {
2422
return {
2523
.id = id,
26-
.flags__deprecated__ = static_cast<FlutterSemanticsFlag>(0),
24+
.flags = static_cast<FlutterSemanticsFlag>(0),
2725
.actions = static_cast<FlutterSemanticsAction>(0),
2826
.text_selection_base = -1,
2927
.text_selection_extent = -1,
@@ -36,7 +34,6 @@ FlutterSemanticsNode2 CreateSemanticsNode(
3634
.children_in_traversal_order = children ? children->data() : nullptr,
3735
.custom_accessibility_actions_count = 0,
3836
.tooltip = "",
39-
.flags2 = &kEmptyFlags,
4037
};
4138
}
4239

@@ -212,12 +209,9 @@ TEST(AccessibilityBridgeTest, CanHandleSelectionChangeCorrectly) {
212209
std::shared_ptr<TestAccessibilityBridge> bridge =
213210
std::make_shared<TestAccessibilityBridge>();
214211
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
215-
auto flags = FlutterSemanticsFlags{
216-
.is_text_field = true,
217-
.is_focused = true,
218-
};
219-
root.flags2 = &flags;
220-
212+
root.flags = static_cast<FlutterSemanticsFlag>(
213+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
214+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocused);
221215
bridge->AddFlutterSemanticsNodeUpdate(root);
222216
bridge->CommitUpdates();
223217

@@ -247,12 +241,9 @@ TEST(AccessibilityBridgeTest, DoesNotAssignEditableRootToSelectableText) {
247241
std::shared_ptr<TestAccessibilityBridge> bridge =
248242
std::make_shared<TestAccessibilityBridge>();
249243
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
250-
auto flags = FlutterSemanticsFlags{
251-
.is_text_field = true,
252-
.is_read_only = true,
253-
};
254-
root.flags2 = &flags;
255-
244+
root.flags = static_cast<FlutterSemanticsFlag>(
245+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField |
246+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly);
256247
bridge->AddFlutterSemanticsNodeUpdate(root);
257248
bridge->CommitUpdates();
258249

@@ -266,14 +257,10 @@ TEST(AccessibilityBridgeTest, SwitchHasSwitchRole) {
266257
std::shared_ptr<TestAccessibilityBridge> bridge =
267258
std::make_shared<TestAccessibilityBridge>();
268259
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
269-
auto flags = FlutterSemanticsFlags{
270-
271-
.has_enabled_state = true,
272-
.is_enabled = true,
273-
.has_toggled_state = true,
274-
};
275-
276-
root.flags2 = &flags;
260+
root.flags = static_cast<FlutterSemanticsFlag>(
261+
FlutterSemanticsFlag::kFlutterSemanticsFlagHasToggledState |
262+
FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
263+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled);
277264
bridge->AddFlutterSemanticsNodeUpdate(root);
278265
bridge->CommitUpdates();
279266

@@ -285,16 +272,11 @@ TEST(AccessibilityBridgeTest, SliderHasSliderRole) {
285272
std::shared_ptr<TestAccessibilityBridge> bridge =
286273
std::make_shared<TestAccessibilityBridge>();
287274
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
288-
auto flags = FlutterSemanticsFlags{
289-
290-
.has_enabled_state = true,
291-
.is_enabled = true,
292-
.is_focusable = true,
293-
.is_slider = true,
294-
};
295-
296-
root.flags2 = &flags;
297-
275+
root.flags = static_cast<FlutterSemanticsFlag>(
276+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsSlider |
277+
FlutterSemanticsFlag::kFlutterSemanticsFlagHasEnabledState |
278+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsEnabled |
279+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsFocusable);
298280
bridge->AddFlutterSemanticsNodeUpdate(root);
299281
bridge->CommitUpdates();
300282

@@ -311,13 +293,9 @@ TEST(AccessibilityBridgeTest, CanSetCheckboxChecked) {
311293
std::shared_ptr<TestAccessibilityBridge> bridge =
312294
std::make_shared<TestAccessibilityBridge>();
313295
FlutterSemanticsNode2 root = CreateSemanticsNode(0, "root");
314-
auto flags = FlutterSemanticsFlags{
315-
316-
.has_checked_state = true,
317-
.is_checked = true,
318-
};
319-
320-
root.flags2 = &flags;
296+
root.flags = static_cast<FlutterSemanticsFlag>(
297+
FlutterSemanticsFlag::kFlutterSemanticsFlagHasCheckedState |
298+
FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked);
321299
bridge->AddFlutterSemanticsNodeUpdate(root);
322300
bridge->CommitUpdates();
323301

0 commit comments

Comments
 (0)