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/accelerators/accelerator_controller.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/root_window_transformers.h" | 10 #include "ash/display/root_window_transformers.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void MoveWindow(int x, int y, bool animate) override; | 86 void MoveWindow(int x, int y, bool animate) override; |
87 void MoveWindow(const gfx::Point& point, bool animate) override; | 87 void MoveWindow(const gfx::Point& point, bool animate) override; |
88 gfx::Point GetWindowPosition() const override { | 88 gfx::Point GetWindowPosition() const override { |
89 return gfx::ToFlooredPoint(origin_); | 89 return gfx::ToFlooredPoint(origin_); |
90 } | 90 } |
91 void SetScrollDirection(ScrollDirection direction) override; | 91 void SetScrollDirection(ScrollDirection direction) override; |
92 gfx::Rect GetViewportRect() const override; | 92 gfx::Rect GetViewportRect() const override; |
93 void HandleFocusedNodeChanged( | 93 void HandleFocusedNodeChanged( |
94 bool is_editable_node, | 94 bool is_editable_node, |
95 const gfx::Rect& node_bounds_in_screen) override; | 95 const gfx::Rect& node_bounds_in_screen) override; |
| 96 void SwitchTargetRootWindow(aura::Window* new_root_window, |
| 97 bool redraw_original_root_window) override; |
96 | 98 |
97 // For test | 99 // For test |
98 gfx::Point GetPointOfInterestForTesting() override { | 100 gfx::Point GetPointOfInterestForTesting() override { |
99 return point_of_interest_; | 101 return point_of_interest_; |
100 } | 102 } |
101 | 103 |
102 bool IsOnAnimationForTesting() const override { return is_on_animation_; } | 104 bool IsOnAnimationForTesting() const override { return is_on_animation_; } |
103 | 105 |
104 private: | 106 private: |
105 // ui::ImplicitAnimationObserver overrides: | 107 // ui::ImplicitAnimationObserver overrides: |
(...skipping 24 matching lines...) Expand all Loading... |
130 // other words, zoom (or unzoom) centering around the cursor. | 132 // other words, zoom (or unzoom) centering around the cursor. |
131 void RedrawKeepingMousePosition(float scale, bool animate); | 133 void RedrawKeepingMousePosition(float scale, bool animate); |
132 | 134 |
133 void OnMouseMove(const gfx::Point& location); | 135 void OnMouseMove(const gfx::Point& location); |
134 | 136 |
135 // Move the mouse cursot to the given point. Actual move will be done when | 137 // Move the mouse cursot to the given point. Actual move will be done when |
136 // the animation is completed. This should be called after animation is | 138 // the animation is completed. This should be called after animation is |
137 // started. | 139 // started. |
138 void AfterAnimationMoveCursorTo(const gfx::Point& location); | 140 void AfterAnimationMoveCursorTo(const gfx::Point& location); |
139 | 141 |
140 // Switch Magnified RootWindow to |new_root_window|. This does following: | |
141 // - Unzoom the current root_window. | |
142 // - Zoom the given new root_window |new_root_window|. | |
143 // - Switch the target window from current window to |new_root_window|. | |
144 void SwitchTargetRootWindow(aura::Window* new_root_window, | |
145 bool redraw_original_root_window); | |
146 | |
147 // Returns if the magnification scale is 1.0 or not (larger then 1.0). | 142 // Returns if the magnification scale is 1.0 or not (larger then 1.0). |
148 bool IsMagnified() const; | 143 bool IsMagnified() const; |
149 | 144 |
150 // Returns the rect of the magnification window. | 145 // Returns the rect of the magnification window. |
151 gfx::RectF GetWindowRectDIP(float scale) const; | 146 gfx::RectF GetWindowRectDIP(float scale) const; |
152 // Returns the size of the root window. | 147 // Returns the size of the root window. |
153 gfx::Size GetHostSizeDIP() const; | 148 gfx::Size GetHostSizeDIP() const; |
154 | 149 |
155 // Correct the given scale value if necessary. | 150 // Correct the given scale value if necessary. |
156 void ValidateScale(float* scale); | 151 void ValidateScale(float* scale); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return; | 375 return; |
381 | 376 |
382 gfx::Rect node_bounds_in_root = | 377 gfx::Rect node_bounds_in_root = |
383 ScreenUtil::ConvertRectFromScreen(root_window_, node_bounds_in_screen); | 378 ScreenUtil::ConvertRectFromScreen(root_window_, node_bounds_in_screen); |
384 if (GetViewportRect().Contains(node_bounds_in_root)) | 379 if (GetViewportRect().Contains(node_bounds_in_root)) |
385 return; | 380 return; |
386 | 381 |
387 MoveMagnifierWindowFollowRect(node_bounds_in_root); | 382 MoveMagnifierWindowFollowRect(node_bounds_in_root); |
388 } | 383 } |
389 | 384 |
| 385 void MagnificationControllerImpl::SwitchTargetRootWindow( |
| 386 aura::Window* new_root_window, |
| 387 bool redraw_original_root_window) { |
| 388 DCHECK(new_root_window); |
| 389 |
| 390 if (new_root_window == root_window_) |
| 391 return; |
| 392 // Update the |root_window_| now because RedrawKeepingMousePosition |
| 393 // may call this back. |
| 394 aura::Window* old_root_window = root_window_; |
| 395 root_window_ = new_root_window; |
| 396 |
| 397 move_cursor_after_animation_ = false; |
| 398 |
| 399 // Stores the previous scale. |
| 400 float scale = GetScale(); |
| 401 |
| 402 // Unmagnify the previous root window. |
| 403 old_root_window->RemoveObserver(this); |
| 404 if (redraw_original_root_window) |
| 405 RedrawKeepingMousePosition(1.0f, true); |
| 406 |
| 407 RedrawKeepingMousePosition(scale, true); |
| 408 root_window_->AddObserver(this); |
| 409 } |
| 410 |
390 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( | 411 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( |
391 const gfx::Point& location) { | 412 const gfx::Point& location) { |
392 DCHECK(root_window_); | 413 DCHECK(root_window_); |
393 | 414 |
394 aura::client::CursorClient* cursor_client = | 415 aura::client::CursorClient* cursor_client = |
395 aura::client::GetCursorClient(root_window_); | 416 aura::client::GetCursorClient(root_window_); |
396 if (cursor_client) { | 417 if (cursor_client) { |
397 // When cursor is invisible, do not move or show the cursor after the | 418 // When cursor is invisible, do not move or show the cursor after the |
398 // animation. | 419 // animation. |
399 if (!cursor_client->IsCursorVisible()) | 420 if (!cursor_client->IsCursorVisible()) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 492 } |
472 } | 493 } |
473 | 494 |
474 void MagnificationControllerImpl::OnWindowBoundsChanged( | 495 void MagnificationControllerImpl::OnWindowBoundsChanged( |
475 aura::Window* window, | 496 aura::Window* window, |
476 const gfx::Rect& old_bounds, | 497 const gfx::Rect& old_bounds, |
477 const gfx::Rect& new_bounds) { | 498 const gfx::Rect& new_bounds) { |
478 // TODO(yoshiki): implement here. crbug.com/230979 | 499 // TODO(yoshiki): implement here. crbug.com/230979 |
479 } | 500 } |
480 | 501 |
481 void MagnificationControllerImpl::SwitchTargetRootWindow( | |
482 aura::Window* new_root_window, | |
483 bool redraw_original_root_window) { | |
484 DCHECK(new_root_window); | |
485 | |
486 if (new_root_window == root_window_) | |
487 return; | |
488 | |
489 // Stores the previous scale. | |
490 float scale = GetScale(); | |
491 | |
492 // Unmagnify the previous root window. | |
493 root_window_->RemoveObserver(this); | |
494 if (redraw_original_root_window) | |
495 RedrawKeepingMousePosition(1.0f, true); | |
496 | |
497 root_window_ = new_root_window; | |
498 RedrawKeepingMousePosition(scale, true); | |
499 root_window_->AddObserver(this); | |
500 } | |
501 | |
502 //////////////////////////////////////////////////////////////////////////////// | 502 //////////////////////////////////////////////////////////////////////////////// |
503 // MagnificationControllerImpl: MagnificationController implementation | 503 // MagnificationControllerImpl: MagnificationController implementation |
504 | 504 |
505 void MagnificationControllerImpl::SetScale(float scale, bool animate) { | 505 void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
506 if (!is_enabled_) | 506 if (!is_enabled_) |
507 return; | 507 return; |
508 | 508 |
509 ValidateScale(&scale); | 509 ValidateScale(&scale); |
510 Shell::GetInstance()->accessibility_delegate()-> | 510 Shell::GetInstance()->accessibility_delegate()-> |
511 SaveScreenMagnifierScale(scale); | 511 SaveScreenMagnifierScale(scale); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 744 |
745 //////////////////////////////////////////////////////////////////////////////// | 745 //////////////////////////////////////////////////////////////////////////////// |
746 // MagnificationController: | 746 // MagnificationController: |
747 | 747 |
748 // static | 748 // static |
749 MagnificationController* MagnificationController::CreateInstance() { | 749 MagnificationController* MagnificationController::CreateInstance() { |
750 return new MagnificationControllerImpl(); | 750 return new MagnificationControllerImpl(); |
751 } | 751 } |
752 | 752 |
753 } // namespace ash | 753 } // namespace ash |
OLD | NEW |