Index: ui/aura/root_window_host_linux.cc |
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc |
index ff80134c75aa6029d2459f3652608082527168f0..1b56bb096b7f0e26b22eeccd710d08d1395adbbf 100644 |
--- a/ui/aura/root_window_host_linux.cc |
+++ b/ui/aura/root_window_host_linux.cc |
@@ -5,6 +5,7 @@ |
#include "ui/aura/root_window_host_linux.h" |
#include <X11/Xatom.h> |
+#include <X11/Xcursor/Xcursor.h> |
#include <X11/cursorfont.h> |
#include <X11/extensions/XInput2.h> |
#include <X11/extensions/Xfixes.h> |
@@ -14,6 +15,8 @@ |
#include "base/message_pump_x.h" |
#include "base/stl_util.h" |
#include "base/stringprintf.h" |
+#include "grit/ui_resources_standard.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/aura/client/user_gesture_client.h" |
#include "ui/aura/dispatcher_linux.h" |
#include "ui/aura/env.h" |
@@ -21,10 +24,12 @@ |
#include "ui/aura/root_window.h" |
#include "ui/base/cursor/cursor.h" |
#include "ui/base/keycodes/keyboard_codes.h" |
+#include "ui/base/resource/resource_bundle.h" |
#include "ui/base/touch/touch_factory.h" |
#include "ui/base/x/x11_util.h" |
#include "ui/base/view_prop.h" |
#include "ui/gfx/compositor/layer.h" |
+#include "ui/gfx/image/image.h" |
using std::max; |
using std::min; |
@@ -292,6 +297,51 @@ const char* kAtomList[] = { |
} // namespace |
+// A utility class that provides X Cursor for NativeCursors for which we have |
+// image resources. |
+class RootWindowHostLinux::ImageCursors { |
+ public: |
+ ImageCursors() { |
+ LoadImageCursor(ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP); |
+ LoadImageCursor(ui::kCursorCopy, IDR_AURA_CURSOR_COPY); |
+ // TODO (varunjain): add more cursors once we have assets. |
+ } |
+ |
+ ~ImageCursors() { |
+ std::map<int, Cursor>::const_iterator it; |
+ for (it = cursors_.begin(); it != cursors_.end(); ++it) |
+ ui::UnrefCustomXCursor(it->second); |
+ } |
+ |
+ // Returns true if we have an image resource loaded for the |native_cursor|. |
+ bool IsImageCursor(gfx::NativeCursor native_cursor) { |
+ return cursors_.find(native_cursor.native_type()) != cursors_.end(); |
+ } |
+ |
+ // Gets the X Cursor corresponding to the |native_cursor|. |
+ ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor) { |
+ DCHECK(cursors_.find(native_cursor.native_type()) != cursors_.end()); |
+ return cursors_[native_cursor.native_type()]; |
+ } |
+ |
+ private: |
+ // Creates an X Cursor from an image resource and puts it in the cursor map. |
+ void LoadImageCursor(int id, int resource_id) { |
+ const SkBitmap* bitmap = |
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ resource_id).ToSkBitmap(); |
+ |
+ XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap, gfx::Point(0, 0)); |
+ cursors_[id] = ui::CreateReffedCustomXCursor(image); |
+ // |bitmap| is owned by the resource bundle. So we do not need to free it. |
+ } |
+ |
+ // A map to hold all image cursors. It maps the cursor ID to the X Cursor. |
+ std::map<int, Cursor> cursors_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ImageCursors); |
+}; |
+ |
RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
: root_window_(NULL), |
xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
@@ -301,7 +351,8 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
cursor_shown_(true), |
bounds_(bounds), |
focus_when_shown_(false), |
- pointer_barriers_(NULL) { |
+ pointer_barriers_(NULL), |
+ image_cursors_(new ImageCursors) { |
XSetWindowAttributes swa; |
memset(&swa, 0, sizeof(swa)); |
swa.background_pixmap = None; |
@@ -794,6 +845,8 @@ bool RootWindowHostLinux::IsWindowManagerPresent() { |
void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
::Cursor xcursor = |
+ image_cursors_->IsImageCursor(cursor) ? |
+ image_cursors_->ImageCursorFromNative(cursor) : |
cursor == ui::kCursorNone ? |
invisible_cursor_ : |
cursor == ui::kCursorCustom ? |