Bug 310924 - GTK: Try named cursors before defaulting to hardcoded glyphs. r=karlt

This commit is contained in:
Phil Schaf 2014-02-19 11:30:08 -05:00
parent 2a9fd71c02
commit 25ab080eb6

View File

@ -4904,7 +4904,12 @@ get_gtk_cursor(nsCursor aCursor)
if ((gdkcursor = gCursorCache[aCursor])) {
return gdkcursor;
}
GdkDisplay *defaultDisplay = gdk_display_get_default();
// The strategy here is to use standard GDK cursors, and, if not available,
// load by standard name with gdk_cursor_new_from_name.
// Spec is here: http://www.freedesktop.org/wiki/Specifications/cursor-spec/
switch (aCursor) {
case eCursor_standard:
gdkcursor = gdk_cursor_new(GDK_LEFT_PTR);
@ -4952,25 +4957,42 @@ get_gtk_cursor(nsCursor aCursor)
gdkcursor = gdk_cursor_new(GDK_QUESTION_ARROW);
break;
case eCursor_copy: // CSS3
newType = MOZ_CURSOR_COPY;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "copy");
if (!gdkcursor)
newType = MOZ_CURSOR_COPY;
break;
case eCursor_alias:
newType = MOZ_CURSOR_ALIAS;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "alias");
if (!gdkcursor)
newType = MOZ_CURSOR_ALIAS;
break;
case eCursor_context_menu:
newType = MOZ_CURSOR_CONTEXT_MENU;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "context-menu");
if (!gdkcursor)
newType = MOZ_CURSOR_CONTEXT_MENU;
break;
case eCursor_cell:
gdkcursor = gdk_cursor_new(GDK_PLUS);
break;
// Those two arent standardized. Trying both KDEs and GNOMEs names
case eCursor_grab:
newType = MOZ_CURSOR_HAND_GRAB;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "openhand");
if (!gdkcursor)
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "hand1");
if (!gdkcursor)
newType = MOZ_CURSOR_HAND_GRAB;
break;
case eCursor_grabbing:
newType = MOZ_CURSOR_HAND_GRABBING;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "closedhand");
if (!gdkcursor)
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "grabbing");
if (!gdkcursor)
newType = MOZ_CURSOR_HAND_GRABBING;
break;
case eCursor_spinning:
newType = MOZ_CURSOR_SPINNING;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "progress");
if (!gdkcursor)
newType = MOZ_CURSOR_SPINNING;
break;
case eCursor_zoom_in:
newType = MOZ_CURSOR_ZOOM_IN;
@ -4979,8 +5001,20 @@ get_gtk_cursor(nsCursor aCursor)
newType = MOZ_CURSOR_ZOOM_OUT;
break;
case eCursor_not_allowed:
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "not-allowed");
if (!gdkcursor) // nonstandard, yet common
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "crossed_circle");
if (!gdkcursor)
newType = MOZ_CURSOR_NOT_ALLOWED;
break;
case eCursor_no_drop:
newType = MOZ_CURSOR_NOT_ALLOWED;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "no-drop");
if (!gdkcursor) // this nonstandard sequence makes it work on KDE and GNOME
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "forbidden");
if (!gdkcursor)
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "circle");
if (!gdkcursor)
newType = MOZ_CURSOR_NOT_ALLOWED;
break;
case eCursor_vertical_text:
newType = MOZ_CURSOR_VERTICAL_TEXT;
@ -4989,19 +5023,32 @@ get_gtk_cursor(nsCursor aCursor)
gdkcursor = gdk_cursor_new(GDK_FLEUR);
break;
case eCursor_nesw_resize:
newType = MOZ_CURSOR_NESW_RESIZE;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "size_bdiag");
if (!gdkcursor)
newType = MOZ_CURSOR_NESW_RESIZE;
break;
case eCursor_nwse_resize:
newType = MOZ_CURSOR_NWSE_RESIZE;
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "size_fdiag");
if (!gdkcursor)
newType = MOZ_CURSOR_NWSE_RESIZE;
break;
case eCursor_ns_resize:
case eCursor_row_resize:
gdkcursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
break;
case eCursor_ew_resize:
case eCursor_col_resize:
gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
break;
// Here, two better fitting cursors exist in some cursor themes. Try those first
case eCursor_row_resize:
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "split_v");
if (!gdkcursor)
gdkcursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
break;
case eCursor_col_resize:
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, "split_h");
if (!gdkcursor)
gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
break;
case eCursor_none:
newType = MOZ_CURSOR_NONE;
break;
@ -5016,8 +5063,7 @@ get_gtk_cursor(nsCursor aCursor)
// custom bitmap, as libXcursor has some magic to convert bitmapped cursors
// to themed cursors
if (newType != 0xFF && GtkCursors[newType].hash) {
gdkcursor = gdk_cursor_new_from_name(gdk_display_get_default(),
GtkCursors[newType].hash);
gdkcursor = gdk_cursor_new_from_name(defaultDisplay, GtkCursors[newType].hash);
}
// If we still don't have a xcursor, we now really create a bitmap cursor