Flutter Engine
The 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
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 FML_CHECK(scrollChildren == 0 ||
71 (scrollChildren > 0 && childrenInHitTestOrder.data()))
72 << "Semantics update contained scrollChildren but did not have "
73 "childrenInHitTestOrder";
74 SemanticsNode node;
75 node.id = id;
76 node.flags = flags;
77 node.actions = actions;
78 node.maxValueLength = maxValueLength;
79 node.currentValueLength = currentValueLength;
80 node.textSelectionBase = textSelectionBase;
81 node.textSelectionExtent = textSelectionExtent;
82 node.platformViewId = platformViewId;
83 node.scrollChildren = scrollChildren;
84 node.scrollIndex = scrollIndex;
85 node.scrollPosition = scrollPosition;
86 node.scrollExtentMax = scrollExtentMax;
87 node.scrollExtentMin = scrollExtentMin;
89 SafeNarrow(right), SafeNarrow(bottom));
90 node.elevation = elevation;
91 node.thickness = thickness;
92 node.identifier = std::move(identifier);
93 node.label = std::move(label);
94 pushStringAttributes(node.labelAttributes, labelAttributes);
95 node.value = std::move(value);
96 pushStringAttributes(node.valueAttributes, valueAttributes);
97 node.increasedValue = std::move(increasedValue);
98 pushStringAttributes(node.increasedValueAttributes, increasedValueAttributes);
99 node.decreasedValue = std::move(decreasedValue);
100 pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes);
101 node.hint = std::move(hint);
102 pushStringAttributes(node.hintAttributes, hintAttributes);
103 node.tooltip = std::move(tooltip);
104 node.textDirection = textDirection;
105 SkScalar scalarTransform[16];
106 for (int i = 0; i < 16; ++i) {
107 scalarTransform[i] = SafeNarrow(transform.data()[i]);
108 }
109 node.transform = SkM44::ColMajor(scalarTransform);
111 std::vector<int32_t>(childrenInTraversalOrder.data(),
112 childrenInTraversalOrder.data() +
113 childrenInTraversalOrder.num_elements());
114 node.childrenInHitTestOrder = std::vector<int32_t>(
115 childrenInHitTestOrder.data(),
116 childrenInHitTestOrder.data() + childrenInHitTestOrder.num_elements());
117 node.customAccessibilityActions = std::vector<int32_t>(
118 localContextActions.data(),
119 localContextActions.data() + localContextActions.num_elements());
120 nodes_[id] = node;
121}
122
124 std::string label,
125 std::string hint,
126 int overrideId) {
128 action.id = id;
129 action.overrideId = overrideId;
130 action.label = std::move(label);
131 action.hint = std::move(hint);
132 actions_[id] = action;
133}
134
135void SemanticsUpdateBuilder::build(Dart_Handle semantics_update_handle) {
136 SemanticsUpdate::create(semantics_update_handle, std::move(nodes_),
137 std::move(actions_));
139}
140
141} // namespace flutter
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
static SkM44 ColMajor(const SkScalar c[16])
Definition SkM44.h:218
void build(Dart_Handle semantics_update_handle)
void updateCustomAction(int id, std::string label, std::string hint, int overrideId)
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)
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
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
float SkScalar
Definition extension.cpp:12
FlutterSemanticsFlag flags
uint8_t value
#define FML_CHECK(condition)
Definition logging.h:85
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