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

Side by Side Diff: ash/wm/workspace/workspace_layout_manager.cc

Issue 13896026: Stick windows to sides of workspaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dock on left or right edge Created 7 years, 6 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
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/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/session_state_delegate.h" 9 #include "ash/session_state_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h"
11 #include "ash/wm/always_on_top_controller.h" 12 #include "ash/wm/always_on_top_controller.h"
12 #include "ash/wm/base_layout_manager.h" 13 #include "ash/wm/base_layout_manager.h"
14 #include "ash/wm/dock/dock_edge_types.h"
13 #include "ash/wm/window_animations.h" 15 #include "ash/wm/window_animations.h"
14 #include "ash/wm/window_properties.h" 16 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/workspace.h" 18 #include "ash/wm/workspace/workspace.h"
17 #include "ash/wm/workspace/workspace_manager.h" 19 #include "ash/wm/workspace/workspace_manager.h"
18 #include "ash/wm/workspace/workspace_window_resizer.h" 20 #include "ash/wm/workspace/workspace_window_resizer.h"
19 #include "base/auto_reset.h" 21 #include "base/auto_reset.h"
20 #include "base/command_line.h" 22 #include "base/command_line.h"
21 #include "ui/aura/client/aura_constants.h" 23 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
(...skipping 18 matching lines...) Expand all
41 typedef std::map<const aura::Window*, gfx::Rect> BoundsMap; 43 typedef std::map<const aura::Window*, gfx::Rect> BoundsMap;
42 44
43 // Adds an entry from |window| to its bounds and recursively invokes this for 45 // Adds an entry from |window| to its bounds and recursively invokes this for
44 // all children. 46 // all children.
45 void BuildWindowBoundsMap(const aura::Window* window, BoundsMap* bounds_map) { 47 void BuildWindowBoundsMap(const aura::Window* window, BoundsMap* bounds_map) {
46 (*bounds_map)[window] = window->bounds(); 48 (*bounds_map)[window] = window->bounds();
47 for (size_t i = 0; i < window->children().size(); ++i) 49 for (size_t i = 0; i < window->children().size(); ++i)
48 BuildWindowBoundsMap(window->children()[i], bounds_map); 50 BuildWindowBoundsMap(window->children()[i], bounds_map);
49 } 51 }
50 52
51 // Resets |window|s bounds from |bounds_map| if currently empty. Recusively 53 // Resets |window|s bounds from |bounds_map| if currently empty. Recursively
52 // invokes this for all children. 54 // invokes this for all children.
53 void ResetBoundsIfNecessary(const BoundsMap& bounds_map, aura::Window* window) { 55 void ResetBoundsIfNecessary(const BoundsMap& bounds_map, aura::Window* window) {
54 if (window->bounds().IsEmpty() && window->GetTargetBounds().IsEmpty()) { 56 if (window->bounds().IsEmpty() && window->GetTargetBounds().IsEmpty()) {
55 BoundsMap::const_iterator i = bounds_map.find(window); 57 BoundsMap::const_iterator i = bounds_map.find(window);
56 if (i != bounds_map.end()) 58 if (i != bounds_map.end())
57 window->SetBounds(i->second); 59 window->SetBounds(i->second);
58 } 60 }
59 for (size_t i = 0; i < window->children().size(); ++i) 61 for (size_t i = 0; i < window->children().size(); ++i)
60 ResetBoundsIfNecessary(bounds_map, window->children()[i]); 62 ResetBoundsIfNecessary(bounds_map, window->children()[i]);
61 } 63 }
62 64
63 // Resets |window|s bounds from |bounds_map| if |window| is marked as a 65 // Resets |window|s bounds from |bounds_map| if |window| is marked as a
64 // constrained window. Recusively invokes this for all children. 66 // constrained window. Recursively invokes this for all children.
65 // TODO(sky): this should key off window type. 67 // TODO(sky): this should key off window type.
66 void ResetConstrainedWindowBoundsIfNecessary(const BoundsMap& bounds_map, 68 void ResetConstrainedWindowBoundsIfNecessary(const BoundsMap& bounds_map,
67 aura::Window* window) { 69 aura::Window* window) {
68 if (window->GetProperty(aura::client::kConstrainedWindowKey)) { 70 if (window->GetProperty(aura::client::kConstrainedWindowKey)) {
69 BoundsMap::const_iterator i = bounds_map.find(window); 71 BoundsMap::const_iterator i = bounds_map.find(window);
70 if (i != bounds_map.end()) 72 if (i != bounds_map.end())
71 window->SetBounds(i->second); 73 window->SetBounds(i->second);
72 } 74 }
73 for (size_t i = 0; i < window->children().size(); ++i) 75 for (size_t i = 0; i < window->children().size(); ++i)
74 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window->children()[i]); 76 ResetConstrainedWindowBoundsIfNecessary(bounds_map, window->children()[i]);
(...skipping 15 matching lines...) Expand all
90 if (root_window_) { 92 if (root_window_) {
91 root_window_->RemoveObserver(this); 93 root_window_->RemoveObserver(this);
92 root_window_->RemoveRootWindowObserver(this); 94 root_window_->RemoveRootWindowObserver(this);
93 } 95 }
94 for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i) 96 for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i)
95 (*i)->RemoveObserver(this); 97 (*i)->RemoveObserver(this);
96 Shell::GetInstance()->RemoveShellObserver(this); 98 Shell::GetInstance()->RemoveShellObserver(this);
97 } 99 }
98 100
99 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) { 101 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) {
102 LOG(INFO) << this << " OnWindowAddedToLayout " << child;
100 // Adjust window bounds in case that the new child is out of the workspace. 103 // Adjust window bounds in case that the new child is out of the workspace.
101 AdjustWindowSizeForScreenChange(child, ADJUST_WINDOW_WINDOW_ADDED); 104 AdjustWindowSizeForScreenChange(child, ADJUST_WINDOW_WINDOW_ADDED);
102 105
103 windows_.insert(child); 106 windows_.insert(child);
104 child->AddObserver(this); 107 child->AddObserver(this);
105 108
106 // Only update the bounds if the window has a show state that depends on the 109 // Only update the bounds if the window has a show state that depends on the
107 // workspace area. 110 // workspace area.
108 if (wm::IsWindowMaximized(child) || wm::IsWindowFullscreen(child)) 111 if (wm::IsWindowMaximized(child) || wm::IsWindowFullscreen(child))
109 UpdateBoundsFromShowState(child); 112 UpdateBoundsFromShowState(child);
110 113
111 workspace_manager()->OnWindowAddedToWorkspace(workspace_, child); 114 workspace_manager()->OnWindowAddedToWorkspace(workspace_, child);
112 } 115 }
113 116
114 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { 117 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) {
115 windows_.erase(child); 118 windows_.erase(child);
116 child->RemoveObserver(this); 119 child->RemoveObserver(this);
117 workspace_manager()->OnWillRemoveWindowFromWorkspace(workspace_, child); 120 workspace_manager()->OnWillRemoveWindowFromWorkspace(workspace_, child);
118 } 121 }
119 122
120 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) { 123 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(Window* child) {
124 LOG(INFO) << this << " OnWindowRemovedFromLayout " << child;
121 workspace_manager()->OnWindowRemovedFromWorkspace(workspace_, child); 125 workspace_manager()->OnWindowRemovedFromWorkspace(workspace_, child);
122 } 126 }
123 127
124 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child, 128 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(Window* child,
125 bool visible) { 129 bool visible) {
126 if (visible && wm::IsWindowMinimized(child)) { 130 if (visible && wm::IsWindowMinimized(child)) {
127 // Attempting to show a minimized window. Unminimize it. 131 // Attempting to show a minimized window. Unminimize it.
128 child->SetProperty(aura::client::kShowStateKey, 132 child->SetProperty(aura::client::kShowStateKey,
129 child->GetProperty(aura::client::kRestoreShowStateKey)); 133 child->GetProperty(aura::client::kRestoreShowStateKey));
130 child->ClearProperty(aura::client::kRestoreShowStateKey); 134 child->ClearProperty(aura::client::kRestoreShowStateKey);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 workspace_manager()->OnTrackedByWorkspaceChanged(workspace_, window); 238 workspace_manager()->OnTrackedByWorkspaceChanged(workspace_, window);
235 } 239 }
236 240
237 if (key == aura::client::kAlwaysOnTopKey && 241 if (key == aura::client::kAlwaysOnTopKey &&
238 window->GetProperty(aura::client::kAlwaysOnTopKey)) { 242 window->GetProperty(aura::client::kAlwaysOnTopKey)) {
239 internal::AlwaysOnTopController* controller = 243 internal::AlwaysOnTopController* controller =
240 window->GetRootWindow()->GetProperty( 244 window->GetRootWindow()->GetProperty(
241 internal::kAlwaysOnTopControllerKey); 245 internal::kAlwaysOnTopControllerKey);
242 controller->GetContainer(window)->AddChild(window); 246 controller->GetContainer(window)->AddChild(window);
243 } 247 }
248
249 if (key == ash::internal::kDockEdges &&
250 GetDockEdges(window) != static_cast<int>(old)) {
251 LOG(INFO) << "Stuck property changed to " << GetDockEdges(window);
252 aura::Window* dock_container = ash::Shell::GetContainer(
253 root_window_,
254 ash::internal::kShellWindowId_DockContainer);
255 DCHECK(dock_container);
256 int edges = GetDockEdges(window) & (DOCK_EDGE_RIGHT | DOCK_EDGE_LEFT);
257 if (edges &&
258 0 == (static_cast<int>(old) & (DOCK_EDGE_RIGHT | DOCK_EDGE_LEFT))) {
259 LOG(INFO) << "adding " << window << " to dock " << dock_container;
260 dock_container->AddChild(window);
261 }
262 }
244 } 263 }
245 264
246 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { 265 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) {
247 if (root_window_ == window) { 266 if (root_window_ == window) {
248 root_window_->RemoveObserver(this); 267 root_window_->RemoveObserver(this);
249 root_window_ = NULL; 268 root_window_ = NULL;
250 } 269 }
251 } 270 }
252 271
253 void WorkspaceLayoutManager::ShowStateChanged( 272 void WorkspaceLayoutManager::ShowStateChanged(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 405 }
387 return false; 406 return false;
388 } 407 }
389 408
390 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { 409 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() {
391 return workspace_->workspace_manager(); 410 return workspace_->workspace_manager();
392 } 411 }
393 412
394 } // namespace internal 413 } // namespace internal
395 } // namespace ash 414 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698