From c8c20fbc1f24bde6741b7a78e86104c5b9c4f180 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Wed, 19 Jun 2019 14:41:44 -0700 Subject: [PATCH] add read only semantics flag (#34683) --- bin/internal/engine.version | 2 +- .../flutter/lib/src/rendering/custom_paint.dart | 3 +++ .../flutter/lib/src/rendering/proxy_box.dart | 14 ++++++++++++++ .../flutter/lib/src/semantics/semantics.dart | 16 ++++++++++++++++ packages/flutter/lib/src/widgets/basic.dart | 4 ++++ .../test/widgets/custom_painter_test.dart | 2 ++ .../flutter/test/widgets/semantics_test.dart | 1 + packages/flutter_test/lib/src/matchers.dart | 3 +++ packages/flutter_test/test/matchers_test.dart | 1 + 9 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bin/internal/engine.version b/bin/internal/engine.version index 10a6760455f..1fb4d38aa53 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -20d3861ac8e1f8f38c8659b16b699d0e63db01b1 +54f88ab5da4d0f3cff5337ab263dbf3385ee78df diff --git a/packages/flutter/lib/src/rendering/custom_paint.dart b/packages/flutter/lib/src/rendering/custom_paint.dart index 44bf46e7ff2..3edf4747713 100644 --- a/packages/flutter/lib/src/rendering/custom_paint.dart +++ b/packages/flutter/lib/src/rendering/custom_paint.dart @@ -832,6 +832,9 @@ class RenderCustomPaint extends RenderProxyBox { if (properties.textField != null) { config.isTextField = properties.textField; } + if (properties.readOnly != null) { + config.isReadOnly = properties.readOnly; + } if (properties.focused != null) { config.isFocused = properties.focused; } diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index c6ae96aa900..cef3bfbb24e 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -3426,6 +3426,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox { bool button, bool header, bool textField, + bool readOnly, bool focused, bool inMutuallyExclusiveGroup, bool obscured, @@ -3473,6 +3474,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox { _button = button, _header = header, _textField = textField, + _readOnly = readOnly, _focused = focused, _inMutuallyExclusiveGroup = inMutuallyExclusiveGroup, _obscured = obscured, @@ -3629,6 +3631,16 @@ class RenderSemanticsAnnotations extends RenderProxyBox { markNeedsSemanticsUpdate(); } + /// If non-null, sets the [SemanticsNode.isReadOnly] semantic to the given value. + bool get readOnly => _readOnly; + bool _readOnly; + set readOnly(bool value) { + if (readOnly == value) + return; + _readOnly = value; + markNeedsSemanticsUpdate(); + } + /// If non-null, sets the [SemanticsNode.isFocused] semantic to the given value. bool get focused => _focused; bool _focused; @@ -4252,6 +4264,8 @@ class RenderSemanticsAnnotations extends RenderProxyBox { config.isHeader = header; if (textField != null) config.isTextField = textField; + if (readOnly != null) + config.isReadOnly = readOnly; if (focused != null) config.isFocused = focused; if (inMutuallyExclusiveGroup != null) diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index e1f57faea87..e23c9978b0a 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -565,6 +565,7 @@ class SemanticsProperties extends DiagnosticableTree { this.button, this.header, this.textField, + this.readOnly, this.focused, this.inMutuallyExclusiveGroup, this.hidden, @@ -651,6 +652,13 @@ class SemanticsProperties extends DiagnosticableTree { /// text field. final bool textField; + /// If non-null, indicates that this subtree is read only. + /// + /// Only applicable when [textField] is true + /// + /// TalkBack/VoiceOver will treat it as non-editable text field. + final bool readOnly; + /// If non-null, whether the node currently holds input focus. /// /// At most one node in the tree should hold input focus at any point in time. @@ -3506,6 +3514,14 @@ class SemanticsConfiguration { _setFlag(SemanticsFlag.isTextField, value); } + /// Whether the owning [RenderObject] is read only. + /// + /// Only applicable when [isTextField] is true. + bool get isReadOnly => _hasFlag(SemanticsFlag.isReadOnly); + set isReadOnly(bool value) { + _setFlag(SemanticsFlag.isReadOnly, value); + } + /// Whether the [value] should be obscured. /// /// This option is usually set in combination with [textField] to indicate diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index a786091c3a8..5a7ef803e03 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -5919,6 +5919,7 @@ class Semantics extends SingleChildRenderObjectWidget { bool button, bool header, bool textField, + bool readOnly, bool focused, bool inMutuallyExclusiveGroup, bool obscured, @@ -5968,6 +5969,7 @@ class Semantics extends SingleChildRenderObjectWidget { button: button, header: header, textField: textField, + readOnly: readOnly, focused: focused, inMutuallyExclusiveGroup: inMutuallyExclusiveGroup, obscured: obscured, @@ -6076,6 +6078,7 @@ class Semantics extends SingleChildRenderObjectWidget { button: properties.button, header: properties.header, textField: properties.textField, + readOnly: properties.readOnly, focused: properties.focused, liveRegion: properties.liveRegion, inMutuallyExclusiveGroup: properties.inMutuallyExclusiveGroup, @@ -6141,6 +6144,7 @@ class Semantics extends SingleChildRenderObjectWidget { ..button = properties.button ..header = properties.header ..textField = properties.textField + ..readOnly = properties.readOnly ..focused = properties.focused ..inMutuallyExclusiveGroup = properties.inMutuallyExclusiveGroup ..obscured = properties.obscured diff --git a/packages/flutter/test/widgets/custom_painter_test.dart b/packages/flutter/test/widgets/custom_painter_test.dart index e7267224f08..eed74c33687 100644 --- a/packages/flutter/test/widgets/custom_painter_test.dart +++ b/packages/flutter/test/widgets/custom_painter_test.dart @@ -412,6 +412,7 @@ void _defineTests() { hidden: true, button: true, textField: true, + readOnly: true, focused: true, inMutuallyExclusiveGroup: true, header: true, @@ -458,6 +459,7 @@ void _defineTests() { hidden: true, button: true, textField: true, + readOnly: true, focused: true, inMutuallyExclusiveGroup: true, header: true, diff --git a/packages/flutter/test/widgets/semantics_test.dart b/packages/flutter/test/widgets/semantics_test.dart index 723930ae0fb..7385f219046 100644 --- a/packages/flutter/test/widgets/semantics_test.dart +++ b/packages/flutter/test/widgets/semantics_test.dart @@ -474,6 +474,7 @@ void main() { selected: true, button: true, textField: true, + readOnly: true, focused: true, inMutuallyExclusiveGroup: true, header: true, diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index fc3efb1d43f..cd041c9c25f 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -413,6 +413,7 @@ Matcher matchesSemantics({ bool isButton = false, bool isFocused = false, bool isTextField = false, + bool isReadOnly = false, bool hasEnabledState = false, bool isEnabled = false, bool isInMutuallyExclusiveGroup = false, @@ -464,6 +465,8 @@ Matcher matchesSemantics({ flags.add(SemanticsFlag.isButton); if (isTextField) flags.add(SemanticsFlag.isTextField); + if (isReadOnly) + flags.add(SemanticsFlag.isReadOnly); if (isFocused) flags.add(SemanticsFlag.isFocused); if (hasEnabledState) diff --git a/packages/flutter_test/test/matchers_test.dart b/packages/flutter_test/test/matchers_test.dart index dd370e0707b..b2108e29ae0 100644 --- a/packages/flutter_test/test/matchers_test.dart +++ b/packages/flutter_test/test/matchers_test.dart @@ -597,6 +597,7 @@ void main() { isSelected: true, isButton: true, isTextField: true, + isReadOnly: true, hasEnabledState: true, isFocused: true, isEnabled: true,