| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/accessibility_types.h" | 7 #include "ash/common/accessibility_types.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void FocusOnTextInput() { GetFocusManager()->SetFocusedView(text_field_); } | 51 void FocusOnTextInput() { GetFocusManager()->SetFocusedView(text_field_); } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 views::Textfield* text_field_; // owned by views hierarchy | 54 views::Textfield* text_field_; // owned by views hierarchy |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(TextInputView); | 56 DISALLOW_COPY_AND_ASSIGN(TextInputView); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 class MagnificationControllerTest: public test::AshTestBase { | 61 class MagnificationControllerTest : public test::AshTestBase { |
| 62 public: | 62 public: |
| 63 MagnificationControllerTest() : text_input_view_(NULL) {} | 63 MagnificationControllerTest() : text_input_view_(NULL) {} |
| 64 ~MagnificationControllerTest() override {} | 64 ~MagnificationControllerTest() override {} |
| 65 | 65 |
| 66 void SetUp() override { | 66 void SetUp() override { |
| 67 AshTestBase::SetUp(); | 67 AshTestBase::SetUp(); |
| 68 UpdateDisplay(base::StringPrintf("%dx%d", kRootWidth, kRootHeight)); | 68 UpdateDisplay(base::StringPrintf("%dx%d", kRootWidth, kRootHeight)); |
| 69 | 69 |
| 70 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
| 71 // RootWindow and Display can't resize on Windows Ash. | 71 // RootWindow and Display can't resize on Windows Ash. |
| 72 // http://crbug.com/165962 | 72 // http://crbug.com/165962 |
| 73 aura::Window* root = GetRootWindow(); | 73 aura::Window* root = GetRootWindow(); |
| 74 gfx::Rect root_bounds(root->bounds()); | 74 gfx::Rect root_bounds(root->bounds()); |
| 75 EXPECT_EQ(kRootHeight, root_bounds.height()); | 75 EXPECT_EQ(kRootHeight, root_bounds.height()); |
| 76 EXPECT_EQ(kRootWidth, root_bounds.width()); | 76 EXPECT_EQ(kRootWidth, root_bounds.width()); |
| 77 #endif | 77 #endif |
| 78 | 78 |
| 79 GetMagnificationController()->DisableMoveMagnifierDelayForTesting(); | 79 GetMagnificationController()->DisableMoveMagnifierDelayForTesting(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void TearDown() override { AshTestBase::TearDown(); } | 82 void TearDown() override { AshTestBase::TearDown(); } |
| 83 | 83 |
| 84 protected: | 84 protected: |
| 85 aura::Window* GetRootWindow() const { | 85 aura::Window* GetRootWindow() const { return Shell::GetPrimaryRootWindow(); } |
| 86 return Shell::GetPrimaryRootWindow(); | |
| 87 } | |
| 88 | 86 |
| 89 std::string GetHostMouseLocation() { | 87 std::string GetHostMouseLocation() { |
| 90 const gfx::Point& location = | 88 const gfx::Point& location = |
| 91 aura::test::QueryLatestMousePositionRequestInHost( | 89 aura::test::QueryLatestMousePositionRequestInHost( |
| 92 GetRootWindow()->GetHost()); | 90 GetRootWindow()->GetHost()); |
| 93 return location.ToString(); | 91 return location.ToString(); |
| 94 } | 92 } |
| 95 | 93 |
| 96 ash::MagnificationController* GetMagnificationController() const { | 94 ash::MagnificationController* GetMagnificationController() const { |
| 97 return ash::Shell::GetInstance()->magnification_controller(); | 95 return ash::Shell::GetInstance()->magnification_controller(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 gfx::Rect GetViewport() const { | 98 gfx::Rect GetViewport() const { |
| 101 gfx::RectF bounds(0, 0, kRootWidth, kRootHeight); | 99 gfx::RectF bounds(0, 0, kRootWidth, kRootHeight); |
| 102 GetRootWindow()->layer()->transform().TransformRectReverse(&bounds); | 100 GetRootWindow()->layer()->transform().TransformRectReverse(&bounds); |
| 103 return gfx::ToEnclosingRect(bounds); | 101 return gfx::ToEnclosingRect(bounds); |
| 104 } | 102 } |
| 105 | 103 |
| 106 std::string CurrentPointOfInterest() const { | 104 std::string CurrentPointOfInterest() const { |
| 107 return GetMagnificationController()-> | 105 return GetMagnificationController() |
| 108 GetPointOfInterestForTesting().ToString(); | 106 ->GetPointOfInterestForTesting() |
| 107 .ToString(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void CreateAndShowTextInputView(const gfx::Rect& bounds) { | 110 void CreateAndShowTextInputView(const gfx::Rect& bounds) { |
| 112 text_input_view_ = new TextInputView; | 111 text_input_view_ = new TextInputView; |
| 113 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 112 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 114 text_input_view_, GetRootWindow(), bounds); | 113 text_input_view_, GetRootWindow(), bounds); |
| 115 widget->Show(); | 114 widget->Show(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 // Returns the text input view's bounds in root window coordinates. | 117 // Returns the text input view's bounds in root window coordinates. |
| 119 gfx::Rect GetTextInputViewBounds() { | 118 gfx::Rect GetTextInputViewBounds() { |
| 120 DCHECK(text_input_view_); | 119 DCHECK(text_input_view_); |
| 121 gfx::Rect bounds = text_input_view_->bounds(); | 120 gfx::Rect bounds = text_input_view_->bounds(); |
| 122 gfx::Point origin = bounds.origin(); | 121 gfx::Point origin = bounds.origin(); |
| 123 // Convert origin to screen coordinates. | 122 // Convert origin to screen coordinates. |
| 124 views::View::ConvertPointToScreen(text_input_view_, &origin); | 123 views::View::ConvertPointToScreen(text_input_view_, &origin); |
| 125 // Convert origin to root_window_ coordinates. | 124 // Convert origin to root_window_ coordinates. |
| 126 ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); | 125 ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
| 127 return gfx::Rect(origin.x(), origin.y(), bounds.width(), bounds.height()); | 126 return gfx::Rect(origin.x(), origin.y(), bounds.width(), bounds.height()); |
| 128 } | 127 } |
| 129 | 128 |
| 130 // Returns the caret bounds in root window coordinates. | 129 // Returns the caret bounds in root window coordinates. |
| 131 gfx::Rect GetCaretBounds() { | 130 gfx::Rect GetCaretBounds() { |
| 132 gfx::Rect caret_bounds = | 131 gfx::Rect caret_bounds = |
| 133 GetInputMethod()->GetTextInputClient()->GetCaretBounds(); | 132 GetInputMethod()->GetTextInputClient()->GetCaretBounds(); |
| 134 gfx::Point origin = caret_bounds.origin(); | 133 gfx::Point origin = caret_bounds.origin(); |
| 135 ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); | 134 ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
| 136 return gfx::Rect( | 135 return gfx::Rect(origin.x(), origin.y(), caret_bounds.width(), |
| 137 origin.x(), origin.y(), caret_bounds.width(), caret_bounds.height()); | 136 caret_bounds.height()); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void FocusOnTextInputView() { | 139 void FocusOnTextInputView() { |
| 141 DCHECK(text_input_view_); | 140 DCHECK(text_input_view_); |
| 142 text_input_view_->FocusOnTextInput(); | 141 text_input_view_->FocusOnTextInput(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 private: | 144 private: |
| 146 TextInputView* text_input_view_; | 145 TextInputView* text_input_view_; |
| 147 | 146 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 GetMagnificationController()->HandleFocusedNodeChanged( | 277 GetMagnificationController()->HandleFocusedNodeChanged( |
| 279 false, gfx::Rect(0, 0, 10, 10)); | 278 false, gfx::Rect(0, 0, 10, 10)); |
| 280 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); | 279 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 281 | 280 |
| 282 // Move viewport to element in lower right. | 281 // Move viewport to element in lower right. |
| 283 GetMagnificationController()->HandleFocusedNodeChanged( | 282 GetMagnificationController()->HandleFocusedNodeChanged( |
| 284 false, gfx::Rect(790, 590, 10, 10)); | 283 false, gfx::Rect(790, 590, 10, 10)); |
| 285 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); | 284 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 286 | 285 |
| 287 // Don't follow focus onto empty rectangle. | 286 // Don't follow focus onto empty rectangle. |
| 288 GetMagnificationController()->HandleFocusedNodeChanged( | 287 GetMagnificationController()->HandleFocusedNodeChanged(false, |
| 289 false, gfx::Rect(0, 0, 0, 0)); | 288 gfx::Rect(0, 0, 0, 0)); |
| 290 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); | 289 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 291 } | 290 } |
| 292 | 291 |
| 293 TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { | 292 TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { |
| 294 const aura::Env* env = aura::Env::GetInstance(); | 293 const aura::Env* env = aura::Env::GetInstance(); |
| 295 | 294 |
| 296 GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 0)); | 295 GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 0)); |
| 297 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); | 296 EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 298 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); | 297 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 299 EXPECT_EQ("0,0", env->last_mouse_location().ToString()); | 298 EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 675 |
| 677 // Verify the view port has been moved to the place where the text field is | 676 // Verify the view port has been moved to the place where the text field is |
| 678 // contained in the view port and the caret is at the center of the view port. | 677 // contained in the view port and the caret is at the center of the view port. |
| 679 gfx::Rect new_view_port = GetViewport(); | 678 gfx::Rect new_view_port = GetViewport(); |
| 680 EXPECT_NE(view_port, new_view_port); | 679 EXPECT_NE(view_port, new_view_port); |
| 681 EXPECT_TRUE(new_view_port.Contains(text_input_bounds)); | 680 EXPECT_TRUE(new_view_port.Contains(text_input_bounds)); |
| 682 gfx::Rect caret_bounds = GetCaretBounds(); | 681 gfx::Rect caret_bounds = GetCaretBounds(); |
| 683 EXPECT_EQ(caret_bounds.CenterPoint(), new_view_port.CenterPoint()); | 682 EXPECT_EQ(caret_bounds.CenterPoint(), new_view_port.CenterPoint()); |
| 684 } | 683 } |
| 685 | 684 |
| 686 | |
| 687 // Make sure that unified desktop can enter magnified mode. | 685 // Make sure that unified desktop can enter magnified mode. |
| 688 TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { | 686 TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { |
| 689 if (!SupportsMultipleDisplays()) | 687 if (!SupportsMultipleDisplays()) |
| 690 return; | 688 return; |
| 691 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); | 689 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); |
| 692 | 690 |
| 693 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); | 691 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 694 | 692 |
| 695 GetMagnificationController()->SetEnabled(true); | 693 GetMagnificationController()->SetEnabled(true); |
| 696 | 694 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 710 UpdateDisplay("500x500"); | 708 UpdateDisplay("500x500"); |
| 711 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); | 709 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 712 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); | 710 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 713 | 711 |
| 714 GetMagnificationController()->SetEnabled(false); | 712 GetMagnificationController()->SetEnabled(false); |
| 715 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); | 713 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 716 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); | 714 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 717 } | 715 } |
| 718 | 716 |
| 719 } // namespace ash | 717 } // namespace ash |
| OLD | NEW |