Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7#include <utility>
8
11#include "third_party/skia/include/core/SkScalar.h"
16
17namespace flutter {
18
20 StringAttributes& destination,
21 const std::vector<NativeStringAttribute*>& native_attributes) {
22 for (const auto& native_attribute : native_attributes) {
23 destination.push_back(native_attribute->GetAttribute());
24 }
25}
26
28
29SemanticsUpdateBuilder::SemanticsUpdateBuilder() = default;
30
32
34 int id,
35 Dart_Handle flags,
36 int actions,
37 int maxValueLength,
38 int currentValueLength,
39 int textSelectionBase,
40 int textSelectionExtent,
41 int platformViewId,
42 int scrollChildren,
43 int scrollIndex,
44 int traversalParent,
45 double scrollPosition,
46 double scrollExtentMax,
47 double scrollExtentMin,
48 double left,
49 double top,
50 double right,
51 double bottom,
52 std::string identifier,
53 std::string label,
54 const std::vector<NativeStringAttribute*>& labelAttributes,
55 std::string value,
56 const std::vector<NativeStringAttribute*>& valueAttributes,
57 std::string increasedValue,
58 const std::vector<NativeStringAttribute*>& increasedValueAttributes,
59 std::string decreasedValue,
60 const std::vector<NativeStringAttribute*>& decreasedValueAttributes,
61 std::string hint,
62 const std::vector<NativeStringAttribute*>& hintAttributes,
63 std::string tooltip,
64 int textDirection,
65 const tonic::Float64List& transform,
66 const tonic::Float64List& hitTestTransform,
67 const tonic::Int32List& childrenInTraversalOrder,
68 const tonic::Int32List& childrenInHitTestOrder,
69 const tonic::Int32List& localContextActions,
70 int headingLevel,
71 std::string linkUrl,
72 int role,
73 const std::vector<std::string>& controlsNodes,
74 int validationResult,
75 int hitTestBehavior,
76 int inputType,
77 std::string locale) {
78 FML_CHECK(scrollChildren == 0 ||
79 (scrollChildren > 0 && childrenInHitTestOrder.data()))
80 << "Semantics update contained scrollChildren but did not have "
81 "childrenInHitTestOrder";
82 SemanticsNode node;
83 node.id = id;
84 auto* flags_object =
86 node.flags = flags_object->GetFlags();
87 node.actions = actions;
88 node.maxValueLength = maxValueLength;
89 node.currentValueLength = currentValueLength;
90 node.textSelectionBase = textSelectionBase;
91 node.textSelectionExtent = textSelectionExtent;
92 node.platformViewId = platformViewId;
93 node.scrollChildren = scrollChildren;
94 node.scrollIndex = scrollIndex;
95 node.traversalParent = traversalParent;
96 node.scrollPosition = scrollPosition;
97 node.scrollExtentMax = scrollExtentMax;
98 node.scrollExtentMin = scrollExtentMin;
99 node.rect = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
100 SafeNarrow(right), SafeNarrow(bottom));
101 node.identifier = std::move(identifier);
102 node.label = std::move(label);
103 pushStringAttributes(node.labelAttributes, labelAttributes);
104 node.value = std::move(value);
105 pushStringAttributes(node.valueAttributes, valueAttributes);
106 node.increasedValue = std::move(increasedValue);
107 pushStringAttributes(node.increasedValueAttributes, increasedValueAttributes);
108 node.decreasedValue = std::move(decreasedValue);
109 pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes);
110 node.hint = std::move(hint);
111 pushStringAttributes(node.hintAttributes, hintAttributes);
112 node.tooltip = std::move(tooltip);
113 node.textDirection = textDirection;
114 SkScalar scalarTransform[16];
115 for (int i = 0; i < 16; ++i) {
116 scalarTransform[i] = SafeNarrow(transform.data()[i]);
117 }
118 node.transform = SkM44::ColMajor(scalarTransform);
119 SkScalar scalarHitTestTransform[16];
120 for (int i = 0; i < 16; ++i) {
121 scalarHitTestTransform[i] = SafeNarrow(hitTestTransform.data()[i]);
122 }
123 node.hitTestTransform = SkM44::ColMajor(scalarHitTestTransform);
125 std::vector<int32_t>(childrenInTraversalOrder.data(),
126 childrenInTraversalOrder.data() +
127 childrenInTraversalOrder.num_elements());
128 node.childrenInHitTestOrder = std::vector<int32_t>(
129 childrenInHitTestOrder.data(),
130 childrenInHitTestOrder.data() + childrenInHitTestOrder.num_elements());
131 node.customAccessibilityActions = std::vector<int32_t>(
132 localContextActions.data(),
133 localContextActions.data() + localContextActions.num_elements());
134 node.headingLevel = headingLevel;
135 node.linkUrl = std::move(linkUrl);
136 node.role = static_cast<SemanticsRole>(role);
137 node.validationResult =
138 static_cast<SemanticsValidationResult>(validationResult);
139 node.locale = std::move(locale);
140
141 nodes_[id] = node;
142}
143
145 std::string label,
146 std::string hint,
147 int overrideId) {
149 action.id = id;
150 action.overrideId = overrideId;
151 action.label = std::move(label);
152 action.hint = std::move(hint);
153 actions_[id] = action;
154}
155
156void SemanticsUpdateBuilder::build(Dart_Handle semantics_update_handle) {
157 SemanticsUpdate::create(semantics_update_handle, std::move(nodes_),
158 std::move(actions_));
160}
161
162} // namespace flutter
void build(Dart_Handle semantics_update_handle)
void updateCustomAction(int id, std::string label, std::string hint, int overrideId)
void updateNode(int id, Dart_Handle flags, int actions, int maxValueLength, int currentValueLength, int textSelectionBase, int textSelectionExtent, int platformViewId, int scrollChildren, int scrollIndex, int traversalParent, double scrollPosition, double scrollExtentMax, double scrollExtentMin, double left, double top, double right, double bottom, std::string identifier, std::string label, const std::vector< NativeStringAttribute * > &labelAttributes, std::string value, const std::vector< NativeStringAttribute * > &valueAttributes, std::string increasedValue, const std::vector< NativeStringAttribute * > &increasedValueAttributes, std::string decreasedValue, const std::vector< NativeStringAttribute * > &decreasedValueAttributes, std::string hint, const std::vector< NativeStringAttribute * > &hintAttributes, std::string tooltip, int textDirection, const tonic::Float64List &transform, const tonic::Float64List &hitTestTransform, const tonic::Int32List &childrenInTraversalOrder, const tonic::Int32List &childrenInHitTestOrder, const tonic::Int32List &customAccessibilityActions, int headingLevel, std::string linkUrl, int role, const std::vector< std::string > &controlsNodes, int validationResult, int hitTestBehavior, int inputType, std::string locale)
static void create(Dart_Handle semantics_update_handle, SemanticsNodeUpdates nodes, CustomAccessibilityActionUpdates actions)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
int32_t value
#define FML_CHECK(condition)
Definition logging.h:104
void pushStringAttributes(StringAttributes &destination, const std::vector< NativeStringAttribute * > &native_attributes)
SemanticsValidationResult
static float SafeNarrow(double value)
std::vector< StringAttributePtr > StringAttributes
StringAttributes decreasedValueAttributes
StringAttributes hintAttributes
StringAttributes increasedValueAttributes
StringAttributes valueAttributes
StringAttributes labelAttributes
std::vector< int32_t > childrenInHitTestOrder
SemanticsValidationResult validationResult
std::vector< int32_t > customAccessibilityActions
std::vector< int32_t > childrenInTraversalOrder
const uintptr_t id