1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ASH_SHELL_H_
6 #define ASH_SHELL_H_
7 
8 #include <memory>
9 #include <utility>
10 #include <vector>
11 
12 #include "ash/ash_export.h"
13 #include "ash/metrics/user_metrics_recorder.h"
14 #include "ash/public/cpp/session/session_observer.h"
15 #include "ash/public/cpp/shelf_types.h"
16 #include "ash/wm/system_modal_container_event_filter_delegate.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/observer_list.h"
21 #include "ui/aura/window.h"
22 #include "ui/base/ui_base_types.h"
23 #include "ui/display/screen.h"
24 #include "ui/events/event_target.h"
25 #include "ui/wm/core/cursor_manager.h"
26 #include "ui/wm/public/activation_change_observer.h"
27 
28 class PrefService;
29 
30 namespace aura {
31 class RootWindow;
32 class Window;
33 }  // namespace aura
34 
35 namespace chromeos {
36 class ImmersiveContext;
37 class SnapController;
38 }  // namespace chromeos
39 
40 namespace dbus {
41 class Bus;
42 }
43 
44 namespace display {
45 class DisplayChangeObserver;
46 class DisplayConfigurator;
47 class DisplayManager;
48 }  // namespace display
49 
50 namespace gfx {
51 class Insets;
52 class Point;
53 }  // namespace gfx
54 
55 namespace keyboard {
56 class KeyboardUIFactory;
57 }
58 
59 namespace ui {
60 class ContextFactory;
61 class UserActivityDetector;
62 class UserActivityPowerManagerNotifier;
63 }  // namespace ui
64 
65 namespace views {
66 class NonClientFrameView;
67 class Widget;
68 namespace corewm {
69 class TooltipController;
70 }
71 }  // namespace views
72 
73 namespace wm {
74 class AcceleratorFilter;
75 class ActivationClient;
76 class CompoundEventFilter;
77 class FocusController;
78 class ShadowController;
79 class VisibilityController;
80 class WindowModalityController;
81 }  // namespace wm
82 
83 namespace ash {
84 
85 class AcceleratorControllerImpl;
86 class AccessibilityControllerImpl;
87 class AccessibilityDelegate;
88 class AccessibilityFocusRingControllerImpl;
89 class AmbientController;
90 class AppListControllerImpl;
91 class AshColorProvider;
92 class AshDBusServices;
93 class AshFocusRules;
94 class AshTouchTransformController;
95 class AssistantControllerImpl;
96 class AutoclickController;
97 class BackGestureEventHandler;
98 class BacklightsForcedOffSetter;
99 class BloomUiControllerImpl;
100 class BluetoothNotificationController;
101 class BluetoothPowerController;
102 class BrightnessControlDelegate;
103 class CaptureModeController;
104 class CrosDisplayConfig;
105 class DesksController;
106 class DetachableBaseHandler;
107 class DetachableBaseNotificationController;
108 class DisplayAlignmentController;
109 class DisplayColorManager;
110 class NativeCursorManagerAsh;
111 class DisplayConfigurationController;
112 class DisplayConfigurationObserver;
113 class DisplayErrorObserver;
114 class DisplayHighlightController;
115 class DisplayPrefs;
116 class DisplayShutdownObserver;
117 class DisplaySpeakerController;
118 class DockedMagnifierControllerImpl;
119 class DragDropController;
120 class EventClientImpl;
121 class EventRewriterControllerImpl;
122 class EventTransformationHandler;
123 class FocusCycler;
124 class FrameThrottlingController;
125 class HighContrastController;
126 class HighlighterController;
127 class HoldingSpaceController;
128 class HomeScreenController;
129 class ImeControllerImpl;
130 class InSessionAuthDialogControllerImpl;
131 class KeyAccessibilityEnabler;
132 class KeyboardBrightnessControlDelegate;
133 class KeyboardControllerImpl;
134 class LaserPointerController;
135 class LocaleUpdateControllerImpl;
136 class LockStateController;
137 class LogoutConfirmationController;
138 class LoginScreenController;
139 class MagnificationController;
140 class TabletModeController;
141 class MediaControllerImpl;
142 class MediaNotificationControllerImpl;
143 class MessageCenterController;
144 class MouseCursorEventFilter;
145 class MruWindowTracker;
146 class MultiDeviceNotificationPresenter;
147 class NearbyShareControllerImpl;
148 class NearbyShareDelegate;
149 class NightLightControllerImpl;
150 class OverlayEventFilter;
151 class OverviewController;
152 class ParentAccessController;
153 class PartialMagnificationController;
154 class PeripheralBatteryNotifier;
155 class PeripheralBatteryTracker;
156 class PersistentWindowController;
157 class PolicyRecommendationRestorer;
158 class PowerButtonController;
159 class PowerEventObserver;
160 class PowerPrefs;
161 class PrivacyScreenController;
162 class ProjectingObserver;
163 class QuickAnswersController;
164 class ResizeShadowController;
165 class ResolutionNotificationController;
166 class RootWindowController;
167 class ScreenLayoutObserver;
168 class ScreenOrientationController;
169 class ScreenshotController;
170 class ScreenPinningController;
171 class ScreenPositionController;
172 class ScreenSwitchCheckController;
173 class SessionControllerImpl;
174 class ShelfConfig;
175 class ShelfController;
176 class ShelfWindowWatcher;
177 class ShellDelegate;
178 struct ShellInitParams;
179 class ShellObserver;
180 class ShutdownControllerImpl;
181 class SmsObserver;
182 class StickyKeysController;
183 class SystemGestureEventFilter;
184 class SystemModalContainerEventFilter;
185 class SystemNotificationController;
186 class SystemTrayModel;
187 class SystemTrayNotifier;
188 class ToastManagerImpl;
189 class ToplevelWindowEventHandler;
190 class ClipboardHistoryControllerImpl;
191 class TouchDevicesController;
192 class TrayAction;
193 class TrayBluetoothHelper;
194 class VideoActivityNotifier;
195 class VideoDetector;
196 class WallpaperControllerImpl;
197 class WindowCycleController;
198 class WindowPositioner;
199 class WindowTreeHostManager;
200 class ArcInputMethodBoundsTracker;
201 
202 enum class LoginStatus;
203 
204 // Shell is a singleton object that presents the Shell API and implements the
205 // RootWindow's delegate interface.
206 //
207 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
208 // takes ownership of the Shell.
209 class ASH_EXPORT Shell : public SessionObserver,
210                          public SystemModalContainerEventFilterDelegate,
211                          public ui::EventTarget,
212                          public ::wm::ActivationChangeObserver {
213  public:
214   typedef std::vector<RootWindowController*> RootWindowControllerList;
215 
216   // Creates the single Shell instance.
217   static Shell* CreateInstance(ShellInitParams init_params);
218 
219   // Should never be called before |CreateInstance()|.
220   static Shell* Get();
221 
222   // Returns true if the ash shell has been instantiated.
223   static bool HasInstance();
224 
225   static void DeleteInstance();
226 
227   // Returns the root window controller for the primary root window.
228   // TODO(oshima): move this to |RootWindowController|
229   static RootWindowController* GetPrimaryRootWindowController();
230 
231   // Returns the RootWindowController for the given display id. If there
232   // is no display for |display_id|, null is returned.
233   static RootWindowController* GetRootWindowControllerWithDisplayId(
234       int64_t display_id);
235 
236   // Returns the root Window for the given display id. If there is no display
237   // for |display_id| null is returned.
238   static aura::Window* GetRootWindowForDisplayId(int64_t display_id);
239 
240   // Returns all root window controllers.
241   // TODO(oshima): move this to |RootWindowController|
242   static RootWindowControllerList GetAllRootWindowControllers();
243 
244   // Returns the primary root Window. The primary root Window is the one that
245   // has a launcher.
246   static aura::Window* GetPrimaryRootWindow();
247 
248   // Sets the root window that newly created windows should be added to.
249   static void SetRootWindowForNewWindows(aura::Window* root);
250 
251   // Returns the root window that newly created windows should be added to.
252   // Value can be temporarily overridden using
253   // display::ScopedDisplayForNewWindows. NOTE: this returns the root, newly
254   // created window should be added to the appropriate container in the returned
255   // window.
256   static aura::Window* GetRootWindowForNewWindows();
257 
258   // Returns all root windows.
259   static aura::Window::Windows GetAllRootWindows();
260 
261   static aura::Window* GetContainer(aura::Window* root_window,
262                                     int container_id);
263   static const aura::Window* GetContainer(const aura::Window* root_window,
264                                           int container_id);
265 
266   // If a system-modal dialog window is currently open, returns the ID of the
267   // system modal window container that contains the window.
268   // If no system-modal dialogs are open it returns -1.
269   static int GetOpenSystemModalWindowContainerId();
270 
271   // Returns true if a system-modal dialog window is currently open.
272   static bool IsSystemModalWindowOpen();
273 
274   // Track/Untrack InputMethod bounds.
275   void TrackInputMethodBounds(ArcInputMethodBoundsTracker* tracker);
276   void UntrackTrackInputMethodBounds(ArcInputMethodBoundsTracker* tracker);
277 
278   // Creates a default views::NonClientFrameView for use by windows in the
279   // Ash environment.
280   std::unique_ptr<views::NonClientFrameView> CreateDefaultNonClientFrameView(
281       views::Widget* widget);
282 
283   // Sets work area insets of the display containing |window|, pings observers.
284   void SetDisplayWorkAreaInsets(aura::Window* window,
285                                 const gfx::Insets& insets);
286 
287   // Called when a casting session is started or stopped.
288   void OnCastingSessionStartedOrStopped(bool started);
289 
290   // Called when a root window is created.
291   void OnRootWindowAdded(aura::Window* root_window);
292 
293   // Called when dictation is activated.
294   void OnDictationStarted();
295 
296   // Called when dictation is ended.
297   void OnDictationEnded();
298 
299   // Returns whether the device is currently in tablet mode. If the tablet
300   // mode controller isn't available, we assume the device is not in
301   // tablet mode.
302   bool IsInTabletMode() const;
303 
304   // Tests if TabletModeWindowManager is not enabled, and if
305   // TabletModeController is not currently setting a display rotation. Or if
306   // the |resolution_notification_controller_| is not showing its confirmation
307   // dialog. If true then changes to display settings can be saved.
308   bool ShouldSaveDisplaySettings();
309 
accelerator_controller()310   AcceleratorControllerImpl* accelerator_controller() {
311     return accelerator_controller_.get();
312   }
accessibility_controller()313   AccessibilityControllerImpl* accessibility_controller() {
314     return accessibility_controller_.get();
315   }
accessibility_delegate()316   AccessibilityDelegate* accessibility_delegate() {
317     return accessibility_delegate_.get();
318   }
accessibility_focus_ring_controller()319   AccessibilityFocusRingControllerImpl* accessibility_focus_ring_controller() {
320     return accessibility_focus_ring_controller_.get();
321   }
322   ::wm::ActivationClient* activation_client();
app_list_controller()323   AppListControllerImpl* app_list_controller() {
324     return app_list_controller_.get();
325   }
ambient_controller()326   AmbientController* ambient_controller() { return ambient_controller_.get(); }
assistant_controller()327   AssistantControllerImpl* assistant_controller() {
328     return assistant_controller_.get();
329   }
autoclick_controller()330   AutoclickController* autoclick_controller() {
331     return autoclick_controller_.get();
332   }
backlights_forced_off_setter()333   BacklightsForcedOffSetter* backlights_forced_off_setter() {
334     return backlights_forced_off_setter_.get();
335   }
bluetooth_power_controller()336   BluetoothPowerController* bluetooth_power_controller() {
337     return bluetooth_power_controller_.get();
338   }
brightness_control_delegate()339   BrightnessControlDelegate* brightness_control_delegate() {
340     return brightness_control_delegate_.get();
341   }
cros_display_config()342   CrosDisplayConfig* cros_display_config() {
343     return cros_display_config_.get();
344   }
cursor_manager()345   ::wm::CursorManager* cursor_manager() { return cursor_manager_.get(); }
desks_controller()346   DesksController* desks_controller() { return desks_controller_.get(); }
detachable_base_handler()347   DetachableBaseHandler* detachable_base_handler() {
348     return detachable_base_handler_.get();
349   }
350 
display_manager()351   display::DisplayManager* display_manager() { return display_manager_.get(); }
display_prefs()352   DisplayPrefs* display_prefs() { return display_prefs_.get(); }
display_configuration_controller()353   DisplayConfigurationController* display_configuration_controller() {
354     return display_configuration_controller_.get();
355   }
356 
display_alignment_controller()357   DisplayAlignmentController* display_alignment_controller() {
358     return display_alignment_controller_.get();
359   }
360 
361   display::DisplayConfigurator* display_configurator();
362 
display_color_manager()363   DisplayColorManager* display_color_manager() {
364     return display_color_manager_.get();
365   }
display_error_observer()366   DisplayErrorObserver* display_error_observer() {
367     return display_error_observer_.get();
368   }
369 
display_highlight_controller()370   DisplayHighlightController* display_highlight_controller() {
371     return display_highlight_controller_.get();
372   }
373 
374   DockedMagnifierControllerImpl* docked_magnifier_controller();
env_filter()375   ::wm::CompoundEventFilter* env_filter() { return env_filter_.get(); }
event_rewriter_controller()376   EventRewriterControllerImpl* event_rewriter_controller() {
377     return event_rewriter_controller_.get();
378   }
event_client()379   EventClientImpl* event_client() { return event_client_.get(); }
event_transformation_handler()380   EventTransformationHandler* event_transformation_handler() {
381     return event_transformation_handler_.get();
382   }
home_screen_controller()383   HomeScreenController* home_screen_controller() {
384     return home_screen_controller_.get();
385   }
focus_controller()386   ::wm::FocusController* focus_controller() { return focus_controller_.get(); }
focus_rules()387   AshFocusRules* focus_rules() { return focus_rules_; }
focus_cycler()388   FocusCycler* focus_cycler() { return focus_cycler_.get(); }
highlighter_controller()389   HighlighterController* highlighter_controller() {
390     return highlighter_controller_.get();
391   }
high_contrast_controller()392   HighContrastController* high_contrast_controller() {
393     return high_contrast_controller_.get();
394   }
ime_controller()395   ImeControllerImpl* ime_controller() { return ime_controller_.get(); }
in_session_auth_dialog_controller()396   InSessionAuthDialogControllerImpl* in_session_auth_dialog_controller() {
397     return in_session_auth_dialog_controller_.get();
398   }
key_accessibility_enabler()399   KeyAccessibilityEnabler* key_accessibility_enabler() {
400     return key_accessibility_enabler_.get();
401   }
keyboard_brightness_control_delegate()402   KeyboardBrightnessControlDelegate* keyboard_brightness_control_delegate() {
403     return keyboard_brightness_control_delegate_.get();
404   }
keyboard_controller()405   KeyboardControllerImpl* keyboard_controller() {
406     return keyboard_controller_.get();
407   }
laser_pointer_controller()408   LaserPointerController* laser_pointer_controller() {
409     return laser_pointer_controller_.get();
410   }
locale_update_controller()411   LocaleUpdateControllerImpl* locale_update_controller() {
412     return locale_update_controller_.get();
413   }
login_screen_controller()414   LoginScreenController* login_screen_controller() {
415     return login_screen_controller_.get();
416   }
lock_state_controller()417   LockStateController* lock_state_controller() {
418     return lock_state_controller_.get();
419   }
logout_confirmation_controller()420   LogoutConfirmationController* logout_confirmation_controller() {
421     return logout_confirmation_controller_.get();
422   }
magnification_controller()423   MagnificationController* magnification_controller() {
424     return magnification_controller_.get();
425   }
media_controller()426   MediaControllerImpl* media_controller() { return media_controller_.get(); }
media_notification_controller()427   MediaNotificationControllerImpl* media_notification_controller() {
428     return media_notification_controller_.get();
429   }
message_center_controller()430   MessageCenterController* message_center_controller() {
431     return message_center_controller_.get();
432   }
mouse_cursor_filter()433   MouseCursorEventFilter* mouse_cursor_filter() {
434     return mouse_cursor_filter_.get();
435   }
mru_window_tracker()436   MruWindowTracker* mru_window_tracker() { return mru_window_tracker_.get(); }
nearby_share_controller()437   NearbyShareControllerImpl* nearby_share_controller() {
438     return nearby_share_controller_.get();
439   }
nearby_share_delegate()440   NearbyShareDelegate* nearby_share_delegate() {
441     return nearby_share_delegate_.get();
442   }
night_light_controller()443   NightLightControllerImpl* night_light_controller() {
444     return night_light_controller_.get();
445   }
privacy_screen_controller()446   PrivacyScreenController* privacy_screen_controller() {
447     return privacy_screen_controller_.get();
448   }
overlay_filter()449   OverlayEventFilter* overlay_filter() { return overlay_filter_.get(); }
parent_access_controller()450   ParentAccessController* parent_access_controller() {
451     return parent_access_controller_.get();
452   }
partial_magnification_controller()453   PartialMagnificationController* partial_magnification_controller() {
454     return partial_magnification_controller_.get();
455   }
policy_recommendation_restorer()456   PolicyRecommendationRestorer* policy_recommendation_restorer() {
457     return policy_recommendation_restorer_.get();
458   }
power_button_controller()459   PowerButtonController* power_button_controller() {
460     return power_button_controller_.get();
461   }
power_event_observer()462   PowerEventObserver* power_event_observer() {
463     return power_event_observer_.get();
464   }
resize_shadow_controller()465   ResizeShadowController* resize_shadow_controller() {
466     return resize_shadow_controller_.get();
467   }
resolution_notification_controller()468   ResolutionNotificationController* resolution_notification_controller() {
469     return resolution_notification_controller_.get();
470   }
screenshot_controller()471   ScreenshotController* screenshot_controller() {
472     return screenshot_controller_.get();
473   }
screen_layout_observer()474   ScreenLayoutObserver* screen_layout_observer() {
475     return screen_layout_observer_.get();
476   }
screen_orientation_controller()477   ScreenOrientationController* screen_orientation_controller() {
478     return screen_orientation_controller_.get();
479   }
screen_pinning_controller()480   ScreenPinningController* screen_pinning_controller() {
481     return screen_pinning_controller_.get();
482   }
screen_switch_check_controller()483   ScreenSwitchCheckController* screen_switch_check_controller() {
484     return screen_switch_check_controller_.get();
485   }
session_controller()486   SessionControllerImpl* session_controller() {
487     return session_controller_.get();
488   }
shadow_controller()489   ::wm::ShadowController* shadow_controller() {
490     return shadow_controller_.get();
491   }
shelf_config()492   ShelfConfig* shelf_config() { return shelf_config_.get(); }
shelf_controller()493   ShelfController* shelf_controller() { return shelf_controller_.get(); }
shell_delegate()494   ShellDelegate* shell_delegate() { return shell_delegate_.get(); }
shutdown_controller()495   ShutdownControllerImpl* shutdown_controller() {
496     return shutdown_controller_.get();
497   }
sticky_keys_controller()498   StickyKeysController* sticky_keys_controller() {
499     return sticky_keys_controller_.get();
500   }
system_notification_controller()501   SystemNotificationController* system_notification_controller() {
502     return system_notification_controller_.get();
503   }
system_tray_model()504   SystemTrayModel* system_tray_model() { return system_tray_model_.get(); }
system_tray_notifier()505   SystemTrayNotifier* system_tray_notifier() {
506     return system_tray_notifier_.get();
507   }
tablet_mode_controller()508   TabletModeController* tablet_mode_controller() const {
509     return tablet_mode_controller_.get();
510   }
toast_manager()511   ToastManagerImpl* toast_manager() { return toast_manager_.get(); }
tooltip_controller()512   views::corewm::TooltipController* tooltip_controller() {
513     return tooltip_controller_.get();
514   }
clipboard_history_controller()515   ClipboardHistoryControllerImpl* clipboard_history_controller() {
516     return clipboard_history_controller_.get();
517   }
touch_devices_controller()518   TouchDevicesController* touch_devices_controller() {
519     return touch_devices_controller_.get();
520   }
touch_transformer_controller()521   AshTouchTransformController* touch_transformer_controller() {
522     return touch_transformer_controller_.get();
523   }
tray_action()524   TrayAction* tray_action() { return tray_action_.get(); }
tray_bluetooth_helper()525   TrayBluetoothHelper* tray_bluetooth_helper() {
526     return tray_bluetooth_helper_.get();
527   }
metrics()528   UserMetricsRecorder* metrics() { return user_metrics_recorder_.get(); }
video_detector()529   VideoDetector* video_detector() { return video_detector_.get(); }
wallpaper_controller()530   WallpaperControllerImpl* wallpaper_controller() {
531     return wallpaper_controller_.get();
532   }
window_cycle_controller()533   WindowCycleController* window_cycle_controller() {
534     return window_cycle_controller_.get();
535   }
window_positioner()536   WindowPositioner* window_positioner() { return window_positioner_.get(); }
overview_controller()537   OverviewController* overview_controller() {
538     return overview_controller_.get();
539   }
window_tree_host_manager()540   WindowTreeHostManager* window_tree_host_manager() {
541     return window_tree_host_manager_.get();
542   }
back_gesture_event_handler()543   BackGestureEventHandler* back_gesture_event_handler() {
544     return back_gesture_event_handler_.get();
545   }
shell_tab_handler()546   ui::EventHandler* shell_tab_handler() { return shell_tab_handler_.get(); }
toplevel_window_event_handler()547   ToplevelWindowEventHandler* toplevel_window_event_handler() {
548     return toplevel_window_event_handler_.get();
549   }
ash_color_provider()550   AshColorProvider* ash_color_provider() { return ash_color_provider_.get(); }
551 
local_state()552   PrefService* local_state() { return local_state_; }
553 
frame_throttling_controller()554   FrameThrottlingController* frame_throttling_controller() {
555     return frame_throttling_controller_.get();
556   }
557 
558   // Force the shelf to query for it's current visibility state.
559   // TODO(jamescook): Move to Shelf.
560   void UpdateShelfVisibility();
561 
562   // Does the primary display have status area?
563   bool HasPrimaryStatusArea();
564 
565   // Starts the animation that occurs on first login.
566   void DoInitialWorkspaceAnimation();
567 
568   void SetLargeCursorSizeInDip(int large_cursor_size_in_dip);
569 
570   // Sets a custom color for the cursor.
571   void SetCursorColor(SkColor cursor_color);
572 
573   // Updates cursor compositing on/off. Native cursor is disabled when cursor
574   // compositing is enabled, and vice versa.
575   void UpdateCursorCompositingEnabled();
576 
577   // Force setting compositing on/off without checking dependency.
578   void SetCursorCompositingEnabled(bool enabled);
579 
580   // Shows the context menu for the wallpaper or shelf at |location_in_screen|.
581   void ShowContextMenu(const gfx::Point& location_in_screen,
582                        ui::MenuSourceType source_type);
583 
584   void AddShellObserver(ShellObserver* observer);
585   void RemoveShellObserver(ShellObserver* observer);
586 
587   // Called when the login status changes.
588   // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
589   void UpdateAfterLoginStatusChange(LoginStatus status);
590 
591   // Notifies observers that fullscreen mode has changed for |container|.
592   // |container| is always the active desk container.
593   void NotifyFullscreenStateChanged(bool is_fullscreen,
594                                     aura::Window* container);
595 
596   // Notifies observers that |pinned_window| changed its pinned window state.
597   void NotifyPinnedStateChanged(aura::Window* pinned_window);
598 
599   // Notifies observers that |root_window|'s user work area insets have changed.
600   // This notification is not fired when shelf bounds changed.
601   void NotifyUserWorkAreaInsetsChanged(aura::Window* root_window);
602 
603   // Notifies observers that |root_window|'s shelf changed alignment.
604   // TODO(jamescook): Move to Shelf.
605   void NotifyShelfAlignmentChanged(aura::Window* root_window,
606                                    ShelfAlignment old_alignment);
607 
608   // Notifies observers that |root_window|'s shelf changed auto-hide behavior.
609   // TODO(jamescook): Move to Shelf.
610   void NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window);
611 
612  private:
613   FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
614   FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
615   FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
616   friend class AcceleratorControllerTest;
617   friend class AshTestHelper;
618   friend class RootWindowController;
619   friend class ScopedRootWindowForNewWindows;
620   friend class ShellTestApi;
621   friend class SmsObserverTest;
622 
623   explicit Shell(std::unique_ptr<ShellDelegate> shell_delegate);
624   ~Shell() override;
625 
626   void Init(ui::ContextFactory* context_factory,
627             PrefService* local_state,
628             std::unique_ptr<keyboard::KeyboardUIFactory> keyboard_ui_factory,
629             scoped_refptr<dbus::Bus> dbus_bus);
630 
631   // Initializes the display manager and related components.
632   void InitializeDisplayManager();
633 
634   // Initializes the root window so that it can host browser windows.
635   void InitRootWindow(aura::Window* root_window);
636 
637   // Destroys all child windows including widgets across all roots.
638   void CloseAllRootWindowChildWindows();
639 
640   // SystemModalContainerEventFilterDelegate:
641   bool CanWindowReceiveEvents(aura::Window* window) override;
642 
643   // Overridden from ui::EventTarget:
644   bool CanAcceptEvent(const ui::Event& event) override;
645   EventTarget* GetParentTarget() override;
646   std::unique_ptr<ui::EventTargetIterator> GetChildIterator() const override;
647   ui::EventTargeter* GetEventTargeter() override;
648 
649   // wm::ActivationChangeObserver:
650   void OnWindowActivated(ActivationReason reason,
651                          aura::Window* gained_active,
652                          aura::Window* lost_active) override;
653 
654   // SessionObserver:
655   void OnFirstSessionStarted() override;
656   void OnSessionStateChanged(session_manager::SessionState state) override;
657   void OnLoginStatusChanged(LoginStatus login_status) override;
658   void OnLockStateChanged(bool locked) override;
659 
660   static Shell* instance_;
661 
662   // The CompoundEventFilter owned by aura::Env object.
663   std::unique_ptr<::wm::CompoundEventFilter> env_filter_;
664 
665   std::unique_ptr<EventRewriterControllerImpl> event_rewriter_controller_;
666 
667   std::unique_ptr<UserMetricsRecorder> user_metrics_recorder_;
668   std::unique_ptr<WindowPositioner> window_positioner_;
669 
670   std::unique_ptr<AcceleratorControllerImpl> accelerator_controller_;
671   std::unique_ptr<AccessibilityControllerImpl> accessibility_controller_;
672   std::unique_ptr<AccessibilityDelegate> accessibility_delegate_;
673   std::unique_ptr<AccessibilityFocusRingControllerImpl>
674       accessibility_focus_ring_controller_;
675   std::unique_ptr<AmbientController> ambient_controller_;
676   std::unique_ptr<AppListControllerImpl> app_list_controller_;
677   // May be null in tests or when running on linux-chromeos.
678   scoped_refptr<dbus::Bus> dbus_bus_;
679   std::unique_ptr<AshDBusServices> ash_dbus_services_;
680   std::unique_ptr<AssistantControllerImpl> assistant_controller_;
681   std::unique_ptr<BacklightsForcedOffSetter> backlights_forced_off_setter_;
682   std::unique_ptr<BloomUiControllerImpl> bloom_ui_controller_;
683   std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate_;
684   std::unique_ptr<CrosDisplayConfig> cros_display_config_;
685   std::unique_ptr<DesksController> desks_controller_;
686   std::unique_ptr<DetachableBaseHandler> detachable_base_handler_;
687   std::unique_ptr<DetachableBaseNotificationController>
688       detachable_base_notification_controller_;
689   std::unique_ptr<DisplayHighlightController> display_highlight_controller_;
690   std::unique_ptr<DisplaySpeakerController> display_speaker_controller_;
691   std::unique_ptr<DragDropController> drag_drop_controller_;
692   std::unique_ptr<FocusCycler> focus_cycler_;
693   std::unique_ptr<HoldingSpaceController> holding_space_controller_;
694   std::unique_ptr<HomeScreenController> home_screen_controller_;
695   std::unique_ptr<ImeControllerImpl> ime_controller_;
696   std::unique_ptr<chromeos::ImmersiveContext> immersive_context_;
697   std::unique_ptr<InSessionAuthDialogControllerImpl>
698       in_session_auth_dialog_controller_;
699   std::unique_ptr<KeyboardBrightnessControlDelegate>
700       keyboard_brightness_control_delegate_;
701   std::unique_ptr<LocaleUpdateControllerImpl> locale_update_controller_;
702   std::unique_ptr<LoginScreenController> login_screen_controller_;
703   std::unique_ptr<LogoutConfirmationController> logout_confirmation_controller_;
704   std::unique_ptr<TabletModeController> tablet_mode_controller_;
705   std::unique_ptr<MediaControllerImpl> media_controller_;
706   std::unique_ptr<MediaNotificationControllerImpl>
707       media_notification_controller_;
708   std::unique_ptr<MruWindowTracker> mru_window_tracker_;
709   std::unique_ptr<MultiDeviceNotificationPresenter>
710       multidevice_notification_presenter_;
711   std::unique_ptr<NearbyShareControllerImpl> nearby_share_controller_;
712   std::unique_ptr<NearbyShareDelegate> nearby_share_delegate_;
713   std::unique_ptr<ParentAccessController> parent_access_controller_;
714   std::unique_ptr<QuickAnswersController> quick_answers_controller_;
715   std::unique_ptr<ResizeShadowController> resize_shadow_controller_;
716   std::unique_ptr<SessionControllerImpl> session_controller_;
717   std::unique_ptr<AshColorProvider> ash_color_provider_;
718   std::unique_ptr<NightLightControllerImpl> night_light_controller_;
719   std::unique_ptr<PrivacyScreenController> privacy_screen_controller_;
720   std::unique_ptr<PolicyRecommendationRestorer> policy_recommendation_restorer_;
721   std::unique_ptr<ScreenSwitchCheckController> screen_switch_check_controller_;
722   std::unique_ptr<ShelfConfig> shelf_config_;
723   std::unique_ptr<ShelfController> shelf_controller_;
724   std::unique_ptr<ShelfWindowWatcher> shelf_window_watcher_;
725   std::unique_ptr<ShellDelegate> shell_delegate_;
726   std::unique_ptr<CaptureModeController> capture_mode_controller_;
727   std::unique_ptr<ShutdownControllerImpl> shutdown_controller_;
728   std::unique_ptr<SystemNotificationController> system_notification_controller_;
729   std::unique_ptr<SystemTrayModel> system_tray_model_;
730   std::unique_ptr<SystemTrayNotifier> system_tray_notifier_;
731   std::unique_ptr<ToastManagerImpl> toast_manager_;
732   std::unique_ptr<ClipboardHistoryControllerImpl> clipboard_history_controller_;
733   std::unique_ptr<TouchDevicesController> touch_devices_controller_;
734   std::unique_ptr<TrayAction> tray_action_;
735   std::unique_ptr<WallpaperControllerImpl> wallpaper_controller_;
736   std::unique_ptr<WindowCycleController> window_cycle_controller_;
737   std::unique_ptr<OverviewController> overview_controller_;
738   // Owned by |focus_controller_|.
739   AshFocusRules* focus_rules_ = nullptr;
740   std::unique_ptr<::wm::ShadowController> shadow_controller_;
741   std::unique_ptr<::wm::VisibilityController> visibility_controller_;
742   std::unique_ptr<::wm::WindowModalityController> window_modality_controller_;
743   PrefService* local_state_ = nullptr;
744   std::unique_ptr<views::corewm::TooltipController> tooltip_controller_;
745   std::unique_ptr<PowerButtonController> power_button_controller_;
746   std::unique_ptr<LockStateController> lock_state_controller_;
747   std::unique_ptr<ui::UserActivityDetector> user_activity_detector_;
748   std::unique_ptr<VideoDetector> video_detector_;
749   std::unique_ptr<WindowTreeHostManager> window_tree_host_manager_;
750   std::unique_ptr<PersistentWindowController> persistent_window_controller_;
751   std::unique_ptr<HighContrastController> high_contrast_controller_;
752   std::unique_ptr<MagnificationController> magnification_controller_;
753   std::unique_ptr<AutoclickController> autoclick_controller_;
754   std::unique_ptr<::wm::FocusController> focus_controller_;
755 
756   std::unique_ptr<ScreenshotController> screenshot_controller_;
757 
758   std::unique_ptr<MouseCursorEventFilter> mouse_cursor_filter_;
759   std::unique_ptr<ScreenPositionController> screen_position_controller_;
760   std::unique_ptr<SystemModalContainerEventFilter> modality_filter_;
761   std::unique_ptr<EventClientImpl> event_client_;
762   std::unique_ptr<EventTransformationHandler> event_transformation_handler_;
763 
764   // An event filter that pre-handles key events while the partial
765   // screenshot UI or the keyboard overlay is active.
766   std::unique_ptr<OverlayEventFilter> overlay_filter_;
767 
768   // An event filter which handles swiping back from left side of the window.
769   std::unique_ptr<BackGestureEventHandler> back_gesture_event_handler_;
770 
771   // An event filter which redirects focus when tab is pressed on a RootWindow
772   // with no active windows.
773   std::unique_ptr<ui::EventHandler> shell_tab_handler_;
774 
775   // An event filter which handles moving and resizing windows.
776   std::unique_ptr<ToplevelWindowEventHandler> toplevel_window_event_handler_;
777 
778   // An event filter which handles system level gestures
779   std::unique_ptr<SystemGestureEventFilter> system_gesture_filter_;
780 
781   // An event filter that pre-handles global accelerators.
782   std::unique_ptr<::wm::AcceleratorFilter> accelerator_filter_;
783 
784   std::unique_ptr<display::DisplayManager> display_manager_;
785   std::unique_ptr<DisplayPrefs> display_prefs_;
786   std::unique_ptr<DisplayConfigurationController>
787       display_configuration_controller_;
788   std::unique_ptr<DisplayConfigurationObserver> display_configuration_observer_;
789 
790   std::unique_ptr<ScreenPinningController> screen_pinning_controller_;
791 
792   std::unique_ptr<PeripheralBatteryNotifier> peripheral_battery_notifier_;
793   std::unique_ptr<PeripheralBatteryTracker> peripheral_battery_tracker_;
794   std::unique_ptr<PowerEventObserver> power_event_observer_;
795   std::unique_ptr<PowerPrefs> power_prefs_;
796   std::unique_ptr<ui::UserActivityPowerManagerNotifier> user_activity_notifier_;
797   std::unique_ptr<VideoActivityNotifier> video_activity_notifier_;
798   std::unique_ptr<StickyKeysController> sticky_keys_controller_;
799   std::unique_ptr<ResolutionNotificationController>
800       resolution_notification_controller_;
801   std::unique_ptr<BluetoothNotificationController>
802       bluetooth_notification_controller_;
803   std::unique_ptr<BluetoothPowerController> bluetooth_power_controller_;
804   std::unique_ptr<TrayBluetoothHelper> tray_bluetooth_helper_;
805   std::unique_ptr<KeyboardControllerImpl> keyboard_controller_;
806   std::unique_ptr<DisplayAlignmentController> display_alignment_controller_;
807   std::unique_ptr<DisplayColorManager> display_color_manager_;
808   std::unique_ptr<DisplayErrorObserver> display_error_observer_;
809   std::unique_ptr<ProjectingObserver> projecting_observer_;
810 
811   // Listens for output changes and updates the display manager.
812   std::unique_ptr<display::DisplayChangeObserver> display_change_observer_;
813 
814   // Listens for shutdown and updates DisplayConfigurator.
815   std::unique_ptr<DisplayShutdownObserver> display_shutdown_observer_;
816 
817   // Listens for new sms messages and shows notifications.
818   std::unique_ptr<SmsObserver> sms_observer_;
819 
820   // Implements content::ScreenOrientationController for Chrome OS.
821   std::unique_ptr<ScreenOrientationController> screen_orientation_controller_;
822   std::unique_ptr<ScreenLayoutObserver> screen_layout_observer_;
823 
824   std::unique_ptr<AshTouchTransformController> touch_transformer_controller_;
825 
826   std::unique_ptr<ui::EventHandler> magnifier_key_scroll_handler_;
827   std::unique_ptr<ui::EventHandler> speech_feedback_handler_;
828   std::unique_ptr<LaserPointerController> laser_pointer_controller_;
829   std::unique_ptr<PartialMagnificationController>
830       partial_magnification_controller_;
831   std::unique_ptr<HighlighterController> highlighter_controller_;
832 
833   std::unique_ptr<DockedMagnifierControllerImpl> docked_magnifier_controller_;
834 
835   std::unique_ptr<chromeos::SnapController> snap_controller_;
836 
837   // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
838   // pointer to vend to test code.
839   NativeCursorManagerAsh* native_cursor_manager_;
840 
841   // Cursor may be hidden on certain key events in Chrome OS, whereas we never
842   // hide the cursor on Windows.
843   std::unique_ptr<::wm::CursorManager> cursor_manager_;
844 
845   // Enables spoken feedback accessibility based on a press and hold of both
846   // volume keys.
847   std::unique_ptr<KeyAccessibilityEnabler> key_accessibility_enabler_;
848 
849   std::unique_ptr<FrameThrottlingController> frame_throttling_controller_;
850 
851   // For testing only: simulate that a modal window is open
852   bool simulate_modal_window_open_for_test_ = false;
853 
854   std::unique_ptr<MessageCenterController> message_center_controller_;
855 
856   base::ObserverList<ShellObserver>::Unchecked shell_observers_;
857 
858   base::WeakPtrFactory<Shell> weak_factory_{this};
859 
860   DISALLOW_COPY_AND_ASSIGN(Shell);
861 };
862 
863 }  // namespace ash
864 
865 #endif  // ASH_SHELL_H_
866