| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_BITMAP_CURSOR_FACTORY_OZONE_H_ | |
| 6 #define UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | |
| 12 #include "ui/base/cursor/cursor.h" | |
| 13 #include "ui/base/ui_base_export.h" | |
| 14 #include "ui/gfx/geometry/point.h" | |
| 15 #include "ui/ozone/public/cursor_factory_ozone.h" | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 // A cursor that is an SkBitmap combined with a gfx::Point hotspot. | |
| 20 class UI_BASE_EXPORT BitmapCursorOzone | |
| 21 : public base::RefCounted<BitmapCursorOzone> { | |
| 22 public: | |
| 23 BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot); | |
| 24 BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps, | |
| 25 const gfx::Point& hotspot, | |
| 26 int frame_delay_ms); | |
| 27 | |
| 28 const gfx::Point& hotspot(); | |
| 29 const SkBitmap& bitmap(); | |
| 30 | |
| 31 // For animated cursors. | |
| 32 const std::vector<SkBitmap>& bitmaps(); | |
| 33 int frame_delay_ms(); | |
| 34 | |
| 35 private: | |
| 36 friend class base::RefCounted<BitmapCursorOzone>; | |
| 37 ~BitmapCursorOzone(); | |
| 38 | |
| 39 std::vector<SkBitmap> bitmaps_; | |
| 40 gfx::Point hotspot_; | |
| 41 int frame_delay_ms_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(BitmapCursorOzone); | |
| 44 }; | |
| 45 | |
| 46 // CursorFactoryOzone implementation for bitmapped cursors. | |
| 47 // | |
| 48 // This is a base class for platforms where PlatformCursor is an SkBitmap | |
| 49 // combined with a gfx::Point for the hotspot. | |
| 50 // | |
| 51 // Subclasses need only implement SetBitmapCursor() as everything else is | |
| 52 // implemented here. | |
| 53 class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone { | |
| 54 public: | |
| 55 BitmapCursorFactoryOzone(); | |
| 56 virtual ~BitmapCursorFactoryOzone(); | |
| 57 | |
| 58 // Convert PlatformCursor to BitmapCursorOzone. | |
| 59 static scoped_refptr<BitmapCursorOzone> GetBitmapCursor( | |
| 60 PlatformCursor platform_cursor); | |
| 61 | |
| 62 // CursorFactoryOzone: | |
| 63 virtual PlatformCursor GetDefaultCursor(int type) override; | |
| 64 virtual PlatformCursor CreateImageCursor(const SkBitmap& bitmap, | |
| 65 const gfx::Point& hotspot) override; | |
| 66 virtual PlatformCursor CreateAnimatedCursor( | |
| 67 const std::vector<SkBitmap>& bitmaps, | |
| 68 const gfx::Point& hotspot, | |
| 69 int frame_delay_ms) override; | |
| 70 virtual void RefImageCursor(PlatformCursor cursor) override; | |
| 71 virtual void UnrefImageCursor(PlatformCursor cursor) override; | |
| 72 | |
| 73 private: | |
| 74 // Get cached BitmapCursorOzone for a default cursor. | |
| 75 scoped_refptr<BitmapCursorOzone> GetDefaultCursorInternal(int type); | |
| 76 | |
| 77 // Default cursors are cached & owned by the factory. | |
| 78 typedef std::map<int, scoped_refptr<BitmapCursorOzone> > DefaultCursorMap; | |
| 79 DefaultCursorMap default_cursors_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(BitmapCursorFactoryOzone); | |
| 82 }; | |
| 83 | |
| 84 } // namespace ui | |
| 85 | |
| 86 #endif // UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_ | |
| OLD | NEW |