Unverified Commit 0bda6335 authored by Tong Mu's avatar Tong Mu Committed by GitHub

InkWell uses MaterialStateMouseCursor and defaults to clickable (#58448)

* Adds support for material state mouse cursor to InkWell and InkResponse
* Set their default cursors to be MaterialStateMouseCursor.clickable.
parent 145d70c1
...@@ -13,6 +13,7 @@ import 'debug.dart'; ...@@ -13,6 +13,7 @@ import 'debug.dart';
import 'feedback.dart'; import 'feedback.dart';
import 'ink_highlight.dart'; import 'ink_highlight.dart';
import 'material.dart'; import 'material.dart';
import 'material_state.dart';
import 'theme.dart'; import 'theme.dart';
/// An ink feature that displays a [color] "splash" in response to a user /// An ink feature that displays a [color] "splash" in response to a user
...@@ -296,7 +297,7 @@ class InkResponse extends StatelessWidget { ...@@ -296,7 +297,7 @@ class InkResponse extends StatelessWidget {
this.onLongPress, this.onLongPress,
this.onHighlightChanged, this.onHighlightChanged,
this.onHover, this.onHover,
this.mouseCursor = MouseCursor.defer, this.mouseCursor,
this.containedInkWell = false, this.containedInkWell = false,
this.highlightShape = BoxShape.circle, this.highlightShape = BoxShape.circle,
this.radius, this.radius,
...@@ -313,8 +314,7 @@ class InkResponse extends StatelessWidget { ...@@ -313,8 +314,7 @@ class InkResponse extends StatelessWidget {
this.canRequestFocus = true, this.canRequestFocus = true,
this.onFocusChange, this.onFocusChange,
this.autofocus = false, this.autofocus = false,
}) : assert(mouseCursor != null), }) : assert(containedInkWell != null),
assert(containedInkWell != null),
assert(highlightShape != null), assert(highlightShape != null),
assert(enableFeedback != null), assert(enableFeedback != null),
assert(excludeFromSemantics != null), assert(excludeFromSemantics != null),
...@@ -367,8 +367,17 @@ class InkResponse extends StatelessWidget { ...@@ -367,8 +367,17 @@ class InkResponse extends StatelessWidget {
/// The cursor for a mouse pointer when it enters or is hovering over the /// The cursor for a mouse pointer when it enters or is hovering over the
/// widget. /// widget.
/// ///
/// The [cursor] defaults to [MouseCursor.defer], deferring the choice of /// If [mouseCursor] is a [MaterialStateProperty<MouseCursor>],
/// cursor to the next region behing it in hit-test order. /// [MaterialStateProperty.resolve] is used for the following [MaterialState]s:
///
/// * [MaterialState.hovered].
/// * [MaterialState.focused].
/// * [MaterialState.disabled].
///
/// When [value] is null and [tristate] is true, [MaterialState.selected] is
/// included as a state.
///
/// If this property is null, [MaterialStateMouseCursor.clickable] will be used.
final MouseCursor mouseCursor; final MouseCursor mouseCursor;
/// Whether this ink response should be clipped its bounds. /// Whether this ink response should be clipped its bounds.
...@@ -601,7 +610,7 @@ class _InkResponseStateWidget extends StatefulWidget { ...@@ -601,7 +610,7 @@ class _InkResponseStateWidget extends StatefulWidget {
this.onLongPress, this.onLongPress,
this.onHighlightChanged, this.onHighlightChanged,
this.onHover, this.onHover,
this.mouseCursor = MouseCursor.defer, this.mouseCursor,
this.containedInkWell = false, this.containedInkWell = false,
this.highlightShape = BoxShape.circle, this.highlightShape = BoxShape.circle,
this.radius, this.radius,
...@@ -626,8 +635,7 @@ class _InkResponseStateWidget extends StatefulWidget { ...@@ -626,8 +635,7 @@ class _InkResponseStateWidget extends StatefulWidget {
assert(enableFeedback != null), assert(enableFeedback != null),
assert(excludeFromSemantics != null), assert(excludeFromSemantics != null),
assert(autofocus != null), assert(autofocus != null),
assert(canRequestFocus != null), assert(canRequestFocus != null);
assert(mouseCursor != null);
final Widget child; final Widget child;
final GestureTapCallback onTap; final GestureTapCallback onTap;
...@@ -672,7 +680,7 @@ class _InkResponseStateWidget extends StatefulWidget { ...@@ -672,7 +680,7 @@ class _InkResponseStateWidget extends StatefulWidget {
if (onTapCancel != null) 'tap cancel', if (onTapCancel != null) 'tap cancel',
]; ];
properties.add(IterableProperty<String>('gestures', gestures, ifEmpty: '<none>')); properties.add(IterableProperty<String>('gestures', gestures, ifEmpty: '<none>'));
properties.add(DiagnosticsProperty<MouseCursor>('mouseCursor', mouseCursor, defaultValue: MouseCursor.defer)); properties.add(DiagnosticsProperty<MouseCursor>('mouseCursor', mouseCursor));
properties.add(DiagnosticsProperty<bool>('containedInkWell', containedInkWell, level: DiagnosticLevel.fine)); properties.add(DiagnosticsProperty<bool>('containedInkWell', containedInkWell, level: DiagnosticLevel.fine));
properties.add(DiagnosticsProperty<BoxShape>( properties.add(DiagnosticsProperty<BoxShape>(
'highlightShape', 'highlightShape',
...@@ -1025,6 +1033,14 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -1025,6 +1033,14 @@ class _InkResponseState extends State<_InkResponseStateWidget>
_highlights[type]?.color = getHighlightColorForType(type); _highlights[type]?.color = getHighlightColorForType(type);
} }
_currentSplash?.color = widget.splashColor ?? Theme.of(context).splashColor; _currentSplash?.color = widget.splashColor ?? Theme.of(context).splashColor;
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
widget.mouseCursor ?? MaterialStateMouseCursor.clickable,
<MaterialState>{
if (!enabled) MaterialState.disabled,
if (_hovering) MaterialState.hovered,
if (_hasFocus) MaterialState.focused,
},
);
return _ParentInkResponseProvider( return _ParentInkResponseProvider(
state: this, state: this,
child: Actions( child: Actions(
...@@ -1035,7 +1051,7 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -1035,7 +1051,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
onFocusChange: _handleFocusUpdate, onFocusChange: _handleFocusUpdate,
autofocus: widget.autofocus, autofocus: widget.autofocus,
child: MouseRegion( child: MouseRegion(
cursor: widget.mouseCursor, cursor: effectiveMouseCursor,
onEnter: enabled ? _handleMouseEnter : null, onEnter: enabled ? _handleMouseEnter : null,
onExit: enabled ? _handleMouseExit : null, onExit: enabled ? _handleMouseExit : null,
child: GestureDetector( child: GestureDetector(
...@@ -1160,7 +1176,7 @@ class InkWell extends InkResponse { ...@@ -1160,7 +1176,7 @@ class InkWell extends InkResponse {
GestureTapCancelCallback onTapCancel, GestureTapCancelCallback onTapCancel,
ValueChanged<bool> onHighlightChanged, ValueChanged<bool> onHighlightChanged,
ValueChanged<bool> onHover, ValueChanged<bool> onHover,
MouseCursor mouseCursor = MouseCursor.defer, MouseCursor mouseCursor,
Color focusColor, Color focusColor,
Color hoverColor, Color hoverColor,
Color highlightColor, Color highlightColor,
......
...@@ -227,7 +227,22 @@ void main() { ...@@ -227,7 +227,22 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.forbidden); expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test disabled
await tester.pumpWidget(
const Material(
child: Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: InkWell(),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
// Test default of InkResponse() // Test default of InkResponse()
await tester.pumpWidget( await tester.pumpWidget(
...@@ -244,7 +259,22 @@ void main() { ...@@ -244,7 +259,22 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.forbidden); expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
// Test disabled
await tester.pumpWidget(
const Material(
child: Directionality(
textDirection: TextDirection.ltr,
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: InkResponse(),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
}); });
group('feedback', () { group('feedback', () {
......
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