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

Side by Side Diff: ui/aura_shell/default_container_layout_manager.cc

Issue 8400063: Move maximize/fullscreen/restore to shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments, property_util Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/aura_shell/default_container_layout_manager.h" 5 #include "ui/aura_shell/default_container_layout_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "ui/aura/aura_constants.h"
8 #include "ui/aura/desktop.h" 9 #include "ui/aura/desktop.h"
9 #include "ui/aura/event.h" 10 #include "ui/aura/event.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
11 #include "ui/aura/screen_aura.h" 12 #include "ui/aura/screen_aura.h"
12 #include "ui/aura/window_types.h" 13 #include "ui/aura/window_types.h"
14 #include "ui/aura/window_observer.h"
15 #include "ui/aura_shell/property_util.h"
16 #include "ui/aura_shell/show_state_controller.h"
13 #include "ui/aura_shell/workspace/workspace.h" 17 #include "ui/aura_shell/workspace/workspace.h"
14 #include "ui/aura_shell/workspace/workspace_manager.h" 18 #include "ui/aura_shell/workspace/workspace_manager.h"
15 #include "ui/base/view_prop.h" 19 #include "ui/base/ui_base_types.h"
16 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
17 #include "views/widget/native_widget_aura.h" 21 #include "views/widget/native_widget_aura.h"
18 22
19 namespace aura_shell { 23 namespace aura_shell {
20 namespace internal { 24 namespace internal {
21 25
22 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
23 // DefaultContainerLayoutManager, public: 27 // DefaultContainerLayoutManager, public:
24 28
25 DefaultContainerLayoutManager::DefaultContainerLayoutManager( 29 DefaultContainerLayoutManager::DefaultContainerLayoutManager(
26 aura::Window* owner, 30 aura::Window* owner,
27 WorkspaceManager* workspace_manager) 31 WorkspaceManager* workspace_manager)
28 : owner_(owner), 32 : owner_(owner),
29 workspace_manager_(workspace_manager), 33 workspace_manager_(workspace_manager),
30 drag_window_(NULL), 34 drag_window_(NULL),
31 ignore_calculate_bounds_(false) { 35 ignore_calculate_bounds_(false),
36 show_state_controller_(new ShowStateController(this)) {
32 } 37 }
33 38
34 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} 39 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {}
35 40
36 void DefaultContainerLayoutManager::PrepareForMoveOrResize( 41 void DefaultContainerLayoutManager::PrepareForMoveOrResize(
37 aura::Window* drag, 42 aura::Window* drag,
38 aura::MouseEvent* event) { 43 aura::MouseEvent* event) {
39 drag_window_ = drag; 44 drag_window_ = drag;
40 } 45 }
41 46
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // DefaultContainerLayoutManager, aura::LayoutManager implementation: 101 // DefaultContainerLayoutManager, aura::LayoutManager implementation:
97 102
98 void DefaultContainerLayoutManager::OnWindowResized() { 103 void DefaultContainerLayoutManager::OnWindowResized() {
99 // Workspace is updated via DesktopObserver::OnDesktopResized. 104 // Workspace is updated via DesktopObserver::OnDesktopResized.
100 } 105 }
101 106
102 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { 107 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
103 if (child->type() != aura::WINDOW_TYPE_NORMAL || child->transient_parent()) 108 if (child->type() != aura::WINDOW_TYPE_NORMAL || child->transient_parent())
104 return; 109 return;
105 110
111 if (!child->GetProperty(aura::kShowStateKey))
112 child->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
113
114 child->AddObserver(show_state_controller_.get());
115
106 AutoReset<bool> reset(&ignore_calculate_bounds_, true); 116 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
107 117
108 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); 118 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
109 if (workspace) { 119 if (workspace) {
110 aura::Window* active = aura::Desktop::GetInstance()->active_window(); 120 aura::Window* active = aura::Desktop::GetInstance()->active_window();
111 // Active window may not be in the default container layer. 121 // Active window may not be in the default container layer.
112 if (!workspace->Contains(active)) 122 if (!workspace->Contains(active))
113 active = NULL; 123 active = NULL;
114 if (workspace->AddWindowAfter(child, active)) 124 if (workspace->AddWindowAfter(child, active))
115 return; 125 return;
116 } 126 }
117 // Create new workspace if new |child| doesn't fit to current workspace. 127 // Create new workspace if new |child| doesn't fit to current workspace.
118 Workspace* new_workspace = workspace_manager_->CreateWorkspace(); 128 Workspace* new_workspace = workspace_manager_->CreateWorkspace();
119 new_workspace->AddWindowAfter(child, NULL); 129 new_workspace->AddWindowAfter(child, NULL);
120 new_workspace->Activate(); 130 new_workspace->Activate();
121 } 131 }
122 132
123 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) { 133 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
124 AutoReset<bool> reset(&ignore_calculate_bounds_, true); 134 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
135 child->RemoveObserver(show_state_controller_.get());
136 ClearRestoreBounds(child);
137
125 Workspace* workspace = workspace_manager_->FindBy(child); 138 Workspace* workspace = workspace_manager_->FindBy(child);
126 if (!workspace) 139 if (!workspace)
127 return; 140 return;
128 workspace->RemoveWindow(child); 141 workspace->RemoveWindow(child);
129 if (workspace->is_empty()) 142 if (workspace->is_empty())
130 delete workspace; 143 delete workspace;
131 } 144 }
132 145
133 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( 146 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
134 aura::Window* child, 147 aura::Window* child,
135 bool visible) { 148 bool visible) {
136 NOTIMPLEMENTED(); 149 NOTIMPLEMENTED();
137 } 150 }
138 151
139 void DefaultContainerLayoutManager::CalculateBoundsForChild( 152 void DefaultContainerLayoutManager::SetChildBounds(
140 aura::Window* child, 153 aura::Window* child,
141 gfx::Rect* requested_bounds) { 154 const gfx::Rect& requested_bounds) {
155 gfx::Rect adjusted_bounds = requested_bounds;
156
157 // First, calculate the adjusted bounds.
142 if (child->type() != aura::WINDOW_TYPE_NORMAL || 158 if (child->type() != aura::WINDOW_TYPE_NORMAL ||
143 ignore_calculate_bounds_ || 159 ignore_calculate_bounds_ ||
144 child->transient_parent()) 160 child->transient_parent()) {
145 return; 161 // Use the requested bounds as is.
146 162 } else if (drag_window_) {
147 // If a drag window is requesting bounds, make sure its attached to 163 // If a drag window is requesting bounds, make sure its attached to
148 // the workarea's top and fits within the total drag area. 164 // the workarea's top and fits within the total drag area.
149 if (drag_window_) {
150 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds(); 165 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds();
151 requested_bounds->set_y(drag_area.y()); 166 adjusted_bounds.set_y(drag_area.y());
152 *requested_bounds = requested_bounds->AdjustToFit(drag_area); 167 adjusted_bounds = adjusted_bounds.AdjustToFit(drag_area);
153 return; 168 } else {
169 Workspace* workspace = workspace_manager_->FindBy(child);
170 gfx::Rect work_area = workspace->GetWorkAreaBounds();
171 adjusted_bounds.set_origin(
172 gfx::Point(child->GetTargetBounds().x(), work_area.y()));
173 adjusted_bounds = adjusted_bounds.AdjustToFit(work_area);
154 } 174 }
155 175
156 Workspace* workspace = workspace_manager_->FindBy(child); 176 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
157 gfx::Rect work_area = workspace->GetWorkAreaBounds(); 177 child->GetIntProperty(aura::kShowStateKey));
158 requested_bounds->set_origin( 178
159 gfx::Point(child->GetTargetBounds().x(), work_area.y())); 179 // Second, check if the window is either maximized or in fullscreen mode.
160 *requested_bounds = requested_bounds->AdjustToFit(work_area); 180 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
181 show_state == ui::SHOW_STATE_FULLSCREEN) {
182 // If the request is not from workspace manager,
183 // remember the requested bounds.
184 if (!ignore_calculate_bounds_)
185 SetRestoreBounds(child, adjusted_bounds);
186
187 Workspace* workspace = workspace_manager_->FindBy(child);
188 if (show_state == ui::SHOW_STATE_MAXIMIZED)
189 adjusted_bounds = workspace->GetWorkAreaBounds();
190 else
191 adjusted_bounds = workspace->bounds();
192 // Don't
193 if (child->GetTargetBounds() == adjusted_bounds)
194 return;
195 }
196 SetChildBoundsDirect(child, adjusted_bounds);
161 } 197 }
162 198
163 } // namespace internal 199 } // namespace internal
164 } // namespace aura_shell 200 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698