Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fbef051

Browse files
authored
Add all system cursors (engine) (#19550)
* Support all system cursors in WIn, Linux, mac, Web and Android.
1 parent 97f6c81 commit fbef051

5 files changed

Lines changed: 156 additions & 41 deletions

File tree

lib/web_ui/lib/src/engine/mouse_cursor.dart

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,46 @@ class MouseCursor {
2020

2121
MouseCursor._() {}
2222

23-
// The kind values must be kept in sync with flutter's
24-
// rendering/mouse_cursor.dart
23+
// Map from Flutter's kind values to CSS's cursor values.
24+
//
25+
// This map must be kept in sync with Flutter framework's
26+
// rendering/mouse_cursor.dart.
2527
static const Map<String, String> _kindToCssValueMap = <String, String>{
26-
'none': 'none',
28+
'alias': 'alias',
29+
'allScroll': 'all-scroll',
2730
'basic': 'default',
31+
'cell': 'cell',
2832
'click': 'pointer',
29-
'text': 'text',
33+
'contextMenu': 'context-menu',
34+
'copy': 'copy',
3035
'forbidden': 'not-allowed',
3136
'grab': 'grab',
3237
'grabbing': 'grabbing',
33-
'horizontalDoubleArrow': 'ew-resize',
34-
'verticalDoubleArrow': 'ns-resize',
38+
'help': 'help',
39+
'move': 'move',
40+
'none': 'none',
41+
'noDrop': 'no-drop',
42+
'precise': 'crosshair',
43+
'progress': 'progress',
44+
'text': 'text',
45+
'resizeColumn': 'col-resize',
46+
'resizeDown': 's-resize',
47+
'resizeDownLeft': 'sw-resize',
48+
'resizeDownRight': 'se-resize',
49+
'resizeLeft': 'w-resize',
50+
'resizeLeftRight': 'ew-resize',
51+
'resizeRight': 'e-resize',
52+
'resizeRow': 'row-resize',
53+
'resizeUp': 'n-resize',
54+
'resizeUpDown': 'ns-resize',
55+
'resizeUpLeft': 'nw-resize',
56+
'resizeUpRight': 'ne-resize',
57+
'resizeUpLeftDownRight': 'nwse-resize',
58+
'resizeUpRightDownLeft': 'nesw-resize',
59+
'verticalText': 'vertical-text',
60+
'wait': 'wait',
61+
'zoomIn': 'zoom-in',
62+
'zoomOut': 'zoom-out',
3563
};
3664
static String _mapKindToCssValue(String? kind) {
3765
return _kindToCssValueMap[kind] ?? 'default';

shell/platform/android/io/flutter/plugin/mouse/MouseCursorPlugin.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,40 @@ private PointerIcon resolveSystemCursor(@NonNull String kind) {
4747
private static final long serialVersionUID = 1L;
4848

4949
{
50-
put("none", Integer.valueOf(PointerIcon.TYPE_NULL));
51-
// "basic": default
52-
put("click", Integer.valueOf(PointerIcon.TYPE_HAND));
53-
put("text", Integer.valueOf(PointerIcon.TYPE_TEXT));
54-
// "forbidden": default
55-
put("grab", Integer.valueOf(PointerIcon.TYPE_GRAB));
56-
put("grabbing", Integer.valueOf(PointerIcon.TYPE_GRABBING));
57-
put(
58-
"horizontalDoubleArrow",
59-
Integer.valueOf(PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW));
60-
put("verticalDoubleArrow", Integer.valueOf(PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW));
50+
put("alias", PointerIcon.TYPE_ALIAS);
51+
put("allScroll", PointerIcon.TYPE_ALL_SCROLL);
52+
put("basic", PointerIcon.TYPE_ARROW);
53+
put("cell", PointerIcon.TYPE_CELL);
54+
put("click", PointerIcon.TYPE_HAND);
55+
put("contextMenu", PointerIcon.TYPE_CONTEXT_MENU);
56+
put("copy", PointerIcon.TYPE_COPY);
57+
put("forbidden", PointerIcon.TYPE_NO_DROP);
58+
put("grab", PointerIcon.TYPE_GRAB);
59+
put("grabbing", PointerIcon.TYPE_GRABBING);
60+
put("help", PointerIcon.TYPE_HELP);
61+
put("move", PointerIcon.TYPE_ALL_SCROLL);
62+
put("none", PointerIcon.TYPE_NULL);
63+
put("noDrop", PointerIcon.TYPE_NO_DROP);
64+
put("precise", PointerIcon.TYPE_CROSSHAIR);
65+
put("text", PointerIcon.TYPE_TEXT);
66+
put("resizeColumn", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
67+
put("resizeDown", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
68+
put("resizeUpLeft", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
69+
put("resizeDownRight", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
70+
put("resizeLeft", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
71+
put("resizeLeftRight", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
72+
put("resizeRight", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
73+
put("resizeRow", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
74+
put("resizeUp", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
75+
put("resizeUpDown", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
76+
put("resizeUpLeft", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
77+
put("resizeUpRight", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
78+
put("resizeUpLeftDownRight", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
79+
put("resizeUpRightDownLeft", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
80+
put("verticalText", PointerIcon.TYPE_VERTICAL_TEXT);
81+
put("wait", PointerIcon.TYPE_WAIT);
82+
put("zoomIn", PointerIcon.TYPE_ZOOM_IN);
83+
put("zoomOut", PointerIcon.TYPE_ZOOM_OUT);
6184
}
6285
};
6386
}

shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
static NSString* const kKindValueNone = @"none";
1616

17+
static NSDictionary* systemCursors;
18+
1719
/**
1820
* Maps a Flutter's constant to a platform's cursor object.
1921
*
@@ -22,24 +24,36 @@
2224
static NSCursor* GetCursorForKind(NSString* kind) {
2325
// The following mapping must be kept in sync with Flutter framework's
2426
// mouse_cursor.dart
25-
if ([kind isEqualToString:@"basic"])
26-
return [NSCursor arrowCursor];
27-
else if ([kind isEqualToString:@"click"])
28-
return [NSCursor pointingHandCursor];
29-
else if ([kind isEqualToString:@"text"])
30-
return [NSCursor IBeamCursor];
31-
else if ([kind isEqualToString:@"forbidden"])
32-
return [NSCursor operationNotAllowedCursor];
33-
else if ([kind isEqualToString:@"grab"])
34-
return [NSCursor openHandCursor];
35-
else if ([kind isEqualToString:@"grabbing"])
36-
return [NSCursor closedHandCursor];
37-
else if ([kind isEqualToString:@"horizontalDoubleArrow"])
38-
return [NSCursor resizeLeftRightCursor];
39-
else if ([kind isEqualToString:@"verticalDoubleArrow"])
40-
return [NSCursor resizeUpDownCursor];
41-
else
27+
28+
if (systemCursors == nil) {
29+
systemCursors = @{
30+
@"alias" : [NSCursor dragLinkCursor],
31+
@"basic" : [NSCursor arrowCursor],
32+
@"click" : [NSCursor pointingHandCursor],
33+
@"contextMenu" : [NSCursor contextualMenuCursor],
34+
@"copy" : [NSCursor dragCopyCursor],
35+
@"disappearing" : [NSCursor disappearingItemCursor],
36+
@"forbidden" : [NSCursor operationNotAllowedCursor],
37+
@"grab" : [NSCursor openHandCursor],
38+
@"grabbing" : [NSCursor closedHandCursor],
39+
@"noDrop" : [NSCursor operationNotAllowedCursor],
40+
@"precise" : [NSCursor crosshairCursor],
41+
@"text" : [NSCursor IBeamCursor],
42+
@"resizeColumn" : [NSCursor resizeLeftRightCursor],
43+
@"resizeDown" : [NSCursor resizeDownCursor],
44+
@"resizeLeft" : [NSCursor resizeLeftCursor],
45+
@"resizeLeftRight" : [NSCursor resizeLeftRightCursor],
46+
@"resizeRight" : [NSCursor resizeRightCursor],
47+
@"resizeRow" : [NSCursor resizeUpDownCursor],
48+
@"resizeUp" : [NSCursor resizeUpCursor],
49+
@"resizeUpDown" : [NSCursor resizeUpDownCursor],
50+
@"verticalText" : [NSCursor IBeamCursorForVerticalLayout],
51+
};
52+
}
53+
NSCursor* result = [systemCursors objectForKey:kind];
54+
if (result == nil)
4255
return [NSCursor arrowCursor];
56+
return result;
4357
}
4458

4559
@interface FlutterMouseCursorPlugin ()

shell/platform/linux/fl_mouse_cursor_plugin.cc

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,41 @@ static bool define_system_cursor(GHashTable* table,
4646
static void populate_system_cursor_table(GHashTable* table) {
4747
// The following mapping must be kept in sync with Flutter framework's
4848
// mouse_cursor.dart.
49-
define_system_cursor(table, "none", "none");
49+
define_system_cursor(table, "alias", "alias");
50+
define_system_cursor(table, "allScroll", "all-scroll");
51+
define_system_cursor(table, "basic", "default");
52+
define_system_cursor(table, "cell", "cell");
5053
define_system_cursor(table, "click", "pointer");
51-
define_system_cursor(table, "text", "text");
54+
define_system_cursor(table, "contextMenu", "context-menu");
55+
define_system_cursor(table, "copy", "copy");
5256
define_system_cursor(table, "forbidden", "not-allowed");
53-
define_system_cursor(table, "grab", "grabbing");
57+
define_system_cursor(table, "grab", "grab");
58+
define_system_cursor(table, "grabbing", "grabbing");
59+
define_system_cursor(table, "help", "help");
60+
define_system_cursor(table, "move", "move");
61+
define_system_cursor(table, "none", "none");
62+
define_system_cursor(table, "noDrop", "no-drop");
63+
define_system_cursor(table, "precise", "crosshair");
64+
define_system_cursor(table, "progress", "progress");
65+
define_system_cursor(table, "text", "text");
66+
define_system_cursor(table, "resizeColumn", "col-resize");
67+
define_system_cursor(table, "resizeDown", "s-resize");
68+
define_system_cursor(table, "resizeDownLeft", "sw-resize");
69+
define_system_cursor(table, "resizeDownRight", "se-resize");
70+
define_system_cursor(table, "resizeLeft", "w-resize");
5471
define_system_cursor(table, "resizeLeftRight", "ew-resize");
72+
define_system_cursor(table, "resizeRight", "e-resize");
73+
define_system_cursor(table, "resizeRow", "row-resize");
74+
define_system_cursor(table, "resizeUp", "n-resize");
5575
define_system_cursor(table, "resizeUpDown", "ns-resize");
76+
define_system_cursor(table, "resizeUpLeft", "nw-resize");
77+
define_system_cursor(table, "resizeUpRight", "ne-resize");
78+
define_system_cursor(table, "resizeUpLeftDownRight", "nwse-resize");
79+
define_system_cursor(table, "resizeUpRightDownLeft", "nesw-resize");
80+
define_system_cursor(table, "verticalText", "vertical-text");
81+
define_system_cursor(table, "wait", "wait");
82+
define_system_cursor(table, "zoomIn", "zoom-in");
83+
define_system_cursor(table, "zoomOut", "zoom-out");
5684
}
5785

5886
// Sets the mouse cursor.

shell/platform/windows/win32_flutter_window.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,37 @@ constexpr int kScrollOffsetMultiplier = 20;
1818
// Maps a Flutter cursor name to an HCURSOR.
1919
//
2020
// Returns the arrow cursor for unknown constants.
21+
//
22+
// This map must be kept in sync with Flutter framework's
23+
// rendering/mouse_cursor.dart.
2124
static HCURSOR GetCursorByName(const std::string& cursor_name) {
2225
static auto* cursors = new std::map<std::string, const wchar_t*>{
23-
{"none", nullptr},
26+
{"allScroll", IDC_SIZEALL},
2427
{"basic", IDC_ARROW},
2528
{"click", IDC_HAND},
26-
{"text", IDC_IBEAM},
2729
{"forbidden", IDC_NO},
28-
{"horizontalDoubleArrow", IDC_SIZEWE},
29-
{"verticalDoubleArrow", IDC_SIZENS},
30+
{"help", IDC_HELP},
31+
{"move", IDC_SIZEALL},
32+
{"none", nullptr},
33+
{"noDrop", IDC_NO},
34+
{"precise", IDC_CROSS},
35+
{"progress", IDC_APPSTARTING},
36+
{"text", IDC_IBEAM},
37+
{"resizeColumn", IDC_SIZEWE},
38+
{"resizeDown", IDC_SIZENS},
39+
{"resizeDownLeft", IDC_SIZENESW},
40+
{"resizeDownRight", IDC_SIZENWSE},
41+
{"resizeLeft", IDC_SIZEWE},
42+
{"resizeLeftRight", IDC_SIZEWE},
43+
{"resizeRight", IDC_SIZEWE},
44+
{"resizeRow", IDC_SIZENS},
45+
{"resizeUp", IDC_SIZENS},
46+
{"resizeUpDown", IDC_SIZENS},
47+
{"resizeUpLeft", IDC_SIZENWSE},
48+
{"resizeUpRight", IDC_SIZENESW},
49+
{"resizeUpLeftDownRight", IDC_SIZENWSE},
50+
{"resizeUpRightDownLeft", IDC_SIZENESW},
51+
{"wait", IDC_WAIT},
3052
};
3153
const wchar_t* idc_name = IDC_ARROW;
3254
auto it = cursors->find(cursor_name);

0 commit comments

Comments
 (0)