x11_cursor.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_X_X11_CURSOR_H_
  5. #define UI_BASE_X_X11_CURSOR_H_
  6. #include <vector>
  7. #include "base/callback.h"
  8. #include "base/component_export.h"
  9. #include "ui/base/cursor/platform_cursor.h"
  10. #include "ui/gfx/x/xproto.h"
  11. template <class T>
  12. class scoped_refptr;
  13. namespace ui {
  14. // Ref counted class to hold an X11 cursor resource. Clears the X11 resources
  15. // on destruction
  16. class COMPONENT_EXPORT(UI_BASE_X) X11Cursor : public PlatformCursor {
  17. public:
  18. using Callback = base::OnceCallback<void(x11::Cursor)>;
  19. static scoped_refptr<X11Cursor> FromPlatformCursor(
  20. scoped_refptr<PlatformCursor> platform_cursor);
  21. X11Cursor();
  22. explicit X11Cursor(x11::Cursor cursor);
  23. X11Cursor(const X11Cursor&) = delete;
  24. X11Cursor& operator=(const X11Cursor&) = delete;
  25. void OnCursorLoaded(Callback callback);
  26. bool loaded() const { return loaded_; }
  27. x11::Cursor xcursor() const { return xcursor_; }
  28. private:
  29. friend class base::RefCounted<PlatformCursor>;
  30. friend class XCursorLoader;
  31. ~X11Cursor() override;
  32. void SetCursor(x11::Cursor cursor);
  33. // This cannot be named Release() since it conflicts with base::RefCounted.
  34. x11::Cursor ReleaseCursor();
  35. bool loaded_ = false;
  36. x11::Cursor xcursor_ = x11::Cursor::None;
  37. std::vector<Callback> callbacks_;
  38. };
  39. } // namespace ui
  40. #endif // UI_BASE_X_X11_CURSOR_H_