Flutter Engine
semantics_update_builder.cc
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 #include "flutter/lib/ui/semantics/semantics_update_builder.h"
6 
7 #include "flutter/lib/ui/ui_dart_state.h"
8 #include "third_party/skia/include/core/SkScalar.h"
13 
14 namespace flutter {
15 
17  StringAttributes& destination,
18  const std::vector<NativeStringAttribute*>& native_attributes) {
19  for (const auto& native_attribute : native_attributes) {
20  destination.push_back(native_attribute->GetAttribute());
21  }
22 }
23 
24 static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args) {
27 }
28 
30 
31 #define FOR_EACH_BINDING(V) \
32  V(SemanticsUpdateBuilder, updateNode) \
33  V(SemanticsUpdateBuilder, updateCustomAction) \
34  V(SemanticsUpdateBuilder, build)
35 
37 
38 void SemanticsUpdateBuilder::RegisterNatives(
39  tonic::DartLibraryNatives* natives) {
40  natives->Register({{"SemanticsUpdateBuilder_constructor",
43 }
44 
45 SemanticsUpdateBuilder::SemanticsUpdateBuilder() = default;
46 
48 
50  int id,
51  int flags,
52  int actions,
53  int maxValueLength,
54  int currentValueLength,
55  int textSelectionBase,
56  int textSelectionExtent,
57  int platformViewId,
58  int scrollChildren,
59  int scrollIndex,
60  double scrollPosition,
61  double scrollExtentMax,
62  double scrollExtentMin,
63  double left,
64  double top,
65  double right,
66  double bottom,
67  double elevation,
68  double thickness,
69  std::string label,
70  std::vector<NativeStringAttribute*> labelAttributes,
71  std::string value,
72  std::vector<NativeStringAttribute*> valueAttributes,
73  std::string increasedValue,
74  std::vector<NativeStringAttribute*> increasedValueAttributes,
75  std::string decreasedValue,
76  std::vector<NativeStringAttribute*> decreasedValueAttributes,
77  std::string hint,
78  std::vector<NativeStringAttribute*> hintAttributes,
79  std::string tooltip,
80  int textDirection,
81  const tonic::Float64List& transform,
82  const tonic::Int32List& childrenInTraversalOrder,
83  const tonic::Int32List& childrenInHitTestOrder,
84  const tonic::Int32List& localContextActions) {
85  FML_CHECK(transform.data() && SkScalarsAreFinite(*transform.data(), 9))
86  << "Semantics update transform was not set or not finite.";
87  FML_CHECK(scrollChildren == 0 ||
88  (scrollChildren > 0 && childrenInHitTestOrder.data()))
89  << "Semantics update contained scrollChildren but did not have "
90  "childrenInHitTestOrder";
92  node.id = id;
93  node.flags = flags;
94  node.actions = actions;
95  node.maxValueLength = maxValueLength;
96  node.currentValueLength = currentValueLength;
97  node.textSelectionBase = textSelectionBase;
98  node.textSelectionExtent = textSelectionExtent;
99  node.platformViewId = platformViewId;
100  node.scrollChildren = scrollChildren;
101  node.scrollIndex = scrollIndex;
102  node.scrollPosition = scrollPosition;
103  node.scrollExtentMax = scrollExtentMax;
104  node.scrollExtentMin = scrollExtentMin;
105  node.rect = SkRect::MakeLTRB(left, top, right, bottom);
106  node.elevation = elevation;
107  node.thickness = thickness;
108  node.label = label;
109  pushStringAttributes(node.labelAttributes, labelAttributes);
110  node.value = value;
111  pushStringAttributes(node.valueAttributes, valueAttributes);
112  node.increasedValue = increasedValue;
113  pushStringAttributes(node.increasedValueAttributes, increasedValueAttributes);
114  node.decreasedValue = decreasedValue;
115  pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes);
116  node.hint = hint;
117  pushStringAttributes(node.hintAttributes, hintAttributes);
118  node.tooltip = tooltip;
119  node.textDirection = textDirection;
120  SkScalar scalarTransform[16];
121  for (int i = 0; i < 16; ++i) {
122  scalarTransform[i] = transform.data()[i];
123  }
124  node.transform = SkM44::ColMajor(scalarTransform);
126  std::vector<int32_t>(childrenInTraversalOrder.data(),
127  childrenInTraversalOrder.data() +
128  childrenInTraversalOrder.num_elements());
129  node.childrenInHitTestOrder = std::vector<int32_t>(
130  childrenInHitTestOrder.data(),
131  childrenInHitTestOrder.data() + childrenInHitTestOrder.num_elements());
132  node.customAccessibilityActions = std::vector<int32_t>(
133  localContextActions.data(),
134  localContextActions.data() + localContextActions.num_elements());
135  nodes_[id] = node;
136 }
137 
139  std::string label,
140  std::string hint,
141  int overrideId) {
143  action.id = id;
144  action.overrideId = overrideId;
145  action.label = label;
146  action.hint = hint;
147  actions_[id] = action;
148 }
149 
150 void SemanticsUpdateBuilder::build(Dart_Handle semantics_update_handle) {
151  SemanticsUpdate::create(semantics_update_handle, std::move(nodes_),
152  std::move(actions_));
153 }
154 
155 } // namespace flutter
G_BEGIN_DECLS FlValue * args
StringAttributes increasedValueAttributes
std::vector< int32_t > childrenInHitTestOrder
StringAttributes decreasedValueAttributes
void DartCallConstructor(Sig func, Dart_NativeArguments args)
Definition: dart_args.h:218
void updateNode(int id, int flags, int actions, int maxValueLength, int currentValueLength, int textSelectionBase, int textSelectionExtent, int platformViewId, int scrollChildren, int scrollIndex, double scrollPosition, double scrollExtentMax, double scrollExtentMin, double left, double top, double right, double bottom, double elevation, double thickness, std::string label, std::vector< NativeStringAttribute *> labelAttributes, std::string value, std::vector< NativeStringAttribute *> valueAttributes, std::string increasedValue, std::vector< NativeStringAttribute *> increasedValueAttributes, std::string decreasedValue, std::vector< NativeStringAttribute *> decreasedValueAttributes, std::string hint, std::vector< NativeStringAttribute *> hintAttributes, std::string tooltip, int textDirection, const tonic::Float64List &transform, const tonic::Int32List &childrenInTraversalOrder, const tonic::Int32List &childrenInHitTestOrder, const tonic::Int32List &customAccessibilityActions)
std::vector< int32_t > customAccessibilityActions
void build(Dart_Handle semantics_update_handle)
void updateCustomAction(int id, std::string label, std::string hint, int overrideId)
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
std::vector< int32_t > childrenInTraversalOrder
std::vector< StringAttributePtr > StringAttributes
static void create(Dart_Handle semantics_update_handle, SemanticsNodeUpdates nodes, CustomAccessibilityActionUpdates actions)
uint8_t value
StringAttributes valueAttributes
const FlutterSemanticsNode * node
Definition: fl_view.cc:83
IMPLEMENT_WRAPPERTYPEINFO(ui, Scene)
SemanticsAction action
static void ThrowIfUIOperationsProhibited()
StringAttributes hintAttributes
#define FML_CHECK(condition)
Definition: logging.h:68
void pushStringAttributes(StringAttributes &destination, const std::vector< NativeStringAttribute *> &native_attributes)
static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args)
StringAttributes labelAttributes
#define FOR_EACH_BINDING(V)
int32_t id
#define DART_REGISTER_NATIVE(CLASS, METHOD)
static fml::RefPtr< SemanticsUpdateBuilder > create()
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