shell.h 37 KB

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