summaryrefslogtreecommitdiffstats
path: root/ash/shell.cc
blob: c2998ae200d631fb54b6321c76109cf8baa97185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/shell.h"

#include <algorithm>

#include "ash/app_list/app_list.h"
#include "ash/ash_switches.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/focus_cycler.h"
#include "ash/ime/input_method_event_filter.h"
#include "ash/launcher/launcher.h"
#include "ash/shell_delegate.h"
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
#include "ash/tooltips/tooltip_controller.h"
#include "ash/wm/activation_controller.h"
#include "ash/wm/base_layout_manager.h"
#include "ash/wm/compact_layout_manager.h"
#include "ash/wm/compact_status_area_layout_manager.h"
#include "ash/wm/dialog_frame_view.h"
#include "ash/wm/panel_window_event_filter.h"
#include "ash/wm/panel_layout_manager.h"
#include "ash/wm/partial_screenshot_event_filter.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/root_window_event_filter.h"
#include "ash/wm/root_window_layout_manager.h"
#include "ash/wm/shadow_controller.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/stacking_controller.h"
#include "ash/wm/status_area_layout_manager.h"
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/wm/toplevel_layout_manager.h"
#include "ash/wm/toplevel_window_event_filter.h"
#include "ash/wm/video_detector.h"
#include "ash/wm/visibility_controller.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_modality_controller.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
#include "ash/wm/workspace/workspace_event_filter.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace/workspace_manager.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget.h"

#if !defined(OS_MACOSX)
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_filter.h"
#include "ash/accelerators/nested_dispatcher_controller.h"
#endif

namespace ash {

namespace {

using aura::Window;
using views::Widget;

// Screen width above which we automatically start in overlapping window mode,
// in pixels. Should be at least 1366 pixels as we traditionally used a single
// window on Chrome OS ZGB devices with that width.
const int kOverlappingWindowModeWidthThreshold = 1366;

// Screen height above which we automatically start in overlapping window mode,
// in pixels. Should be at least 800 pixels as we traditionally used a single
// window on Chrome OS alex devices with that height.
const int kOverlappingWindowModeHeightThreshold = 800;

// Creates a new window for use as a container.
aura::Window* CreateContainer(int window_id, aura::Window* parent) {
  aura::Window* container = new aura::Window(NULL);
  container->set_id(window_id);
  container->Init(ui::Layer::LAYER_NOT_DRAWN);
  parent->AddChild(container);
  if (window_id != internal::kShellWindowId_UnparentedControlContainer)
    container->Show();
  return container;
}

// Creates each of the special window containers that holds windows of various
// types in the shell UI.
void CreateSpecialContainers(aura::Window* root_window) {
  // These containers are just used by PowerButtonController to animate groups
  // of containers simultaneously without messing up the current transformations
  // on those containers.  These are direct children of the root window; all of
  // the other containers are their children.
  aura::Window* non_lock_screen_containers = CreateContainer(
      internal::kShellWindowId_NonLockScreenContainersContainer, root_window);
  aura::Window* lock_screen_containers = CreateContainer(
      internal::kShellWindowId_LockScreenContainersContainer, root_window);
  aura::Window* lock_screen_related_containers = CreateContainer(
      internal::kShellWindowId_LockScreenRelatedContainersContainer,
      root_window);

  CreateContainer(internal::kShellWindowId_UnparentedControlContainer,
                  non_lock_screen_containers);

  CreateContainer(internal::kShellWindowId_DesktopBackgroundContainer,
                  non_lock_screen_containers);

  aura::Window* default_container = CreateContainer(
      internal::kShellWindowId_DefaultContainer, non_lock_screen_containers);
  default_container->SetEventFilter(
      new ToplevelWindowEventFilter(default_container));
  SetChildWindowVisibilityChangesAnimated(default_container);

  aura::Window* always_on_top_container = CreateContainer(
      internal::kShellWindowId_AlwaysOnTopContainer,
      non_lock_screen_containers);
  always_on_top_container->SetEventFilter(
      new ToplevelWindowEventFilter(always_on_top_container));
  SetChildWindowVisibilityChangesAnimated(always_on_top_container);

  aura::Window* panel_container = CreateContainer(
      internal::kShellWindowId_PanelContainer, non_lock_screen_containers);
  if (CommandLine::ForCurrentProcess()->
      HasSwitch(switches::kAuraPanelManager)) {
    internal::PanelLayoutManager* layout_manager =
        new internal::PanelLayoutManager(panel_container);
    panel_container->SetEventFilter(
        new internal::PanelWindowEventFilter(panel_container, layout_manager));
    panel_container->SetLayoutManager(layout_manager);
  }

  CreateContainer(internal::kShellWindowId_LauncherContainer,
                  non_lock_screen_containers);

  aura::Window* modal_container = CreateContainer(
      internal::kShellWindowId_SystemModalContainer,
      non_lock_screen_containers);
  modal_container->SetEventFilter(
      new ToplevelWindowEventFilter(modal_container));
  modal_container->SetLayoutManager(
      new internal::SystemModalContainerLayoutManager(modal_container));
  SetChildWindowVisibilityChangesAnimated(modal_container);

  // TODO(beng): Figure out if we can make this use
  // SystemModalContainerEventFilter instead of stops_event_propagation.
  aura::Window* lock_container = CreateContainer(
      internal::kShellWindowId_LockScreenContainer, lock_screen_containers);
  lock_container->SetLayoutManager(new internal::BaseLayoutManager);
  lock_container->set_stops_event_propagation(true);

  aura::Window* lock_modal_container = CreateContainer(
      internal::kShellWindowId_LockSystemModalContainer,
      lock_screen_containers);
  lock_modal_container->SetEventFilter(
      new ToplevelWindowEventFilter(lock_modal_container));
  lock_modal_container->SetLayoutManager(
      new internal::SystemModalContainerLayoutManager(lock_modal_container));
  SetChildWindowVisibilityChangesAnimated(lock_modal_container);

  CreateContainer(internal::kShellWindowId_StatusContainer,
                  lock_screen_related_containers);

  aura::Window* menu_container = CreateContainer(
      internal::kShellWindowId_MenuContainer, lock_screen_related_containers);
  SetChildWindowVisibilityChangesAnimated(menu_container);

  aura::Window* drag_drop_container = CreateContainer(
      internal::kShellWindowId_DragImageAndTooltipContainer,
      lock_screen_related_containers);
  SetChildWindowVisibilityChangesAnimated(drag_drop_container);

  CreateContainer(internal::kShellWindowId_SettingBubbleContainer,
                  lock_screen_related_containers);

  CreateContainer(internal::kShellWindowId_OverlayContainer,
                  lock_screen_related_containers);
}

// Maximizes all the windows in a |container|.
void MaximizeWindows(aura::Window* container) {
  const std::vector<aura::Window*>& windows = container->children();
  for (std::vector<aura::Window*>::const_iterator it = windows.begin();
       it != windows.end();
       ++it)
    window_util::MaximizeWindow(*it);
}

// Restores all maximized windows in a |container|.
void RestoreMaximizedWindows(aura::Window* container) {
  const std::vector<aura::Window*>& windows = container->children();
  for (std::vector<aura::Window*>::const_iterator it = windows.begin();
       it != windows.end();
       ++it) {
    if (window_util::IsWindowMaximized(*it))
      window_util::RestoreWindow(*it);
  }
}

}  // namespace

// static
Shell* Shell::instance_ = NULL;

////////////////////////////////////////////////////////////////////////////////
// Shell, public:

Shell::Shell(ShellDelegate* delegate)
    : root_filter_(new internal::RootWindowEventFilter),
#if !defined(OS_MACOSX)
      nested_dispatcher_controller_(new NestedDispatcherController),
      accelerator_controller_(new AcceleratorController),
#endif
      delegate_(delegate),
      shelf_(NULL),
      dynamic_window_mode_(false),
      window_mode_(MODE_OVERLAPPING),
      desktop_background_mode_(BACKGROUND_IMAGE),
      root_window_layout_(NULL),
      status_widget_(NULL) {
  // Pass ownership of the filter to the root window.
  GetRootWindow()->SetEventFilter(root_filter_);
}

Shell::~Shell() {
  RemoveRootWindowEventFilter(partial_screenshot_filter_.get());
  RemoveRootWindowEventFilter(input_method_filter_.get());
  RemoveRootWindowEventFilter(window_modality_controller_.get());
#if !defined(OS_MACOSX)
  RemoveRootWindowEventFilter(accelerator_filter_.get());
#endif

  // Close background widget now so that the focus manager of the
  // widget gets deleted in the final message loop run.
  root_window_layout_->SetBackgroundWidget(NULL);

  // TooltipController is deleted with the Shell so removing its references.
  RemoveRootWindowEventFilter(tooltip_controller_.get());
  aura::client::SetTooltipClient(NULL);

  // Make sure we delete WorkspaceController before launcher is
  // deleted as it has a reference to launcher model.
  workspace_controller_.reset();

  // Delete containers now so that child windows does not access
  // observers when they are destructed.
  aura::RootWindow* root_window = GetRootWindow();
  while (!root_window->children().empty()) {
    aura::Window* child = root_window->children()[0];
    delete child;
  }

  // These need a valid Shell instance to clean up properly, so explicitly
  // delete them before invalidating the instance.
  drag_drop_controller_.reset();
  window_cycle_controller_.reset();

  // Launcher widget has a InputMethodBridge that references to
  // input_method_filter_'s input_method_. So explicitly release launcher_
  // before input_method_filter_. And this needs to be after we delete all
  // containers in case there are still live browser windows which access
  // LauncherModel during close.
  launcher_.reset();

  DCHECK(instance_ == this);
  instance_ = NULL;
}

// static
Shell* Shell::CreateInstance(ShellDelegate* delegate) {
  CHECK(!instance_);
  instance_ = new Shell(delegate);
  instance_->Init();
  return instance_;
}

// static
Shell* Shell::GetInstance() {
  DCHECK(instance_);
  return instance_;
}

// static
void Shell::DeleteInstance() {
  delete instance_;
  instance_ = NULL;
}

// static
aura::RootWindow* Shell::GetRootWindow() {
  return aura::RootWindow::GetInstance();
}

void Shell::Init() {
  DCHECK(!GetRootWindowEventFilterCount());

  // PartialScreenshotEventFilter must be the first one to capture key
  // events when the taking partial screenshot UI is there.
  partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter);
  AddRootWindowEventFilter(partial_screenshot_filter_.get());

  // Then AcceleratorFilter and InputMethodEventFilter must be added (in this
  // order) since they have the second highest priority.
  DCHECK_EQ(1U, GetRootWindowEventFilterCount());
#if !defined(OS_MACOSX)
  accelerator_filter_.reset(new internal::AcceleratorFilter);
  AddRootWindowEventFilter(accelerator_filter_.get());
  DCHECK_EQ(2U, GetRootWindowEventFilterCount());
#endif
  input_method_filter_.reset(new internal::InputMethodEventFilter);
  AddRootWindowEventFilter(input_method_filter_.get());

  // Dynamic window mode affects window mode computation.
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  dynamic_window_mode_ = command_line->HasSwitch(
      switches::kAuraDynamicWindowMode);

  // Window mode must be set before computing containers or layout managers.
  gfx::Size monitor_size = gfx::Screen::GetPrimaryMonitorSize();
  window_mode_ = ComputeWindowMode(monitor_size, command_line);

  aura::RootWindow* root_window = GetRootWindow();
  root_window->SetCursor(aura::kCursorPointer);

  activation_controller_.reset(new internal::ActivationController);

  CreateSpecialContainers(root_window);

  stacking_controller_.reset(new internal::StackingController);

  root_window_layout_ = new internal::RootWindowLayoutManager(root_window);
  root_window->SetLayoutManager(root_window_layout_);

  if (delegate_.get())
    status_widget_ = delegate_->CreateStatusArea();
  if (!status_widget_)
    status_widget_ = internal::CreateStatusArea();

  aura::Window* default_container =
      GetContainer(internal::kShellWindowId_DefaultContainer);
  launcher_.reset(new Launcher(default_container));

  if (window_mode_ == MODE_COMPACT)
    SetupCompactWindowMode();
  else
    SetupNonCompactWindowMode();

  if (!command_line->HasSwitch(switches::kAuraNoShadows))
    shadow_controller_.reset(new internal::ShadowController());

  focus_cycler_.reset(new internal::FocusCycler());
  focus_cycler_->AddWidget(status_widget_);
  focus_cycler_->AddWidget(launcher_->widget());
  launcher_->SetFocusCycler(focus_cycler_.get());

  // Force a layout.
  root_window->layout_manager()->OnWindowResized();

  window_modality_controller_.reset(new internal::WindowModalityController);
  AddRootWindowEventFilter(window_modality_controller_.get());

  visibility_controller_.reset(new internal::VisibilityController);
  aura::client::SetVisibilityClient(visibility_controller_.get());

  tooltip_controller_.reset(new internal::TooltipController);
  AddRootWindowEventFilter(tooltip_controller_.get());
  aura::client::SetTooltipClient(tooltip_controller_.get());

  drag_drop_controller_.reset(new internal::DragDropController);
  power_button_controller_.reset(new PowerButtonController);
  video_detector_.reset(new VideoDetector);
  window_cycle_controller_.reset(new WindowCycleController);
}

Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size,
                                           CommandLine* command_line) const {
  // Some devices don't perform well with overlapping windows.
  if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode))
    return MODE_COMPACT;

  // If user set the flag, use their desired behavior.
  if (command_line->HasSwitch(switches::kAuraWindowMode)) {
    std::string mode =
        command_line->GetSwitchValueASCII(switches::kAuraWindowMode);
    if (mode == switches::kAuraWindowModeCompact)
      return MODE_COMPACT;
    if (mode == switches::kAuraWindowModeManaged)
      return MODE_MANAGED;
    if (mode == switches::kAuraWindowModeOverlapping)
      return MODE_OVERLAPPING;
  }

  // If we're trying to dynamically choose window mode based on screen
  // resolution, use compact mode for narrow/short screens.
  // TODO(jamescook): If we go with a simple variant of overlapping mode for
  // small screens we should remove this and the dynamic mode switching code
  // in SetupCompactWindowMode and SetupNonCompactWindowMode.
  if (dynamic_window_mode_ &&
      monitor_size.width() <= kOverlappingWindowModeWidthThreshold &&
      monitor_size.height() <= kOverlappingWindowModeHeightThreshold)
    return Shell::MODE_COMPACT;

  // Overlapping is the default.
  return Shell::MODE_OVERLAPPING;
}

aura::Window* Shell::GetContainer(int container_id) {
  return const_cast<aura::Window*>(
      const_cast<const Shell*>(this)->GetContainer(container_id));
}

const aura::Window* Shell::GetContainer(int container_id) const {
  return GetRootWindow()->GetChildById(container_id);
}

void Shell::AddRootWindowEventFilter(aura::EventFilter* filter) {
  static_cast<internal::RootWindowEventFilter*>(
      GetRootWindow()->event_filter())->AddFilter(filter);
}

void Shell::RemoveRootWindowEventFilter(aura::EventFilter* filter) {
  static_cast<internal::RootWindowEventFilter*>(
      GetRootWindow()->event_filter())->RemoveFilter(filter);
}

size_t Shell::GetRootWindowEventFilterCount() const {
  return static_cast<internal::RootWindowEventFilter*>(
      GetRootWindow()->event_filter())->GetFilterCount();
}

void Shell::ShowBackgroundMenu(views::Widget* widget,
                               const gfx::Point& location) {
  if (workspace_controller_.get())
    workspace_controller_->ShowMenu(widget, location);
}

void Shell::ToggleAppList() {
  if (!app_list_.get())
    app_list_.reset(new internal::AppList);
  app_list_->SetVisible(!app_list_->IsVisible());
}

void Shell::ChangeWindowMode(WindowMode mode) {
  if (mode == window_mode_)
    return;
  // Window mode must be set before we resize/layout the windows.
  window_mode_ = mode;
  if (window_mode_ == MODE_COMPACT)
    SetupCompactWindowMode();
  else
    SetupNonCompactWindowMode();
}

void Shell::SetWindowModeForMonitorSize(const gfx::Size& monitor_size) {
  // If we're running on a device, a resolution change means the user plugged in
  // or unplugged an external monitor. Change window mode to be appropriate for
  // the new screen resolution.
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  WindowMode new_mode = ComputeWindowMode(monitor_size, command_line);
  ChangeWindowMode(new_mode);
}

void Shell::SetDesktopBackgroundMode(BackgroundMode mode) {
  if (mode == BACKGROUND_SOLID_COLOR) {
    // Set a solid black background.
    // TODO(derat): Remove this in favor of having the compositor only clear the
    // viewport when there are regions not covered by a layer:
    // http://crbug.com/113445
    ui::Layer* background_layer = new ui::Layer(ui::Layer::LAYER_SOLID_COLOR);
    background_layer->SetColor(SK_ColorBLACK);
    GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->
        layer()->Add(background_layer);
    root_window_layout_->SetBackgroundLayer(background_layer);
    root_window_layout_->SetBackgroundWidget(NULL);
  } else {
    // Create the desktop background image.
    root_window_layout_->SetBackgroundLayer(NULL);
    root_window_layout_->SetBackgroundWidget(
        internal::CreateDesktopBackground());
  }
  desktop_background_mode_ = mode;
}

bool Shell::IsScreenLocked() const {
  const aura::Window* lock_screen_container = GetContainer(
      internal::kShellWindowId_LockScreenContainer);
  return lock_screen_container->StopsEventPropagation();
}

bool Shell::IsModalWindowOpen() const {
  const aura::Window* modal_container = GetContainer(
      internal::kShellWindowId_SystemModalContainer);
  return !modal_container->children().empty();
}

void Shell::SetCompactStatusAreaOffset(gfx::Size& offset) {
  compact_status_area_offset_ = offset;

  // Trigger a relayout.
  if (IsWindowModeCompact()) {
    aura::LayoutManager* layout_manager = GetContainer(
        internal::kShellWindowId_StatusContainer)->layout_manager();
    if (layout_manager)
      layout_manager->OnWindowResized();
  }
}

views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
    views::Widget* widget) {
  if (CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kAuraGoogleDialogFrames)) {
    return new internal::DialogFrameView;
  }
  return NULL;
}

void Shell::RotateFocus(Direction direction) {
  focus_cycler_->RotateFocus(
      direction == FORWARD ? internal::FocusCycler::FORWARD :
                             internal::FocusCycler::BACKWARD);
}

////////////////////////////////////////////////////////////////////////////////
// Shell, private:

// Compact mode has a simplified layout manager and doesn't use the shelf,
// desktop background, etc.  The launcher still exists so we can use its
// data model and list of open windows, but we hide the UI to save space.
void Shell::SetupCompactWindowMode() {
  DCHECK(root_window_layout_);
  DCHECK(status_widget_);

  shelf_ = NULL;

  // Clean out the old layout managers before we start.
  ResetLayoutManager(internal::kShellWindowId_DefaultContainer);
  ResetLayoutManager(internal::kShellWindowId_LauncherContainer);
  ResetLayoutManager(internal::kShellWindowId_StatusContainer);

  // Don't use an event filter for the default container, as we don't support
  // window dragging, double-click to maximize, etc.
  aura::Window* default_container =
      GetContainer(internal::kShellWindowId_DefaultContainer);
  default_container->SetEventFilter(NULL);

  // Set up our new layout managers.
  internal::CompactLayoutManager* compact_layout_manager =
      new internal::CompactLayoutManager();
  compact_layout_manager->set_status_area_widget(status_widget_);
  internal::CompactStatusAreaLayoutManager* status_area_layout_manager =
      new internal::CompactStatusAreaLayoutManager(status_widget_);
  GetContainer(internal::kShellWindowId_StatusContainer)->
      SetLayoutManager(status_area_layout_manager);
  default_container->SetLayoutManager(compact_layout_manager);

  // Keep the launcher for its data model, but hide it.  Do this before
  // maximizing the windows so the work area is the right size.
  launcher_->widget()->Hide();

  // Maximize all the windows, using the new layout manager.
  MaximizeWindows(default_container);

  // Set a solid black background.
  SetDesktopBackgroundMode(BACKGROUND_SOLID_COLOR);
}

void Shell::SetupNonCompactWindowMode() {
  DCHECK(root_window_layout_);
  DCHECK(status_widget_);

  // Clean out the old layout managers before we start.
  ResetLayoutManager(internal::kShellWindowId_DefaultContainer);
  ResetLayoutManager(internal::kShellWindowId_LauncherContainer);
  ResetLayoutManager(internal::kShellWindowId_StatusContainer);

  internal::ShelfLayoutManager* shelf_layout_manager =
      new internal::ShelfLayoutManager(launcher_->widget(), status_widget_);
  GetContainer(internal::kShellWindowId_LauncherContainer)->
      SetLayoutManager(shelf_layout_manager);
  shelf_ = shelf_layout_manager;

  internal::StatusAreaLayoutManager* status_area_layout_manager =
      new internal::StatusAreaLayoutManager(shelf_layout_manager);
  GetContainer(internal::kShellWindowId_StatusContainer)->
      SetLayoutManager(status_area_layout_manager);

  aura::Window* default_container =
      GetContainer(internal::kShellWindowId_DefaultContainer);
  if (window_mode_ == MODE_MANAGED) {
    // Workspace manager has its own layout managers.
    workspace_controller_.reset(
        new internal::WorkspaceController(default_container));
    workspace_controller_->workspace_manager()->set_shelf(shelf_layout_manager);
  } else {
    // Default layout manager.
    internal::ToplevelLayoutManager* toplevel_layout_manager =
        new internal::ToplevelLayoutManager();
    toplevel_layout_manager->set_shelf(shelf_layout_manager);
    default_container->SetLayoutManager(toplevel_layout_manager);
    default_container->SetEventFilter(
        new ToplevelWindowEventFilter(default_container));
  }
  // Ensure launcher is visible.
  launcher_->widget()->Show();

  // Restore all maximized windows.  Don't change full screen windows, as we
  // don't want to disrupt a user trying to plug in an external monitor to
  // give a presentation.
  RestoreMaximizedWindows(default_container);

  // Create the desktop background image.
  SetDesktopBackgroundMode(BACKGROUND_IMAGE);
}

void Shell::ResetLayoutManager(int container_id) {
  GetContainer(container_id)->SetLayoutManager(NULL);
}

}  // namespace ash