Commit f8a2bd20 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Redesign Semantic Tree Compilation Algorithm (#12605)

* Oct 12 10:12am

* implicit_semantics_test.dart passes

* refactoring

* works in nice

* minor rename

* more doc comments

* to be explicit check better

* fix test

* ++

* ++

* semantics_9_test (BlockSemantics) and implicit_semantics_test are passing

* doc updates

* tiny refactor

* fix static errors in tests

* fix gesture detector

* ++

* ++

* geometry

* ++

* remove noGeometry

* revert test

* +

* all tests but scrolling/clipping pass

* clipping works

* scrolling halfway

* sliver tests pass

* ALL TESTS PASS

* SemanticsNode changed

* docs and tiny fixes

* card test

* more doc comments

* remove missed print

* more tests

* make test pass on Linux

* remove changes to intellij proj file

* review comments
parent d47d2687
......@@ -251,48 +251,46 @@ class RecipeCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MergeSemantics(
child: new GestureDetector(
onTap: onTap,
child: new Card(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Hero(
tag: 'packages/$_kGalleryAssetsPackage/${recipe.imagePath}',
child: new Image.asset(
recipe.imagePath,
package: recipe.imagePackage,
fit: BoxFit.contain,
),
return new GestureDetector(
onTap: onTap,
child: new Card(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Hero(
tag: 'packages/$_kGalleryAssetsPackage/${recipe.imagePath}',
child: new Image.asset(
recipe.imagePath,
package: recipe.imagePackage,
fit: BoxFit.contain,
),
new Expanded(
child: new Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(16.0),
child: new Image.asset(
recipe.ingredientsImagePath,
package: recipe.ingredientsImagePackage,
width: 48.0,
height: 48.0,
),
),
new Expanded(
child: new Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(16.0),
child: new Image.asset(
recipe.ingredientsImagePath,
package: recipe.ingredientsImagePackage,
width: 48.0,
height: 48.0,
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(recipe.name, style: titleStyle, softWrap: false, overflow: TextOverflow.ellipsis),
new Text(recipe.author, style: authorStyle),
],
),
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(recipe.name, style: titleStyle, softWrap: false, overflow: TextOverflow.ellipsis),
new Text(recipe.author, style: authorStyle),
],
),
],
),
),
],
),
],
),
),
],
),
),
);
......
......@@ -31,20 +31,18 @@ class GalleryItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MergeSemantics(
child: new ListTile(
title: new Text(title),
subtitle: new Text(subtitle),
onTap: () {
if (routeName != null) {
Timeline.instantSync('Start Transition', arguments: <String, String>{
'from': '/',
'to': routeName
});
Navigator.pushNamed(context, routeName);
}
return new ListTile(
title: new Text(title),
subtitle: new Text(subtitle),
onTap: () {
if (routeName != null) {
Timeline.instantSync('Start Transition', arguments: <String, String>{
'from': '/',
'to': routeName
});
Navigator.pushNamed(context, routeName);
}
),
}
);
}
}
......
......@@ -187,7 +187,7 @@ final Duration _kDiscreteTransitionDuration = const Duration(milliseconds: 500);
const double _kAdjustmentUnit = 0.1; // Matches iOS implementation of material slider.
class _RenderCupertinoSlider extends RenderConstrainedBox implements SemanticsActionHandler {
class _RenderCupertinoSlider extends RenderConstrainedBox {
_RenderCupertinoSlider({
@required double value,
int divisions,
......@@ -253,7 +253,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements SemanticsAc
final bool wasInteractive = isInteractive;
_onChanged = value;
if (wasInteractive != isInteractive)
markNeedsSemanticsUpdate(noGeometry: true);
markNeedsSemanticsUpdate();
}
TextDirection get textDirection => _textDirection;
......@@ -379,31 +379,25 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements SemanticsAc
}
@override
bool get isSemanticBoundary => isInteractive;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
config.isSemanticBoundary = isInteractive;
if (isInteractive) {
config.addAction(SemanticsAction.increase, _increaseAction);
config.addAction(SemanticsAction.decrease, _decreaseAction);
}
}
double get _semanticActionUnit => divisions != null ? 1.0 / divisions : _kAdjustmentUnit;
void _annotate(SemanticsNode semantics) {
void _increaseAction() {
if (isInteractive)
semantics.addAdjustmentActions();
onChanged((value + _semanticActionUnit).clamp(0.0, 1.0));
}
@override
void performAction(SemanticsAction action) {
final double unit = divisions != null ? 1.0 / divisions : _kAdjustmentUnit;
switch (action) {
case SemanticsAction.increase:
if (isInteractive)
onChanged((value + unit).clamp(0.0, 1.0));
break;
case SemanticsAction.decrease:
if (isInteractive)
onChanged((value - unit).clamp(0.0, 1.0));
break;
default:
assert(false);
break;
}
void _decreaseAction() {
if (isInteractive)
onChanged((value - _semanticActionUnit).clamp(0.0, 1.0));
}
}
......@@ -156,7 +156,7 @@ const Color _kTrackColor = CupertinoColors.lightBackgroundGray;
const Duration _kReactionDuration = const Duration(milliseconds: 300);
const Duration _kToggleDuration = const Duration(milliseconds: 200);
class _RenderCupertinoSwitch extends RenderConstrainedBox implements SemanticsActionHandler {
class _RenderCupertinoSwitch extends RenderConstrainedBox {
_RenderCupertinoSwitch({
@required bool value,
@required Color activeColor,
......@@ -214,7 +214,7 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox implements SemanticsAc
if (value == _value)
return;
_value = value;
markNeedsSemanticsUpdate(onlyLocalUpdates: true, noGeometry: true);
markNeedsSemanticsUpdate(onlyLocalUpdates: true);
_position
..curve = Curves.ease
..reverseCurve = Curves.ease.flipped;
......@@ -254,7 +254,7 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox implements SemanticsAc
_onChanged = value;
if (wasInteractive != isInteractive) {
markNeedsPaint();
markNeedsSemanticsUpdate(noGeometry: true);
markNeedsSemanticsUpdate();
}
}
......@@ -375,23 +375,13 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox implements SemanticsAc
}
@override
bool get isSemanticBoundary => isInteractive;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void _annotate(SemanticsNode semantics) {
semantics
..hasCheckedState = true
..isChecked = _value;
config.isSemanticBoundary = isInteractive;
if (isInteractive)
semantics.addAction(SemanticsAction.tap);
}
@override
void performAction(SemanticsAction action) {
if (action == SemanticsAction.tap)
_handleTap();
config.addAction(SemanticsAction.tap, _handleTap);
config.isChecked = _value;
}
final CupertinoThumbPainter _thumbPainter = new CupertinoThumbPainter();
......
......@@ -80,14 +80,17 @@ class Card extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container(
margin: const EdgeInsets.all(4.0),
child: new Material(
color: color,
type: MaterialType.card,
elevation: elevation,
child: child
)
return new Semantics(
container: true,
child: new Container(
margin: const EdgeInsets.all(4.0),
child: new Material(
color: color,
type: MaterialType.card,
elevation: elevation,
child: child
)
),
);
}
}
......@@ -307,7 +307,7 @@ double _getPreferredTotalHeight(String label) {
return 2 * _kReactionRadius + _getAdditionalHeightForLabel(label);
}
class _RenderSlider extends RenderBox implements SemanticsActionHandler {
class _RenderSlider extends RenderBox {
_RenderSlider({
@required double value,
int divisions,
......@@ -441,7 +441,7 @@ class _RenderSlider extends RenderBox implements SemanticsActionHandler {
_onChanged = value;
if (wasInteractive != isInteractive) {
markNeedsPaint();
markNeedsSemanticsUpdate(noGeometry: true);
markNeedsSemanticsUpdate();
}
}
......@@ -708,31 +708,25 @@ class _RenderSlider extends RenderBox implements SemanticsActionHandler {
}
@override
bool get isSemanticBoundary => isInteractive;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
config.isSemanticBoundary = isInteractive;
if (isInteractive) {
config.addAction(SemanticsAction.increase, _increaseAction);
config.addAction(SemanticsAction.decrease, _decreaseAction);
}
}
double get _semanticActionUnit => divisions != null ? 1.0 / divisions : _kAdjustmentUnit;
void _annotate(SemanticsNode semantics) {
void _increaseAction() {
if (isInteractive)
semantics.addAdjustmentActions();
onChanged((value + _semanticActionUnit).clamp(0.0, 1.0));
}
@override
void performAction(SemanticsAction action) {
final double unit = divisions != null ? 1.0 / divisions : _kAdjustmentUnit;
switch (action) {
case SemanticsAction.increase:
if (isInteractive)
onChanged((value + unit).clamp(0.0, 1.0));
break;
case SemanticsAction.decrease:
if (isInteractive)
onChanged((value - unit).clamp(0.0, 1.0));
break;
default:
assert(false);
break;
}
void _decreaseAction() {
if (isInteractive)
onChanged((value - _semanticActionUnit).clamp(0.0, 1.0));
}
}
......@@ -754,22 +754,20 @@ class _TabBarState extends State<TabBar> {
// reflect the intrinsic width of their labels.
final int tabCount = widget.tabs.length;
for (int index = 0; index < tabCount; index++) {
wrappedTabs[index] = new MergeSemantics(
child: new Stack(
children: <Widget>[
new InkWell(
onTap: () { _handleTap(index); },
child: new Padding(
padding: new EdgeInsets.only(bottom: widget.indicatorWeight),
child: wrappedTabs[index],
wrappedTabs[index] = new InkWell(
onTap: () { _handleTap(index); },
child: new Padding(
padding: new EdgeInsets.only(bottom: widget.indicatorWeight),
child: new Stack(
children: <Widget>[
wrappedTabs[index],
new Semantics(
selected: index == _currentIndex,
// TODO(goderbauer): I10N-ify
label: 'Tab ${index + 1} of $tabCount',
),
),
new Semantics(
selected: index == _currentIndex,
// TODO(goderbauer): I10N-ify
label: 'Tab ${index + 1} of $tabCount',
),
],
]
),
),
);
if (!widget.isScrollable)
......
......@@ -18,7 +18,7 @@ final Tween<double> _kRadialReactionRadiusTween = new Tween<double>(begin: 0.0,
/// This class handles storing the current value, dispatching ValueChanged on a
/// tap gesture and driving a changed animation. Subclasses are responsible for
/// painting.
abstract class RenderToggleable extends RenderConstrainedBox implements SemanticsActionHandler {
abstract class RenderToggleable extends RenderConstrainedBox {
/// Creates a toggleable render object.
///
/// The [value], [activeColor], and [inactiveColor] arguments must not be
......@@ -122,7 +122,7 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
if (value == _value)
return;
_value = value;
markNeedsSemanticsUpdate(onlyLocalUpdates: true, noGeometry: true);
markNeedsSemanticsUpdate(onlyLocalUpdates: true);
_position
..curve = Curves.easeIn
..reverseCurve = Curves.easeOut;
......@@ -178,7 +178,7 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
_onChanged = value;
if (wasInteractive != isInteractive) {
markNeedsPaint();
markNeedsSemanticsUpdate(noGeometry: true);
markNeedsSemanticsUpdate();
}
}
......@@ -283,23 +283,13 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
}
@override
bool get isSemanticBoundary => isInteractive;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void _annotate(SemanticsNode semantics) {
semantics
..hasCheckedState = true
..isChecked = _value;
config.isSemanticBoundary = isInteractive;
if (isInteractive)
semantics.addAction(SemanticsAction.tap);
}
@override
void performAction(SemanticsAction action) {
if (action == SemanticsAction.tap)
_handleTap();
config.addAction(SemanticsAction.tap, _handleTap);
config.isChecked = _value;
}
@override
......
......@@ -404,11 +404,11 @@ class RenderParagraph extends RenderBox {
}
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void _annotate(SemanticsNode node) {
node.label = text.toPlainText();
node.textDirection = textDirection;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
config
..label = text.toPlainText()
..textDirection = textDirection;
}
@override
......
......@@ -221,10 +221,11 @@ abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObje
}
@override
SemanticsAnnotator get semanticsAnnotator => _excludeFromSemanticsScrolling ? _annotate : null;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
void _annotate(SemanticsNode node) {
node.addTag(RenderSemanticsGestureHandler.excludeFromScrolling);
if (_excludeFromSemanticsScrolling)
config.addTagForChildren(RenderSemanticsGestureHandler.excludeFromScrolling);
}
@override
......
......@@ -91,11 +91,12 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
_crossAxisDirection = crossAxisDirection,
_offset = offset;
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
void _annotate(SemanticsNode node) {
node.addTag(RenderSemanticsGestureHandler.useTwoPaneSemantics);
config.addTagForChildren(RenderSemanticsGestureHandler.useTwoPaneSemantics);
}
@override
......
......@@ -4434,6 +4434,7 @@ class Semantics extends SingleChildRenderObjectWidget {
Key key,
Widget child,
this.container: false,
this.explicitChildNodes: false,
this.checked,
this.selected,
this.label,
......@@ -4441,18 +4442,29 @@ class Semantics extends SingleChildRenderObjectWidget {
}) : assert(container != null),
super(key: key, child: child);
/// If 'container' is true, this Widget will introduce a new node in
/// the semantics tree. Otherwise, the semantics will be merged with
/// the semantics of any ancestors.
/// If 'container' is true, this widget will introduce a new
/// node in the semantics tree. Otherwise, the semantics will be
/// merged with the semantics of any ancestors (if the ancestor allows that).
///
/// The 'container' flag is implicitly set to true on the immediate
/// semantics-providing descendants of a node where multiple
/// children have semantics or have descendants providing semantics.
/// In other words, the semantics of siblings are not merged. To
/// merge the semantics of an entire subtree, including siblings,
/// you can use a [MergeSemantics] widget.
/// Whether descendants of this widget can add their semantic information to the
/// [SemanticsNode] introduced by this configuration is controlled by
/// [explicitChildNodes].
final bool container;
/// Whether descendants of this widget are allowed to add semantic information
/// to the [SemanticsNode] annotated by this widget.
///
/// When set to false descendants are allowed to annotate [SemanticNode]s of
/// their parent with the semantic information they want to contribute to the
/// semantic tree.
/// When set to true the only way for descendants to contribute semantic
/// information to the semantic tree is to introduce new explicit
/// [SemanticNode]s to the tree.
///
/// This setting is often used in combination with [isSemanticBoundary] to
/// create semantic boundaries that are either writable or not for children.
final bool explicitChildNodes;
/// If non-null, indicates that this subtree represents a checkbox
/// or similar widget with a "checked" state, and what its current
/// state is.
......@@ -4484,6 +4496,7 @@ class Semantics extends SingleChildRenderObjectWidget {
RenderSemanticsAnnotations createRenderObject(BuildContext context) {
return new RenderSemanticsAnnotations(
container: container,
explicitChildNodes: explicitChildNodes,
checked: checked,
selected: selected,
label: label,
......@@ -4495,6 +4508,7 @@ class Semantics extends SingleChildRenderObjectWidget {
void updateRenderObject(BuildContext context, RenderSemanticsAnnotations renderObject) {
renderObject
..container = container
..explicitChildNodes = explicitChildNodes
..checked = checked
..selected = selected
..label = label
......
......@@ -104,7 +104,7 @@ class _FocusScopeState extends State<FocusScope> {
Widget build(BuildContext context) {
FocusScope.of(context).reparentScopeIfNeeded(widget.node);
return new Semantics(
container: true,
explicitChildNodes: true,
child: new _FocusScopeMarker(
node: widget.node,
child: widget.child,
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart';
void main() {
testWidgets('Card can take semantic text from multiple children', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Center(
child: new Card(
child: new Column(
children: <Widget>[
const Text('I am text!'),
const Text('Moar text!!1'),
new MaterialButton(
child: const Text('Button'),
onPressed: () { },
)
],
)
),
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
label: 'I am text!\nMoar text!!1',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
new TestSemantics(
id: 1,
label: 'Button',
textDirection: TextDirection.ltr,
actions: SemanticsAction.tap.index,
),
],
),
],
),
ignoreTransform: true,
ignoreRect: true,
));
semantics.dispose();
});
}
......@@ -95,7 +95,7 @@ void main() {
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 7,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: null,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
......@@ -103,7 +103,7 @@ void main() {
label: 'aaa\nAAA',
),
new TestSemantics.rootChild(
id: 6,
id: 8,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: new Matrix4.translationValues(0.0, 56.0, 0.0),
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
......@@ -111,7 +111,7 @@ void main() {
label: 'bbb\nBBB',
),
new TestSemantics.rootChild(
id: 11,
id: 9,
rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 56.0),
transform: new Matrix4.translationValues(0.0, 112.0, 0.0),
flags: SemanticsFlags.hasCheckedState.index,
......
......@@ -1011,11 +1011,11 @@ void main() {
final TestSemantics expectedSemantics = new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 3,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 2,
id: 1,
actions: SemanticsAction.tap.index,
flags: SemanticsFlags.isSelected.index,
label: 'TAB #0\nTab 1 of 2',
......@@ -1023,13 +1023,14 @@ void main() {
transform: new Matrix4.translationValues(0.0, 276.0, 0.0),
),
new TestSemantics(
id: 5,
id: 2,
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),
),
]),
],
),
],
);
......@@ -1064,15 +1065,19 @@ void main() {
),
);
const String tab0title = 'This is a very wide tab #0\nTab 1 of 20';
const String tab10title = 'This is a very wide tab #10\nTab 11 of 20';
expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.scrollLeft]));
expect(semantics, isNot(includesNodeWith(label: 'This is a very wide tab #10')));
expect(semantics, includesNodeWith(label: tab0title));
expect(semantics, isNot(includesNodeWith(label: tab10title)));
controller.index = 10;
await tester.pumpAndSettle();
expect(semantics, isNot(includesNodeWith(label: 'This is a very wide tab #0')));
expect(semantics, isNot(includesNodeWith(label: tab0title)));
expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.scrollLeft, SemanticsAction.scrollRight]));
expect(semantics, includesNodeWith(label: 'This is a very wide tab #10'));
expect(semantics, includesNodeWith(label: tab10title));
controller.index = 19;
await tester.pumpAndSettle();
......@@ -1083,7 +1088,8 @@ void main() {
await tester.pumpAndSettle();
expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.scrollLeft]));
expect(semantics, includesNodeWith(label: 'This is a very wide tab #0'));
expect(semantics, includesNodeWith(label: tab0title));
expect(semantics, isNot(includesNodeWith(label: tab10title)));
semantics.dispose();
});
......
......@@ -473,7 +473,7 @@ void main() {
child: new Tooltip(
key: key,
message: tooltipText,
child: new Container(width: 0.0, height: 0.0),
child: new Container(width: 10.0, height: 10.0),
),
),
],
......@@ -485,14 +485,23 @@ void main() {
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: tooltipText)));
final TestSemantics expected = new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: tooltipText,
),
]
);
expect(semantics, hasSemantics(expected, ignoreTransform: true, ignoreRect: true));
// before using "as dynamic" in your code, see note top of file
(key.currentState as dynamic).ensureTooltipVisible(); // this triggers a rebuild of the semantics because the tree changes
await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)
expect(semantics, hasSemantics(new TestSemantics.root(label: tooltipText)));
expect(semantics, hasSemantics(expected, ignoreTransform: true, ignoreRect: true));
semantics.dispose();
});
......
......@@ -55,6 +55,9 @@ class TestRenderObject extends RenderObject {
Rect get semanticBounds => new Rect.fromLTWH(0.0, 0.0, 10.0, 20.0);
@override
bool get isSemanticBoundary => true;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
config.isSemanticBoundary = true;
}
}
......@@ -72,23 +72,23 @@ void main() {
});
test('RenderSemanticsGestureHandler adds/removes correct semantic actions', () {
SemanticsNode node = new SemanticsNode();
final RenderSemanticsGestureHandler renderObj = new RenderSemanticsGestureHandler(
onTap: () {},
onHorizontalDragUpdate: (DragUpdateDetails details) {},
);
renderObj.semanticsAnnotator(node);
expect(node.getSemanticsData().hasAction(SemanticsAction.tap), isTrue);
expect(node.getSemanticsData().hasAction(SemanticsAction.scrollLeft), isTrue);
expect(node.getSemanticsData().hasAction(SemanticsAction.scrollRight), isTrue);
SemanticsConfiguration config = new SemanticsConfiguration();
renderObj.describeSemanticsConfiguration(config);
expect(config.getActionHandler(SemanticsAction.tap), isNotNull);
expect(config.getActionHandler(SemanticsAction.scrollLeft), isNotNull);
expect(config.getActionHandler(SemanticsAction.scrollRight), isNotNull);
node = new SemanticsNode();
config = new SemanticsConfiguration();
renderObj.validActions = <SemanticsAction>[SemanticsAction.tap, SemanticsAction.scrollLeft].toSet();
renderObj.semanticsAnnotator(node);
expect(node.getSemanticsData().hasAction(SemanticsAction.tap), isTrue);
expect(node.getSemanticsData().hasAction(SemanticsAction.scrollLeft), isTrue);
expect(node.getSemanticsData().hasAction(SemanticsAction.scrollRight), isFalse);
renderObj.describeSemanticsConfiguration(config);
expect(config.getActionHandler(SemanticsAction.tap), isNotNull);
expect(config.getActionHandler(SemanticsAction.scrollLeft), isNotNull);
expect(config.getActionHandler(SemanticsAction.scrollRight), isNull);
});
}
......@@ -29,6 +29,7 @@ class TestTree {
child: new RenderPositionedBox(
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0),
child: new RenderSemanticsAnnotations(label: 'Hello there foo', textDirection: TextDirection.ltr)
),
),
),
......@@ -127,7 +128,7 @@ void main() {
layout(testTree.root, phase: EnginePhase.paint);
expect(testTree.painted, isTrue);
});
test('objects can be detached and re-attached: semantics', () {
test('objects can be detached and re-attached: semantics (no change)', () {
final TestTree testTree = new TestTree();
int semanticsUpdateCount = 0;
final SemanticsHandle semanticsHandle = renderer.pipelineOwner.ensureSemantics(
......@@ -147,7 +148,31 @@ void main() {
expect(semanticsUpdateCount, 0);
// Lay out, composite, paint, and update semantics again
layout(testTree.root, phase: EnginePhase.flushSemantics);
expect(semanticsUpdateCount, 0); // no semantics have changed.
semanticsHandle.dispose();
});
test('objects can be detached and re-attached: semantics (with change)', () {
final TestTree testTree = new TestTree();
int semanticsUpdateCount = 0;
final SemanticsHandle semanticsHandle = renderer.pipelineOwner.ensureSemantics(
listener: () {
++semanticsUpdateCount;
}
);
// Lay out, composite, paint, and update semantics
layout(testTree.root, phase: EnginePhase.flushSemantics);
expect(semanticsUpdateCount, 1);
// Remove testTree from the custom render view
renderer.renderView.child = null;
expect(testTree.child.owner, isNull);
// Dirty one of the elements
semanticsUpdateCount = 0;
testTree.child.additionalConstraints = const BoxConstraints.tightFor(height: 20.0, width: 30.0);
testTree.child.markNeedsSemanticsUpdate();
expect(semanticsUpdateCount, 0);
// Lay out, composite, paint, and update semantics again
layout(testTree.root, phase: EnginePhase.flushSemantics);
expect(semanticsUpdateCount, 1); // semantics have changed.
semanticsHandle.dispose();
});
}
......@@ -18,41 +18,45 @@ void main() {
test('tagging', () {
final SemanticsNode node = new SemanticsNode();
expect(node.hasTag(tag1), isFalse);
expect(node.hasTag(tag2), isFalse);
expect(node.isTagged(tag1), isFalse);
expect(node.isTagged(tag2), isFalse);
node.addTag(tag1);
expect(node.hasTag(tag1), isTrue);
expect(node.hasTag(tag2), isFalse);
node.tags = new Set<SemanticsTag>()..add(tag1);
expect(node.isTagged(tag1), isTrue);
expect(node.isTagged(tag2), isFalse);
node.addTag(tag2);
expect(node.hasTag(tag1), isTrue);
expect(node.hasTag(tag2), isTrue);
node.tags.add(tag2);
expect(node.isTagged(tag1), isTrue);
expect(node.isTagged(tag2), isTrue);
});
test('getSemanticsData includes tags', () {
final Set<SemanticsTag> tags = new Set<SemanticsTag>()
..add(tag1)
..add(tag2);
final SemanticsNode node = new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0)
..addTag(tag1)
..addTag(tag2);
..tags = tags;
final Set<SemanticsTag> expected = new Set<SemanticsTag>()
..add(tag1)
..add(tag2);
expect(node.getSemanticsData().tags, tags);
expect(node.getSemanticsData().tags, expected);
tags.add(tag3);
node.mergeAllDescendantsIntoThisNode = true;
node.addChildren(<SemanticsNode>[
new SemanticsNode()
..rect = new Rect.fromLTRB(5.0, 5.0, 10.0, 10.0)
..addTag(tag3),
]);
node.finalizeChildren();
final SemanticsConfiguration config = new SemanticsConfiguration()
..isMergingSemanticsOfDescendants = true;
expected.add(tag3);
node.updateWith(
config: config,
childrenInInversePaintOrder: <SemanticsNode>[
new SemanticsNode()
..isMergedIntoParent = true
..rect = new Rect.fromLTRB(5.0, 5.0, 10.0, 10.0)
..tags = tags,
],
);
expect(node.getSemanticsData().tags, expected);
expect(node.getSemanticsData().tags, tags);
});
test('after markNeedsSemanticsUpdate(onlyLocalUpdates: true) all render objects between two semantic boundaries are asked for annotations', () {
......@@ -88,7 +92,6 @@ void main() {
middle.action = SemanticsAction.scrollDown;
middle.markNeedsSemanticsUpdate(onlyLocalUpdates: true);
expect(root.debugSemantics.getSemanticsData().actions, 0); // SemanticsNode is reset
pumpFrame(phase: EnginePhase.flushSemantics);
......@@ -104,8 +107,10 @@ void main() {
..rect = new Rect.fromLTRB(5.0, 0.0, 10.0, 5.0);
final SemanticsNode root = new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 10.0, 5.0);
root.addChildren(<SemanticsNode>[child1, child2]);
root.finalizeChildren();
root.updateWith(
config: null,
childrenInInversePaintOrder: <SemanticsNode>[child1, child2],
);
expect(root.transform, isNull);
expect(child1.transform, isNull);
......@@ -126,8 +131,10 @@ void main() {
..rect = new Rect.fromLTRB(10.0, 0.0, 15.0, 5.0);
final SemanticsNode root = new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 20.0, 5.0);
root.addChildren(<SemanticsNode>[child1, child2]);
root.finalizeChildren();
root.updateWith(
config: null,
childrenInInversePaintOrder: <SemanticsNode>[child1, child2],
);
expect(
root.toStringDeep(childOrder: DebugSemanticsDumpOrder.traversal),
'SemanticsNode#11(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 20.0, 5.0))\n'
......@@ -144,18 +151,22 @@ void main() {
final SemanticsNode child3 = new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 10.0, 5.0);
child3.addChildren(<SemanticsNode>[
new SemanticsNode()
..rect = new Rect.fromLTRB(5.0, 0.0, 10.0, 5.0),
new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 5.0, 5.0),
]);
child3.finalizeChildren();
child3.updateWith(
config: null,
childrenInInversePaintOrder: <SemanticsNode>[
new SemanticsNode()
..rect = new Rect.fromLTRB(5.0, 0.0, 10.0, 5.0),
new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 5.0, 5.0),
],
);
final SemanticsNode rootComplex = new SemanticsNode()
..rect = new Rect.fromLTRB(0.0, 0.0, 25.0, 5.0);
rootComplex.addChildren(<SemanticsNode>[child1, child2, child3]);
rootComplex.finalizeChildren();
rootComplex.updateWith(
config: null,
childrenInInversePaintOrder: <SemanticsNode>[child1, child2, child3]
);
expect(
rootComplex.toStringDeep(childOrder: DebugSemanticsDumpOrder.traversal),
......@@ -187,28 +198,30 @@ void main() {
expect(
minimalProperties.toStringDeep(minLevel: DiagnosticLevel.hidden),
'SemanticsNode#16(owner: null, isPartOfNodeMerging: false, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), wasAffectedByClip: false, actions: [], tags: [], isSelected: false, label: "", textDirection: null)\n',
'SemanticsNode#16(owner: null, isPartOfNodeMerging: false, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), wasAffectedByClip: false, actions: [], isSelected: false, label: "", textDirection: null)\n',
);
final SemanticsNode allProperties = new SemanticsNode()
..rect = new Rect.fromLTWH(50.0, 10.0, 20.0, 30.0)
..mergeAllDescendantsIntoThisNode = true
..transform = new Matrix4.translation(new Vector3(10.0, 10.0, 0.0))
..wasAffectedByClip = true
..addAction(SemanticsAction.scrollUp)
..addAction(SemanticsAction.longPress)
..addAction(SemanticsAction.showOnScreen)
final SemanticsConfiguration config = new SemanticsConfiguration()
..isMergingSemanticsOfDescendants = true
..addAction(SemanticsAction.scrollUp, () { })
..addAction(SemanticsAction.longPress, () { })
..addAction(SemanticsAction.showOnScreen, () { })
..isChecked = false
..isSelected = true
..label = "Use all the properties"
..textDirection = TextDirection.rtl;
final SemanticsNode allProperties = new SemanticsNode()
..rect = new Rect.fromLTWH(50.0, 10.0, 20.0, 30.0)
..transform = new Matrix4.translation(new Vector3(10.0, 10.0, 0.0))
..wasAffectedByClip = true
..updateWith(config: config, childrenInInversePaintOrder: null);
expect(
allProperties.toStringDeep(),
'SemanticsNode#17(STALE, owner: null, leaf merge, Rect.fromLTRB(60.0, 20.0, 80.0, 50.0), clipped, actions: [longPress, scrollUp, showOnScreen], selected, label: "Use all the properties", textDirection: rtl)\n',
'SemanticsNode#17(STALE, owner: null, leaf merge, Rect.fromLTRB(60.0, 20.0, 80.0, 50.0), clipped, actions: [longPress, scrollUp, showOnScreen], unchecked, selected, label: "Use all the properties", textDirection: rtl)\n',
);
expect(
allProperties.getSemanticsData().toString(),
'SemanticsData(Rect.fromLTRB(50.0, 10.0, 70.0, 40.0), [1.0,0.0,0.0,10.0; 0.0,1.0,0.0,10.0; 0.0,0.0,1.0,0.0; 0.0,0.0,0.0,1.0], actions: [longPress, scrollUp, showOnScreen], flags: [isSelected], label: "Use all the properties", textDirection: rtl)',
'SemanticsData(Rect.fromLTRB(50.0, 10.0, 70.0, 40.0), [1.0,0.0,0.0,10.0; 0.0,1.0,0.0,10.0; 0.0,0.0,1.0,0.0; 0.0,0.0,0.0,1.0], actions: [longPress, scrollUp, showOnScreen], flags: [hasCheckedState, isSelected], label: "Use all the properties", textDirection: rtl)',
);
final SemanticsNode scaled = new SemanticsNode()
......@@ -223,37 +236,22 @@ void main() {
'SemanticsData(Rect.fromLTRB(50.0, 10.0, 70.0, 40.0), [10.0,0.0,0.0,0.0; 0.0,10.0,0.0,0.0; 0.0,0.0,1.0,0.0; 0.0,0.0,0.0,1.0])',
);
});
test('reset clears tags', () {
const SemanticsTag tag = const SemanticsTag('tag for testing');
final SemanticsNode node = new SemanticsNode();
expect(node.hasTag(tag), isFalse);
node.addTag(tag);
expect(node.hasTag(tag), isTrue);
node.reset();
expect(node.hasTag(tag), isFalse);
});
}
class TestRender extends RenderProxyBox {
TestRender({ this.action, this.isSemanticBoundary, RenderObject child }) : super(child);
@override
final bool isSemanticBoundary;
SemanticsAction action;
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
void _annotate(SemanticsNode node) {
node.addAction(action);
config
..isSemanticBoundary = isSemanticBoundary
..addAction(action, () { });
}
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'rendering_tester.dart';
void main() {
test('only send semantics update if semantics have changed', () {
final TestRender testRender = new TestRender()
..label = 'hello'
..textDirection = TextDirection.ltr;
final RenderObject tree = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0),
child: testRender,
);
int semanticsUpdateCount = 0;
final SemanticsHandle semanticsHandle = renderer.pipelineOwner.ensureSemantics(
listener: () {
++semanticsUpdateCount;
}
);
layout(tree, phase: EnginePhase.flushSemantics);
// Initial render does semantics.
expect(semanticsUpdateCount, 1);
expect(testRender.describeSemanticsConfigurationCallCount, isNot(0));
testRender.describeSemanticsConfigurationCallCount = 0;
semanticsUpdateCount = 0;
// Request semantics update even though nothing changed.
testRender.markNeedsSemanticsUpdate();
pumpFrame(phase: EnginePhase.flushSemantics);
// Object is asked for semantics, but no update is sent.
expect(semanticsUpdateCount, 0);
expect(testRender.describeSemanticsConfigurationCallCount, 1);
testRender.describeSemanticsConfigurationCallCount = 0;
semanticsUpdateCount = 0;
// Change semantics and request update.
testRender.label = 'bye';
testRender.markNeedsSemanticsUpdate();
pumpFrame(phase: EnginePhase.flushSemantics);
// Object is asked for semantics, and update is sent.
expect(semanticsUpdateCount, 1);
expect(testRender.describeSemanticsConfigurationCallCount, 1);
semanticsHandle.dispose();
});
}
class TestRender extends RenderSemanticsAnnotations {
int describeSemanticsConfigurationCallCount = 0;
@override
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
describeSemanticsConfigurationCallCount += 1;
}
}
......@@ -141,7 +141,7 @@ void main() {
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'a label')));
expect(semantics, includesNodeWith(label: 'a label'));
});
testWidgets('Null icon with semantic label', (WidgetTester tester) async {
......@@ -159,7 +159,7 @@ void main() {
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'a label')));
expect(semantics, includesNodeWith(label: 'a label'));
});
testWidgets('Changing semantic label from null doesn\'t rebuild tree ', (WidgetTester tester) async {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' show SemanticsFlags;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'semantics_tester.dart';
void main() {
testWidgets('Implicit Semantics merge behavior', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Semantics(
container: true,
explicitChildNodes: false,
child: new Column(
children: <Widget>[
const Text('Michael Goderbauer'),
const Text('goderbauer@google.com'),
],
),
),
),
);
// SemanticsNode#0()
// └SemanticsNode#1(label: "Michael Goderbauer\ngoderbauer@google.com", textDirection: ltr)
expect(
semantics,
hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'Michael Goderbauer\ngoderbauer@google.com',
),
],
),
ignoreRect: true,
ignoreTransform: true,
),
);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Semantics(
container: true,
explicitChildNodes: true,
child: new Column(
children: <Widget>[
const Text('Michael Goderbauer'),
const Text('goderbauer@google.com'),
],
),
),
),
);
// SemanticsNode#0()
// └SemanticsNode#1()
// ├SemanticsNode#2(label: "Michael Goderbauer", textDirection: ltr)
// └SemanticsNode#3(label: "goderbauer@google.com", textDirection: ltr)
expect(
semantics,
hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
children: <TestSemantics>[
new TestSemantics(
id: 2,
label: 'Michael Goderbauer',
),
new TestSemantics(
id: 3,
label: 'goderbauer@google.com',
),
],
),
],
),
ignoreRect: true,
ignoreTransform: true,
),
);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Semantics(
container: true,
explicitChildNodes: true,
child: new Semantics(
label: 'Signed in as',
child: new Column(
children: <Widget>[
const Text('Michael Goderbauer'),
const Text('goderbauer@google.com'),
],
),
),
),
),
);
// SemanticsNode#0()
// └SemanticsNode#1()
// └SemanticsNode#4(label: "Signed in as\nMichael Goderbauer\ngoderbauer@google.com", textDirection: ltr)
expect(
semantics,
hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
children: <TestSemantics>[
new TestSemantics(
id: 4,
label: 'Signed in as\nMichael Goderbauer\ngoderbauer@google.com',
),
],
),
],
),
ignoreRect: true,
ignoreTransform: true,
),
);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Semantics(
container: true,
explicitChildNodes: false,
child: new Semantics(
label: 'Signed in as',
child: new Column(
children: <Widget>[
const Text('Michael Goderbauer'),
const Text('goderbauer@google.com'),
],
),
),
),
),
);
// SemanticsNode#0()
// └SemanticsNode#1(label: "Signed in as\nMichael Goderbauer\ngoderbauer@google.com", textDirection: ltr)
expect(
semantics,
hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'Signed in as\nMichael Goderbauer\ngoderbauer@google.com',
),
],
),
ignoreRect: true,
ignoreTransform: true,
),
);
semantics.dispose();
});
testWidgets('Do not merge with conflicts', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Semantics(
container: true,
explicitChildNodes: false,
child: new Column(
children: <Widget>[
new Semantics(
label: 'node 1',
selected: true,
child: new Container(
width: 10.0,
height: 10.0,
),
),
new Semantics(
label: 'node 2',
selected: true,
child: new Container(
width: 10.0,
height: 10.0,
),
),
new Semantics(
label: 'node 3',
selected: true,
child: new Container(
width: 10.0,
height: 10.0,
),
),
],
),
),
),
);
// SemanticsNode#0()
// └SemanticsNode#8()
// ├SemanticsNode#5(selected, label: "node 1", textDirection: ltr)
// ├SemanticsNode#6(selected, label: "node 2", textDirection: ltr)
// └SemanticsNode#7(selected, label: "node 3", textDirection: ltr)
expect(
semantics,
hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 8,
children: <TestSemantics>[
new TestSemantics(
id: 5,
flags: SemanticsFlags.isSelected.index,
label: 'node 1',
),
new TestSemantics(
id: 6,
flags: SemanticsFlags.isSelected.index,
label: 'node 2',
),
new TestSemantics(
id: 7,
flags: SemanticsFlags.isSelected.index,
label: 'node 3',
),
],
),
],
),
ignoreRect: true,
ignoreTransform: true,
),
);
semantics.dispose();
});
}
......@@ -104,11 +104,11 @@ void main() {
final TestSemantics expectedSemantics = new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 2,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 2,
id: 1,
rect: TestSemantics.fullScreen,
actions: SemanticsAction.tap.index,
),
......
......@@ -94,12 +94,19 @@ class TestWidget extends SingleChildRenderObjectWidget {
}
class RenderTest extends RenderProxyBox {
@override
SemanticsAnnotator get semanticsAnnotator => isSemanticBoundary ? _annotate : null;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
if (!_isSemanticBoundary)
return;
config
..isSemanticBoundary = _isSemanticBoundary
..label = _label
..textDirection = TextDirection.ltr;
void _annotate(SemanticsNode node) {
node.label = _label;
node.textDirection = TextDirection.ltr;
}
String _label;
......@@ -111,8 +118,7 @@ class RenderTest extends RenderProxyBox {
callLog.add('markNeedsSemanticsUpdate(onlyChanges: true)');
}
@override
bool get isSemanticBoundary => _isSemanticBoundary;
bool _isSemanticBoundary;
set isSemanticBoundary(bool value) {
if (_isSemanticBoundary == value)
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'semantics_tester.dart';
void main() {
testWidgets('markNeedsSemanticsUpdate allways resets node', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(const TestWidget());
final RenderTest renderObj = tester.renderObject(find.byType(TestWidget));
expect(renderObj.labelWasReset, hasLength(1));
expect(renderObj.labelWasReset.last, true);
expect(semantics, includesNodeWith(label: 'Label 1'));
renderObj.markNeedsSemanticsUpdate(onlyLocalUpdates: false, noGeometry: false);
await tester.pumpAndSettle();
expect(renderObj.labelWasReset, hasLength(2));
expect(renderObj.labelWasReset.last, true);
expect(semantics, includesNodeWith(label: 'Label 2'));
renderObj.markNeedsSemanticsUpdate(onlyLocalUpdates: true, noGeometry: false);
await tester.pumpAndSettle();
expect(renderObj.labelWasReset, hasLength(3));
expect(renderObj.labelWasReset.last, true);
expect(semantics, includesNodeWith(label: 'Label 3'));
renderObj.markNeedsSemanticsUpdate(onlyLocalUpdates: true, noGeometry: true);
await tester.pumpAndSettle();
expect(renderObj.labelWasReset, hasLength(4));
expect(renderObj.labelWasReset.last, true);
expect(semantics, includesNodeWith(label: 'Label 4'));
renderObj.markNeedsSemanticsUpdate(onlyLocalUpdates: false, noGeometry: true);
await tester.pumpAndSettle();
expect(renderObj.labelWasReset, hasLength(5));
expect(renderObj.labelWasReset.last, true);
expect(semantics, includesNodeWith(label: 'Label 5'));
semantics.dispose();
});
}
class TestWidget extends SingleChildRenderObjectWidget {
const TestWidget({
Key key,
Widget child,
}) : super(key: key, child: child);
@override
RenderTest createRenderObject(BuildContext context) {
return new RenderTest();
}
}
class RenderTest extends RenderProxyBox {
List<bool> labelWasReset = <bool>[];
@override
SemanticsAnnotator get semanticsAnnotator => _annotate;
void _annotate(SemanticsNode node) {
labelWasReset.add(node.label == '');
node.label = 'Label ${labelWasReset.length}';
node.textDirection = TextDirection.ltr;
}
}
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' show SemanticsFlags;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -15,136 +17,221 @@ void main() {
// smoketest
await tester.pumpWidget(
new Container(
child: new Semantics(
label: 'test1',
textDirection: TextDirection.ltr,
child: new Container()
)
)
new Semantics(
container: true,
child: new Container(
child: new Semantics(
label: 'test1',
textDirection: TextDirection.ltr,
child: new Container(),
selected: true,
),
),
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'test1')));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'test1',
rect: TestSemantics.fullScreen,
flags: SemanticsFlags.isSelected.index,
)
]
)));
// control for forking
await tester.pumpWidget(
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr),
)
),
],
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'child1')));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'child1',
rect: TestSemantics.fullScreen,
flags: SemanticsFlags.isSelected.index,
)
],
)));
// forking semantics
await tester.pumpWidget(
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr),
)
),
],
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
),
new TestSemantics.rootChild(
id: 2,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
),
],
)
));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 2,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
new TestSemantics(
id: 3,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
],
),
],
), ignoreTransform: true));
// toggle a branch off
await tester.pumpWidget(
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
)
),
],
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'child1')));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'child1',
rect: TestSemantics.fullScreen,
flags: SemanticsFlags.isSelected.index,
)
],
)));
// toggle a branch back on
await tester.pumpWidget(
new Column(
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
)
),
],
crossAxisAlignment: CrossAxisAlignment.stretch
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
),
new TestSemantics.rootChild(
id: 2,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
),
],
)
));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 4,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
new TestSemantics(
id: 3,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
],
),
],
), ignoreTransform: true));
semantics.dispose();
});
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' show SemanticsFlags;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -19,105 +21,153 @@ void main() {
// forking semantics
await tester.pumpWidget(
new Column(
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
)
),
],
crossAxisAlignment: CrossAxisAlignment.stretch
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'child1',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
),
new TestSemantics.rootChild(
id: 2,
label: 'child2',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
),
],
)
));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 1,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
new TestSemantics(
id: 2,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
],
),
],
), ignoreTransform: true));
// toggle a branch off
await tester.pumpWidget(
new Column(
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
)
),
],
crossAxisAlignment: CrossAxisAlignment.stretch
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: true,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(new TestSemantics.root(label: 'child1')));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
label: 'child1',
rect: TestSemantics.fullScreen,
flags: SemanticsFlags.isSelected.index,
)
],
)));
// toggle a branch back on
await tester.pumpWidget(
new Column(
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(label: 'child1', textDirection: TextDirection.ltr)
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(label: 'child2', textDirection: TextDirection.ltr)
)
),
],
crossAxisAlignment: CrossAxisAlignment.stretch
)
new Semantics(
container: true,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 10.0,
child: const Semantics(
label: 'child1',
textDirection: TextDirection.ltr,
selected: true,
),
),
new Container(
height: 10.0,
child: const IgnorePointer(
ignoring: false,
child: const Semantics(
label: 'child2',
textDirection: TextDirection.ltr,
selected: true,
),
),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
label: 'child1',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
),
new TestSemantics.rootChild(
id: 2,
label: 'child2',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
transform: new Matrix4.translationValues(0.0, 10.0, 0.0),
),
],
)
));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 4,
label: 'child1',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
new TestSemantics(
id: 2,
label: 'child2',
rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 10.0),
flags: SemanticsFlags.isSelected.index,
),
],
),
],
), ignoreTransform: true));
semantics.dispose();
});
......
......@@ -16,81 +16,112 @@ void main() {
// implicit annotators
await tester.pumpWidget(
new Container(
child: new Semantics(
label: 'test',
textDirection: TextDirection.ltr,
child: new Container(
child: const Semantics(
checked: true
)
)
)
)
new Semantics(
container: true,
child: new Container(
child: new Semantics(
label: 'test',
textDirection: TextDirection.ltr,
child: new Container(
child: const Semantics(
checked: true
),
),
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'test',
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'test',
rect: TestSemantics.fullScreen,
)
]
)
));
// remove one
await tester.pumpWidget(
new Container(
new Semantics(
container: true,
child: new Container(
child: const Semantics(
checked: true
)
)
)
checked: true,
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
rect: TestSemantics.fullScreen,
),
]
)
));
// change what it says
await tester.pumpWidget(
new Container(
new Semantics(
container: true,
child: new Container(
child: const Semantics(
label: 'test',
textDirection: TextDirection.ltr,
)
)
)
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
label: 'test',
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'test',
textDirection: TextDirection.ltr,
rect: TestSemantics.fullScreen,
),
]
)
));
// add a node
await tester.pumpWidget(
new Container(
child: new Semantics(
checked: true,
child: new Container(
new Semantics(
container: true,
child: new Container(
child: const Semantics(
checked: true,
child: const Semantics(
label: 'test',
textDirection: TextDirection.ltr,
)
)
)
)
),
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'test',
)
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'test',
rect: TestSemantics.fullScreen,
)
],
),
));
int changeCount = 0;
......@@ -100,17 +131,18 @@ void main() {
// make no changes
await tester.pumpWidget(
new Container(
child: new Semantics(
checked: true,
child: new Container(
new Semantics(
container: true,
child: new Container(
child: const Semantics(
checked: true,
child: const Semantics(
label: 'test',
textDirection: TextDirection.ltr,
)
)
)
)
),
),
),
),
);
expect(changeCount, 0);
......
......@@ -6,6 +6,7 @@ import 'dart:ui' show SemanticsFlags;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'semantics_tester.dart';
......@@ -26,10 +27,12 @@ void main() {
fit: StackFit.expand,
children: <Widget>[
const Semantics(
container: true,
label: 'L1',
),
new Semantics(
label: 'L2',
container: true,
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
......@@ -50,22 +53,22 @@ void main() {
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 3,
label: 'L1',
rect: TestSemantics.fullScreen,
),
new TestSemantics.rootChild(
id: 2,
id: 4,
label: 'L2',
rect: TestSemantics.fullScreen,
children: <TestSemantics>[
new TestSemantics(
id: 3,
id: 1,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
rect: TestSemantics.fullScreen,
),
new TestSemantics(
id: 4,
id: 2,
flags: SemanticsFlags.hasCheckedState.index,
rect: TestSemantics.fullScreen,
),
......@@ -87,9 +90,11 @@ void main() {
children: <Widget>[
const Semantics(
label: 'L1',
container: true,
),
new Semantics(
label: 'L2',
container: true,
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
......@@ -108,12 +113,12 @@ void main() {
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 3,
label: 'L1',
rect: TestSemantics.fullScreen,
),
new TestSemantics.rootChild(
id: 2,
id: 4,
label: 'L2',
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
rect: TestSemantics.fullScreen,
......@@ -134,6 +139,7 @@ void main() {
const Semantics(),
new Semantics(
label: 'L2',
container: true,
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
......@@ -150,8 +156,14 @@ void main() {
expect(semantics, hasSemantics(
new TestSemantics.root(
label: 'L2',
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 4,
label: 'L2',
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
rect: TestSemantics.fullScreen,
),
],
)
));
......
......@@ -55,7 +55,7 @@ void main() {
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 3,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: label,
rect: TestSemantics.fullScreen,
......@@ -111,7 +111,7 @@ void main() {
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
id: 3,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: label,
rect: TestSemantics.fullScreen,
......
......@@ -39,9 +39,15 @@ void main() {
expect(semantics, hasSemantics(
new TestSemantics.root(
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'label',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'label',
textDirection: TextDirection.ltr,
rect: TestSemantics.fullScreen,
)
]
)
));
......@@ -71,10 +77,16 @@ void main() {
expect(semantics, hasSemantics(
new TestSemantics.root(
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'label',
textDirection: TextDirection.ltr,
)
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
flags: SemanticsFlags.hasCheckedState.index | SemanticsFlags.isChecked.index,
label: 'label',
textDirection: TextDirection.ltr,
rect: TestSemantics.fullScreen,
)
],
),
));
semantics.dispose();
......
......@@ -61,6 +61,7 @@ void main() {
new Semantics(
label: '#2',
container: true,
explicitChildNodes: true,
child: new Stack(
children: <Widget>[
new Semantics(
......@@ -146,9 +147,12 @@ class RenderBoundaryBlockSemantics extends RenderProxyBox {
RenderBoundaryBlockSemantics({ RenderBox child }) : super(child);
@override
bool get isBlockingSemanticsOfPreviouslyPaintedNodes => true;
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
@override
bool get isSemanticBoundary => true;
config
..isBlockingSemanticsOfPreviouslyPaintedNodes = true
..isSemanticBoundary = true;
}
}
......@@ -62,15 +62,9 @@ void main() {
final SemanticsNode node1 = tester.renderObject(find.byWidget(const Text('1'))).debugSemantics;
final SemanticsNode node2 = tester.renderObject(find.byWidget(const Text('2'))).debugSemantics;
final SemanticsNode node3 = tester.renderObject(find.byWidget(const Text('3'))).debugSemantics;
expect(node1.wasAffectedByClip, false);
expect(node2.wasAffectedByClip, true);
expect(node3.wasAffectedByClip, true);
expect(node1.isInvisible, isFalse);
expect(node2.isInvisible, isFalse);
expect(node3.isInvisible, isTrue);
semantics.dispose();
});
......@@ -117,12 +111,12 @@ void main() {
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics(
id: 4,
id: 3,
label: '1',
rect: new Rect.fromLTRB(0.0, 0.0, 75.0, 14.0),
),
new TestSemantics(
id: 5,
id: 4,
label: '2\n3',
rect: new Rect.fromLTRB(0.0, 0.0, 25.0, 14.0), // clipped form original 75.0 to 25.0
),
......
......@@ -53,7 +53,14 @@ void main() {
);
expect(semantics, hasSemantics(
new TestSemantics.root(label: 'test1\ntest2'),
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
label: 'test1\ntest2',
),
]
),
ignoreRect: true,
ignoreTransform: true,
));
......@@ -74,8 +81,8 @@ void main() {
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(id: 5, label: 'test1'),
new TestSemantics.rootChild(id: 6, label: 'test2'),
new TestSemantics.rootChild(id: 4, label: 'test1'),
new TestSemantics.rootChild(id: 5, label: 'test2'),
],
),
ignoreRect: true,
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'semantics_tester.dart';
void main() {
testWidgets('Simple tree is simple', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
const Center(
child: const Text('Hello!', textDirection: TextDirection.ltr)
),
);
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
label: 'Hello!',
textDirection: TextDirection.ltr,
rect: new Rect.fromLTRB(0.0, 0.0, 84.0, 14.0),
transform: new Matrix4.translationValues(358.0, 293.0, 0.0),
)
],
)));
semantics.dispose();
});
testWidgets('Simple tree is simple - material', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
// Not using Text widget because of https://github.com/flutter/flutter/issues/12357.
await tester.pumpWidget(new MaterialApp(
home: new Center(
child: new Semantics(
label: 'Hello!',
child: new Container(
width: 10.0,
height: 10.0,
),
),
),
));
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 2,
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),
)
],
)));
semantics.dispose();
});
}
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