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 // 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 DISALLOW_COPY_AND_ASSIGN(XCursorCache); | 205 DISALLOW_COPY_AND_ASSIGN(XCursorCache); |
206 }; | 206 }; |
207 | 207 |
208 XCursorCache* cursor_cache = NULL; | 208 XCursorCache* cursor_cache = NULL; |
209 | 209 |
210 // A process wide singleton cache for custom X cursors. | 210 // A process wide singleton cache for custom X cursors. |
211 class XCustomCursorCache { | 211 class XCustomCursorCache { |
212 public: | 212 public: |
213 static XCustomCursorCache* GetInstance() { | 213 static XCustomCursorCache* GetInstance() { |
214 return Singleton<XCustomCursorCache>::get(); | 214 return base::Singleton<XCustomCursorCache>::get(); |
215 } | 215 } |
216 | 216 |
217 ::Cursor InstallCustomCursor(XcursorImage* image) { | 217 ::Cursor InstallCustomCursor(XcursorImage* image) { |
218 XCustomCursor* custom_cursor = new XCustomCursor(image); | 218 XCustomCursor* custom_cursor = new XCustomCursor(image); |
219 ::Cursor xcursor = custom_cursor->cursor(); | 219 ::Cursor xcursor = custom_cursor->cursor(); |
220 cache_[xcursor] = custom_cursor; | 220 cache_[xcursor] = custom_cursor; |
221 return xcursor; | 221 return xcursor; |
222 } | 222 } |
223 | 223 |
224 void Ref(::Cursor cursor) { | 224 void Ref(::Cursor cursor) { |
225 cache_[cursor]->Ref(); | 225 cache_[cursor]->Ref(); |
226 } | 226 } |
227 | 227 |
228 void Unref(::Cursor cursor) { | 228 void Unref(::Cursor cursor) { |
229 if (cache_[cursor]->Unref()) | 229 if (cache_[cursor]->Unref()) |
230 cache_.erase(cursor); | 230 cache_.erase(cursor); |
231 } | 231 } |
232 | 232 |
233 void Clear() { | 233 void Clear() { |
234 cache_.clear(); | 234 cache_.clear(); |
235 } | 235 } |
236 | 236 |
237 const XcursorImage* GetXcursorImage(::Cursor cursor) const { | 237 const XcursorImage* GetXcursorImage(::Cursor cursor) const { |
238 return cache_.find(cursor)->second->image(); | 238 return cache_.find(cursor)->second->image(); |
239 } | 239 } |
240 | 240 |
241 private: | 241 private: |
242 friend struct DefaultSingletonTraits<XCustomCursorCache>; | 242 friend struct base::DefaultSingletonTraits<XCustomCursorCache>; |
243 | 243 |
244 class XCustomCursor { | 244 class XCustomCursor { |
245 public: | 245 public: |
246 // This takes ownership of the image. | 246 // This takes ownership of the image. |
247 XCustomCursor(XcursorImage* image) | 247 XCustomCursor(XcursorImage* image) |
248 : image_(image), | 248 : image_(image), |
249 ref_(1) { | 249 ref_(1) { |
250 cursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image); | 250 cursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image); |
251 } | 251 } |
252 | 252 |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1407 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1408 << "minor_code " << static_cast<int>(error_event.minor_code) | 1408 << "minor_code " << static_cast<int>(error_event.minor_code) |
1409 << " (" << request_str << ")"; | 1409 << " (" << request_str << ")"; |
1410 } | 1410 } |
1411 | 1411 |
1412 // ---------------------------------------------------------------------------- | 1412 // ---------------------------------------------------------------------------- |
1413 // End of x11_util_internal.h | 1413 // End of x11_util_internal.h |
1414 | 1414 |
1415 | 1415 |
1416 } // namespace ui | 1416 } // namespace ui |
OLD | NEW |