| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 |
| 5 #ifndef UI_BASE_CURSOR_OZONE_CURSORD_DATA_FACTORY_OZONE_H_ |
| 6 #define UI_BASE_CURSOR_OZONE_CURSORD_DATA_FACTORY_OZONE_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/base/cursor/cursor_data.h" |
| 14 #include "ui/base/ui_base_export.h" |
| 15 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 17 |
| 18 namespace ui { |
| 19 |
| 20 // A refcounted wrapper around a ui::CursorData to obey CursorFactoryOzone's |
| 21 // refcounting interface while building ui::CursorData objects for transport |
| 22 // over mojo pipes. |
| 23 // |
| 24 // TODO(erg): In the long term, this should go away. When //content/ switches |
| 25 // from webcursor.h to use ui::CursorData directly, we should be able to get |
| 26 // rid of this class which is an adaptor for the existing ozone code. |
| 27 class UI_BASE_EXPORT CursorDataOzone |
| 28 : public base::RefCounted<CursorDataOzone> { |
| 29 public: |
| 30 explicit CursorDataOzone(const ui::CursorData& data); |
| 31 |
| 32 const ui::CursorData& data() const { return data_; } |
| 33 |
| 34 // Instances of CursorDataOzone are passed around as void* because of the low |
| 35 // level CursorFactoryOzone interface. Even worse, there can be multiple |
| 36 // subclasses that map to this void* type. This asserts that a magic cookie |
| 37 // that we put at the start of valid CursorDataOzone objects is correct. |
| 38 void AssertIsACusrorDataOzone(); |
| 39 |
| 40 private: |
| 41 friend class base::RefCounted<CursorDataOzone>; |
| 42 ~CursorDataOzone(); |
| 43 |
| 44 // This is always a magic constant value. This is set in the constructor and |
| 45 // unset in the destructor. |
| 46 uint32_t magic_cookie_; |
| 47 |
| 48 ui::CursorData data_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(CursorDataOzone); |
| 51 }; |
| 52 |
| 53 // CursorFactoryOzone implementation for processes which use ui::CursorDatas. |
| 54 // |
| 55 // Inside some sandboxed processes, we need to save all source data so it can |
| 56 // be processed in a remote process. This plugs into the current ozone cursor |
| 57 // creating code, and builds the cross platform mojo data structure. |
| 58 class UI_BASE_EXPORT CursorDataFactoryOzone : public CursorFactoryOzone { |
| 59 public: |
| 60 CursorDataFactoryOzone(); |
| 61 ~CursorDataFactoryOzone() override; |
| 62 |
| 63 // Converts a PlatformCursor back to a ui::CursorData. |
| 64 static const ui::CursorData& GetCursorData(PlatformCursor platform_cursor); |
| 65 |
| 66 // CursorFactoryOzone: |
| 67 PlatformCursor GetDefaultCursor(int type) override; |
| 68 PlatformCursor CreateImageCursor(const SkBitmap& bitmap, |
| 69 const gfx::Point& hotspot, |
| 70 float bitmap_dpi) override; |
| 71 PlatformCursor CreateAnimatedCursor(const std::vector<SkBitmap>& bitmaps, |
| 72 const gfx::Point& hotspot, |
| 73 int frame_delay_ms, |
| 74 float bitmap_dpi) override; |
| 75 void RefImageCursor(PlatformCursor cursor) override; |
| 76 void UnrefImageCursor(PlatformCursor cursor) override; |
| 77 |
| 78 private: |
| 79 // Get cached BitmapCursorOzone for a default cursor. |
| 80 scoped_refptr<CursorDataOzone> GetDefaultCursorInternal(int type); |
| 81 |
| 82 // Default cursors are cached & owned by the factory. |
| 83 typedef std::map<int, scoped_refptr<CursorDataOzone>> DefaultCursorMap; |
| 84 DefaultCursorMap default_cursors_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(CursorDataFactoryOzone); |
| 87 }; |
| 88 |
| 89 } // namespace ui |
| 90 |
| 91 #endif // UI_BASE_CURSOR_OZONE_CURSORD_DATA_FACTORY_OZONE_H_ |
| OLD | NEW |