Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ui/base/cursor/cursor_loader_ozone.cc

Issue 2961403002: WIP fix for Ozone cursor woes in Mushrome: Numéro deux
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/cursor/cursor_loader_ozone.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/cursor/cursor_loader_ozone.h" 5 #include "ui/base/cursor/cursor_loader_ozone.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/debug/stack_trace.h"
9 #include "ui/base/cursor/cursor.h" 10 #include "ui/base/cursor/cursor.h"
10 #include "ui/base/cursor/cursor_util.h" 11 #include "ui/base/cursor/cursor_util.h"
11 #include "ui/ozone/public/cursor_factory_ozone.h" 12 #include "ui/ozone/public/cursor_factory_ozone.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 CursorLoaderOzone::CursorLoaderOzone() {} 16 CursorLoaderOzone::CursorLoaderOzone() {
17 factory_ = CursorFactoryOzone::GetInstance();
18 }
16 19
17 CursorLoaderOzone::~CursorLoaderOzone() {} 20 CursorLoaderOzone::~CursorLoaderOzone() {}
18 21
19 void CursorLoaderOzone::LoadImageCursor(CursorType id, 22 void CursorLoaderOzone::LoadImageCursor(CursorType id,
20 int resource_id, 23 int resource_id,
21 const gfx::Point& hot) { 24 const gfx::Point& hot) {
22 SkBitmap bitmap; 25 SkBitmap bitmap;
23 gfx::Point hotspot = hot; 26 gfx::Point hotspot = hot;
24 27
25 GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); 28 GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap);
26 29
27 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateImageCursor( 30 cursors_[id] = factory_->CreateImageCursor(bitmap, hotspot, scale());
28 bitmap, hotspot, scale());
29 } 31 }
30 32
31 void CursorLoaderOzone::LoadAnimatedCursor(CursorType id, 33 void CursorLoaderOzone::LoadAnimatedCursor(CursorType id,
32 int resource_id, 34 int resource_id,
33 const gfx::Point& hot, 35 const gfx::Point& hot,
34 int frame_delay_ms) { 36 int frame_delay_ms) {
35 std::vector<SkBitmap> bitmaps; 37 std::vector<SkBitmap> bitmaps;
36 gfx::Point hotspot = hot; 38 gfx::Point hotspot = hot;
37 39
38 GetAnimatedCursorBitmaps( 40 GetAnimatedCursorBitmaps(
39 resource_id, scale(), rotation(), &hotspot, &bitmaps); 41 resource_id, scale(), rotation(), &hotspot, &bitmaps);
40 42
41 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateAnimatedCursor( 43 cursors_[id] =
42 bitmaps, hotspot, frame_delay_ms, scale()); 44 factory_->CreateAnimatedCursor(bitmaps, hotspot, frame_delay_ms, scale());
43 } 45 }
44 46
45 void CursorLoaderOzone::UnloadAll() { 47 void CursorLoaderOzone::UnloadAll() {
46 for (ImageCursorMap::const_iterator it = cursors_.begin(); 48 for (ImageCursorMap::const_iterator it = cursors_.begin();
47 it != cursors_.end(); 49 it != cursors_.end(); ++it) {
48 ++it) 50 factory_->UnrefImageCursor(it->second);
49 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second); 51 }
50 cursors_.clear(); 52 cursors_.clear();
51 } 53 }
52 54
53 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { 55 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) {
54 CursorType native_type = cursor->native_type(); 56 CursorType native_type = cursor->native_type();
55 PlatformCursor platform; 57 PlatformCursor platform;
56 58
57 if (cursors_.count(native_type)) { 59 if (cursors_.count(native_type)) {
58 // An image cursor is loaded for this type. 60 // An image cursor is loaded for this type.
59 platform = cursors_[native_type]; 61 platform = cursors_[native_type];
60 } else if (native_type == CursorType::kCustom) { 62 } else if (native_type == CursorType::kCustom) {
61 // The platform cursor was already set via WebCursor::GetPlatformCursor. 63 // The platform cursor was already set via WebCursor::GetPlatformCursor.
62 platform = cursor->platform(); 64 platform = cursor->platform();
63 } else { 65 } else {
64 // Use default cursor of this type. 66 // Use default cursor of this type.
65 platform = CursorFactoryOzone::GetInstance()->GetDefaultCursor(native_type); 67 platform = factory_->GetDefaultCursor(native_type);
66 } 68 }
67 69
68 cursor->SetPlatformCursor(platform); 70 cursor->SetPlatformCursor(platform);
69 } 71 }
70 72
71 CursorLoader* CursorLoader::Create() { 73 CursorLoader* CursorLoader::Create() {
72 return new CursorLoaderOzone(); 74 return new CursorLoaderOzone();
73 } 75 }
74 76
75 } // namespace ui 77 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cursor/cursor_loader_ozone.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698