Adding wrapper class WKBackForwardListItemHolder
[chromium-blink-merge.git] / ui / base / cursor / cursor_loader_ozone.cc
blob08b831e6d959712e91f4fe22475189423156d8fc
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 #include "ui/base/cursor/cursor_loader_ozone.h"
7 #include <vector>
9 #include "ui/base/cursor/cursor.h"
10 #include "ui/base/cursor/cursor_util.h"
11 #include "ui/ozone/public/cursor_factory_ozone.h"
13 namespace ui {
15 CursorLoaderOzone::CursorLoaderOzone() {}
17 CursorLoaderOzone::~CursorLoaderOzone() {}
19 void CursorLoaderOzone::LoadImageCursor(int id,
20 int resource_id,
21 const gfx::Point& hot) {
22 SkBitmap bitmap;
23 gfx::Point hotspot = hot;
25 GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap);
27 cursors_[id] =
28 CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap, hotspot);
31 void CursorLoaderOzone::LoadAnimatedCursor(int id,
32 int resource_id,
33 const gfx::Point& hot,
34 int frame_delay_ms) {
35 std::vector<SkBitmap> bitmaps;
36 gfx::Point hotspot = hot;
38 GetAnimatedCursorBitmaps(
39 resource_id, scale(), rotation(), &hotspot, &bitmaps);
41 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateAnimatedCursor(
42 bitmaps, hotspot, frame_delay_ms);
45 void CursorLoaderOzone::UnloadAll() {
46 for (ImageCursorMap::const_iterator it = cursors_.begin();
47 it != cursors_.end();
48 ++it)
49 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second);
50 cursors_.clear();
53 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) {
54 int native_type = cursor->native_type();
55 PlatformCursor platform;
57 if (cursors_.count(native_type)) {
58 // An image cursor is loaded for this type.
59 platform = cursors_[native_type];
60 } else if (native_type == kCursorCustom) {
61 // The platform cursor was already set via WebCursor::GetPlatformCursor.
62 platform = cursor->platform();
63 } else {
64 // Use default cursor of this type.
65 platform = CursorFactoryOzone::GetInstance()->GetDefaultCursor(native_type);
68 cursor->SetPlatformCursor(platform);
71 CursorLoader* CursorLoader::Create() {
72 return new CursorLoaderOzone();
75 } // namespace ui