Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions lib/web_ui/lib/src/engine/mouse_cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,46 @@ class MouseCursor {

MouseCursor._() {}

// The kind values must be kept in sync with flutter's
// rendering/mouse_cursor.dart
// Map from Flutter's kind values to CSS's cursor values.
//
// This map must be kept in sync with Flutter framework's
// rendering/mouse_cursor.dart.
static const Map<String, String> _kindToCssValueMap = <String, String>{
'none': 'none',
'alias': 'alias',
'allScroll': 'all-scroll',
'basic': 'default',
'cell': 'cell',
'click': 'pointer',
'text': 'text',
'contextMenu': 'context-menu',
'copy': 'copy',
'forbidden': 'not-allowed',
'grab': 'grab',
'grabbing': 'grabbing',
'horizontalDoubleArrow': 'ew-resize',
'verticalDoubleArrow': 'ns-resize',
'help': 'help',
'move': 'move',
'none': 'none',
'noDrop': 'no-drop',
'precise': 'crosshair',
'progress': 'progress',
'text': 'text',
'resizeColumn': 'col-resize',
'resizeDown': 's-resize',
'resizeDownLeft': 'sw-resize',
'resizeDownRight': 'se-resize',
'resizeLeft': 'w-resize',
'resizeLeftRight': 'ew-resize',
'resizeRight': 'e-resize',
'resizeRow': 'row-resize',
'resizeUp': 'n-resize',
'resizeUpDown': 'ns-resize',
'resizeUpLeft': 'nw-resize',
'resizeUpRight': 'ne-resize',
'resizeUpLeftDownRight': 'nwse-resize',
'resizeUpRightDownLeft': 'nesw-resize',
'verticalText': 'vertical-text',
'wait': 'wait',
'zoomIn': 'zoom-in',
'zoomOut': 'zoom-out',
};
static String _mapKindToCssValue(String? kind) {
return _kindToCssValueMap[kind] ?? 'default';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,40 @@ private PointerIcon resolveSystemCursor(@NonNull String kind) {
private static final long serialVersionUID = 1L;

{
put("none", Integer.valueOf(PointerIcon.TYPE_NULL));
// "basic": default
put("click", Integer.valueOf(PointerIcon.TYPE_HAND));
put("text", Integer.valueOf(PointerIcon.TYPE_TEXT));
// "forbidden": default
put("grab", Integer.valueOf(PointerIcon.TYPE_GRAB));
put("grabbing", Integer.valueOf(PointerIcon.TYPE_GRABBING));
put(
"horizontalDoubleArrow",
Integer.valueOf(PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW));
put("verticalDoubleArrow", Integer.valueOf(PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW));
put("alias", PointerIcon.TYPE_ALIAS);
put("allScroll", PointerIcon.TYPE_ALL_SCROLL);
put("basic", PointerIcon.TYPE_ARROW);
put("cell", PointerIcon.TYPE_CELL);
put("click", PointerIcon.TYPE_HAND);
put("contextMenu", PointerIcon.TYPE_CONTEXT_MENU);
put("copy", PointerIcon.TYPE_COPY);
put("forbidden", PointerIcon.TYPE_NO_DROP);
put("grab", PointerIcon.TYPE_GRAB);
put("grabbing", PointerIcon.TYPE_GRABBING);
put("help", PointerIcon.TYPE_HELP);
put("move", PointerIcon.TYPE_ALL_SCROLL);
put("none", PointerIcon.TYPE_NULL);
put("noDrop", PointerIcon.TYPE_NO_DROP);
put("precise", PointerIcon.TYPE_CROSSHAIR);
put("text", PointerIcon.TYPE_TEXT);
put("resizeColumn", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
put("resizeDown", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
put("resizeUpLeft", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
put("resizeDownRight", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
put("resizeLeft", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
put("resizeLeftRight", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
put("resizeRight", PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW);
put("resizeRow", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
put("resizeUp", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
put("resizeUpDown", PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW);
put("resizeUpLeft", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
put("resizeUpRight", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
put("resizeUpLeftDownRight", PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW);
put("resizeUpRightDownLeft", PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW);
put("verticalText", PointerIcon.TYPE_VERTICAL_TEXT);
put("wait", PointerIcon.TYPE_WAIT);
put("zoomIn", PointerIcon.TYPE_ZOOM_IN);
put("zoomOut", PointerIcon.TYPE_ZOOM_OUT);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

static NSString* const kKindValueNone = @"none";

static NSDictionary* systemCursors;

/**
* Maps a Flutter's constant to a platform's cursor object.
*
Expand All @@ -22,24 +24,36 @@
static NSCursor* GetCursorForKind(NSString* kind) {
// The following mapping must be kept in sync with Flutter framework's
// mouse_cursor.dart
if ([kind isEqualToString:@"basic"])
return [NSCursor arrowCursor];
else if ([kind isEqualToString:@"click"])
return [NSCursor pointingHandCursor];
else if ([kind isEqualToString:@"text"])
return [NSCursor IBeamCursor];
else if ([kind isEqualToString:@"forbidden"])
return [NSCursor operationNotAllowedCursor];
else if ([kind isEqualToString:@"grab"])
return [NSCursor openHandCursor];
else if ([kind isEqualToString:@"grabbing"])
return [NSCursor closedHandCursor];
else if ([kind isEqualToString:@"horizontalDoubleArrow"])
return [NSCursor resizeLeftRightCursor];
else if ([kind isEqualToString:@"verticalDoubleArrow"])
return [NSCursor resizeUpDownCursor];
else

if (systemCursors == nil) {
systemCursors = @{
@"alias" : [NSCursor dragLinkCursor],
@"basic" : [NSCursor arrowCursor],
@"click" : [NSCursor pointingHandCursor],
@"contextMenu" : [NSCursor contextualMenuCursor],
@"copy" : [NSCursor dragCopyCursor],
@"disappearing" : [NSCursor disappearingItemCursor],
@"forbidden" : [NSCursor operationNotAllowedCursor],
@"grab" : [NSCursor openHandCursor],
@"grabbing" : [NSCursor closedHandCursor],
@"noDrop" : [NSCursor operationNotAllowedCursor],
@"precise" : [NSCursor crosshairCursor],
@"text" : [NSCursor IBeamCursor],
@"resizeColumn" : [NSCursor resizeLeftRightCursor],
@"resizeDown" : [NSCursor resizeDownCursor],
@"resizeLeft" : [NSCursor resizeLeftCursor],
@"resizeLeftRight" : [NSCursor resizeLeftRightCursor],
@"resizeRight" : [NSCursor resizeRightCursor],
@"resizeRow" : [NSCursor resizeUpDownCursor],
@"resizeUp" : [NSCursor resizeUpCursor],
@"resizeUpDown" : [NSCursor resizeUpDownCursor],
@"verticalText" : [NSCursor IBeamCursorForVerticalLayout],
};
}
NSCursor* result = [systemCursors objectForKey:kind];
if (result == nil)
return [NSCursor arrowCursor];
return result;
}

@interface FlutterMouseCursorPlugin ()
Expand Down
34 changes: 31 additions & 3 deletions shell/platform/linux/fl_mouse_cursor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,41 @@ static bool define_system_cursor(GHashTable* table,
static void populate_system_cursor_table(GHashTable* table) {
// The following mapping must be kept in sync with Flutter framework's
// mouse_cursor.dart.
define_system_cursor(table, "none", "none");
define_system_cursor(table, "alias", "alias");
define_system_cursor(table, "allScroll", "all-scroll");
define_system_cursor(table, "basic", "default");
define_system_cursor(table, "cell", "cell");
define_system_cursor(table, "click", "pointer");
define_system_cursor(table, "text", "text");
define_system_cursor(table, "contextMenu", "context-menu");
define_system_cursor(table, "copy", "copy");
define_system_cursor(table, "forbidden", "not-allowed");
define_system_cursor(table, "grab", "grabbing");
define_system_cursor(table, "grab", "grab");
define_system_cursor(table, "grabbing", "grabbing");
define_system_cursor(table, "help", "help");
define_system_cursor(table, "move", "move");
define_system_cursor(table, "none", "none");
define_system_cursor(table, "noDrop", "no-drop");
define_system_cursor(table, "precise", "crosshair");
define_system_cursor(table, "progress", "progress");
define_system_cursor(table, "text", "text");
define_system_cursor(table, "resizeColumn", "col-resize");
define_system_cursor(table, "resizeDown", "s-resize");
define_system_cursor(table, "resizeDownLeft", "sw-resize");
define_system_cursor(table, "resizeDownRight", "se-resize");
define_system_cursor(table, "resizeLeft", "w-resize");
define_system_cursor(table, "resizeLeftRight", "ew-resize");
define_system_cursor(table, "resizeRight", "e-resize");
define_system_cursor(table, "resizeRow", "row-resize");
define_system_cursor(table, "resizeUp", "n-resize");
define_system_cursor(table, "resizeUpDown", "ns-resize");
define_system_cursor(table, "resizeUpLeft", "nw-resize");
define_system_cursor(table, "resizeUpRight", "ne-resize");
define_system_cursor(table, "resizeUpLeftDownRight", "nwse-resize");
define_system_cursor(table, "resizeUpRightDownLeft", "nesw-resize");
define_system_cursor(table, "verticalText", "vertical-text");
define_system_cursor(table, "wait", "wait");
define_system_cursor(table, "zoomIn", "zoom-in");
define_system_cursor(table, "zoomOut", "zoom-out");
}

// Sets the mouse cursor.
Expand Down
30 changes: 26 additions & 4 deletions shell/platform/windows/win32_flutter_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,37 @@ constexpr int kScrollOffsetMultiplier = 20;
// Maps a Flutter cursor name to an HCURSOR.
//
// Returns the arrow cursor for unknown constants.
//
// This map must be kept in sync with Flutter framework's
// rendering/mouse_cursor.dart.
static HCURSOR GetCursorByName(const std::string& cursor_name) {
static auto* cursors = new std::map<std::string, const wchar_t*>{
{"none", nullptr},
{"allScroll", IDC_SIZEALL},
{"basic", IDC_ARROW},
{"click", IDC_HAND},
{"text", IDC_IBEAM},
{"forbidden", IDC_NO},
{"horizontalDoubleArrow", IDC_SIZEWE},
{"verticalDoubleArrow", IDC_SIZENS},
{"help", IDC_HELP},
{"move", IDC_SIZEALL},
{"none", nullptr},
{"noDrop", IDC_NO},
{"precise", IDC_CROSS},
{"progress", IDC_APPSTARTING},
{"text", IDC_IBEAM},
{"resizeColumn", IDC_SIZEWE},
{"resizeDown", IDC_SIZENS},
{"resizeDownLeft", IDC_SIZENESW},
{"resizeDownRight", IDC_SIZENWSE},
{"resizeLeft", IDC_SIZEWE},
{"resizeLeftRight", IDC_SIZEWE},
{"resizeRight", IDC_SIZEWE},
{"resizeRow", IDC_SIZENS},
{"resizeUp", IDC_SIZENS},
{"resizeUpDown", IDC_SIZENS},
{"resizeUpLeft", IDC_SIZENWSE},
{"resizeUpRight", IDC_SIZENESW},
{"resizeUpLeftDownRight", IDC_SIZENWSE},
{"resizeUpRightDownLeft", IDC_SIZENESW},
{"wait", IDC_WAIT},
};
const wchar_t* idc_name = IDC_ARROW;
auto it = cursors->find(cursor_name);
Expand Down