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

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: 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 cursor_loader_->set_scale(scale_factor);
tdanderson 2014/04/22 17:28:10 Would set_rotation() be needed here too?
oshima 2014/04/23 01:47:11 This was actually redundant (They're updated after
80 } else if (cursor_loader_->display().rotation() == display.rotation() && 98 } else if (cursor_loader_->rotation() == display.rotation() &&
81 cursor_loader_->display().device_scale_factor() == 99 cursor_loader_->scale() == scale_factor) {
82 device_scale_factor) {
83 return false; 100 return false;
84 } 101 }
85 102
86 cursor_loader_->set_display(display); 103 cursor_loader_->set_rotation(display.rotation());
104 cursor_loader_->set_scale(scale_factor);
87 ReloadCursors(); 105 ReloadCursors();
88 return true; 106 return true;
89 } 107 }
90 108
91 void ImageCursors::ReloadCursors() { 109 void ImageCursors::ReloadCursors() {
92 const gfx::Display& display = cursor_loader_->display(); 110 float device_scale_factor = cursor_loader_->scale();
93 float device_scale_factor = display.device_scale_factor();
94 111
95 cursor_loader_->UnloadAll(); 112 cursor_loader_->UnloadAll();
96 113
97 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { 114 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) {
98 int resource_id = -1; 115 int resource_id = -1;
99 gfx::Point hot_point; 116 gfx::Point hot_point;
100 bool success = ui::GetCursorDataFor(cursor_set_, 117 bool success = ui::GetCursorDataFor(cursor_set_,
101 kImageCursorIds[i], 118 kImageCursorIds[i],
102 device_scale_factor, 119 device_scale_factor,
103 &resource_id, 120 &resource_id,
(...skipping 10 matching lines...) Expand all
114 &resource_id, 131 &resource_id,
115 &hot_point); 132 &hot_point);
116 DCHECK(success); 133 DCHECK(success);
117 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], 134 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i],
118 resource_id, 135 resource_id,
119 hot_point, 136 hot_point,
120 ui::kAnimatedCursorFrameDelayMs); 137 ui::kAnimatedCursorFrameDelayMs);
121 } 138 }
122 } 139 }
123 140
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) { 141 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) {
139 if (cursor_set_ == cursor_set) 142 if (cursor_set_ == cursor_set)
140 return; 143 return;
141 144
142 cursor_set_ = cursor_set; 145 cursor_set_ = cursor_set;
143 146
144 if (cursor_loader_.get()) 147 if (cursor_loader_.get())
145 ReloadCursors(); 148 ReloadCursors();
146 } 149 }
147 150
148 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { 151 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) {
149 cursor_loader_->SetPlatformCursor(cursor); 152 cursor_loader_->SetPlatformCursor(cursor);
150 } 153 }
151 154
152 } // namespace ash 155 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698