OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
6 #include "ash/screen_ash.h" | 6 #include "ash/screen_ash.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/shell_test_api.h" | 9 #include "ash/test/shell_test_api.h" |
10 #include "ash/wm/mru_window_tracker.h" | 10 #include "ash/wm/mru_window_tracker.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 ScopedVector<LayerAnimationObserver> animations; | 100 ScopedVector<LayerAnimationObserver> animations; |
101 for (size_t i = 0; i < windows.size(); ++i) { | 101 for (size_t i = 0; i < windows.size(); ++i) { |
102 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); | 102 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); |
103 } | 103 } |
104 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | 104 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); |
105 for (size_t i = 0; i < animations.size(); ++i) { | 105 for (size_t i = 0; i < animations.size(); ++i) { |
106 animations[i]->WaitUntilDone(); | 106 animations[i]->WaitUntilDone(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
| 110 void Cycle(WindowSelector::Direction direction) { |
| 111 if (!IsSelecting()) { |
| 112 std::vector<aura::Window*> windows = ash::Shell::GetInstance()-> |
| 113 mru_window_tracker()->BuildMruWindowList(); |
| 114 ScopedVector<LayerAnimationObserver> animations; |
| 115 for (size_t i = 0; i < windows.size(); ++i) |
| 116 animations.push_back(new LayerAnimationObserver(windows[i]->layer())); |
| 117 ash::Shell::GetInstance()->window_selector_controller()-> |
| 118 HandleCycleWindow(direction); |
| 119 for (size_t i = 0; i < animations.size(); ++i) |
| 120 animations[i]->WaitUntilDone(); |
| 121 } else { |
| 122 ash::Shell::GetInstance()->window_selector_controller()-> |
| 123 HandleCycleWindow(direction); |
| 124 } |
| 125 } |
| 126 |
| 127 void StopCycling() { |
| 128 ash::Shell::GetInstance()->window_selector_controller()->AltKeyReleased(); |
| 129 } |
| 130 |
110 gfx::RectF GetTransformedBounds(aura::Window* window) { | 131 gfx::RectF GetTransformedBounds(aura::Window* window) { |
111 gfx::RectF bounds(window->layer()->bounds()); | 132 gfx::RectF bounds(window->layer()->bounds()); |
112 window->layer()->transform().TransformRect(&bounds); | 133 window->layer()->transform().TransformRect(&bounds); |
113 return bounds; | 134 return bounds; |
114 } | 135 } |
115 | 136 |
116 gfx::RectF GetTransformedTargetBounds(aura::Window* window) { | 137 gfx::RectF GetTransformedTargetBounds(aura::Window* window) { |
117 gfx::RectF bounds(window->layer()->GetTargetBounds()); | 138 gfx::RectF bounds(window->layer()->GetTargetBounds()); |
118 window->layer()->GetTargetTransform().TransformRect(&bounds); | 139 window->layer()->GetTargetTransform().TransformRect(&bounds); |
119 return bounds; | 140 return bounds; |
120 } | 141 } |
121 | 142 |
122 void ClickWindow(aura::Window* window) { | 143 void ClickWindow(aura::Window* window) { |
123 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); | 144 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); |
124 gfx::RectF target = GetTransformedBounds(window); | 145 gfx::RectF target = GetTransformedBounds(window); |
125 event_generator.ClickLeftButton(); | 146 event_generator.ClickLeftButton(); |
126 } | 147 } |
127 | 148 |
| 149 bool IsSelecting() { |
| 150 return ash::Shell::GetInstance()->window_selector_controller()-> |
| 151 IsSelecting(); |
| 152 } |
| 153 |
128 private: | 154 private: |
129 aura::test::TestWindowDelegate wd; | 155 aura::test::TestWindowDelegate wd; |
130 | 156 |
131 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | 157 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
132 }; | 158 }; |
133 | 159 |
134 // Tests entering overview mode with two windows and selecting one. | 160 // Tests entering overview mode with two windows and selecting one. |
135 TEST_F(WindowSelectorTest, Basic) { | 161 TEST_F(WindowSelectorTest, Basic) { |
136 gfx::Rect bounds(0, 0, 400, 400); | 162 gfx::Rect bounds(0, 0, 400, 400); |
137 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 163 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
138 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 164 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
139 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); | 165 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); |
140 wm::ActivateWindow(window2.get()); | 166 wm::ActivateWindow(window2.get()); |
141 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 167 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
142 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 168 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
143 | 169 |
144 // In overview mode the windows should no longer overlap. | 170 // In overview mode the windows should no longer overlap. |
145 ToggleOverview(); | 171 ToggleOverview(); |
146 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | 172 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); |
147 | 173 |
148 // Clicking window 1 should activate it. | 174 // Clicking window 1 should activate it. |
149 ClickWindow(window1.get()); | 175 ClickWindow(window1.get()); |
150 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 176 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
151 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 177 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
152 } | 178 } |
153 | 179 |
| 180 // Tests entering overview mode with three windows and cycling through them. |
| 181 TEST_F(WindowSelectorTest, BasicCycle) { |
| 182 gfx::Rect bounds(0, 0, 400, 400); |
| 183 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 184 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 185 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); |
| 186 wm::ActivateWindow(window3.get()); |
| 187 wm::ActivateWindow(window2.get()); |
| 188 wm::ActivateWindow(window1.get()); |
| 189 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 190 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
| 191 EXPECT_FALSE(wm::IsActiveWindow(window3.get())); |
| 192 |
| 193 Cycle(WindowSelector::FORWARD); |
| 194 EXPECT_TRUE(IsSelecting()); |
| 195 Cycle(WindowSelector::FORWARD); |
| 196 StopCycling(); |
| 197 EXPECT_FALSE(IsSelecting()); |
| 198 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 199 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
| 200 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 201 } |
| 202 |
154 // Tests that overview mode is exited if the last remaining window is destroyed. | 203 // Tests that overview mode is exited if the last remaining window is destroyed. |
155 TEST_F(WindowSelectorTest, LastWindowDestroyed) { | 204 TEST_F(WindowSelectorTest, LastWindowDestroyed) { |
156 gfx::Rect bounds(0, 0, 400, 400); | 205 gfx::Rect bounds(0, 0, 400, 400); |
157 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 206 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
158 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 207 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
159 ToggleOverview(); | 208 ToggleOverview(); |
160 | 209 |
161 window1.reset(); | 210 window1.reset(); |
162 window2.reset(); | 211 window2.reset(); |
163 EXPECT_FALSE(ash::Shell::GetInstance()->window_selector_controller()-> | 212 EXPECT_FALSE(IsSelecting()); |
164 IsSelecting()); | |
165 } | 213 } |
166 | 214 |
167 // Tests that windows remain on the display they are currently on in overview | 215 // Tests that windows remain on the display they are currently on in overview |
168 // mode. | 216 // mode. |
169 TEST_F(WindowSelectorTest, MultipleDisplays) { | 217 TEST_F(WindowSelectorTest, MultipleDisplays) { |
170 if (!SupportsMultipleDisplays()) | 218 if (!SupportsMultipleDisplays()) |
171 return; | 219 return; |
172 | 220 |
173 UpdateDisplay("400x400,400x400"); | 221 UpdateDisplay("400x400,400x400"); |
174 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
(...skipping 18 matching lines...) Expand all Loading... |
193 root_windows[0]->bounds().Contains( | 241 root_windows[0]->bounds().Contains( |
194 ToEnclosingRect(GetTransformedBounds(window2.get()))); | 242 ToEnclosingRect(GetTransformedBounds(window2.get()))); |
195 root_windows[1]->bounds().Contains( | 243 root_windows[1]->bounds().Contains( |
196 ToEnclosingRect(GetTransformedBounds(window3.get()))); | 244 ToEnclosingRect(GetTransformedBounds(window3.get()))); |
197 root_windows[1]->bounds().Contains( | 245 root_windows[1]->bounds().Contains( |
198 ToEnclosingRect(GetTransformedBounds(window4.get()))); | 246 ToEnclosingRect(GetTransformedBounds(window4.get()))); |
199 } | 247 } |
200 | 248 |
201 } // namespace internal | 249 } // namespace internal |
202 } // namespace ash | 250 } // namespace ash |
OLD | NEW |