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

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: add comment. 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 return std::find(root_windows.begin(), root_windows.end(), root_window) !=
48 root_windows.end();
49 }
50
40 } // namespace 51 } // namespace
41 52
42 namespace ash { 53 namespace ash {
43 54
44 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
45 // MagnificationControllerImpl: 56 // MagnificationControllerImpl:
46 57
47 class MagnificationControllerImpl : virtual public MagnificationController, 58 class MagnificationControllerImpl : virtual public MagnificationController,
48 public ui::EventHandler, 59 public ui::EventHandler,
49 public ui::ImplicitAnimationObserver { 60 public ui::ImplicitAnimationObserver,
61 public aura::WindowObserver {
50 public: 62 public:
51 MagnificationControllerImpl(); 63 MagnificationControllerImpl();
52 virtual ~MagnificationControllerImpl(); 64 virtual ~MagnificationControllerImpl();
53 65
54 // MagnificationController overrides: 66 // MagnificationController overrides:
55 virtual void SetEnabled(bool enabled) OVERRIDE; 67 virtual void SetEnabled(bool enabled) OVERRIDE;
56 virtual bool IsEnabled() const OVERRIDE; 68 virtual bool IsEnabled() const OVERRIDE;
57 virtual void SetScale(float scale, bool animate) OVERRIDE; 69 virtual void SetScale(float scale, bool animate) OVERRIDE;
58 virtual float GetScale() const OVERRIDE { return scale_; } 70 virtual float GetScale() const OVERRIDE { return scale_; }
59 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; 71 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE;
60 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; 72 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE;
61 virtual gfx::Point GetWindowPosition() const OVERRIDE { 73 virtual gfx::Point GetWindowPosition() const OVERRIDE {
62 return gfx::ToFlooredPoint(origin_); 74 return gfx::ToFlooredPoint(origin_);
63 } 75 }
64 virtual void EnsureRectIsVisible(const gfx::Rect& rect, 76 virtual void EnsureRectIsVisible(const gfx::Rect& rect,
65 bool animate) OVERRIDE; 77 bool animate) OVERRIDE;
66 virtual void EnsurePointIsVisible(const gfx::Point& point, 78 virtual void EnsurePointIsVisible(const gfx::Point& point,
67 bool animate) OVERRIDE; 79 bool animate) OVERRIDE;
68 80
69 private: 81 private:
70 // ui::ImplicitAnimationObserver overrides: 82 // ui::ImplicitAnimationObserver overrides:
71 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 83 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
72 84
85 // aura::WindowObserver overrides:
86 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE;
87
73 // Redraws the magnification window with the given origin position and the 88 // Redraws the magnification window with the given origin position and the
74 // given scale. Returns true if the window is changed; otherwise, false. 89 // given scale. Returns true if the window is changed; otherwise, false.
75 // These methods should be called internally just after the scale and/or 90 // These methods should be called internally just after the scale and/or
76 // the position are changed to redraw the window. 91 // the position are changed to redraw the window.
77 bool Redraw(const gfx::PointF& position, float scale, bool animate); 92 bool Redraw(const gfx::PointF& position, float scale, bool animate);
78 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); 93 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate);
79 94
80 // Redraw with the given zoom scale keeping the mouse cursor location. In 95 // Redraw with the given zoom scale keeping the mouse cursor location. In
81 // other words, zoom (or unzoom) centering around the cursor. 96 // other words, zoom (or unzoom) centering around the cursor.
82 void RedrawKeepingMousePosition(float scale, bool animate); 97 void RedrawKeepingMousePosition(float scale, bool animate);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 gfx::Size GetHostSizeDIP() const; 130 gfx::Size GetHostSizeDIP() const;
116 131
117 // Correct the givin scale value if nessesary. 132 // Correct the givin scale value if nessesary.
118 void ValidateScale(float* scale); 133 void ValidateScale(float* scale);
119 134
120 // ui::EventHandler overrides: 135 // ui::EventHandler overrides:
121 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 136 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
122 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 137 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
123 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 138 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
124 139
140 // Target root window. This might be NULL when all root windows has been gone
141 // at shutdown.
oshima 2013/02/26 18:57:38 can't you destroy this object before all root wind
125 aura::RootWindow* root_window_; 142 aura::RootWindow* root_window_;
126 143
127 // True if the magnified window is currently animating a change. Otherwise, 144 // True if the magnified window is currently animating a change. Otherwise,
128 // false. 145 // false.
129 bool is_on_animation_; 146 bool is_on_animation_;
130 147
131 bool is_enabled_; 148 bool is_enabled_;
132 149
133 // True if the cursor needs to move the given position after the animation 150 // True if the cursor needs to move the given position after the animation
134 // will be finished. When using this, set |position_after_animation_| as well. 151 // will be finished. When using this, set |position_after_animation_| as well.
(...skipping 16 matching lines...) Expand all
151 // MagnificationControllerImpl: 168 // MagnificationControllerImpl:
152 169
153 MagnificationControllerImpl::MagnificationControllerImpl() 170 MagnificationControllerImpl::MagnificationControllerImpl()
154 : root_window_(ash::Shell::GetPrimaryRootWindow()), 171 : root_window_(ash::Shell::GetPrimaryRootWindow()),
155 is_on_animation_(false), 172 is_on_animation_(false),
156 is_enabled_(false), 173 is_enabled_(false),
157 move_cursor_after_animation_(false), 174 move_cursor_after_animation_(false),
158 scale_(kNonMagnifiedScale) { 175 scale_(kNonMagnifiedScale) {
159 Shell::GetInstance()->AddPreTargetHandler(this); 176 Shell::GetInstance()->AddPreTargetHandler(this);
160 177
161 if (root_window_) 178 if (root_window_) {
179 root_window_->AddObserver(this);
162 point_of_interest_ = root_window_->bounds().CenterPoint(); 180 point_of_interest_ = root_window_->bounds().CenterPoint();
181 }
163 } 182 }
164 183
165 MagnificationControllerImpl::~MagnificationControllerImpl() { 184 MagnificationControllerImpl::~MagnificationControllerImpl() {
185 if (root_window_)
186 root_window_->RemoveObserver(this);
187
166 Shell::GetInstance()->RemovePreTargetHandler(this); 188 Shell::GetInstance()->RemovePreTargetHandler(this);
167 } 189 }
168 190
169 void MagnificationControllerImpl::RedrawKeepingMousePosition( 191 void MagnificationControllerImpl::RedrawKeepingMousePosition(
170 float scale, bool animate) { 192 float scale, bool animate) {
193 CHECK(root_window_); // |root_window_| should be checked at the caller.
194
171 gfx::Point mouse_in_root = point_of_interest_; 195 gfx::Point mouse_in_root = point_of_interest_;
172 196
173 // mouse_in_root is invalid value when the cursor is hidden. 197 // mouse_in_root is invalid value when the cursor is hidden.
174 if (!root_window_->bounds().Contains(mouse_in_root)) 198 if (!root_window_->bounds().Contains(mouse_in_root))
175 mouse_in_root = root_window_->bounds().CenterPoint(); 199 mouse_in_root = root_window_->bounds().CenterPoint();
176 200
177 const gfx::PointF origin = 201 const gfx::PointF origin =
178 gfx::PointF(mouse_in_root.x() - 202 gfx::PointF(mouse_in_root.x() -
179 (scale_ / scale) * (mouse_in_root.x() - origin_.x()), 203 (scale_ / scale) * (mouse_in_root.x() - origin_.x()),
180 mouse_in_root.y() - 204 mouse_in_root.y() -
181 (scale_ / scale) * (mouse_in_root.y() - origin_.y())); 205 (scale_ / scale) * (mouse_in_root.y() - origin_.y()));
182 bool changed = RedrawDIP(origin, scale, animate); 206 bool changed = RedrawDIP(origin, scale, animate);
183 if (changed) 207 if (changed)
184 AfterAnimationMoveCursorTo(mouse_in_root); 208 AfterAnimationMoveCursorTo(mouse_in_root);
185 } 209 }
186 210
187 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, 211 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position,
188 float scale, 212 float scale,
189 bool animate) { 213 bool animate) {
214 CHECK(root_window_); // |root_window_| should be checked at the caller.
215
190 const gfx::PointF position_in_dip = 216 const gfx::PointF position_in_dip =
191 ui::ConvertPointToDIP(root_window_->layer(), position); 217 ui::ConvertPointToDIP(root_window_->layer(), position);
192 return RedrawDIP(position_in_dip, scale, animate); 218 return RedrawDIP(position_in_dip, scale, animate);
193 } 219 }
194 220
195 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip, 221 bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip,
196 float scale, 222 float scale,
197 bool animate) { 223 bool animate) {
224 CHECK(root_window_); // |root_window_| should be checked at the caller.
225
198 float x = position_in_dip.x(); 226 float x = position_in_dip.x();
199 float y = position_in_dip.y(); 227 float y = position_in_dip.y();
200 228
201 ValidateScale(&scale); 229 ValidateScale(&scale);
202 230
203 if (x < 0) 231 if (x < 0)
204 x = 0; 232 x = 0;
205 if (y < 0) 233 if (y < 0)
206 y = 0; 234 y = 0;
207 235
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if (animate) 274 if (animate)
247 is_on_animation_ = true; 275 is_on_animation_ = true;
248 276
249 return true; 277 return true;
250 } 278 }
251 279
252 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale( 280 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale(
253 const gfx::Rect& target_rect, 281 const gfx::Rect& target_rect,
254 float scale, 282 float scale,
255 bool animate) { 283 bool animate) {
284 CHECK(root_window_); // |root_window_| should be checked at the caller.
285
256 const gfx::Rect target_rect_in_dip = 286 const gfx::Rect target_rect_in_dip =
257 ui::ConvertRectToDIP(root_window_->layer(), target_rect); 287 ui::ConvertRectToDIP(root_window_->layer(), target_rect);
258 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate); 288 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate);
259 } 289 }
260 290
261 void MagnificationControllerImpl::EnsureRectIsVisibleDIP( 291 void MagnificationControllerImpl::EnsureRectIsVisibleDIP(
262 const gfx::Rect& target_rect, 292 const gfx::Rect& target_rect,
263 float scale, 293 float scale,
264 bool animate) { 294 bool animate) {
265 ValidateScale(&scale); 295 ValidateScale(&scale);
(...skipping 26 matching lines...) Expand all
292 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale( 322 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale(
293 const gfx::Point& point, 323 const gfx::Point& point,
294 float scale, 324 float scale,
295 bool animate) { 325 bool animate) {
296 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)), 326 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)),
297 scale, 327 scale,
298 animate); 328 animate);
299 } 329 }
300 330
301 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { 331 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
332 CHECK(root_window_); // |root_window_| should be checked at the caller.
333
302 gfx::Point mouse(location); 334 gfx::Point mouse(location);
303 335
304 int x = origin_.x(); 336 int x = origin_.x();
305 int y = origin_.y(); 337 int y = origin_.y();
306 bool start_zoom = false; 338 bool start_zoom = false;
307 339
308 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); 340 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale_));
309 const int left = window_rect.x(); 341 const int left = window_rect.x();
310 const int right = window_rect.right(); 342 const int right = window_rect.right();
311 int margin = kPanningMergin / scale_; // No need to consider DPI. 343 int margin = kPanningMergin / scale_; // No need to consider DPI.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (ret) { 378 if (ret) {
347 // If the magnified region is moved, hides the mouse cursor and moves it. 379 // If the magnified region is moved, hides the mouse cursor and moves it.
348 if (x_diff != 0 || y_diff != 0) 380 if (x_diff != 0 || y_diff != 0)
349 root_window_->MoveCursorTo(mouse); 381 root_window_->MoveCursorTo(mouse);
350 } 382 }
351 } 383 }
352 } 384 }
353 385
354 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( 386 void MagnificationControllerImpl::AfterAnimationMoveCursorTo(
355 const gfx::Point& location) { 387 const gfx::Point& location) {
388 CHECK(root_window_); // |root_window_| should be checked at the caller.
389
356 aura::client::CursorClient* cursor_client = 390 aura::client::CursorClient* cursor_client =
357 aura::client::GetCursorClient(root_window_); 391 aura::client::GetCursorClient(root_window_);
358 if (cursor_client) { 392 if (cursor_client) {
359 // When cursor is invisible, do not move or show the cursor after the 393 // When cursor is invisible, do not move or show the cursor after the
360 // animation. 394 // animation.
361 if (!cursor_client->IsCursorVisible()) 395 if (!cursor_client->IsCursorVisible())
362 return; 396 return;
363 cursor_client->DisableMouseEvents(); 397 cursor_client->DisableMouseEvents();
364 } 398 }
365 move_cursor_after_animation_ = true; 399 move_cursor_after_animation_ = true;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 443
410 aura::client::CursorClient* cursor_client = 444 aura::client::CursorClient* cursor_client =
411 aura::client::GetCursorClient(root_window_); 445 aura::client::GetCursorClient(root_window_);
412 if (cursor_client) 446 if (cursor_client)
413 cursor_client->EnableMouseEvents(); 447 cursor_client->EnableMouseEvents();
414 } 448 }
415 449
416 is_on_animation_ = false; 450 is_on_animation_ = false;
417 } 451 }
418 452
453 void MagnificationControllerImpl::OnWindowDestroying(
454 aura::Window* root_window) {
455 if (root_window == root_window_) {
456 aura::RootWindow* active_root_window = Shell::GetActiveRootWindow();
457 // The destroyed root window must not be active.
458 CHECK_NE(active_root_window, root_window);
459
460 if (active_root_window) {
461 SwitchTargetRootWindow(active_root_window);
462 point_of_interest_ = active_root_window->bounds().CenterPoint();
463 } else {
464 // No need to call |root_window_.removeObserver(this)| because the root
465 // window is being destroyed.
466
467 root_window_ = NULL;
468 }
469 }
470 }
471
419 void MagnificationControllerImpl::SwitchTargetRootWindow( 472 void MagnificationControllerImpl::SwitchTargetRootWindow(
420 aura::RootWindow* new_root_window) { 473 aura::RootWindow* new_root_window) {
421 if (new_root_window == root_window_) 474 if (new_root_window == root_window_)
422 return; 475 return;
423 476
477 // Stores the previous scale.
424 float scale = GetScale(); 478 float scale = GetScale();
425 479
426 RedrawKeepingMousePosition(1.0f, true); 480 // Unmagnify the previous root window if it exists.
481 if (IsRootWindowValid(root_window_)) {
482 root_window_->RemoveObserver(this);
483 RedrawKeepingMousePosition(1.0f, true);
484 }
485
427 root_window_ = new_root_window; 486 root_window_ = new_root_window;
428 RedrawKeepingMousePosition(scale, true); 487 RedrawKeepingMousePosition(scale, true);
488 root_window_->AddObserver(this);
429 } 489 }
430 490
431 //////////////////////////////////////////////////////////////////////////////// 491 ////////////////////////////////////////////////////////////////////////////////
432 // MagnificationControllerImpl: MagnificationController implementation 492 // MagnificationControllerImpl: MagnificationController implementation
433 493
434 void MagnificationControllerImpl::SetScale(float scale, bool animate) { 494 void MagnificationControllerImpl::SetScale(float scale, bool animate) {
435 if (!is_enabled_) 495 if (!is_enabled_ || root_window_ == NULL)
436 return; 496 return;
437 497
438 ValidateScale(&scale); 498 ValidateScale(&scale);
439 ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale); 499 ash::Shell::GetInstance()->delegate()->SaveScreenMagnifierScale(scale);
440 RedrawKeepingMousePosition(scale, animate); 500 RedrawKeepingMousePosition(scale, animate);
441 } 501 }
442 502
443 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { 503 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) {
444 if (!is_enabled_) 504 if (!is_enabled_ || root_window_ == NULL)
445 return; 505 return;
446 506
447 Redraw(gfx::Point(x, y), scale_, animate); 507 Redraw(gfx::Point(x, y), scale_, animate);
448 } 508 }
449 509
450 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, 510 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point,
451 bool animate) { 511 bool animate) {
452 if (!is_enabled_) 512 if (!is_enabled_ || root_window_ == NULL)
453 return; 513 return;
454 514
455 Redraw(point, scale_, animate); 515 Redraw(point, scale_, animate);
456 } 516 }
457 517
458 void MagnificationControllerImpl::EnsureRectIsVisible( 518 void MagnificationControllerImpl::EnsureRectIsVisible(
459 const gfx::Rect& target_rect, 519 const gfx::Rect& target_rect,
460 bool animate) { 520 bool animate) {
461 if (!is_enabled_) 521 if (!is_enabled_ || root_window_ == NULL)
462 return; 522 return;
463 523
464 EnsureRectIsVisibleWithScale(target_rect, scale_, animate); 524 EnsureRectIsVisibleWithScale(target_rect, scale_, animate);
465 } 525 }
466 526
467 void MagnificationControllerImpl::EnsurePointIsVisible( 527 void MagnificationControllerImpl::EnsurePointIsVisible(
468 const gfx::Point& point, 528 const gfx::Point& point,
469 bool animate) { 529 bool animate) {
470 if (!is_enabled_) 530 if (!is_enabled_ || root_window_ == NULL)
471 return; 531 return;
472 532
473 EnsurePointIsVisibleWithScale(point, scale_, animate); 533 EnsurePointIsVisibleWithScale(point, scale_, animate);
474 } 534 }
475 535
476 void MagnificationControllerImpl::SetEnabled(bool enabled) { 536 void MagnificationControllerImpl::SetEnabled(bool enabled) {
537 if (root_window_ == NULL)
538 return;
539
477 if (enabled) { 540 if (enabled) {
478 float scale = 541 float scale =
479 ash::Shell::GetInstance()->delegate()->GetSavedScreenMagnifierScale(); 542 ash::Shell::GetInstance()->delegate()->GetSavedScreenMagnifierScale();
480 if (scale <= 0.0f) 543 if (scale <= 0.0f)
481 scale = kInitialMagnifiedScale; 544 scale = kInitialMagnifiedScale;
482 ValidateScale(&scale); 545 ValidateScale(&scale);
483 546
484 // Do nothing, if already enabled with same scale. 547 // Do nothing, if already enabled with same scale.
485 if (is_enabled_ && scale == scale_) 548 if (is_enabled_ && scale == scale_)
486 return; 549 return;
(...skipping 17 matching lines...) Expand all
504 567
505 //////////////////////////////////////////////////////////////////////////////// 568 ////////////////////////////////////////////////////////////////////////////////
506 // MagnificationControllerImpl: aura::EventFilter implementation 569 // MagnificationControllerImpl: aura::EventFilter implementation
507 570
508 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) { 571 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
509 aura::Window* target = static_cast<aura::Window*>(event->target()); 572 aura::Window* target = static_cast<aura::Window*>(event->target());
510 aura::RootWindow* current_root = target->GetRootWindow(); 573 aura::RootWindow* current_root = target->GetRootWindow();
511 gfx::Rect root_bounds = current_root->bounds(); 574 gfx::Rect root_bounds = current_root->bounds();
512 575
513 if (root_bounds.Contains(event->root_location())) { 576 if (root_bounds.Contains(event->root_location())) {
577 // This must be before |SwitchTargetRootWindow()|.
578 point_of_interest_ = event->root_location();
579
514 if (current_root != root_window_) 580 if (current_root != root_window_)
515 SwitchTargetRootWindow(current_root); 581 SwitchTargetRootWindow(current_root);
516 582
517 point_of_interest_ = event->root_location(); 583 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()); 584 OnMouseMove(event->root_location());
521 } 585 }
522 } 586 }
523 587
524 void MagnificationControllerImpl::OnScrollEvent(ui::ScrollEvent* event) { 588 void MagnificationControllerImpl::OnScrollEvent(ui::ScrollEvent* event) {
525 if (event->IsAltDown() && event->IsControlDown()) { 589 if (event->IsAltDown() && event->IsControlDown()) {
526 if (event->type() == ui::ET_SCROLL_FLING_START || 590 if (event->type() == ui::ET_SCROLL_FLING_START ||
527 event->type() == ui::ET_SCROLL_FLING_CANCEL) { 591 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
528 event->StopPropagation(); 592 event->StopPropagation();
529 return; 593 return;
530 } 594 }
531 595
532 if (event->type() == ui::ET_SCROLL) { 596 if (event->type() == ui::ET_SCROLL) {
533 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); 597 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event);
534 float scale = GetScale(); 598 float scale = GetScale();
535 scale += scroll_event->y_offset() * kScrollScaleChangeFactor; 599 scale += scroll_event->y_offset() * kScrollScaleChangeFactor;
536 SetScale(scale, true); 600 SetScale(scale, true);
537 event->StopPropagation(); 601 event->StopPropagation();
538 return; 602 return;
539 } 603 }
540 } 604 }
541 } 605 }
542 606
543 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { 607 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) {
544 aura::Window* target = static_cast<aura::Window*>(event->target()); 608 aura::Window* target = static_cast<aura::Window*>(event->target());
545 aura::RootWindow* current_root = target->GetRootWindow(); 609 aura::RootWindow* current_root = target->GetRootWindow();
546 if (current_root == root_window_) { 610 if (current_root && current_root == root_window_) {
547 gfx::Rect root_bounds = current_root->bounds(); 611 gfx::Rect root_bounds = current_root->bounds();
548 if (root_bounds.Contains(event->root_location())) 612 if (root_bounds.Contains(event->root_location()))
549 point_of_interest_ = event->root_location(); 613 point_of_interest_ = event->root_location();
550 } 614 }
551 } 615 }
552 616
553 //////////////////////////////////////////////////////////////////////////////// 617 ////////////////////////////////////////////////////////////////////////////////
554 // MagnificationController: 618 // MagnificationController:
555 619
556 // static 620 // static
557 MagnificationController* MagnificationController::CreateInstance() { 621 MagnificationController* MagnificationController::CreateInstance() {
558 return new MagnificationControllerImpl(); 622 return new MagnificationControllerImpl();
559 } 623 }
560 624
561 } // namespace ash 625 } // 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