1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #ifndef FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_ |
6 | #define FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_ |
7 | |
8 | #include <stdint.h> |
9 | |
10 | #include <string> |
11 | #include <unordered_map> |
12 | #include <vector> |
13 | |
14 | #include "third_party/skia/include/core/SkM44.h" |
15 | #include "third_party/skia/include/core/SkRect.h" |
16 | |
17 | namespace flutter { |
18 | |
19 | // Must match the SemanticsAction enum in semantics.dart and in each of the |
20 | // embedders. |
21 | enum class SemanticsAction : int32_t { |
22 | kTap = 1 << 0, |
23 | kLongPress = 1 << 1, |
24 | kScrollLeft = 1 << 2, |
25 | kScrollRight = 1 << 3, |
26 | kScrollUp = 1 << 4, |
27 | kScrollDown = 1 << 5, |
28 | kIncrease = 1 << 6, |
29 | kDecrease = 1 << 7, |
30 | kShowOnScreen = 1 << 8, |
31 | kMoveCursorForwardByCharacter = 1 << 9, |
32 | kMoveCursorBackwardByCharacter = 1 << 10, |
33 | kSetSelection = 1 << 11, |
34 | kCopy = 1 << 12, |
35 | kCut = 1 << 13, |
36 | kPaste = 1 << 14, |
37 | kDidGainAccessibilityFocus = 1 << 15, |
38 | kDidLoseAccessibilityFocus = 1 << 16, |
39 | kCustomAction = 1 << 17, |
40 | kDismiss = 1 << 18, |
41 | kMoveCursorForwardByWordIndex = 1 << 19, |
42 | kMoveCursorBackwardByWordIndex = 1 << 20, |
43 | }; |
44 | |
45 | const int kScrollableSemanticsActions = |
46 | static_cast<int32_t>(SemanticsAction::kScrollLeft) | |
47 | static_cast<int32_t>(SemanticsAction::kScrollRight) | |
48 | static_cast<int32_t>(SemanticsAction::kScrollUp) | |
49 | static_cast<int32_t>(SemanticsAction::kScrollDown); |
50 | |
51 | /// C/C++ representation of `SemanticsFlags` defined in |
52 | /// `lib/ui/semantics.dart`. |
53 | ///\warning This must match the `SemanticsFlags` enum in |
54 | /// `lib/ui/semantics.dart`. |
55 | /// See also: |
56 | /// - file://./../../../lib/ui/semantics.dart |
57 | enum class SemanticsFlags : int32_t { |
58 | kHasCheckedState = 1 << 0, |
59 | kIsChecked = 1 << 1, |
60 | kIsSelected = 1 << 2, |
61 | kIsButton = 1 << 3, |
62 | kIsTextField = 1 << 4, |
63 | kIsFocused = 1 << 5, |
64 | kHasEnabledState = 1 << 6, |
65 | kIsEnabled = 1 << 7, |
66 | kIsInMutuallyExclusiveGroup = 1 << 8, |
67 | = 1 << 9, |
68 | kIsObscured = 1 << 10, |
69 | kScopesRoute = 1 << 11, |
70 | kNamesRoute = 1 << 12, |
71 | kIsHidden = 1 << 13, |
72 | kIsImage = 1 << 14, |
73 | kIsLiveRegion = 1 << 15, |
74 | kHasToggledState = 1 << 16, |
75 | kIsToggled = 1 << 17, |
76 | kHasImplicitScrolling = 1 << 18, |
77 | // The Dart API defines the following flag but it isn't used in iOS. |
78 | // kIsMultiline = 1 << 19, |
79 | kIsReadOnly = 1 << 20, |
80 | kIsFocusable = 1 << 21, |
81 | kIsLink = 1 << 22, |
82 | }; |
83 | |
84 | const int kScrollableSemanticsFlags = |
85 | static_cast<int32_t>(SemanticsFlags::kHasImplicitScrolling); |
86 | |
87 | struct SemanticsNode { |
88 | SemanticsNode(); |
89 | |
90 | SemanticsNode(const SemanticsNode& other); |
91 | |
92 | ~SemanticsNode(); |
93 | |
94 | bool HasAction(SemanticsAction action) const; |
95 | bool HasFlag(SemanticsFlags flag) const; |
96 | |
97 | // Whether this node is for embedded platform views. |
98 | bool IsPlatformViewNode() const; |
99 | |
100 | int32_t id = 0; |
101 | int32_t flags = 0; |
102 | int32_t actions = 0; |
103 | int32_t maxValueLength = -1; |
104 | int32_t currentValueLength = -1; |
105 | int32_t textSelectionBase = -1; |
106 | int32_t textSelectionExtent = -1; |
107 | int32_t platformViewId = -1; |
108 | int32_t scrollChildren = 0; |
109 | int32_t scrollIndex = 0; |
110 | double scrollPosition = std::nan("" ); |
111 | double scrollExtentMax = std::nan("" ); |
112 | double scrollExtentMin = std::nan("" ); |
113 | double elevation = 0.0; |
114 | double thickness = 0.0; |
115 | std::string label; |
116 | std::string hint; |
117 | std::string value; |
118 | std::string increasedValue; |
119 | std::string decreasedValue; |
120 | int32_t textDirection = 0; // 0=unknown, 1=rtl, 2=ltr |
121 | |
122 | SkRect rect = SkRect::MakeEmpty(); |
123 | SkM44 transform = SkM44{}; // Identity |
124 | std::vector<int32_t> childrenInTraversalOrder; |
125 | std::vector<int32_t> childrenInHitTestOrder; |
126 | std::vector<int32_t> customAccessibilityActions; |
127 | }; |
128 | |
129 | // Contains semantic nodes that need to be updated. |
130 | // |
131 | // The keys in the map are stable node IDd, and the values contain |
132 | // semantic information for the node corresponding to the ID. |
133 | using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>; |
134 | |
135 | } // namespace flutter |
136 | |
137 | #endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_ |
138 | |