1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | export component TestCase { |
5 | in-out property <int> touch1; |
6 | in-out property <int> touch2; |
7 | in-out property <int> touch3; |
8 | in-out property <int> touch_double1; |
9 | in-out property <int> touch_double2; |
10 | in-out property <int> touch_double3; |
11 | |
12 | in-out property <string> pointer-event-test; |
13 | |
14 | TouchArea { |
15 | x: 100phx; |
16 | y: 100phx; |
17 | width: 10phx; |
18 | height: 10phx; |
19 | clicked => { touch1+=1; } |
20 | double-clicked => { touch_double1+=1; } |
21 | mouse-cursor: move; |
22 | TouchArea { |
23 | y: 2phx; |
24 | height: 2phx; |
25 | x: 3phx; |
26 | width: 4phx; |
27 | clicked => { touch3+=1; } |
28 | double-clicked => { touch_double3+=1; } |
29 | mouse-cursor: default; |
30 | } |
31 | } |
32 | TouchArea { |
33 | x: 100phx; |
34 | y: 100phx; |
35 | width: 5phx; |
36 | height: 5phx; |
37 | mouse-cursor: pointer; |
38 | clicked => { |
39 | pointer-event-test += "click:" ; |
40 | touch2+=1; |
41 | } |
42 | double-clicked => { |
43 | pointer-event-test += "double_click:" ; |
44 | touch_double2+=1; |
45 | } |
46 | pointer-event(e) => { |
47 | if (e.kind == PointerEventKind.cancel) { |
48 | pointer-event-test += "cancel." ; |
49 | } else if (e.kind == PointerEventKind.up) { |
50 | pointer-event-test += "up." ; |
51 | } else if (e.kind == PointerEventKind.down) { |
52 | pointer-event-test += "down." ; |
53 | } else if (e.kind == PointerEventKind.move) { |
54 | pointer-event-test += "move." ; |
55 | } else { |
56 | pointer-event-test += "err." ; |
57 | } |
58 | if (e.button == PointerEventButton.right) { |
59 | pointer-event-test += "right" ; |
60 | } else if (e.button == PointerEventButton.left) { |
61 | pointer-event-test += "left" ; |
62 | } else if (e.button == PointerEventButton.middle) { |
63 | pointer-event-test += "middle" ; |
64 | } else if (e.button == PointerEventButton.other) { |
65 | pointer-event-test += "other" ; |
66 | } else { |
67 | pointer-event-test += "???" ; |
68 | } |
69 | if (e.modifiers.control) { |
70 | pointer-event-test += "(ctrl)" ; |
71 | } |
72 | if (e.modifiers.shift) { |
73 | pointer-event-test += "(shift)" ; |
74 | } |
75 | if (e.modifiers.meta) { |
76 | pointer-event-test += "(meta)" ; |
77 | } |
78 | if (e.modifiers.alt) { |
79 | pointer-event-test += "(alt)" ; |
80 | } |
81 | pointer-event-test += ":" ; |
82 | } |
83 | } |
84 | } |
85 | |
86 | /* |
87 | ```cpp |
88 | using slint::PointerEventButton; |
89 | |
90 | auto handle = TestCase::create(); |
91 | const TestCase &instance = *handle; |
92 | |
93 | auto double_click = [&](float x, float y) { |
94 | slint_testing::send_mouse_click(&instance, x, y); |
95 | slint_testing::mock_elapsed_time(50); |
96 | slint_testing::send_mouse_click(&instance, x, y); |
97 | }; |
98 | |
99 | // does not click on anything |
100 | slint_testing::send_mouse_click(&instance, 5., 5.); |
101 | assert_eq(instance.get_touch1(), 0); |
102 | assert_eq(instance.get_touch2(), 0); |
103 | assert_eq(instance.get_touch3(), 0); |
104 | assert_eq(instance.get_touch_double1(), 0); |
105 | assert_eq(instance.get_touch_double2(), 0); |
106 | assert_eq(instance.get_touch_double3(), 0); |
107 | |
108 | // click on second one |
109 | slint_testing::mock_elapsed_time(1000); |
110 | slint_testing::send_mouse_click(&instance, 101., 101.); |
111 | assert_eq(instance.get_touch1(), 0); |
112 | assert_eq(instance.get_touch2(), 1); |
113 | assert_eq(instance.get_touch3(), 0); |
114 | assert_eq(instance.get_touch_double1(), 0); |
115 | assert_eq(instance.get_touch_double2(), 0); |
116 | assert_eq(instance.get_touch_double3(), 0); |
117 | |
118 | // click on first one only |
119 | slint_testing::mock_elapsed_time(1000); |
120 | slint_testing::send_mouse_click(&instance, 108., 108.); |
121 | assert_eq(instance.get_touch1(), 1); |
122 | assert_eq(instance.get_touch2(), 1); |
123 | assert_eq(instance.get_touch3(), 0); |
124 | assert_eq(instance.get_touch_double1(), 0); |
125 | assert_eq(instance.get_touch_double2(), 0); |
126 | assert_eq(instance.get_touch_double3(), 0); |
127 | |
128 | // click on the third |
129 | slint_testing::mock_elapsed_time(1000); |
130 | slint_testing::send_mouse_click(&instance, 106., 103.); |
131 | assert_eq(instance.get_touch1(), 1); |
132 | assert_eq(instance.get_touch2(), 1); |
133 | assert_eq(instance.get_touch3(), 1); |
134 | assert_eq(instance.get_touch_double1(), 0); |
135 | assert_eq(instance.get_touch_double2(), 0); |
136 | assert_eq(instance.get_touch_double3(), 0); |
137 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:"); |
138 | |
139 | // does not double-click on anything |
140 | slint_testing::mock_elapsed_time(1000); |
141 | double_click(5., 5.); |
142 | assert_eq(instance.get_touch1(), 1); |
143 | assert_eq(instance.get_touch2(), 1); |
144 | assert_eq(instance.get_touch3(), 1); |
145 | assert_eq(instance.get_touch_double1(), 0); |
146 | assert_eq(instance.get_touch_double2(), 0); |
147 | assert_eq(instance.get_touch_double3(), 0); |
148 | |
149 | // double-click on second one |
150 | slint_testing::mock_elapsed_time(1000); |
151 | instance.set_pointer_event_test(""); |
152 | double_click(101., 101.); |
153 | assert_eq(instance.get_touch1(), 1); |
154 | assert_eq(instance.get_touch2(), 3); |
155 | assert_eq(instance.get_touch3(), 1); |
156 | assert_eq(instance.get_touch_double1(), 0); |
157 | assert_eq(instance.get_touch_double2(), 1); |
158 | assert_eq(instance.get_touch_double3(), 0); |
159 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:"); |
160 | |
161 | // double-click on first one only |
162 | slint_testing::mock_elapsed_time(1000); |
163 | double_click(108., 108.); |
164 | assert_eq(instance.get_touch1(), 3); |
165 | assert_eq(instance.get_touch2(), 3); |
166 | assert_eq(instance.get_touch3(), 1); |
167 | assert_eq(instance.get_touch_double1(), 1); |
168 | assert_eq(instance.get_touch_double2(), 1); |
169 | assert_eq(instance.get_touch_double3(), 0); |
170 | |
171 | // double-click on the third |
172 | slint_testing::mock_elapsed_time(1000); |
173 | double_click(106., 103.); |
174 | assert_eq(instance.get_touch1(), 3); |
175 | assert_eq(instance.get_touch2(), 3); |
176 | assert_eq(instance.get_touch3(), 3); |
177 | assert_eq(instance.get_touch_double1(), 1); |
178 | assert_eq(instance.get_touch_double2(), 1); |
179 | assert_eq(instance.get_touch_double3(), 1); |
180 | |
181 | // triple-click on second one |
182 | slint_testing::mock_elapsed_time(1000); |
183 | slint_testing::send_mouse_click(&instance, 106., 103.); |
184 | slint_testing::send_mouse_click(&instance, 106., 103.); |
185 | slint_testing::send_mouse_click(&instance, 106., 103.); |
186 | assert_eq(instance.get_touch1(), 3); |
187 | assert_eq(instance.get_touch2(), 3); |
188 | assert_eq(instance.get_touch3(), 6); |
189 | assert_eq(instance.get_touch_double1(), 1); |
190 | assert_eq(instance.get_touch_double2(), 1); |
191 | assert_eq(instance.get_touch_double3(), 2); |
192 | |
193 | // click quickly on two different mouse areas |
194 | slint_testing::mock_elapsed_time(1000); |
195 | instance.set_pointer_event_test(""); |
196 | slint_testing::mock_elapsed_time(1000); |
197 | slint_testing::send_mouse_click(&instance, 101., 106.); // first |
198 | slint_testing::mock_elapsed_time(20); |
199 | slint_testing::send_mouse_click(&instance, 101., 104.); // second |
200 | instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 1.0, 1.0 })); |
201 | assert_eq(instance.get_touch1(), 4); |
202 | assert_eq(instance.get_touch2(), 4); |
203 | assert_eq(instance.get_touch3(), 6); |
204 | assert_eq(instance.get_touch_double1(), 1); |
205 | assert_eq(instance.get_touch_double2(), 1); |
206 | assert_eq(instance.get_touch_double3(), 2); |
207 | assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:"); |
208 | |
209 | // click slowly on the same touch areas twice |
210 | slint_testing::mock_elapsed_time(1000); |
211 | instance.set_pointer_event_test(""); |
212 | slint_testing::mock_elapsed_time(1000); |
213 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
214 | slint_testing::mock_elapsed_time(1000); |
215 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
216 | instance.window().dispatch_pointer_move_event(slint::LogicalPosition({1.0, 1.0})); |
217 | assert_eq(instance.get_touch1(), 4); |
218 | assert_eq(instance.get_touch2(), 6); |
219 | assert_eq(instance.get_touch3(), 6); |
220 | assert_eq(instance.get_touch_double1(), 1); |
221 | assert_eq(instance.get_touch_double2(), 1); |
222 | assert_eq(instance.get_touch_double3(), 2); |
223 | |
224 | slint_testing::mock_elapsed_time(1000); |
225 | slint_testing::send_mouse_click(&instance, 109., 101.); // first |
226 | slint_testing::mock_elapsed_time(10); |
227 | slint_testing::send_mouse_click(&instance, 101., 109.); // first |
228 | assert_eq(instance.get_touch1(), 6); |
229 | assert_eq(instance.get_touch2(), 6); |
230 | assert_eq(instance.get_touch3(), 6); |
231 | assert_eq(instance.get_touch_double1(), 1); |
232 | assert_eq(instance.get_touch_double2(), 1); |
233 | assert_eq(instance.get_touch_double3(), 2); |
234 | |
235 | |
236 | slint_testing::mock_elapsed_time(1000); |
237 | assert_eq(instance.get_touch1(), 6); |
238 | assert_eq(instance.get_touch2(), 6); |
239 | assert_eq(instance.get_touch3(), 6); |
240 | assert_eq(instance.get_touch_double1(), 1); |
241 | assert_eq(instance.get_touch_double2(), 1); |
242 | assert_eq(instance.get_touch_double3(), 2); |
243 | ``` |
244 | |
245 | ```rust |
246 | use slint::{platform::WindowEvent, LogicalPosition}; |
247 | use slint::private_unstable_api::re_exports::MouseCursor; |
248 | |
249 | let instance = TestCase::new().unwrap(); |
250 | |
251 | let double_click = |x, y| { |
252 | slint_testing::send_mouse_click(&instance, x, y); |
253 | slint_testing::mock_elapsed_time(50); |
254 | slint_testing::send_mouse_click(&instance, x, y); |
255 | }; |
256 | |
257 | |
258 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
259 | "Unexpected mousecursor at start"); |
260 | |
261 | // does not click on anything |
262 | slint_testing::send_mouse_click(&instance, 5., 5.); |
263 | slint_testing::mock_elapsed_time(1000); |
264 | assert_eq!(instance.get_touch1(), 0, "Mis-click registered at touch1"); |
265 | assert_eq!(instance.get_touch2(), 0, "Mis-click registered at touch2"); |
266 | assert_eq!(instance.get_touch3(), 0, "Mis-click registered at touch3"); |
267 | assert_eq!(instance.get_touch_double1(), 0, "Mis-click registered at touch1 as double-click"); |
268 | assert_eq!(instance.get_touch_double2(), 0, "Mis-click registered at touch2 as double-click"); |
269 | assert_eq!(instance.get_touch_double3(), 0, "Mis-click registered at touch3 as double-click"); |
270 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
271 | "Mis-click changed mouse cursor"); |
272 | |
273 | // click on second one |
274 | instance.set_pointer_event_test("".into()); |
275 | slint_testing::mock_elapsed_time(1000); |
276 | slint_testing::send_mouse_click(&instance, 101., 101.); |
277 | assert_eq!(instance.get_touch1(), 0, "Click on 2 registered at touch1"); |
278 | assert_eq!(instance.get_touch2(), 1, "Click on 2 did not register at touch2"); |
279 | assert_eq!(instance.get_touch3(), 0, "Click on 2 registered at touch3"); |
280 | assert_eq!(instance.get_touch_double1(), 0, "Click on 2 registered at touch1 as double-click"); |
281 | assert_eq!(instance.get_touch_double2(), 0, "Click on 2 registered at touch2 as double-click"); |
282 | assert_eq!(instance.get_touch_double3(), 0, "Click on 2 registered at touch3 as double-click"); |
283 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
284 | "Click on 1 did not change mouse pointer"); |
285 | |
286 | // click on first one only |
287 | slint_testing::mock_elapsed_time(1000); |
288 | slint_testing::send_mouse_click(&instance, 108., 108.); |
289 | assert_eq!(instance.get_touch1(), 1, "Click on 1 did not register at touch1"); |
290 | assert_eq!(instance.get_touch2(), 1, "Click on 1 registered at touch2"); |
291 | assert_eq!(instance.get_touch3(), 0, "Click on 1 registered at touch3"); |
292 | assert_eq!(instance.get_touch_double1(), 0, "Click on 1 registered at touch1 as double-click"); |
293 | assert_eq!(instance.get_touch_double2(), 0, "Click on 1 registered at touch2 as double-click"); |
294 | assert_eq!(instance.get_touch_double3(), 0, "Click on 1 registered at touch3 as double-click"); |
295 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
296 | "Click on 2 did not change mouse pointer"); |
297 | |
298 | // click on the third |
299 | slint_testing::mock_elapsed_time(1000); |
300 | slint_testing::send_mouse_click(&instance, 106., 103.); |
301 | assert_eq!(instance.get_touch1(), 1, "Click on 3 registered at touch1"); |
302 | assert_eq!(instance.get_touch2(), 1, "Click on 3 registered at touch2"); |
303 | assert_eq!(instance.get_touch3(), 1, "Click on 3 did not register at touch3"); |
304 | assert_eq!(instance.get_touch_double1(), 0, "Click on 3 registered at touch1 as double-click"); |
305 | assert_eq!(instance.get_touch_double2(), 0, "Click on 3 registered at touch2 as double-click"); |
306 | assert_eq!(instance.get_touch_double3(), 0, "Click on 3 registered at touch3 as double-click"); |
307 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:", |
308 | "Click on 3 produced an unexpected sequence of events"); |
309 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
310 | "Click on 3 did not change mouse pointer"); |
311 | |
312 | // does not double-click on anything |
313 | slint_testing::mock_elapsed_time(1000); |
314 | double_click(5., 5.); |
315 | assert_eq!(instance.get_touch1(), 1, "Mis-double-click registered at touch1"); |
316 | assert_eq!(instance.get_touch2(), 1, "Mis-double-click registered at touch2"); |
317 | assert_eq!(instance.get_touch3(), 1, "Mis-double-click registered at touch3"); |
318 | assert_eq!(instance.get_touch_double1(), 0, "Mis-double-click registered at touch1 as double-click"); |
319 | assert_eq!(instance.get_touch_double2(), 0, "Mis-double-click registered at touch2 as double-click"); |
320 | assert_eq!(instance.get_touch_double3(), 0, "Mis-double-click registered at touch3 as double-click"); |
321 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
322 | "Mis-double-click on 3 did not change mouse pointer"); |
323 | |
324 | // double-click on second one |
325 | slint_testing::mock_elapsed_time(1000); |
326 | instance.set_pointer_event_test("".into()); |
327 | double_click(101., 101.); |
328 | assert_eq!(instance.get_touch1(), 1, "Double-click on 2 registered at touch1"); |
329 | assert_eq!(instance.get_touch2(), 3, "Double-click on 2 did not registered at touch2"); |
330 | assert_eq!(instance.get_touch3(), 1, "Double-click on 2 registered at touch3"); |
331 | assert_eq!(instance.get_touch_double1(), 0, "Double-click on 2 registered at touch1 as double-click"); |
332 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 2 did not register at touch1 as double-click"); |
333 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 2 registered at touch1 as double-click"); |
334 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:", |
335 | "Double-click on 2 produced an unexpected sequence of events"); |
336 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer, |
337 | "Double-click on 2 did not change mouse pointer"); |
338 | |
339 | // double-click on first one only |
340 | slint_testing::mock_elapsed_time(1000); |
341 | double_click(108., 108.); |
342 | assert_eq!(instance.get_touch1(), 3, "Double-click on 1 did not registered at touch1"); |
343 | assert_eq!(instance.get_touch2(), 3, "Double-click on 1 registered at touch2"); |
344 | assert_eq!(instance.get_touch3(), 1, "Double-click on 1 registered at touch3"); |
345 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 1 did not register at touch1 as double-click"); |
346 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 1 registered at touch2 as double-click"); |
347 | assert_eq!(instance.get_touch_double3(), 0, "Double-click on 1 registered at touch3 as double-click"); |
348 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move, |
349 | "Double-click on 1 did not change mouse pointer"); |
350 | |
351 | // double-click on the third |
352 | slint_testing::mock_elapsed_time(1000); |
353 | double_click(106., 103.); |
354 | assert_eq!(instance.get_touch1(), 3, "Double-click on 3 registered at touch1"); |
355 | assert_eq!(instance.get_touch2(), 3, "Double-click on 3 registered at touch2"); |
356 | assert_eq!(instance.get_touch3(), 3, "Double-click on 3 did not registered at touch3"); |
357 | assert_eq!(instance.get_touch_double1(), 1, "Double-click on 3 registered at touch1 as double-click"); |
358 | assert_eq!(instance.get_touch_double2(), 1, "Double-click on 3 registered at touch2 as double-click"); |
359 | assert_eq!(instance.get_touch_double3(), 1, "Double-click on 3 did not register at touch3 as double-click"); |
360 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
361 | "Double-click on 3 did not change mouse pointer"); |
362 | |
363 | // triple-click on the third (treated as a double click, followed by a single click) |
364 | slint_testing::mock_elapsed_time(1000); |
365 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
366 | assert_eq!(instance.get_touch1(), 3, "Triple-click (1st click) on 3 registered at touch1"); |
367 | assert_eq!(instance.get_touch2(), 3, "Triple-click (1st click) on 3 registered at touch2"); |
368 | assert_eq!(instance.get_touch3(), 4, "Triple-click (1st click) on 3 did not register at touch3"); |
369 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
370 | assert_eq!(instance.get_touch1(), 3, "Triple-click (2st click) on 3 registered at touch1"); |
371 | assert_eq!(instance.get_touch2(), 3, "Triple-click (2st click) on 3 registered at touch2"); |
372 | assert_eq!(instance.get_touch3(), 5, "Triple-click (2st click) on 3 did not register at touch3"); |
373 | slint_testing::send_mouse_click(&instance, 106.0, 103.0); |
374 | assert_eq!(instance.get_touch1(), 3, "Triple-click on 3 registered at touch1"); |
375 | assert_eq!(instance.get_touch2(), 3, "Triple-click on 3 registered at touch1"); |
376 | assert_eq!(instance.get_touch3(), 6, "Triple-click on 3 registered at touch1"); |
377 | assert_eq!(instance.get_touch_double1(), 1, "Triple-click on 3 registered at touch1"); |
378 | assert_eq!(instance.get_touch_double2(), 1, "Triple-click on 3 registered at touch2"); |
379 | assert_eq!(instance.get_touch_double3(), 2, "Triple-click on 3 did not register at touch3 as double-click"); |
380 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
381 | "Triple-click on 3 did not change mouse pointer"); |
382 | |
383 | // click really quickly on two different mouse areas |
384 | slint_testing::mock_elapsed_time(1000); |
385 | instance.set_pointer_event_test("".into()); |
386 | slint_testing::mock_elapsed_time(1000); |
387 | slint_testing::send_mouse_click(&instance, 101., 106.); // first |
388 | slint_testing::mock_elapsed_time(20); |
389 | slint_testing::send_mouse_click(&instance, 101., 104.); // second |
390 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
391 | assert_eq!(instance.get_touch1(), 4, "click on different touch areas did not register on touch1"); |
392 | assert_eq!(instance.get_touch2(), 4, "click on different touch areas did not register on touch2"); |
393 | assert_eq!(instance.get_touch3(), 6, "click on different touch areas registered at touch3"); |
394 | assert_eq!(instance.get_touch_double1(), 1, "click on different touch areas registered on touch1 as double-click"); |
395 | assert_eq!(instance.get_touch_double2(), 1, "click on different touch areas registered on touch2 as double-click"); |
396 | assert_eq!(instance.get_touch_double3(), 2, "click on different touch areas registered on touch3 as double-click"); |
397 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
398 | "click on different touch areas changed mouse pointer"); |
399 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:", |
400 | "click on different touch areas produced an unexpected sequence of events"); |
401 | |
402 | // click slowly on the same touch areas twice |
403 | slint_testing::mock_elapsed_time(1000); |
404 | instance.set_pointer_event_test("".into()); |
405 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
406 | slint_testing::mock_elapsed_time(1000); |
407 | slint_testing::send_mouse_click(&instance, 101., 101.); // second |
408 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) }); |
409 | |
410 | assert_eq!(instance.get_touch1(), 4, "Slow double click did not register on touch1"); |
411 | assert_eq!(instance.get_touch2(), 6, "Slow double click did not register on touch2"); |
412 | assert_eq!(instance.get_touch3(), 6, "Slow double click did not register on touch3"); |
413 | assert_eq!(instance.get_touch_double1(), 1, "Slow double click registered on touch1 as double-click"); |
414 | assert_eq!(instance.get_touch_double2(), 1, "Slow double click registered on touch2 as double-click"); |
415 | assert_eq!(instance.get_touch_double3(), 2, "Slow double click registered on touch3 as double-click"); |
416 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default, |
417 | "click on different touch areas changed mouse pointer"); |
418 | assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:", |
419 | "click on different touch areas produced an unexpected sequence of events"); |
420 | |
421 | |
422 | // Click on the same mouse area but using a distance which is more than the threshold |
423 | slint_testing::mock_elapsed_time(1000); |
424 | slint_testing::send_mouse_click(&instance, 109., 101.); // first |
425 | slint_testing::mock_elapsed_time(10); |
426 | slint_testing::send_mouse_click(&instance, 101., 109.); // first |
427 | assert_eq!(instance.get_touch1(), 6, "long distance click 1"); |
428 | assert_eq!(instance.get_touch2(), 6, "long distance click 2"); |
429 | assert_eq!(instance.get_touch3(), 6, "long distance click 3"); |
430 | assert_eq!(instance.get_touch_double1(), 1, "long distance click as double click 1"); |
431 | assert_eq!(instance.get_touch_double2(), 1, "long distance click as double click 2"); |
432 | assert_eq!(instance.get_touch_double3(), 2, "long distance click as double click 3"); |
433 | |
434 | |
435 | slint_testing::mock_elapsed_time(1000); |
436 | assert_eq!(instance.get_touch1(), 6, "Cool down changed touch1"); |
437 | assert_eq!(instance.get_touch2(), 6, "Cool down changed touch2"); |
438 | assert_eq!(instance.get_touch3(), 6, "Cool down changed touch3"); |
439 | assert_eq!(instance.get_touch_double1(), 1, "Cool down changed touch-double1"); |
440 | assert_eq!(instance.get_touch_double2(), 1, "Cool down changed touch-double2"); |
441 | assert_eq!(instance.get_touch_double3(), 2, "Cool down changed touch-double3"); |
442 | ``` |
443 | |
444 | ```js |
445 | var instance = new slint.TestCase(); |
446 | |
447 | function double_click(x, y) { |
448 | slintlib.private_api.send_mouse_click(instance, x, y); |
449 | slintlib.private_api.mock_elapsed_time(50); |
450 | slintlib.private_api.send_mouse_click(instance, x, y); |
451 | } |
452 | |
453 | // // // Disable the test as the time handling is currently broken in JS tests! |
454 | |
455 | // // does not click on anything |
456 | // slintlib.private_api.send_mouse_click(instance, 5., 5.); |
457 | // assert.equal(instance.touch1, 0); |
458 | // assert.equal(instance.touch2, 0); |
459 | // assert.equal(instance.touch3, 0); |
460 | // assert.equal(instance.touch_double1, 0); |
461 | // assert.equal(instance.touch_double2, 0); |
462 | // assert.equal(instance.touch_double3, 0); |
463 | |
464 | // // click on second one |
465 | // slintlib.private_api.mock_elapsed_time(1000); |
466 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
467 | // assert.equal(instance.touch1, 0); |
468 | // assert.equal(instance.touch2, 1); |
469 | // assert.equal(instance.touch3, 0); |
470 | // assert.equal(instance.touch_double1, 0); |
471 | // assert.equal(instance.touch_double2, 0); |
472 | // assert.equal(instance.touch_double3, 0); |
473 | |
474 | // // click on first one only |
475 | // slintlib.private_api.mock_elapsed_time(2000); |
476 | // slintlib.private_api.send_mouse_click(instance, 108., 108.); |
477 | // assert.equal(instance.touch1, 1); |
478 | // assert.equal(instance.touch2, 1); |
479 | // assert.equal(instance.touch3, 0); |
480 | // assert.equal(instance.touch_double1, 0); |
481 | // assert.equal(instance.touch_double2, 0); |
482 | // assert.equal(instance.touch_double3, 0); |
483 | |
484 | // // click on the third |
485 | // slintlib.private_api.mock_elapsed_time(1000); |
486 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
487 | // assert.equal(instance.touch1, 1); |
488 | // assert.equal(instance.touch2, 1); |
489 | // assert.equal(instance.touch3, 1); |
490 | // assert.equal(instance.touch_double1, 0); |
491 | // assert.equal(instance.touch_double2, 0); |
492 | // assert.equal(instance.touch_double3, 0); |
493 | |
494 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:"); |
495 | |
496 | // // does not double-click on anything |
497 | // slintlib.private_api.mock_elapsed_time(1000); |
498 | // double_click(5., 5.); |
499 | // assert.equal(instance.touch1, 1); |
500 | // assert.equal(instance.touch2, 1); |
501 | // assert.equal(instance.touch3, 1); |
502 | // assert.equal(instance.touch_double1, 0); |
503 | // assert.equal(instance.touch_double2, 0); |
504 | // assert.equal(instance.touch_double3, 0); |
505 | |
506 | // // double-click on second one |
507 | // slintlib.private_api.mock_elapsed_time(1000); |
508 | // instance.pointer_event_test = ""; |
509 | // double_click(101., 101.); |
510 | // assert.equal(instance.touch1, 1); |
511 | // assert.equal(instance.touch2, 3); |
512 | // assert.equal(instance.touch3, 1); |
513 | // assert.equal(instance.touch_double1, 0); |
514 | // assert.equal(instance.touch_double2, 1); |
515 | // assert.equal(instance.touch_double3, 0); |
516 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:move.other:down.left:click:double_click:up.left:move.other:"); |
517 | |
518 | // // double-click on first one only |
519 | // slintlib.private_api.mock_elapsed_time(1000); |
520 | // double_click(108., 108.); |
521 | // assert.equal(instance.touch1, 3); |
522 | // assert.equal(instance.touch2, 3); |
523 | // assert.equal(instance.touch3, 1); |
524 | // assert.equal(instance.touch_double1, 1); |
525 | // assert.equal(instance.touch_double2, 1); |
526 | // assert.equal(instance.touch_double3, 0); |
527 | |
528 | // // double-click on third one only |
529 | // slintlib.private_api.mock_elapsed_time(1000); |
530 | // double_click(106., 103.); |
531 | // assert.equal(instance.touch1, 3); |
532 | // assert.equal(instance.touch2, 3); |
533 | // assert.equal(instance.touch3, 3); |
534 | // assert.equal(instance.touch_double1, 1); |
535 | // assert.equal(instance.touch_double2, 1); |
536 | // assert.equal(instance.touch_double3, 1); |
537 | |
538 | // // triple-click on the third |
539 | // slintlib.private_api.mock_elapsed_time(1000); |
540 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
541 | // assert.equal(instance.touch3, 4); |
542 | // assert.equal(instance.touch_double3, 1); |
543 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
544 | // assert.equal(instance.touch3, 5); |
545 | // assert.equal(instance.touch_double3, 2); |
546 | // slintlib.private_api.send_mouse_click(instance, 106., 103.); |
547 | // assert.equal(instance.touch1, 3); |
548 | // assert.equal(instance.touch2, 3); |
549 | // assert.equal(instance.touch3, 6); |
550 | // assert.equal(instance.touch_double1, 1); |
551 | // assert.equal(instance.touch_double2, 1); |
552 | // assert.equal(instance.touch_double3, 2); |
553 | |
554 | // // click really quickly on two different mouse areas |
555 | // slintlib.private_api.mock_elapsed_time(1000); |
556 | // instance.pointer_event_test = ""; |
557 | // slintlib.private_api.send_mouse_click(instance, 108., 108.); |
558 | // slintlib.private_api.mock_elapsed_time(20); |
559 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
560 | // assert.equal(instance.touch1, 4); |
561 | // assert.equal(instance.touch2, 4); |
562 | // assert.equal(instance.touch3, 6); |
563 | // assert.equal(instance.touch_double1, 1); |
564 | // assert.equal(instance.touch_double2, 1); |
565 | // assert.equal(instance.touch_double3, 2); |
566 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:"); |
567 | |
568 | // // click slowly on the same touch areas twice |
569 | // slintlib.private_api.mock_elapsed_time(1000); |
570 | // instance.pointer_event_test = ""; |
571 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
572 | // slintlib.private_api.mock_elapsed_time(1000); |
573 | // slintlib.private_api.send_mouse_click(instance, 101., 101.); |
574 | // assert.equal(instance.touch1, 4); |
575 | // assert.equal(instance.touch2, 6); |
576 | // assert.equal(instance.touch3, 6); |
577 | // assert.equal(instance.touch_double1, 1); |
578 | // assert.equal(instance.touch_double2, 1); |
579 | // assert.equal(instance.touch_double3, 2); |
580 | // assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:"); |
581 | |
582 | // slintlib.private_api.mock_elapsed_time(1000); |
583 | // assert.equal(instance.touch1, 4); |
584 | // assert.equal(instance.touch2, 6); |
585 | // assert.equal(instance.touch3, 6); |
586 | // assert.equal(instance.touch_double1, 1); |
587 | // assert.equal(instance.touch_double2, 1); |
588 | // assert.equal(instance.touch_double3, 2); |
589 | ``` |
590 | */ |
591 | |