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