| 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" |
| 11 #include "ash/host/ash_window_tree_host.h" | 11 #include "ash/host/ash_window_tree_host.h" |
| 12 #include "ash/host/root_window_transformer.h" | 12 #include "ash/host/root_window_transformer.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/screen_util.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 15 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 17 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/cursor_client.h" | 20 #include "ui/aura/client/cursor_client.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/base/ime/input_method.h" | 23 #include "ui/base/ime/input_method.h" |
| 23 #include "ui/base/ime/input_method_observer.h" | 24 #include "ui/base/ime/input_method_observer.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 void SetEnabled(bool enabled) override; | 82 void SetEnabled(bool enabled) override; |
| 82 bool IsEnabled() const override; | 83 bool IsEnabled() const override; |
| 83 void SetScale(float scale, bool animate) override; | 84 void SetScale(float scale, bool animate) override; |
| 84 float GetScale() const override { return scale_; } | 85 float GetScale() const override { return scale_; } |
| 85 void MoveWindow(int x, int y, bool animate) override; | 86 void MoveWindow(int x, int y, bool animate) override; |
| 86 void MoveWindow(const gfx::Point& point, bool animate) override; | 87 void MoveWindow(const gfx::Point& point, bool animate) override; |
| 87 gfx::Point GetWindowPosition() const override { | 88 gfx::Point GetWindowPosition() const override { |
| 88 return gfx::ToFlooredPoint(origin_); | 89 return gfx::ToFlooredPoint(origin_); |
| 89 } | 90 } |
| 90 void SetScrollDirection(ScrollDirection direction) override; | 91 void SetScrollDirection(ScrollDirection direction) override; |
| 92 gfx::Rect GetViewportRect() override; |
| 93 void HandleFocusedNodeChanged( |
| 94 bool is_editable_node, |
| 95 const gfx::Rect& node_bounds_in_screen) override; |
| 91 | 96 |
| 92 // For test | 97 // For test |
| 93 gfx::Point GetPointOfInterestForTesting() override { | 98 gfx::Point GetPointOfInterestForTesting() override { |
| 94 return point_of_interest_; | 99 return point_of_interest_; |
| 95 } | 100 } |
| 96 | 101 |
| 97 private: | 102 private: |
| 98 // ui::ImplicitAnimationObserver overrides: | 103 // ui::ImplicitAnimationObserver overrides: |
| 99 void OnImplicitAnimationsCompleted() override; | 104 void OnImplicitAnimationsCompleted() override; |
| 100 | 105 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 bool redraw_original_root_window); | 143 bool redraw_original_root_window); |
| 139 | 144 |
| 140 // Returns if the magnification scale is 1.0 or not (larger then 1.0). | 145 // Returns if the magnification scale is 1.0 or not (larger then 1.0). |
| 141 bool IsMagnified() const; | 146 bool IsMagnified() const; |
| 142 | 147 |
| 143 // Returns the rect of the magnification window. | 148 // Returns the rect of the magnification window. |
| 144 gfx::RectF GetWindowRectDIP(float scale) const; | 149 gfx::RectF GetWindowRectDIP(float scale) const; |
| 145 // Returns the size of the root window. | 150 // Returns the size of the root window. |
| 146 gfx::Size GetHostSizeDIP() const; | 151 gfx::Size GetHostSizeDIP() const; |
| 147 | 152 |
| 148 // Correct the givin scale value if nessesary. | 153 // Correct the given scale value if necessary. |
| 149 void ValidateScale(float* scale); | 154 void ValidateScale(float* scale); |
| 150 | 155 |
| 151 // ui::EventHandler overrides: | 156 // ui::EventHandler overrides: |
| 152 void OnMouseEvent(ui::MouseEvent* event) override; | 157 void OnMouseEvent(ui::MouseEvent* event) override; |
| 153 void OnScrollEvent(ui::ScrollEvent* event) override; | 158 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 154 void OnTouchEvent(ui::TouchEvent* event) override; | 159 void OnTouchEvent(ui::TouchEvent* event) override; |
| 155 | 160 |
| 156 // Moves the view port when |point| is located within | 161 // Moves the view port when |point| is located within |
| 157 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible | 162 // |x_panning_margin| and |y_pannin_margin| to the edge of the visible |
| 158 // window region. The view port will be moved so that the |point| will be | 163 // window region. The view port will be moved so that the |point| will be |
| 159 // moved to the point where it has |x_target_margin| and |y_target_margin| | 164 // moved to the point where it has |x_target_margin| and |y_target_margin| |
| 160 // to the edge of the visible region. | 165 // to the edge of the visible region. |
| 161 void MoveMagnifierWindow(const gfx::Point& point, | 166 void MoveMagnifierWindowFollowPoint(const gfx::Point& point, |
| 162 int x_panning_margin, | 167 int x_panning_margin, |
| 163 int y_panning_margin, | 168 int y_panning_margin, |
| 164 int x_target_margin, | 169 int x_target_margin, |
| 165 int y_target_margin); | 170 int y_target_margin); |
| 171 |
| 172 // Moves the view port to follow |rect|, if |rect| is partially or completely |
| 173 // outside of the view port. |
| 174 void MoveMaginifierWindowFollowRect(const gfx::Rect& rect); |
| 166 | 175 |
| 167 // ui::InputMethodObserver: | 176 // ui::InputMethodObserver: |
| 168 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} | 177 void OnTextInputTypeChanged(const ui::TextInputClient* client) override {} |
| 169 void OnFocus() override {} | 178 void OnFocus() override {} |
| 170 void OnBlur() override {} | 179 void OnBlur() override {} |
| 171 void OnTextInputStateChanged(const ui::TextInputClient* client) override {} | 180 void OnTextInputStateChanged(const ui::TextInputClient* client) override {} |
| 172 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {} | 181 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {} |
| 173 void OnShowImeIfNeeded() override {} | 182 void OnShowImeIfNeeded() override {} |
| 174 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; | 183 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; |
| 175 | 184 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 break; | 355 break; |
| 347 } | 356 } |
| 348 RedrawDIP(new_origin, scale_, true); | 357 RedrawDIP(new_origin, scale_, true); |
| 349 } | 358 } |
| 350 | 359 |
| 351 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { | 360 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { |
| 352 DCHECK(root_window_); | 361 DCHECK(root_window_); |
| 353 | 362 |
| 354 gfx::Point mouse(location); | 363 gfx::Point mouse(location); |
| 355 int margin = kPanningMergin / scale_; // No need to consider DPI. | 364 int margin = kPanningMergin / scale_; // No need to consider DPI. |
| 356 MoveMagnifierWindow(mouse, margin, margin, margin, margin); | 365 MoveMagnifierWindowFollowPoint(mouse, margin, margin, margin, margin); |
| 366 } |
| 367 |
| 368 gfx::Rect MagnificationControllerImpl::GetViewportRect() { |
| 369 return gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); |
| 370 } |
| 371 |
| 372 void MagnificationControllerImpl::HandleFocusedNodeChanged( |
| 373 bool is_editable_node, |
| 374 const gfx::Rect& node_bounds_in_screen) { |
| 375 // The editable node is handled by OnCaretBoundsChanged. |
| 376 if (is_editable_node) |
| 377 return; |
| 378 |
| 379 gfx::Rect node_bounds_in_root = |
| 380 ScreenUtil::ConvertRectFromScreen(root_window_, node_bounds_in_screen); |
| 381 if (GetViewportRect().Contains(node_bounds_in_root)) |
| 382 return; |
| 383 |
| 384 MoveMaginifierWindowFollowRect(node_bounds_in_root); |
| 357 } | 385 } |
| 358 | 386 |
| 359 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( | 387 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( |
| 360 const gfx::Point& location) { | 388 const gfx::Point& location) { |
| 361 DCHECK(root_window_); | 389 DCHECK(root_window_); |
| 362 | 390 |
| 363 aura::client::CursorClient* cursor_client = | 391 aura::client::CursorClient* cursor_client = |
| 364 aura::client::GetCursorClient(root_window_); | 392 aura::client::GetCursorClient(root_window_); |
| 365 if (cursor_client) { | 393 if (cursor_client) { |
| 366 // When cursor is invisible, do not move or show the cursor after the | 394 // When cursor is invisible, do not move or show the cursor after the |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { | 618 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { |
| 591 aura::Window* target = static_cast<aura::Window*>(event->target()); | 619 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 592 aura::Window* current_root = target->GetRootWindow(); | 620 aura::Window* current_root = target->GetRootWindow(); |
| 593 if (current_root == root_window_) { | 621 if (current_root == root_window_) { |
| 594 gfx::Rect root_bounds = current_root->bounds(); | 622 gfx::Rect root_bounds = current_root->bounds(); |
| 595 if (root_bounds.Contains(event->root_location())) | 623 if (root_bounds.Contains(event->root_location())) |
| 596 point_of_interest_ = event->root_location(); | 624 point_of_interest_ = event->root_location(); |
| 597 } | 625 } |
| 598 } | 626 } |
| 599 | 627 |
| 600 void MagnificationControllerImpl::MoveMagnifierWindow(const gfx::Point& point, | 628 void MagnificationControllerImpl::MoveMagnifierWindowFollowPoint( |
| 601 int x_panning_margin, | 629 const gfx::Point& point, |
| 602 int y_panning_margin, | 630 int x_panning_margin, |
| 603 int x_target_margin, | 631 int y_panning_margin, |
| 604 int y_target_margin) { | 632 int x_target_margin, |
| 633 int y_target_margin) { |
| 605 DCHECK(root_window_); | 634 DCHECK(root_window_); |
| 606 int x = origin_.x(); | |
| 607 int y = origin_.y(); | |
| 608 bool start_zoom = false; | 635 bool start_zoom = false; |
| 609 | 636 |
| 610 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); | 637 const gfx::Rect window_rect = GetViewportRect(); |
| 611 const int left = window_rect.x(); | 638 const int left = window_rect.x(); |
| 612 const int right = window_rect.right(); | 639 const int right = window_rect.right(); |
| 613 | 640 |
| 614 int x_diff = 0; | 641 int x_diff = 0; |
| 615 if (point.x() < left + x_panning_margin) { | 642 if (point.x() < left + x_panning_margin) { |
| 616 // Panning left. | 643 // Panning left. |
| 617 x_diff = point.x() - (left + x_target_margin); | 644 x_diff = point.x() - (left + x_target_margin); |
| 618 start_zoom = true; | 645 start_zoom = true; |
| 619 } else if (right - x_panning_margin < point.x()) { | 646 } else if (right - x_panning_margin < point.x()) { |
| 620 // Panning right. | 647 // Panning right. |
| 621 x_diff = point.x() - (right - x_target_margin); | 648 x_diff = point.x() - (right - x_target_margin); |
| 622 start_zoom = true; | 649 start_zoom = true; |
| 623 } | 650 } |
| 624 x = left + x_diff; | 651 int x = left + x_diff; |
| 625 | 652 |
| 626 const int top = window_rect.y(); | 653 const int top = window_rect.y(); |
| 627 const int bottom = window_rect.bottom(); | 654 const int bottom = window_rect.bottom(); |
| 628 | 655 |
| 629 int y_diff = 0; | 656 int y_diff = 0; |
| 630 if (point.y() < top + y_panning_margin) { | 657 if (point.y() < top + y_panning_margin) { |
| 631 // Panning up. | 658 // Panning up. |
| 632 y_diff = point.y() - (top + y_target_margin); | 659 y_diff = point.y() - (top + y_target_margin); |
| 633 start_zoom = true; | 660 start_zoom = true; |
| 634 } else if (bottom - y_panning_margin < point.y()) { | 661 } else if (bottom - y_panning_margin < point.y()) { |
| 635 // Panning down. | 662 // Panning down. |
| 636 y_diff = point.y() - (bottom - y_target_margin); | 663 y_diff = point.y() - (bottom - y_target_margin); |
| 637 start_zoom = true; | 664 start_zoom = true; |
| 638 } | 665 } |
| 639 y = top + y_diff; | 666 int y = top + y_diff; |
| 640 if (start_zoom && !is_on_animation_) { | 667 if (start_zoom && !is_on_animation_) { |
| 641 // No animation on panning. | 668 // No animation on panning. |
| 642 bool animate = false; | 669 bool animate = false; |
| 643 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); | 670 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); |
| 644 | 671 |
| 645 if (ret) { | 672 if (ret) { |
| 646 // If the magnified region is moved, hides the mouse cursor and moves it. | 673 // If the magnified region is moved, hides the mouse cursor and moves it. |
| 647 if (x_diff != 0 || y_diff != 0) | 674 if (x_diff != 0 || y_diff != 0) |
| 648 MoveCursorTo(root_window_->GetHost(), point); | 675 MoveCursorTo(root_window_->GetHost(), point); |
| 649 } | 676 } |
| 650 } | 677 } |
| 651 } | 678 } |
| 652 | 679 |
| 680 void MagnificationControllerImpl::MoveMaginifierWindowFollowRect( |
| 681 const gfx::Rect& rect) { |
| 682 DCHECK(root_window_); |
| 683 bool start_zoom = false; |
| 684 |
| 685 const gfx::Rect window_rect = GetViewportRect(); |
| 686 const int left = window_rect.x(); |
| 687 const int right = window_rect.right(); |
| 688 const gfx::Point rect_center = rect.CenterPoint(); |
| 689 const gfx::Point window_center = window_rect.CenterPoint(); |
| 690 |
| 691 int x_diff = 0; |
| 692 if (rect.x() < left || right < rect.right()) { |
| 693 // Panning horizontally. |
| 694 x_diff = rect_center.x() - window_center.x(); |
| 695 start_zoom = true; |
| 696 } |
| 697 int x = left + x_diff; |
| 698 |
| 699 const int top = window_rect.y(); |
| 700 const int bottom = window_rect.bottom(); |
| 701 |
| 702 int y_diff = 0; |
| 703 if (rect.y() < top || bottom < rect.bottom()) { |
| 704 // Panning vertically. |
| 705 y_diff = rect_center.y() - window_center.y(); |
| 706 start_zoom = true; |
| 707 } |
| 708 int y = top + y_diff; |
| 709 |
| 710 if (start_zoom && !is_on_animation_) { |
| 711 RedrawDIP(gfx::Point(x, y), scale_, false); // No animation on panning. |
| 712 } |
| 713 } |
| 714 |
| 653 void MagnificationControllerImpl::OnCaretBoundsChanged( | 715 void MagnificationControllerImpl::OnCaretBoundsChanged( |
| 654 const ui::TextInputClient* client) { | 716 const ui::TextInputClient* client) { |
| 655 // caret bounds in screen coordinates. | 717 // caret bounds in screen coordinates. |
| 656 const gfx::Rect caret_bounds = client->GetCaretBounds(); | 718 const gfx::Rect caret_bounds = client->GetCaretBounds(); |
| 657 // Note: OnCaretBoundsChanged could be fired OnTextInputTypeChanged during | 719 // Note: OnCaretBoundsChanged could be fired OnTextInputTypeChanged during |
| 658 // which the caret position is not set a meaning position, and we do not | 720 // which the caret position is not set a meaning position, and we do not |
| 659 // need to adjust the view port position based on the bogus caret position. | 721 // need to adjust the view port position based on the bogus caret position. |
| 660 // This is only a transition period, the caret position will be fixed upon | 722 // This is only a transition period, the caret position will be fixed upon |
| 661 // focusing right after. | 723 // focusing right after. |
| 662 if (caret_bounds.width() == 0 && caret_bounds.height() == 0) | 724 if (caret_bounds.width() == 0 && caret_bounds.height() == 0) |
| 663 return; | 725 return; |
| 664 | 726 |
| 665 gfx::Point caret_origin = caret_bounds.origin(); | 727 gfx::Point caret_origin = caret_bounds.origin(); |
| 666 // caret_origin in |root_window_| coordinates. | 728 // caret_origin in |root_window_| coordinates. |
| 667 wm::ConvertPointFromScreen(root_window_, &caret_origin); | 729 wm::ConvertPointFromScreen(root_window_, &caret_origin); |
| 668 | 730 |
| 669 // Visible window_rect in |root_window_| coordinates. | 731 // Visible window_rect in |root_window_| coordinates. |
| 670 const gfx::Rect visible_window_rect = | 732 const gfx::Rect visible_window_rect = GetViewportRect(); |
| 671 gfx::ToEnclosingRect(GetWindowRectDIP(scale_)); | |
| 672 | 733 |
| 673 const int panning_margin = kCaretPanningMargin / scale_; | 734 const int panning_margin = kCaretPanningMargin / scale_; |
| 674 MoveMagnifierWindow(caret_origin, | 735 MoveMagnifierWindowFollowPoint(caret_origin, panning_margin, panning_margin, |
| 675 panning_margin, | 736 visible_window_rect.width() / 2, |
| 676 panning_margin, | 737 visible_window_rect.height() / 2); |
| 677 visible_window_rect.width() / 2, | |
| 678 visible_window_rect.height() / 2); | |
| 679 } | 738 } |
| 680 | 739 |
| 681 //////////////////////////////////////////////////////////////////////////////// | 740 //////////////////////////////////////////////////////////////////////////////// |
| 682 // MagnificationController: | 741 // MagnificationController: |
| 683 | 742 |
| 684 // static | 743 // static |
| 685 MagnificationController* MagnificationController::CreateInstance() { | 744 MagnificationController* MagnificationController::CreateInstance() { |
| 686 return new MagnificationControllerImpl(); | 745 return new MagnificationControllerImpl(); |
| 687 } | 746 } |
| 688 | 747 |
| 689 } // namespace ash | 748 } // namespace ash |
| OLD | NEW |