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

Side by Side Diff: ash/shell.cc

Issue 9316005: Aura: Rework window mode flags to compact/overlapping/managed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with review feedback Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ash/shell.h ('k') | ash/shell_unittest.cc » ('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) 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/shell.h" 5 #include "ash/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/accelerators/accelerator_controller.h" 9 #include "ash/accelerators/accelerator_controller.h"
10 #include "ash/accelerators/accelerator_filter.h" 10 #include "ash/accelerators/accelerator_filter.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // static 168 // static
169 Shell* Shell::instance_ = NULL; 169 Shell* Shell::instance_ = NULL;
170 170
171 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
172 // Shell, public: 172 // Shell, public:
173 173
174 Shell::Shell(ShellDelegate* delegate) 174 Shell::Shell(ShellDelegate* delegate)
175 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 175 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
176 accelerator_controller_(new AcceleratorController), 176 accelerator_controller_(new AcceleratorController),
177 delegate_(delegate), 177 delegate_(delegate),
178 window_mode_(NORMAL_MODE), 178 window_mode_(MODE_OVERLAPPING),
179 root_window_layout_(NULL), 179 root_window_layout_(NULL),
180 status_widget_(NULL) { 180 status_widget_(NULL) {
181 aura::RootWindow::GetInstance()->SetEventFilter( 181 aura::RootWindow::GetInstance()->SetEventFilter(
182 new internal::RootWindowEventFilter); 182 new internal::RootWindowEventFilter);
183 } 183 }
184 184
185 Shell::~Shell() { 185 Shell::~Shell() {
186 RemoveRootWindowEventFilter(input_method_filter_.get()); 186 RemoveRootWindowEventFilter(input_method_filter_.get());
187 RemoveRootWindowEventFilter(window_modality_controller_.get()); 187 RemoveRootWindowEventFilter(window_modality_controller_.get());
188 RemoveRootWindowEventFilter(accelerator_filter_.get()); 188 RemoveRootWindowEventFilter(accelerator_filter_.get());
189 189
190 // TooltipController needs a valid shell instance. We delete it before 190 // TooltipController needs a valid shell instance. We delete it before
191 // deleting the shell |instance_|. 191 // deleting the shell |instance_|.
192 RemoveRootWindowEventFilter(tooltip_controller_.get()); 192 RemoveRootWindowEventFilter(tooltip_controller_.get());
193 aura::client::SetTooltipClient(NULL); 193 aura::client::SetTooltipClient(NULL);
194 194
195 // The LayoutManagers for the default and status containers talk to 195 // The LayoutManagers for the default and status containers talk to
196 // ShelfLayoutManager (LayoutManager installed on the launcher container). 196 // ShelfLayoutManager (LayoutManager installed on the launcher container).
197 // ShelfLayoutManager has a reference to the launcher widget. To avoid any of 197 // ShelfLayoutManager has a reference to the launcher widget. To avoid any of
198 // these trying to reference launcher after it's deleted we delete them all, 198 // these trying to reference launcher after it's deleted we delete them all,
199 // then the launcher. 199 // then the launcher.
200 if (!CommandLine::ForCurrentProcess()-> 200 if (window_mode_ != MODE_MANAGED)
201 HasSwitch(switches::kAuraWorkspaceManager)) {
202 ResetLayoutManager(internal::kShellWindowId_DefaultContainer); 201 ResetLayoutManager(internal::kShellWindowId_DefaultContainer);
203 }
204 ResetLayoutManager(internal::kShellWindowId_StatusContainer); 202 ResetLayoutManager(internal::kShellWindowId_StatusContainer);
205 ResetLayoutManager(internal::kShellWindowId_LauncherContainer); 203 ResetLayoutManager(internal::kShellWindowId_LauncherContainer);
206 // Make sure we delete WorkspaceController before launcher is 204 // Make sure we delete WorkspaceController before launcher is
207 // deleted as it has a reference to launcher model. 205 // deleted as it has a reference to launcher model.
208 workspace_controller_.reset(); 206 workspace_controller_.reset();
209 launcher_.reset(); 207 launcher_.reset();
210 208
211 // Delete containers now so that child windows does not access 209 // Delete containers now so that child windows does not access
212 // observers when they are destructed. This has to be after launcher 210 // observers when they are destructed. This has to be after launcher
213 // is destructed because launcher closes the widget in its destructor. 211 // is destructed because launcher closes the widget in its destructor.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 282
285 if (delegate_.get()) 283 if (delegate_.get())
286 status_widget_ = delegate_->CreateStatusArea(); 284 status_widget_ = delegate_->CreateStatusArea();
287 if (!status_widget_) 285 if (!status_widget_)
288 status_widget_ = internal::CreateStatusArea(); 286 status_widget_ = internal::CreateStatusArea();
289 287
290 aura::Window* default_container = 288 aura::Window* default_container =
291 GetContainer(internal::kShellWindowId_DefaultContainer); 289 GetContainer(internal::kShellWindowId_DefaultContainer);
292 launcher_.reset(new Launcher(default_container)); 290 launcher_.reset(new Launcher(default_container));
293 291
294 if (IsWindowModeCompact()) 292 if (window_mode_ == MODE_COMPACT)
295 SetupCompactWindowMode(); 293 SetupCompactWindowMode();
296 else 294 else
297 SetupNormalWindowMode(); 295 SetupNonCompactWindowMode();
298 296
299 if (!command_line->HasSwitch(switches::kAuraNoShadows)) 297 if (!command_line->HasSwitch(switches::kAuraNoShadows))
300 shadow_controller_.reset(new internal::ShadowController()); 298 shadow_controller_.reset(new internal::ShadowController());
301 299
302 // Force a layout. 300 // Force a layout.
303 root_window->layout_manager()->OnWindowResized(); 301 root_window->layout_manager()->OnWindowResized();
304 302
305 window_modality_controller_.reset(new internal::WindowModalityController); 303 window_modality_controller_.reset(new internal::WindowModalityController);
306 AddRootWindowEventFilter(window_modality_controller_.get()); 304 AddRootWindowEventFilter(window_modality_controller_.get());
307 305
308 visibility_controller_.reset(new internal::VisibilityController); 306 visibility_controller_.reset(new internal::VisibilityController);
309 aura::client::SetVisibilityClient(visibility_controller_.get()); 307 aura::client::SetVisibilityClient(visibility_controller_.get());
310 308
311 accelerator_filter_.reset(new internal::AcceleratorFilter); 309 accelerator_filter_.reset(new internal::AcceleratorFilter);
312 AddRootWindowEventFilter(accelerator_filter_.get()); 310 AddRootWindowEventFilter(accelerator_filter_.get());
313 311
314 tooltip_controller_.reset(new internal::TooltipController); 312 tooltip_controller_.reset(new internal::TooltipController);
315 AddRootWindowEventFilter(tooltip_controller_.get()); 313 AddRootWindowEventFilter(tooltip_controller_.get());
316 aura::client::SetTooltipClient(tooltip_controller_.get()); 314 aura::client::SetTooltipClient(tooltip_controller_.get());
317 315
318 drag_drop_controller_.reset(new internal::DragDropController); 316 drag_drop_controller_.reset(new internal::DragDropController);
319 power_button_controller_.reset(new PowerButtonController); 317 power_button_controller_.reset(new PowerButtonController);
320 video_detector_.reset(new VideoDetector); 318 video_detector_.reset(new VideoDetector);
321 window_cycle_controller_.reset(new WindowCycleController); 319 window_cycle_controller_.reset(new WindowCycleController);
322 } 320 }
323 321
324 Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, 322 Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size,
325 CommandLine* command_line) const { 323 CommandLine* command_line) const {
326 if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode)) 324 if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode))
327 return COMPACT_MODE; 325 return MODE_COMPACT;
328 326
329 // If user set the flag, use their desired behavior. 327 // If user set the flag, use their desired behavior.
330 if (command_line->HasSwitch(switches::kAuraWindowMode)) { 328 if (command_line->HasSwitch(switches::kAuraWindowMode)) {
331 std::string mode = 329 std::string mode =
332 command_line->GetSwitchValueASCII(switches::kAuraWindowMode); 330 command_line->GetSwitchValueASCII(switches::kAuraWindowMode);
333 if (mode == switches::kAuraWindowModeNormal)
334 return NORMAL_MODE;
335 if (mode == switches::kAuraWindowModeCompact) 331 if (mode == switches::kAuraWindowModeCompact)
336 return COMPACT_MODE; 332 return MODE_COMPACT;
333 if (mode == switches::kAuraWindowModeManaged)
334 return MODE_MANAGED;
335 if (mode == switches::kAuraWindowModeOverlapping)
336 return MODE_OVERLAPPING;
337 } 337 }
338 338
339 // Developers often run the Aura shell in small windows on their desktop. 339 // Developers often run the Aura shell in small windows on their desktop.
340 // Prefer normal mode for them. 340 // Prefer overlapping mode for them.
341 if (!aura::RootWindow::use_fullscreen_host_window()) 341 if (!aura::RootWindow::use_fullscreen_host_window())
342 return NORMAL_MODE; 342 return MODE_OVERLAPPING;
343 343
344 // If the screen is narrow we prefer a single compact window display. 344 // If the screen is narrow we prefer a single compact window display.
345 // We explicitly don't care about height, since users don't generally stack 345 // We explicitly don't care about height, since users don't generally stack
346 // browser windows vertically. 346 // browser windows vertically.
347 if (monitor_size.width() <= kCompactWindowModeWidthThreshold) 347 if (monitor_size.width() <= kCompactWindowModeWidthThreshold)
348 return COMPACT_MODE; 348 return MODE_COMPACT;
349 349
350 return NORMAL_MODE; 350 return MODE_OVERLAPPING;
351 } 351 }
352 352
353 aura::Window* Shell::GetContainer(int container_id) { 353 aura::Window* Shell::GetContainer(int container_id) {
354 return const_cast<aura::Window*>( 354 return const_cast<aura::Window*>(
355 const_cast<const Shell*>(this)->GetContainer(container_id)); 355 const_cast<const Shell*>(this)->GetContainer(container_id));
356 } 356 }
357 357
358 const aura::Window* Shell::GetContainer(int container_id) const { 358 const aura::Window* Shell::GetContainer(int container_id) const {
359 return aura::RootWindow::GetInstance()->GetChildById(container_id); 359 return aura::RootWindow::GetInstance()->GetChildById(container_id);
360 } 360 }
(...skipping 23 matching lines...) Expand all
384 if (!app_list_.get()) 384 if (!app_list_.get())
385 app_list_.reset(new internal::AppList); 385 app_list_.reset(new internal::AppList);
386 app_list_->SetVisible(!app_list_->IsVisible()); 386 app_list_->SetVisible(!app_list_->IsVisible());
387 } 387 }
388 388
389 void Shell::ChangeWindowMode(WindowMode mode) { 389 void Shell::ChangeWindowMode(WindowMode mode) {
390 if (mode == window_mode_) 390 if (mode == window_mode_)
391 return; 391 return;
392 // Window mode must be set before we resize/layout the windows. 392 // Window mode must be set before we resize/layout the windows.
393 window_mode_ = mode; 393 window_mode_ = mode;
394 if (window_mode_ == COMPACT_MODE) 394 if (window_mode_ == MODE_COMPACT)
395 SetupCompactWindowMode(); 395 SetupCompactWindowMode();
396 else 396 else
397 SetupNormalWindowMode(); 397 SetupNonCompactWindowMode();
398 // Force a layout. 398 // Force a layout.
399 aura::RootWindow::GetInstance()->layout_manager()->OnWindowResized(); 399 aura::RootWindow::GetInstance()->layout_manager()->OnWindowResized();
400 } 400 }
401 401
402 bool Shell::IsScreenLocked() const { 402 bool Shell::IsScreenLocked() const {
403 const aura::Window* lock_screen_container = GetContainer( 403 const aura::Window* lock_screen_container = GetContainer(
404 internal::kShellWindowId_LockScreenContainer); 404 internal::kShellWindowId_LockScreenContainer);
405 return lock_screen_container->StopsEventPropagation(); 405 return lock_screen_container->StopsEventPropagation();
406 } 406 }
407 407
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // maximizing the windows so the work area is the right size. 456 // maximizing the windows so the work area is the right size.
457 launcher_->widget()->Hide(); 457 launcher_->widget()->Hide();
458 458
459 // Maximize all the windows, using the new layout manager. 459 // Maximize all the windows, using the new layout manager.
460 MaximizeWindows(default_container); 460 MaximizeWindows(default_container);
461 461
462 // Eliminate the background widget. 462 // Eliminate the background widget.
463 root_window_layout_->SetBackgroundWidget(NULL); 463 root_window_layout_->SetBackgroundWidget(NULL);
464 } 464 }
465 465
466 void Shell::SetupNormalWindowMode() { 466 void Shell::SetupNonCompactWindowMode() {
467 DCHECK(root_window_layout_); 467 DCHECK(root_window_layout_);
468 DCHECK(status_widget_); 468 DCHECK(status_widget_);
469 469
470 // Clean out the old layout managers before we start. 470 // Clean out the old layout managers before we start.
471 ResetLayoutManager(internal::kShellWindowId_DefaultContainer); 471 ResetLayoutManager(internal::kShellWindowId_DefaultContainer);
472 ResetLayoutManager(internal::kShellWindowId_LauncherContainer); 472 ResetLayoutManager(internal::kShellWindowId_LauncherContainer);
473 ResetLayoutManager(internal::kShellWindowId_StatusContainer); 473 ResetLayoutManager(internal::kShellWindowId_StatusContainer);
474 474
475 internal::ShelfLayoutManager* shelf_layout_manager = 475 internal::ShelfLayoutManager* shelf_layout_manager =
476 new internal::ShelfLayoutManager(launcher_->widget(), status_widget_); 476 new internal::ShelfLayoutManager(launcher_->widget(), status_widget_);
477 GetContainer(internal::kShellWindowId_LauncherContainer)-> 477 GetContainer(internal::kShellWindowId_LauncherContainer)->
478 SetLayoutManager(shelf_layout_manager); 478 SetLayoutManager(shelf_layout_manager);
479 479
480 internal::StatusAreaLayoutManager* status_area_layout_manager = 480 internal::StatusAreaLayoutManager* status_area_layout_manager =
481 new internal::StatusAreaLayoutManager(shelf_layout_manager); 481 new internal::StatusAreaLayoutManager(shelf_layout_manager);
482 GetContainer(internal::kShellWindowId_StatusContainer)-> 482 GetContainer(internal::kShellWindowId_StatusContainer)->
483 SetLayoutManager(status_area_layout_manager); 483 SetLayoutManager(status_area_layout_manager);
484 484
485 aura::Window* default_container = 485 aura::Window* default_container =
486 GetContainer(internal::kShellWindowId_DefaultContainer); 486 GetContainer(internal::kShellWindowId_DefaultContainer);
487 if (CommandLine::ForCurrentProcess()-> 487 if (window_mode_ == MODE_MANAGED) {
488 HasSwitch(switches::kAuraWorkspaceManager)) {
489 // Workspace manager has its own layout managers. 488 // Workspace manager has its own layout managers.
490 workspace_controller_.reset( 489 workspace_controller_.reset(
491 new internal::WorkspaceController(default_container)); 490 new internal::WorkspaceController(default_container));
492 } else { 491 } else {
493 // Default layout manager. 492 // Default layout manager.
494 internal::ToplevelLayoutManager* toplevel_layout_manager = 493 internal::ToplevelLayoutManager* toplevel_layout_manager =
495 new internal::ToplevelLayoutManager(); 494 new internal::ToplevelLayoutManager();
496 toplevel_layout_manager->set_shelf(shelf_layout_manager); 495 toplevel_layout_manager->set_shelf(shelf_layout_manager);
497 default_container->SetLayoutManager(toplevel_layout_manager); 496 default_container->SetLayoutManager(toplevel_layout_manager);
498 default_container->SetEventFilter( 497 default_container->SetEventFilter(
499 new ToplevelWindowEventFilter(default_container)); 498 new ToplevelWindowEventFilter(default_container));
500 } 499 }
501 // Ensure launcher is visible. 500 // Ensure launcher is visible.
502 launcher_->widget()->Show(); 501 launcher_->widget()->Show();
503 502
504 // Restore all maximized windows. Don't change full screen windows, as we 503 // Restore all maximized windows. Don't change full screen windows, as we
505 // don't want to disrupt a user trying to plug in an external monitor to 504 // don't want to disrupt a user trying to plug in an external monitor to
506 // give a presentation. 505 // give a presentation.
507 RestoreMaximizedWindows(default_container); 506 RestoreMaximizedWindows(default_container);
508 507
509 // Create the desktop background image. 508 // Create the desktop background image.
510 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground()); 509 root_window_layout_->SetBackgroundWidget(internal::CreateDesktopBackground());
511 } 510 }
512 511
513 void Shell::ResetLayoutManager(int container_id) { 512 void Shell::ResetLayoutManager(int container_id) {
514 GetContainer(container_id)->SetLayoutManager(NULL); 513 GetContainer(container_id)->SetLayoutManager(NULL);
515 } 514 }
516 515
517 } // namespace ash 516 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell.h ('k') | ash/shell_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698