Unverified Commit a7d7652a authored by Yegor's avatar Yegor Committed by GitHub

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

* Set text direction in semantics along with Directionality

* update tests for the extra SemanticsNode
parent 00221820
...@@ -544,14 +544,17 @@ class _LocalizationsState extends State<Localizations> { ...@@ -544,14 +544,17 @@ 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(
key: _localizedResourcesScopeKey, textDirection: _textDirection,
locale: _locale, child: new _LocalizationsScope(
localizationsState: this, key: _localizedResourcesScopeKey,
typeToResources: _typeToResources, locale: _locale,
child: new Directionality( localizationsState: this,
textDirection: _textDirection, typeToResources: _typeToResources,
child: widget.child, child: new Directionality(
textDirection: _textDirection,
child: widget.child,
),
), ),
); );
} }
......
...@@ -1216,34 +1216,38 @@ void main() { ...@@ -1216,34 +1216,38 @@ void main() {
new TestSemantics.root( new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Leading', children: <TestSemantics>[
textDirection: TextDirection.ltr, new TestSemantics(
), label: 'Leading',
new TestSemantics( textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[SemanticsFlag.namesRoute], ),
label: 'Title', new TestSemantics(
textDirection: TextDirection.ltr, flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
), label: 'Title',
new TestSemantics( textDirection: TextDirection.ltr,
label: 'Action 1', ),
textDirection: TextDirection.ltr, new TestSemantics(
), label: 'Action 1',
new TestSemantics( textDirection: TextDirection.ltr,
label: 'Action 2', ),
textDirection: TextDirection.ltr, new TestSemantics(
), label: 'Action 2',
new TestSemantics( textDirection: TextDirection.ltr,
label: 'Action 3', ),
textDirection: TextDirection.ltr, new TestSemantics(
), label: 'Action 3',
new TestSemantics( textDirection: TextDirection.ltr,
label: 'Bottom', ),
textDirection: TextDirection.ltr, new TestSemantics(
label: 'Bottom',
textDirection: TextDirection.ltr,
),
],
), ),
], ],
), ),
...@@ -1292,37 +1296,41 @@ void main() { ...@@ -1292,37 +1296,41 @@ void main() {
new TestSemantics.root( new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
textDirection: TextDirection.rtl, flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
textDirection: TextDirection.rtl,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Leading', children: <TestSemantics>[
textDirection: TextDirection.rtl, new TestSemantics(
), label: 'Leading',
new TestSemantics( textDirection: TextDirection.rtl,
flags: <SemanticsFlag>[SemanticsFlag.namesRoute], ),
label: 'Title', new TestSemantics(
textDirection: TextDirection.rtl, flags: <SemanticsFlag>[SemanticsFlag.namesRoute],
), label: 'Title',
new TestSemantics( textDirection: TextDirection.rtl,
label: 'Action 1', ),
textDirection: TextDirection.rtl, new TestSemantics(
), label: 'Action 1',
new TestSemantics( textDirection: TextDirection.rtl,
label: 'Action 2', ),
textDirection: TextDirection.rtl, new TestSemantics(
), label: 'Action 2',
new TestSemantics( textDirection: TextDirection.rtl,
label: 'Action 3', ),
textDirection: TextDirection.rtl, new TestSemantics(
), label: 'Action 3',
new TestSemantics( textDirection: TextDirection.rtl,
label: 'Bottom', ),
textDirection: TextDirection.rtl, new TestSemantics(
label: 'Bottom',
textDirection: TextDirection.rtl,
),
],
), ),
], ],
), ),
......
...@@ -519,22 +519,27 @@ void main() { ...@@ -519,22 +519,27 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 2, id: 2,
flags: <SemanticsFlag>[SemanticsFlag.isSelected], children: <TestSemantics>[
actions: <SemanticsAction>[SemanticsAction.tap], new TestSemantics(
label: 'AC\nTab 1 of 3', id: 3,
textDirection: TextDirection.ltr, flags: <SemanticsFlag>[SemanticsFlag.isSelected],
), actions: <SemanticsAction>[SemanticsAction.tap],
new TestSemantics( label: 'AC\nTab 1 of 3',
id: 3, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[SemanticsAction.tap], ),
label: 'Alarm\nTab 2 of 3', new TestSemantics(
textDirection: TextDirection.ltr, id: 4,
), actions: <SemanticsAction>[SemanticsAction.tap],
new TestSemantics( label: 'Alarm\nTab 2 of 3',
id: 4, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[SemanticsAction.tap], ),
label: 'Hot Tub\nTab 3 of 3', new TestSemantics(
textDirection: TextDirection.ltr, id: 5,
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'Hot Tub\nTab 3 of 3',
textDirection: TextDirection.ltr,
),
],
), ),
], ],
), ),
......
...@@ -609,7 +609,11 @@ void _tests() { ...@@ -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,
......
...@@ -281,19 +281,23 @@ void main() { ...@@ -281,19 +281,23 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root( expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
flags: <SemanticsFlag>[
SemanticsFlag.scopesRoute,
],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Add Photo',
actions: <SemanticsAction>[
SemanticsAction.tap
],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isButton, SemanticsFlag.scopesRoute,
SemanticsFlag.hasEnabledState, ],
SemanticsFlag.isEnabled, children: <TestSemantics>[
new TestSemantics(
label: 'Add Photo',
actions: <SemanticsAction>[
SemanticsAction.tap
],
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
),
], ],
), ),
], ],
......
...@@ -1360,22 +1360,28 @@ void main() { ...@@ -1360,22 +1360,28 @@ void main() {
rect: TestSemantics.fullScreen, rect: TestSemantics.fullScreen,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
actions: SemanticsAction.tap.index, rect: TestSemantics.fullScreen,
flags: SemanticsFlag.isSelected.index, children: <TestSemantics>[
label: 'TAB #0\nTab 1 of 2', new TestSemantics(
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), id: 4,
transform: new Matrix4.translationValues(0.0, 276.0, 0.0), actions: SemanticsAction.tap.index,
), flags: SemanticsFlag.isSelected.index,
new TestSemantics( label: 'TAB #0\nTab 1 of 2',
id: 4, rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
actions: SemanticsAction.tap.index, transform: new Matrix4.translationValues(0.0, 276.0, 0.0),
label: 'TAB #1\nTab 2 of 2', ),
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), new TestSemantics(
transform: new Matrix4.translationValues(108.0, 276.0, 0.0), id: 5,
), actions: SemanticsAction.tap.index,
] label: 'TAB #1\nTab 2 of 2',
) rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
transform: new Matrix4.translationValues(108.0, 276.0, 0.0),
),
]
)
],
),
], ],
), ),
], ],
...@@ -1617,22 +1623,28 @@ void main() { ...@@ -1617,22 +1623,28 @@ void main() {
rect: TestSemantics.fullScreen, rect: TestSemantics.fullScreen,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 3,
actions: SemanticsAction.tap.index, rect: TestSemantics.fullScreen,
flags: SemanticsFlag.isSelected.index, children: <TestSemantics>[
label: 'Semantics override 0\nTab 1 of 2', new TestSemantics(
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), id: 4,
transform: new Matrix4.translationValues(0.0, 276.0, 0.0), actions: SemanticsAction.tap.index,
), flags: SemanticsFlag.isSelected.index,
new TestSemantics( label: 'Semantics override 0\nTab 1 of 2',
id: 4, rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
actions: SemanticsAction.tap.index, transform: new Matrix4.translationValues(0.0, 276.0, 0.0),
label: 'Semantics override 1\nTab 2 of 2', ),
rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight), new TestSemantics(
transform: new Matrix4.translationValues(108.0, 276.0, 0.0), id: 5,
), actions: SemanticsAction.tap.index,
] label: 'Semantics override 1\nTab 2 of 2',
) rect: new Rect.fromLTRB(0.0, 0.0, 108.0, kTextTabBarHeight),
transform: new Matrix4.translationValues(108.0, 276.0, 0.0),
),
]
)
],
),
], ],
), ),
], ],
......
...@@ -622,12 +622,16 @@ void main() { ...@@ -622,12 +622,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(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Foo\nBar', flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
textDirection: TextDirection.ltr, children: <TestSemantics>[
) new TestSemantics(
label: 'Foo\nBar',
textDirection: TextDirection.ltr,
)
],
),
], ],
), ),
], ],
...@@ -654,12 +658,16 @@ void main() { ...@@ -654,12 +658,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(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Bar', flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
textDirection: TextDirection.ltr, children: <TestSemantics>[
) new TestSemantics(
label: 'Bar',
textDirection: TextDirection.ltr,
)
],
),
], ],
), ),
], ],
......
...@@ -333,29 +333,33 @@ void main() { ...@@ -333,29 +333,33 @@ void main() {
new TestSemantics( new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Signed in\nname\nemail', flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
textDirection: TextDirection.ltr,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: r'B', label: 'Signed in\nname\nemail',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'D',
textDirection: TextDirection.ltr,
),
new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Show accounts',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
children: <TestSemantics>[
new TestSemantics(
label: r'B',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'D',
textDirection: TextDirection.ltr,
),
new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Show accounts',
textDirection: TextDirection.ltr,
),
],
), ),
], ],
), ),
...@@ -385,23 +389,27 @@ void main() { ...@@ -385,23 +389,27 @@ void main() {
new TestSemantics( new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: 'Signed in', flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
textDirection: TextDirection.ltr,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
label: r'B', label: 'Signed in',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'D',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
children: <TestSemantics>[
new TestSemantics(
label: r'B',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'C',
textDirection: TextDirection.ltr,
),
new TestSemantics(
label: r'D',
textDirection: TextDirection.ltr,
),
],
), ),
], ],
), ),
......
...@@ -592,12 +592,16 @@ void main() { ...@@ -592,12 +592,16 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics( expect(semantics, hasSemantics(new TestSemantics(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics.rootChild(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute], children: <TestSemantics>[
children: <TestSemantics>[
new TestSemantics( new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isObscured], flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
value: expectedValue, children: <TestSemantics>[
textDirection: TextDirection.ltr, new TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isObscured],
value: expectedValue,
textDirection: TextDirection.ltr,
),
],
), ),
], ],
), ),
...@@ -714,30 +718,35 @@ void main() { ...@@ -714,30 +718,35 @@ 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,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics(
id: expectedNodeId, id: 2,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
SemanticsFlag.isTextField, children: <TestSemantics>[
SemanticsFlag.isFocused new TestSemantics.rootChild(
], id: expectedNodeId,
actions: <SemanticsAction>[ flags: <SemanticsFlag>[
SemanticsAction.moveCursorBackwardByCharacter, SemanticsFlag.isTextField,
SemanticsAction.setSelection, SemanticsFlag.isFocused
SemanticsAction.copy, ],
SemanticsAction.cut, actions: <SemanticsAction>[
SemanticsAction.paste SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.setSelection,
SemanticsAction.copy,
SemanticsAction.cut,
SemanticsAction.paste
],
value: 'test',
textSelection: new TextSelection.collapsed(offset: controller.text.length),
textDirection: TextDirection.ltr,
),
], ],
value: 'test',
textSelection: new TextSelection.collapsed(offset: controller.text.length),
textDirection: TextDirection.ltr,
), ),
], ],
), ),
......
...@@ -105,31 +105,37 @@ void _tests() { ...@@ -105,31 +105,37 @@ 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,
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 5, id: 3,
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics( new TestSemantics(
id: 3, id: 6,
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')], children: <TestSemantics>[
label: 'Plain text', new TestSemantics(
textDirection: TextDirection.ltr, id: 4,
), tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
new TestSemantics( label: 'Plain text',
id: 4, textDirection: TextDirection.ltr,
tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')], ),
flags: <SemanticsFlag>[SemanticsFlag.hasCheckedState, SemanticsFlag.isChecked, SemanticsFlag.isSelected], new TestSemantics(
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.decrease], id: 5,
label: '‪Interactive text‬', tags: <SemanticsTag>[const SemanticsTag('RenderViewport.twoPane')],
value: 'test-value', flags: <SemanticsFlag>[SemanticsFlag.hasCheckedState, SemanticsFlag.isChecked, SemanticsFlag.isSelected],
increasedValue: 'test-increasedValue', actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.decrease],
decreasedValue: 'test-decreasedValue', label: '‪Interactive text‬',
hint: 'test-hint', value: 'test-value',
textDirection: TextDirection.rtl, increasedValue: 'test-increasedValue',
decreasedValue: 'test-decreasedValue',
hint: 'test-hint',
textDirection: TextDirection.rtl,
),
],
), ),
], ],
), ),
......
...@@ -55,17 +55,23 @@ void main() { ...@@ -55,17 +55,23 @@ 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,
label: 'Hello!', rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 600.0),
textDirection: TextDirection.ltr, flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
rect: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0), children: <TestSemantics>[
transform: new Matrix4.translationValues(395.0, 295.0, 0.0), new TestSemantics(
) id: 4,
label: 'Hello!',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
transform: new Matrix4.translationValues(395.0, 295.0, 0.0),
)
],
),
], ],
), ),
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment