diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 00:55:28 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 00:55:28 +0000 |
commit | f0b6b4881e24a1e7cd9524c4e381382c14bde1f1 (patch) | |
tree | a003cdb87339224ae24f3dd39f8d3fc9a8f1c8fc /webkit/glue | |
parent | 1edd9e76f6dac6bcdbdebf51eceb7b6665fe52fa (diff) | |
download | chromium_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')
-rw-r--r-- | webkit/glue/webcursor.h | 11 | ||||
-rw-r--r-- | webkit/glue/webcursor_gtk.cc | 33 | ||||
-rw-r--r-- | webkit/glue/webcursor_mac.mm | 4 | ||||
-rw-r--r-- | webkit/glue/webcursor_win.cc | 4 |
4 files changed, 46 insertions, 6 deletions
diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h index 35eb001..daad15f 100644 --- a/webkit/glue/webcursor.h +++ b/webkit/glue/webcursor.h @@ -6,6 +6,7 @@ #define WEBKIT_GLUE_WEBCURSOR_H_ #include "base/basictypes.h" +#include "gfx/native_widget_types.h" #include "gfx/point.h" #include "gfx/size.h" @@ -65,6 +66,9 @@ class WebCursor { // compare the bitmaps to verify whether they are equal. bool IsEqual(const WebCursor& other) const; + // Returns a native cursor representing the current WebCursor instance. + gfx::NativeCursor GetNativeCursor(); + #if defined(OS_WIN) // Returns a HCURSOR representing the current WebCursor instance. // The ownership of the HCURSOR (does not apply to external cursors) remains @@ -85,7 +89,7 @@ class WebCursor { // Return a new GdkCursor* for this cursor. Only valid if GetCursorType // returns GDK_CURSOR_IS_PIXMAP. - GdkCursor* GetCustomCursor() const; + GdkCursor* GetCustomCursor(); #elif defined(OS_MACOSX) // Gets an NSCursor* for this cursor. NSCursor* GetCursor() const; @@ -147,6 +151,11 @@ class WebCursor { // A custom cursor created from custom bitmap data by Webkit. HCURSOR custom_cursor_; #endif // OS_WIN + +#if defined(USE_X11) + // A custom cursor created that should be unref'ed from the destructor. + GdkCursor* unref_; +#endif }; #endif // WEBKIT_GLUE_WEBCURSOR_H_ 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; } diff --git a/webkit/glue/webcursor_mac.mm b/webkit/glue/webcursor_mac.mm index 6b2729e..1aeb1e0 100644 --- a/webkit/glue/webcursor_mac.mm +++ b/webkit/glue/webcursor_mac.mm @@ -160,6 +160,10 @@ NSCursor* WebCursor::GetCursor() const { return nil; } +gfx::NativeCursor WebCursor::GetNativeCursor() { + return GetCursor(); +} + void WebCursor::InitFromThemeCursor(ThemeCursor cursor) { WebKit::WebCursorInfo cursor_info; diff --git a/webkit/glue/webcursor_win.cc b/webkit/glue/webcursor_win.cc index 4435e06..2141969 100644 --- a/webkit/glue/webcursor_win.cc +++ b/webkit/glue/webcursor_win.cc @@ -186,6 +186,10 @@ HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ return custom_cursor_; } +gfx::NativeCursor WebCursor::GetNativeCursor() { + return GetCursor(NULL); +} + void WebCursor::InitFromExternalCursor(HCURSOR cursor) { WebCursorInfo::Type cursor_type = ToCursorType(cursor); |