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

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

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily exlucde tests failing on win 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
« no previous file with comments | « ui/aura_shell/shell.h ('k') | ui/aura_shell/workspace/workspace.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) 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/shell.h" 5 #include "ui/aura_shell/shell.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/desktop.h" 8 #include "ui/aura/desktop.h"
9 #include "ui/aura/screen_aura.h" 9 #include "ui/aura/screen_aura.h"
10 #include "ui/aura/toplevel_window_container.h" 10 #include "ui/aura/toplevel_window_container.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/aura/window_types.h" 12 #include "ui/aura/window_types.h"
13 #include "ui/aura_shell/default_container_event_filter.h"
13 #include "ui/aura_shell/default_container_layout_manager.h" 14 #include "ui/aura_shell/default_container_layout_manager.h"
14 #include "ui/aura_shell/desktop_layout_manager.h" 15 #include "ui/aura_shell/desktop_layout_manager.h"
15 #include "ui/aura_shell/launcher/launcher.h" 16 #include "ui/aura_shell/launcher/launcher.h"
16 #include "ui/aura_shell/shell_delegate.h" 17 #include "ui/aura_shell/shell_delegate.h"
17 #include "ui/aura_shell/shell_factory.h" 18 #include "ui/aura_shell/shell_factory.h"
18 #include "ui/aura_shell/shell_window_ids.h" 19 #include "ui/aura_shell/shell_window_ids.h"
20 #include "ui/aura_shell/workspace/workspace_manager.h"
19 #include "ui/base/view_prop.h" 21 #include "ui/base/view_prop.h"
20 #include "ui/gfx/compositor/layer.h" 22 #include "ui/gfx/compositor/layer.h"
21 #include "views/widget/native_widget_aura.h" 23 #include "views/widget/native_widget_aura.h"
22 #include "views/widget/widget.h" 24 #include "views/widget/widget.h"
23 25
24 namespace aura_shell { 26 namespace aura_shell {
25 27
26 namespace { 28 namespace {
27 29
30 // The right/left margin of work area in the screen.
31 const int kWorkAreaHorizontalMargin = 15;
32
28 using views::Widget; 33 using views::Widget;
29 34
30 // Creates each of the special window containers that holds windows of various 35 // Creates each of the special window containers that holds windows of various
31 // types in the shell UI. They are added to |containers| from back to front in 36 // types in the shell UI. They are added to |containers| from back to front in
32 // the z-index. 37 // the z-index.
33 void CreateSpecialContainers(aura::Window::Windows* containers) { 38 void CreateSpecialContainers(aura::Window::Windows* containers) {
34 aura::Window* background_container = new aura::Window(NULL); 39 aura::Window* background_container = new aura::Window(NULL);
35 background_container->set_id( 40 background_container->set_id(
36 internal::kShellWindowId_DesktopBackgroundContainer); 41 internal::kShellWindowId_DesktopBackgroundContainer);
37 containers->push_back(background_container); 42 containers->push_back(background_container);
38 43
39 aura::Window* default_container = new aura::ToplevelWindowContainer; 44 aura::Window* default_container = new aura::ToplevelWindowContainer;
40 default_container->set_id(internal::kShellWindowId_DefaultContainer); 45 default_container->set_id(internal::kShellWindowId_DefaultContainer);
41 default_container->SetLayoutManager( 46 default_container->SetEventFilter(
42 new internal::DefaultContainerLayoutManager(default_container)); 47 new internal::DefaultContainerEventFilter(default_container));
43 containers->push_back(default_container); 48 containers->push_back(default_container);
44 49
45 aura::Window* always_on_top_container = new aura::ToplevelWindowContainer; 50 aura::Window* always_on_top_container = new aura::ToplevelWindowContainer;
46 always_on_top_container->set_id( 51 always_on_top_container->set_id(
47 internal::kShellWindowId_AlwaysOnTopContainer); 52 internal::kShellWindowId_AlwaysOnTopContainer);
48 containers->push_back(always_on_top_container); 53 containers->push_back(always_on_top_container);
49 54
50 aura::Window* launcher_container = new aura::Window(NULL); 55 aura::Window* launcher_container = new aura::Window(NULL);
51 launcher_container->set_id(internal::kShellWindowId_LauncherContainer); 56 launcher_container->set_id(internal::kShellWindowId_LauncherContainer);
52 containers->push_back(launcher_container); 57 containers->push_back(launcher_container);
53 58
54 aura::Window* lock_container = new aura::Window(NULL); 59 aura::Window* lock_container = new aura::Window(NULL);
55 lock_container->set_stops_event_propagation(true); 60 lock_container->set_stops_event_propagation(true);
56 lock_container->set_id(internal::kShellWindowId_LockScreenContainer); 61 lock_container->set_id(internal::kShellWindowId_LockScreenContainer);
57 containers->push_back(lock_container); 62 containers->push_back(lock_container);
58 63
59 aura::Window* status_container = new aura::Window(NULL); 64 aura::Window* status_container = new aura::Window(NULL);
60 status_container->set_id(internal::kShellWindowId_StatusContainer); 65 status_container->set_id(internal::kShellWindowId_StatusContainer);
61 containers->push_back(status_container); 66 containers->push_back(status_container);
62 67
63 aura::Window* menu_container = new aura::Window(NULL); 68 aura::Window* menu_container = new aura::Window(NULL);
64 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer); 69 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer);
65 containers->push_back(menu_container); 70 containers->push_back(menu_container);
66 } 71 }
67 72
68 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
69
70 void CalculateWindowBoundsAndScaleForTiling(
71 const gfx::Size& containing_size,
72 const aura::Window::Windows& windows,
73 float* x_scale,
74 float* y_scale,
75 std::vector<WindowAndBoundsPair>* bounds) {
76 *x_scale = 1.0f;
77 *y_scale = 1.0f;
78 int total_width = 0;
79 int max_height = 0;
80 int shown_window_count = 0;
81 for (aura::Window::Windows::const_iterator i = windows.begin();
82 i != windows.end(); ++i) {
83 if ((*i)->IsVisible()) {
84 total_width += (*i)->bounds().width();
85 max_height = std::max((*i)->bounds().height(), max_height);
86 shown_window_count++;
87 }
88 }
89
90 if (shown_window_count == 0)
91 return;
92
93 const int kPadding = 10;
94 total_width += (shown_window_count - 1) * kPadding;
95 if (total_width > containing_size.width()) {
96 *x_scale = static_cast<float>(containing_size.width()) /
97 static_cast<float>(total_width);
98 }
99 if (max_height > containing_size.height()) {
100 *y_scale = static_cast<float>(containing_size.height()) /
101 static_cast<float>(max_height);
102 }
103 *x_scale = *y_scale = std::min(*x_scale, *y_scale);
104
105 int x = std::max(0, static_cast<int>(
106 (containing_size.width() * - total_width * *x_scale) / 2));
107 for (aura::Window::Windows::const_iterator i = windows.begin();
108 i != windows.end();
109 ++i) {
110 if ((*i)->IsVisible()) {
111 const gfx::Rect& current_bounds((*i)->bounds());
112 int y = (containing_size.height() -
113 current_bounds.height() * *y_scale) / 2;
114 bounds->push_back(std::make_pair(*i,
115 gfx::Rect(x, y, current_bounds.width(), current_bounds.height())));
116 x += static_cast<int>(
117 static_cast<float>(current_bounds.width() + kPadding) * *x_scale);
118 }
119 }
120 }
121
122 } // namespace 73 } // namespace
123 74
124 // static 75 // static
125 Shell* Shell::instance_ = NULL; 76 Shell* Shell::instance_ = NULL;
126 77
127 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
128 // Shell, public: 79 // Shell, public:
129 80
130 Shell::Shell() 81 Shell::Shell()
131 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 82 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
(...skipping 29 matching lines...) Expand all
161 new internal::DesktopLayoutManager(desktop_window); 112 new internal::DesktopLayoutManager(desktop_window);
162 desktop_window->SetLayoutManager(desktop_layout); 113 desktop_window->SetLayoutManager(desktop_layout);
163 114
164 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); 115 desktop_layout->set_background_widget(internal::CreateDesktopBackground());
165 aura::ToplevelWindowContainer* toplevel_container = 116 aura::ToplevelWindowContainer* toplevel_container =
166 GetContainer(internal::kShellWindowId_DefaultContainer)-> 117 GetContainer(internal::kShellWindowId_DefaultContainer)->
167 AsToplevelWindowContainer(); 118 AsToplevelWindowContainer();
168 launcher_.reset(new Launcher(toplevel_container)); 119 launcher_.reset(new Launcher(toplevel_container));
169 desktop_layout->set_launcher_widget(launcher_->widget()); 120 desktop_layout->set_launcher_widget(launcher_->widget());
170 desktop_layout->set_status_area_widget(internal::CreateStatusArea()); 121 desktop_layout->set_status_area_widget(internal::CreateStatusArea());
122
171 desktop_window->screen()->set_work_area_insets( 123 desktop_window->screen()->set_work_area_insets(
172 gfx::Insets(0, 0, launcher_->widget()->GetWindowScreenBounds().height(), 124 gfx::Insets(
173 0)); 125 0, kWorkAreaHorizontalMargin,
126 launcher_->widget()->GetWindowScreenBounds().height(),
127 kWorkAreaHorizontalMargin));
128
129 // Workspace Manager
130 workspace_manager_.reset(new WorkspaceManager(toplevel_container));
131 toplevel_container->SetLayoutManager(
132 new internal::DefaultContainerLayoutManager(
133 toplevel_container, workspace_manager_.get()));
174 134
175 // Force a layout. 135 // Force a layout.
176 desktop_layout->OnWindowResized(); 136 desktop_layout->OnWindowResized();
177 } 137 }
178 138
179 void Shell::SetDelegate(ShellDelegate* delegate) { 139 void Shell::SetDelegate(ShellDelegate* delegate) {
180 delegate_.reset(delegate); 140 delegate_.reset(delegate);
181 } 141 }
182 142
183 aura::Window* Shell::GetContainer(int container_id) { 143 aura::Window* Shell::GetContainer(int container_id) {
184 return const_cast<aura::Window*>( 144 return const_cast<aura::Window*>(
185 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); 145 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id));
186 } 146 }
187 147
188 const aura::Window* Shell::GetContainer(int container_id) const { 148 const aura::Window* Shell::GetContainer(int container_id) const {
189 return aura::Desktop::GetInstance()->GetChildById(container_id); 149 return aura::Desktop::GetInstance()->GetChildById(container_id);
190 } 150 }
191 151
192 void Shell::TileWindows() { 152 void Shell::ToggleOverview() {
193 to_restore_.clear(); 153 workspace_manager_->SetOverview(!workspace_manager_->is_overview());
194 aura::Window* window_container =
195 aura::Desktop::GetInstance()->GetChildById(
196 internal::kShellWindowId_DefaultContainer);
197 const aura::Window::Windows& windows = window_container->children();
198 if (windows.empty())
199 return;
200 float x_scale = 1.0f;
201 float y_scale = 1.0f;
202 std::vector<WindowAndBoundsPair> bounds;
203 CalculateWindowBoundsAndScaleForTiling(window_container->bounds().size(),
204 windows, &x_scale, &y_scale, &bounds);
205 if (bounds.empty())
206 return;
207 ui::Transform transform;
208 transform.SetScale(x_scale, y_scale);
209 for (size_t i = 0; i < bounds.size(); ++i) {
210 to_restore_.push_back(
211 std::make_pair(bounds[i].first, bounds[i].first->bounds()));
212 bounds[i].first->layer()->SetAnimation(
213 aura::Window::CreateDefaultAnimation());
214 bounds[i].first->SetBounds(bounds[i].second);
215 bounds[i].first->layer()->SetTransform(transform);
216 bounds[i].first->layer()->SetOpacity(0.5f);
217 }
218
219 MessageLoop::current()->PostDelayedTask(
220 FROM_HERE,
221 base::Bind(&Shell::RestoreTiledWindows, method_factory_.GetWeakPtr()),
222 2000);
223 }
224
225 void Shell::RestoreTiledWindows() {
226 ui::Transform identity_transform;
227 for (size_t i = 0; i < to_restore_.size(); ++i) {
228 to_restore_[i].first->layer()->SetAnimation(
229 aura::Window::CreateDefaultAnimation());
230 to_restore_[i].first->SetBounds(to_restore_[i].second);
231 to_restore_[i].first->layer()->SetTransform(identity_transform);
232 to_restore_[i].first->layer()->SetOpacity(1.0f);
233 }
234 to_restore_.clear();
235 } 154 }
236 155
237 //////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////
238 // Shell, aura::DesktopDelegate implementation: 157 // Shell, aura::DesktopDelegate implementation:
239 158
240 void Shell::AddChildToDefaultParent(aura::Window* window) { 159 void Shell::AddChildToDefaultParent(aura::Window* window) {
241 aura::Window* parent = NULL; 160 aura::Window* parent = NULL;
242 intptr_t type = reinterpret_cast<intptr_t>( 161 intptr_t type = reinterpret_cast<intptr_t>(
243 ui::ViewProp::GetValue(window, views::NativeWidgetAura::kWindowTypeKey)); 162 ui::ViewProp::GetValue(window, views::NativeWidgetAura::kWindowTypeKey));
244 switch (static_cast<Widget::InitParams::Type>(type)) { 163 switch (static_cast<Widget::InitParams::Type>(type)) {
(...skipping 16 matching lines...) Expand all
261 } 180 }
262 181
263 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { 182 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const {
264 const aura::ToplevelWindowContainer* container = 183 const aura::ToplevelWindowContainer* container =
265 GetContainer(internal::kShellWindowId_DefaultContainer)-> 184 GetContainer(internal::kShellWindowId_DefaultContainer)->
266 AsToplevelWindowContainer(); 185 AsToplevelWindowContainer();
267 return container->GetTopmostWindowToActivate(ignore); 186 return container->GetTopmostWindowToActivate(ignore);
268 } 187 }
269 188
270 } // namespace aura_shell 189 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shell.h ('k') | ui/aura_shell/workspace/workspace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698