Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Side by Side Diff: ash/wm/window_cycle_controller.cc

Issue 10830365: Initial crack at new workspace behavior. Each workspace now has its (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/window_cycle_controller.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ash/wm/activation_controller.h" 11 #include "ash/wm/activation_controller.h"
12 #include "ash/wm/window_cycle_list.h" 12 #include "ash/wm/window_cycle_list.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "ash/wm/workspace_controller.h"
14 #include "ui/aura/event_filter.h" 15 #include "ui/aura/event_filter.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
16 #include "ui/base/event.h" 17 #include "ui/base/event.h"
17 18
18 namespace ash { 19 namespace ash {
19 20
20 namespace { 21 namespace {
21 22
22 // List of containers whose children we will cycle through. 23 // List of containers whose children we will cycle through.
23 const int kContainerIds[] = { 24 const int kContainerIds[] = {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ui::TouchEvent* event) { 78 ui::TouchEvent* event) {
78 return ui::TOUCH_STATUS_UNKNOWN; // Not handled. 79 return ui::TOUCH_STATUS_UNKNOWN; // Not handled.
79 } 80 }
80 81
81 ui::GestureStatus WindowCycleEventFilter::PreHandleGestureEvent( 82 ui::GestureStatus WindowCycleEventFilter::PreHandleGestureEvent(
82 aura::Window* target, 83 aura::Window* target,
83 ui::GestureEvent* event) { 84 ui::GestureEvent* event) {
84 return ui::GESTURE_STATUS_UNKNOWN; // Not handled. 85 return ui::GESTURE_STATUS_UNKNOWN; // Not handled.
85 } 86 }
86 87
88 // Adds all the children of |window| to |windows|.
89 void AddAllChildren(aura::Window* window,
90 WindowCycleList::WindowList* windows) {
91 const WindowCycleList::WindowList& children(window->children());
92 windows->insert(windows->end(), children.begin(), children.end());
93 }
94
95 // Adds all the children of all of |window|s children to |windows|.
96 void AddWorkspace2Children(aura::Window* window,
97 WindowCycleList::WindowList* windows) {
98 for (size_t i = 0; i < window->children().size(); ++i)
99 AddAllChildren(window->children()[i], windows);
100 }
101
102 // Adds the windows that can be cycled through for the specified window id to
103 // |windows|.
104 void AddCycleWindows(aura::RootWindow* root,
105 int container_id,
106 WindowCycleList::WindowList* windows) {
107 aura::Window* container = Shell::GetContainer(root, container_id);
108 if (container_id == internal::kShellWindowId_DefaultContainer &&
109 internal::WorkspaceController::IsWorkspace2Enabled()) {
110 AddWorkspace2Children(container, windows);
111 } else {
112 AddAllChildren(container, windows);
113 }
114 }
115
87 } // namespace 116 } // namespace
88 117
89 ////////////////////////////////////////////////////////////////////////////// 118 //////////////////////////////////////////////////////////////////////////////
90 // WindowCycleController, public: 119 // WindowCycleController, public:
91 120
92 WindowCycleController::WindowCycleController( 121 WindowCycleController::WindowCycleController(
93 internal::ActivationController* activation_controller) 122 internal::ActivationController* activation_controller)
94 : activation_controller_(activation_controller) { 123 : activation_controller_(activation_controller) {
95 activation_controller_->AddObserver(this); 124 activation_controller_->AddObserver(this);
96 } 125 }
97 126
98 WindowCycleController::~WindowCycleController() { 127 WindowCycleController::~WindowCycleController() {
99 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 128 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
100 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); 129 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
101 iter != root_windows.end(); ++iter) { 130 iter != root_windows.end(); ++iter) {
102 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { 131 for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
103 aura::Window* container = Shell::GetContainer(*iter, kContainerIds[i]); 132 aura::Window* container = Shell::GetContainer(*iter, kContainerIds[i]);
104 if (container) 133 if (container)
105 container->RemoveObserver(this); 134 container->RemoveObserver(this);
106 } 135 }
136 aura::Window* default_container =
137 Shell::GetContainer(*iter, internal::kShellWindowId_DefaultContainer);
138 if (default_container) {
139 for (size_t i = 0; i < default_container->children().size(); ++i) {
140 aura::Window* workspace_window = default_container->children()[i];
141 DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
142 workspace_window->id());
143 workspace_window->RemoveObserver(this);
144 }
145 }
107 } 146 }
108 147
109 activation_controller_->RemoveObserver(this); 148 activation_controller_->RemoveObserver(this);
110 StopCycling(); 149 StopCycling();
111 } 150 }
112 151
113 // static 152 // static
114 bool WindowCycleController::CanCycle() { 153 bool WindowCycleController::CanCycle() {
115 // Don't allow window cycling if the screen is locked or a modal dialog is 154 // Don't allow window cycling if the screen is locked or a modal dialog is
116 // open. 155 // open.
(...skipping 28 matching lines...) Expand all
145 void WindowCycleController::AltKeyReleased() { 184 void WindowCycleController::AltKeyReleased() {
146 StopCycling(); 185 StopCycling();
147 } 186 }
148 187
149 // static 188 // static
150 std::vector<aura::Window*> WindowCycleController::BuildWindowList( 189 std::vector<aura::Window*> WindowCycleController::BuildWindowList(
151 const std::list<aura::Window*>* mru_windows) { 190 const std::list<aura::Window*>* mru_windows) {
152 WindowCycleList::WindowList windows; 191 WindowCycleList::WindowList windows;
153 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 192 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
154 193
194 aura::RootWindow* active_root = Shell::GetActiveRootWindow();
155 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); 195 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
156 iter != root_windows.end(); ++iter) { 196 iter != root_windows.end(); ++iter) {
157 if (*iter == Shell::GetActiveRootWindow()) 197 if (*iter == active_root)
158 continue; 198 continue;
159 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { 199 for (size_t i = 0; i < arraysize(kContainerIds); ++i)
160 aura::Window* container = Shell::GetContainer(*iter, kContainerIds[i]); 200 AddCycleWindows(*iter, kContainerIds[i], &windows);
161 WindowCycleList::WindowList children = container->children();
162 windows.insert(windows.end(), children.begin(), children.end());
163 }
164 } 201 }
165 202
166 // Add windows in the active root windows last so that the topmost window 203 // Add windows in the active root windows last so that the topmost window
167 // in the active root window becomes the front of the list. 204 // in the active root window becomes the front of the list.
168 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { 205 for (size_t i = 0; i < arraysize(kContainerIds); ++i)
169 aura::Window* container = 206 AddCycleWindows(active_root, kContainerIds[i], &windows);
170 Shell::GetContainer(Shell::GetActiveRootWindow(), kContainerIds[i]);
171
172 WindowCycleList::WindowList children = container->children();
173 windows.insert(windows.end(), children.begin(), children.end());
174 }
175 207
176 // Removes unfocusable windows. 208 // Removes unfocusable windows.
177 WindowCycleList::WindowList::iterator last = 209 WindowCycleList::WindowList::iterator last =
178 std::remove_if( 210 std::remove_if(
179 windows.begin(), 211 windows.begin(),
180 windows.end(), 212 windows.end(),
181 std::not1(std::ptr_fun(ash::wm::CanActivateWindow))); 213 std::not1(std::ptr_fun(ash::wm::CanActivateWindow)));
182 windows.erase(last, windows.end()); 214 windows.erase(last, windows.end());
183 215
184 // Put the windows in the mru_windows list at the head, if it's available. 216 // Put the windows in the mru_windows list at the head, if it's available.
(...skipping 17 matching lines...) Expand all
202 234
203 return windows; 235 return windows;
204 } 236 }
205 237
206 void WindowCycleController::OnRootWindowAdded(aura::RootWindow* root_window) { 238 void WindowCycleController::OnRootWindowAdded(aura::RootWindow* root_window) {
207 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { 239 for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
208 aura::Window* container = 240 aura::Window* container =
209 Shell::GetContainer(root_window, kContainerIds[i]); 241 Shell::GetContainer(root_window, kContainerIds[i]);
210 container->AddObserver(this); 242 container->AddObserver(this);
211 } 243 }
244
245 aura::Window* default_container =
246 Shell::GetContainer(root_window,
247 internal::kShellWindowId_DefaultContainer);
248 for (size_t i = 0; i < default_container->children().size(); ++i) {
249 aura::Window* workspace_window = default_container->children()[i];
250 DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
251 workspace_window->id());
252 workspace_window->AddObserver(this);
253 }
212 } 254 }
213 255
214 ////////////////////////////////////////////////////////////////////////////// 256 //////////////////////////////////////////////////////////////////////////////
215 // WindowCycleController, private: 257 // WindowCycleController, private:
216 258
217 void WindowCycleController::StartCycling() { 259 void WindowCycleController::StartCycling() {
218 windows_.reset(new WindowCycleList(BuildWindowList(&mru_windows_))); 260 windows_.reset(new WindowCycleList(BuildWindowList(&mru_windows_)));
219 } 261 }
220 262
221 void WindowCycleController::Step(Direction direction) { 263 void WindowCycleController::Step(Direction direction) {
(...skipping 18 matching lines...) Expand all
240 282
241 // static 283 // static
242 bool WindowCycleController::IsTrackedContainer(aura::Window* window) { 284 bool WindowCycleController::IsTrackedContainer(aura::Window* window) {
243 if (!window) 285 if (!window)
244 return false; 286 return false;
245 for (size_t i = 0; i < arraysize(kContainerIds); ++i) { 287 for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
246 if (window->id() == kContainerIds[i]) { 288 if (window->id() == kContainerIds[i]) {
247 return true; 289 return true;
248 } 290 }
249 } 291 }
250 return false; 292 return window->id() == internal::kShellWindowId_WorkspaceContainer;
251 } 293 }
252 294
253 void WindowCycleController::InstallEventFilter() { 295 void WindowCycleController::InstallEventFilter() {
254 event_filter_.reset(new WindowCycleEventFilter()); 296 event_filter_.reset(new WindowCycleEventFilter());
255 Shell::GetInstance()->AddEnvEventFilter(event_filter_.get()); 297 Shell::GetInstance()->AddEnvEventFilter(event_filter_.get());
256 } 298 }
257 299
258 void WindowCycleController::OnWindowActivated(aura::Window* active, 300 void WindowCycleController::OnWindowActivated(aura::Window* active,
259 aura::Window* old_active) { 301 aura::Window* old_active) {
260 if (active && !IsCycling() && IsTrackedContainer(active->parent())) { 302 if (active && !IsCycling() && IsTrackedContainer(active->parent())) {
261 mru_windows_.remove(active); 303 mru_windows_.remove(active);
262 mru_windows_.push_front(active); 304 mru_windows_.push_front(active);
263 } 305 }
264 } 306 }
265 307
308 void WindowCycleController::OnWindowAdded(aura::Window* window) {
309 if (window->id() == internal::kShellWindowId_WorkspaceContainer)
310 window->AddObserver(this);
311 }
312
266 void WindowCycleController::OnWillRemoveWindow(aura::Window* window) { 313 void WindowCycleController::OnWillRemoveWindow(aura::Window* window) {
267 mru_windows_.remove(window); 314 mru_windows_.remove(window);
315 if (window->id() == internal::kShellWindowId_WorkspaceContainer)
316 window->RemoveObserver(this);
268 } 317 }
269 318
270 void WindowCycleController::OnWindowDestroying(aura::Window* window) { 319 void WindowCycleController::OnWindowDestroying(aura::Window* window) {
271 window->RemoveObserver(this); 320 window->RemoveObserver(this);
272 } 321 }
273 322
274 } // namespace ash 323 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_controller.h ('k') | ash/wm/window_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698