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/wm/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 Step(direction); | 142 Step(direction); |
143 } | 143 } |
144 } else { | 144 } else { |
145 // This is a simple, single-step window cycle. | 145 // This is a simple, single-step window cycle. |
146 StartCycling(); | 146 StartCycling(); |
147 Step(direction); | 147 Step(direction); |
148 StopCycling(); | 148 StopCycling(); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
| 152 void WindowCycleController::HandleLinearCycleWindow() { |
| 153 if (!CanCycle() || IsCycling()) |
| 154 return; |
| 155 |
| 156 // Use the reversed list of windows to prevent a 2-cycle of the most recent |
| 157 // windows occurring. |
| 158 WindowCycleList cycle_list(BuildWindowList(NULL,true)); |
| 159 cycle_list.Step(WindowCycleList::FORWARD); |
| 160 } |
| 161 |
152 void WindowCycleController::AltKeyReleased() { | 162 void WindowCycleController::AltKeyReleased() { |
153 StopCycling(); | 163 StopCycling(); |
154 } | 164 } |
155 | 165 |
156 // static | 166 // static |
157 std::vector<aura::Window*> WindowCycleController::BuildWindowList( | 167 std::vector<aura::Window*> WindowCycleController::BuildWindowList( |
158 const std::list<aura::Window*>* mru_windows) { | 168 const std::list<aura::Window*>* mru_windows, |
| 169 bool top_most_at_end) { |
159 WindowCycleList::WindowList windows; | 170 WindowCycleList::WindowList windows; |
160 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 171 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
161 | 172 |
162 aura::RootWindow* active_root = Shell::GetActiveRootWindow(); | 173 aura::RootWindow* active_root = Shell::GetActiveRootWindow(); |
163 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); | 174 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
164 iter != root_windows.end(); ++iter) { | 175 iter != root_windows.end(); ++iter) { |
165 if (*iter == active_root) | 176 if (*iter == active_root) |
166 continue; | 177 continue; |
167 for (size_t i = 0; i < arraysize(kContainerIds); ++i) | 178 for (size_t i = 0; i < arraysize(kContainerIds); ++i) |
168 AddCycleWindows(*iter, kContainerIds[i], &windows); | 179 AddCycleWindows(*iter, kContainerIds[i], &windows); |
(...skipping 22 matching lines...) Expand all Loading... |
191 WindowCycleList::WindowList::iterator window = | 202 WindowCycleList::WindowList::iterator window = |
192 std::find(windows.begin(), windows.end(), *ix); | 203 std::find(windows.begin(), windows.end(), *ix); |
193 if (window != windows.end()) { | 204 if (window != windows.end()) { |
194 windows.erase(window); | 205 windows.erase(window); |
195 windows.push_back(*ix); | 206 windows.push_back(*ix); |
196 } | 207 } |
197 } | 208 } |
198 } | 209 } |
199 | 210 |
200 // Window cycling expects the topmost window at the front of the list. | 211 // Window cycling expects the topmost window at the front of the list. |
201 std::reverse(windows.begin(), windows.end()); | 212 if (!top_most_at_end) |
| 213 std::reverse(windows.begin(), windows.end()); |
202 | 214 |
203 return windows; | 215 return windows; |
204 } | 216 } |
205 | 217 |
206 void WindowCycleController::OnRootWindowAdded(aura::RootWindow* root_window) { | 218 void WindowCycleController::OnRootWindowAdded(aura::RootWindow* root_window) { |
207 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { | 219 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { |
208 aura::Window* container = | 220 aura::Window* container = |
209 Shell::GetContainer(root_window, kContainerIds[i]); | 221 Shell::GetContainer(root_window, kContainerIds[i]); |
210 container->AddObserver(this); | 222 container->AddObserver(this); |
211 } | 223 } |
212 | 224 |
213 aura::Window* default_container = | 225 aura::Window* default_container = |
214 Shell::GetContainer(root_window, | 226 Shell::GetContainer(root_window, |
215 internal::kShellWindowId_DefaultContainer); | 227 internal::kShellWindowId_DefaultContainer); |
216 for (size_t i = 0; i < default_container->children().size(); ++i) { | 228 for (size_t i = 0; i < default_container->children().size(); ++i) { |
217 aura::Window* workspace_window = default_container->children()[i]; | 229 aura::Window* workspace_window = default_container->children()[i]; |
218 DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer, | 230 DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer, |
219 workspace_window->id()); | 231 workspace_window->id()); |
220 workspace_window->AddObserver(this); | 232 workspace_window->AddObserver(this); |
221 } | 233 } |
222 } | 234 } |
223 | 235 |
224 ////////////////////////////////////////////////////////////////////////////// | 236 ////////////////////////////////////////////////////////////////////////////// |
225 // WindowCycleController, private: | 237 // WindowCycleController, private: |
226 | 238 |
227 void WindowCycleController::StartCycling() { | 239 void WindowCycleController::StartCycling() { |
228 windows_.reset(new WindowCycleList(BuildWindowList(&mru_windows_))); | 240 windows_.reset(new WindowCycleList(BuildWindowList(&mru_windows_, false))); |
229 } | 241 } |
230 | 242 |
231 void WindowCycleController::Step(Direction direction) { | 243 void WindowCycleController::Step(Direction direction) { |
232 DCHECK(windows_.get()); | 244 DCHECK(windows_.get()); |
233 windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD : | 245 windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD : |
234 WindowCycleList::BACKWARD); | 246 WindowCycleList::BACKWARD); |
235 } | 247 } |
236 | 248 |
237 void WindowCycleController::StopCycling() { | 249 void WindowCycleController::StopCycling() { |
238 windows_.reset(); | 250 windows_.reset(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 mru_windows_.remove(window); | 295 mru_windows_.remove(window); |
284 if (window->id() == internal::kShellWindowId_WorkspaceContainer) | 296 if (window->id() == internal::kShellWindowId_WorkspaceContainer) |
285 window->RemoveObserver(this); | 297 window->RemoveObserver(this); |
286 } | 298 } |
287 | 299 |
288 void WindowCycleController::OnWindowDestroying(aura::Window* window) { | 300 void WindowCycleController::OnWindowDestroying(aura::Window* window) { |
289 window->RemoveObserver(this); | 301 window->RemoveObserver(this); |
290 } | 302 } |
291 | 303 |
292 } // namespace ash | 304 } // namespace ash |
OLD | NEW |