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

Side by Side Diff: ash/magnifier/magnification_controller.cc

Issue 12328030: Magnifier: add validation of root window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/magnifier/magnification_controller.h" 5 #include "ash/magnifier/magnification_controller.h"
6 6
7 #include "ash/display/display_controller.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.h"
9 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ui/aura/client/cursor_client.h" 11 #include "ui/aura/client/cursor_client.h"
11 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
12 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
13 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
14 #include "ui/base/events/event.h" 15 #include "ui/base/events/event.h"
15 #include "ui/base/events/event_handler.h" 16 #include "ui/base/events/event_handler.h"
16 #include "ui/compositor/dip_util.h" 17 #include "ui/compositor/dip_util.h"
(...skipping 13 matching lines...) Expand all
30 const float kMinMagnifiedScaleThreshold = 1.1f; 31 const float kMinMagnifiedScaleThreshold = 1.1f;
31 const float kNonMagnifiedScale = 1.0f; 32 const float kNonMagnifiedScale = 1.0f;
32 33
33 const float kInitialMagnifiedScale = 2.0f; 34 const float kInitialMagnifiedScale = 2.0f;
34 const float kScrollScaleChangeFactor = 0.05f; 35 const float kScrollScaleChangeFactor = 0.05f;
35 36
36 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of 37 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of
37 // |kPanningMergin| from the edge, the view-port moves. 38 // |kPanningMergin| from the edge, the view-port moves.
38 const int kPanningMergin = 100; 39 const int kPanningMergin = 100;
39 40
41 bool IsRootWindowValid(aura::RootWindow* root_window) {
42 if (!root_window)
43 return false;
44
45 std::vector<aura::RootWindow*> root_windows =
46 ash::Shell::GetInstance()->display_controller()->GetAllRootWindows();
47 if (std::find(root_windows.begin(), root_windows.end(), root_window) !=
48 root_windows.end()) {
49 return true;
50 }
51
52 return false;
53 }
oshima 2013/02/21 16:45:06 Just return std::find(...) != root_windows.end();
yoshiki 2013/02/25 12:32:44 Done.
54
40 } // namespace 55 } // namespace
41 56
42 namespace ash { 57 namespace ash {
43 58
44 //////////////////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////////////
45 // MagnificationControllerImpl: 60 // MagnificationControllerImpl:
46 61
47 class MagnificationControllerImpl : virtual public MagnificationController, 62 class MagnificationControllerImpl : virtual public MagnificationController,
48 public ui::EventHandler, 63 public ui::EventHandler,
49 public ui::ImplicitAnimationObserver { 64 public ui::ImplicitAnimationObserver,
65 public aura::WindowObserver {
50 public: 66 public:
51 MagnificationControllerImpl(); 67 MagnificationControllerImpl();
52 virtual ~MagnificationControllerImpl(); 68 virtual ~MagnificationControllerImpl();
53 69
54 // MagnificationController overrides: 70 // MagnificationController overrides:
55 virtual void SetEnabled(bool enabled) OVERRIDE; 71 virtual void SetEnabled(bool enabled) OVERRIDE;
56 virtual bool IsEnabled() const OVERRIDE; 72 virtual bool IsEnabled() const OVERRIDE;
57 virtual void SetScale(float scale, bool animate) OVERRIDE; 73 virtual void SetScale(float scale, bool animate) OVERRIDE;
58 virtual float GetScale() const OVERRIDE { return scale_; } 74 virtual float GetScale() const OVERRIDE { return scale_; }
59 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; 75 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE;
60 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; 76 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE;
61 virtual gfx::Point GetWindowPosition() const OVERRIDE { 77 virtual gfx::Point GetWindowPosition() const OVERRIDE {
62 return gfx::ToFlooredPoint(origin_); 78 return gfx::ToFlooredPoint(origin_);
63 } 79 }
64 virtual void EnsureRectIsVisible(const gfx::Rect& rect, 80 virtual void EnsureRectIsVisible(const gfx::Rect& rect,
65 bool animate) OVERRIDE; 81 bool animate) OVERRIDE;
66 virtual void EnsurePointIsVisible(const gfx::Point& point, 82 virtual void EnsurePointIsVisible(const gfx::Point& point,
67 bool animate) OVERRIDE; 83 bool animate) OVERRIDE;
68 84
69 private: 85 private:
70 // ui::ImplicitAnimationObserver overrides: 86 // ui::ImplicitAnimationObserver overrides:
71 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 87 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
72 88
89 // aura::WindowObserver overrides:
90 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE;
91
73 // Redraws the magnification window with the given origin position and the 92 // Redraws the magnification window with the given origin position and the
74 // given scale. Returns true if the window is changed; otherwise, false. 93 // given scale. Returns true if the window is changed; otherwise, false.
75 // These methods should be called internally just after the scale and/or 94 // These methods should be called internally just after the scale and/or
76 // the position are changed to redraw the window. 95 // the position are changed to redraw the window.
77 bool Redraw(const gfx::PointF& position, float scale, bool animate); 96 bool Redraw(const gfx::PointF& position, float scale, bool animate);
78 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); 97 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate);
79 98
80 // Redraw with the given zoom scale keeping the mouse cursor location. In 99 // Redraw with the given zoom scale keeping the mouse cursor location. In
81 // other words, zoom (or unzoom) centering around the cursor. 100 // other words, zoom (or unzoom) centering around the cursor.
82 void RedrawKeepingMousePosition(float scale, bool animate); 101 void RedrawKeepingMousePosition(float scale, bool animate);
(...skipping 16 matching lines...) Expand all
99 // the animation is completed. This should be called after animation is 118 // the animation is completed. This should be called after animation is
100 // started. 119 // started.
101 void AfterAnimationMoveCursorTo(const gfx::Point& location); 120 void AfterAnimationMoveCursorTo(const gfx::Point& location);
102 121
103 // Switch Magnified RootWindow to |new_root_window|. This does following: 122 // Switch Magnified RootWindow to |new_root_window|. This does following:
104 // - Unzoom the current root_window. 123 // - Unzoom the current root_window.
105 // - Zoom the given new root_window |new_root_window|. 124 // - Zoom the given new root_window |new_root_window|.
106 // - Switch the target window from current window to |new_root_window|. 125 // - Switch the target window from current window to |new_root_window|.
107 void SwitchTargetRootWindow(aura::RootWindow* new_root_window); 126 void SwitchTargetRootWindow(aura::RootWindow* new_root_window);
108 127
128 // Checks the current target root window is still alive or not. If it's stale,
129 // the current primary root window is newly assigned as the current target
130 // root window instead.
131 bool IsRootwindowStale();
132
109 // Returns if the magnification scale is 1.0 or not (larger then 1.0). 133 // Returns if the magnification scale is 1.0 or not (larger then 1.0).
110 bool IsMagnified() const; 134 bool IsMagnified() const;
111 135
112 // Returns the rect of the magnification window. 136 // Returns the rect of the magnification window.
113 gfx::RectF GetWindowRectDIP(float scale) const; 137 gfx::RectF GetWindowRectDIP(float scale) const;
114 // Returns the size of the root window. 138 // Returns the size of the root window.
115 gfx::Size GetHostSizeDIP() const; 139 gfx::Size GetHostSizeDIP() const;
116 140
117 // Correct the givin scale value if nessesary. 141 // Correct the givin scale value if nessesary.
118 void ValidateScale(float* scale); 142 void ValidateScale(float* scale);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (root_window_) 185 if (root_window_)
162 point_of_interest_ = root_window_->bounds().CenterPoint(); 186 point_of_interest_ = root_window_->bounds().CenterPoint();
163 } 187 }
164 188
165 MagnificationControllerImpl::~MagnificationControllerImpl() { 189 MagnificationControllerImpl::~MagnificationControllerImpl() {
166 Shell::GetInstance()->RemovePreTargetHandler(this); 190 Shell::GetInstance()->RemovePreTargetHandler(this);
167 } 191 }
168 192
169 void MagnificationControllerImpl::RedrawKeepingMousePosition( 193 void MagnificationControllerImpl::RedrawKeepingMousePosition(
170 float scale, bool animate) { 194 float scale, bool animate) {
195 CHECK(root_window_); // |root_window_| should be checked at the caller.
196
171 gfx::Point mouse_in_root = point_of_interest_; 197 gfx::Point mouse_in_root = point_of_interest_;
172 198
173 // mouse_in_root is invalid value when the cursor is hidden. 199 // mouse_in_root is invalid value when the cursor is hidden.
174 if (!root_window_->bounds().Contains(mouse_in_root)) 200 if (!root_window_->bounds().Contains(mouse_in_root))
175 mouse_in_root = root_window_->bounds().CenterPoint(); 201 mouse_in_root = root_window_->bounds().CenterPoint();
176 202
177 const gfx::PointF origin = 203 const gfx::PointF origin =
178 gfx::PointF(mouse_in_root.x() - 204 gfx::PointF(mouse_in_root.x() -
179 (scale_ / scale) * (mouse_in_root.x() - origin_.x()), 205 (scale_ / scale) * (mouse_in_root.x() - origin_.x()),
180 mouse_in_root.y() - 206 mouse_in_root.y() -
181 (scale_ / scale) * (mouse_in_root.y() - origin_.y())); 207 (scale_ / scale) * (mouse_in_root.y() - origin_.y()));
182 bool changed = RedrawDIP(origin, scale, animate); 208 bool changed = RedrawDIP(origin, scale, animate);
183 if (changed) 209 if (changed)
184 AfterAnimationMoveCursorTo(mouse_in_root); 210 AfterAnimationMoveCursorTo(mouse_in_root);
185 } 211 }
186 212
187 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, 213 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position,
188 float scale, 214 float scale,
189 bool animate) { 215 bool animate) {
216 CHECK(root_window_); // |root_window_| should be checked at the caller.
217
190 const gfx::PointF position_in_dip = 218 const gfx::PointF position_in_dip =
191 ui::ConvertPointToDIP(root_window_->layer(), position); 219 ui::ConvertPointToDIP(root_window_->layer(), position);
192 return RedrawDIP(position_in_dip, scale, animate); 220 return RedrawDIP(position_in_dip, scale, animate);
193 } 221 }
194 222
195 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip, 223 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip,
196 float scale, 224 float scale,
197 bool animate) { 225 bool animate) {
226 CHECK(root_window_); // |root_window_| should be checked at the caller.
227
198 float x = position_in_dip.x(); 228 float x = position_in_dip.x();
199 float y = position_in_dip.y(); 229 float y = position_in_dip.y();
200 230
201 ValidateScale(&scale); 231 ValidateScale(&scale);
202 232
203 if (x < 0) 233 if (x < 0)
204 x = 0; 234 x = 0;
205 if (y < 0) 235 if (y < 0)
206 y = 0; 236 y = 0;
207 237
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if (animate) 276 if (animate)
247 is_on_animation_ = true; 277 is_on_animation_ = true;
248 278
249 return true; 279 return true;
250 } 280 }
251 281
252 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale( 282 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale(
253 const gfx::Rect& target_rect, 283 const gfx::Rect& target_rect,
254 float scale, 284 float scale,
255 bool animate) { 285 bool animate) {
286 CHECK(root_window_); // |root_window_| should be checked at the caller.
287
256 const gfx::Rect target_rect_in_dip = 288 const gfx::Rect target_rect_in_dip =
257 ui::ConvertRectToDIP(root_window_->layer(), target_rect); 289 ui::ConvertRectToDIP(root_window_->layer(), target_rect);
258 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate); 290 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate);
259 } 291 }
260 292
261 void MagnificationControllerImpl::EnsureRectIsVisibleDIP( 293 void MagnificationControllerImpl::EnsureRectIsVisibleDIP(
262 const gfx::Rect& target_rect, 294 const gfx::Rect& target_rect,
263 float scale, 295 float scale,
264 bool animate) { 296 bool animate) {
265 ValidateScale(&scale); 297 ValidateScale(&scale);
(...skipping 26 matching lines...) Expand all
292 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale( 324 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale(
293 const gfx::Point& point, 325 const gfx::Point& point,
294 float scale, 326 float scale,
295 bool animate) { 327 bool animate) {
296 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)), 328 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)),
297 scale, 329 scale,
298 animate); 330 animate);
299 } 331 }
300 332
301 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { 333 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
334 CHECK(root_window_); // |root_window_| should be checked at the caller.
335
302 gfx::Point mouse(location); 336 gfx::Point mouse(location);
303 337
304 int x = origin_.x(); 338 int x = origin_.x();
305 int y = origin_.y(); 339 int y = origin_.y();
306 bool start_zoom = false; 340 bool start_zoom = false;
307 341
308 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); 342 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale_));
309 const int left = window_rect.x(); 343 const int left = window_rect.x();
310 const int right = window_rect.right(); 344 const int right = window_rect.right();
311 int margin = kPanningMergin / scale_; // No need to consider DPI. 345 int margin = kPanningMergin / scale_; // No need to consider DPI.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (ret) { 380 if (ret) {
347 // If the magnified region is moved, hides the mouse cursor and moves it. 381 // If the magnified region is moved, hides the mouse cursor and moves it.
348 if (x_diff != 0 || y_diff != 0) 382 if (x_diff != 0 || y_diff != 0)
349 root_window_->MoveCursorTo(mouse); 383 root_window_->MoveCursorTo(mouse);
350 } 384 }
351 } 385 }
352 } 386 }
353 387
354 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( 388 void MagnificationControllerImpl::AfterAnimationMoveCursorTo(
355 const gfx::Point& location) { 389 const gfx::Point& location) {
390 CHECK(root_window_); // |root_window_| should be checked at the caller.
391
356 aura::client::CursorClient* cursor_client = 392 aura::client::CursorClient* cursor_client =
357 aura::client::GetCursorClient(root_window_); 393 aura::client::GetCursorClient(root_window_);
358 if (cursor_client) { 394 if (cursor_client) {
359 // When cursor is invisible, do not move or show the cursor after the 395 // When cursor is invisible, do not move or show the cursor after the
360 // animation. 396 // animation.
361 if (!cursor_client->IsCursorVisible()) 397 if (!cursor_client->IsCursorVisible())
362 return; 398 return;
363 cursor_client->DisableMouseEvents(); 399 cursor_client->DisableMouseEvents();
364 } 400 }
365 move_cursor_after_animation_ = true; 401 move_cursor_after_animation_ = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 445
410 aura::client::CursorClient* cursor_client = 446 aura::client::CursorClient* cursor_client =
411 aura::client::GetCursorClient(root_window_); 447 aura::client::GetCursorClient(root_window_);
412 if (cursor_client) 448 if (cursor_client)
413 cursor_client->EnableMouseEvents(); 449 cursor_client->EnableMouseEvents();
414 } 450 }
415 451
416 is_on_animation_ = false; 452 is_on_animation_ = false;
417 } 453 }
418 454
455 void MagnificationControllerImpl::OnWindowDestroying(
456 aura::Window* root_window) {
457 if (root_window == root_window_)
458 root_window_ = NULL;
oshima 2013/02/21 16:45:06 Shouldn't you switch the root window here? This w
yoshiki 2013/02/25 12:32:44 Done. Switching root window here.
459 }
460
419 void MagnificationControllerImpl::SwitchTargetRootWindow( 461 void MagnificationControllerImpl::SwitchTargetRootWindow(
420 aura::RootWindow* new_root_window) { 462 aura::RootWindow* new_root_window) {
421 if (new_root_window == root_window_) 463 if (new_root_window == root_window_)
422 return; 464 return;
423 465
466 // Stores the previous scale.
424 float scale = GetScale(); 467 float scale = GetScale();
425 468
469 // Unmagnify the previous root window.
470 root_window_->RemoveObserver(this);
oshima 2013/02/21 16:45:06 root_window_ can be NULL at this point, can't it?
yoshiki 2013/02/25 12:32:44 Done. I've added the check.
426 RedrawKeepingMousePosition(1.0f, true); 471 RedrawKeepingMousePosition(1.0f, true);
427 root_window_ = new_root_window; 472
428 RedrawKeepingMousePosition(scale, true); 473 // Ensures that |new_root_window_| is valid.
474 if (IsRootWindowValid(new_root_window)) {
oshima 2013/02/21 16:45:06 Looking through call flow, this should never be fa
yoshiki 2013/02/25 12:32:44 Done.
475 root_window_ = new_root_window;
476 RedrawKeepingMousePosition(scale, true);
477 root_window_->AddObserver(this);
478 } else {
479 root_window_ = NULL;
480 }
481 }
482
483 bool MagnificationControllerImpl::IsRootwindowStale() {
oshima 2013/02/21 16:45:06 Changing a state inside predicate style method lik
yoshiki 2013/02/25 12:32:44 Removed.
484 // If the current target root window is stale, try to switch target to the
485 // primary root window.
486 if (!IsRootWindowValid(root_window_)) {
487 root_window_ = NULL;
488
489 aura::RootWindow* primary_root_window = Shell::GetPrimaryRootWindow();
490 SwitchTargetRootWindow(primary_root_window);
491
492 // When there are no root windows.
493 if (!root_window_)
494 return true;
495
496 point_of_interest_ = root_window_->bounds().CenterPoint();
497 }
498
499 return false;
429 } 500 }
430 501
431 //////////////////////////////////////////////////////////////////////////////// 502 ////////////////////////////////////////////////////////////////////////////////
432 // MagnificationControllerImpl: MagnificationController implementation 503 // MagnificationControllerImpl: MagnificationController implementation
433 504
434 void MagnificationControllerImpl::SetScale(float scale, bool animate) { 505 void MagnificationControllerImpl::SetScale(float scale, bool animate) {
435 if (!is_enabled_) 506 if (!is_enabled_ || IsRootwindowStale())
436 return; 507 return;
437 508
438 ValidateScale(&scale); 509 ValidateScale(&scale);
439 ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale); 510 ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale);
440 RedrawKeepingMousePosition(scale, animate); 511 RedrawKeepingMousePosition(scale, animate);
441 } 512 }
442 513
443 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { 514 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) {
444 if (!is_enabled_) 515 if (!is_enabled_ || IsRootwindowStale())
445 return; 516 return;
446 517
447 Redraw(gfx::Point(x, y), scale_, animate); 518 Redraw(gfx::Point(x, y), scale_, animate);
448 } 519 }
449 520
450 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, 521 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point,
451 bool animate) { 522 bool animate) {
452 if (!is_enabled_) 523 if (!is_enabled_ || IsRootwindowStale())
453 return; 524 return;
454 525
455 Redraw(point, scale_, animate); 526 Redraw(point, scale_, animate);
456 } 527 }
457 528
458 void MagnificationControllerImpl::EnsureRectIsVisible( 529 void MagnificationControllerImpl::EnsureRectIsVisible(
459 const gfx::Rect& target_rect, 530 const gfx::Rect& target_rect,
460 bool animate) { 531 bool animate) {
461 if (!is_enabled_) 532 if (!is_enabled_ || IsRootwindowStale())
462 return; 533 return;
463 534
464 EnsureRectIsVisibleWithScale(target_rect, scale_, animate); 535 EnsureRectIsVisibleWithScale(target_rect, scale_, animate);
465 } 536 }
466 537
467 void MagnificationControllerImpl::EnsurePointIsVisible( 538 void MagnificationControllerImpl::EnsurePointIsVisible(
468 const gfx::Point& point, 539 const gfx::Point& point,
469 bool animate) { 540 bool animate) {
470 if (!is_enabled_) 541 if (!is_enabled_ || IsRootwindowStale())
471 return; 542 return;
472 543
473 EnsurePointIsVisibleWithScale(point, scale_, animate); 544 EnsurePointIsVisibleWithScale(point, scale_, animate);
474 } 545 }
475 546
476 void MagnificationControllerImpl::SetEnabled(bool enabled) { 547 void MagnificationControllerImpl::SetEnabled(bool enabled) {
548 if (IsRootwindowStale())
549 return;
550
477 if (enabled) { 551 if (enabled) {
478 float scale = 552 float scale =
479 ash::Shell::GetInstance()->delegate()->GetSavedScreenMagnifierScale(); 553 ash::Shell::GetInstance()->delegate()->GetSavedScreenMagnifierScale();
480 if (scale <= 0.0f) 554 if (scale <= 0.0f)
481 scale = kInitialMagnifiedScale; 555 scale = kInitialMagnifiedScale;
482 ValidateScale(&scale); 556 ValidateScale(&scale);
483 557
484 // Do nothing, if already enabled with same scale. 558 // Do nothing, if already enabled with same scale.
485 if (is_enabled_ && scale == scale_) 559 if (is_enabled_ && scale == scale_)
486 return; 560 return;
(...skipping 17 matching lines...) Expand all
504 578
505 //////////////////////////////////////////////////////////////////////////////// 579 ////////////////////////////////////////////////////////////////////////////////
506 // MagnificationControllerImpl: aura::EventFilter implementation 580 // MagnificationControllerImpl: aura::EventFilter implementation
507 581
508 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) { 582 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
509 aura::Window* target = static_cast<aura::Window*>(event->target()); 583 aura::Window* target = static_cast<aura::Window*>(event->target());
510 aura::RootWindow* current_root = target->GetRootWindow(); 584 aura::RootWindow* current_root = target->GetRootWindow();
511 gfx::Rect root_bounds = current_root->bounds(); 585 gfx::Rect root_bounds = current_root->bounds();
512 586
513 if (root_bounds.Contains(event->root_location())) { 587 if (root_bounds.Contains(event->root_location())) {
588 // This must be before |SwitchTargetRootWindow()|.
589 point_of_interest_ = event->root_location();
590
514 if (current_root != root_window_) 591 if (current_root != root_window_)
515 SwitchTargetRootWindow(current_root); 592 SwitchTargetRootWindow(current_root);
516 593
517 point_of_interest_ = event->root_location(); 594 if (IsMagnified() && root_window_ && event->type() == ui::ET_MOUSE_MOVED)
518
519 if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED)
520 OnMouseMove(event->root_location()); 595 OnMouseMove(event->root_location());
521 } 596 }
522 } 597 }
523 598
524 void MagnificationControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { 599 void MagnificationControllerImpl::OnScrollEvent(ui::ScrollEvent* event) {
525 if (event->IsAltDown() && event->IsControlDown()) { 600 if (event->IsAltDown() && event->IsControlDown()) {
526 if (event->type() == ui::ET_SCROLL_FLING_START || 601 if (event->type() == ui::ET_SCROLL_FLING_START ||
527 event->type() == ui::ET_SCROLL_FLING_CANCEL) { 602 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
528 event->StopPropagation(); 603 event->StopPropagation();
529 return; 604 return;
530 } 605 }
531 606
532 if (event->type() == ui::ET_SCROLL) { 607 if (event->type() == ui::ET_SCROLL) {
533 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); 608 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event);
534 float scale = GetScale(); 609 float scale = GetScale();
535 scale += scroll_event->y_offset() * kScrollScaleChangeFactor; 610 scale += scroll_event->y_offset() * kScrollScaleChangeFactor;
536 SetScale(scale, true); 611 SetScale(scale, true);
537 event->StopPropagation(); 612 event->StopPropagation();
538 return; 613 return;
539 } 614 }
540 } 615 }
541 } 616 }
542 617
543 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { 618 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) {
544 aura::Window* target = static_cast<aura::Window*>(event->target()); 619 aura::Window* target = static_cast<aura::Window*>(event->target());
545 aura::RootWindow* current_root = target->GetRootWindow(); 620 aura::RootWindow* current_root = target->GetRootWindow();
546 if (current_root == root_window_) { 621 if (current_root && current_root == root_window_) {
547 gfx::Rect root_bounds = current_root->bounds(); 622 gfx::Rect root_bounds = current_root->bounds();
548 if (root_bounds.Contains(event->root_location())) 623 if (root_bounds.Contains(event->root_location()))
549 point_of_interest_ = event->root_location(); 624 point_of_interest_ = event->root_location();
550 } 625 }
551 } 626 }
552 627
553 //////////////////////////////////////////////////////////////////////////////// 628 ////////////////////////////////////////////////////////////////////////////////
554 // MagnificationController: 629 // MagnificationController:
555 630
556 // static 631 // static
557 MagnificationController* MagnificationController::CreateInstance() { 632 MagnificationController* MagnificationController::CreateInstance() {
558 return new MagnificationControllerImpl(); 633 return new MagnificationControllerImpl();
559 } 634 }
560 635
561 } // namespace ash 636 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698