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 "third_party/skia/include/core/SkScalar.h"
8
9 namespace flutter {
10
SemanticsUpdateBuilder_constructor(Dart_NativeArguments args)11 static void SemanticsUpdateBuilder_constructor(Dart_NativeArguments args) {
12 DartCallConstructor(&SemanticsUpdateBuilder::create, args);
13 }
14
15 IMPLEMENT_WRAPPERTYPEINFO(ui, SemanticsUpdateBuilder);
16
17 #define FOR_EACH_BINDING(V) \
18 V(SemanticsUpdateBuilder, updateNode) \
19 V(SemanticsUpdateBuilder, updateCustomAction) \
20 V(SemanticsUpdateBuilder, build)
21
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)22 FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
23
24 void SemanticsUpdateBuilder::RegisterNatives(
25 tonic::DartLibraryNatives* natives) {
26 natives->Register({{"SemanticsUpdateBuilder_constructor",
27 SemanticsUpdateBuilder_constructor, 1, true},
28 FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
29 }
30
31 SemanticsUpdateBuilder::SemanticsUpdateBuilder() = default;
32
33 SemanticsUpdateBuilder::~SemanticsUpdateBuilder() = default;
34
updateNode(int id,int flags,int actions,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::string hint,std::string value,std::string increasedValue,std::string decreasedValue,int textDirection,const tonic::Float64List & transform,const tonic::Int32List & childrenInTraversalOrder,const tonic::Int32List & childrenInHitTestOrder,const tonic::Int32List & localContextActions)35 void SemanticsUpdateBuilder::updateNode(
36 int id,
37 int flags,
38 int actions,
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 label,
54 std::string hint,
55 std::string value,
56 std::string increasedValue,
57 std::string decreasedValue,
58 int textDirection,
59 const tonic::Float64List& transform,
60 const tonic::Int32List& childrenInTraversalOrder,
61 const tonic::Int32List& childrenInHitTestOrder,
62 const tonic::Int32List& localContextActions) {
63 FML_CHECK(transform.data() && SkScalarsAreFinite(*transform.data(), 9))
64 << "Semantics update transform was not set or not finite.";
65 FML_CHECK(scrollChildren == 0 ||
66 (scrollChildren > 0 && childrenInHitTestOrder.data()))
67 << "Semantics update contained scrollChildren but did not have "
68 "childrenInHitTestOrder";
69 SemanticsNode node;
70 node.id = id;
71 node.flags = flags;
72 node.actions = actions;
73 node.textSelectionBase = textSelectionBase;
74 node.textSelectionExtent = textSelectionExtent;
75 node.platformViewId = platformViewId;
76 node.scrollChildren = scrollChildren;
77 node.scrollIndex = scrollIndex;
78 node.scrollPosition = scrollPosition;
79 node.scrollExtentMax = scrollExtentMax;
80 node.scrollExtentMin = scrollExtentMin;
81 node.rect = SkRect::MakeLTRB(left, top, right, bottom);
82 node.elevation = elevation;
83 node.thickness = thickness;
84 node.label = label;
85 node.hint = hint;
86 node.value = value;
87 node.increasedValue = increasedValue;
88 node.decreasedValue = decreasedValue;
89 node.textDirection = textDirection;
90 node.transform.setColMajord(transform.data());
91 node.childrenInTraversalOrder =
92 std::vector<int32_t>(childrenInTraversalOrder.data(),
93 childrenInTraversalOrder.data() +
94 childrenInTraversalOrder.num_elements());
95 node.childrenInHitTestOrder = std::vector<int32_t>(
96 childrenInHitTestOrder.data(),
97 childrenInHitTestOrder.data() + childrenInHitTestOrder.num_elements());
98 node.customAccessibilityActions = std::vector<int32_t>(
99 localContextActions.data(),
100 localContextActions.data() + localContextActions.num_elements());
101 nodes_[id] = node;
102 }
103
updateCustomAction(int id,std::string label,std::string hint,int overrideId)104 void SemanticsUpdateBuilder::updateCustomAction(int id,
105 std::string label,
106 std::string hint,
107 int overrideId) {
108 CustomAccessibilityAction action;
109 action.id = id;
110 action.overrideId = overrideId;
111 action.label = label;
112 action.hint = hint;
113 actions_[id] = action;
114 }
115
build()116 fml::RefPtr<SemanticsUpdate> SemanticsUpdateBuilder::build() {
117 return SemanticsUpdate::create(std::move(nodes_), std::move(actions_));
118 }
119
120 } // namespace flutter
121