1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
4
5export component TestCase {
6 in-out property <int> touch1;
7 in-out property <int> touch2;
8 in-out property <int> touch3;
9 in-out property <int> touch_double1;
10 in-out property <int> touch_double2;
11 in-out property <int> touch_double3;
12
13 in-out property <string> pointer-event-test;
14
15 TouchArea {
16 x: 100phx;
17 y: 100phx;
18 width: 10phx;
19 height: 10phx;
20 clicked => { touch1+=1; }
21 double-clicked => { touch_double1+=1; }
22 mouse-cursor: move;
23 TouchArea {
24 y: 2phx;
25 height: 2phx;
26 x: 3phx;
27 width: 4phx;
28 clicked => { touch3+=1; }
29 double-clicked => { touch_double3+=1; }
30 mouse-cursor: default;
31 }
32 }
33 TouchArea {
34 x: 100phx;
35 y: 100phx;
36 width: 5phx;
37 height: 5phx;
38 mouse-cursor: pointer;
39 clicked => {
40 pointer-event-test += "click:";
41 touch2+=1;
42 }
43 double-clicked => {
44 pointer-event-test += "double_click:";
45 touch_double2+=1;
46 }
47 pointer-event(e) => {
48 if (e.kind == PointerEventKind.cancel) {
49 pointer-event-test += "cancel.";
50 } else if (e.kind == PointerEventKind.up) {
51 pointer-event-test += "up.";
52 } else if (e.kind == PointerEventKind.down) {
53 pointer-event-test += "down.";
54 } else if (e.kind == PointerEventKind.move) {
55 pointer-event-test += "move.";
56 } else {
57 pointer-event-test += "err.";
58 }
59 if (e.button == PointerEventButton.right) {
60 pointer-event-test += "right";
61 } else if (e.button == PointerEventButton.left) {
62 pointer-event-test += "left";
63 } else if (e.button == PointerEventButton.middle) {
64 pointer-event-test += "middle";
65 } else if (e.button == PointerEventButton.other) {
66 pointer-event-test += "other";
67 } else {
68 pointer-event-test += "???";
69 }
70 if (e.modifiers.control) {
71 pointer-event-test += "(ctrl)";
72 }
73 if (e.modifiers.shift) {
74 pointer-event-test += "(shift)";
75 }
76 if (e.modifiers.meta) {
77 pointer-event-test += "(meta)";
78 }
79 if (e.modifiers.alt) {
80 pointer-event-test += "(alt)";
81 }
82 pointer-event-test += ":";
83 }
84 }
85}
86
87/*
88```cpp
89using slint::PointerEventButton;
90
91auto handle = TestCase::create();
92const TestCase &instance = *handle;
93
94auto double_click = [&](float x, float y) {
95 slint_testing::send_mouse_click(&instance, x, y);
96 slint_testing::mock_elapsed_time(50);
97 slint_testing::send_mouse_click(&instance, x, y);
98};
99
100// does not click on anything
101slint_testing::send_mouse_click(&instance, 5., 5.);
102assert_eq(instance.get_touch1(), 0);
103assert_eq(instance.get_touch2(), 0);
104assert_eq(instance.get_touch3(), 0);
105assert_eq(instance.get_touch_double1(), 0);
106assert_eq(instance.get_touch_double2(), 0);
107assert_eq(instance.get_touch_double3(), 0);
108
109// click on second one
110slint_testing::mock_elapsed_time(1000);
111slint_testing::send_mouse_click(&instance, 101., 101.);
112assert_eq(instance.get_touch1(), 0);
113assert_eq(instance.get_touch2(), 1);
114assert_eq(instance.get_touch3(), 0);
115assert_eq(instance.get_touch_double1(), 0);
116assert_eq(instance.get_touch_double2(), 0);
117assert_eq(instance.get_touch_double3(), 0);
118
119// click on first one only
120slint_testing::mock_elapsed_time(1000);
121slint_testing::send_mouse_click(&instance, 108., 108.);
122assert_eq(instance.get_touch1(), 1);
123assert_eq(instance.get_touch2(), 1);
124assert_eq(instance.get_touch3(), 0);
125assert_eq(instance.get_touch_double1(), 0);
126assert_eq(instance.get_touch_double2(), 0);
127assert_eq(instance.get_touch_double3(), 0);
128
129// click on the third
130slint_testing::mock_elapsed_time(1000);
131slint_testing::send_mouse_click(&instance, 106., 103.);
132assert_eq(instance.get_touch1(), 1);
133assert_eq(instance.get_touch2(), 1);
134assert_eq(instance.get_touch3(), 1);
135assert_eq(instance.get_touch_double1(), 0);
136assert_eq(instance.get_touch_double2(), 0);
137assert_eq(instance.get_touch_double3(), 0);
138assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:");
139
140// does not double-click on anything
141slint_testing::mock_elapsed_time(1000);
142double_click(5., 5.);
143assert_eq(instance.get_touch1(), 1);
144assert_eq(instance.get_touch2(), 1);
145assert_eq(instance.get_touch3(), 1);
146assert_eq(instance.get_touch_double1(), 0);
147assert_eq(instance.get_touch_double2(), 0);
148assert_eq(instance.get_touch_double3(), 0);
149
150// double-click on second one
151slint_testing::mock_elapsed_time(1000);
152instance.set_pointer_event_test("");
153double_click(101., 101.);
154assert_eq(instance.get_touch1(), 1);
155assert_eq(instance.get_touch2(), 3);
156assert_eq(instance.get_touch3(), 1);
157assert_eq(instance.get_touch_double1(), 0);
158assert_eq(instance.get_touch_double2(), 1);
159assert_eq(instance.get_touch_double3(), 0);
160assert_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:");
161
162// double-click on first one only
163slint_testing::mock_elapsed_time(1000);
164double_click(108., 108.);
165assert_eq(instance.get_touch1(), 3);
166assert_eq(instance.get_touch2(), 3);
167assert_eq(instance.get_touch3(), 1);
168assert_eq(instance.get_touch_double1(), 1);
169assert_eq(instance.get_touch_double2(), 1);
170assert_eq(instance.get_touch_double3(), 0);
171
172// double-click on the third
173slint_testing::mock_elapsed_time(1000);
174double_click(106., 103.);
175assert_eq(instance.get_touch1(), 3);
176assert_eq(instance.get_touch2(), 3);
177assert_eq(instance.get_touch3(), 3);
178assert_eq(instance.get_touch_double1(), 1);
179assert_eq(instance.get_touch_double2(), 1);
180assert_eq(instance.get_touch_double3(), 1);
181
182// triple-click on second one
183slint_testing::mock_elapsed_time(1000);
184slint_testing::send_mouse_click(&instance, 106., 103.);
185slint_testing::send_mouse_click(&instance, 106., 103.);
186slint_testing::send_mouse_click(&instance, 106., 103.);
187assert_eq(instance.get_touch1(), 3);
188assert_eq(instance.get_touch2(), 3);
189assert_eq(instance.get_touch3(), 6);
190assert_eq(instance.get_touch_double1(), 1);
191assert_eq(instance.get_touch_double2(), 1);
192assert_eq(instance.get_touch_double3(), 2);
193
194// click quickly on two different mouse areas
195slint_testing::mock_elapsed_time(1000);
196instance.set_pointer_event_test("");
197slint_testing::mock_elapsed_time(1000);
198slint_testing::send_mouse_click(&instance, 101., 106.); // first
199slint_testing::mock_elapsed_time(20);
200slint_testing::send_mouse_click(&instance, 101., 104.); // second
201instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 1.0, 1.0 }));
202assert_eq(instance.get_touch1(), 4);
203assert_eq(instance.get_touch2(), 4);
204assert_eq(instance.get_touch3(), 6);
205assert_eq(instance.get_touch_double1(), 1);
206assert_eq(instance.get_touch_double2(), 1);
207assert_eq(instance.get_touch_double3(), 2);
208assert_eq(instance.get_pointer_event_test(), "move.other:down.left:click:up.left:move.other:");
209
210// click slowly on the same touch areas twice
211slint_testing::mock_elapsed_time(1000);
212instance.set_pointer_event_test("");
213slint_testing::mock_elapsed_time(1000);
214slint_testing::send_mouse_click(&instance, 101., 101.); // second
215slint_testing::mock_elapsed_time(1000);
216slint_testing::send_mouse_click(&instance, 101., 101.); // second
217instance.window().dispatch_pointer_move_event(slint::LogicalPosition({1.0, 1.0}));
218assert_eq(instance.get_touch1(), 4);
219assert_eq(instance.get_touch2(), 6);
220assert_eq(instance.get_touch3(), 6);
221assert_eq(instance.get_touch_double1(), 1);
222assert_eq(instance.get_touch_double2(), 1);
223assert_eq(instance.get_touch_double3(), 2);
224
225slint_testing::mock_elapsed_time(1000);
226slint_testing::send_mouse_click(&instance, 109., 101.); // first
227slint_testing::mock_elapsed_time(10);
228slint_testing::send_mouse_click(&instance, 101., 109.); // first
229assert_eq(instance.get_touch1(), 6);
230assert_eq(instance.get_touch2(), 6);
231assert_eq(instance.get_touch3(), 6);
232assert_eq(instance.get_touch_double1(), 1);
233assert_eq(instance.get_touch_double2(), 1);
234assert_eq(instance.get_touch_double3(), 2);
235
236
237slint_testing::mock_elapsed_time(1000);
238assert_eq(instance.get_touch1(), 6);
239assert_eq(instance.get_touch2(), 6);
240assert_eq(instance.get_touch3(), 6);
241assert_eq(instance.get_touch_double1(), 1);
242assert_eq(instance.get_touch_double2(), 1);
243assert_eq(instance.get_touch_double3(), 2);
244```
245
246```rust
247use slint::{platform::WindowEvent, LogicalPosition};
248use slint::private_unstable_api::re_exports::MouseCursor;
249
250let instance = TestCase::new().unwrap();
251
252let double_click = |x, y| {
253 slint_testing::send_mouse_click(&instance, x, y);
254 slint_testing::mock_elapsed_time(50);
255 slint_testing::send_mouse_click(&instance, x, y);
256};
257
258
259assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
260 "Unexpected mousecursor at start");
261
262// does not click on anything
263slint_testing::send_mouse_click(&instance, 5., 5.);
264slint_testing::mock_elapsed_time(1000);
265assert_eq!(instance.get_touch1(), 0, "Mis-click registered at touch1");
266assert_eq!(instance.get_touch2(), 0, "Mis-click registered at touch2");
267assert_eq!(instance.get_touch3(), 0, "Mis-click registered at touch3");
268assert_eq!(instance.get_touch_double1(), 0, "Mis-click registered at touch1 as double-click");
269assert_eq!(instance.get_touch_double2(), 0, "Mis-click registered at touch2 as double-click");
270assert_eq!(instance.get_touch_double3(), 0, "Mis-click registered at touch3 as double-click");
271assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
272 "Mis-click changed mouse cursor");
273
274// click on second one
275instance.set_pointer_event_test("".into());
276slint_testing::mock_elapsed_time(1000);
277slint_testing::send_mouse_click(&instance, 101., 101.);
278assert_eq!(instance.get_touch1(), 0, "Click on 2 registered at touch1");
279assert_eq!(instance.get_touch2(), 1, "Click on 2 did not register at touch2");
280assert_eq!(instance.get_touch3(), 0, "Click on 2 registered at touch3");
281assert_eq!(instance.get_touch_double1(), 0, "Click on 2 registered at touch1 as double-click");
282assert_eq!(instance.get_touch_double2(), 0, "Click on 2 registered at touch2 as double-click");
283assert_eq!(instance.get_touch_double3(), 0, "Click on 2 registered at touch3 as double-click");
284assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer,
285 "Click on 1 did not change mouse pointer");
286
287// click on first one only
288slint_testing::mock_elapsed_time(1000);
289slint_testing::send_mouse_click(&instance, 108., 108.);
290assert_eq!(instance.get_touch1(), 1, "Click on 1 did not register at touch1");
291assert_eq!(instance.get_touch2(), 1, "Click on 1 registered at touch2");
292assert_eq!(instance.get_touch3(), 0, "Click on 1 registered at touch3");
293assert_eq!(instance.get_touch_double1(), 0, "Click on 1 registered at touch1 as double-click");
294assert_eq!(instance.get_touch_double2(), 0, "Click on 1 registered at touch2 as double-click");
295assert_eq!(instance.get_touch_double3(), 0, "Click on 1 registered at touch3 as double-click");
296assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move,
297 "Click on 2 did not change mouse pointer");
298
299// click on the third
300slint_testing::mock_elapsed_time(1000);
301slint_testing::send_mouse_click(&instance, 106., 103.);
302assert_eq!(instance.get_touch1(), 1, "Click on 3 registered at touch1");
303assert_eq!(instance.get_touch2(), 1, "Click on 3 registered at touch2");
304assert_eq!(instance.get_touch3(), 1, "Click on 3 did not register at touch3");
305assert_eq!(instance.get_touch_double1(), 0, "Click on 3 registered at touch1 as double-click");
306assert_eq!(instance.get_touch_double2(), 0, "Click on 3 registered at touch2 as double-click");
307assert_eq!(instance.get_touch_double3(), 0, "Click on 3 registered at touch3 as double-click");
308assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:",
309 "Click on 3 produced an unexpected sequence of events");
310assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
311 "Click on 3 did not change mouse pointer");
312
313// does not double-click on anything
314slint_testing::mock_elapsed_time(1000);
315double_click(5., 5.);
316assert_eq!(instance.get_touch1(), 1, "Mis-double-click registered at touch1");
317assert_eq!(instance.get_touch2(), 1, "Mis-double-click registered at touch2");
318assert_eq!(instance.get_touch3(), 1, "Mis-double-click registered at touch3");
319assert_eq!(instance.get_touch_double1(), 0, "Mis-double-click registered at touch1 as double-click");
320assert_eq!(instance.get_touch_double2(), 0, "Mis-double-click registered at touch2 as double-click");
321assert_eq!(instance.get_touch_double3(), 0, "Mis-double-click registered at touch3 as double-click");
322assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
323 "Mis-double-click on 3 did not change mouse pointer");
324
325// double-click on second one
326slint_testing::mock_elapsed_time(1000);
327instance.set_pointer_event_test("".into());
328double_click(101., 101.);
329assert_eq!(instance.get_touch1(), 1, "Double-click on 2 registered at touch1");
330assert_eq!(instance.get_touch2(), 3, "Double-click on 2 did not registered at touch2");
331assert_eq!(instance.get_touch3(), 1, "Double-click on 2 registered at touch3");
332assert_eq!(instance.get_touch_double1(), 0, "Double-click on 2 registered at touch1 as double-click");
333assert_eq!(instance.get_touch_double2(), 1, "Double-click on 2 did not register at touch1 as double-click");
334assert_eq!(instance.get_touch_double3(), 0, "Double-click on 2 registered at touch1 as double-click");
335assert_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:",
336 "Double-click on 2 produced an unexpected sequence of events");
337assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer,
338 "Double-click on 2 did not change mouse pointer");
339
340// double-click on first one only
341slint_testing::mock_elapsed_time(1000);
342double_click(108., 108.);
343assert_eq!(instance.get_touch1(), 3, "Double-click on 1 did not registered at touch1");
344assert_eq!(instance.get_touch2(), 3, "Double-click on 1 registered at touch2");
345assert_eq!(instance.get_touch3(), 1, "Double-click on 1 registered at touch3");
346assert_eq!(instance.get_touch_double1(), 1, "Double-click on 1 did not register at touch1 as double-click");
347assert_eq!(instance.get_touch_double2(), 1, "Double-click on 1 registered at touch2 as double-click");
348assert_eq!(instance.get_touch_double3(), 0, "Double-click on 1 registered at touch3 as double-click");
349assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move,
350 "Double-click on 1 did not change mouse pointer");
351
352// double-click on the third
353slint_testing::mock_elapsed_time(1000);
354double_click(106., 103.);
355assert_eq!(instance.get_touch1(), 3, "Double-click on 3 registered at touch1");
356assert_eq!(instance.get_touch2(), 3, "Double-click on 3 registered at touch2");
357assert_eq!(instance.get_touch3(), 3, "Double-click on 3 did not registered at touch3");
358assert_eq!(instance.get_touch_double1(), 1, "Double-click on 3 registered at touch1 as double-click");
359assert_eq!(instance.get_touch_double2(), 1, "Double-click on 3 registered at touch2 as double-click");
360assert_eq!(instance.get_touch_double3(), 1, "Double-click on 3 did not register at touch3 as double-click");
361assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
362 "Double-click on 3 did not change mouse pointer");
363
364// triple-click on the third (treated as a double click, followed by a single click)
365slint_testing::mock_elapsed_time(1000);
366slint_testing::send_mouse_click(&instance, 106.0, 103.0);
367assert_eq!(instance.get_touch1(), 3, "Triple-click (1st click) on 3 registered at touch1");
368assert_eq!(instance.get_touch2(), 3, "Triple-click (1st click) on 3 registered at touch2");
369assert_eq!(instance.get_touch3(), 4, "Triple-click (1st click) on 3 did not register at touch3");
370slint_testing::send_mouse_click(&instance, 106.0, 103.0);
371assert_eq!(instance.get_touch1(), 3, "Triple-click (2st click) on 3 registered at touch1");
372assert_eq!(instance.get_touch2(), 3, "Triple-click (2st click) on 3 registered at touch2");
373assert_eq!(instance.get_touch3(), 5, "Triple-click (2st click) on 3 did not register at touch3");
374slint_testing::send_mouse_click(&instance, 106.0, 103.0);
375assert_eq!(instance.get_touch1(), 3, "Triple-click on 3 registered at touch1");
376assert_eq!(instance.get_touch2(), 3, "Triple-click on 3 registered at touch1");
377assert_eq!(instance.get_touch3(), 6, "Triple-click on 3 registered at touch1");
378assert_eq!(instance.get_touch_double1(), 1, "Triple-click on 3 registered at touch1");
379assert_eq!(instance.get_touch_double2(), 1, "Triple-click on 3 registered at touch2");
380assert_eq!(instance.get_touch_double3(), 2, "Triple-click on 3 did not register at touch3 as double-click");
381assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
382 "Triple-click on 3 did not change mouse pointer");
383
384// click really quickly on two different mouse areas
385slint_testing::mock_elapsed_time(1000);
386instance.set_pointer_event_test("".into());
387slint_testing::mock_elapsed_time(1000);
388slint_testing::send_mouse_click(&instance, 101., 106.); // first
389slint_testing::mock_elapsed_time(20);
390slint_testing::send_mouse_click(&instance, 101., 104.); // second
391instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) });
392assert_eq!(instance.get_touch1(), 4, "click on different touch areas did not register on touch1");
393assert_eq!(instance.get_touch2(), 4, "click on different touch areas did not register on touch2");
394assert_eq!(instance.get_touch3(), 6, "click on different touch areas registered at touch3");
395assert_eq!(instance.get_touch_double1(), 1, "click on different touch areas registered on touch1 as double-click");
396assert_eq!(instance.get_touch_double2(), 1, "click on different touch areas registered on touch2 as double-click");
397assert_eq!(instance.get_touch_double3(), 2, "click on different touch areas registered on touch3 as double-click");
398assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
399 "click on different touch areas changed mouse pointer");
400assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:",
401 "click on different touch areas produced an unexpected sequence of events");
402
403// click slowly on the same touch areas twice
404slint_testing::mock_elapsed_time(1000);
405instance.set_pointer_event_test("".into());
406slint_testing::send_mouse_click(&instance, 101., 101.); // second
407slint_testing::mock_elapsed_time(1000);
408slint_testing::send_mouse_click(&instance, 101., 101.); // second
409instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) });
410
411assert_eq!(instance.get_touch1(), 4, "Slow double click did not register on touch1");
412assert_eq!(instance.get_touch2(), 6, "Slow double click did not register on touch2");
413assert_eq!(instance.get_touch3(), 6, "Slow double click did not register on touch3");
414assert_eq!(instance.get_touch_double1(), 1, "Slow double click registered on touch1 as double-click");
415assert_eq!(instance.get_touch_double2(), 1, "Slow double click registered on touch2 as double-click");
416assert_eq!(instance.get_touch_double3(), 2, "Slow double click registered on touch3 as double-click");
417assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
418 "click on different touch areas changed mouse pointer");
419assert_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:",
420 "click on different touch areas produced an unexpected sequence of events");
421
422
423// Click on the same mouse area but using a distance which is more than the threshold
424slint_testing::mock_elapsed_time(1000);
425slint_testing::send_mouse_click(&instance, 109., 101.); // first
426slint_testing::mock_elapsed_time(10);
427slint_testing::send_mouse_click(&instance, 101., 109.); // first
428assert_eq!(instance.get_touch1(), 6, "long distance click 1");
429assert_eq!(instance.get_touch2(), 6, "long distance click 2");
430assert_eq!(instance.get_touch3(), 6, "long distance click 3");
431assert_eq!(instance.get_touch_double1(), 1, "long distance click as double click 1");
432assert_eq!(instance.get_touch_double2(), 1, "long distance click as double click 2");
433assert_eq!(instance.get_touch_double3(), 2, "long distance click as double click 3");
434
435
436slint_testing::mock_elapsed_time(1000);
437assert_eq!(instance.get_touch1(), 6, "Cool down changed touch1");
438assert_eq!(instance.get_touch2(), 6, "Cool down changed touch2");
439assert_eq!(instance.get_touch3(), 6, "Cool down changed touch3");
440assert_eq!(instance.get_touch_double1(), 1, "Cool down changed touch-double1");
441assert_eq!(instance.get_touch_double2(), 1, "Cool down changed touch-double2");
442assert_eq!(instance.get_touch_double3(), 2, "Cool down changed touch-double3");
443```
444
445```js
446var instance = new slint.TestCase();
447
448function double_click(x, y) {
449 slintlib.private_api.send_mouse_click(instance, x, y);
450 slintlib.private_api.mock_elapsed_time(50);
451 slintlib.private_api.send_mouse_click(instance, x, y);
452}
453
454// // // Disable the test as the time handling is currently broken in JS tests!
455
456// // does not click on anything
457// slintlib.private_api.send_mouse_click(instance, 5., 5.);
458// assert.equal(instance.touch1, 0);
459// assert.equal(instance.touch2, 0);
460// assert.equal(instance.touch3, 0);
461// assert.equal(instance.touch_double1, 0);
462// assert.equal(instance.touch_double2, 0);
463// assert.equal(instance.touch_double3, 0);
464
465// // click on second one
466// slintlib.private_api.mock_elapsed_time(1000);
467// slintlib.private_api.send_mouse_click(instance, 101., 101.);
468// assert.equal(instance.touch1, 0);
469// assert.equal(instance.touch2, 1);
470// assert.equal(instance.touch3, 0);
471// assert.equal(instance.touch_double1, 0);
472// assert.equal(instance.touch_double2, 0);
473// assert.equal(instance.touch_double3, 0);
474
475// // click on first one only
476// slintlib.private_api.mock_elapsed_time(2000);
477// slintlib.private_api.send_mouse_click(instance, 108., 108.);
478// assert.equal(instance.touch1, 1);
479// assert.equal(instance.touch2, 1);
480// assert.equal(instance.touch3, 0);
481// assert.equal(instance.touch_double1, 0);
482// assert.equal(instance.touch_double2, 0);
483// assert.equal(instance.touch_double3, 0);
484
485// // click on the third
486// slintlib.private_api.mock_elapsed_time(1000);
487// slintlib.private_api.send_mouse_click(instance, 106., 103.);
488// assert.equal(instance.touch1, 1);
489// assert.equal(instance.touch2, 1);
490// assert.equal(instance.touch3, 1);
491// assert.equal(instance.touch_double1, 0);
492// assert.equal(instance.touch_double2, 0);
493// assert.equal(instance.touch_double3, 0);
494
495// assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:");
496
497// // does not double-click on anything
498// slintlib.private_api.mock_elapsed_time(1000);
499// double_click(5., 5.);
500// assert.equal(instance.touch1, 1);
501// assert.equal(instance.touch2, 1);
502// assert.equal(instance.touch3, 1);
503// assert.equal(instance.touch_double1, 0);
504// assert.equal(instance.touch_double2, 0);
505// assert.equal(instance.touch_double3, 0);
506
507// // double-click on second one
508// slintlib.private_api.mock_elapsed_time(1000);
509// instance.pointer_event_test = "";
510// double_click(101., 101.);
511// assert.equal(instance.touch1, 1);
512// assert.equal(instance.touch2, 3);
513// assert.equal(instance.touch3, 1);
514// assert.equal(instance.touch_double1, 0);
515// assert.equal(instance.touch_double2, 1);
516// assert.equal(instance.touch_double3, 0);
517// 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:");
518
519// // double-click on first one only
520// slintlib.private_api.mock_elapsed_time(1000);
521// double_click(108., 108.);
522// assert.equal(instance.touch1, 3);
523// assert.equal(instance.touch2, 3);
524// assert.equal(instance.touch3, 1);
525// assert.equal(instance.touch_double1, 1);
526// assert.equal(instance.touch_double2, 1);
527// assert.equal(instance.touch_double3, 0);
528
529// // double-click on third one only
530// slintlib.private_api.mock_elapsed_time(1000);
531// double_click(106., 103.);
532// assert.equal(instance.touch1, 3);
533// assert.equal(instance.touch2, 3);
534// assert.equal(instance.touch3, 3);
535// assert.equal(instance.touch_double1, 1);
536// assert.equal(instance.touch_double2, 1);
537// assert.equal(instance.touch_double3, 1);
538
539// // triple-click on the third
540// slintlib.private_api.mock_elapsed_time(1000);
541// slintlib.private_api.send_mouse_click(instance, 106., 103.);
542// assert.equal(instance.touch3, 4);
543// assert.equal(instance.touch_double3, 1);
544// slintlib.private_api.send_mouse_click(instance, 106., 103.);
545// assert.equal(instance.touch3, 5);
546// assert.equal(instance.touch_double3, 2);
547// slintlib.private_api.send_mouse_click(instance, 106., 103.);
548// assert.equal(instance.touch1, 3);
549// assert.equal(instance.touch2, 3);
550// assert.equal(instance.touch3, 6);
551// assert.equal(instance.touch_double1, 1);
552// assert.equal(instance.touch_double2, 1);
553// assert.equal(instance.touch_double3, 2);
554
555// // click really quickly on two different mouse areas
556// slintlib.private_api.mock_elapsed_time(1000);
557// instance.pointer_event_test = "";
558// slintlib.private_api.send_mouse_click(instance, 108., 108.);
559// slintlib.private_api.mock_elapsed_time(20);
560// slintlib.private_api.send_mouse_click(instance, 101., 101.);
561// assert.equal(instance.touch1, 4);
562// assert.equal(instance.touch2, 4);
563// assert.equal(instance.touch3, 6);
564// assert.equal(instance.touch_double1, 1);
565// assert.equal(instance.touch_double2, 1);
566// assert.equal(instance.touch_double3, 2);
567// assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:");
568
569// // click slowly on the same touch areas twice
570// slintlib.private_api.mock_elapsed_time(1000);
571// instance.pointer_event_test = "";
572// slintlib.private_api.send_mouse_click(instance, 101., 101.);
573// slintlib.private_api.mock_elapsed_time(1000);
574// slintlib.private_api.send_mouse_click(instance, 101., 101.);
575// assert.equal(instance.touch1, 4);
576// assert.equal(instance.touch2, 6);
577// assert.equal(instance.touch3, 6);
578// assert.equal(instance.touch_double1, 1);
579// assert.equal(instance.touch_double2, 1);
580// assert.equal(instance.touch_double3, 2);
581// assert.equal(instance.pointer_event_test, "move.other:down.left:click:up.left:move.other:move.other:down.left:click:up.left:move.other:");
582
583// slintlib.private_api.mock_elapsed_time(1000);
584// assert.equal(instance.touch1, 4);
585// assert.equal(instance.touch2, 6);
586// assert.equal(instance.touch3, 6);
587// assert.equal(instance.touch_double1, 1);
588// assert.equal(instance.touch_double2, 1);
589// assert.equal(instance.touch_double3, 2);
590```
591*/
592}
593
594#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
595 use i_slint_backend_testing as slint_testing;
596 slint_testing::init();
597 use slint::{platform::WindowEvent, LogicalPosition};
598 use slint::private_unstable_api::re_exports::MouseCursor;
599
600 let instance = TestCase::new().unwrap();
601
602 let double_click = |x, y| {
603 slint_testing::send_mouse_click(&instance, x, y);
604 slint_testing::mock_elapsed_time(50);
605 slint_testing::send_mouse_click(&instance, x, y);
606 };
607
608
609 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
610 "Unexpected mousecursor at start");
611
612 // does not click on anything
613 slint_testing::send_mouse_click(&instance, 5., 5.);
614 slint_testing::mock_elapsed_time(1000);
615 assert_eq!(instance.get_touch1(), 0, "Mis-click registered at touch1");
616 assert_eq!(instance.get_touch2(), 0, "Mis-click registered at touch2");
617 assert_eq!(instance.get_touch3(), 0, "Mis-click registered at touch3");
618 assert_eq!(instance.get_touch_double1(), 0, "Mis-click registered at touch1 as double-click");
619 assert_eq!(instance.get_touch_double2(), 0, "Mis-click registered at touch2 as double-click");
620 assert_eq!(instance.get_touch_double3(), 0, "Mis-click registered at touch3 as double-click");
621 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
622 "Mis-click changed mouse cursor");
623
624 // click on second one
625 instance.set_pointer_event_test("".into());
626 slint_testing::mock_elapsed_time(1000);
627 slint_testing::send_mouse_click(&instance, 101., 101.);
628 assert_eq!(instance.get_touch1(), 0, "Click on 2 registered at touch1");
629 assert_eq!(instance.get_touch2(), 1, "Click on 2 did not register at touch2");
630 assert_eq!(instance.get_touch3(), 0, "Click on 2 registered at touch3");
631 assert_eq!(instance.get_touch_double1(), 0, "Click on 2 registered at touch1 as double-click");
632 assert_eq!(instance.get_touch_double2(), 0, "Click on 2 registered at touch2 as double-click");
633 assert_eq!(instance.get_touch_double3(), 0, "Click on 2 registered at touch3 as double-click");
634 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer,
635 "Click on 1 did not change mouse pointer");
636
637 // click on first one only
638 slint_testing::mock_elapsed_time(1000);
639 slint_testing::send_mouse_click(&instance, 108., 108.);
640 assert_eq!(instance.get_touch1(), 1, "Click on 1 did not register at touch1");
641 assert_eq!(instance.get_touch2(), 1, "Click on 1 registered at touch2");
642 assert_eq!(instance.get_touch3(), 0, "Click on 1 registered at touch3");
643 assert_eq!(instance.get_touch_double1(), 0, "Click on 1 registered at touch1 as double-click");
644 assert_eq!(instance.get_touch_double2(), 0, "Click on 1 registered at touch2 as double-click");
645 assert_eq!(instance.get_touch_double3(), 0, "Click on 1 registered at touch3 as double-click");
646 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move,
647 "Click on 2 did not change mouse pointer");
648
649 // click on the third
650 slint_testing::mock_elapsed_time(1000);
651 slint_testing::send_mouse_click(&instance, 106., 103.);
652 assert_eq!(instance.get_touch1(), 1, "Click on 3 registered at touch1");
653 assert_eq!(instance.get_touch2(), 1, "Click on 3 registered at touch2");
654 assert_eq!(instance.get_touch3(), 1, "Click on 3 did not register at touch3");
655 assert_eq!(instance.get_touch_double1(), 0, "Click on 3 registered at touch1 as double-click");
656 assert_eq!(instance.get_touch_double2(), 0, "Click on 3 registered at touch2 as double-click");
657 assert_eq!(instance.get_touch_double3(), 0, "Click on 3 registered at touch3 as double-click");
658 assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:",
659 "Click on 3 produced an unexpected sequence of events");
660 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
661 "Click on 3 did not change mouse pointer");
662
663 // does not double-click on anything
664 slint_testing::mock_elapsed_time(1000);
665 double_click(5., 5.);
666 assert_eq!(instance.get_touch1(), 1, "Mis-double-click registered at touch1");
667 assert_eq!(instance.get_touch2(), 1, "Mis-double-click registered at touch2");
668 assert_eq!(instance.get_touch3(), 1, "Mis-double-click registered at touch3");
669 assert_eq!(instance.get_touch_double1(), 0, "Mis-double-click registered at touch1 as double-click");
670 assert_eq!(instance.get_touch_double2(), 0, "Mis-double-click registered at touch2 as double-click");
671 assert_eq!(instance.get_touch_double3(), 0, "Mis-double-click registered at touch3 as double-click");
672 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
673 "Mis-double-click on 3 did not change mouse pointer");
674
675 // double-click on second one
676 slint_testing::mock_elapsed_time(1000);
677 instance.set_pointer_event_test("".into());
678 double_click(101., 101.);
679 assert_eq!(instance.get_touch1(), 1, "Double-click on 2 registered at touch1");
680 assert_eq!(instance.get_touch2(), 3, "Double-click on 2 did not registered at touch2");
681 assert_eq!(instance.get_touch3(), 1, "Double-click on 2 registered at touch3");
682 assert_eq!(instance.get_touch_double1(), 0, "Double-click on 2 registered at touch1 as double-click");
683 assert_eq!(instance.get_touch_double2(), 1, "Double-click on 2 did not register at touch1 as double-click");
684 assert_eq!(instance.get_touch_double3(), 0, "Double-click on 2 registered at touch1 as double-click");
685 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:",
686 "Double-click on 2 produced an unexpected sequence of events");
687 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer,
688 "Double-click on 2 did not change mouse pointer");
689
690 // double-click on first one only
691 slint_testing::mock_elapsed_time(1000);
692 double_click(108., 108.);
693 assert_eq!(instance.get_touch1(), 3, "Double-click on 1 did not registered at touch1");
694 assert_eq!(instance.get_touch2(), 3, "Double-click on 1 registered at touch2");
695 assert_eq!(instance.get_touch3(), 1, "Double-click on 1 registered at touch3");
696 assert_eq!(instance.get_touch_double1(), 1, "Double-click on 1 did not register at touch1 as double-click");
697 assert_eq!(instance.get_touch_double2(), 1, "Double-click on 1 registered at touch2 as double-click");
698 assert_eq!(instance.get_touch_double3(), 0, "Double-click on 1 registered at touch3 as double-click");
699 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move,
700 "Double-click on 1 did not change mouse pointer");
701
702 // double-click on the third
703 slint_testing::mock_elapsed_time(1000);
704 double_click(106., 103.);
705 assert_eq!(instance.get_touch1(), 3, "Double-click on 3 registered at touch1");
706 assert_eq!(instance.get_touch2(), 3, "Double-click on 3 registered at touch2");
707 assert_eq!(instance.get_touch3(), 3, "Double-click on 3 did not registered at touch3");
708 assert_eq!(instance.get_touch_double1(), 1, "Double-click on 3 registered at touch1 as double-click");
709 assert_eq!(instance.get_touch_double2(), 1, "Double-click on 3 registered at touch2 as double-click");
710 assert_eq!(instance.get_touch_double3(), 1, "Double-click on 3 did not register at touch3 as double-click");
711 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
712 "Double-click on 3 did not change mouse pointer");
713
714 // triple-click on the third (treated as a double click, followed by a single click)
715 slint_testing::mock_elapsed_time(1000);
716 slint_testing::send_mouse_click(&instance, 106.0, 103.0);
717 assert_eq!(instance.get_touch1(), 3, "Triple-click (1st click) on 3 registered at touch1");
718 assert_eq!(instance.get_touch2(), 3, "Triple-click (1st click) on 3 registered at touch2");
719 assert_eq!(instance.get_touch3(), 4, "Triple-click (1st click) on 3 did not register at touch3");
720 slint_testing::send_mouse_click(&instance, 106.0, 103.0);
721 assert_eq!(instance.get_touch1(), 3, "Triple-click (2st click) on 3 registered at touch1");
722 assert_eq!(instance.get_touch2(), 3, "Triple-click (2st click) on 3 registered at touch2");
723 assert_eq!(instance.get_touch3(), 5, "Triple-click (2st click) on 3 did not register at touch3");
724 slint_testing::send_mouse_click(&instance, 106.0, 103.0);
725 assert_eq!(instance.get_touch1(), 3, "Triple-click on 3 registered at touch1");
726 assert_eq!(instance.get_touch2(), 3, "Triple-click on 3 registered at touch1");
727 assert_eq!(instance.get_touch3(), 6, "Triple-click on 3 registered at touch1");
728 assert_eq!(instance.get_touch_double1(), 1, "Triple-click on 3 registered at touch1");
729 assert_eq!(instance.get_touch_double2(), 1, "Triple-click on 3 registered at touch2");
730 assert_eq!(instance.get_touch_double3(), 2, "Triple-click on 3 did not register at touch3 as double-click");
731 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
732 "Triple-click on 3 did not change mouse pointer");
733
734 // click really quickly on two different mouse areas
735 slint_testing::mock_elapsed_time(1000);
736 instance.set_pointer_event_test("".into());
737 slint_testing::mock_elapsed_time(1000);
738 slint_testing::send_mouse_click(&instance, 101., 106.); // first
739 slint_testing::mock_elapsed_time(20);
740 slint_testing::send_mouse_click(&instance, 101., 104.); // second
741 instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) });
742 assert_eq!(instance.get_touch1(), 4, "click on different touch areas did not register on touch1");
743 assert_eq!(instance.get_touch2(), 4, "click on different touch areas did not register on touch2");
744 assert_eq!(instance.get_touch3(), 6, "click on different touch areas registered at touch3");
745 assert_eq!(instance.get_touch_double1(), 1, "click on different touch areas registered on touch1 as double-click");
746 assert_eq!(instance.get_touch_double2(), 1, "click on different touch areas registered on touch2 as double-click");
747 assert_eq!(instance.get_touch_double3(), 2, "click on different touch areas registered on touch3 as double-click");
748 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
749 "click on different touch areas changed mouse pointer");
750 assert_eq!(instance.get_pointer_event_test().as_str(), "move.other:down.left:click:up.left:move.other:",
751 "click on different touch areas produced an unexpected sequence of events");
752
753 // click slowly on the same touch areas twice
754 slint_testing::mock_elapsed_time(1000);
755 instance.set_pointer_event_test("".into());
756 slint_testing::send_mouse_click(&instance, 101., 101.); // second
757 slint_testing::mock_elapsed_time(1000);
758 slint_testing::send_mouse_click(&instance, 101., 101.); // second
759 instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(1.0, 1.0) });
760
761 assert_eq!(instance.get_touch1(), 4, "Slow double click did not register on touch1");
762 assert_eq!(instance.get_touch2(), 6, "Slow double click did not register on touch2");
763 assert_eq!(instance.get_touch3(), 6, "Slow double click did not register on touch3");
764 assert_eq!(instance.get_touch_double1(), 1, "Slow double click registered on touch1 as double-click");
765 assert_eq!(instance.get_touch_double2(), 1, "Slow double click registered on touch2 as double-click");
766 assert_eq!(instance.get_touch_double3(), 2, "Slow double click registered on touch3 as double-click");
767 assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default,
768 "click on different touch areas changed mouse pointer");
769 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:",
770 "click on different touch areas produced an unexpected sequence of events");
771
772
773 // Click on the same mouse area but using a distance which is more than the threshold
774 slint_testing::mock_elapsed_time(1000);
775 slint_testing::send_mouse_click(&instance, 109., 101.); // first
776 slint_testing::mock_elapsed_time(10);
777 slint_testing::send_mouse_click(&instance, 101., 109.); // first
778 assert_eq!(instance.get_touch1(), 6, "long distance click 1");
779 assert_eq!(instance.get_touch2(), 6, "long distance click 2");
780 assert_eq!(instance.get_touch3(), 6, "long distance click 3");
781 assert_eq!(instance.get_touch_double1(), 1, "long distance click as double click 1");
782 assert_eq!(instance.get_touch_double2(), 1, "long distance click as double click 2");
783 assert_eq!(instance.get_touch_double3(), 2, "long distance click as double click 3");
784
785
786 slint_testing::mock_elapsed_time(1000);
787 assert_eq!(instance.get_touch1(), 6, "Cool down changed touch1");
788 assert_eq!(instance.get_touch2(), 6, "Cool down changed touch2");
789 assert_eq!(instance.get_touch3(), 6, "Cool down changed touch3");
790 assert_eq!(instance.get_touch_double1(), 1, "Cool down changed touch-double1");
791 assert_eq!(instance.get_touch_double2(), 1, "Cool down changed touch-double2");
792 assert_eq!(instance.get_touch_double3(), 2, "Cool down changed touch-double3");
793 Ok(())
794}