Flutter Engine
The 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 <utility>
8
9#include "flutter/lib/ui/floating_point.h"
10#include "flutter/lib/ui/ui_dart_state.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 int 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 double scrollPosition,
45 double scrollExtentMax,
46 double scrollExtentMin,
47 double left,
48 double top,
49 double right,
50 double bottom,
51 double elevation,
52 double thickness,
53 std::string identifier,
54 std::string label,
55 const std::vector<NativeStringAttribute*>& labelAttributes,
56 std::string value,
57 const std::vector<NativeStringAttribute*>& valueAttributes,
58 std::string increasedValue,
59 const std::vector<NativeStringAttribute*>& increasedValueAttributes,
60 std::string decreasedValue,
61 const std::vector<NativeStringAttribute*>& decreasedValueAttributes,
62 std::string hint,
63 const std::vector<NativeStringAttribute*>& hintAttributes,
64 std::string tooltip,
65 int textDirection,
66 const tonic::Float64List& transform,
67 const tonic::Int32List& childrenInTraversalOrder,
68 const tonic::Int32List& childrenInHitTestOrder,
69 const tonic::Int32List& localContextActions,
70 int headingLevel) {
71 FML_CHECK(scrollChildren == 0 ||
72 (scrollChildren > 0 && childrenInHitTestOrder.data()))
73 << "Semantics update contained scrollChildren but did not have "
74 "childrenInHitTestOrder";
75 SemanticsNode node;
76 node.id = id;
77 node.flags = flags;
78 node.actions = actions;
79 node.maxValueLength = maxValueLength;
80 node.currentValueLength = currentValueLength;
81 node.textSelectionBase = textSelectionBase;
82 node.textSelectionExtent = textSelectionExtent;
83 node.platformViewId = platformViewId;
84 node.scrollChildren = scrollChildren;
85 node.scrollIndex = scrollIndex;
86 node.scrollPosition = scrollPosition;
87 node.scrollExtentMax = scrollExtentMax;
88 node.scrollExtentMin = scrollExtentMin;
89 node.rect = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
90 SafeNarrow(right), SafeNarrow(bottom));
91 node.elevation = elevation;
92 node.thickness = thickness;
93 node.identifier = std::move(identifier);
94 node.label = std::move(label);
95 pushStringAttributes(node.labelAttributes, labelAttributes);
96 node.value = std::move(value);
97 pushStringAttributes(node.valueAttributes, valueAttributes);
98 node.increasedValue = std::move(increasedValue);
99 pushStringAttributes(node.increasedValueAttributes, increasedValueAttributes);
100 node.decreasedValue = std::move(decreasedValue);
101 pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes);
102 node.hint = std::move(hint);
103 pushStringAttributes(node.hintAttributes, hintAttributes);
104 node.tooltip = std::move(tooltip);
105 node.textDirection = textDirection;
106 SkScalar scalarTransform[16];
107 for (int i = 0; i < 16; ++i) {
108 scalarTransform[i] = SafeNarrow(transform.data()[i]);
109 }
110 node.transform = SkM44::ColMajor(scalarTransform);
112 std::vector<int32_t>(childrenInTraversalOrder.data(),
113 childrenInTraversalOrder.data() +
114 childrenInTraversalOrder.num_elements());
115 node.childrenInHitTestOrder = std::vector<int32_t>(
116 childrenInHitTestOrder.data(),
117 childrenInHitTestOrder.data() + childrenInHitTestOrder.num_elements());
118 node.customAccessibilityActions = std::vector<int32_t>(
119 localContextActions.data(),
120 localContextActions.data() + localContextActions.num_elements());
121 nodes_[id] = node;
122
123 node.headingLevel = headingLevel;
124}
125
127 std::string label,
128 std::string hint,
129 int overrideId) {
131 action.id = id;
132 action.overrideId = overrideId;
133 action.label = std::move(label);
134 action.hint = std::move(hint);
135 actions_[id] = action;
136}
137
138void SemanticsUpdateBuilder::build(Dart_Handle semantics_update_handle) {
139 SemanticsUpdate::create(semantics_update_handle, std::move(nodes_),
140 std::move(actions_));
142}
143
144} // namespace flutter
static SkM44 ColMajor(const SkScalar c[16])
Definition: SkM44.h:218
void build(Dart_Handle semantics_update_handle)
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 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::Int32List &childrenInTraversalOrder, const tonic::Int32List &childrenInHitTestOrder, const tonic::Int32List &customAccessibilityActions, int headingLevel)
void updateCustomAction(int id, std::string label, std::string hint, int overrideId)
static void create(Dart_Handle semantics_update_handle, SemanticsNodeUpdates nodes, CustomAccessibilityActionUpdates actions)
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
uint8_t value
#define FML_CHECK(condition)
Definition: logging.h:85
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
void pushStringAttributes(StringAttributes &destination, const std::vector< NativeStringAttribute * > &native_attributes)
static float SafeNarrow(double value)
std::vector< StringAttributePtr > StringAttributes
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
StringAttributes decreasedValueAttributes
StringAttributes hintAttributes
StringAttributes increasedValueAttributes
StringAttributes valueAttributes
StringAttributes labelAttributes
std::vector< int32_t > childrenInHitTestOrder
std::vector< int32_t > customAccessibilityActions
std::vector< int32_t > childrenInTraversalOrder
const uintptr_t id