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/shelf/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 63 } |
64 | 64 |
65 ShelfLayoutManager* GetShelfLayoutManager() { | 65 ShelfLayoutManager* GetShelfLayoutManager() { |
66 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 66 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
67 } | 67 } |
68 | 68 |
69 SystemTray* GetSystemTray() { | 69 SystemTray* GetSystemTray() { |
70 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); | 70 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); |
71 } | 71 } |
72 | 72 |
73 // Class which waits till the shelf finishes animating to the target size and | |
74 // counts the number of animation steps. | |
75 class ShelfAnimationWaiter : views::WidgetObserver { | |
sadrul
2013/08/13 17:21:34
: public
| |
76 public: | |
77 ShelfAnimationWaiter(const gfx::Rect& target_bounds) | |
sadrul
2013/08/13 17:21:34
explicit
pkotwicz
2013/08/14 17:03:21
Done.
| |
78 : target_bounds_(target_bounds), | |
79 animation_steps_(0), | |
80 done_waiting_(false) { | |
81 GetShelfWidget()->AddObserver(this); | |
82 } | |
83 | |
84 virtual ~ShelfAnimationWaiter() { | |
85 GetShelfWidget()->RemoveObserver(this); | |
86 } | |
87 | |
88 // Wait till the shelf finishes animating to its expected bounds. | |
89 void WaitTillDoneAnimating() { | |
90 if (IsDoneAnimating()) | |
91 done_waiting_ = true; | |
92 else | |
93 base::MessageLoop::current()->Run(); | |
94 } | |
95 | |
96 // Returns true if the animation has completed and it was valid. | |
97 bool WasValidAnimation() const { | |
98 return done_waiting_ && animation_steps_ > 0; | |
99 } | |
100 | |
101 private: | |
102 // Returns true if shelf has finished animating to the target size. | |
103 bool IsDoneAnimating() const { | |
104 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); | |
105 gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); | |
106 int size = layout_manager->PrimaryAxisValue(current_bounds.height(), | |
107 current_bounds.width()); | |
108 int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(), | |
109 target_bounds_.width()); | |
110 return size == desired_size; | |
111 } | |
112 | |
113 // views::WidgetObserver override. | |
114 virtual void OnWidgetBoundsChanged(views::Widget* widget, | |
115 const gfx::Rect& new_bounds) OVERRIDE { | |
116 if (done_waiting_) | |
117 return; | |
118 | |
119 ++animation_steps_; | |
120 if (IsDoneAnimating()) { | |
121 done_waiting_ = true; | |
122 base::MessageLoop::current()->Quit(); | |
123 } | |
124 } | |
125 | |
126 gfx::Rect target_bounds_; | |
127 int animation_steps_; | |
128 bool done_waiting_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter); | |
131 }; | |
132 | |
133 | |
73 class ShelfDragCallback { | 134 class ShelfDragCallback { |
74 public: | 135 public: |
75 ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible) | 136 ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible) |
76 : not_visible_bounds_(not_visible), | 137 : not_visible_bounds_(not_visible), |
77 visible_bounds_(visible), | 138 visible_bounds_(visible), |
78 was_visible_on_drag_start_(false) { | 139 was_visible_on_drag_start_(false) { |
79 EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom()); | 140 EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom()); |
80 } | 141 } |
81 | 142 |
82 virtual ~ShelfDragCallback() { | 143 virtual ~ShelfDragCallback() { |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 base::Bind(&ShelfDragCallback::ProcessScroll, | 630 base::Bind(&ShelfDragCallback::ProcessScroll, |
570 base::Unretained(&handler))); | 631 base::Unretained(&handler))); |
571 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); | 632 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); |
572 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | 633 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); |
573 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString()); | 634 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString()); |
574 | 635 |
575 // Close actually, otherwise further event may be affected since widget | 636 // Close actually, otherwise further event may be affected since widget |
576 // is fullscreen status. | 637 // is fullscreen status. |
577 widget->Close(); | 638 widget->Close(); |
578 RunAllPendingInMessageLoop(); | 639 RunAllPendingInMessageLoop(); |
640 | |
641 // The shelf should be shown because there are no more visible windows. | |
642 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | |
643 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | |
644 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | |
645 | |
646 // Swipe-up to hide. This should have no effect because there are no visible | |
647 // windows. | |
648 end = below_start - delta; | |
649 generator.GestureScrollSequenceWithCallback(below_start, end, | |
650 base::TimeDelta::FromMilliseconds(10), kNumScrollSteps, | |
651 base::Bind(&ShelfDragCallback::ProcessScroll, | |
652 base::Unretained(&handler))); | |
653 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | |
654 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | |
655 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); | |
579 } | 656 } |
580 | 657 |
581 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. | 658 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. |
582 #if defined(OS_MACOSX) || defined(OS_WIN) | 659 #if defined(OS_MACOSX) || defined(OS_WIN) |
583 #define MAYBE_SetVisible DISABLED_SetVisible | 660 #define MAYBE_SetVisible DISABLED_SetVisible |
584 #else | 661 #else |
585 #define MAYBE_SetVisible SetVisible | 662 #define MAYBE_SetVisible SetVisible |
586 #endif | 663 #endif |
587 // Makes sure SetVisible updates work area and widget appropriately. | 664 // Makes sure SetVisible updates work area and widget appropriately. |
588 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { | 665 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 // both visible => normal autohide | 1483 // both visible => normal autohide |
1407 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1484 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1408 | 1485 |
1409 // either minimzed => normal autohide | 1486 // either minimzed => normal autohide |
1410 window2->Minimize(); | 1487 window2->Minimize(); |
1411 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1488 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1412 window2->Restore(); | 1489 window2->Restore(); |
1413 window1->Minimize(); | 1490 window1->Minimize(); |
1414 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1491 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1415 | 1492 |
1416 // both minimzed => disable auto hide | 1493 // both minimized => disable auto hide |
1417 window2->Minimize(); | 1494 window2->Minimize(); |
1418 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 1495 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
1419 | 1496 |
1420 // Test moving windows to/from other display. | 1497 // Test moving windows to/from other display. |
1421 window2->Restore(); | 1498 window2->Restore(); |
1422 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1499 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1423 // Move to second display. | 1500 // Move to second display. |
1424 window2->SetBounds(gfx::Rect(850, 50, 50, 50)); | 1501 window2->SetBounds(gfx::Rect(850, 50, 50, 50)); |
1425 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 1502 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
1426 // Move back to primary display. | 1503 // Move back to primary display. |
1427 window2->SetBounds(gfx::Rect(50, 50, 50, 50)); | 1504 window2->SetBounds(gfx::Rect(50, 50, 50, 50)); |
1428 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 1505 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
1429 } | 1506 } |
1430 | 1507 |
1431 #if defined(OS_WIN) | 1508 // Test that the shelf animates back to its normal position upon a user |
1432 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 | 1509 // completing a gesture drag. |
1433 #define MAYBE_GestureRevealsTrayBubble DISABLED_GestureRevealsTrayBubble | 1510 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) { |
1434 #else | 1511 if (!SupportsHostWindowResize()) |
1435 #define MAYBE_GestureRevealsTrayBubble GestureRevealsTrayBubble | 1512 return; |
1436 #endif | |
1437 | 1513 |
1438 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureRevealsTrayBubble) { | 1514 // Create a visible window so auto-hide behavior is enforced. |
1515 CreateTestWidget(); | |
1516 | |
1517 // Get the bounds of the shelf when it is hidden. | |
1518 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | |
1519 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
1520 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | |
1521 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | |
1522 | |
1523 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); | |
1524 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | |
1525 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); | |
1526 | |
1527 // Reenable the animations so that we can make sure they do occur. | |
1528 ui::ScopedAnimationDurationScaleMode regular_animations( | |
1529 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
1530 | |
1531 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1532 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint(); | |
1533 gfx::Point end(start.x(), start.y() - 100); | |
1534 generator.GestureScrollSequence(start, end, | |
1535 base::TimeDelta::FromMilliseconds(10), 1); | |
1536 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); | |
1537 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | |
1538 | |
1539 ShelfAnimationWaiter waiter(auto_hidden_bounds); | |
1540 // Wait till the animation completes and check that it occurred. | |
1541 waiter.WaitTillDoneAnimating(); | |
1542 EXPECT_TRUE(waiter.WasValidAnimation()); | |
sadrul
2013/08/13 17:21:34
Can we also have a test that the animation happens
pkotwicz
2013/08/14 17:03:21
Done.
| |
1543 } | |
1544 | |
1545 TEST_F(ShelfLayoutManagerTest, GestureRevealsTrayBubble) { | |
1546 if (!SupportsHostWindowResize()) | |
1547 return; | |
1548 | |
1439 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 1549 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
1440 shelf->LayoutShelf(); | 1550 shelf->LayoutShelf(); |
1441 | 1551 |
1442 // Create a visible window so auto-hide behavior is enforced. | 1552 // Create a visible window so auto-hide behavior is enforced. |
1443 CreateTestWidget(); | 1553 CreateTestWidget(); |
1444 | 1554 |
1445 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 1555 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
1446 SystemTray* tray = GetSystemTray(); | 1556 SystemTray* tray = GetSystemTray(); |
1447 | 1557 |
1448 // First, make sure the shelf is visible. | 1558 // First, make sure the shelf is visible. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1678 scoped_ptr<aura::Window> w1(CreateTestWindow()); | 1788 scoped_ptr<aura::Window> w1(CreateTestWindow()); |
1679 w1->Show(); | 1789 w1->Show(); |
1680 wm::ActivateWindow(w1.get()); | 1790 wm::ActivateWindow(w1.get()); |
1681 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); | 1791 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); |
1682 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1792 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
1683 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); | 1793 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); |
1684 } | 1794 } |
1685 | 1795 |
1686 } // namespace internal | 1796 } // namespace internal |
1687 } // namespace ash | 1797 } // namespace ash |
OLD | NEW |