Flutter Engine
The Flutter Engine
pointer_event_utility.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
8
9using fup_EventPhase = fuchsia::ui::pointer::EventPhase;
10using fup_TouchEvent = fuchsia::ui::pointer::TouchEvent;
11using fup_TouchIxnId = fuchsia::ui::pointer::TouchInteractionId;
12using fup_TouchIxnResult = fuchsia::ui::pointer::TouchInteractionResult;
13using fup_TouchPointerSample = fuchsia::ui::pointer::TouchPointerSample;
14using fup_ViewParameters = fuchsia::ui::pointer::ViewParameters;
15using fup_MouseEvent = fuchsia::ui::pointer::MouseEvent;
16using fup_MousePointerSample = fuchsia::ui::pointer::MousePointerSample;
17using fup_MouseDeviceInfo = fuchsia::ui::pointer::MouseDeviceInfo;
18
19namespace {
20
21fup_ViewParameters CreateViewParameters(
22 std::array<std::array<float, 2>, 2> view,
23 std::array<std::array<float, 2>, 2> viewport,
24 std::array<float, 9> transform) {
26 fuchsia::ui::pointer::Rectangle view_rect;
27 view_rect.min = view[0];
28 view_rect.max = view[1];
29 params.view = view_rect;
30 fuchsia::ui::pointer::Rectangle viewport_rect;
31 viewport_rect.min = viewport[0];
32 viewport_rect.max = viewport[1];
33 params.viewport = viewport_rect;
34 params.viewport_to_view_transform = transform;
35 return params;
36}
37
38} // namespace
39
41 return TouchEventBuilder();
42}
43
45 time_ = time;
46 return *this;
47}
48
50 fup_EventPhase phase,
51 std::array<float, 2> position) {
52 sample_ = std::make_optional<fup_TouchPointerSample>();
53 sample_->set_interaction(id);
54 sample_->set_phase(phase);
55 sample_->set_position_in_viewport(position);
56 return *this;
57}
58
60 std::array<std::array<float, 2>, 2> view,
61 std::array<std::array<float, 2>, 2> viewport,
62 std::array<float, 9> transform) {
63 params_ = CreateViewParameters(std::move(view), std::move(viewport),
64 std::move(transform));
65 return *this;
66}
67
69 result_ = result;
70 return *this;
71}
72
75 if (time_) {
76 event.set_timestamp(time_.value());
77 }
78 if (params_) {
79 event.set_view_parameters(std::move(params_.value()));
80 }
81 if (sample_) {
82 event.set_pointer_sample(std::move(sample_.value()));
83 }
84 if (result_) {
85 event.set_interaction_result(std::move(result_.value()));
86 }
87 return event;
88}
89
90std::vector<fup_TouchEvent> TouchEventBuilder::BuildAsVector() {
91 std::vector<fup_TouchEvent> events;
92 events.emplace_back(Build());
93 return events;
94}
95
97 return MouseEventBuilder();
98}
99
101 time_ = time;
102 return *this;
103}
104
106 uint32_t id,
107 std::array<float, 2> position,
108 std::vector<uint8_t> pressed_buttons,
109 std::array<int64_t, 2> scroll,
110 std::array<int64_t, 2> scroll_in_physical_pixel,
111 bool is_precision_scroll) {
112 sample_ = std::make_optional<fup_MousePointerSample>();
113 sample_->set_device_id(id);
114 if (!pressed_buttons.empty()) {
115 sample_->set_pressed_buttons(pressed_buttons);
116 }
117 sample_->set_position_in_viewport(position);
118 if (scroll[0] != 0) {
119 sample_->set_scroll_h(scroll[0]);
120 }
121 if (scroll[1] != 0) {
122 sample_->set_scroll_v(scroll[1]);
123 }
124 if (scroll_in_physical_pixel[0] != 0) {
125 sample_->set_scroll_h_physical_pixel(scroll_in_physical_pixel[0]);
126 }
127 if (scroll_in_physical_pixel[1] != 0) {
128 sample_->set_scroll_v_physical_pixel(scroll_in_physical_pixel[1]);
129 }
130 sample_->set_is_precision_scroll(is_precision_scroll);
131 return *this;
132}
133
135 std::array<std::array<float, 2>, 2> view,
136 std::array<std::array<float, 2>, 2> viewport,
137 std::array<float, 9> transform) {
138 params_ = CreateViewParameters(std::move(view), std::move(viewport),
139 std::move(transform));
140 return *this;
141}
142
144 uint32_t id,
145 std::vector<uint8_t> buttons) {
146 device_info_ = std::make_optional<fup_MouseDeviceInfo>();
147 device_info_->set_id(id);
148 device_info_->set_buttons(buttons);
149 return *this;
150}
151
154 if (time_) {
155 event.set_timestamp(time_.value());
156 }
157 if (params_) {
158 event.set_view_parameters(std::move(params_.value()));
159 }
160 if (sample_) {
161 event.set_pointer_sample(std::move(sample_.value()));
162 }
163 if (device_info_) {
164 event.set_device_info(std::move(device_info_.value()));
165 }
166 event.set_trace_flow_id(123);
167 return event;
168}
169
170std::vector<fup_MouseEvent> MouseEventBuilder::BuildAsVector() {
171 std::vector<fup_MouseEvent> events;
172 events.emplace_back(Build());
173 return events;
174}
175
176} // namespace flutter_runner::testing
fuchsia::ui::pointer::MouseEvent Build()
MouseEventBuilder & AddSample(uint32_t id, std::array< float, 2 > position, std::vector< uint8_t > pressed_buttons, std::array< int64_t, 2 > scroll, std::array< int64_t, 2 > scroll_in_physical_pixel, bool is_precision_scroll)
std::vector< fuchsia::ui::pointer::MouseEvent > BuildAsVector()
MouseEventBuilder & AddViewParameters(std::array< std::array< float, 2 >, 2 > view, std::array< std::array< float, 2 >, 2 > viewport, std::array< float, 9 > transform)
MouseEventBuilder & AddTime(zx_time_t time)
MouseEventBuilder & AddMouseDeviceInfo(uint32_t id, std::vector< uint8_t > buttons)
std::vector< fuchsia::ui::pointer::TouchEvent > BuildAsVector()
fuchsia::ui::pointer::TouchEvent Build()
TouchEventBuilder & AddViewParameters(std::array< std::array< float, 2 >, 2 > view, std::array< std::array< float, 2 >, 2 > viewport, std::array< float, 9 > transform)
TouchEventBuilder & AddSample(fuchsia::ui::pointer::TouchInteractionId id, fuchsia::ui::pointer::EventPhase phase, std::array< float, 2 > position)
TouchEventBuilder & AddTime(zx_time_t time)
TouchEventBuilder & AddResult(fuchsia::ui::pointer::TouchInteractionResult result)
const EmbeddedViewParams * params
FlKeyEvent * event
GAsyncResult * result
fuchsia::ui::pointer::TouchEvent fup_TouchEvent
fuchsia::ui::pointer::EventPhase fup_EventPhase
fuchsia::ui::pointer::MouseDeviceInfo fup_MouseDeviceInfo
fuchsia::ui::pointer::TouchPointerSample fup_TouchPointerSample
fuchsia::ui::pointer::MousePointerSample fup_MousePointerSample
fuchsia::ui::pointer::TouchInteractionResult fup_TouchIxnResult
fuchsia::ui::pointer::MouseEvent fup_MouseEvent
fuchsia::ui::pointer::ViewParameters fup_ViewParameters
fuchsia::ui::pointer::TouchInteractionId fup_TouchIxnId
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47