Unverified Commit 1aada6fc authored by xubaolin's avatar xubaolin Committed by GitHub

[New Feature]Support mouse wheel event on the scrollbar widget (#109659)

* rebase master and add a test

* fix the test

* fix the test

* fix the test
parent 96f9ca83
...@@ -1200,25 +1200,32 @@ void main() { ...@@ -1200,25 +1200,32 @@ void main() {
pointer.hover(const Offset(793.0, 15.0)); pointer.hover(const Offset(793.0, 15.0));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar and still hovered over
// the scrollbar should not have changed the scroll offset. if (!kIsWeb) {
expect(pointer.location, const Offset(793.0, 15.0)); // Scrolling while holding the drag on the scrollbar and still hovered over
expect(scrollController.offset, previousOffset); // the scrollbar should not have changed the scroll offset.
expect( expect(pointer.location, const Offset(793.0, 15.0));
find.byType(CupertinoScrollbar), expect(scrollController.offset, previousOffset);
paints..rrect( expect(
rrect: RRect.fromRectAndRadius( find.byType(CupertinoScrollbar),
const Rect.fromLTRB(789.0, 13.0, 797.0, 102.1), paints..rrect(
const Radius.circular(4.0), rrect: RRect.fromRectAndRadius(
const Rect.fromLTRB(789.0, 13.0, 797.0, 102.1),
const Radius.circular(4.0),
),
color: _kScrollbarColor.color,
), ),
color: _kScrollbarColor.color, );
), } else {
); expect(pointer.location, const Offset(793.0, 15.0));
expect(scrollController.offset, previousOffset + 20.0);
}
// Drag is still being held, move pointer to be hovering over another area // Drag is still being held, move pointer to be hovering over another area
// of the scrollable (not over the scrollbar) and execute another pointer scroll // of the scrollable (not over the scrollbar) and execute another pointer scroll
pointer.hover(tester.getCenter(find.byType(SingleChildScrollView))); pointer.hover(tester.getCenter(find.byType(SingleChildScrollView)));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -70.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -90.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar changed the offset // Scrolling while holding the drag on the scrollbar changed the offset
expect(pointer.location, const Offset(400.0, 300.0)); expect(pointer.location, const Offset(400.0, 300.0));
......
...@@ -1634,33 +1634,39 @@ void main() { ...@@ -1634,33 +1634,39 @@ void main() {
pointer.hover(const Offset(798.0, 15.0)); pointer.hover(const Offset(798.0, 15.0));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar and still hovered over
// the scrollbar should not have changed the scroll offset. if (!kIsWeb) {
expect(pointer.location, const Offset(798.0, 15.0)); // Scrolling while holding the drag on the scrollbar and still hovered over
expect(scrollController.offset, previousOffset); // the scrollbar should not have changed the scroll offset.
expect( expect(pointer.location, const Offset(798.0, 15.0));
find.byType(Scrollbar), expect(scrollController.offset, previousOffset);
paints expect(
..rect( find.byType(Scrollbar),
rect: const Rect.fromLTRB(796.0, 0.0, 800.0, 600.0), paints
color: Colors.transparent, ..rect(
) rect: const Rect.fromLTRB(796.0, 0.0, 800.0, 600.0),
..line( color: Colors.transparent,
p1: const Offset(796.0, 0.0), )
p2: const Offset(796.0, 600.0), ..line(
strokeWidth: 1.0, p1: const Offset(796.0, 0.0),
color: Colors.transparent, p2: const Offset(796.0, 600.0),
) strokeWidth: 1.0,
..rect( color: Colors.transparent,
rect: const Rect.fromLTRB(796.0, 10.0, 800.0, 100.0), )
color: const Color(0x99000000), ..rect(
), rect: const Rect.fromLTRB(796.0, 10.0, 800.0, 100.0),
); color: const Color(0x99000000),
),
);
} else {
expect(pointer.location, const Offset(798.0, 15.0));
expect(scrollController.offset, previousOffset + 20.0);
}
// Drag is still being held, move pointer to be hovering over another area // Drag is still being held, move pointer to be hovering over another area
// of the scrollable (not over the scrollbar) and execute another pointer scroll // of the scrollable (not over the scrollbar) and execute another pointer scroll
pointer.hover(tester.getCenter(find.byType(SingleChildScrollView))); pointer.hover(tester.getCenter(find.byType(SingleChildScrollView)));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -70.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -90.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar changed the offset // Scrolling while holding the drag on the scrollbar changed the offset
expect(pointer.location, const Offset(400.0, 300.0)); expect(pointer.location, const Offset(400.0, 300.0));
......
...@@ -1607,33 +1607,39 @@ void main() { ...@@ -1607,33 +1607,39 @@ void main() {
pointer.hover(const Offset(798.0, 15.0)); pointer.hover(const Offset(798.0, 15.0));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 20.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar and still hovered over
// the scrollbar should not have changed the scroll offset. if (!kIsWeb) {
expect(pointer.location, const Offset(798.0, 15.0)); // Scrolling while holding the drag on the scrollbar and still hovered over
expect(scrollController.offset, previousOffset); // the scrollbar should not have changed the scroll offset.
expect( expect(pointer.location, const Offset(798.0, 15.0));
find.byType(RawScrollbar), expect(scrollController.offset, previousOffset);
paints expect(
..rect( find.byType(RawScrollbar),
rect: const Rect.fromLTRB(794.0, 0.0, 800.0, 600.0), paints
color: const Color(0x00000000), ..rect(
) rect: const Rect.fromLTRB(794.0, 0.0, 800.0, 600.0),
..line( color: const Color(0x00000000),
p1: const Offset(794.0, 0.0), )
p2: const Offset(794.0, 600.0), ..line(
strokeWidth: 1.0, p1: const Offset(794.0, 0.0),
color: const Color(0x00000000), p2: const Offset(794.0, 600.0),
) strokeWidth: 1.0,
..rect( color: const Color(0x00000000),
rect: const Rect.fromLTRB(794.0, 10.0, 800.0, 100.0), )
color: const Color(0x66bcbcbc), ..rect(
), rect: const Rect.fromLTRB(794.0, 10.0, 800.0, 100.0),
); color: const Color(0x66bcbcbc),
),
);
} else {
expect(pointer.location, const Offset(798.0, 15.0));
expect(scrollController.offset, previousOffset + 20.0);
}
// Drag is still being held, move pointer to be hovering over another area // Drag is still being held, move pointer to be hovering over another area
// of the scrollable (not over the scrollbar) and execute another pointer scroll // of the scrollable (not over the scrollbar) and execute another pointer scroll
pointer.hover(tester.getCenter(find.byType(SingleChildScrollView))); pointer.hover(tester.getCenter(find.byType(SingleChildScrollView)));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -70.0))); await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, -90.0)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// Scrolling while holding the drag on the scrollbar changed the offset // Scrolling while holding the drag on the scrollbar changed the offset
expect(pointer.location, const Offset(400.0, 300.0)); expect(pointer.location, const Offset(400.0, 300.0));
...@@ -2788,4 +2794,50 @@ void main() { ...@@ -2788,4 +2794,50 @@ void main() {
), ),
); );
}); });
testWidgets('The bar support mouse wheel event', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/pull/109659
final ScrollController scrollController = ScrollController();
Widget buildFrame() {
return Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: PrimaryScrollController(
controller: scrollController,
child: RawScrollbar(
thumbVisibility: true,
controller: scrollController,
child: const SingleChildScrollView(
primary: true,
child: SizedBox(
width: double.infinity,
height: 1200.0,
),
),
),
),
),
);
}
await tester.pumpWidget(buildFrame());
await tester.pumpAndSettle();
expect(scrollController.offset, 0.0);
// Execute a pointer scroll hover on the scroll bar
final TestPointer pointer = TestPointer(1, ui.PointerDeviceKind.mouse);
pointer.hover(const Offset(798.0, 15.0));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 30.0)));
await tester.pumpAndSettle();
expect(scrollController.offset, 30.0);
// Execute a pointer scroll outside the scroll bar
pointer.hover(const Offset(198.0, 15.0));
await tester.sendEventToBinding(pointer.scroll(const Offset(0.0, 70.0)));
await tester.pumpAndSettle();
expect(scrollController.offset, 100.0);
}, variant: TargetPlatformVariant.all());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment