Flutter Engine
semantics_node.h
Go to the documentation of this file.
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 <cstdint>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12 
13 #include "third_party/skia/include/core/SkM44.h"
14 #include "third_party/skia/include/core/SkRect.h"
15 
16 namespace flutter {
17 
18 // Must match the SemanticsAction enum in semantics.dart and in each of the
19 // embedders.
20 enum class SemanticsAction : int32_t {
21  kTap = 1 << 0,
22  kLongPress = 1 << 1,
23  kScrollLeft = 1 << 2,
24  kScrollRight = 1 << 3,
25  kScrollUp = 1 << 4,
26  kScrollDown = 1 << 5,
27  kIncrease = 1 << 6,
28  kDecrease = 1 << 7,
29  kShowOnScreen = 1 << 8,
32  kSetSelection = 1 << 11,
33  kCopy = 1 << 12,
34  kCut = 1 << 13,
35  kPaste = 1 << 14,
38  kCustomAction = 1 << 17,
39  kDismiss = 1 << 18,
42 };
43 
45  static_cast<int32_t>(SemanticsAction::kScrollLeft) |
46  static_cast<int32_t>(SemanticsAction::kScrollRight) |
47  static_cast<int32_t>(SemanticsAction::kScrollUp) |
48  static_cast<int32_t>(SemanticsAction::kScrollDown);
49 
50 /// C/C++ representation of `SemanticsFlags` defined in
51 /// `lib/ui/semantics.dart`.
52 ///\warning This must match the `SemanticsFlags` enum in
53 /// `lib/ui/semantics.dart`.
54 /// See also:
55 /// - file://./../../../lib/ui/semantics.dart
56 enum class SemanticsFlags : int32_t {
57  kHasCheckedState = 1 << 0,
58  kIsChecked = 1 << 1,
59  kIsSelected = 1 << 2,
60  kIsButton = 1 << 3,
61  kIsTextField = 1 << 4,
62  kIsFocused = 1 << 5,
63  kHasEnabledState = 1 << 6,
64  kIsEnabled = 1 << 7,
66  kIsHeader = 1 << 9,
67  kIsObscured = 1 << 10,
68  kScopesRoute = 1 << 11,
69  kNamesRoute = 1 << 12,
70  kIsHidden = 1 << 13,
71  kIsImage = 1 << 14,
72  kIsLiveRegion = 1 << 15,
73  kHasToggledState = 1 << 16,
74  kIsToggled = 1 << 17,
75  kHasImplicitScrolling = 1 << 18,
76  // The Dart API defines the following flag but it isn't used in iOS.
77  // kIsMultiline = 1 << 19,
78  kIsReadOnly = 1 << 20,
79  kIsFocusable = 1 << 21,
80  kIsLink = 1 << 22,
81  kIsSlider = 1 << 23,
82 };
83 
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(); // Local space, relative to parent.
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_
std::vector< int32_t > childrenInHitTestOrder
std::vector< int32_t > customAccessibilityActions
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
const int kScrollableSemanticsFlags
std::vector< int32_t > childrenInTraversalOrder
const int kScrollableSemanticsActions
SemanticsAction action
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66