• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkMatrix44.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 // Must match the SemanticsFlags enum in semantics.dart.
52 enum class SemanticsFlags : int32_t {
53   kHasCheckedState = 1 << 0,
54   kIsChecked = 1 << 1,
55   kIsSelected = 1 << 2,
56   kIsButton = 1 << 3,
57   kIsTextField = 1 << 4,
58   kIsFocused = 1 << 5,
59   kHasEnabledState = 1 << 6,
60   kIsEnabled = 1 << 7,
61   kIsInMutuallyExclusiveGroup = 1 << 8,
62   kIsHeader = 1 << 9,
63   kIsObscured = 1 << 10,
64   kScopesRoute = 1 << 11,
65   kNamesRoute = 1 << 12,
66   kIsHidden = 1 << 13,
67   kIsImage = 1 << 14,
68   kIsLiveRegion = 1 << 15,
69   kHasToggledState = 1 << 16,
70   kIsToggled = 1 << 17,
71   kHasImplicitScrolling = 1 << 18,
72   // The Dart API defines the following flag but it isn't used in iOS.
73   // kIsMultiline = 1 << 19,
74   kIsReadOnly = 1 << 20,
75 };
76 
77 const int kScrollableSemanticsFlags =
78     static_cast<int32_t>(SemanticsFlags::kHasImplicitScrolling);
79 
80 struct SemanticsNode {
81   SemanticsNode();
82 
83   SemanticsNode(const SemanticsNode& other);
84 
85   ~SemanticsNode();
86 
87   bool HasAction(SemanticsAction action) const;
88   bool HasFlag(SemanticsFlags flag) const;
89 
90   // Whether this node is for embedded platform views.
91   bool IsPlatformViewNode() const;
92 
93   int32_t id = 0;
94   int32_t flags = 0;
95   int32_t actions = 0;
96   int32_t textSelectionBase = -1;
97   int32_t textSelectionExtent = -1;
98   int32_t platformViewId = -1;
99   int32_t scrollChildren = 0;
100   int32_t scrollIndex = 0;
101   double scrollPosition = std::nan("");
102   double scrollExtentMax = std::nan("");
103   double scrollExtentMin = std::nan("");
104   double elevation = 0.0;
105   double thickness = 0.0;
106   std::string label;
107   std::string hint;
108   std::string value;
109   std::string increasedValue;
110   std::string decreasedValue;
111   int32_t textDirection = 0;  // 0=unknown, 1=rtl, 2=ltr
112 
113   SkRect rect = SkRect::MakeEmpty();
114   SkMatrix44 transform = SkMatrix44(SkMatrix44::kIdentity_Constructor);
115   std::vector<int32_t> childrenInTraversalOrder;
116   std::vector<int32_t> childrenInHitTestOrder;
117   std::vector<int32_t> customAccessibilityActions;
118 };
119 
120 // Contains semantic nodes that need to be updated.
121 //
122 // The keys in the map are stable node IDd, and the values contain
123 // semantic information for the node corresponding to the ID.
124 using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>;
125 
126 }  // namespace flutter
127 
128 #endif  // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
129