Unverified Commit 72df4801 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Land Set "basic" mouse cursor for disabled buttons, PR #89346 (#96561)

parent c24b2c3c
...@@ -255,7 +255,7 @@ class ElevatedButton extends ButtonStyleButton { ...@@ -255,7 +255,7 @@ class ElevatedButton extends ButtonStyleButton {
/// * `side` - null /// * `side` - null
/// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
/// * `mouseCursor` /// * `mouseCursor`
/// * disabled - SystemMouseCursors.forbidden /// * disabled - SystemMouseCursors.basic
/// * others - SystemMouseCursors.click /// * others - SystemMouseCursors.click
/// * `visualDensity` - theme.visualDensity /// * `visualDensity` - theme.visualDensity
/// * `tapTargetSize` - theme.materialTapTargetSize /// * `tapTargetSize` - theme.materialTapTargetSize
...@@ -300,7 +300,7 @@ class ElevatedButton extends ButtonStyleButton { ...@@ -300,7 +300,7 @@ class ElevatedButton extends ButtonStyleButton {
maximumSize: Size.infinite, maximumSize: Size.infinite,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
enabledMouseCursor: SystemMouseCursors.click, enabledMouseCursor: SystemMouseCursors.click,
disabledMouseCursor: SystemMouseCursors.forbidden, disabledMouseCursor: SystemMouseCursors.basic,
visualDensity: theme.visualDensity, visualDensity: theme.visualDensity,
tapTargetSize: theme.materialTapTargetSize, tapTargetSize: theme.materialTapTargetSize,
animationDuration: kThemeChangeDuration, animationDuration: kThemeChangeDuration,
......
...@@ -256,7 +256,7 @@ class IconButton extends StatelessWidget { ...@@ -256,7 +256,7 @@ class IconButton extends StatelessWidget {
/// {@macro flutter.material.RawMaterialButton.mouseCursor} /// {@macro flutter.material.RawMaterialButton.mouseCursor}
/// ///
/// If set to null, will default to /// If set to null, will default to
/// - [SystemMouseCursors.forbidden], if [onPressed] is null /// - [SystemMouseCursors.basic], if [onPressed] is null
/// - [SystemMouseCursors.click], otherwise /// - [SystemMouseCursors.click], otherwise
final MouseCursor? mouseCursor; final MouseCursor? mouseCursor;
...@@ -357,7 +357,7 @@ class IconButton extends StatelessWidget { ...@@ -357,7 +357,7 @@ class IconButton extends StatelessWidget {
autofocus: autofocus, autofocus: autofocus,
canRequestFocus: onPressed != null, canRequestFocus: onPressed != null,
onTap: onPressed, onTap: onPressed,
mouseCursor: mouseCursor ?? (onPressed == null ? SystemMouseCursors.forbidden : SystemMouseCursors.click), mouseCursor: mouseCursor ?? (onPressed == null ? SystemMouseCursors.basic : SystemMouseCursors.click),
enableFeedback: enableFeedback, enableFeedback: enableFeedback,
focusColor: focusColor ?? theme.focusColor, focusColor: focusColor ?? theme.focusColor,
hoverColor: hoverColor ?? theme.hoverColor, hoverColor: hoverColor ?? theme.hoverColor,
......
...@@ -240,7 +240,7 @@ class OutlinedButton extends ButtonStyleButton { ...@@ -240,7 +240,7 @@ class OutlinedButton extends ButtonStyleButton {
/// * `side` - BorderSide(width: 1, color: Theme.colorScheme.onSurface(0.12)) /// * `side` - BorderSide(width: 1, color: Theme.colorScheme.onSurface(0.12))
/// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
/// * `mouseCursor` /// * `mouseCursor`
/// * disabled - SystemMouseCursors.forbidden /// * disabled - SystemMouseCursors.basic
/// * others - SystemMouseCursors.click /// * others - SystemMouseCursors.click
/// * `visualDensity` - theme.visualDensity /// * `visualDensity` - theme.visualDensity
/// * `tapTargetSize` - theme.materialTapTargetSize /// * `tapTargetSize` - theme.materialTapTargetSize
...@@ -275,7 +275,7 @@ class OutlinedButton extends ButtonStyleButton { ...@@ -275,7 +275,7 @@ class OutlinedButton extends ButtonStyleButton {
), ),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
enabledMouseCursor: SystemMouseCursors.click, enabledMouseCursor: SystemMouseCursors.click,
disabledMouseCursor: SystemMouseCursors.forbidden, disabledMouseCursor: SystemMouseCursors.basic,
visualDensity: theme.visualDensity, visualDensity: theme.visualDensity,
tapTargetSize: theme.materialTapTargetSize, tapTargetSize: theme.materialTapTargetSize,
animationDuration: kThemeChangeDuration, animationDuration: kThemeChangeDuration,
......
...@@ -244,7 +244,7 @@ class TextButton extends ButtonStyleButton { ...@@ -244,7 +244,7 @@ class TextButton extends ButtonStyleButton {
/// * `side` - null /// * `side` - null
/// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)) /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
/// * `mouseCursor` /// * `mouseCursor`
/// * disabled - SystemMouseCursors.forbidden /// * disabled - SystemMouseCursors.basic
/// * others - SystemMouseCursors.click /// * others - SystemMouseCursors.click
/// * `visualDensity` - theme.visualDensity /// * `visualDensity` - theme.visualDensity
/// * `tapTargetSize` - theme.materialTapTargetSize /// * `tapTargetSize` - theme.materialTapTargetSize
...@@ -288,7 +288,7 @@ class TextButton extends ButtonStyleButton { ...@@ -288,7 +288,7 @@ class TextButton extends ButtonStyleButton {
maximumSize: Size.infinite, maximumSize: Size.infinite,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
enabledMouseCursor: SystemMouseCursors.click, enabledMouseCursor: SystemMouseCursors.click,
disabledMouseCursor: SystemMouseCursors.forbidden, disabledMouseCursor: SystemMouseCursors.basic,
visualDensity: theme.visualDensity, visualDensity: theme.visualDensity,
tapTargetSize: theme.materialTapTargetSize, tapTargetSize: theme.materialTapTargetSize,
animationDuration: kThemeChangeDuration, animationDuration: kThemeChangeDuration,
......
...@@ -1418,6 +1418,85 @@ void main() { ...@@ -1418,6 +1418,85 @@ void main() {
expect(tester.getSize(find.widgetWithText(ElevatedButton, '200x200')), const Size(200, 200)); expect(tester.getSize(find.widgetWithText(ElevatedButton, '200x200')), const Size(200, 200));
expect(tester.getSize(find.widgetWithText(ElevatedButton, '200,200')), const Size(200, 200)); expect(tester.getSize(find.widgetWithText(ElevatedButton, '200,200')), const Size(200, 200));
}); });
testWidgets('ElevatedButton changes mouse cursor when hovered', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: () {},
child: const Text('button'),
),
),
),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: Offset.zero);
addTearDown(gesture.removePointer);
await tester.pump();
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
// Test cursor when disabled
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: null,
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
// Test default cursor
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ElevatedButton(
onPressed: () {},
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test default cursor when disabled
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: ElevatedButton(
onPressed: null,
child: Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
});
} }
TextStyle _iconStyle(WidgetTester tester, IconData icon) { TextStyle _iconStyle(WidgetTester tester, IconData icon) {
......
...@@ -793,7 +793,7 @@ void main() { ...@@ -793,7 +793,7 @@ void main() {
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
}); });
testWidgets('disabled IconButton has forbidden mouse cursor', (WidgetTester tester) async { testWidgets('disabled IconButton has basic mouse cursor', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Material( const Material(
child: Directionality( child: Directionality(
...@@ -814,7 +814,7 @@ void main() { ...@@ -814,7 +814,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.forbidden); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
}); });
testWidgets('IconButton.mouseCursor overrides implicit setting of mouse cursor', (WidgetTester tester) async { testWidgets('IconButton.mouseCursor overrides implicit setting of mouse cursor', (WidgetTester tester) async {
......
...@@ -1593,6 +1593,85 @@ void main() { ...@@ -1593,6 +1593,85 @@ void main() {
expect(tester.getSize(find.widgetWithText(OutlinedButton, '200x200')), const Size(200, 200)); expect(tester.getSize(find.widgetWithText(OutlinedButton, '200x200')), const Size(200, 200));
expect(tester.getSize(find.widgetWithText(OutlinedButton, '200,200')), const Size(200, 200)); expect(tester.getSize(find.widgetWithText(OutlinedButton, '200,200')), const Size(200, 200));
}); });
testWidgets('OutlinedButton changes mouse cursor when hovered', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: () {},
child: const Text('button'),
),
),
),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: Offset.zero);
addTearDown(gesture.removePointer);
await tester.pump();
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
// Test cursor when disabled
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: null,
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
// Test default cursor
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: OutlinedButton(
onPressed: () {},
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test default cursor when disabled
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: OutlinedButton(
onPressed: null,
child: Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
});
} }
PhysicalModelLayer _findPhysicalLayer(Element element) { PhysicalModelLayer _findPhysicalLayer(Element element) {
......
...@@ -1391,6 +1391,84 @@ void main() { ...@@ -1391,6 +1391,84 @@ void main() {
expect(tester.getSize(find.widgetWithText(TextButton, '200,200')), const Size(200, 200)); expect(tester.getSize(find.widgetWithText(TextButton, '200,200')), const Size(200, 200));
}); });
testWidgets('TextButton changes mouse cursor when hovered', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextButton(
style: TextButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: () {},
child: const Text('button'),
),
),
),
);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: Offset.zero);
addTearDown(gesture.removePointer);
await tester.pump();
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
// Test cursor when disabled
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextButton(
style: TextButton.styleFrom(
enabledMouseCursor: SystemMouseCursors.text,
disabledMouseCursor: SystemMouseCursors.grab,
),
onPressed: null,
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
// Test default cursor
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextButton(
onPressed: () {},
child: const Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test default cursor when disabled
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextButton(
onPressed: null,
child: Text('button'),
),
),
),
);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
});
} }
TextStyle? _iconStyle(WidgetTester tester, IconData icon) { TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
......
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