OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/cursors/webcursor.h" | 5 #include "content/common/cursors/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" |
11 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 11 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
12 #include "ui/gfx/gtk_util.h" | 12 #include "ui/gfx/gtk_util.h" |
13 | 13 |
14 using blink::WebCursorInfo; | 14 using blink::WebCursorInfo; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // webcursor_gtk_data.h is taken directly from WebKit's CursorGtk.h. | 18 // webcursor_gtk_data.h is taken directly from WebKit's CursorGtk.h. |
19 #include "webkit/common/cursors/webcursor_gtk_data.h" | 19 #include "content/common/cursors/webcursor_gtk_data.h" |
20 | 20 |
21 // This helper function is taken directly from WebKit's CursorGtk.cpp. | 21 // This helper function is taken directly from WebKit's CursorGtk.cpp. |
22 // It attempts to create a custom cursor from the data inlined in | 22 // It attempts to create a custom cursor from the data inlined in |
23 // webcursor_gtk_data.h. | 23 // webcursor_gtk_data.h. |
24 GdkCursor* GetInlineCustomCursor(CustomCursorType type) { | 24 GdkCursor* GetInlineCustomCursor(CustomCursorType type) { |
25 static GdkCursor* CustomCursorsGdk[G_N_ELEMENTS(CustomCursors)]; | 25 static GdkCursor* CustomCursorsGdk[G_N_ELEMENTS(CustomCursors)]; |
26 GdkCursor* cursor = CustomCursorsGdk[type]; | 26 GdkCursor* cursor = CustomCursorsGdk[type]; |
27 if (cursor) | 27 if (cursor) |
28 return cursor; | 28 return cursor; |
29 const CustomCursor& custom = CustomCursors[type]; | 29 const CustomCursor& custom = CustomCursors[type]; |
30 cursor = gdk_cursor_new_from_name(gdk_display_get_default(), custom.name); | 30 cursor = gdk_cursor_new_from_name(gdk_display_get_default(), custom.name); |
31 if (!cursor) { | 31 if (!cursor) { |
32 const GdkColor fg = { 0, 0, 0, 0 }; | 32 const GdkColor fg = { 0, 0, 0, 0 }; |
33 const GdkColor bg = { 65535, 65535, 65535, 65535 }; | 33 const GdkColor bg = { 65535, 65535, 65535, 65535 }; |
34 GdkPixmap* source = gdk_bitmap_create_from_data( | 34 GdkPixmap* source = gdk_bitmap_create_from_data( |
35 NULL, reinterpret_cast<const gchar*>(custom.bits), 32, 32); | 35 NULL, reinterpret_cast<const gchar*>(custom.bits), 32, 32); |
36 GdkPixmap* mask = gdk_bitmap_create_from_data( | 36 GdkPixmap* mask = gdk_bitmap_create_from_data( |
37 NULL, reinterpret_cast<const gchar*>(custom.mask_bits), 32, 32); | 37 NULL, reinterpret_cast<const gchar*>(custom.mask_bits), 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 } // end anonymous namespace | 47 } // namespace |
| 48 |
| 49 namespace content { |
48 | 50 |
49 int WebCursor::GetCursorType() const { | 51 int WebCursor::GetCursorType() const { |
50 // http://library.gnome.org/devel/gdk/2.12/gdk-Cursors.html has images | 52 // http://library.gnome.org/devel/gdk/2.12/gdk-Cursors.html has images |
51 // of the default X theme, but beware that the user's cursor theme can | 53 // of the default X theme, but beware that the user's cursor theme can |
52 // change everything. | 54 // change everything. |
53 switch (type_) { | 55 switch (type_) { |
54 case WebCursorInfo::TypePointer: | 56 case WebCursorInfo::TypePointer: |
55 return GDK_LAST_CURSOR; | 57 return GDK_LAST_CURSOR; |
56 case WebCursorInfo::TypeCross: | 58 case WebCursorInfo::TypeCross: |
57 return GDK_CROSS; | 59 return GDK_CROSS; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 unref_ = NULL; | 215 unref_ = NULL; |
214 } | 216 } |
215 return; | 217 return; |
216 } | 218 } |
217 | 219 |
218 void WebCursor::CopyPlatformData(const WebCursor& other) { | 220 void WebCursor::CopyPlatformData(const WebCursor& other) { |
219 if (other.unref_) | 221 if (other.unref_) |
220 unref_ = gdk_cursor_ref(other.unref_); | 222 unref_ = gdk_cursor_ref(other.unref_); |
221 return; | 223 return; |
222 } | 224 } |
| 225 |
| 226 } // namespace content |
OLD | NEW |