Skip to content

Commit 798ff59

Browse files
authored
Update some semantics flags updated to use enum (engine, framework, web) (flutter#170696)
issue: flutter#166101, new Updates : Add new enum Tristate and CheckedState in for 7 flags. For CheckState, it used to use 3 bools (hasCheck, isChecked, isCheckStateMixed) to represent check states, replace them with a CheckState enum. For other 6 flags, each has 2 bools (hasXXState and isXX), replace them with a Tristate enum. This will be a breaking changes to the SemanticsFlags class , which was added in April in flutter#166101 and flutter#167771 , will write a breaking change doc for this PR ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 699f21a commit 798ff59

23 files changed

Lines changed: 682 additions & 746 deletions

File tree

engine/src/flutter/lib/ui/semantics.dart

Lines changed: 177 additions & 198 deletions
Large diffs are not rendered by default.

engine/src/flutter/lib/ui/semantics/semantics_flags.cc

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ NativeSemanticsFlags::~NativeSemanticsFlags() {}
1818

1919
void NativeSemanticsFlags::initSemanticsFlags(
2020
Dart_Handle semantics_flags_handle,
21-
bool hasCheckedState,
22-
bool isChecked,
23-
bool isSelected,
21+
int isChecked,
22+
int isSelected,
23+
int isEnabled,
24+
int isToggled,
25+
int isExpanded,
26+
int isRequired,
27+
int isFocused,
2428
bool isButton,
2529
bool isTextField,
26-
bool isFocused,
27-
bool hasEnabledState,
28-
bool isEnabled,
2930
bool isInMutuallyExclusiveGroup,
3031
bool isHeader,
3132
bool isObscured,
@@ -34,34 +35,27 @@ void NativeSemanticsFlags::initSemanticsFlags(
3435
bool isHidden,
3536
bool isImage,
3637
bool isLiveRegion,
37-
bool hasToggledState,
38-
bool isToggled,
3938
bool hasImplicitScrolling,
4039
bool isMultiline,
4140
bool isReadOnly,
4241
bool isFocusable,
4342
bool isLink,
4443
bool isSlider,
45-
bool isKeyboardKey,
46-
bool isCheckStateMixed,
47-
bool hasExpandedState,
48-
bool isExpanded,
49-
bool hasSelectedState,
50-
bool hasRequiredState,
51-
bool isRequired) {
44+
bool isKeyboardKey) {
5245
UIDartState::ThrowIfUIOperationsProhibited();
5346
auto native_semantics_flags = fml::MakeRefCounted<NativeSemanticsFlags>();
5447
native_semantics_flags->AssociateWithDartWrapper(semantics_flags_handle);
5548

5649
native_semantics_flags->flags_ = SemanticsFlags{
57-
.hasCheckedState = hasCheckedState,
58-
.isChecked = isChecked,
59-
.isSelected = isSelected,
50+
.isChecked = static_cast<SemanticsCheckState>(isChecked),
51+
.isSelected = static_cast<SemanticsTristate>(isSelected),
52+
.isEnabled = static_cast<SemanticsTristate>(isEnabled),
53+
.isToggled = static_cast<SemanticsTristate>(isToggled),
54+
.isExpanded = static_cast<SemanticsTristate>(isExpanded),
55+
.isRequired = static_cast<SemanticsTristate>(isRequired),
56+
.isFocused = static_cast<SemanticsTristate>(isFocused),
6057
.isButton = isButton,
6158
.isTextField = isTextField,
62-
.isFocused = isFocused,
63-
.hasEnabledState = hasEnabledState,
64-
.isEnabled = isEnabled,
6559
.isInMutuallyExclusiveGroup = isInMutuallyExclusiveGroup,
6660
.isHeader = isHeader,
6761
.isObscured = isObscured,
@@ -70,21 +64,12 @@ void NativeSemanticsFlags::initSemanticsFlags(
7064
.isHidden = isHidden,
7165
.isImage = isImage,
7266
.isLiveRegion = isLiveRegion,
73-
.hasToggledState = hasToggledState,
74-
.isToggled = isToggled,
7567
.hasImplicitScrolling = hasImplicitScrolling,
7668
.isMultiline = isMultiline,
7769
.isReadOnly = isReadOnly,
78-
.isFocusable = isFocusable,
7970
.isLink = isLink,
8071
.isSlider = isSlider,
8172
.isKeyboardKey = isKeyboardKey,
82-
.isCheckStateMixed = isCheckStateMixed,
83-
.hasExpandedState = hasExpandedState,
84-
.isExpanded = isExpanded,
85-
.hasSelectedState = hasSelectedState,
86-
.hasRequiredState = hasRequiredState,
87-
.isRequired = isRequired,
8873
};
8974
}
9075

engine/src/flutter/lib/ui/semantics/semantics_flags.h

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,28 @@
1010

1111
namespace flutter {
1212

13+
enum class SemanticsTristate : int32_t {
14+
kNone = 0,
15+
kTrue = 1,
16+
kFalse = 2,
17+
};
18+
enum class SemanticsCheckState : int32_t {
19+
kNone = 0,
20+
kTrue = 1,
21+
kFalse = 2,
22+
kMixed = 3,
23+
};
24+
1325
struct SemanticsFlags {
14-
bool hasCheckedState = false;
15-
bool isChecked = false;
16-
bool isSelected = false;
26+
SemanticsCheckState isChecked = SemanticsCheckState::kNone;
27+
SemanticsTristate isSelected = SemanticsTristate::kNone;
28+
SemanticsTristate isEnabled = SemanticsTristate::kNone;
29+
SemanticsTristate isToggled = SemanticsTristate::kNone;
30+
SemanticsTristate isExpanded = SemanticsTristate::kNone;
31+
SemanticsTristate isRequired = SemanticsTristate::kNone;
32+
SemanticsTristate isFocused = SemanticsTristate::kNone;
1733
bool isButton = false;
1834
bool isTextField = false;
19-
bool isFocused = false;
20-
bool hasEnabledState = false;
21-
bool isEnabled = false;
2235
bool isInMutuallyExclusiveGroup = false;
2336
bool isHeader = false;
2437
bool isObscured = false;
@@ -27,21 +40,12 @@ struct SemanticsFlags {
2740
bool isHidden = false;
2841
bool isImage = false;
2942
bool isLiveRegion = false;
30-
bool hasToggledState = false;
31-
bool isToggled = false;
3243
bool hasImplicitScrolling = false;
3344
bool isMultiline = false;
3445
bool isReadOnly = false;
35-
bool isFocusable = false;
3646
bool isLink = false;
3747
bool isSlider = false;
3848
bool isKeyboardKey = false;
39-
bool isCheckStateMixed = false;
40-
bool hasExpandedState = false;
41-
bool isExpanded = false;
42-
bool hasSelectedState = false;
43-
bool hasRequiredState = false;
44-
bool isRequired = false;
4549
};
4650

4751
//------------------------------------------------------------------------------
@@ -57,14 +61,15 @@ class NativeSemanticsFlags
5761
//----------------------------------------------------------------------------
5862
/// The init method
5963
static void initSemanticsFlags(Dart_Handle semantics_flags_handle,
60-
bool hasCheckedState,
61-
bool isChecked,
62-
bool isSelected,
64+
int isChecked,
65+
int isSelected,
66+
int isEnabled,
67+
int isToggled,
68+
int isExpanded,
69+
int isRequired,
70+
int isFocused,
6371
bool isButton,
6472
bool isTextField,
65-
bool isFocused,
66-
bool hasEnabledState,
67-
bool isEnabled,
6873
bool isInMutuallyExclusiveGroup,
6974
bool isHeader,
7075
bool isObscured,
@@ -73,21 +78,13 @@ class NativeSemanticsFlags
7378
bool isHidden,
7479
bool isImage,
7580
bool isLiveRegion,
76-
bool hasToggledState,
77-
bool isToggled,
7881
bool hasImplicitScrolling,
7982
bool isMultiline,
8083
bool isReadOnly,
8184
bool isFocusable,
8285
bool isLink,
8386
bool isSlider,
84-
bool isKeyboardKey,
85-
bool isCheckStateMixed,
86-
bool hasExpandedState,
87-
bool isExpanded,
88-
bool hasSelectedState,
89-
bool hasRequiredState,
90-
bool isRequired);
87+
bool isKeyboardKey);
9188

9289
//----------------------------------------------------------------------------
9390
/// Returns the c++ representataion of SemanticsFlags.

0 commit comments

Comments
 (0)