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

Side by Side Diff: ash/wm/image_cursors.cc

Issue 258893002: app_shell: Add support for mouse cursors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update build to exclude ImageCursors on android Created 6 years, 7 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
« no previous file with comments | « ash/wm/image_cursors.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
(Empty)
1 // Copyright (c) 2012 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 "ash/wm/image_cursors.h"
6
7 #include <float.h>
8
9 #include "ash/display/display_info.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/cursor/cursor_loader.h"
16 #include "ui/base/cursor/cursors_aura.h"
17 #include "ui/gfx/display.h"
18 #include "ui/gfx/point.h"
19
20 namespace ash {
21
22 const int kImageCursorIds[] = {
23 ui::kCursorNull,
24 ui::kCursorPointer,
25 ui::kCursorNoDrop,
26 ui::kCursorNotAllowed,
27 ui::kCursorCopy,
28 ui::kCursorHand,
29 ui::kCursorMove,
30 ui::kCursorNorthEastResize,
31 ui::kCursorSouthWestResize,
32 ui::kCursorSouthEastResize,
33 ui::kCursorNorthWestResize,
34 ui::kCursorNorthResize,
35 ui::kCursorSouthResize,
36 ui::kCursorEastResize,
37 ui::kCursorWestResize,
38 ui::kCursorIBeam,
39 ui::kCursorAlias,
40 ui::kCursorCell,
41 ui::kCursorContextMenu,
42 ui::kCursorCross,
43 ui::kCursorHelp,
44 ui::kCursorVerticalText,
45 ui::kCursorZoomIn,
46 ui::kCursorZoomOut,
47 ui::kCursorRowResize,
48 ui::kCursorColumnResize,
49 ui::kCursorEastWestResize,
50 ui::kCursorNorthSouthResize,
51 ui::kCursorNorthEastSouthWestResize,
52 ui::kCursorNorthWestSouthEastResize,
53 ui::kCursorGrab,
54 ui::kCursorGrabbing,
55 };
56
57 const int kAnimatedCursorIds[] = {
58 ui::kCursorWait,
59 ui::kCursorProgress
60 };
61
62 ImageCursors::ImageCursors() : cursor_set_(ui::CURSOR_SET_NORMAL) {
63 }
64
65 ImageCursors::~ImageCursors() {
66 }
67
68 float ImageCursors::GetScale() const {
69 if (!cursor_loader_) {
70 NOTREACHED();
71 // Returning default on release build as it's not serious enough to crash
72 // even if this ever happens.
73 return 1.0f;
74 }
75 return cursor_loader_->scale();
76 }
77
78 gfx::Display::Rotation ImageCursors::GetRotation() const {
79 if (!cursor_loader_) {
80 NOTREACHED();
81 // Returning default on release build as it's not serious enough to crash
82 // even if this ever happens.
83 return gfx::Display::ROTATE_0;
84 }
85 return cursor_loader_->rotation();
86 }
87
88 bool ImageCursors::SetDisplay(const gfx::Display& display) {
89 DCHECK(display.is_valid());
90 // Use the platform's device scale factor instead of display's
91 // that might have been adjusted for UI scale.
92 float scale_factor = Shell::GetInstance()->display_manager()->
93 GetDisplayInfo(display.id()).device_scale_factor();
94
95 if (!cursor_loader_) {
96 cursor_loader_.reset(ui::CursorLoader::Create());
97 } else if (cursor_loader_->rotation() == display.rotation() &&
98 cursor_loader_->scale() == scale_factor) {
99 return false;
100 }
101
102 cursor_loader_->set_rotation(display.rotation());
103 cursor_loader_->set_scale(scale_factor);
104 ReloadCursors();
105 return true;
106 }
107
108 void ImageCursors::ReloadCursors() {
109 float device_scale_factor = cursor_loader_->scale();
110
111 cursor_loader_->UnloadAll();
112
113 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) {
114 int resource_id = -1;
115 gfx::Point hot_point;
116 bool success = ui::GetCursorDataFor(cursor_set_,
117 kImageCursorIds[i],
118 device_scale_factor,
119 &resource_id,
120 &hot_point);
121 DCHECK(success);
122 cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point);
123 }
124 for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) {
125 int resource_id = -1;
126 gfx::Point hot_point;
127 bool success = ui::GetAnimatedCursorDataFor(cursor_set_,
128 kAnimatedCursorIds[i],
129 device_scale_factor,
130 &resource_id,
131 &hot_point);
132 DCHECK(success);
133 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i],
134 resource_id,
135 hot_point,
136 ui::kAnimatedCursorFrameDelayMs);
137 }
138 }
139
140 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) {
141 if (cursor_set_ == cursor_set)
142 return;
143
144 cursor_set_ = cursor_set;
145
146 if (cursor_loader_.get())
147 ReloadCursors();
148 }
149
150 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) {
151 cursor_loader_->SetPlatformCursor(cursor);
152 }
153
154 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/image_cursors.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698