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.
5 #ifndef UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_
6 #define UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_
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"
19 // A cursor that is an SkBitmap combined with a gfx::Point hotspot.
20 class UI_BASE_EXPORT BitmapCursorOzone
21 : public base::RefCounted<BitmapCursorOzone> {
23 BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot);
24 BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps,
25 const gfx::Point& hotspot,
28 const gfx::Point& hotspot();
29 const SkBitmap& bitmap();
31 // For animated cursors.
32 const std::vector<SkBitmap>& bitmaps();
36 friend class base::RefCounted<BitmapCursorOzone>;
39 std::vector<SkBitmap> bitmaps_;
43 DISALLOW_COPY_AND_ASSIGN(BitmapCursorOzone);
46 // CursorFactoryOzone implementation for bitmapped cursors.
48 // This is a base class for platforms where PlatformCursor is an SkBitmap
49 // combined with a gfx::Point for the hotspot.
51 // Subclasses need only implement SetBitmapCursor() as everything else is
53 class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone {
55 BitmapCursorFactoryOzone();
56 virtual ~BitmapCursorFactoryOzone();
58 // Convert PlatformCursor to BitmapCursorOzone.
59 static scoped_refptr<BitmapCursorOzone> GetBitmapCursor(
60 PlatformCursor platform_cursor);
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;
74 // Get cached BitmapCursorOzone for a default cursor.
75 scoped_refptr<BitmapCursorOzone> GetDefaultCursorInternal(int type);
77 // Default cursors are cached & owned by the factory.
78 typedef std::map<int, scoped_refptr<BitmapCursorOzone> > DefaultCursorMap;
79 DefaultCursorMap default_cursors_;
81 DISALLOW_COPY_AND_ASSIGN(BitmapCursorFactoryOzone);
86 #endif // UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_