OLD | NEW |
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/accelerators/accelerator_controller.h" |
7 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/ash_switches.h" |
8 #include "ash/display/root_window_transformers.h" | 10 #include "ash/display/root_window_transformers.h" |
9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 13 #include "base/command_line.h" |
11 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
12 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
13 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
14 #include "ui/aura/root_window_transformer.h" | 17 #include "ui/aura/root_window_transformer.h" |
15 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
16 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
17 #include "ui/compositor/dip_util.h" | 20 #include "ui/compositor/dip_util.h" |
18 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
19 #include "ui/compositor/layer_animation_observer.h" | 22 #include "ui/compositor/layer_animation_observer.h" |
20 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // MagnificationController overrides: | 70 // MagnificationController overrides: |
68 virtual void SetEnabled(bool enabled) OVERRIDE; | 71 virtual void SetEnabled(bool enabled) OVERRIDE; |
69 virtual bool IsEnabled() const OVERRIDE; | 72 virtual bool IsEnabled() const OVERRIDE; |
70 virtual void SetScale(float scale, bool animate) OVERRIDE; | 73 virtual void SetScale(float scale, bool animate) OVERRIDE; |
71 virtual float GetScale() const OVERRIDE { return scale_; } | 74 virtual float GetScale() const OVERRIDE { return scale_; } |
72 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; | 75 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; |
73 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; | 76 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; |
74 virtual gfx::Point GetWindowPosition() const OVERRIDE { | 77 virtual gfx::Point GetWindowPosition() const OVERRIDE { |
75 return gfx::ToFlooredPoint(origin_); | 78 return gfx::ToFlooredPoint(origin_); |
76 } | 79 } |
77 virtual void EnsureRectIsVisible(const gfx::Rect& rect, | 80 virtual void SetScrollDirection(ScrollDirection direction) OVERRIDE; |
78 bool animate) OVERRIDE; | 81 |
79 virtual void EnsurePointIsVisible(const gfx::Point& point, | |
80 bool animate) OVERRIDE; | |
81 // For test | 82 // For test |
82 virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE { | 83 virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE { |
83 return point_of_interest_; | 84 return point_of_interest_; |
84 } | 85 } |
85 | 86 |
86 private: | 87 private: |
87 // ui::ImplicitAnimationObserver overrides: | 88 // ui::ImplicitAnimationObserver overrides: |
88 virtual void OnImplicitAnimationsCompleted() OVERRIDE; | 89 virtual void OnImplicitAnimationsCompleted() OVERRIDE; |
89 | 90 |
90 // aura::WindowObserver overrides: | 91 // aura::WindowObserver overrides: |
91 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE; | 92 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE; |
92 virtual void OnWindowBoundsChanged(aura::Window* window, | 93 virtual void OnWindowBoundsChanged(aura::Window* window, |
93 const gfx::Rect& old_bounds, | 94 const gfx::Rect& old_bounds, |
94 const gfx::Rect& new_bounds) OVERRIDE; | 95 const gfx::Rect& new_bounds) OVERRIDE; |
95 | 96 |
96 // Redraws the magnification window with the given origin position and the | 97 // Redraws the magnification window with the given origin position and the |
97 // given scale. Returns true if the window is changed; otherwise, false. | 98 // given scale. Returns true if the window is changed; otherwise, false. |
98 // These methods should be called internally just after the scale and/or | 99 // These methods should be called internally just after the scale and/or |
99 // the position are changed to redraw the window. | 100 // the position are changed to redraw the window. |
100 bool Redraw(const gfx::PointF& position, float scale, bool animate); | 101 bool Redraw(const gfx::PointF& position, float scale, bool animate); |
101 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); | 102 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); |
102 | 103 |
| 104 // 1) If the screen is scrolling (i.e. animating) and should scroll further, |
| 105 // it does nothing. |
| 106 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE, |
| 107 // it stops the scrolling animation. |
| 108 // 3) If the direction is set to value other than NONE, it starts the |
| 109 // scrolling/ animation towards that direction. |
| 110 void StartOrStopScrollIfNecessary(); |
| 111 |
103 // Redraw with the given zoom scale keeping the mouse cursor location. In | 112 // Redraw with the given zoom scale keeping the mouse cursor location. In |
104 // other words, zoom (or unzoom) centering around the cursor. | 113 // other words, zoom (or unzoom) centering around the cursor. |
105 void RedrawKeepingMousePosition(float scale, bool animate); | 114 void RedrawKeepingMousePosition(float scale, bool animate); |
106 | 115 |
107 // Ensures that the given point, rect or last mouse location is inside | |
108 // magnification window. If not, the controller moves the window to contain | |
109 // the given point/rect. | |
110 void EnsureRectIsVisibleWithScale(const gfx::Rect& target_rect, | |
111 float scale, | |
112 bool animate); | |
113 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip, | |
114 float scale, | |
115 bool animate); | |
116 void EnsurePointIsVisibleWithScale(const gfx::Point& point, | |
117 float scale, | |
118 bool animate); | |
119 void OnMouseMove(const gfx::Point& location); | 116 void OnMouseMove(const gfx::Point& location); |
120 | 117 |
121 // Move the mouse cursot to the given point. Actual move will be done when | 118 // Move the mouse cursot to the given point. Actual move will be done when |
122 // the animation is completed. This should be called after animation is | 119 // the animation is completed. This should be called after animation is |
123 // started. | 120 // started. |
124 void AfterAnimationMoveCursorTo(const gfx::Point& location); | 121 void AfterAnimationMoveCursorTo(const gfx::Point& location); |
125 | 122 |
126 // Switch Magnified RootWindow to |new_root_window|. This does following: | 123 // Switch Magnified RootWindow to |new_root_window|. This does following: |
127 // - Unzoom the current root_window. | 124 // - Unzoom the current root_window. |
128 // - Zoom the given new root_window |new_root_window|. | 125 // - Zoom the given new root_window |new_root_window|. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 gfx::Point position_after_animation_; | 159 gfx::Point position_after_animation_; |
163 | 160 |
164 // Stores the last mouse cursor (or last touched) location. This value is | 161 // Stores the last mouse cursor (or last touched) location. This value is |
165 // used on zooming to keep this location visible. | 162 // used on zooming to keep this location visible. |
166 gfx::Point point_of_interest_; | 163 gfx::Point point_of_interest_; |
167 | 164 |
168 // Current scale, origin (left-top) position of the magnification window. | 165 // Current scale, origin (left-top) position of the magnification window. |
169 float scale_; | 166 float scale_; |
170 gfx::PointF origin_; | 167 gfx::PointF origin_; |
171 | 168 |
| 169 ScrollDirection scroll_direction_; |
| 170 |
172 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); | 171 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); |
173 }; | 172 }; |
174 | 173 |
175 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
176 // MagnificationControllerImpl: | 175 // MagnificationControllerImpl: |
177 | 176 |
178 MagnificationControllerImpl::MagnificationControllerImpl() | 177 MagnificationControllerImpl::MagnificationControllerImpl() |
179 : root_window_(ash::Shell::GetPrimaryRootWindow()), | 178 : root_window_(Shell::GetPrimaryRootWindow()), |
180 is_on_animation_(false), | 179 is_on_animation_(false), |
181 is_enabled_(false), | 180 is_enabled_(false), |
182 move_cursor_after_animation_(false), | 181 move_cursor_after_animation_(false), |
183 scale_(kNonMagnifiedScale) { | 182 scale_(kNonMagnifiedScale), |
| 183 scroll_direction_(SCROLL_NONE) { |
184 Shell::GetInstance()->AddPreTargetHandler(this); | 184 Shell::GetInstance()->AddPreTargetHandler(this); |
185 root_window_->AddObserver(this); | 185 root_window_->AddObserver(this); |
186 point_of_interest_ = root_window_->bounds().CenterPoint(); | 186 point_of_interest_ = root_window_->bounds().CenterPoint(); |
187 } | 187 } |
188 | 188 |
189 MagnificationControllerImpl::~MagnificationControllerImpl() { | 189 MagnificationControllerImpl::~MagnificationControllerImpl() { |
190 root_window_->RemoveObserver(this); | 190 root_window_->RemoveObserver(this); |
191 | 191 |
192 Shell::GetInstance()->RemovePreTargetHandler(this); | 192 Shell::GetInstance()->RemovePreTargetHandler(this); |
193 } | 193 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 internal::CreateRootWindowTransformerForDisplay(root_window_, display)); | 275 internal::CreateRootWindowTransformerForDisplay(root_window_, display)); |
276 root_window_->GetDispatcher()->host()->SetRootWindowTransformer( | 276 root_window_->GetDispatcher()->host()->SetRootWindowTransformer( |
277 transformer.Pass()); | 277 transformer.Pass()); |
278 | 278 |
279 if (animate) | 279 if (animate) |
280 is_on_animation_ = true; | 280 is_on_animation_ = true; |
281 | 281 |
282 return true; | 282 return true; |
283 } | 283 } |
284 | 284 |
285 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale( | 285 void MagnificationControllerImpl::StartOrStopScrollIfNecessary() { |
286 const gfx::Rect& target_rect, | 286 // This value controls the scrolling speed. |
287 float scale, | 287 const int kMoveOffset = 40; |
288 bool animate) { | 288 if (is_on_animation_) { |
289 const gfx::Rect target_rect_in_dip = | 289 if (scroll_direction_ == SCROLL_NONE) |
290 ui::ConvertRectToDIP(root_window_->layer(), target_rect); | 290 root_window_->layer()->GetAnimator()->StopAnimating(); |
291 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate); | 291 return; |
292 } | 292 } |
293 | 293 |
294 void MagnificationControllerImpl::EnsureRectIsVisibleDIP( | 294 gfx::PointF new_origin = origin_; |
295 const gfx::Rect& target_rect, | 295 switch (scroll_direction_) { |
296 float scale, | 296 case SCROLL_NONE: |
297 bool animate) { | 297 // No need to take action. |
298 ValidateScale(&scale); | 298 return; |
299 | 299 case SCROLL_LEFT: |
300 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale)); | 300 new_origin.Offset(-kMoveOffset, 0); |
301 if (scale == scale_ && window_rect.Contains(target_rect)) | 301 break; |
302 return; | 302 case SCROLL_RIGHT: |
303 | 303 new_origin.Offset(kMoveOffset, 0); |
304 // TODO(yoshiki): Un-zoom and change the scale if the magnification window | 304 break; |
305 // can't contain the whole given rect. | 305 case SCROLL_UP: |
306 | 306 new_origin.Offset(0, -kMoveOffset); |
307 gfx::Rect rect = window_rect; | 307 break; |
308 if (target_rect.width() > rect.width()) | 308 case SCROLL_DOWN: |
309 rect.set_x(target_rect.CenterPoint().x() - rect.x() / 2); | 309 new_origin.Offset(0, kMoveOffset); |
310 else if (target_rect.right() < rect.x()) | 310 break; |
311 rect.set_x(target_rect.right()); | 311 } |
312 else if (rect.right() < target_rect.x()) | 312 RedrawDIP(new_origin, scale_, true); |
313 rect.set_x(target_rect.x() - rect.width()); | |
314 | |
315 if (rect.height() > window_rect.height()) | |
316 rect.set_y(target_rect.CenterPoint().y() - rect.y() / 2); | |
317 else if (target_rect.bottom() < rect.y()) | |
318 rect.set_y(target_rect.bottom()); | |
319 else if (rect.bottom() < target_rect.y()) | |
320 rect.set_y(target_rect.y() - rect.height()); | |
321 | |
322 RedrawDIP(rect.origin(), scale, animate); | |
323 } | |
324 | |
325 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale( | |
326 const gfx::Point& point, | |
327 float scale, | |
328 bool animate) { | |
329 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)), | |
330 scale, | |
331 animate); | |
332 } | 313 } |
333 | 314 |
334 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { | 315 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { |
335 DCHECK(root_window_); | 316 DCHECK(root_window_); |
336 | 317 |
337 gfx::Point mouse(location); | 318 gfx::Point mouse(location); |
338 | 319 |
339 int x = origin_.x(); | 320 int x = origin_.x(); |
340 int y = origin_.y(); | 321 int y = origin_.y(); |
341 bool start_zoom = false; | 322 bool start_zoom = false; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 MoveCursorTo(root_window_->GetDispatcher(), position_after_animation_); | 422 MoveCursorTo(root_window_->GetDispatcher(), position_after_animation_); |
442 move_cursor_after_animation_ = false; | 423 move_cursor_after_animation_ = false; |
443 | 424 |
444 aura::client::CursorClient* cursor_client = | 425 aura::client::CursorClient* cursor_client = |
445 aura::client::GetCursorClient(root_window_); | 426 aura::client::GetCursorClient(root_window_); |
446 if (cursor_client) | 427 if (cursor_client) |
447 cursor_client->EnableMouseEvents(); | 428 cursor_client->EnableMouseEvents(); |
448 } | 429 } |
449 | 430 |
450 is_on_animation_ = false; | 431 is_on_animation_ = false; |
| 432 |
| 433 StartOrStopScrollIfNecessary(); |
451 } | 434 } |
452 | 435 |
453 void MagnificationControllerImpl::OnWindowDestroying( | 436 void MagnificationControllerImpl::OnWindowDestroying( |
454 aura::Window* root_window) { | 437 aura::Window* root_window) { |
455 if (root_window == root_window_) { | 438 if (root_window == root_window_) { |
456 // There must be at least one root window because this controller is | 439 // There must be at least one root window because this controller is |
457 // destroyed before the root windows get destroyed. | 440 // destroyed before the root windows get destroyed. |
458 DCHECK(root_window); | 441 DCHECK(root_window); |
459 | 442 |
460 aura::Window* target_root_window = Shell::GetTargetRootWindow(); | 443 aura::Window* target_root_window = Shell::GetTargetRootWindow(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 } | 480 } |
498 | 481 |
499 //////////////////////////////////////////////////////////////////////////////// | 482 //////////////////////////////////////////////////////////////////////////////// |
500 // MagnificationControllerImpl: MagnificationController implementation | 483 // MagnificationControllerImpl: MagnificationController implementation |
501 | 484 |
502 void MagnificationControllerImpl::SetScale(float scale, bool animate) { | 485 void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
503 if (!is_enabled_) | 486 if (!is_enabled_) |
504 return; | 487 return; |
505 | 488 |
506 ValidateScale(&scale); | 489 ValidateScale(&scale); |
507 ash::Shell::GetInstance()->accessibility_delegate()-> | 490 Shell::GetInstance()->accessibility_delegate()-> |
508 SaveScreenMagnifierScale(scale); | 491 SaveScreenMagnifierScale(scale); |
509 RedrawKeepingMousePosition(scale, animate); | 492 RedrawKeepingMousePosition(scale, animate); |
510 } | 493 } |
511 | 494 |
512 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { | 495 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { |
513 if (!is_enabled_) | 496 if (!is_enabled_) |
514 return; | 497 return; |
515 | 498 |
516 Redraw(gfx::Point(x, y), scale_, animate); | 499 Redraw(gfx::Point(x, y), scale_, animate); |
517 } | 500 } |
518 | 501 |
519 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, | 502 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, |
520 bool animate) { | 503 bool animate) { |
521 if (!is_enabled_) | 504 if (!is_enabled_) |
522 return; | 505 return; |
523 | 506 |
524 Redraw(point, scale_, animate); | 507 Redraw(point, scale_, animate); |
525 } | 508 } |
526 | 509 |
527 void MagnificationControllerImpl::EnsureRectIsVisible( | 510 void MagnificationControllerImpl::SetScrollDirection( |
528 const gfx::Rect& target_rect, | 511 ScrollDirection direction) { |
529 bool animate) { | 512 scroll_direction_ = direction; |
530 if (!is_enabled_) | 513 StartOrStopScrollIfNecessary(); |
531 return; | |
532 | |
533 EnsureRectIsVisibleWithScale(target_rect, scale_, animate); | |
534 } | |
535 | |
536 void MagnificationControllerImpl::EnsurePointIsVisible( | |
537 const gfx::Point& point, | |
538 bool animate) { | |
539 if (!is_enabled_) | |
540 return; | |
541 | |
542 EnsurePointIsVisibleWithScale(point, scale_, animate); | |
543 } | 514 } |
544 | 515 |
545 void MagnificationControllerImpl::SetEnabled(bool enabled) { | 516 void MagnificationControllerImpl::SetEnabled(bool enabled) { |
| 517 Shell* shell = Shell::GetInstance(); |
546 if (enabled) { | 518 if (enabled) { |
547 float scale = | 519 float scale = |
548 ash::Shell::GetInstance()->accessibility_delegate()-> | 520 Shell::GetInstance()->accessibility_delegate()-> |
549 GetSavedScreenMagnifierScale(); | 521 GetSavedScreenMagnifierScale(); |
550 if (scale <= 0.0f) | 522 if (scale <= 0.0f) |
551 scale = kInitialMagnifiedScale; | 523 scale = kInitialMagnifiedScale; |
552 ValidateScale(&scale); | 524 ValidateScale(&scale); |
553 | 525 |
554 // Do nothing, if already enabled with same scale. | 526 // Do nothing, if already enabled with same scale. |
555 if (is_enabled_ && scale == scale_) | 527 if (is_enabled_ && scale == scale_) |
556 return; | 528 return; |
557 | 529 |
558 is_enabled_ = enabled; | 530 is_enabled_ = enabled; |
559 RedrawKeepingMousePosition(scale, true); | 531 RedrawKeepingMousePosition(scale, true); |
560 ash::Shell::GetInstance()->accessibility_delegate()-> | 532 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); |
561 SaveScreenMagnifierScale(scale); | |
562 } else { | 533 } else { |
563 // Do nothing, if already disabled. | 534 // Do nothing, if already disabled. |
564 if (!is_enabled_) | 535 if (!is_enabled_) |
565 return; | 536 return; |
566 | 537 |
567 RedrawKeepingMousePosition(kNonMagnifiedScale, true); | 538 RedrawKeepingMousePosition(kNonMagnifiedScale, true); |
568 is_enabled_ = enabled; | 539 is_enabled_ = enabled; |
569 } | 540 } |
570 } | 541 } |
571 | 542 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 597 |
627 //////////////////////////////////////////////////////////////////////////////// | 598 //////////////////////////////////////////////////////////////////////////////// |
628 // MagnificationController: | 599 // MagnificationController: |
629 | 600 |
630 // static | 601 // static |
631 MagnificationController* MagnificationController::CreateInstance() { | 602 MagnificationController* MagnificationController::CreateInstance() { |
632 return new MagnificationControllerImpl(); | 603 return new MagnificationControllerImpl(); |
633 } | 604 } |
634 | 605 |
635 } // namespace ash | 606 } // namespace ash |
OLD | NEW |