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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "ui/base/x/x11_util.h" 9 #include "ui/base/x/x11_util.h"
10 10
(...skipping 17 matching lines...) Expand all
28 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 28 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
29 #include "ui/base/x/x11_util_internal.h" 29 #include "ui/base/x/x11_util_internal.h"
30 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
31 #include "ui/gfx/size.h" 31 #include "ui/gfx/size.h"
32 32
33 #if defined(OS_FREEBSD) 33 #if defined(OS_FREEBSD)
34 #include <sys/types.h> 34 #include <sys/types.h>
35 #include <sys/sysctl.h> 35 #include <sys/sysctl.h>
36 #endif 36 #endif
37 37
38 #if defined(USE_AURA)
39 #include <X11/Xcursor/Xcursor.h>
40 #endif
41
38 #if defined(TOOLKIT_USES_GTK) 42 #if defined(TOOLKIT_USES_GTK)
39 #include <gdk/gdk.h> 43 #include <gdk/gdk.h>
40 #include <gdk/gdkx.h> 44 #include <gdk/gdkx.h>
41 #include <gtk/gtk.h> 45 #include <gtk/gtk.h>
42 #include "ui/base/gtk/gtk_compat.h" 46 #include "ui/base/gtk/gtk_compat.h"
43 #include "ui/base/gtk/gdk_x_compat.h" 47 #include "ui/base/gtk/gdk_x_compat.h"
44 #else 48 #else
45 // TODO(sad): Use the new way of handling X errors when 49 // TODO(sad): Use the new way of handling X errors when
46 // http://codereview.chromium.org/7889040/ lands. 50 // http://codereview.chromium.org/7889040/ lands.
47 #define gdk_error_trap_push() 51 #define gdk_error_trap_push()
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 cache_.clear(); 185 cache_.clear();
182 } 186 }
183 187
184 private: 188 private:
185 // Maps X11 font cursor shapes to Cursor IDs. 189 // Maps X11 font cursor shapes to Cursor IDs.
186 std::map<int, Cursor> cache_; 190 std::map<int, Cursor> cache_;
187 191
188 DISALLOW_COPY_AND_ASSIGN(XCursorCache); 192 DISALLOW_COPY_AND_ASSIGN(XCursorCache);
189 }; 193 };
190 194
195 #if defined(USE_AURA)
196 // A process wide singleton cache for custom X cursors.
197 class XCustomCursorCache {
198 public:
199 static XCustomCursorCache* GetInstance() {
200 return Singleton<XCustomCursorCache>::get();
201 }
202
203 Cursor InstallCustomCursor(XcursorImage* image) {
204 XCustomCursor* custom_cursor = new XCustomCursor(image);
205 Cursor xcursor = custom_cursor->cursor();
206 cache_[xcursor] = custom_cursor;
207 return xcursor;
208 }
209
210 void Ref(Cursor cursor) {
211 cache_[cursor]->Ref();
212 }
213
214 void Unref(Cursor cursor) {
215 if (cache_[cursor]->Unref())
216 cache_.erase(cursor);
217 }
218
219 void Clear() {
220 cache_.clear();
221 }
222
223 private:
224 friend struct DefaultSingletonTraits<XCustomCursorCache>;
225
226 class XCustomCursor {
227 public:
228 // This takes ownership of the image.
229 XCustomCursor(XcursorImage* image)
230 : image_(image),
231 ref_(1) {
232 cursor_ = XcursorImageLoadCursor(GetXDisplay(), image);
233 }
234
235 ~XCustomCursor() {
236 XcursorImageDestroy(image_);
237 XFreeCursor(GetXDisplay(), cursor_);
238 }
239
240 Cursor cursor() const { return cursor_; }
241
242 void Ref() {
243 ++ref_;
244 }
245
246 // Returns true if the cursor was destroyed because of the unref.
247 bool Unref() {
248 if (--ref_ == 0) {
249 delete this;
250 return true;
251 }
252 return false;
253 }
254
255 private:
256 XcursorImage* image_;
257 int ref_;
258 Cursor cursor_;
259
260 DISALLOW_COPY_AND_ASSIGN(XCustomCursor);
261 };
262
263 XCustomCursorCache() {}
264 ~XCustomCursorCache() {
265 Clear();
266 }
267
268 std::map<Cursor, XCustomCursor*> cache_;
269 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache);
270 };
271 #endif // defined(USE_AURA)
272
191 // A singleton object that remembers remappings of mouse buttons. 273 // A singleton object that remembers remappings of mouse buttons.
192 class XButtonMap { 274 class XButtonMap {
193 public: 275 public:
194 static XButtonMap* GetInstance() { 276 static XButtonMap* GetInstance() {
195 return Singleton<XButtonMap>::get(); 277 return Singleton<XButtonMap>::get();
196 } 278 }
197 279
198 void UpdateMapping() { 280 void UpdateMapping() {
199 count_ = XGetPointerMapping(ui::GetXDisplay(), map_, arraysize(map_)); 281 count_ = XGetPointerMapping(ui::GetXDisplay(), map_, arraysize(map_));
200 } 282 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 CR_DEFINE_STATIC_LOCAL(XCursorCache, cache, ()); 392 CR_DEFINE_STATIC_LOCAL(XCursorCache, cache, ());
311 393
312 if (cursor_shape == kCursorClearXCursorCache) { 394 if (cursor_shape == kCursorClearXCursorCache) {
313 cache.Clear(); 395 cache.Clear();
314 return 0; 396 return 0;
315 } 397 }
316 398
317 return cache.GetCursor(cursor_shape); 399 return cache.GetCursor(cursor_shape);
318 } 400 }
319 401
402 #if defined(USE_AURA)
403 Cursor CreateReffedCustomXCursor(XcursorImage* image) {
404 return XCustomCursorCache::GetInstance()->InstallCustomCursor(image);
405 }
406
407 void RefCustomXCursor(Cursor cursor) {
408 XCustomCursorCache::GetInstance()->Ref(cursor);
409 }
410
411 void UnrefCustomXCursor(Cursor cursor) {
412 XCustomCursorCache::GetInstance()->Unref(cursor);
413 }
414 #endif
415
320 XID GetX11RootWindow() { 416 XID GetX11RootWindow() {
321 return DefaultRootWindow(GetXDisplay()); 417 return DefaultRootWindow(GetXDisplay());
322 } 418 }
323 419
324 bool GetCurrentDesktop(int* desktop) { 420 bool GetCurrentDesktop(int* desktop) {
325 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); 421 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop);
326 } 422 }
327 423
328 #if defined(TOOLKIT_USES_GTK) 424 #if defined(TOOLKIT_USES_GTK)
329 XID GetX11WindowFromGtkWidget(GtkWidget* widget) { 425 XID GetX11WindowFromGtkWidget(GtkWidget* widget) {
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1226 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1131 << "minor_code " << static_cast<int>(error_event.minor_code) 1227 << "minor_code " << static_cast<int>(error_event.minor_code)
1132 << " (" << request_str << ")"; 1228 << " (" << request_str << ")";
1133 } 1229 }
1134 1230
1135 // ---------------------------------------------------------------------------- 1231 // ----------------------------------------------------------------------------
1136 // End of x11_util_internal.h 1232 // End of x11_util_internal.h
1137 1233
1138 1234
1139 } // namespace ui 1235 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698