Set text direction in semantics along with Directionality (#16907)

* Set text direction in semantics along with Directionality

* update tests for the extra SemanticsNode
This commit is contained in:
Yegor 2018-04-24 18:29:26 -07:00 committed by GitHub
parent 00221820df
commit a7d7652a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 274 additions and 201 deletions

View File

@ -544,7 +544,9 @@ class _LocalizationsState extends State<Localizations> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_locale == null) if (_locale == null)
return new Container(); return new Container();
return new _LocalizationsScope( return new Semantics(
textDirection: _textDirection,
child: new _LocalizationsScope(
key: _localizedResourcesScopeKey, key: _localizedResourcesScopeKey,
locale: _locale, locale: _locale,
localizationsState: this, localizationsState: this,
@ -553,6 +555,7 @@ class _LocalizationsState extends State<Localizations> {
textDirection: _textDirection, textDirection: _textDirection,
child: widget.child, child: widget.child,
), ),
),
); );
} }
} }

View File

@ -1214,6 +1214,8 @@ void main() {
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
new TestSemantics.root( new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
@ -1251,6 +1253,8 @@ void main() {
), ),
], ],
), ),
],
),
ignoreRect: true, ignoreRect: true,
ignoreTransform: true, ignoreTransform: true,
ignoreId: true, ignoreId: true,
@ -1290,6 +1294,8 @@ void main() {
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
new TestSemantics.root( new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
@ -1332,6 +1338,8 @@ void main() {
), ),
], ],
), ),
],
),
ignoreRect: true, ignoreRect: true,
ignoreTransform: true, ignoreTransform: true,
ignoreId: true, ignoreId: true,

View File

@ -519,19 +519,22 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 2, id: 2,
children: <TestSemantics>[
new TestSemantics(
id: 3,
flags: <SemanticsFlag>[SemanticsFlag.isSelected], flags: <SemanticsFlag>[SemanticsFlag.isSelected],
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
label: 'AC\nTab 1 of 3', label: 'AC\nTab 1 of 3',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
new TestSemantics( new TestSemantics(
id: 3, id: 4,
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
label: 'Alarm\nTab 2 of 3', label: 'Alarm\nTab 2 of 3',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
new TestSemantics( new TestSemantics(
id: 4, id: 5,
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
label: 'Hot Tub\nTab 3 of 3', label: 'Hot Tub\nTab 3 of 3',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
@ -539,6 +542,8 @@ void main() {
], ],
), ),
], ],
),
],
); );
expect(semantics, hasSemantics(expected, ignoreTransform: true, ignoreRect: true)); expect(semantics, hasSemantics(expected, ignoreTransform: true, ignoreRect: true));

View File

@ -609,7 +609,11 @@ void _tests() {
); );
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
new TestSemantics.root(children: <TestSemantics>[expected]), new TestSemantics.root(children: <TestSemantics>[
new TestSemantics(
children: <TestSemantics>[expected],
),
]),
ignoreId: true, ignoreId: true,
ignoreTransform: true, ignoreTransform: true,
ignoreRect: true, ignoreRect: true,

View File

@ -281,6 +281,8 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
children: <TestSemantics>[
new TestSemantics(
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.scopesRoute, SemanticsFlag.scopesRoute,
], ],
@ -299,6 +301,8 @@ void main() {
], ],
), ),
], ],
),
],
), ignoreTransform: true, ignoreId: true, ignoreRect: true)); ), ignoreTransform: true, ignoreId: true, ignoreRect: true));
semantics.dispose(); semantics.dispose();

View File

@ -1361,6 +1361,10 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 4,
actions: SemanticsAction.tap.index, actions: SemanticsAction.tap.index,
flags: SemanticsFlag.isSelected.index, flags: SemanticsFlag.isSelected.index,
label: 'TAB #0\nTab 1 of 2', label: 'TAB #0\nTab 1 of 2',
@ -1368,7 +1372,7 @@ void main() {
transform: new Matrix4.translationValues(0.0, 276.0, 0.0), transform: new Matrix4.translationValues(0.0, 276.0, 0.0),
), ),
new TestSemantics( new TestSemantics(
id: 4, id: 5,
actions: SemanticsAction.tap.index, actions: SemanticsAction.tap.index,
label: 'TAB #1\nTab 2 of 2', label: 'TAB #1\nTab 2 of 2',
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
@ -1379,6 +1383,8 @@ void main() {
], ],
), ),
], ],
),
],
); );
expect(semantics, hasSemantics(expectedSemantics)); expect(semantics, hasSemantics(expectedSemantics));
@ -1618,6 +1624,10 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 4,
actions: SemanticsAction.tap.index, actions: SemanticsAction.tap.index,
flags: SemanticsFlag.isSelected.index, flags: SemanticsFlag.isSelected.index,
label: 'Semantics override 0\nTab 1 of 2', label: 'Semantics override 0\nTab 1 of 2',
@ -1625,7 +1635,7 @@ void main() {
transform: new Matrix4.translationValues(0.0, 276.0, 0.0), transform: new Matrix4.translationValues(0.0, 276.0, 0.0),
), ),
new TestSemantics( new TestSemantics(
id: 4, id: 5,
actions: SemanticsAction.tap.index, actions: SemanticsAction.tap.index,
label: 'Semantics override 1\nTab 2 of 2', label: 'Semantics override 1\nTab 2 of 2',
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
@ -1636,6 +1646,8 @@ void main() {
], ],
), ),
], ],
),
],
); );
expect(semantics, hasSemantics(expectedSemantics)); expect(semantics, hasSemantics(expectedSemantics));

View File

@ -622,6 +622,8 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
children: <TestSemantics>[
new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
@ -631,6 +633,8 @@ void main() {
], ],
), ),
], ],
),
],
), ignoreRect: true, ignoreId: true, ignoreTransform: true)); ), ignoreRect: true, ignoreId: true, ignoreTransform: true));
semantics.dispose(); semantics.dispose();
@ -654,6 +658,8 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
children: <TestSemantics>[
new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
@ -663,6 +669,8 @@ void main() {
], ],
), ),
], ],
),
],
), ignoreRect: true, ignoreId: true, ignoreTransform: true)); ), ignoreRect: true, ignoreId: true, ignoreTransform: true));
semantics.dispose(); semantics.dispose();

View File

@ -330,6 +330,8 @@ void main() {
expect( expect(
semantics, semantics,
hasSemantics( hasSemantics(
new TestSemantics(
children: <TestSemantics>[
new TestSemantics( new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
@ -363,6 +365,8 @@ void main() {
), ),
], ],
), ),
],
),
ignoreId: true, ignoreTransform: true, ignoreRect: true, ignoreId: true, ignoreTransform: true, ignoreRect: true,
), ),
); );
@ -382,6 +386,8 @@ void main() {
expect( expect(
semantics, semantics,
hasSemantics( hasSemantics(
new TestSemantics(
children: <TestSemantics>[
new TestSemantics( new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
@ -409,6 +415,8 @@ void main() {
), ),
], ],
), ),
],
),
ignoreId: true, ignoreTransform: true, ignoreRect: true, ignoreId: true, ignoreTransform: true, ignoreRect: true,
), ),
); );

View File

@ -592,6 +592,8 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics( expect(semantics, hasSemantics(new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
children: <TestSemantics>[
new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
@ -602,6 +604,8 @@ void main() {
], ],
), ),
], ],
),
],
), ignoreTransform: true, ignoreRect: true, ignoreId: true)); ), ignoreTransform: true, ignoreRect: true, ignoreId: true));
semantics.dispose(); semantics.dispose();
@ -714,12 +718,15 @@ void main() {
await tester.pump(); await tester.pump();
final SemanticsOwner owner = tester.binding.pipelineOwner.semanticsOwner; final SemanticsOwner owner = tester.binding.pipelineOwner.semanticsOwner;
const int expectedNodeId = 3; const int expectedNodeId = 4;
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
id: 1, id: 1,
children: <TestSemantics>[
new TestSemantics(
id: 2,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
@ -742,6 +749,8 @@ void main() {
], ],
), ),
], ],
),
],
), ignoreRect: true, ignoreTransform: true)); ), ignoreRect: true, ignoreTransform: true));
owner.performAction(expectedNodeId, SemanticsAction.copy); owner.performAction(expectedNodeId, SemanticsAction.copy);

View File

@ -105,22 +105,26 @@ void _tests() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 1, id: 1,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], textDirection: TextDirection.ltr,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 2, id: 2,
children: <TestSemantics>[ flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
new TestSemantics(
id: 5,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
children: <TestSemantics>[
new TestSemantics(
id: 6,
children: <TestSemantics>[
new TestSemantics(
id: 4,
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')], tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
label: 'Plain text', label: 'Plain text',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
new TestSemantics( new TestSemantics(
id: 4, id: 5,
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')], tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
flags: <SemanticsFlag>[SemanticsFlag.hasCheckedState, SemanticsFlag.isChecked, SemanticsFlag.isSelected], flags: <SemanticsFlag>[SemanticsFlag.hasCheckedState, SemanticsFlag.isChecked, SemanticsFlag.isSelected],
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.decrease], actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.decrease],
@ -139,6 +143,8 @@ void _tests() {
), ),
], ],
), ),
],
),
// ^^^^^^^^^^^^ // ^^^^^^^^^^^^
ignoreRect: true, ignoreRect: true,
ignoreTransform: true, ignoreTransform: true,

View File

@ -55,12 +55,16 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
id: 2, id: 2,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
new TestSemantics(
id: 4,
label: 'Hello!', label: 'Hello!',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0), rect: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
@ -69,6 +73,8 @@ void main() {
], ],
), ),
], ],
),
],
))); )));
semantics.dispose(); semantics.dispose();