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

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

Issue 8430024: Add WorkspaceObserver to observe changes in workspace state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update comments 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"
8 #include "ui/aura/aura_constants.h" 7 #include "ui/aura/aura_constants.h"
9 #include "ui/aura/desktop.h" 8 #include "ui/aura/desktop.h"
10 #include "ui/aura/event.h" 9 #include "ui/aura/event.h"
11 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
12 #include "ui/aura/screen_aura.h" 11 #include "ui/aura/screen_aura.h"
13 #include "ui/aura/window_types.h" 12 #include "ui/aura/window_types.h"
14 #include "ui/aura/window_observer.h" 13 #include "ui/aura/window_observer.h"
15 #include "ui/aura_shell/property_util.h" 14 #include "ui/aura_shell/property_util.h"
16 #include "ui/aura_shell/show_state_controller.h" 15 #include "ui/aura_shell/show_state_controller.h"
17 #include "ui/aura_shell/workspace/workspace.h" 16 #include "ui/aura_shell/workspace/workspace.h"
18 #include "ui/aura_shell/workspace/workspace_manager.h" 17 #include "ui/aura_shell/workspace/workspace_manager.h"
19 #include "ui/base/ui_base_types.h" 18 #include "ui/base/ui_base_types.h"
20 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
21 #include "views/widget/native_widget_aura.h" 20 #include "views/widget/native_widget_aura.h"
22 21
23 namespace aura_shell { 22 namespace aura_shell {
24 namespace internal { 23 namespace internal {
25 24
26 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
27 // DefaultContainerLayoutManager, public: 26 // DefaultContainerLayoutManager, public:
28 27
29 DefaultContainerLayoutManager::DefaultContainerLayoutManager( 28 DefaultContainerLayoutManager::DefaultContainerLayoutManager(
30 aura::Window* owner,
31 WorkspaceManager* workspace_manager) 29 WorkspaceManager* workspace_manager)
32 : owner_(owner), 30 : workspace_manager_(workspace_manager),
33 workspace_manager_(workspace_manager),
34 drag_window_(NULL), 31 drag_window_(NULL),
35 ignore_calculate_bounds_(false), 32 show_state_controller_(new ShowStateController(workspace_manager)) {
36 show_state_controller_(new ShowStateController(this)) {
37 } 33 }
38 34
39 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} 35 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {}
40 36
41 void DefaultContainerLayoutManager::PrepareForMoveOrResize( 37 void DefaultContainerLayoutManager::PrepareForMoveOrResize(
42 aura::Window* drag, 38 aura::Window* drag,
43 aura::MouseEvent* event) { 39 aura::MouseEvent* event) {
44 drag_window_ = drag; 40 drag_window_ = drag;
45 } 41 }
46 42
47 void DefaultContainerLayoutManager::CancelMoveOrResize( 43 void DefaultContainerLayoutManager::CancelMoveOrResize(
48 aura::Window* drag, 44 aura::Window* drag,
49 aura::MouseEvent* event) { 45 aura::MouseEvent* event) {
50 drag_window_ = NULL; 46 drag_window_ = NULL;
51 } 47 }
52 48
53 void DefaultContainerLayoutManager::ProcessMove( 49 void DefaultContainerLayoutManager::ProcessMove(
54 aura::Window* drag, 50 aura::Window* drag,
55 aura::MouseEvent* event) { 51 aura::MouseEvent* event) {
56 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
57
58 // TODO(oshima): Just zooming out may (and will) move/swap window without 52 // TODO(oshima): Just zooming out may (and will) move/swap window without
59 // a users's intent. We probably should scroll viewport, but that may not 53 // a users's intent. We probably should scroll viewport, but that may not
60 // be enough. See crbug.com/101826 for more discussion. 54 // be enough. See crbug.com/101826 for more discussion.
61 workspace_manager_->SetOverview(true); 55 workspace_manager_->SetOverview(true);
62 56
63 gfx::Point point_in_owner = event->location(); 57 gfx::Point point_in_owner = event->location();
64 aura::Window::ConvertPointToWindow( 58 aura::Window::ConvertPointToWindow(
65 drag, 59 drag,
66 owner_, 60 workspace_manager_->viewport(),
67 &point_in_owner); 61 &point_in_owner);
68 // TODO(oshima): We should support simply moving to another 62 // TODO(oshima): We should support simply moving to another
69 // workspace when the destination workspace has enough room to accomodate. 63 // workspace when the destination workspace has enough room to accomodate.
70 aura::Window* rotate_target = 64 aura::Window* rotate_target =
71 workspace_manager_->FindRotateWindowForLocation(point_in_owner); 65 workspace_manager_->FindRotateWindowForLocation(point_in_owner);
72 if (rotate_target) 66 if (rotate_target)
73 workspace_manager_->RotateWindows(drag, rotate_target); 67 workspace_manager_->RotateWindows(drag, rotate_target);
74 } 68 }
75 69
76 void DefaultContainerLayoutManager::EndMove( 70 void DefaultContainerLayoutManager::EndMove(
77 aura::Window* drag, 71 aura::Window* drag,
78 aura::MouseEvent* evnet) { 72 aura::MouseEvent* evnet) {
79 // TODO(oshima): finish moving window between workspaces. 73 // TODO(oshima): finish moving window between workspaces.
80 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
81 drag_window_ = NULL; 74 drag_window_ = NULL;
82 75
83 Workspace* workspace = workspace_manager_->FindBy(drag); 76 Workspace* workspace = workspace_manager_->FindBy(drag);
84 workspace->Layout(NULL, NULL); 77 workspace->Layout(NULL, NULL);
85 workspace->Activate(); 78 workspace->Activate();
86 workspace_manager_->SetOverview(false); 79 workspace_manager_->SetOverview(false);
87 } 80 }
88 81
89 void DefaultContainerLayoutManager::EndResize( 82 void DefaultContainerLayoutManager::EndResize(
90 aura::Window* drag, 83 aura::Window* drag,
91 aura::MouseEvent* evnet) { 84 aura::MouseEvent* evnet) {
92 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
93 drag_window_ = NULL; 85 drag_window_ = NULL;
94 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); 86 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
95 if (workspace) 87 if (workspace)
96 workspace->Layout(NULL, NULL); 88 workspace->Layout(NULL, NULL);
97 workspace_manager_->SetOverview(false); 89 workspace_manager_->SetOverview(false);
98 } 90 }
99 91
100 //////////////////////////////////////////////////////////////////////////////// 92 ////////////////////////////////////////////////////////////////////////////////
101 // DefaultContainerLayoutManager, aura::LayoutManager implementation: 93 // DefaultContainerLayoutManager, aura::LayoutManager implementation:
102 94
103 void DefaultContainerLayoutManager::OnWindowResized() { 95 void DefaultContainerLayoutManager::OnWindowResized() {
104 // Workspace is updated via DesktopObserver::OnDesktopResized. 96 // Workspace is updated via DesktopObserver::OnDesktopResized.
105 } 97 }
106 98
107 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { 99 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
108 if (child->type() != aura::WINDOW_TYPE_NORMAL || child->transient_parent()) 100 if (child->type() != aura::WINDOW_TYPE_NORMAL || child->transient_parent())
109 return; 101 return;
110 102
111 if (!child->GetProperty(aura::kShowStateKey)) 103 if (!child->GetProperty(aura::kShowStateKey))
112 child->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); 104 child->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
113 105
114 child->AddObserver(show_state_controller_.get()); 106 child->AddObserver(show_state_controller_.get());
115 107
116 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
117
118 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); 108 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
119 if (workspace) { 109 if (workspace) {
120 aura::Window* active = aura::Desktop::GetInstance()->active_window(); 110 aura::Window* active = aura::Desktop::GetInstance()->active_window();
121 // Active window may not be in the default container layer. 111 // Active window may not be in the default container layer.
122 if (!workspace->Contains(active)) 112 if (!workspace->Contains(active))
123 active = NULL; 113 active = NULL;
124 if (workspace->AddWindowAfter(child, active)) 114 if (workspace->AddWindowAfter(child, active))
125 return; 115 return;
126 } 116 }
127 // Create new workspace if new |child| doesn't fit to current workspace. 117 // Create new workspace if new |child| doesn't fit to current workspace.
128 Workspace* new_workspace = workspace_manager_->CreateWorkspace(); 118 Workspace* new_workspace = workspace_manager_->CreateWorkspace();
129 new_workspace->AddWindowAfter(child, NULL); 119 new_workspace->AddWindowAfter(child, NULL);
130 new_workspace->Activate(); 120 new_workspace->Activate();
131 } 121 }
132 122
133 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) { 123 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
134 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
135 child->RemoveObserver(show_state_controller_.get()); 124 child->RemoveObserver(show_state_controller_.get());
136 ClearRestoreBounds(child); 125 ClearRestoreBounds(child);
137 126
138 Workspace* workspace = workspace_manager_->FindBy(child); 127 Workspace* workspace = workspace_manager_->FindBy(child);
139 if (!workspace) 128 if (!workspace)
140 return; 129 return;
141 workspace->RemoveWindow(child); 130 workspace->RemoveWindow(child);
142 if (workspace->is_empty()) 131 if (workspace->is_empty())
143 delete workspace; 132 delete workspace;
144 } 133 }
145 134
146 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( 135 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
147 aura::Window* child, 136 aura::Window* child,
148 bool visible) { 137 bool visible) {
149 NOTIMPLEMENTED(); 138 NOTIMPLEMENTED();
150 } 139 }
151 140
152 void DefaultContainerLayoutManager::SetChildBounds( 141 void DefaultContainerLayoutManager::SetChildBounds(
153 aura::Window* child, 142 aura::Window* child,
154 const gfx::Rect& requested_bounds) { 143 const gfx::Rect& requested_bounds) {
155 gfx::Rect adjusted_bounds = requested_bounds; 144 gfx::Rect adjusted_bounds = requested_bounds;
156 145
157 // First, calculate the adjusted bounds. 146 // First, calculate the adjusted bounds.
158 if (child->type() != aura::WINDOW_TYPE_NORMAL || 147 if (child->type() != aura::WINDOW_TYPE_NORMAL ||
159 ignore_calculate_bounds_ || 148 workspace_manager_->layout_in_progress() ||
160 child->transient_parent()) { 149 child->transient_parent()) {
161 // Use the requested bounds as is. 150 // Use the requested bounds as is.
162 } else if (drag_window_) { 151 } else if (drag_window_) {
163 // If a drag window is requesting bounds, make sure its attached to 152 // If a drag window is requesting bounds, make sure its attached to
164 // the workarea's top and fits within the total drag area. 153 // the workarea's top and fits within the total drag area.
165 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds(); 154 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds();
166 adjusted_bounds.set_y(drag_area.y()); 155 adjusted_bounds.set_y(drag_area.y());
167 adjusted_bounds = adjusted_bounds.AdjustToFit(drag_area); 156 adjusted_bounds = adjusted_bounds.AdjustToFit(drag_area);
168 } else { 157 } else {
169 Workspace* workspace = workspace_manager_->FindBy(child); 158 Workspace* workspace = workspace_manager_->FindBy(child);
170 gfx::Rect work_area = workspace->GetWorkAreaBounds(); 159 gfx::Rect work_area = workspace->GetWorkAreaBounds();
171 adjusted_bounds.set_origin( 160 adjusted_bounds.set_origin(
172 gfx::Point(child->GetTargetBounds().x(), work_area.y())); 161 gfx::Point(child->GetTargetBounds().x(), work_area.y()));
173 adjusted_bounds = adjusted_bounds.AdjustToFit(work_area); 162 adjusted_bounds = adjusted_bounds.AdjustToFit(work_area);
174 } 163 }
175 164
176 ui::WindowShowState show_state = static_cast<ui::WindowShowState>( 165 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
177 child->GetIntProperty(aura::kShowStateKey)); 166 child->GetIntProperty(aura::kShowStateKey));
178 167
179 // Second, check if the window is either maximized or in fullscreen mode. 168 // Second, check if the window is either maximized or in fullscreen mode.
180 if (show_state == ui::SHOW_STATE_MAXIMIZED || 169 if (show_state == ui::SHOW_STATE_MAXIMIZED ||
181 show_state == ui::SHOW_STATE_FULLSCREEN) { 170 show_state == ui::SHOW_STATE_FULLSCREEN) {
182 // If the request is not from workspace manager, 171 // If the request is not from workspace manager,
183 // remember the requested bounds. 172 // remember the requested bounds.
184 if (!ignore_calculate_bounds_) 173 if (!workspace_manager_->layout_in_progress())
185 SetRestoreBounds(child, adjusted_bounds); 174 SetRestoreBounds(child, adjusted_bounds);
186 175
187 Workspace* workspace = workspace_manager_->FindBy(child); 176 Workspace* workspace = workspace_manager_->FindBy(child);
188 if (show_state == ui::SHOW_STATE_MAXIMIZED) 177 if (show_state == ui::SHOW_STATE_MAXIMIZED)
189 adjusted_bounds = workspace->GetWorkAreaBounds(); 178 adjusted_bounds = workspace->GetWorkAreaBounds();
190 else 179 else
191 adjusted_bounds = workspace->bounds(); 180 adjusted_bounds = workspace->bounds();
192 // Don't 181 // Don't
193 if (child->GetTargetBounds() == adjusted_bounds) 182 if (child->GetTargetBounds() == adjusted_bounds)
194 return; 183 return;
195 } 184 }
196 SetChildBoundsDirect(child, adjusted_bounds); 185 SetChildBoundsDirect(child, adjusted_bounds);
197 } 186 }
198 187
199 } // namespace internal 188 } // namespace internal
200 } // namespace aura_shell 189 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/default_container_layout_manager.h ('k') | ui/aura_shell/default_container_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698