Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: ui/base/x/x11_util.cc

Issue 9463003: aura-x11: Add custom web cursor support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/x/x11_util.cc
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 288344828ee8620707daa7b597a22f93af4627ab..c17ee38c69e41f990682602853787bccdeb4f8e1 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -35,6 +35,10 @@
#include <sys/sysctl.h>
#endif
+#if defined(USE_AURA)
+#include <X11/Xcursor/Xcursor.h>
+#endif
+
#if defined(TOOLKIT_USES_GTK)
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
@@ -188,6 +192,84 @@ class XCursorCache {
DISALLOW_COPY_AND_ASSIGN(XCursorCache);
};
+#if defined(USE_AURA)
+// A process wide singleton cache for custom X cursors.
+class XCustomCursorCache {
+ public:
+ static XCustomCursorCache* GetInstance() {
+ return Singleton<XCustomCursorCache>::get();
+ }
+
+ Cursor InstallCustomCursor(XcursorImage* image) {
+ XCustomCursor* custom_cursor = new XCustomCursor(image);
+ Cursor xcursor = custom_cursor->cursor();
+ cache_[xcursor] = custom_cursor;
+ return xcursor;
+ }
+
+ void Ref(Cursor cursor) {
+ cache_[cursor]->Ref();
+ }
+
+ void Unref(Cursor cursor) {
+ if (cache_[cursor]->Unref())
+ cache_.erase(cursor);
+ }
+
+ void Clear() {
+ cache_.clear();
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<XCustomCursorCache>;
+
+ class XCustomCursor {
+ public:
+ // This takes ownership of the image.
+ XCustomCursor(XcursorImage* image)
+ : image_(image),
+ ref_(1) {
+ cursor_ = XcursorImageLoadCursor(GetXDisplay(), image);
+ }
+
+ ~XCustomCursor() {
+ XcursorImageDestroy(image_);
+ XFreeCursor(GetXDisplay(), cursor_);
+ }
+
+ Cursor cursor() const { return cursor_; }
+
+ void Ref() {
+ ++ref_;
+ }
+
+ // Returns true if the cursor was destroyed because of the unref.
+ bool Unref() {
+ if (--ref_ == 0) {
+ delete this;
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ XcursorImage* image_;
+ int ref_;
+ Cursor cursor_;
+
+ DISALLOW_COPY_AND_ASSIGN(XCustomCursor);
+ };
+
+ XCustomCursorCache() {}
+ ~XCustomCursorCache() {
+ Clear();
+ }
+
+ std::map<Cursor, XCustomCursor*> cache_;
+ DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache);
+};
+#endif // defined(USE_AURA)
+
// A singleton object that remembers remappings of mouse buttons.
class XButtonMap {
public:
@@ -317,6 +399,20 @@ Cursor GetXCursor(int cursor_shape) {
return cache.GetCursor(cursor_shape);
}
+#if defined(USE_AURA)
+Cursor CreateReffedCustomXCursor(XcursorImage* image) {
+ return XCustomCursorCache::GetInstance()->InstallCustomCursor(image);
+}
+
+void RefCustomXCursor(Cursor cursor) {
+ XCustomCursorCache::GetInstance()->Ref(cursor);
+}
+
+void UnrefCustomXCursor(Cursor cursor) {
+ XCustomCursorCache::GetInstance()->Unref(cursor);
+}
+#endif
+
XID GetX11RootWindow() {
return DefaultRootWindow(GetXDisplay());
}

Powered by Google App Engine
This is Rietveld 408576698