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 #include "flutter/lib/ui/semantics/string_attribute.h"
17 
18 namespace flutter {
19 
20 // Must match the SemanticsAction enum in semantics.dart and in each of the
21 // embedders.
22 enum class SemanticsAction : int32_t {
23  kTap = 1 << 0,
24  kLongPress = 1 << 1,
25  kScrollLeft = 1 << 2,
26  kScrollRight = 1 << 3,
27  kScrollUp = 1 << 4,
28  kScrollDown = 1 << 5,
29  kIncrease = 1 << 6,
30  kDecrease = 1 << 7,
31  kShowOnScreen = 1 << 8,
34  kSetSelection = 1 << 11,
35  kCopy = 1 << 12,
36  kCut = 1 << 13,
37  kPaste = 1 << 14,
40  kCustomAction = 1 << 17,
41  kDismiss = 1 << 18,
44  kSetText = 1 << 21,
45 };
46 
48  static_cast<int32_t>(SemanticsAction::kScrollUp) |
49  static_cast<int32_t>(SemanticsAction::kScrollDown);
50 
52  static_cast<int32_t>(SemanticsAction::kScrollLeft) |
53  static_cast<int32_t>(SemanticsAction::kScrollRight);
54 
56  kVerticalScrollSemanticsActions | kHorizontalScrollSemanticsActions;
57 
58 /// C/C++ representation of `SemanticsFlags` defined in
59 /// `lib/ui/semantics.dart`.
60 ///\warning This must match the `SemanticsFlags` enum in
61 /// `lib/ui/semantics.dart`.
62 /// See also:
63 /// - file://./../../../lib/ui/semantics.dart
64 enum class SemanticsFlags : int32_t {
65  kHasCheckedState = 1 << 0,
66  kIsChecked = 1 << 1,
67  kIsSelected = 1 << 2,
68  kIsButton = 1 << 3,
69  kIsTextField = 1 << 4,
70  kIsFocused = 1 << 5,
71  kHasEnabledState = 1 << 6,
72  kIsEnabled = 1 << 7,
74  kIsHeader = 1 << 9,
75  kIsObscured = 1 << 10,
76  kScopesRoute = 1 << 11,
77  kNamesRoute = 1 << 12,
78  kIsHidden = 1 << 13,
79  kIsImage = 1 << 14,
80  kIsLiveRegion = 1 << 15,
81  kHasToggledState = 1 << 16,
82  kIsToggled = 1 << 17,
83  kHasImplicitScrolling = 1 << 18,
84  // The Dart API defines the following flag but it isn't used in iOS.
85  // kIsMultiline = 1 << 19,
86  kIsReadOnly = 1 << 20,
87  kIsFocusable = 1 << 21,
88  kIsLink = 1 << 22,
89  kIsSlider = 1 << 23,
90  kIsKeyboardKey = 1 << 24,
91 };
92 
94  static_cast<int32_t>(SemanticsFlags::kHasImplicitScrolling);
95 
96 struct SemanticsNode {
97  SemanticsNode();
98 
99  SemanticsNode(const SemanticsNode& other);
100 
101  ~SemanticsNode();
102 
103  bool HasAction(SemanticsAction action) const;
104  bool HasFlag(SemanticsFlags flag) const;
105 
106  // Whether this node is for embedded platform views.
107  bool IsPlatformViewNode() const;
108 
109  int32_t id = 0;
110  int32_t flags = 0;
111  int32_t actions = 0;
112  int32_t maxValueLength = -1;
113  int32_t currentValueLength = -1;
114  int32_t textSelectionBase = -1;
115  int32_t textSelectionExtent = -1;
116  int32_t platformViewId = -1;
117  int32_t scrollChildren = 0;
118  int32_t scrollIndex = 0;
119  double scrollPosition = std::nan("");
120  double scrollExtentMax = std::nan("");
121  double scrollExtentMin = std::nan("");
122  double elevation = 0.0;
123  double thickness = 0.0;
124  std::string label;
126  std::string hint;
128  std::string value;
130  std::string increasedValue;
132  std::string decreasedValue;
134  std::string tooltip;
135  int32_t textDirection = 0; // 0=unknown, 1=rtl, 2=ltr
136 
137  SkRect rect = SkRect::MakeEmpty(); // Local space, relative to parent.
138  SkM44 transform = SkM44{}; // Identity
139  std::vector<int32_t> childrenInTraversalOrder;
140  std::vector<int32_t> childrenInHitTestOrder;
141  std::vector<int32_t> customAccessibilityActions;
142 };
143 
144 // Contains semantic nodes that need to be updated.
145 //
146 // The keys in the map are stable node IDd, and the values contain
147 // semantic information for the node corresponding to the ID.
148 using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>;
149 
150 } // namespace flutter
151 
152 #endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
const int kVerticalScrollSemanticsActions
StringAttributes increasedValueAttributes
std::vector< int32_t > childrenInHitTestOrder
StringAttributes decreasedValueAttributes
std::vector< int32_t > customAccessibilityActions
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
const int kScrollableSemanticsFlags
std::vector< int32_t > childrenInTraversalOrder
const int kHorizontalScrollSemanticsActions
std::vector< StringAttributePtr > StringAttributes
const int kScrollableSemanticsActions
StringAttributes valueAttributes
SemanticsAction action
FlutterSemanticsFlag flag
StringAttributes hintAttributes
StringAttributes labelAttributes
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