|
6 | 6 | library;
|
7 | 7 |
|
8 | 8 | import 'dart:async';
|
| 9 | +import 'dart:ui' show PointerDeviceKind; |
9 | 10 | import 'dart:ui_web' as ui_web;
|
10 | 11 |
|
| 12 | +import 'package:flutter/material.dart'; |
11 | 13 | import 'package:flutter/rendering.dart';
|
12 | 14 | import 'package:flutter/services.dart';
|
13 |
| -import 'package:flutter/widgets.dart'; |
14 | 15 | import 'package:flutter_test/flutter_test.dart';
|
15 | 16 | import 'package:web/web.dart' as web;
|
16 | 17 |
|
@@ -44,6 +45,17 @@ void main() {
|
44 | 45 | return web.document.createElement(params['tagName']! as String);
|
45 | 46 | },
|
46 | 47 | );
|
| 48 | + fakePlatformViewRegistry.registerViewFactory('Browser__WebContextMenuViewType__', ( |
| 49 | + int viewId, { |
| 50 | + Object? params, |
| 51 | + }) { |
| 52 | + final web.HTMLElement htmlElement = web.document.createElement('div') as web.HTMLElement; |
| 53 | + htmlElement |
| 54 | + ..style.width = '100%' |
| 55 | + ..style.height = '100%' |
| 56 | + ..classList.add('web-selectable-region-context-menu'); |
| 57 | + return htmlElement; |
| 58 | + }); |
47 | 59 | });
|
48 | 60 |
|
49 | 61 | group('HtmlElementView', () {
|
@@ -417,4 +429,81 @@ void main() {
|
417 | 429 | });
|
418 | 430 | });
|
419 | 431 | });
|
| 432 | + |
| 433 | + // Regression test for https://github.com/flutter/flutter/issues/174246 |
| 434 | + // There is a control case for non-Web in selection_area_test.dart. |
| 435 | + testWidgets('SelectionArea applies correct mouse cursors in its empty region on Web', ( |
| 436 | + WidgetTester tester, |
| 437 | + ) async { |
| 438 | + final GlobalKey innerRegion = GlobalKey(); |
| 439 | + await tester.pumpWidget( |
| 440 | + MaterialApp( |
| 441 | + debugShowCheckedModeBanner: false, |
| 442 | + home: Scaffold( |
| 443 | + // Region 1 (fullscreen) |
| 444 | + body: MouseRegion( |
| 445 | + cursor: SystemMouseCursors.grab, |
| 446 | + child: Center( |
| 447 | + child: Container( |
| 448 | + decoration: BoxDecoration(border: Border.all()), |
| 449 | + // Region 2 (SelectionArea) |
| 450 | + child: SelectionArea( |
| 451 | + child: Padding( |
| 452 | + padding: const EdgeInsetsGeometry.all(40), |
| 453 | + // Region 3 (inner MouseRegion) |
| 454 | + child: MouseRegion( |
| 455 | + key: innerRegion, |
| 456 | + cursor: SystemMouseCursors.forbidden, |
| 457 | + onHover: (_) {}, |
| 458 | + child: Container(color: const Color(0xFFAA9933), width: 200, height: 50), |
| 459 | + ), |
| 460 | + ), |
| 461 | + ), |
| 462 | + ), |
| 463 | + ), |
| 464 | + ), |
| 465 | + ), |
| 466 | + ), |
| 467 | + ); |
| 468 | + |
| 469 | + // Initialize the HtmlElementView inside SelectionArea. |
| 470 | + await tester.pump(); |
| 471 | + |
| 472 | + // Ensure that the HtmlElementView is initialized. |
| 473 | + expect( |
| 474 | + find.byWidgetPredicate( |
| 475 | + (Widget widget) => widget.toString().contains('_PlatformViewPlaceHolder'), |
| 476 | + ), |
| 477 | + findsNothing, |
| 478 | + ); |
| 479 | + |
| 480 | + const Offset region1 = Offset(10, 10); |
| 481 | + final Offset region2 = tester.getTopLeft(find.byKey(innerRegion)) - const Offset(3, 3); |
| 482 | + final Offset region3 = tester.getCenter(find.byKey(innerRegion)); |
| 483 | + |
| 484 | + final TestGesture gesture = await tester.startGesture(region1, kind: PointerDeviceKind.mouse); |
| 485 | + addTearDown(gesture.removePointer); |
| 486 | + expect( |
| 487 | + RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), |
| 488 | + SystemMouseCursors.grab, |
| 489 | + ); |
| 490 | + |
| 491 | + await gesture.moveTo(region2); |
| 492 | + expect( |
| 493 | + RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), |
| 494 | + SystemMouseCursors.grab, |
| 495 | + ); |
| 496 | + |
| 497 | + await gesture.moveTo(region3); |
| 498 | + expect( |
| 499 | + RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), |
| 500 | + SystemMouseCursors.forbidden, |
| 501 | + ); |
| 502 | + |
| 503 | + await gesture.moveTo(region2); |
| 504 | + expect( |
| 505 | + RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), |
| 506 | + SystemMouseCursors.grab, |
| 507 | + ); |
| 508 | + }); |
420 | 509 | }
|
0 commit comments