blob: 037fd0865d3c23f77c6af6fd528712121ba312e3 [file] [log] [blame]
// 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.
#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> {
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();
friend class base::RefCounted<BitmapCursorOzone>;
std::vector<SkBitmap> bitmaps_;
gfx::Point hotspot_;
int frame_delay_ms_;
// 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 {
virtual ~BitmapCursorFactoryOzone();
// Convert PlatformCursor to BitmapCursorOzone.
static scoped_refptr<BitmapCursorOzone> GetBitmapCursor(
PlatformCursor platform_cursor);
// CursorFactoryOzone:
virtual PlatformCursor GetDefaultCursor(int type) override;
virtual PlatformCursor CreateImageCursor(const SkBitmap& bitmap,
const gfx::Point& hotspot) override;
virtual PlatformCursor CreateAnimatedCursor(
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
int frame_delay_ms) override;
virtual void RefImageCursor(PlatformCursor cursor) override;
virtual void UnrefImageCursor(PlatformCursor cursor) override;
// 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_;
} // namespace ui