Skip to content

Commit

Permalink
a11y: remove SemanticsSortOrder; sort locally only; semanticsOwner po…
Browse files Browse the repository at this point in the history
…st-test check (flutter#15537)

* a11y: remove SemanticsSortOrder; sort locally only; semanticsOwner post-test check

* update accessibility test framework

- default nextNodeId/previousNodeId to -1
- stop treating null as opt-out from value testing
- add `id`, `TestSemantics.root`, and `tags` to the suggested code in the TestSemantics failure message
- fix a small bug with raw string escaping
- update all tests accordingly

* fix sortKey doc

* prefer const over final
  • Loading branch information
yjbanov committed Mar 19, 2018
1 parent 7475345 commit e417679
Show file tree
Hide file tree
Showing 29 changed files with 450 additions and 642 deletions.
22 changes: 11 additions & 11 deletions packages/flutter/lib/src/rendering/proxy_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3025,7 +3025,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
String decreasedValue,
String hint,
TextDirection textDirection,
SemanticsSortOrder sortOrder,
SemanticsSortKey sortKey,
VoidCallback onTap,
VoidCallback onLongPress,
VoidCallback onScrollLeft,
Expand Down Expand Up @@ -3059,7 +3059,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
_decreasedValue = decreasedValue,
_hint = hint,
_textDirection = textDirection,
_sortOrder = sortOrder,
_sortKey = sortKey,
_onTap = onTap,
_onLongPress = onLongPress,
_onScrollLeft = onScrollLeft,
Expand Down Expand Up @@ -3276,17 +3276,17 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
markNeedsSemanticsUpdate();
}

/// Sets the [SemanticsNode.sortOrder] to the given value.
/// Sets the [SemanticsNode.sortKey] to the given value.
///
/// This defines how this node will be sorted with the other semantics nodes
/// This defines how this node is sorted among the sibling semantics nodes
/// to determine the order in which they are traversed by the accessibility
/// services on the platform (e.g. VoiceOver on iOS and TalkBack on Android).
SemanticsSortOrder get sortOrder => _sortOrder;
SemanticsSortOrder _sortOrder;
set sortOrder(SemanticsSortOrder value) {
if (sortOrder == value)
SemanticsSortKey get sortKey => _sortKey;
SemanticsSortKey _sortKey;
set sortKey(SemanticsSortKey value) {
if (sortKey == value)
return;
_sortOrder = value;
_sortKey = value;
markNeedsSemanticsUpdate();
}

Expand Down Expand Up @@ -3650,8 +3650,8 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
config.hint = hint;
if (textDirection != null)
config.textDirection = textDirection;
if (sortOrder != null)
config.sortOrder = sortOrder;
if (sortKey != null)
config.sortKey = sortKey;
// Registering _perform* as action handlers instead of the user provided
// ones to ensure that changing a user provided handler from a non-null to
// another non-null value doesn't require a semantics update.
Expand Down
339 changes: 100 additions & 239 deletions packages/flutter/lib/src/semantics/semantics.dart

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions packages/flutter/lib/src/widgets/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4875,13 +4875,9 @@ class Semantics extends SingleChildRenderObjectWidget {
/// The [container] argument must not be null. To create a `const` instance
/// of [Semantics], use the [Semantics.fromProperties] constructor.
///
/// Only one of [sortKey] or [sortOrder] may be specified. Specifying [sortKey]
/// is just a shorthand for specifying `new SemanticsSortOrder(key: sortKey)`
/// for the [sortOrder].
///
/// See also:
///
/// * [SemanticsSortOrder] for a class that determines accessibility traversal
/// * [SemanticsSortKey] for a class that determines accessibility traversal
/// order.
Semantics({
Key key,
Expand All @@ -4902,7 +4898,6 @@ class Semantics extends SingleChildRenderObjectWidget {
String decreasedValue,
String hint,
TextDirection textDirection,
SemanticsSortOrder sortOrder,
SemanticsSortKey sortKey,
VoidCallback onTap,
VoidCallback onLongPress,
Expand Down Expand Up @@ -4940,7 +4935,7 @@ class Semantics extends SingleChildRenderObjectWidget {
decreasedValue: decreasedValue,
hint: hint,
textDirection: textDirection,
sortOrder: _effectiveSortOrder(sortKey, sortOrder),
sortKey: sortKey,
onTap: onTap,
onLongPress: onLongPress,
onScrollLeft: onScrollLeft,
Expand Down Expand Up @@ -4972,11 +4967,6 @@ class Semantics extends SingleChildRenderObjectWidget {
assert(properties != null),
super(key: key, child: child);

static SemanticsSortOrder _effectiveSortOrder(SemanticsSortKey sortKey, SemanticsSortOrder sortOrder) {
assert(sortOrder == null || sortKey == null, 'Only one of sortOrder or sortKey may be specified.');
return sortOrder ?? (sortKey != null ? new SemanticsSortOrder(key: sortKey) : null);
}

/// Contains properties used by assistive technologies to make the application
/// more accessible.
final SemanticsProperties properties;
Expand Down Expand Up @@ -5023,7 +5013,7 @@ class Semantics extends SingleChildRenderObjectWidget {
decreasedValue: properties.decreasedValue,
hint: properties.hint,
textDirection: _getTextDirection(context),
sortOrder: properties.sortOrder,
sortKey: properties.sortKey,
onTap: properties.onTap,
onLongPress: properties.onLongPress,
onScrollLeft: properties.onScrollLeft,
Expand Down Expand Up @@ -5069,7 +5059,7 @@ class Semantics extends SingleChildRenderObjectWidget {
..decreasedValue = properties.decreasedValue
..hint = properties.hint
..textDirection = _getTextDirection(context)
..sortOrder = properties.sortOrder
..sortKey = properties.sortKey
..onTap = properties.onTap
..onLongPress = properties.onLongPress
..onScrollLeft = properties.onScrollLeft
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/test/material/animated_icons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void main() {
);

expect(semantics, includesNodeWith(label: 'a label'));

semantics.dispose();
});

testWidgets('Inherited text direction rtl', (WidgetTester tester) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ void main() {
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'AC\nTab 1 of 3',
textDirection: TextDirection.ltr,
nextNodeId: -1,
previousNodeId: 3, // Should be 2
),
new TestSemantics(
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/test/material/control_list_tile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void main() {
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
nextNodeId: 3,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: null,
flags: <SemanticsFlag>[
Expand All @@ -113,6 +114,8 @@ void main() {
),
new TestSemantics.rootChild(
id: 3,
previousNodeId: 1,
nextNodeId: 5,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: new Matrix4.translationValues(0.0, 56.0, 0.0),
flags: <SemanticsFlag>[
Expand All @@ -126,6 +129,7 @@ void main() {
),
new TestSemantics.rootChild(
id: 5,
previousNodeId: 3,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: new Matrix4.translationValues(0.0, 112.0, 0.0),
flags: <SemanticsFlag>[
Expand All @@ -139,6 +143,8 @@ void main() {
),
],
)));

semantics.dispose();
});

}
2 changes: 2 additions & 0 deletions packages/flutter/test/material/date_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -622,5 +622,7 @@ void _tests() {
ignoreRect: true,
));
});

semantics.dispose();
});
}
4 changes: 4 additions & 0 deletions packages/flutter/test/material/tabs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ void main() {
children: <TestSemantics>[
new TestSemantics(
id: 3,
nextNodeId: 4,
actions: SemanticsAction.tap.index,
flags: SemanticsFlag.isSelected.index,
label: 'TAB #0\nTab 1 of 2',
Expand All @@ -1371,6 +1372,7 @@ void main() {
),
new TestSemantics(
id: 4,
previousNodeId: 3,
actions: SemanticsAction.tap.index,
label: 'TAB #1\nTab 2 of 2',
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
Expand Down Expand Up @@ -1620,6 +1622,7 @@ void main() {
children: <TestSemantics>[
new TestSemantics(
id: 3,
nextNodeId: 4,
actions: SemanticsAction.tap.index,
flags: SemanticsFlag.isSelected.index,
label: 'Semantics override 0\nTab 1 of 2',
Expand All @@ -1628,6 +1631,7 @@ void main() {
),
new TestSemantics(
id: 4,
previousNodeId: 3,
actions: SemanticsAction.tap.index,
label: 'Semantics override 1\nTab 2 of 2',
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
Expand Down
20 changes: 11 additions & 9 deletions packages/flutter/test/material/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ void main() {
);

expect(semantics, includesNodeWith(flags: <SemanticsFlag>[SemanticsFlag.isTextField]));

semantics.dispose();
});

testWidgets('Caret works when maxLines is null', (WidgetTester tester) async {
Expand Down Expand Up @@ -1771,7 +1773,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
textDirection: TextDirection.ltr,
actions: <SemanticsAction>[
SemanticsAction.tap,
Expand All @@ -1789,7 +1791,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
textDirection: TextDirection.ltr,
value: 'Guten Tag',
actions: <SemanticsAction>[
Expand All @@ -1808,7 +1810,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
textDirection: TextDirection.ltr,
value: 'Guten Tag',
textSelection: const TextSelection.collapsed(offset: 9),
Expand All @@ -1832,7 +1834,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 4),
value: 'Guten Tag',
Expand All @@ -1858,7 +1860,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 0),
value: 'Schönen Feierabend',
Expand Down Expand Up @@ -1897,7 +1899,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
value: 'Hello',
textDirection: TextDirection.ltr,
actions: <SemanticsAction>[
Expand All @@ -1917,7 +1919,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
value: 'Hello',
textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr,
Expand All @@ -1941,7 +1943,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
id: 1,
value: 'Hello',
textSelection: const TextSelection(baseOffset: 5, extentOffset: 3),
textDirection: TextDirection.ltr,
Expand Down Expand Up @@ -1985,7 +1987,7 @@ void main() {
await tester.tap(find.byKey(key));
await tester.pump();

const int inputFieldId = 2;
const int inputFieldId = 1;

expect(controller.selection, const TextSelection.collapsed(offset: 5, affinity: TextAffinity.upstream));
expect(semantics, hasSemantics(new TestSemantics.root(
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter/test/material/time_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ void _tests() {
action: SemanticsAction.decrease,
finalValue: '23',
);

semantics.dispose();
});

testWidgets('can increment and decrement minutes', (WidgetTester tester) async {
Expand Down Expand Up @@ -501,6 +503,8 @@ void _tests() {
action: SemanticsAction.decrease,
finalValue: '58',
);

semantics.dispose();
});
}

Expand Down
Loading

0 comments on commit e417679

Please sign in to comment.