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 | |
5 | export component TestCase { |
6 | in-out property <int> touch1; |
7 | in-out property <int> touch2; |
8 | in-out property <int> touch3; |
9 | |
10 | in-out property <string> pointer-event-test; |
11 | |
12 | TouchArea { |
13 | x: 100phx; |
14 | y: 100phx; |
15 | width: 10phx; |
16 | height: 10phx; |
17 | clicked => { touch1+=1; } |
18 | mouse-cursor: move; |
19 | TouchArea { |
20 | y: 2phx; |
21 | height: 2phx; |
22 | x: 3phx; |
23 | width: 4phx; |
24 | clicked => { touch3+=1; } |
25 | mouse-cursor: default; |
26 | } |
27 | } |
28 | TouchArea { |
29 | x: 100phx; |
30 | y: 100phx; |
31 | width: 5phx; |
32 | height: 5phx; |
33 | mouse-cursor: pointer; |
34 | clicked => { |
35 | pointer-event-test += "click" ; |
36 | touch2+=1; |
37 | } |
38 | pointer-event(e) => { |
39 | if (e.kind == PointerEventKind.cancel) { |
40 | pointer-event-test += "cancel" ; |
41 | } else if (e.kind == PointerEventKind.up) { |
42 | pointer-event-test += "up" ; |
43 | } else if (e.kind == PointerEventKind.down) { |
44 | pointer-event-test += "down" ; |
45 | } else if (e.kind == PointerEventKind.move) { |
46 | pointer-event-test += "move" ; |
47 | } else { |
48 | pointer-event-test += "err" ; |
49 | } |
50 | if (e.button == PointerEventButton.right) { |
51 | pointer-event-test += "right" ; |
52 | } else if (e.button == PointerEventButton.left) { |
53 | pointer-event-test += "left" ; |
54 | } else if (e.button == PointerEventButton.middle) { |
55 | pointer-event-test += "middle" ; |
56 | } else if (e.button == PointerEventButton.other) { |
57 | pointer-event-test += "other" ; |
58 | } else { |
59 | pointer-event-test += "???" ; |
60 | } |
61 | if (e.modifiers.control) { |
62 | pointer-event-test += "(ctrl)" ; |
63 | } |
64 | if (e.modifiers.shift) { |
65 | pointer-event-test += "(shift)" ; |
66 | } |
67 | if (e.modifiers.meta) { |
68 | pointer-event-test += "(meta)" ; |
69 | } |
70 | if (e.modifiers.alt) { |
71 | pointer-event-test += "(alt)" ; |
72 | } |
73 | } |
74 | } |
75 | } |
76 | |
77 | /* |
78 | ```cpp |
79 | using slint::PointerEventButton; |
80 | |
81 | auto handle = TestCase::create(); |
82 | const TestCase &instance = *handle; |
83 | |
84 | // does not click on anything |
85 | slint_testing::send_mouse_click(&instance, 5., 5.); |
86 | assert_eq(instance.get_touch1(), 0); |
87 | assert_eq(instance.get_touch2(), 0); |
88 | assert_eq(instance.get_touch3(), 0); |
89 | |
90 | // click on second one |
91 | slint_testing::send_mouse_click(&instance, 101., 101.); |
92 | assert_eq(instance.get_touch1(), 0); |
93 | assert_eq(instance.get_touch2(), 1); |
94 | assert_eq(instance.get_touch3(), 0); |
95 | |
96 | // click on first one only |
97 | slint_testing::send_mouse_click(&instance, 108., 108.); |
98 | assert_eq(instance.get_touch1(), 1); |
99 | assert_eq(instance.get_touch2(), 1); |
100 | assert_eq(instance.get_touch3(), 0); |
101 | |
102 | // click on the third |
103 | slint_testing::send_mouse_click(&instance, 106., 103.); |
104 | assert_eq(instance.get_touch1(), 1); |
105 | assert_eq(instance.get_touch2(), 1); |
106 | assert_eq(instance.get_touch3(), 1); |
107 | |
108 | // The final moveother is added by the grab handler! |
109 | assert_eq(instance.get_pointer_event_test(), "moveotherdownleftclickupleftmoveother"); |
110 | |
111 | instance.set_pointer_event_test(""); |
112 | // issue #2918: press anywhere, release on a toucharea |
113 | instance.window().dispatch_pointer_press_event(slint::LogicalPosition({70.0, 6.0}), PointerEventButton::Left); |
114 | instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 102.0, 103.0 })); |
115 | instance.window().dispatch_pointer_release_event(slint::LogicalPosition({101.0, 104.0}), PointerEventButton::Left); |
116 | assert_eq(instance.get_pointer_event_test(), "moveotherupleft"); // no "clicked" |
117 | assert_eq(instance.get_touch1(), 1); |
118 | assert_eq(instance.get_touch2(), 1); |
119 | assert_eq(instance.get_touch3(), 1); |
120 | ``` |
121 | |
122 | ```rust |
123 | use slint::{platform::WindowEvent, platform::PointerEventButton, platform::Key, LogicalPosition}; |
124 | use slint::private_unstable_api::re_exports::MouseCursor; |
125 | |
126 | let instance = TestCase::new().unwrap(); |
127 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
128 | |
129 | // does not click on anything |
130 | slint_testing::send_mouse_click(&instance, 5., 5.); |
131 | assert_eq!(instance.get_touch1(), 0); |
132 | assert_eq!(instance.get_touch2(), 0); |
133 | assert_eq!(instance.get_touch3(), 0); |
134 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
135 | |
136 | // click on second one |
137 | slint_testing::send_mouse_click(&instance, 101., 101.); |
138 | assert_eq!(instance.get_touch1(), 0); |
139 | assert_eq!(instance.get_touch2(), 1); |
140 | assert_eq!(instance.get_touch3(), 0); |
141 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer); |
142 | |
143 | // click on first one only |
144 | slint_testing::send_mouse_click(&instance, 108., 108.); |
145 | assert_eq!(instance.get_touch1(), 1); |
146 | assert_eq!(instance.get_touch2(), 1); |
147 | assert_eq!(instance.get_touch3(), 0); |
148 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move); |
149 | |
150 | // click on the third |
151 | slint_testing::send_mouse_click(&instance, 106., 103.); |
152 | assert_eq!(instance.get_touch1(), 1); |
153 | assert_eq!(instance.get_touch2(), 1); |
154 | assert_eq!(instance.get_touch3(), 1); |
155 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
156 | |
157 | // The final moveother is added by the grab handler! |
158 | assert_eq!(instance.get_pointer_event_test().as_str(), "moveotherdownleftclickupleftmoveother"); |
159 | |
160 | instance.set_pointer_event_test("".into()); |
161 | // issue #2918: press anywhere, release on a toucharea |
162 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
163 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(102.0, 103.0) }); |
164 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
165 | assert_eq!(instance.get_pointer_event_test().as_str(), "moveotherupleft"); // no "clicked" |
166 | assert_eq!(instance.get_touch1(), 1); |
167 | assert_eq!(instance.get_touch2(), 1); |
168 | assert_eq!(instance.get_touch3(), 1); |
169 | |
170 | instance.set_pointer_event_test("".into()); |
171 | slint_testing::send_keyboard_char(&instance, Key::Control.into(), true); |
172 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
173 | slint_testing::send_keyboard_char(&instance, Key::Control.into(), false); |
174 | slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true); |
175 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
176 | assert_eq!(instance.get_pointer_event_test().as_str(), "downleft(ctrl)clickupleft(shift)moveother(shift)"); |
177 | ``` |
178 | |
179 | ```js |
180 | var instance = new slint.TestCase(); |
181 | // does not click on anything |
182 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
183 | assert.equal(instance.touch1, 0); |
184 | assert.equal(instance.touch2, 0); |
185 | assert.equal(instance.touch3, 0); |
186 | |
187 | // click on second one |
188 | slintlib.private_api.send_mouse_click(instance, 101., 101.); |
189 | assert.equal(instance.touch1, 0); |
190 | assert.equal(instance.touch2, 1); |
191 | assert.equal(instance.touch3, 0); |
192 | |
193 | // click on first one only |
194 | slintlib.private_api.send_mouse_click(instance, 108., 108.); |
195 | assert.equal(instance.touch1, 1); |
196 | assert.equal(instance.touch2, 1); |
197 | assert.equal(instance.touch3, 0); |
198 | |
199 | // click on the third |
200 | slintlib.private_api.send_mouse_click(instance, 106., 103.); |
201 | assert.equal(instance.touch1, 1); |
202 | assert.equal(instance.touch2, 1); |
203 | assert.equal(instance.touch3, 1); |
204 | |
205 | assert.equal(instance.pointer_event_test, "moveotherdownleftclickupleftmoveother"); |
206 | ``` |
207 | */ |
208 | } |
209 | |
210 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
211 | use i_slint_backend_testing as slint_testing; |
212 | slint_testing::init(); |
213 | use slint::{platform::WindowEvent, platform::PointerEventButton, platform::Key, LogicalPosition}; |
214 | use slint::private_unstable_api::re_exports::MouseCursor; |
215 | |
216 | let instance = TestCase::new().unwrap(); |
217 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
218 | |
219 | // does not click on anything |
220 | slint_testing::send_mouse_click(&instance, 5., 5.); |
221 | assert_eq!(instance.get_touch1(), 0); |
222 | assert_eq!(instance.get_touch2(), 0); |
223 | assert_eq!(instance.get_touch3(), 0); |
224 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
225 | |
226 | // click on second one |
227 | slint_testing::send_mouse_click(&instance, 101., 101.); |
228 | assert_eq!(instance.get_touch1(), 0); |
229 | assert_eq!(instance.get_touch2(), 1); |
230 | assert_eq!(instance.get_touch3(), 0); |
231 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Pointer); |
232 | |
233 | // click on first one only |
234 | slint_testing::send_mouse_click(&instance, 108., 108.); |
235 | assert_eq!(instance.get_touch1(), 1); |
236 | assert_eq!(instance.get_touch2(), 1); |
237 | assert_eq!(instance.get_touch3(), 0); |
238 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Move); |
239 | |
240 | // click on the third |
241 | slint_testing::send_mouse_click(&instance, 106., 103.); |
242 | assert_eq!(instance.get_touch1(), 1); |
243 | assert_eq!(instance.get_touch2(), 1); |
244 | assert_eq!(instance.get_touch3(), 1); |
245 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default); |
246 | |
247 | // The final moveother is added by the grab handler! |
248 | assert_eq!(instance.get_pointer_event_test().as_str(), "moveotherdownleftclickupleftmoveother" ); |
249 | |
250 | instance.set_pointer_event_test("" .into()); |
251 | // issue #2918: press anywhere, release on a toucharea |
252 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(70.0, 6.0), button: PointerEventButton::Left }); |
253 | instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(102.0, 103.0) }); |
254 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
255 | assert_eq!(instance.get_pointer_event_test().as_str(), "moveotherupleft" ); // no "clicked" |
256 | assert_eq!(instance.get_touch1(), 1); |
257 | assert_eq!(instance.get_touch2(), 1); |
258 | assert_eq!(instance.get_touch3(), 1); |
259 | |
260 | instance.set_pointer_event_test("" .into()); |
261 | slint_testing::send_keyboard_char(&instance, Key::Control.into(), true); |
262 | instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
263 | slint_testing::send_keyboard_char(&instance, Key::Control.into(), false); |
264 | slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true); |
265 | instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 104.0), button: PointerEventButton::Left }); |
266 | assert_eq!(instance.get_pointer_event_test().as_str(), "downleft(ctrl)clickupleft(shift)moveother(shift)" ); |
267 | Ok(()) |
268 | } |