Flutter Engine
The 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
15
16#include "flutter/lib/ui/semantics/string_attribute.h"
17
18namespace flutter {
19
20// Must match the SemanticsAction enum in semantics.dart and in each of the
21// embedders.
22enum 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 kFocus = 1 << 22,
46};
47
49 static_cast<int32_t>(SemanticsAction::kScrollUp) |
50 static_cast<int32_t>(SemanticsAction::kScrollDown);
51
53 static_cast<int32_t>(SemanticsAction::kScrollLeft) |
54 static_cast<int32_t>(SemanticsAction::kScrollRight);
55
58
59/// C/C++ representation of `SemanticsFlags` defined in
60/// `lib/ui/semantics.dart`.
61///\warning This must match the `SemanticsFlags` enum in
62/// `lib/ui/semantics.dart`.
63/// See also:
64/// - file://./../../../lib/ui/semantics.dart
65enum class SemanticsFlags : int32_t {
66 kHasCheckedState = 1 << 0,
67 kIsChecked = 1 << 1,
68 kIsSelected = 1 << 2,
69 kIsButton = 1 << 3,
70 kIsTextField = 1 << 4,
71 kIsFocused = 1 << 5,
72 kHasEnabledState = 1 << 6,
73 kIsEnabled = 1 << 7,
75 kIsHeader = 1 << 9,
76 kIsObscured = 1 << 10,
77 kScopesRoute = 1 << 11,
78 kNamesRoute = 1 << 12,
79 kIsHidden = 1 << 13,
80 kIsImage = 1 << 14,
81 kIsLiveRegion = 1 << 15,
82 kHasToggledState = 1 << 16,
83 kIsToggled = 1 << 17,
84 kHasImplicitScrolling = 1 << 18,
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 kIsCheckStateMixed = 1 << 25,
92 kHasExpandedState = 1 << 26,
93 kIsExpanded = 1 << 27,
94};
95
97 static_cast<int32_t>(SemanticsFlags::kHasImplicitScrolling);
98
101
103
105
106 bool HasAction(SemanticsAction action) const;
107 bool HasFlag(SemanticsFlags flag) const;
108
109 // Whether this node is for embedded platform views.
110 bool IsPlatformViewNode() const;
111
112 int32_t id = 0;
113 int32_t flags = 0;
114 int32_t actions = 0;
115 int32_t maxValueLength = -1;
116 int32_t currentValueLength = -1;
117 int32_t textSelectionBase = -1;
119 int32_t platformViewId = -1;
120 int32_t scrollChildren = 0;
121 int32_t scrollIndex = 0;
122 double scrollPosition = std::nan("");
123 double scrollExtentMax = std::nan("");
124 double scrollExtentMin = std::nan("");
125 double elevation = 0.0;
126 double thickness = 0.0;
127 std::string identifier;
128 std::string label;
130 std::string hint;
132 std::string value;
134 std::string increasedValue;
136 std::string decreasedValue;
138 std::string tooltip;
139 int32_t textDirection = 0; // 0=unknown, 1=rtl, 2=ltr
140
141 SkRect rect = SkRect::MakeEmpty(); // Local space, relative to parent.
142 SkM44 transform = SkM44{}; // Identity
143 std::vector<int32_t> childrenInTraversalOrder;
144 std::vector<int32_t> childrenInHitTestOrder;
145 std::vector<int32_t> customAccessibilityActions;
146 int32_t headingLevel = 0;
147};
148
149// Contains semantic nodes that need to be updated.
150//
151// The keys in the map are stable node IDd, and the values contain
152// semantic information for the node corresponding to the ID.
153using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>;
154
155} // namespace flutter
156
157#endif // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
Definition: SkM44.h:150
FlutterSemanticsFlag flag
const int kScrollableSemanticsFlags
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
const int kHorizontalScrollSemanticsActions
const int kVerticalScrollSemanticsActions
std::vector< StringAttributePtr > StringAttributes
const int kScrollableSemanticsActions
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
SemanticsNode(const SemanticsNode &other)
StringAttributes decreasedValueAttributes
StringAttributes hintAttributes
StringAttributes increasedValueAttributes
StringAttributes valueAttributes
StringAttributes labelAttributes
std::vector< int32_t > childrenInHitTestOrder
bool HasAction(SemanticsAction action) const
bool HasFlag(SemanticsFlags flag) const
std::vector< int32_t > customAccessibilityActions
bool IsPlatformViewNode() const
std::vector< int32_t > childrenInTraversalOrder