Skip to content

Commit c8c20fb

Browse files
authored
add read only semantics flag (flutter#34683)
1 parent 0d9a1b2 commit c8c20fb

File tree

9 files changed

+45
-1
lines changed

9 files changed

+45
-1
lines changed

bin/internal/engine.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20d3861ac8e1f8f38c8659b16b699d0e63db01b1
1+
54f88ab5da4d0f3cff5337ab263dbf3385ee78df

packages/flutter/lib/src/rendering/custom_paint.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ class RenderCustomPaint extends RenderProxyBox {
832832
if (properties.textField != null) {
833833
config.isTextField = properties.textField;
834834
}
835+
if (properties.readOnly != null) {
836+
config.isReadOnly = properties.readOnly;
837+
}
835838
if (properties.focused != null) {
836839
config.isFocused = properties.focused;
837840
}

packages/flutter/lib/src/rendering/proxy_box.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
34263426
bool button,
34273427
bool header,
34283428
bool textField,
3429+
bool readOnly,
34293430
bool focused,
34303431
bool inMutuallyExclusiveGroup,
34313432
bool obscured,
@@ -3473,6 +3474,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
34733474
_button = button,
34743475
_header = header,
34753476
_textField = textField,
3477+
_readOnly = readOnly,
34763478
_focused = focused,
34773479
_inMutuallyExclusiveGroup = inMutuallyExclusiveGroup,
34783480
_obscured = obscured,
@@ -3629,6 +3631,16 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
36293631
markNeedsSemanticsUpdate();
36303632
}
36313633

3634+
/// If non-null, sets the [SemanticsNode.isReadOnly] semantic to the given value.
3635+
bool get readOnly => _readOnly;
3636+
bool _readOnly;
3637+
set readOnly(bool value) {
3638+
if (readOnly == value)
3639+
return;
3640+
_readOnly = value;
3641+
markNeedsSemanticsUpdate();
3642+
}
3643+
36323644
/// If non-null, sets the [SemanticsNode.isFocused] semantic to the given value.
36333645
bool get focused => _focused;
36343646
bool _focused;
@@ -4252,6 +4264,8 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
42524264
config.isHeader = header;
42534265
if (textField != null)
42544266
config.isTextField = textField;
4267+
if (readOnly != null)
4268+
config.isReadOnly = readOnly;
42554269
if (focused != null)
42564270
config.isFocused = focused;
42574271
if (inMutuallyExclusiveGroup != null)

packages/flutter/lib/src/semantics/semantics.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ class SemanticsProperties extends DiagnosticableTree {
565565
this.button,
566566
this.header,
567567
this.textField,
568+
this.readOnly,
568569
this.focused,
569570
this.inMutuallyExclusiveGroup,
570571
this.hidden,
@@ -651,6 +652,13 @@ class SemanticsProperties extends DiagnosticableTree {
651652
/// text field.
652653
final bool textField;
653654

655+
/// If non-null, indicates that this subtree is read only.
656+
///
657+
/// Only applicable when [textField] is true
658+
///
659+
/// TalkBack/VoiceOver will treat it as non-editable text field.
660+
final bool readOnly;
661+
654662
/// If non-null, whether the node currently holds input focus.
655663
///
656664
/// At most one node in the tree should hold input focus at any point in time.
@@ -3506,6 +3514,14 @@ class SemanticsConfiguration {
35063514
_setFlag(SemanticsFlag.isTextField, value);
35073515
}
35083516

3517+
/// Whether the owning [RenderObject] is read only.
3518+
///
3519+
/// Only applicable when [isTextField] is true.
3520+
bool get isReadOnly => _hasFlag(SemanticsFlag.isReadOnly);
3521+
set isReadOnly(bool value) {
3522+
_setFlag(SemanticsFlag.isReadOnly, value);
3523+
}
3524+
35093525
/// Whether the [value] should be obscured.
35103526
///
35113527
/// This option is usually set in combination with [textField] to indicate

packages/flutter/lib/src/widgets/basic.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5919,6 +5919,7 @@ class Semantics extends SingleChildRenderObjectWidget {
59195919
bool button,
59205920
bool header,
59215921
bool textField,
5922+
bool readOnly,
59225923
bool focused,
59235924
bool inMutuallyExclusiveGroup,
59245925
bool obscured,
@@ -5968,6 +5969,7 @@ class Semantics extends SingleChildRenderObjectWidget {
59685969
button: button,
59695970
header: header,
59705971
textField: textField,
5972+
readOnly: readOnly,
59715973
focused: focused,
59725974
inMutuallyExclusiveGroup: inMutuallyExclusiveGroup,
59735975
obscured: obscured,
@@ -6076,6 +6078,7 @@ class Semantics extends SingleChildRenderObjectWidget {
60766078
button: properties.button,
60776079
header: properties.header,
60786080
textField: properties.textField,
6081+
readOnly: properties.readOnly,
60796082
focused: properties.focused,
60806083
liveRegion: properties.liveRegion,
60816084
inMutuallyExclusiveGroup: properties.inMutuallyExclusiveGroup,
@@ -6141,6 +6144,7 @@ class Semantics extends SingleChildRenderObjectWidget {
61416144
..button = properties.button
61426145
..header = properties.header
61436146
..textField = properties.textField
6147+
..readOnly = properties.readOnly
61446148
..focused = properties.focused
61456149
..inMutuallyExclusiveGroup = properties.inMutuallyExclusiveGroup
61466150
..obscured = properties.obscured

packages/flutter/test/widgets/custom_painter_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ void _defineTests() {
412412
hidden: true,
413413
button: true,
414414
textField: true,
415+
readOnly: true,
415416
focused: true,
416417
inMutuallyExclusiveGroup: true,
417418
header: true,
@@ -458,6 +459,7 @@ void _defineTests() {
458459
hidden: true,
459460
button: true,
460461
textField: true,
462+
readOnly: true,
461463
focused: true,
462464
inMutuallyExclusiveGroup: true,
463465
header: true,

packages/flutter/test/widgets/semantics_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ void main() {
474474
selected: true,
475475
button: true,
476476
textField: true,
477+
readOnly: true,
477478
focused: true,
478479
inMutuallyExclusiveGroup: true,
479480
header: true,

packages/flutter_test/lib/src/matchers.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ Matcher matchesSemantics({
413413
bool isButton = false,
414414
bool isFocused = false,
415415
bool isTextField = false,
416+
bool isReadOnly = false,
416417
bool hasEnabledState = false,
417418
bool isEnabled = false,
418419
bool isInMutuallyExclusiveGroup = false,
@@ -464,6 +465,8 @@ Matcher matchesSemantics({
464465
flags.add(SemanticsFlag.isButton);
465466
if (isTextField)
466467
flags.add(SemanticsFlag.isTextField);
468+
if (isReadOnly)
469+
flags.add(SemanticsFlag.isReadOnly);
467470
if (isFocused)
468471
flags.add(SemanticsFlag.isFocused);
469472
if (hasEnabledState)

packages/flutter_test/test/matchers_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ void main() {
597597
isSelected: true,
598598
isButton: true,
599599
isTextField: true,
600+
isReadOnly: true,
600601
hasEnabledState: true,
601602
isFocused: true,
602603
isEnabled: true,

0 commit comments

Comments
 (0)