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

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

Issue 9969164: Ignoring alignment when it pushes a window out of the screen (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moving align to grid functionality into WindowPositioner / WindowSizer Created 8 years, 8 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_manager.h" 5 #include "ash/wm/workspace/workspace_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/wm/property_util.h" 11 #include "ash/wm/property_util.h"
12 #include "ash/wm/shelf_layout_manager.h" 12 #include "ash/wm/shelf_layout_manager.h"
13 #include "ash/wm/window_animations.h" 13 #include "ash/wm/window_animations.h"
14 #include "ash/wm/window_resizer.h" 14 #include "ash/wm/window_resizer.h"
sky 2012/04/13 19:44:02 Can you remove this include now?
Mr4D (OOO till 08-26) 2012/04/13 20:47:39 Done.
15 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/managed_workspace.h" 16 #include "ash/wm/workspace/managed_workspace.h"
17 #include "ash/wm/workspace/maximized_workspace.h" 17 #include "ash/wm/workspace/maximized_workspace.h"
18 #include "base/auto_reset.h" 18 #include "base/auto_reset.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "ui/aura/env.h" 21 #include "ui/aura/env.h"
22 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
24 #include "ui/aura/monitor.h" 24 #include "ui/aura/monitor.h"
(...skipping 11 matching lines...) Expand all
36 // Returns a list of all the windows with layers in |result|. 36 // Returns a list of all the windows with layers in |result|.
37 void BuildWindowList(const std::vector<aura::Window*>& windows, 37 void BuildWindowList(const std::vector<aura::Window*>& windows,
38 std::vector<aura::Window*>* result) { 38 std::vector<aura::Window*>* result) {
39 for (size_t i = 0; i < windows.size(); ++i) { 39 for (size_t i = 0; i < windows.size(); ++i) {
40 if (windows[i]->layer()) 40 if (windows[i]->layer())
41 result->push_back(windows[i]); 41 result->push_back(windows[i]);
42 BuildWindowList(windows[i]->transient_children(), result); 42 BuildWindowList(windows[i]->transient_children(), result);
43 } 43 }
44 } 44 }
45 45
46 gfx::Rect AlignRectToGrid(const gfx::Rect& rect, int grid_size) {
47 if (grid_size <= 1)
48 return rect;
49 return gfx::Rect(ash::WindowResizer::AlignToGrid(rect.x(), grid_size),
50 ash::WindowResizer::AlignToGrid(rect.y(), grid_size),
51 ash::WindowResizer::AlignToGrid(rect.width(), grid_size),
52 ash::WindowResizer::AlignToGrid(rect.height(), grid_size));
53 }
54
55 } 46 }
56 47
57 namespace ash { 48 namespace ash {
58 namespace internal { 49 namespace internal {
59 50
60 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
61 // WindowManager, public: 52 // WindowManager, public:
62 53
63 WorkspaceManager::WorkspaceManager(aura::Window* contents_view) 54 WorkspaceManager::WorkspaceManager(aura::Window* contents_view)
64 : contents_view_(contents_view), 55 : contents_view_(contents_view),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (active_workspace_ != current_workspace) { 89 if (active_workspace_ != current_workspace) {
99 if (active_workspace_) 90 if (active_workspace_)
100 window->layer()->GetAnimator()->StopAnimating(); 91 window->layer()->GetAnimator()->StopAnimating();
101 current_workspace->Activate(); 92 current_workspace->Activate();
102 } 93 }
103 window->Show(); 94 window->Show();
104 UpdateShelfVisibility(); 95 UpdateShelfVisibility();
105 return; 96 return;
106 } 97 }
107 98
108 if (wm::IsWindowNormal(window) && grid_size_ > 1)
109 SetWindowBounds(window, AlignBoundsToGrid(window->GetTargetBounds()));
110
111 Workspace* workspace = NULL; 99 Workspace* workspace = NULL;
112 Workspace::Type type_for_window = Workspace::TypeForWindow(window); 100 Workspace::Type type_for_window = Workspace::TypeForWindow(window);
113 switch (type_for_window) { 101 switch (type_for_window) {
114 case Workspace::TYPE_MANAGED: 102 case Workspace::TYPE_MANAGED:
115 // All normal windows go in the same workspace. 103 // All normal windows go in the same workspace.
116 workspace = GetManagedWorkspace(); 104 workspace = GetManagedWorkspace();
117 break; 105 break;
118 106
119 case Workspace::TYPE_MAXIMIZED: 107 case Workspace::TYPE_MAXIMIZED:
120 // All maximized windows go in their own workspace. 108 // All maximized windows go in their own workspace.
(...skipping 15 matching lines...) Expand all
136 CleanupWorkspace(workspace); 124 CleanupWorkspace(workspace);
137 UpdateShelfVisibility(); 125 UpdateShelfVisibility();
138 } 126 }
139 127
140 void WorkspaceManager::SetActiveWorkspaceByWindow(aura::Window* window) { 128 void WorkspaceManager::SetActiveWorkspaceByWindow(aura::Window* window) {
141 Workspace* workspace = FindBy(window); 129 Workspace* workspace = FindBy(window);
142 if (workspace) 130 if (workspace)
143 workspace->Activate(); 131 workspace->Activate();
144 } 132 }
145 133
146 gfx::Rect WorkspaceManager::AlignBoundsToGrid(const gfx::Rect& bounds) {
147 if (grid_size_ <= 1)
148 return bounds;
149 return AlignRectToGrid(bounds, grid_size_);
150 }
151
152 void WorkspaceManager::UpdateShelfVisibility() { 134 void WorkspaceManager::UpdateShelfVisibility() {
153 shelf_->UpdateVisibilityState(); 135 shelf_->UpdateVisibilityState();
154 } 136 }
155 137
156 WorkspaceManager::WindowState WorkspaceManager::GetWindowState() { 138 WorkspaceManager::WindowState WorkspaceManager::GetWindowState() {
157 if (!shelf_ || !active_workspace_) 139 if (!shelf_ || !active_workspace_)
158 return WINDOW_STATE_DEFAULT; 140 return WINDOW_STATE_DEFAULT;
159 141
160 // TODO: this code needs to be made multi-monitor aware. 142 // TODO: this code needs to be made multi-monitor aware.
161 gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(contents_view_)); 143 gfx::Rect bounds(gfx::Screen::GetMonitorAreaNearestWindow(contents_view_));
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return workspace; 331 return workspace;
350 } 332 }
351 333
352 void WorkspaceManager::CleanupWorkspace(Workspace* workspace) { 334 void WorkspaceManager::CleanupWorkspace(Workspace* workspace) {
353 if (workspace->type() != Workspace::TYPE_MANAGED && workspace->is_empty()) 335 if (workspace->type() != Workspace::TYPE_MANAGED && workspace->is_empty())
354 delete workspace; 336 delete workspace;
355 } 337 }
356 338
357 } // namespace internal 339 } // namespace internal
358 } // namespace ash 340 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698