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

Side by Side Diff: ash/display/cursor_window_controller.cc

Issue 948583005: Add more tests for mouse rotation,scale&position after display change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "ash/display/cursor_window_controller.h" 5 #include "ash/display/cursor_window_controller.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/display/mirror_window_controller.h" 8 #include "ash/display/mirror_window_controller.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 gfx::Size size_; 87 gfx::Size size_;
88 88
89 DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate); 89 DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate);
90 }; 90 };
91 91
92 CursorWindowController::CursorWindowController() 92 CursorWindowController::CursorWindowController()
93 : is_cursor_compositing_enabled_(false), 93 : is_cursor_compositing_enabled_(false),
94 container_(NULL), 94 container_(NULL),
95 cursor_type_(ui::kCursorNone), 95 cursor_type_(ui::kCursorNone),
96 cursor_set_(ui::CURSOR_SET_NORMAL), 96 cursor_set_(ui::CURSOR_SET_NORMAL),
97 cursor_rotation_(gfx::Display::ROTATE_0),
98 delegate_(new CursorWindowDelegate()) { 97 delegate_(new CursorWindowDelegate()) {
99 } 98 }
100 99
101 CursorWindowController::~CursorWindowController() { 100 CursorWindowController::~CursorWindowController() {
102 SetContainer(NULL); 101 SetContainer(NULL);
103 } 102 }
104 103
105 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) { 104 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) {
106 if (is_cursor_compositing_enabled_ != enabled) { 105 if (is_cursor_compositing_enabled_ != enabled) {
107 is_cursor_compositing_enabled_ = enabled; 106 is_cursor_compositing_enabled_ = enabled;
(...skipping 13 matching lines...) Expand all
121 SetDisplay(display); 120 SetDisplay(display);
122 } else { 121 } else {
123 aura::Window* mirror_window = Shell::GetInstance()-> 122 aura::Window* mirror_window = Shell::GetInstance()->
124 display_controller()-> 123 display_controller()->
125 mirror_window_controller()-> 124 mirror_window_controller()->
126 GetWindow(); 125 GetWindow();
127 if (mirror_window) 126 if (mirror_window)
128 display_ = Shell::GetScreen()->GetPrimaryDisplay(); 127 display_ = Shell::GetScreen()->GetPrimaryDisplay();
129 SetContainer(mirror_window); 128 SetContainer(mirror_window);
130 } 129 }
131 // Updates the hot point based on the current display/container. 130 // Updates the hot point based on the current display.
132 UpdateCursorImage(); 131 UpdateCursorImage();
133 } 132 }
134 133
135 void CursorWindowController::SetDisplay(const gfx::Display& display) { 134 void CursorWindowController::SetDisplay(const gfx::Display& display) {
136 if (!is_cursor_compositing_enabled_) 135 if (!is_cursor_compositing_enabled_)
137 return; 136 return;
138 137
139 display_ = display; 138 display_ = display;
140 aura::Window* root_window = Shell::GetInstance()->display_controller()-> 139 aura::Window* root_window = Shell::GetInstance()->display_controller()->
141 GetRootWindowForDisplayId(display.id()); 140 GetRootWindowForDisplayId(display.id());
142 if (!root_window) 141 if (!root_window)
143 return; 142 return;
144 143
145 SetContainer(GetRootWindowController(root_window)->GetContainer( 144 SetContainer(GetRootWindowController(root_window)->GetContainer(
146 kShellWindowId_MouseCursorContainer)); 145 kShellWindowId_MouseCursorContainer));
147 SetBoundsInScreen(display.bounds()); 146 SetBoundsInScreen(display.bounds());
147 // Updates the hot point based on the current display.
148 UpdateCursorImage();
oshima 2015/03/09 23:08:20 can you move the method to private, then you don't
pkotwicz 2015/03/10 03:13:05 I don't think I understand your comment. CursorWi
148 } 149 }
149 150
150 void CursorWindowController::UpdateLocation() { 151 void CursorWindowController::UpdateLocation() {
151 if (!cursor_window_) 152 if (!cursor_window_)
152 return; 153 return;
153 gfx::Point point = aura::Env::GetInstance()->last_mouse_location(); 154 gfx::Point point = aura::Env::GetInstance()->last_mouse_location();
154 if (!is_cursor_compositing_enabled_) { 155 if (!is_cursor_compositing_enabled_) {
155 Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point); 156 Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point);
156 } else { 157 } else {
157 point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y()); 158 point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y());
158 } 159 }
159 point.Offset(-hot_point_.x(), -hot_point_.y()); 160 point.Offset(-hot_point_.x(), -hot_point_.y());
160 gfx::Rect bounds = cursor_window_->bounds(); 161 gfx::Rect bounds = cursor_window_->bounds();
161 bounds.set_origin(point); 162 bounds.set_origin(point);
162 cursor_window_->SetBounds(bounds); 163 cursor_window_->SetBounds(bounds);
163 } 164 }
164 165
165 void CursorWindowController::SetCursor(gfx::NativeCursor cursor) { 166 void CursorWindowController::SetCursor(gfx::NativeCursor cursor) {
166 if (cursor_type_ == cursor.native_type() && 167 if (cursor_type_ == cursor.native_type())
167 cursor_rotation_ == display_.rotation())
168 return; 168 return;
169 cursor_type_ = cursor.native_type(); 169 cursor_type_ = cursor.native_type();
170 cursor_rotation_ = display_.rotation();
171 UpdateCursorImage(); 170 UpdateCursorImage();
172 } 171 }
173 172
174 void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) { 173 void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) {
175 cursor_set_ = cursor_set; 174 cursor_set_ = cursor_set;
176 UpdateCursorImage(); 175 UpdateCursorImage();
177 } 176 }
178 177
179 void CursorWindowController::SetVisibility(bool visible) { 178 void CursorWindowController::SetVisibility(bool visible) {
180 if (!cursor_window_) 179 if (!cursor_window_)
(...skipping 13 matching lines...) Expand all
194 return; 193 return;
195 } 194 }
196 195
197 // Reusing the window does not work when the display is disconnected. 196 // Reusing the window does not work when the display is disconnected.
198 // Just creates a new one instead. crbug.com/384218. 197 // Just creates a new one instead. crbug.com/384218.
199 cursor_window_.reset(new aura::Window(delegate_.get())); 198 cursor_window_.reset(new aura::Window(delegate_.get()));
200 cursor_window_->SetTransparent(true); 199 cursor_window_->SetTransparent(true);
201 cursor_window_->Init(aura::WINDOW_LAYER_TEXTURED); 200 cursor_window_->Init(aura::WINDOW_LAYER_TEXTURED);
202 cursor_window_->set_ignore_events(true); 201 cursor_window_->set_ignore_events(true);
203 cursor_window_->set_owned_by_parent(false); 202 cursor_window_->set_owned_by_parent(false);
203 // Call UpdateCursorImage() to figure out |cursor_window_|'s desired size.
204 UpdateCursorImage(); 204 UpdateCursorImage();
205 205
206 container->AddChild(cursor_window_.get()); 206 container->AddChild(cursor_window_.get());
207 cursor_window_->Show(); 207 cursor_window_->Show();
208 SetBoundsInScreen(container->bounds()); 208 SetBoundsInScreen(container->bounds());
209 } 209 }
210 210
211 void CursorWindowController::SetBoundsInScreen(const gfx::Rect& bounds) { 211 void CursorWindowController::SetBoundsInScreen(const gfx::Rect& bounds) {
212 bounds_in_screen_ = bounds; 212 bounds_in_screen_ = bounds;
213 UpdateLocation(); 213 UpdateLocation();
214 } 214 }
215 215
216 void CursorWindowController::UpdateCursorImage() { 216 void CursorWindowController::UpdateCursorImage() {
217 int resource_id; 217 int resource_id;
218 // TODO(hshi): support custom cursor set. 218 // TODO(hshi): support custom cursor set.
219 if (!ui::GetCursorDataFor(cursor_set_, 219 if (!ui::GetCursorDataFor(cursor_set_,
220 cursor_type_, 220 cursor_type_,
221 display_.device_scale_factor(), 221 display_.device_scale_factor(),
222 &resource_id, 222 &resource_id,
223 &hot_point_)) { 223 &hot_point_)) {
224 return; 224 return;
225 } 225 }
226 const gfx::ImageSkia* image = 226 const gfx::ImageSkia* image =
227 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 227 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
228 gfx::ImageSkia rotated = *image; 228 gfx::ImageSkia rotated = *image;
229 if (!is_cursor_compositing_enabled_) { 229 if (!is_cursor_compositing_enabled_) {
230 switch (cursor_rotation_) { 230 switch (display_.rotation()) {
231 case gfx::Display::ROTATE_0: 231 case gfx::Display::ROTATE_0:
232 break; 232 break;
233 case gfx::Display::ROTATE_90: 233 case gfx::Display::ROTATE_90:
234 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( 234 rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
235 *image, SkBitmapOperations::ROTATION_90_CW); 235 *image, SkBitmapOperations::ROTATION_90_CW);
236 hot_point_.SetPoint( 236 hot_point_.SetPoint(
237 rotated.width() - hot_point_.y(), 237 rotated.width() - hot_point_.y(),
238 hot_point_.x()); 238 hot_point_.x());
239 break; 239 break;
240 case gfx::Display::ROTATE_180: 240 case gfx::Display::ROTATE_180:
(...skipping 18 matching lines...) Expand all
259 delegate_->SetCursorImage(rotated, display_); 259 delegate_->SetCursorImage(rotated, display_);
260 if (cursor_window_) { 260 if (cursor_window_) {
261 cursor_window_->SetBounds(gfx::Rect(delegate_->size())); 261 cursor_window_->SetBounds(gfx::Rect(delegate_->size()));
262 cursor_window_->SchedulePaintInRect( 262 cursor_window_->SchedulePaintInRect(
263 gfx::Rect(cursor_window_->bounds().size())); 263 gfx::Rect(cursor_window_->bounds().size()));
264 UpdateLocation(); 264 UpdateLocation();
265 } 265 }
266 } 266 }
267 267
268 } // namespace ash 268 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698