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

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

Issue 158023006: Adding Ozone CursorLoader and necessary API functions to allow setting the cursor in SoftwareFactor… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ui/base/cursor/cursor_loader_ozone.h"
6
7 #include "ui/base/cursor/cursor.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/image/image_skia.h"
10
11 namespace ui {
12
13 namespace {
14
15 // Creates a 1x1 cursor which will be fully transparent.
16 SkBitmap CreateInvisibleCursor() {
17 SkBitmap cursor;
18 cursor.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
19 cursor.allocPixels();
20
21 cursor.lockPixels();
22 cursor.eraseARGB(0, 0, 0, 0);
23 cursor.unlockPixels();
24
25 return cursor;
26 }
27
28 } // namespace
29
30 CursorLoaderOzone::CursorLoaderOzone()
31 : invisible_cursor_(CreateInvisibleCursor()) {}
32
33 CursorLoaderOzone::~CursorLoaderOzone() {}
34
35 void CursorLoaderOzone::LoadImageCursor(int id,
36 int resource_id,
37 const gfx::Point& hot) {
38 const gfx::ImageSkia* image = ResourceBundle::GetSharedInstance()
39 .GetImageSkiaNamed(resource_id);
40
41 cursors_[id] = image;
sky 2014/02/12 21:47:22 nit: do away with temporary (eg assign directly).
dnicoara 2014/02/12 21:57:40 Done.
42 }
43
44 void CursorLoaderOzone::LoadAnimatedCursor(int id,
45 int resource_id,
46 const gfx::Point& hot,
47 int frame_delay_ms) {
48 // TODO(dnicoara) Add support: crbug.com/343245
49 NOTIMPLEMENTED();
50 }
51
52 void CursorLoaderOzone::UnloadAll() {
53 cursors_.clear();
54 }
55
56 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) {
57 if (cursors_.find(cursor->native_type()) != cursors_.end()) {
58 const gfx::ImageSkiaRep& image_rep =
59 cursors_[cursor->native_type()]->GetRepresentation(
60 display().device_scale_factor());
61
62 cursor->SetPlatformCursor(&image_rep.sk_bitmap());
63 } else if (*cursor == kCursorNone) {
64 cursor->SetPlatformCursor(&invisible_cursor_);
65 } else if (*cursor == kCursorCustom) {
66 // TODO(dnicoara) Add support for custom cursors: crbug.com/343155
67 cursor->SetPlatformCursor(cursor->platform());
68 } else {
69 const gfx::ImageSkiaRep& image_rep =
70 cursors_[kCursorPointer]->GetRepresentation(
71 display().device_scale_factor());
72
73 cursor->SetPlatformCursor(&image_rep.sk_bitmap());
74 }
75 }
76
77 CursorLoader* CursorLoader::Create() {
78 return new CursorLoaderOzone();
79 }
80
81 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698