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

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, 9 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 visible_(true), 96 visible_(true),
97 cursor_set_(ui::CURSOR_SET_NORMAL), 97 cursor_set_(ui::CURSOR_SET_NORMAL),
98 cursor_rotation_(gfx::Display::ROTATE_0),
99 delegate_(new CursorWindowDelegate()) { 98 delegate_(new CursorWindowDelegate()) {
100 } 99 }
101 100
102 CursorWindowController::~CursorWindowController() { 101 CursorWindowController::~CursorWindowController() {
103 SetContainer(NULL); 102 SetContainer(NULL);
104 } 103 }
105 104
106 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) { 105 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) {
107 if (is_cursor_compositing_enabled_ != enabled) { 106 if (is_cursor_compositing_enabled_ != enabled) {
108 is_cursor_compositing_enabled_ = enabled; 107 is_cursor_compositing_enabled_ = enabled;
(...skipping 13 matching lines...) Expand all
122 SetDisplay(display); 121 SetDisplay(display);
123 } else { 122 } else {
124 aura::Window* mirror_window = Shell::GetInstance()-> 123 aura::Window* mirror_window = Shell::GetInstance()->
125 display_controller()-> 124 display_controller()->
126 mirror_window_controller()-> 125 mirror_window_controller()->
127 GetWindow(); 126 GetWindow();
128 if (mirror_window) 127 if (mirror_window)
129 display_ = Shell::GetScreen()->GetPrimaryDisplay(); 128 display_ = Shell::GetScreen()->GetPrimaryDisplay();
130 SetContainer(mirror_window); 129 SetContainer(mirror_window);
131 } 130 }
132 // Updates the hot point based on the current display/container. 131 // Updates the hot point based on the current display.
133 UpdateCursorImage(); 132 UpdateCursorImage();
134 } 133 }
135 134
136 void CursorWindowController::SetDisplay(const gfx::Display& display) { 135 void CursorWindowController::SetDisplay(const gfx::Display& display) {
137 if (!is_cursor_compositing_enabled_) 136 if (!is_cursor_compositing_enabled_)
138 return; 137 return;
139 138
140 display_ = display; 139 display_ = display;
141 aura::Window* root_window = Shell::GetInstance()->display_controller()-> 140 aura::Window* root_window = Shell::GetInstance()->display_controller()->
142 GetRootWindowForDisplayId(display.id()); 141 GetRootWindowForDisplayId(display.id());
143 if (!root_window) 142 if (!root_window)
144 return; 143 return;
145 144
146 SetContainer(GetRootWindowController(root_window)->GetContainer( 145 SetContainer(GetRootWindowController(root_window)->GetContainer(
147 kShellWindowId_MouseCursorContainer)); 146 kShellWindowId_MouseCursorContainer));
148 SetBoundsInScreen(display.bounds()); 147 SetBoundsInScreen(display.bounds());
148 // Updates the hot point based on the current display.
149 UpdateCursorImage();
149 } 150 }
150 151
151 void CursorWindowController::UpdateLocation() { 152 void CursorWindowController::UpdateLocation() {
152 if (!cursor_window_) 153 if (!cursor_window_)
153 return; 154 return;
154 gfx::Point point = aura::Env::GetInstance()->last_mouse_location(); 155 gfx::Point point = aura::Env::GetInstance()->last_mouse_location();
155 if (!is_cursor_compositing_enabled_) { 156 if (!is_cursor_compositing_enabled_) {
156 Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point); 157 Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point);
157 } else { 158 } else {
158 point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y()); 159 point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y());
159 } 160 }
160 point.Offset(-hot_point_.x(), -hot_point_.y()); 161 point.Offset(-hot_point_.x(), -hot_point_.y());
161 gfx::Rect bounds = cursor_window_->bounds(); 162 gfx::Rect bounds = cursor_window_->bounds();
162 bounds.set_origin(point); 163 bounds.set_origin(point);
163 cursor_window_->SetBounds(bounds); 164 cursor_window_->SetBounds(bounds);
164 } 165 }
165 166
166 void CursorWindowController::SetCursor(gfx::NativeCursor cursor) { 167 void CursorWindowController::SetCursor(gfx::NativeCursor cursor) {
167 if (cursor_type_ == cursor.native_type() && 168 if (cursor_type_ == cursor.native_type())
168 cursor_rotation_ == display_.rotation())
169 return; 169 return;
170 cursor_type_ = cursor.native_type(); 170 cursor_type_ = cursor.native_type();
171 cursor_rotation_ = display_.rotation();
172 UpdateCursorImage(); 171 UpdateCursorImage();
173 UpdateCursorVisibility(); 172 UpdateCursorVisibility();
174 } 173 }
175 174
176 void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) { 175 void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) {
177 cursor_set_ = cursor_set; 176 cursor_set_ = cursor_set;
178 UpdateCursorImage(); 177 UpdateCursorImage();
179 } 178 }
180 179
181 void CursorWindowController::SetVisibility(bool visible) { 180 void CursorWindowController::SetVisibility(bool visible) {
(...skipping 12 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 UpdateCursorVisibility(); 207 UpdateCursorVisibility();
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 28 matching lines...) Expand all
269 if (!cursor_window_) 269 if (!cursor_window_)
270 return; 270 return;
271 bool visible = (visible_ && cursor_type_ != ui::kCursorNone); 271 bool visible = (visible_ && cursor_type_ != ui::kCursorNone);
272 if (visible) 272 if (visible)
273 cursor_window_->Show(); 273 cursor_window_->Show();
274 else 274 else
275 cursor_window_->Hide(); 275 cursor_window_->Hide();
276 } 276 }
277 277
278 } // namespace ash 278 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/cursor_window_controller.h ('k') | ash/display/cursor_window_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698