summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webcursor_gtk.cc
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 00:55:28 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 00:55:28 +0000
commitf0b6b4881e24a1e7cd9524c4e381382c14bde1f1 (patch)
treea003cdb87339224ae24f3dd39f8d3fc9a8f1c8fc /webkit/glue/webcursor_gtk.cc
parent1edd9e76f6dac6bcdbdebf51eceb7b6665fe52fa (diff)
downloadchromium_src-f0b6b4881e24a1e7cd9524c4e381382c14bde1f1.zip
chromium_src-f0b6b4881e24a1e7cd9524c4e381382c14bde1f1.tar.gz
chromium_src-f0b6b4881e24a1e7cd9524c4e381382c14bde1f1.tar.bz2
Refactoring of cursor usage (primarily for linux).
Add API to WebCursor to return a native-cursor, and implementation for windows, linux and mac. For linux: Move gtk_util::GetCursor into gfx:: namespace. Also, get rid of ref/unref'ing the cursors from everywhere. Instead, do almost all of it in one place (in gfx). Also, show proper cursors for web-pages with touchui=1 (i.e. add support for updating cursor in RenderWidgetHostViewViews). Review URL: http://codereview.chromium.org/5110010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67034 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webcursor_gtk.cc')
-rw-r--r--webkit/glue/webcursor_gtk.cc33
1 files changed, 28 insertions, 5 deletions
diff --git a/webkit/glue/webcursor_gtk.cc b/webkit/glue/webcursor_gtk.cc
index 6734ef2..1ff8316 100644
--- a/webkit/glue/webcursor_gtk.cc
+++ b/webkit/glue/webcursor_gtk.cc
@@ -22,9 +22,12 @@ namespace {
// It attempts to create a custom cursor from the data inlined in
// webcursor_gtk_data.h.
GdkCursor* GetInlineCustomCursor(CustomCursorType type) {
+ static GdkCursor* CustomCursorsGdk[G_N_ELEMENTS(CustomCursors)];
+ GdkCursor* cursor = CustomCursorsGdk[type];
+ if (cursor)
+ return cursor;
const CustomCursor& custom = CustomCursors[type];
- GdkCursor* cursor = gdk_cursor_new_from_name(gdk_display_get_default(),
- custom.name);
+ cursor = gdk_cursor_new_from_name(gdk_display_get_default(), custom.name);
if (!cursor) {
const GdkColor fg = { 0, 0, 0, 0 };
const GdkColor bg = { 65535, 65535, 65535, 65535 };
@@ -37,6 +40,7 @@ GdkCursor* GetInlineCustomCursor(CustomCursorType type) {
g_object_unref(source);
g_object_unref(mask);
}
+ CustomCursorsGdk[type] = cursor;
return cursor;
}
@@ -45,11 +49,13 @@ GdkCursor* GetInlineCustomCursor(CustomCursorType type) {
#if !GTK_CHECK_VERSION(2, 16, 0)
// Get/create a custom cursor which is invisible.
GdkCursor* GetInvisibleCustomCursor() {
+ static GdkCursor* cursor = NULL;
+ if (cursor)
+ return cursor;
const char bits[] = { 0 };
const GdkColor color = { 0, 0, 0, 0 };
GdkPixmap* bitmap = gdk_bitmap_create_from_data(NULL, bits, 1, 1);
- GdkCursor* cursor =
- gdk_cursor_new_from_pixmap(bitmap, bitmap, &color, &color, 0, 0);
+ cursor = gdk_cursor_new_from_pixmap(bitmap, bitmap, &color, &color, 0, 0);
g_object_unref(bitmap);
return cursor;
}
@@ -154,7 +160,14 @@ int WebCursor::GetCursorType() const {
return GDK_LAST_CURSOR;
}
-GdkCursor* WebCursor::GetCustomCursor() const {
+gfx::NativeCursor WebCursor::GetNativeCursor() {
+ int type = GetCursorType();
+ if (type == GDK_CURSOR_IS_PIXMAP)
+ return GetCustomCursor();
+ return gfx::GetCursor(type);
+}
+
+GdkCursor* WebCursor::GetCustomCursor() {
switch (type_) {
// See comment above |GetInvisibleCustomCursor()|.
#if !GTK_CHECK_VERSION(2, 16, 0)
@@ -186,10 +199,14 @@ GdkCursor* WebCursor::GetCustomCursor() const {
gdk_pixbuf_unref(pixbuf);
+ if (unref_)
+ gdk_cursor_unref(unref_);
+ unref_ = cursor;
return cursor;
}
void WebCursor::InitPlatformData() {
+ unref_ = NULL;
return;
}
@@ -206,9 +223,15 @@ bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
}
void WebCursor::CleanupPlatformData() {
+ if (unref_) {
+ gdk_cursor_unref(unref_);
+ unref_ = NULL;
+ }
return;
}
void WebCursor::CopyPlatformData(const WebCursor& other) {
+ if (other.unref_)
+ unref_ = gdk_cursor_ref(other.unref_);
return;
}