| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/webcursor.h" | 5 #include "webkit/glue/webcursor.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 32, 32); | 37 32, 32); |
| 38 cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, | 38 cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, |
| 39 custom.hot_x, custom.hot_y); | 39 custom.hot_x, custom.hot_y); |
| 40 g_object_unref(source); | 40 g_object_unref(source); |
| 41 g_object_unref(mask); | 41 g_object_unref(mask); |
| 42 } | 42 } |
| 43 CustomCursorsGdk[type] = cursor; | 43 CustomCursorsGdk[type] = cursor; |
| 44 return cursor; | 44 return cursor; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // For GTK 2.16 and beyond, GDK_BLANK_CURSOR is available. Before, we have to | |
| 48 // use a custom cursor. | |
| 49 #if !GTK_CHECK_VERSION(2, 16, 0) | |
| 50 // Get/create a custom cursor which is invisible. | |
| 51 GdkCursor* GetInvisibleCustomCursor() { | |
| 52 static GdkCursor* cursor = NULL; | |
| 53 if (cursor) | |
| 54 return cursor; | |
| 55 const char bits[] = { 0 }; | |
| 56 const GdkColor color = { 0, 0, 0, 0 }; | |
| 57 GdkPixmap* bitmap = gdk_bitmap_create_from_data(NULL, bits, 1, 1); | |
| 58 cursor = gdk_cursor_new_from_pixmap(bitmap, bitmap, &color, &color, 0, 0); | |
| 59 g_object_unref(bitmap); | |
| 60 return cursor; | |
| 61 } | |
| 62 #endif | |
| 63 | |
| 64 } // end anonymous namespace | 47 } // end anonymous namespace |
| 65 | 48 |
| 66 int WebCursor::GetCursorType() const { | 49 int WebCursor::GetCursorType() const { |
| 67 // http://library.gnome.org/devel/gdk/2.12/gdk-Cursors.html has images | 50 // http://library.gnome.org/devel/gdk/2.12/gdk-Cursors.html has images |
| 68 // of the default X theme, but beware that the user's cursor theme can | 51 // of the default X theme, but beware that the user's cursor theme can |
| 69 // change everything. | 52 // change everything. |
| 70 switch (type_) { | 53 switch (type_) { |
| 71 case WebCursorInfo::TypePointer: | 54 case WebCursorInfo::TypePointer: |
| 72 return GDK_LAST_CURSOR; | 55 return GDK_LAST_CURSOR; |
| 73 case WebCursorInfo::TypeCross: | 56 case WebCursorInfo::TypeCross: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; | 119 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; |
| 137 case WebCursorInfo::TypeAlias: | 120 case WebCursorInfo::TypeAlias: |
| 138 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; | 121 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; |
| 139 case WebCursorInfo::TypeProgress: | 122 case WebCursorInfo::TypeProgress: |
| 140 return GDK_WATCH; | 123 return GDK_WATCH; |
| 141 case WebCursorInfo::TypeNoDrop: | 124 case WebCursorInfo::TypeNoDrop: |
| 142 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; | 125 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; |
| 143 case WebCursorInfo::TypeCopy: | 126 case WebCursorInfo::TypeCopy: |
| 144 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; | 127 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; |
| 145 case WebCursorInfo::TypeNone: | 128 case WebCursorInfo::TypeNone: |
| 146 // See comment above |GetInvisibleCustomCursor()|. | |
| 147 #if !GTK_CHECK_VERSION(2, 16, 0) | |
| 148 return GDK_CURSOR_IS_PIXMAP; | |
| 149 #else | |
| 150 return GDK_BLANK_CURSOR; | 129 return GDK_BLANK_CURSOR; |
| 151 #endif | |
| 152 case WebCursorInfo::TypeNotAllowed: | 130 case WebCursorInfo::TypeNotAllowed: |
| 153 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; | 131 NOTIMPLEMENTED(); return GDK_LAST_CURSOR; |
| 154 case WebCursorInfo::TypeZoomIn: | 132 case WebCursorInfo::TypeZoomIn: |
| 155 case WebCursorInfo::TypeZoomOut: | 133 case WebCursorInfo::TypeZoomOut: |
| 156 case WebCursorInfo::TypeGrab: | 134 case WebCursorInfo::TypeGrab: |
| 157 case WebCursorInfo::TypeGrabbing: | 135 case WebCursorInfo::TypeGrabbing: |
| 158 case WebCursorInfo::TypeCustom: | 136 case WebCursorInfo::TypeCustom: |
| 159 return GDK_CURSOR_IS_PIXMAP; | 137 return GDK_CURSOR_IS_PIXMAP; |
| 160 } | 138 } |
| 161 NOTREACHED(); | 139 NOTREACHED(); |
| 162 return GDK_LAST_CURSOR; | 140 return GDK_LAST_CURSOR; |
| 163 } | 141 } |
| 164 | 142 |
| 165 gfx::NativeCursor WebCursor::GetNativeCursor() { | 143 gfx::NativeCursor WebCursor::GetNativeCursor() { |
| 166 int type = GetCursorType(); | 144 int type = GetCursorType(); |
| 167 if (type == GDK_CURSOR_IS_PIXMAP) | 145 if (type == GDK_CURSOR_IS_PIXMAP) |
| 168 return GetCustomCursor(); | 146 return GetCustomCursor(); |
| 169 return gfx::GetCursor(type); | 147 return gfx::GetCursor(type); |
| 170 } | 148 } |
| 171 | 149 |
| 172 GdkCursor* WebCursor::GetCustomCursor() { | 150 GdkCursor* WebCursor::GetCustomCursor() { |
| 173 switch (type_) { | 151 switch (type_) { |
| 174 // See comment above |GetInvisibleCustomCursor()|. | |
| 175 #if !GTK_CHECK_VERSION(2, 16, 0) | |
| 176 case WebCursorInfo::TypeNone: | |
| 177 return GetInvisibleCustomCursor(); | |
| 178 #endif | |
| 179 case WebCursorInfo::TypeZoomIn: | 152 case WebCursorInfo::TypeZoomIn: |
| 180 return GetInlineCustomCursor(CustomCursorZoomIn); | 153 return GetInlineCustomCursor(CustomCursorZoomIn); |
| 181 case WebCursorInfo::TypeZoomOut: | 154 case WebCursorInfo::TypeZoomOut: |
| 182 return GetInlineCustomCursor(CustomCursorZoomOut); | 155 return GetInlineCustomCursor(CustomCursorZoomOut); |
| 183 case WebCursorInfo::TypeGrab: | 156 case WebCursorInfo::TypeGrab: |
| 184 return GetInlineCustomCursor(CustomCursorGrab); | 157 return GetInlineCustomCursor(CustomCursorGrab); |
| 185 case WebCursorInfo::TypeGrabbing: | 158 case WebCursorInfo::TypeGrabbing: |
| 186 return GetInlineCustomCursor(CustomCursorGrabbing); | 159 return GetInlineCustomCursor(CustomCursorGrabbing); |
| 187 } | 160 } |
| 188 | 161 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 unref_ = NULL; | 207 unref_ = NULL; |
| 235 } | 208 } |
| 236 return; | 209 return; |
| 237 } | 210 } |
| 238 | 211 |
| 239 void WebCursor::CopyPlatformData(const WebCursor& other) { | 212 void WebCursor::CopyPlatformData(const WebCursor& other) { |
| 240 if (other.unref_) | 213 if (other.unref_) |
| 241 unref_ = gdk_cursor_ref(other.unref_); | 214 unref_ = gdk_cursor_ref(other.unref_); |
| 242 return; | 215 return; |
| 243 } | 216 } |
| OLD | NEW |