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/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/display_manager_test_api.h" | 10 #include "ash/test/display_manager_test_api.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 aura::Window* root = GetRootWindow(); | 72 aura::Window* root = GetRootWindow(); |
73 gfx::Rect root_bounds(root->bounds()); | 73 gfx::Rect root_bounds(root->bounds()); |
74 | 74 |
75 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
76 // RootWindow and Display can't resize on Windows Ash. | 76 // RootWindow and Display can't resize on Windows Ash. |
77 // http://crbug.com/165962 | 77 // http://crbug.com/165962 |
78 EXPECT_EQ(kRootHeight, root_bounds.height()); | 78 EXPECT_EQ(kRootHeight, root_bounds.height()); |
79 EXPECT_EQ(kRootWidth, root_bounds.width()); | 79 EXPECT_EQ(kRootWidth, root_bounds.width()); |
80 #endif | 80 #endif |
| 81 |
| 82 GetMagnificationController()->DisableMoveMagnifierDelayForTesting(); |
81 } | 83 } |
82 | 84 |
83 void TearDown() override { AshTestBase::TearDown(); } | 85 void TearDown() override { AshTestBase::TearDown(); } |
84 | 86 |
85 protected: | 87 protected: |
86 aura::Window* GetRootWindow() const { | 88 aura::Window* GetRootWindow() const { |
87 return Shell::GetPrimaryRootWindow(); | 89 return Shell::GetPrimaryRootWindow(); |
88 } | 90 } |
89 | 91 |
90 std::string GetHostMouseLocation() { | 92 std::string GetHostMouseLocation() { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 521 } |
520 | 522 |
521 TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { | 523 TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { |
522 CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); | 524 CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); |
523 gfx::Rect text_input_bounds = GetTextInputViewBounds(); | 525 gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
524 | 526 |
525 // Enables magnifier and confirm the viewport is at center. | 527 // Enables magnifier and confirm the viewport is at center. |
526 GetMagnificationController()->SetEnabled(true); | 528 GetMagnificationController()->SetEnabled(true); |
527 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); | 529 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
528 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); | 530 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 531 EXPECT_FALSE(GetMagnificationController()->KeepFocusCentered()); |
529 | 532 |
530 // Move the viewport to (0, 0), so that text input field will be out of | 533 // Move the viewport to (0, 0), so that text input field will be out of |
531 // the viewport region. | 534 // the viewport region. |
532 GetMagnificationController()->MoveWindow(0, 0, false); | 535 GetMagnificationController()->MoveWindow(0, 0, false); |
533 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); | 536 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
534 EXPECT_FALSE(GetViewport().Intersects(text_input_bounds)); | 537 EXPECT_FALSE(GetViewport().Intersects(text_input_bounds)); |
535 | 538 |
536 // Focus on the text input field. | 539 // Focus on the text input field. |
537 FocusOnTextInputView(); | 540 FocusOnTextInputView(); |
538 | 541 |
539 // Verify the view port has been moved to the place where the text field is | 542 // Verify the view port has been moved to the place where the text field is |
540 // contained in the view port and the caret is at the center of the view port. | 543 // contained in the view port and the caret is at the center of the view port. |
541 gfx::Rect view_port = GetViewport(); | 544 gfx::Rect view_port = GetViewport(); |
542 EXPECT_TRUE(view_port.Contains(text_input_bounds)); | 545 EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
543 gfx::Rect caret_bounds = GetCaretBounds(); | 546 gfx::Rect caret_bounds = GetCaretBounds(); |
544 EXPECT_TRUE(text_input_bounds.Contains(caret_bounds)); | 547 EXPECT_TRUE(text_input_bounds.Contains(caret_bounds)); |
545 EXPECT_EQ(caret_bounds.origin(), view_port.CenterPoint()); | 548 EXPECT_EQ(caret_bounds.CenterPoint(), view_port.CenterPoint()); |
546 } | 549 } |
547 | 550 |
| 551 // Tests the following case. First the text input field intersects on the right |
| 552 // edge with the view port, with focus caret sitting just a little left to the |
| 553 // caret panning margin, so that when it gets focus, the view port won't move. |
| 554 // Then when user types a character, the caret moves beyond the right panning |
| 555 // edge, the view port will be moved to center the caret horizontally. |
548 TEST_F(MagnificationControllerTest, FollowTextInputFieldKeyPress) { | 556 TEST_F(MagnificationControllerTest, FollowTextInputFieldKeyPress) { |
549 CreateAndShowTextInputView(gfx::Rect(385, 200, 80, 80)); | 557 const int kCaretPanningMargin = 50; |
| 558 const int kScale = 2.0f; |
| 559 const int kViewportWidth = 400; |
| 560 // Add some extra distance horizontally from text caret to to left edge of |
| 561 // the text input view. |
| 562 int x = kViewportWidth - (kCaretPanningMargin + 20) / kScale; |
| 563 CreateAndShowTextInputView(gfx::Rect(x, 200, 80, 80)); |
550 gfx::Rect text_input_bounds = GetTextInputViewBounds(); | 564 gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
551 | 565 |
552 // Enables magnifier and confirm the viewport is at center. | 566 // Enables magnifier and confirm the viewport is at center. |
553 GetMagnificationController()->SetEnabled(true); | 567 GetMagnificationController()->SetEnabled(true); |
554 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); | 568 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
555 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); | 569 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 570 EXPECT_FALSE(GetMagnificationController()->KeepFocusCentered()); |
556 | 571 |
557 // Move the viewport to (0, 0), so that text input field intersects the | 572 // Move the viewport to (0, 0), so that text input field intersects the |
558 // view port at the right edge. | 573 // view port at the right edge. |
559 GetMagnificationController()->MoveWindow(0, 0, false); | 574 GetMagnificationController()->MoveWindow(0, 0, false); |
560 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); | 575 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
561 EXPECT_TRUE(GetViewport().Intersects(text_input_bounds)); | 576 EXPECT_TRUE(GetViewport().Intersects(text_input_bounds)); |
562 | 577 |
563 // Focus on the text input field. | 578 // Focus on the text input field. |
564 FocusOnTextInputView(); | 579 FocusOnTextInputView(); |
565 | 580 |
566 // Verify the view port is not moved, and the caret is inside the view port. | 581 // Verify the view port is not moved, and the caret is inside the view port |
| 582 // and not beyond the caret right panning margin. |
567 gfx::Rect view_port = GetViewport(); | 583 gfx::Rect view_port = GetViewport(); |
568 EXPECT_EQ("0,0 400x300", view_port.ToString()); | 584 EXPECT_EQ("0,0 400x300", view_port.ToString()); |
569 EXPECT_TRUE(view_port.Intersects(text_input_bounds)); | |
570 EXPECT_TRUE(text_input_bounds.Contains(GetCaretBounds())); | 585 EXPECT_TRUE(text_input_bounds.Contains(GetCaretBounds())); |
| 586 EXPECT_GT(view_port.right() - kCaretPanningMargin / kScale, |
| 587 GetCaretBounds().x()); |
571 | 588 |
572 // Press keys on text input simulate typing on text field and the caret | 589 // Press keys on text input simulate typing on text field and the caret |
573 // moves out of the old view port region. The view port is moved to the place | 590 // moves beyond the caret right panning margin. The view port is moved to the |
574 // where caret's x coordinate is centered at the new view port. | 591 // place where caret's x coordinate is centered at the new view port. |
575 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 592 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
576 generator.PressKey(ui::VKEY_A, 0); | 593 generator.PressKey(ui::VKEY_A, 0); |
577 generator.ReleaseKey(ui::VKEY_A, 0); | 594 generator.ReleaseKey(ui::VKEY_A, 0); |
578 gfx::Rect caret_bounds = GetCaretBounds(); | 595 gfx::Rect caret_bounds = GetCaretBounds(); |
579 EXPECT_FALSE(view_port.Intersects(caret_bounds)); | 596 EXPECT_LT(view_port.right() - kCaretPanningMargin / kScale, |
| 597 GetCaretBounds().x()); |
580 | 598 |
581 gfx::Rect new_view_port = GetViewport(); | 599 gfx::Rect new_view_port = GetViewport(); |
582 EXPECT_TRUE(new_view_port.Contains(caret_bounds)); | 600 EXPECT_EQ(caret_bounds.CenterPoint().x(), new_view_port.CenterPoint().x()); |
583 EXPECT_EQ(caret_bounds.x(), new_view_port.CenterPoint().x()); | |
584 EXPECT_EQ(view_port.y(), new_view_port.y()); | |
585 } | 601 } |
586 | 602 |
| 603 TEST_F(MagnificationControllerTest, CenterTextCaretNotInsideViewport) { |
| 604 CreateAndShowTextInputView(gfx::Rect(500, 300, 50, 30)); |
| 605 gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 606 |
| 607 // Enables magnifier and confirm the viewport is at center. |
| 608 GetMagnificationController()->SetKeepFocusCentered(true); |
| 609 GetMagnificationController()->SetEnabled(true); |
| 610 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 611 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 612 EXPECT_TRUE(GetMagnificationController()->KeepFocusCentered()); |
| 613 |
| 614 // Move the viewport to (0, 0), so that text input field will be out of |
| 615 // the viewport region. |
| 616 GetMagnificationController()->MoveWindow(0, 0, false); |
| 617 EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 618 EXPECT_FALSE(GetViewport().Contains(text_input_bounds)); |
| 619 |
| 620 // Focus on the text input field. |
| 621 FocusOnTextInputView(); |
| 622 RunAllPendingInMessageLoop(); |
| 623 // Verify the view port has been moved to the place where the text field is |
| 624 // contained in the view port and the caret is at the center of the view port. |
| 625 gfx::Rect view_port = GetViewport(); |
| 626 EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 627 gfx::Rect caret_bounds = GetCaretBounds(); |
| 628 EXPECT_EQ(caret_bounds.CenterPoint(), view_port.CenterPoint()); |
| 629 |
| 630 // Press keys on text input simulate typing on text field and the view port |
| 631 // should be moved to keep the caret centered. |
| 632 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 633 generator.PressKey(ui::VKEY_A, 0); |
| 634 generator.ReleaseKey(ui::VKEY_A, 0); |
| 635 RunAllPendingInMessageLoop(); |
| 636 gfx::Rect new_caret_bounds = GetCaretBounds(); |
| 637 EXPECT_NE(caret_bounds, new_caret_bounds); |
| 638 |
| 639 gfx::Rect new_view_port = GetViewport(); |
| 640 EXPECT_NE(view_port, new_view_port); |
| 641 EXPECT_TRUE(new_view_port.Contains(new_caret_bounds)); |
| 642 EXPECT_EQ(new_caret_bounds.CenterPoint(), new_view_port.CenterPoint()); |
| 643 } |
| 644 |
| 645 TEST_F(MagnificationControllerTest, CenterTextCaretInViewport) { |
| 646 CreateAndShowTextInputView(gfx::Rect(250, 200, 50, 30)); |
| 647 gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 648 |
| 649 // Enables magnifier and confirm the viewport is at center. |
| 650 GetMagnificationController()->SetKeepFocusCentered(true); |
| 651 GetMagnificationController()->SetEnabled(true); |
| 652 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 653 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 654 EXPECT_TRUE(GetMagnificationController()->KeepFocusCentered()); |
| 655 |
| 656 // Verify the text input field is inside the view port. |
| 657 gfx::Rect view_port = GetViewport(); |
| 658 EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 659 |
| 660 // Focus on the text input field. |
| 661 FocusOnTextInputView(); |
| 662 RunAllPendingInMessageLoop(); |
| 663 |
| 664 // Verify the view port has been moved to the place where the text field is |
| 665 // contained in the view port and the caret is at the center of the view port. |
| 666 gfx::Rect new_view_port = GetViewport(); |
| 667 EXPECT_NE(view_port, new_view_port); |
| 668 EXPECT_TRUE(new_view_port.Contains(text_input_bounds)); |
| 669 gfx::Rect caret_bounds = GetCaretBounds(); |
| 670 EXPECT_EQ(caret_bounds.CenterPoint(), new_view_port.CenterPoint()); |
| 671 } |
| 672 |
| 673 |
587 // Make sure that unified desktop can enter magnified mode. | 674 // Make sure that unified desktop can enter magnified mode. |
588 TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { | 675 TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { |
589 if (!SupportsMultipleDisplays()) | 676 if (!SupportsMultipleDisplays()) |
590 return; | 677 return; |
591 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); | 678 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest(); |
592 | 679 |
593 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 680 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
594 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); | 681 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); |
595 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); | 682 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); |
596 | 683 |
(...skipping 18 matching lines...) Expand all Loading... |
615 UpdateDisplay("500x500"); | 702 UpdateDisplay("500x500"); |
616 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); | 703 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
617 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); | 704 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
618 | 705 |
619 GetMagnificationController()->SetEnabled(false); | 706 GetMagnificationController()->SetEnabled(false); |
620 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); | 707 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
621 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); | 708 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
622 } | 709 } |
623 | 710 |
624 } // namespace ash | 711 } // namespace ash |
OLD | NEW |