From d61b4fae64bd773e0d5cd6a6719c7c7a87a536f2 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 23 Jul 2018 15:28:34 -0700 Subject: [PATCH] Add ignoringSemantics argument to AbsorbPointer (#19651) --- .../flutter/lib/src/rendering/proxy_box.dart | 46 ++++++++++++++++++- packages/flutter/lib/src/widgets/basic.dart | 29 ++++++++++-- .../test/widgets/absorb_pointer_test.dart | 41 ++++++++++++++++- 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index ec837823ae..01cd6a4933 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -2881,8 +2881,11 @@ class RenderAbsorbPointer extends RenderProxyBox { /// The [absorbing] argument must not be null. RenderAbsorbPointer({ RenderBox child, - this.absorbing = true + bool absorbing = true, + bool ignoringSemantics, }) : assert(absorbing != null), + _absorbing = absorbing, + _ignoringSemantics = ignoringSemantics, super(child); /// Whether this render object absorbs pointers during hit testing. @@ -2890,7 +2893,33 @@ class RenderAbsorbPointer extends RenderProxyBox { /// Regardless of whether this render object absorbs pointers during hit /// testing, it will still consume space during layout and be visible during /// painting. - bool absorbing; + bool get absorbing => _absorbing; + bool _absorbing; + set absorbing(bool value) { + if (_absorbing == value) + return; + _absorbing = value; + if (ignoringSemantics == null) + markNeedsSemanticsUpdate(); + } + + /// Whether the semantics of this render object is ignored when compiling the semantics tree. + /// + /// If null, defaults to value of [absorbing]. + /// + /// See [SemanticsNode] for additional information about the semantics tree. + bool get ignoringSemantics => _ignoringSemantics; + bool _ignoringSemantics; + set ignoringSemantics(bool value) { + if (value == _ignoringSemantics) + return; + final bool oldEffectiveValue = _effectiveIgnoringSemantics; + _ignoringSemantics = value; + if (oldEffectiveValue != _effectiveIgnoringSemantics) + markNeedsSemanticsUpdate(); + } + + bool get _effectiveIgnoringSemantics => ignoringSemantics == null ? absorbing : ignoringSemantics; @override bool hitTest(HitTestResult result, { Offset position }) { @@ -2899,10 +2928,23 @@ class RenderAbsorbPointer extends RenderProxyBox { : super.hitTest(result, position: position); } + @override + void visitChildrenForSemantics(RenderObjectVisitor visitor) { + if (child != null && !_effectiveIgnoringSemantics) + visitor(child); + } + @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(new DiagnosticsProperty('absorbing', absorbing)); + properties.add( + new DiagnosticsProperty( + 'ignoringSemantics', + _effectiveIgnoringSemantics, + description: ignoringSemantics == null ? 'implicitly $_effectiveIgnoringSemantics' : null, + ), + ); } } diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index b46efef71d..4eed28a9e3 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -4949,7 +4949,8 @@ class AbsorbPointer extends SingleChildRenderObjectWidget { const AbsorbPointer({ Key key, this.absorbing = true, - Widget child + Widget child, + this.ignoringSemantics, }) : assert(absorbing != null), super(key: key, child: child); @@ -4960,12 +4961,34 @@ class AbsorbPointer extends SingleChildRenderObjectWidget { /// painting. final bool absorbing; + /// Whether the semantics of this render object is ignored when compiling the + /// semantics tree. + /// + /// If null, defaults to the value of [absorbing]. + /// + /// See [SemanticsNode] for additional information about the semantics tree. + final bool ignoringSemantics; + @override - RenderAbsorbPointer createRenderObject(BuildContext context) => new RenderAbsorbPointer(absorbing: absorbing); + RenderAbsorbPointer createRenderObject(BuildContext context) { + return new RenderAbsorbPointer( + absorbing: absorbing, + ignoringSemantics: ignoringSemantics, + ); + } @override void updateRenderObject(BuildContext context, RenderAbsorbPointer renderObject) { - renderObject.absorbing = absorbing; + renderObject + ..absorbing = absorbing + ..ignoringSemantics = ignoringSemantics; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(new DiagnosticsProperty('absorbing', absorbing)); + properties.add(new DiagnosticsProperty('ignoringSemantics', ignoringSemantics, defaultValue: null)); } } diff --git a/packages/flutter/test/widgets/absorb_pointer_test.dart b/packages/flutter/test/widgets/absorb_pointer_test.dart index 2a7d8641c3..5faa6d9406 100644 --- a/packages/flutter/test/widgets/absorb_pointer_test.dart +++ b/packages/flutter/test/widgets/absorb_pointer_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; +import 'semantics_tester.dart'; + void main() { testWidgets('AbsorbPointers do not block siblings', (WidgetTester tester) async { bool tapped = false; @@ -28,4 +30,41 @@ void main() { await tester.tap(find.byType(GestureDetector)); expect(tapped, true); }); -} \ No newline at end of file + + testWidgets('AbsorbPointers semantics', (WidgetTester tester) async { + final SemanticsTester semantics = new SemanticsTester(tester); + await tester.pumpWidget( + new AbsorbPointer( + absorbing: true, + child: new Semantics( + label: 'test', + textDirection: TextDirection.ltr, + ), + ), + ); + expect(semantics, hasSemantics( + new TestSemantics.root(), ignoreId: true, ignoreRect: true, ignoreTransform: true)); + + await tester.pumpWidget( + new AbsorbPointer( + absorbing: false, + child: new Semantics( + label: 'test', + textDirection: TextDirection.ltr, + ), + ), + ); + + expect(semantics, hasSemantics( + new TestSemantics.root( + children: [ + new TestSemantics.rootChild( + label: 'test', + textDirection: TextDirection.ltr, + ), + ], + ), + ignoreId: true, ignoreRect: true, ignoreTransform: true)); + semantics.dispose(); + }); +}