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