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

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

Issue 226293005: Use platform's device scale factor for cursor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new tests Created 6 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/wm/image_cursors.h" 5 #include "ash/wm/image_cursors.h"
6 6
7 #include <float.h> 7 #include <float.h>
8 8
9 #include "ash/display/display_info.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h"
9 #include "base/logging.h" 12 #include "base/logging.h"
10 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
11 #include "ui/base/cursor/cursor.h" 14 #include "ui/base/cursor/cursor.h"
12 #include "ui/base/cursor/cursor_loader.h" 15 #include "ui/base/cursor/cursor_loader.h"
13 #include "ui/base/cursor/cursors_aura.h" 16 #include "ui/base/cursor/cursors_aura.h"
14 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
15 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
16 19
17 namespace ash { 20 namespace ash {
18 21
(...skipping 30 matching lines...) Expand all
49 ui::kCursorNorthWestSouthEastResize, 52 ui::kCursorNorthWestSouthEastResize,
50 ui::kCursorGrab, 53 ui::kCursorGrab,
51 ui::kCursorGrabbing, 54 ui::kCursorGrabbing,
52 }; 55 };
53 56
54 const int kAnimatedCursorIds[] = { 57 const int kAnimatedCursorIds[] = {
55 ui::kCursorWait, 58 ui::kCursorWait,
56 ui::kCursorProgress 59 ui::kCursorProgress
57 }; 60 };
58 61
59 ImageCursors::ImageCursors() : scale_(1.f), cursor_set_(ui::CURSOR_SET_NORMAL) { 62 ImageCursors::ImageCursors() : cursor_set_(ui::CURSOR_SET_NORMAL) {
60 } 63 }
61 64
62 ImageCursors::~ImageCursors() { 65 ImageCursors::~ImageCursors() {
63 } 66 }
64 67
65 gfx::Display ImageCursors::GetDisplay() const { 68 float ImageCursors::GetScale() const {
66 if (!cursor_loader_) { 69 if (!cursor_loader_) {
67 NOTREACHED(); 70 NOTREACHED();
68 // Returning default on release build as it's not serious enough to crash 71 // Returning default on release build as it's not serious enough to crash
69 // even if this ever happens. 72 // even if this ever happens.
70 return gfx::Display(); 73 return 1.0f;
71 } 74 }
72 return cursor_loader_->display(); 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();
73 } 86 }
74 87
75 bool ImageCursors::SetDisplay(const gfx::Display& display) { 88 bool ImageCursors::SetDisplay(const gfx::Display& display) {
76 float device_scale_factor = display.device_scale_factor(); 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
77 if (!cursor_loader_) { 95 if (!cursor_loader_) {
78 cursor_loader_.reset(ui::CursorLoader::Create()); 96 cursor_loader_.reset(ui::CursorLoader::Create());
79 cursor_loader_->set_scale(scale_); 97 } else if (cursor_loader_->rotation() == display.rotation() &&
80 } else if (cursor_loader_->display().rotation() == display.rotation() && 98 cursor_loader_->scale() == scale_factor) {
81 cursor_loader_->display().device_scale_factor() ==
82 device_scale_factor) {
83 return false; 99 return false;
84 } 100 }
85 101
86 cursor_loader_->set_display(display); 102 cursor_loader_->set_rotation(display.rotation());
103 cursor_loader_->set_scale(scale_factor);
87 ReloadCursors(); 104 ReloadCursors();
88 return true; 105 return true;
89 } 106 }
90 107
91 void ImageCursors::ReloadCursors() { 108 void ImageCursors::ReloadCursors() {
92 const gfx::Display& display = cursor_loader_->display(); 109 float device_scale_factor = cursor_loader_->scale();
93 float device_scale_factor = display.device_scale_factor();
94 110
95 cursor_loader_->UnloadAll(); 111 cursor_loader_->UnloadAll();
96 112
97 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { 113 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) {
98 int resource_id = -1; 114 int resource_id = -1;
99 gfx::Point hot_point; 115 gfx::Point hot_point;
100 bool success = ui::GetCursorDataFor(cursor_set_, 116 bool success = ui::GetCursorDataFor(cursor_set_,
101 kImageCursorIds[i], 117 kImageCursorIds[i],
102 device_scale_factor, 118 device_scale_factor,
103 &resource_id, 119 &resource_id,
(...skipping 10 matching lines...) Expand all
114 &resource_id, 130 &resource_id,
115 &hot_point); 131 &hot_point);
116 DCHECK(success); 132 DCHECK(success);
117 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], 133 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i],
118 resource_id, 134 resource_id,
119 hot_point, 135 hot_point,
120 ui::kAnimatedCursorFrameDelayMs); 136 ui::kAnimatedCursorFrameDelayMs);
121 } 137 }
122 } 138 }
123 139
124 void ImageCursors::SetScale(float scale) {
125 if (scale < FLT_EPSILON) {
126 NOTREACHED() << "Scale must be bigger than 0.";
127 scale = 1.0f;
128 }
129
130 scale_ = scale;
131
132 if (cursor_loader_.get()) {
133 cursor_loader_->set_scale(scale);
134 ReloadCursors();
135 }
136 }
137
138 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) { 140 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) {
139 if (cursor_set_ == cursor_set) 141 if (cursor_set_ == cursor_set)
140 return; 142 return;
141 143
142 cursor_set_ = cursor_set; 144 cursor_set_ = cursor_set;
143 145
144 if (cursor_loader_.get()) 146 if (cursor_loader_.get())
145 ReloadCursors(); 147 ReloadCursors();
146 } 148 }
147 149
148 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { 150 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) {
149 cursor_loader_->SetPlatformCursor(cursor); 151 cursor_loader_->SetPlatformCursor(cursor);
150 } 152 }
151 153
152 } // namespace ash 154 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698