15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ash/accelerators/accelerator_controller.h"
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/accelerators/accelerator_delegate.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/accelerators/focus_manager_factory.h"
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/accelerators/nested_accelerator_delegate.h"
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ash/accelerometer/accelerometer_controller.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_switches.h"
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/autoclick/autoclick_controller.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/desktop_background/desktop_background_controller.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/desktop_background/desktop_background_view.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/desktop_background/user_wallpaper_delegate.h"
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/display/cursor_window_controller.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/display_controller.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/event_transformation_handler.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/mouse_cursor_event_filter.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/screen_position_controller.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/drag_drop/drag_drop_controller.h"
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/first_run/first_run_helper_impl.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/focus_cycler.h"
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/frame/custom_frame_view_ash.h"
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/gpu_support.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/high_contrast/high_contrast_controller.h"
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/host/ash_window_tree_host_init_params.h"
334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/keyboard_uma_event_filter.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/magnifier/magnification_controller.h"
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/magnifier/partial_magnification_controller.h"
360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ash/media_delegate.h"
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/new_window_delegate.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/root_window_controller.h"
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h"
4068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/shelf/app_list_shelf_item_delegate.h"
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_delegate.h"
42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_item_delegate.h"
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_item_delegate_manager.h"
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h"
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h"
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_window_watcher.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_delegate.h"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_factory.h"
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/shell_init_params.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_window_ids.h"
52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/system/locale/locale_notification_controller.h"
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/status_area_widget.h"
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ash/virtual_keyboard_controller.h"
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/app_list_controller.h"
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/ash_focus_rules.h"
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/ash_native_cursor_manager.h"
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/coordinate_conversion.h"
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/event_client_impl.h"
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/lock_state_controller.h"
63c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ash/wm/maximize_mode/maximize_mode_controller.h"
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/mru_window_tracker.h"
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/overlay_event_filter.h"
673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/wm/overview/window_selector_controller.h"
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/power_button_controller.h"
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/resize_shadow_controller.h"
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/root_window_layout_manager.h"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/screen_dimmer.h"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/system_gesture_event_filter.h"
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/system_modal_container_event_filter.h"
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/system_modal_container_layout_manager.h"
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/wm/toplevel_window_event_handler.h"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/video_detector.h"
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/window_animations.h"
78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/wm/window_cycle_controller.h"
794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/wm/window_positioner.h"
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_properties.h"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_util.h"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/workspace_controller.h"
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
8458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/debug/trace_event.h"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h"
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/layout_manager.h"
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/ui_base_switches.h"
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h"
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animator.h"
93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/events/event_target_iterator.h"
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image_skia.h"
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/size.h"
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/keyboard/keyboard.h"
994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/keyboard/keyboard_controller.h"
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/keyboard/keyboard_switches.h"
101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/keyboard/keyboard_util.h"
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center.h"
1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/corewm/tooltip_aura.h"
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/corewm/tooltip_controller.h"
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/focus/focus_manager_factory.h"
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_aura.h"
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/wm/core/accelerator_filter.h"
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/compound_event_filter.h"
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/focus_controller.h"
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/input_method_event_filter.h"
112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/wm/core/nested_accelerator_controller.h"
113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/shadow_controller.h"
114c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/wm/core/user_activity_detector.h"
115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/visibility_controller.h"
116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_modality_controller.h"
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_CHROMEOS)
119eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(USE_X11)
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accelerators/magnifier_key_scroller.h"
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accelerators/spoken_feedback_toggler.h"
122cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/touch/touch_transformer_controller.h"
123a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/x/x11_types.h"
124effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif  // defined(USE_X11)
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/ash_constants.h"
1263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/display/display_change_observer_chromeos.h"
1275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/display/display_configurator_animation.h"
1283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/display/display_error_observer_chromeos.h"
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/display/projecting_observer_chromeos.h"
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/display/resolution_notification_controller.h"
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/sticky_keys/sticky_keys_controller.h"
132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h"
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/system/chromeos/power/power_event_observer.h"
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/system/chromeos/power/power_status.h"
1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/system/chromeos/power/video_activity_notifier.h"
137effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ash/system/chromeos/session/last_window_closed_logout_reminder.h"
138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/logout_confirmation_controller.h"
139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/bind_helpers.h"
140effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/sys_info.h"
1410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "ui/chromeos/user_activity_power_manager_notifier.h"
142c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/display/chromeos/display_configurator.h"
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_CHROMEOS)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using aura::Window;
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using views::Widget;
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A Corewm VisibilityController subclass that calls the Ash animation routine
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// so we can pick up our extended animations. See ash/wm/window_animations.h.
154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class AshVisibilityController : public ::wm::VisibilityController {
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AshVisibilityController() {}
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~AshVisibilityController() {}
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Overridden from ::wm::VisibilityController:
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool CallAnimateOnChildWindowVisibilityChanged(
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      aura::Window* window,
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bool visible) OVERRIDE {
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return AnimateOnChildWindowVisibilityChanged(window, visible);
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
170cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams(
171cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    const ShellInitParams& shell_init_params) {
172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  AshWindowTreeHostInitParams ash_init_params;
173cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_WIN)
174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ash_init_params.remote_hwnd = shell_init_params.remote_hwnd;
175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif
176cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return ash_init_params;
177cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
178cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Shell* Shell::instance_ = NULL;
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Shell::initially_hide_cursor_ = false;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Shell, public:
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
190cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CHECK(!instance_);
192cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  instance_ = new Shell(init_params.delegate);
193cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  instance_->Init(init_params);
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return instance_;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Shell* Shell::GetInstance() {
1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(instance_);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return instance_;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Shell::HasInstance() {
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return !!instance_;
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::DeleteInstance() {
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  delete instance_;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  instance_ = NULL;
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
215c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochRootWindowController* Shell::GetPrimaryRootWindowController() {
2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(HasInstance());
217c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return GetRootWindowController(GetPrimaryRootWindow());
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(HasInstance());
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Shell::GetInstance()->display_controller()->
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetAllRootWindowControllers();
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)aura::Window* Shell::GetPrimaryRootWindow() {
2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(HasInstance());
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetInstance()->display_controller()->GetPrimaryRootWindow();
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)aura::Window* Shell::GetTargetRootWindow() {
2351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(HasInstance());
236a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  Shell* shell = GetInstance();
237a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (shell->scoped_target_root_window_)
238a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    return shell->scoped_target_root_window_;
239a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return shell->target_root_window_;
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Screen* Shell::GetScreen() {
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)aura::Window::Windows Shell::GetAllRootWindows() {
2491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CHECK(HasInstance());
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Shell::GetInstance()->display_controller()->
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetAllRootWindows();
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)aura::Window* Shell::GetContainer(aura::Window* root_window,
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  int container_id) {
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return root_window->GetChildById(container_id);
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const aura::Window* Shell::GetContainer(const aura::Window* root_window,
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        int container_id) {
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return root_window->GetChildById(container_id);
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int container_id,
2691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::Window* priority_root) {
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<aura::Window*> containers;
271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = GetAllRootWindows();
272f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (aura::Window::Windows::const_iterator it = root_windows.begin();
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       it != root_windows.end(); ++it) {
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    aura::Window* container = (*it)->GetChildById(container_id);
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (container) {
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (priority_root && priority_root->Contains(container))
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        containers.insert(containers.begin(), container);
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      else
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        containers.push_back(container);
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return containers;
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
2864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                            ui::MenuSourceType source_type) {
2874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // No context menus if there is no session with an active user.
2884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!session_state_delegate_->NumberOfLoggedInUsers())
2894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // No context menus when screen is locked.
2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (session_state_delegate_->IsScreenLocked())
2924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
29390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root =
2954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
296c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  GetRootWindowController(root)
297c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ->ShowContextMenu(location_in_screen, source_type);
2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void Shell::ShowAppList(aura::Window* window) {
3014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If the context window is not given, show it on the target root window.
3024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!window)
3034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    window = GetTargetRootWindow();
3044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!app_list_controller_)
305c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    app_list_controller_.reset(new AppListController);
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  app_list_controller_->Show(window);
3076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
3086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void Shell::DismissAppList() {
3106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (!app_list_controller_)
3116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    return;
3121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  app_list_controller_->Dismiss();
3136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}
3146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)void Shell::ToggleAppList(aura::Window* window) {
31603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (app_list_controller_ && app_list_controller_->IsVisible()) {
3176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    DismissAppList();
3186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    return;
3196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
3206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
3216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ShowAppList(window);
3224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool Shell::GetAppListTargetVisibility() const {
3254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return app_list_controller_.get() &&
3264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      app_list_controller_->GetTargetVisibility();
3274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)aura::Window* Shell::GetAppListWindow() {
3304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
3314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)app_list::AppListView* Shell::GetAppListView() {
3348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return app_list_controller_.get() ? app_list_controller_->GetView() : NULL;
3358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
3368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
3374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool Shell::IsSystemModalWindowOpen() const {
3384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (simulate_modal_window_open_for_testing_)
3394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return true;
3404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
341c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      kShellWindowId_SystemModalContainer, NULL);
3424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
3434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)       cit != containers.end(); ++cit) {
3444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
3454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)         wit != (*cit)->children().end(); ++wit) {
3464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      if ((*wit)->GetProperty(aura::client::kModalKey) ==
3474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
3484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        return true;
3494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      }
3504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
3514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
3524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return false;
3534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
35490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
3564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    views::Widget* widget) {
3574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Use translucent-style window frames for dialogs.
3588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return new CustomFrameViewAsh(widget);
3594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void Shell::RotateFocus(Direction direction) {
362c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  focus_cycler_->RotateFocus(direction == FORWARD ? FocusCycler::FORWARD
363c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                                  : FocusCycler::BACKWARD);
3644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::SetDisplayWorkAreaInsets(Window* contains,
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     const gfx::Insets& insets) {
3687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if (!display_controller_->UpdateWorkAreaOfDisplayNearestWindow(
3697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          contains, insets)) {
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
3717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_,
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    OnDisplayWorkAreaInsetsChanged());
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::OnLoginStateChanged(user::LoginStatus status) {
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
380f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void Shell::OnLoginUserProfilePrepared() {
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CreateShelf();
382f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  CreateKeyboard();
383f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
384f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != controllers.end(); ++iter)
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    (*iter)->UpdateAfterLoginStatusChange(status);
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::OnAppTerminating() {
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::OnLockStateChanged(bool locked) {
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
398ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#ifndef NDEBUG
399ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Make sure that there is no system modal in Lock layer when unlocked.
400ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  if (!locked) {
401ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
402c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
403ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
404ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch         iter != containers.end(); ++iter) {
405ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      DCHECK_EQ(0u, (*iter)->children().size());
406ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    }
407ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
408ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#endif
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void Shell::OnCastingSessionStartedOrStopped(bool started) {
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS) && defined(USE_X11)
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (projecting_observer_)
4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    projecting_observer_->OnCastingSessionStartedOrStopped(started);
4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
418a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void Shell::OnOverviewModeStarting() {
419a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeStarting());
420a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
421a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
422a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void Shell::OnOverviewModeEnding() {
423a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeEnding());
424a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
425a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
426a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void Shell::OnMaximizeModeStarted() {
427a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeStarted());
428a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
429a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
430a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void Shell::OnMaximizeModeEnded() {
431a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeEnded());
432a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
433a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
434a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid Shell::OnRootWindowAdded(aura::Window* root_window) {
435a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  FOR_EACH_OBSERVER(ShellObserver, observers_, OnRootWindowAdded(root_window));
436a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
437a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void Shell::CreateShelf() {
439b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
440b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
441b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)       iter != controllers.end(); ++iter)
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    (*iter)->shelf()->CreateShelf();
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid Shell::OnShelfCreatedForRootWindow(aura::Window* root_window) {
4460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  FOR_EACH_OBSERVER(ShellObserver,
4470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                    observers_,
4480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                    OnShelfCreatedForRootWindow(root_window));
4490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
4500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
451f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void Shell::CreateKeyboard() {
452f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // TODO(bshe): Primary root window controller may not be the controller to
453f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // attach virtual keyboard. See http://crbug.com/303429
454f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  InitKeyboard();
4551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  GetPrimaryRootWindowController()->
4561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ActivateKeyboard(keyboard::KeyboardController::GetInstance());
457f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void Shell::DeactivateKeyboard() {
460c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (keyboard::KeyboardController::GetInstance()) {
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    RootWindowControllerList controllers = GetAllRootWindowControllers();
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    for (RootWindowControllerList::iterator iter = controllers.begin();
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        iter != controllers.end(); ++iter) {
464c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
467c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  keyboard::KeyboardController::ResetInstance(NULL);
4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void Shell::ShowShelf() {
471b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
472b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
473b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)       iter != controllers.end(); ++iter)
4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    (*iter)->ShowShelf();
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::AddShellObserver(ShellObserver* observer) {
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observers_.AddObserver(observer);
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::RemoveShellObserver(ShellObserver* observer) {
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observers_.RemoveObserver(observer);
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS)
486cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool Shell::ShouldSaveDisplaySettings() {
487f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return !((maximize_mode_controller_->IsMaximizeModeWindowManagerEnabled() &&
48803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)            maximize_mode_controller_->
48903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                ignore_display_configuration_updates()) ||
490cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)           resolution_notification_controller_->DoesNotificationTimeout());
491cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
492cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif
493cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::UpdateShelfVisibility() {
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != controllers.end(); ++iter)
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if ((*iter)->shelf())
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (*iter)->UpdateShelfVisibility();
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
5031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                     aura::Window* root_window) {
504c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ash::ShelfLayoutManager::ForShelf(root_window)->SetAutoHideBehavior(behavior);
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
5081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::Window* root_window) const {
509c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return ash::ShelfLayoutManager::ForShelf(root_window)->auto_hide_behavior();
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::SetShelfAlignment(ShelfAlignment alignment,
5131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                              aura::Window* root_window) {
514c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (ash::ShelfLayoutManager::ForShelf(root_window)->SetAlignment(alignment)) {
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    FOR_EACH_OBSERVER(
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
520f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)ShelfAlignment Shell::GetShelfAlignment(const aura::Window* root_window) {
521c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return GetRootWindowController(root_window)
522c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ->GetShelfLayoutManager()
523c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ->GetAlignment();
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::SetDimming(bool should_dim) {
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != controllers.end(); ++iter)
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    (*iter)->screen_dimmer()->SetDimming(should_dim);
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                        aura::Window* root_window) {
5354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  FOR_EACH_OBSERVER(ShellObserver, observers_, OnFullscreenStateChanged(
5364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      is_fullscreen, root_window));
5374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
5384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::CreateModalBackground(aura::Window* window) {
540c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!modality_filter_) {
541c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    modality_filter_.reset(new SystemModalContainerEventFilter(this));
5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    AddPreTargetHandler(modality_filter_.get());
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != controllers.end(); ++iter)
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::OnModalWindowRemoved(aura::Window* removed) {
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RootWindowControllerList controllers = GetAllRootWindowControllers();
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool activated = false;
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (RootWindowControllerList::iterator iter = controllers.begin();
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       iter != controllers.end() && !activated; ++iter) {
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    activated = (*iter)->GetSystemModalLayoutManager(removed)->
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ActivateNextModalWindow();
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!activated) {
5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    RemovePreTargetHandler(modality_filter_.get());
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    modality_filter_.reset();
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (RootWindowControllerList::iterator iter = controllers.begin();
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         iter != controllers.end(); ++iter)
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebNotificationTray* Shell::GetWebNotificationTray() {
5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return GetPrimaryRootWindowController()->shelf()->
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      status_area_widget()->web_notification_tray();
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool Shell::HasPrimaryStatusArea() {
5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf();
5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return shelf && shelf->status_area_widget();
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)SystemTray* Shell::GetPrimarySystemTray() {
5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return GetPrimaryRootWindowController()->GetSystemTray();
5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
581a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)ShelfDelegate* Shell::GetShelfDelegate() {
582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!shelf_delegate_) {
583f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    shelf_model_.reset(new ShelfModel);
584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Creates ShelfItemDelegateManager before ShelfDelegate.
585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    shelf_item_delegate_manager_.reset(
586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        new ShelfItemDelegateManager(shelf_model_.get()));
5874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    shelf_delegate_.reset(delegate_->CreateShelfDelegate(shelf_model_.get()));
589c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    scoped_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate);
5904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Finding the shelf model's location of the app list and setting its
592a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // ShelfItemDelegate.
593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    int app_list_index = shelf_model_->GetItemIndexForType(TYPE_APP_LIST);
5941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DCHECK_GE(app_list_index, 0);
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID app_list_id = shelf_model_->items()[app_list_index].id;
5964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    DCHECK(app_list_id);
597a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id,
598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                       controller.Pass());
599c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    shelf_window_watcher_.reset(new ShelfWindowWatcher(
600c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        shelf_model_.get(), shelf_item_delegate_manager_.get()));
6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
602a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return shelf_delegate_.get();
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid Shell::SetTouchHudProjectionEnabled(bool enabled) {
606eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (is_touch_hud_projection_enabled_ == enabled)
607eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
608eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
609eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  is_touch_hud_projection_enabled_ = enabled;
6107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  FOR_EACH_OBSERVER(ShellObserver, observers_,
6117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                    OnTouchHudProjectionToggled(enabled));
612eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
613eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
6148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(OS_CHROMEOS)
6158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)ash::FirstRunHelper* Shell::CreateFirstRunHelper() {
6168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  return new ash::FirstRunHelperImpl;
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void Shell::SetCursorCompositingEnabled(bool enabled) {
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  display_controller_->cursor_window_controller()->SetCursorCompositingEnabled(
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      enabled);
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  native_cursor_manager_->SetNativeCursorEnabled(!enabled);
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif  // defined(OS_CHROMEOS)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Shell::DoInitialWorkspaceAnimation() {
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetPrimaryRootWindowController()->workspace_controller()->
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      DoInitialAnimation();
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Shell, private:
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)Shell::Shell(ShellDelegate* delegate)
6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : target_root_window_(NULL),
6364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      scoped_target_root_window_(NULL),
6374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      delegate_(delegate),
6384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      window_positioner_(new WindowPositioner),
6394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      activation_client_(NULL),
640c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      accelerometer_controller_(new AccelerometerController()),
641effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_CHROMEOS)
642c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      display_configurator_(new ui::DisplayConfigurator()),
643effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif  // defined(OS_CHROMEOS)
6444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      native_cursor_manager_(new AshNativeCursorManager),
645effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      cursor_manager_(
646effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch          scoped_ptr< ::wm::NativeCursorManager>(native_cursor_manager_)),
6474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      simulate_modal_window_open_for_testing_(false),
6484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      is_touch_hud_projection_enabled_(false) {
6494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DCHECK(delegate_.get());
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gpu_support_.reset(delegate_->CreateGPUSupport());
651c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  display_manager_.reset(new DisplayManager);
6524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_controller_.reset(new DisplayController);
6534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_CHROMEOS) && defined(USE_X11)
6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_metrics_recorder_.reset(new UserMetricsRecorder);
6554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif  // defined(OS_CHROMEOS)
6564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_CHROMEOS)
658c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  PowerStatus::Initialize();
6594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif
6604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)Shell::~Shell() {
6634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
6644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
665effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  delegate_->PreShutdown();
666effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
6674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  views::FocusManagerFactory::Install(NULL);
6684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Remove the focus from any window. This will prevent overhead and side
6704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // effects (e.g. crashes) from changing focus during shutdown.
6714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // See bug crbug.com/134502.
6724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(NULL);
6734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Please keep in same order as in Init() because it's easy to miss one.
6754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (window_modality_controller_)
6764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    window_modality_controller_.reset();
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS) && defined(USE_X11)
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  magnifier_key_scroll_handler_.reset();
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePreTargetHandler(speech_feedback_handler_.get());
6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  speech_feedback_handler_.reset();
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
6844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(user_activity_detector_.get());
6854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(overlay_filter_.get());
6864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(input_method_filter_.get());
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePreTargetHandler(accelerator_filter_.get());
6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePreTargetHandler(event_transformation_handler_.get());
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePreTargetHandler(toplevel_window_event_handler_.get());
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RemovePostTargetHandler(toplevel_window_event_handler_.get());
6914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(system_gesture_filter_.get());
6924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(keyboard_metrics_filter_.get());
693cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  RemovePreTargetHandler(mouse_cursor_filter_.get());
6944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // TooltipController is deleted with the Shell so removing its references.
6964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RemovePreTargetHandler(tooltip_controller_.get());
6974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
698f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Destroy maximize mode controller early on since it has some observers which
699a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // need to be removed.
700f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  maximize_mode_controller_->Shutdown();
701c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  maximize_mode_controller_.reset();
702a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // AppList needs to be released before shelf layout manager, which is
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // destroyed with shelf container in the loop below. However, app list
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // container is now on top of shelf container and released after it.
7064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // TODO(xiyuan): Move it back when app list container is no longer needed.
7074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  app_list_controller_.reset();
7084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
709a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(OS_CHROMEOS)
710a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Destroy the LastWindowClosedLogoutReminder before the
711a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // LogoutConfirmationController.
712a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  last_window_closed_logout_reminder_.reset();
713a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
714a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Destroy the LogoutConfirmationController before the SystemTrayDelegate.
715a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  logout_confirmation_controller_.reset();
716a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif
717a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Destroy SystemTrayDelegate before destroying the status area(s).
7194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  system_tray_delegate_->Shutdown();
7204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  system_tray_delegate_.reset();
7214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  locale_notification_controller_.reset();
7234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Drag-and-drop must be canceled prior to close all windows.
7254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  drag_drop_controller_.reset();
7264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
727a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Controllers who have WindowObserver added must be deleted
728a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // before |display_controller_| is deleted.
729a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
730a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS)
731a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // VideoActivityNotifier must be deleted before |video_detector_| is
732a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // deleted because it's observing video activity through
733a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // VideoDetectorObserver interface.
734a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  video_activity_notifier_.reset();
735a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // defined(OS_CHROMEOS)
736a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  video_detector_.reset();
737a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  high_contrast_controller_.reset();
738a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
739a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  shadow_controller_.reset();
740a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  resize_shadow_controller_.reset();
741a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
742cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  window_cycle_controller_.reset();
7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window_selector_controller_.reset();
744a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  mru_window_tracker_.reset();
745a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
746a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // |shelf_window_watcher_| has a weak pointer to |shelf_Model_|
747a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // and has window observers.
748a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  shelf_window_watcher_.reset();
749a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
7504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Destroy all child windows including widgets.
7514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_controller_->CloseChildWindows();
752f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_controller_->CloseNonDesktopDisplay();
7534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
754a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Chrome implementation of shelf delegate depends on FocusClient,
755a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // so must be deleted before |focus_client_|.
756a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  shelf_delegate_.reset();
757a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  focus_client_.reset();
758a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
7594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
7604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // needs to remove observers from it.
7614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  system_tray_notifier_.reset();
7624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // These need a valid Shell instance to clean up properly, so explicitly
7644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // delete them before invalidating the instance.
7654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Alphabetical. TODO(oshima): sort.
7664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  magnification_controller_.reset();
7674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  partial_magnification_controller_.reset();
7684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  tooltip_controller_.reset();
7694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  event_client_.reset();
770cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  nested_accelerator_controller_.reset();
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  toplevel_window_event_handler_.reset();
7724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  visibility_controller_.reset();
773a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
774f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // destroyed before |shelf_model_| is destroyed.
775a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  shelf_item_delegate_manager_.reset();
776f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  shelf_model_.reset();
7774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  power_button_controller_.reset();
7794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  lock_state_controller_.reset();
7804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS)
7824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  resolution_notification_controller_.reset();
7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
7844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  desktop_background_controller_.reset();
785cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  mouse_cursor_filter_.reset();
786cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
787cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) && defined(USE_X11)
788cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  touch_transformer_controller_.reset();
789cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif  // defined(OS_CHROMEOS) && defined(USE_X11)
7904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // This also deletes all RootWindows. Note that we invoke Shutdown() on
7924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // DisplayController before resetting |display_controller_|, since destruction
7934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // of its owned RootWindowControllers relies on the value.
7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  display_manager_->CreateScreenForShutdown();
7954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_controller_->Shutdown();
7964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_controller_.reset();
7971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual_keyboard_controller_.reset();
7984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  screen_position_controller_.reset();
7991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  accessibility_delegate_.reset();
8000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  new_window_delegate_.reset();
8010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  media_delegate_.reset();
8024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
803c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  keyboard::KeyboardController::ResetInstance(NULL);
804c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
805effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_CHROMEOS)
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (display_change_observer_)
807c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->RemoveObserver(display_change_observer_.get());
8085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (display_configurator_animation_)
8095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    display_configurator_->RemoveObserver(
8105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        display_configurator_animation_.get());
8114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (display_error_observer_)
812c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->RemoveObserver(display_error_observer_.get());
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (projecting_observer_)
814c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->RemoveObserver(projecting_observer_.get());
8154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_change_observer_.reset();
8164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif  // defined(OS_CHROMEOS)
8174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_CHROMEOS)
819c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  PowerStatus::Shutdown();
8204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif
8214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DCHECK(instance_ == this);
8234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  instance_ = NULL;
8244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
8254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
826cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void Shell::Init(const ShellInitParams& init_params) {
8274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  delegate_->PreInit();
8280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  bool display_initialized = display_manager_->InitFromCommandLine();
829effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_CHROMEOS)
830c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  display_configurator_->Init(!gpu_support_->IsPanelFittingDisabled());
8315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  display_configurator_animation_.reset(new DisplayConfiguratorAnimation());
8325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  display_configurator_->AddObserver(display_configurator_animation_.get());
8330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
834c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  projecting_observer_.reset(new ProjectingObserver());
835c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  display_configurator_->AddObserver(projecting_observer_.get());
8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  if (!display_initialized && base::SysInfo::IsRunningOnChromeOS()) {
838c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_change_observer_.reset(new DisplayChangeObserver);
8394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // Register |display_change_observer_| first so that the rest of
8404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // observer gets invoked after the root windows are configured.
841c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->AddObserver(display_change_observer_.get());
842c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_error_observer_.reset(new DisplayErrorObserver());
843c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->AddObserver(display_error_observer_.get());
844c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->set_state_controller(display_change_observer_.get());
845c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->set_mirroring_controller(display_manager_.get());
846c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    display_configurator_->ForceInitialConfigure(
8474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
8484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    display_initialized = true;
8494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
850effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif  // defined(OS_CHROMEOS)
8514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!display_initialized)
8520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    display_manager_->InitDefaultDisplay();
8534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
85403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  display_manager_->InitFontParams();
85503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
8564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Install the custom factory first so that views::FocusManagers for Tray,
8575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Shelf, and WallPaper could be created by the factory.
8584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  views::FocusManagerFactory::Install(new AshFocusManagerFactory);
8594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
860010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  aura::Env::CreateInstance(true);
861cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
8624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The WindowModalityController needs to be at the front of the input event
8644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // pretarget handler list to ensure that it processes input events when modal
8654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // windows are active.
8664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_modality_controller_.reset(
867a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      new ::wm::WindowModalityController(this));
8684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
869a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  env_filter_.reset(new ::wm::CompoundEventFilter);
8704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(env_filter_.get());
8714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
872a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::FocusController* focus_controller =
873a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      new ::wm::FocusController(new wm::AshFocusRules);
8744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  focus_client_.reset(focus_controller);
8754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  activation_client_ = focus_controller;
8764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  activation_client_->AddObserver(this);
877c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  focus_cycler_.reset(new FocusCycler());
8784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
879c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  screen_position_controller_.reset(new ScreenPositionController);
8804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  display_controller_->Start();
882cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  display_controller_->CreatePrimaryHost(
883cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      ShellInitParamsToAshWindowTreeHostInitParams(init_params));
8841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual_keyboard_controller_.reset(new VirtualKeyboardController);
8851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window = display_controller_->GetPrimaryRootWindow();
8864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  target_root_window_ = root_window;
8874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS)
8894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  resolution_notification_controller_.reset(
890c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      new ResolutionNotificationController);
8915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
8924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
8935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  cursor_manager_.SetDisplay(GetScreen()->GetPrimaryDisplay());
8944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
895cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  nested_accelerator_controller_.reset(
896cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate));
8974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  accelerator_controller_.reset(new AcceleratorController);
898c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  maximize_mode_controller_.reset(new MaximizeModeController());
8994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS) && defined(USE_X11)
9015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler().Pass();
9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddPreTargetHandler(magnifier_key_scroll_handler_.get());
9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler().Pass();
9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddPreTargetHandler(speech_feedback_handler_.get());
9055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
9065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The order in which event filters are added is significant.
9084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
909c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // wm::UserActivityDetector passes events to observers, so let them get
9104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // rewritten first.
911c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  user_activity_detector_.reset(new ::wm::UserActivityDetector);
9124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(user_activity_detector_.get());
9134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
914c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  overlay_filter_.reset(new OverlayEventFilter);
9154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(overlay_filter_.get());
9164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddShellObserver(overlay_filter_.get());
9174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
918a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  input_method_filter_.reset(new ::wm::InputMethodEventFilter(
919a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      root_window->GetHost()->GetAcceleratedWidget()));
9204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(input_method_filter_.get());
9214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
922cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  accelerator_filter_.reset(new ::wm::AcceleratorFilter(
923cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      scoped_ptr< ::wm::AcceleratorDelegate>(new AcceleratorDelegate).Pass()));
9244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(accelerator_filter_.get());
9254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
926c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  event_transformation_handler_.reset(new EventTransformationHandler);
9274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(event_transformation_handler_.get());
9284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  toplevel_window_event_handler_.reset(new ToplevelWindowEventHandler);
9305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
931c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  system_gesture_filter_.reset(new SystemGestureEventFilter);
9324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(system_gesture_filter_.get());
9334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
934c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  keyboard_metrics_filter_.reset(new KeyboardUMAEventFilter);
9354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddPreTargetHandler(keyboard_metrics_filter_.get());
9364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The keyboard system must be initialized before the RootWindowController is
9384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // created.
9395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS)
9404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    keyboard::InitializeKeyboard();
9415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
9424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
943116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if defined(OS_CHROMEOS)
944116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  sticky_keys_controller_.reset(new StickyKeysController);
945116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif
946116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
9474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  lock_state_controller_.reset(new LockStateController);
9484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  power_button_controller_.reset(new PowerButtonController(
9494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      lock_state_controller_.get()));
950effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_CHROMEOS)
951a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Pass the initial display state to PowerButtonController.
952a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  power_button_controller_->OnDisplayModeChanged(
953c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      display_configurator_->cached_displays());
954a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif
9554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  AddShellObserver(lock_state_controller_.get());
9564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
957c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  drag_drop_controller_.reset(new DragDropController);
958c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  mouse_cursor_filter_.reset(new MouseCursorEventFilter());
9594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PrependPreTargetHandler(mouse_cursor_filter_.get());
9604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Create Controllers that may need root window.
9624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // TODO(oshima): Move as many controllers before creating
9634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // RootWindowController as possible.
9644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  visibility_controller_.reset(new AshVisibilityController);
9654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  magnification_controller_.reset(
9674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      MagnificationController::CreateInstance());
9684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  mru_window_tracker_.reset(new MruWindowTracker(activation_client_));
9694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  partial_magnification_controller_.reset(
9714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      new PartialMagnificationController());
9724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  autoclick_controller_.reset(AutoclickController::CreateInstance());
9744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  high_contrast_controller_.reset(new HighContrastController);
9764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  video_detector_.reset(new VideoDetector);
9774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_selector_controller_.reset(new