shelf_layout_manager.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. // Copyright 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_SHELF_SHELF_LAYOUT_MANAGER_H_
  5. #define ASH_SHELF_SHELF_LAYOUT_MANAGER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/cpp/app_list/app_list_controller_observer.h"
  9. #include "ash/public/cpp/session/session_observer.h"
  10. #include "ash/public/cpp/shelf_config.h"
  11. #include "ash/public/cpp/shelf_types.h"
  12. #include "ash/public/cpp/wallpaper/wallpaper_controller.h"
  13. #include "ash/public/cpp/wallpaper/wallpaper_controller_observer.h"
  14. #include "ash/shelf/drag_window_from_shelf_controller.h"
  15. #include "ash/shelf/shelf.h"
  16. #include "ash/shelf/shelf_metrics.h"
  17. #include "ash/shelf/shelf_observer.h"
  18. #include "ash/shelf/shelf_widget.h"
  19. #include "ash/shell_observer.h"
  20. #include "ash/system/locale/locale_update_controller_impl.h"
  21. #include "ash/wm/desks/desks_controller.h"
  22. #include "ash/wm/lock_state_observer.h"
  23. #include "ash/wm/overview/overview_observer.h"
  24. #include "ash/wm/splitview/split_view_controller.h"
  25. #include "ash/wm/splitview/split_view_observer.h"
  26. #include "ash/wm/wm_default_layout_manager.h"
  27. #include "ash/wm/workspace/workspace_types.h"
  28. #include "base/memory/weak_ptr.h"
  29. #include "base/observer_list.h"
  30. #include "base/scoped_observation.h"
  31. #include "base/strings/string_number_conversions.h"
  32. #include "base/timer/timer.h"
  33. #include "third_party/abseil-cpp/absl/types/optional.h"
  34. #include "ui/compositor/layer_animation_observer.h"
  35. #include "ui/display/display.h"
  36. #include "ui/display/display_observer.h"
  37. #include "ui/gfx/geometry/insets.h"
  38. #include "ui/gfx/geometry/rect.h"
  39. #include "ui/wm/public/activation_change_observer.h"
  40. namespace ui {
  41. class EventHandler;
  42. class LocatedEvent;
  43. class MouseEvent;
  44. class MouseWheelEvent;
  45. class PresentationTimeRecorder;
  46. } // namespace ui
  47. namespace ash {
  48. enum class AnimationChangeType;
  49. class DragWindowFromShelfController;
  50. class HomeToOverviewNudgeController;
  51. class InAppToHomeNudgeController;
  52. class PanelLayoutManagerTest;
  53. class ScopedDragDropObserver;
  54. class Shelf;
  55. class ShelfLayoutManagerObserver;
  56. class ShelfLayoutManagerTestBase;
  57. class ShelfWidget;
  58. class SwipeHomeToOverviewController;
  59. // ShelfLayoutManager is the layout manager responsible for the shelf and
  60. // status widgets. The shelf is given the total available width and told the
  61. // width of the status area. This allows the shelf to draw the background and
  62. // layout to the status area.
  63. // To respond to bounds changes in the status area StatusAreaLayoutManager works
  64. // closely with ShelfLayoutManager.
  65. class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
  66. public ShelfObserver,
  67. public ShellObserver,
  68. public SplitViewObserver,
  69. public OverviewObserver,
  70. public ::wm::ActivationChangeObserver,
  71. public LockStateObserver,
  72. public WmDefaultLayoutManager,
  73. public display::DisplayObserver,
  74. public SessionObserver,
  75. public WallpaperControllerObserver,
  76. public LocaleChangeObserver,
  77. public DesksController::Observer,
  78. public ShelfConfig::Observer {
  79. public:
  80. // See `drag_status_`. Visible for testing.
  81. enum DragStatus {
  82. kDragNone,
  83. kDragAttempt,
  84. kDragInProgress,
  85. kDragCancelInProgress,
  86. kDragCompleteInProgress,
  87. kDragAppListInProgress,
  88. kDragHomeToOverviewInProgress,
  89. };
  90. // Suspend work area updates within its scope. Note that relevant
  91. // ShelfLayoutManager must outlive this class.
  92. class ScopedSuspendWorkAreaUpdate {
  93. public:
  94. // |manager| is the ShelfLayoutManager whose visibility update is suspended.
  95. explicit ScopedSuspendWorkAreaUpdate(ShelfLayoutManager* manager);
  96. ScopedSuspendWorkAreaUpdate(const ScopedSuspendWorkAreaUpdate&) = delete;
  97. ScopedSuspendWorkAreaUpdate& operator=(const ScopedSuspendWorkAreaUpdate&) =
  98. delete;
  99. ~ScopedSuspendWorkAreaUpdate();
  100. private:
  101. ShelfLayoutManager* const manager_;
  102. };
  103. // Used to maintain a lock for the shelf visibility state. If locked, then we
  104. // should not update the state of the shelf visibility.
  105. class ScopedVisibilityLock {
  106. public:
  107. explicit ScopedVisibilityLock(ShelfLayoutManager* shelf);
  108. ~ScopedVisibilityLock();
  109. private:
  110. base::WeakPtr<ShelfLayoutManager> shelf_;
  111. };
  112. ShelfLayoutManager(ShelfWidget* shelf_widget, Shelf* shelf);
  113. ShelfLayoutManager(const ShelfLayoutManager&) = delete;
  114. ShelfLayoutManager& operator=(const ShelfLayoutManager&) = delete;
  115. ~ShelfLayoutManager() override;
  116. // Initializes observers.
  117. void InitObservers();
  118. // Clears internal data for shutdown process.
  119. void PrepareForShutdown();
  120. // Returns whether the shelf and its contents (shelf, status) are visible
  121. // on the screen.
  122. bool IsVisible() const;
  123. // Returns the ideal bounds of the shelf assuming it is visible.
  124. gfx::Rect GetIdealBounds() const;
  125. // Returns the ideal bounds of the shelf, but always returns in-app shelf
  126. // bounds in tablet mode.
  127. gfx::Rect GetIdealBoundsForWorkAreaCalculation() const;
  128. // Sets the bounds of the shelf and status widgets.
  129. void LayoutShelf(bool animate = false);
  130. // Updates the visibility state.
  131. void UpdateVisibilityState();
  132. // Shows the shelf and hotseat for the back gesture.
  133. void UpdateVisibilityStateForBackGesture();
  134. // Invoked by the shelf when the auto-hide state may have changed.
  135. void UpdateAutoHideState();
  136. // Updates the auto-hide state for mouse events.
  137. void UpdateAutoHideForMouseEvent(ui::MouseEvent* event, aura::Window* target);
  138. // Shows or hides contextual nudges for shelf gestures, depending on the shelf
  139. // state.
  140. void UpdateContextualNudges();
  141. // Hides any visible contextual nudge for shelf gestures.
  142. void HideContextualNudges();
  143. // Called by AutoHideEventHandler to process the gesture events when shelf is
  144. // auto hidden.
  145. void ProcessGestureEventOfAutoHideShelf(ui::GestureEvent* event,
  146. aura::Window* target);
  147. // Handles events that are detected while the hotseat is kExtended in in-app
  148. // shelf.
  149. void ProcessGestureEventOfInAppHotseat(ui::GestureEvent* event,
  150. aura::Window* target);
  151. // Updates the auto-dim state. Returns true if successful.
  152. bool SetDimmed(bool dimmed);
  153. void AddObserver(ShelfLayoutManagerObserver* observer);
  154. void RemoveObserver(ShelfLayoutManagerObserver* observer);
  155. // Processes a gesture event and updates the status of the shelf when
  156. // appropriate. Returns true if the gesture has been handled and it should not
  157. // be processed any further, false otherwise.
  158. bool ProcessGestureEvent(const ui::GestureEvent& event_in_screen);
  159. // Handles mouse events from the shelf.
  160. void ProcessMouseEventFromShelf(const ui::MouseEvent& event_in_screen);
  161. // Handles events from ShelfWidget.
  162. void ProcessGestureEventFromShelfWidget(ui::GestureEvent* event_in_screen);
  163. // Handles mouse wheel events from the shelf.
  164. void ProcessMouseWheelEventFromShelf(ui::MouseWheelEvent* event);
  165. // Handles scroll events from the shelf.
  166. void ProcessScrollEventFromShelf(ui::ScrollEvent* event);
  167. // Contains logic that is the same between mouse wheel and gesture scrolling.
  168. void ProcessScrollOffset(int offset, base::TimeTicks time_stamp);
  169. // Returns how the shelf background should be painted.
  170. ShelfBackgroundType GetShelfBackgroundType() const;
  171. // Updates the background of the shelf if it has changed.
  172. void MaybeUpdateShelfBackground(AnimationChangeType change_type);
  173. // Returns whether the shelf should show a blurred background. This may
  174. // return false even if background blur is enabled depending on the session
  175. // state.
  176. bool ShouldBlurShelfBackground();
  177. // Returns true if at least one window is visible.
  178. bool HasVisibleWindow() const;
  179. // Cancel the drag if the shelf is in drag progress.
  180. void CancelDragOnShelfIfInProgress();
  181. // Suspends shelf visibility updates, to be used during shutdown. Since there
  182. // is no balanced "resume" public API, the suspension will be indefinite.
  183. void SuspendVisibilityUpdateForShutdown();
  184. // Called when ShelfItems are interacted with in the shelf.
  185. void OnShelfItemSelected(ShelfAction action);
  186. // WmDefaultLayoutManager:
  187. void OnWindowResized() override;
  188. void SetChildBounds(aura::Window* child,
  189. const gfx::Rect& requested_bounds) override;
  190. // ShelfObserver:
  191. void OnShelfAutoHideBehaviorChanged() override;
  192. // ShellObserver:
  193. void OnShelfAlignmentChanged(aura::Window* root_window,
  194. ShelfAlignment old_alignment) override;
  195. void OnUserWorkAreaInsetsChanged(aura::Window* root_window) override;
  196. void OnPinnedStateChanged(aura::Window* pinned_window) override;
  197. void OnShellDestroying() override;
  198. // SplitViewObserver:
  199. void OnSplitViewStateChanged(SplitViewController::State previous_state,
  200. SplitViewController::State state) override;
  201. // OverviewObserver:
  202. void OnOverviewModeWillStart() override;
  203. void OnOverviewModeStarting() override;
  204. void OnOverviewModeStartingAnimationComplete(bool canceled) override;
  205. void OnOverviewModeEnding(OverviewSession* overview_session) override;
  206. void OnOverviewModeEndingAnimationComplete(bool canceled) override;
  207. void OnOverviewModeEnded() override;
  208. // AppListControllerObserver:
  209. void OnAppListVisibilityWillChange(bool shown, int64_t display_id) override;
  210. void OnAppListVisibilityChanged(bool shown, int64_t display_id) override;
  211. // wm::ActivationChangeObserver:
  212. void OnWindowActivated(ActivationReason reason,
  213. aura::Window* gained_active,
  214. aura::Window* lost_active) override;
  215. // LockStateObserver:
  216. void OnLockStateEvent(LockStateObserver::EventType event) override;
  217. // SessionObserver:
  218. void OnSessionStateChanged(session_manager::SessionState state) override;
  219. void OnLoginStatusChanged(LoginStatus loing_status) override;
  220. // WallpaperControllerObserver:
  221. void OnWallpaperBlurChanged() override;
  222. void OnFirstWallpaperShown() override;
  223. // DisplayObserver:
  224. void OnDisplayMetricsChanged(const display::Display& display,
  225. uint32_t changed_metrics) override;
  226. // LocaleChangeObserver:
  227. void OnLocaleChanged() override;
  228. // DesksController::Observer:
  229. void OnDeskAdded(const Desk* desk) override {}
  230. void OnDeskRemoved(const Desk* desk) override {}
  231. void OnDeskReordered(int old_index, int new_index) override {}
  232. void OnDeskActivationChanged(const Desk* activated,
  233. const Desk* deactivated) override {}
  234. void OnDeskSwitchAnimationLaunching() override;
  235. void OnDeskSwitchAnimationFinished() override;
  236. void OnDeskNameChanged(const Desk* desk,
  237. const std::u16string& new_name) override {}
  238. ShelfVisibilityState visibility_state() const {
  239. return state_.visibility_state;
  240. }
  241. bool is_active_session_state() const { return state_.IsActiveSessionState(); }
  242. bool is_shelf_auto_hidden() const { return state_.IsShelfAutoHidden(); }
  243. // Locks or unlocks the state of shelf auto-hide. On unlock, the auto-hide
  244. // state will be recomputed.
  245. void LockAutoHideState(bool lock_auto_hide_state);
  246. ShelfAutoHideBehavior auto_hide_behavior() const {
  247. return shelf_->auto_hide_behavior();
  248. }
  249. // ShelfConfig::Observer:
  250. void OnShelfConfigUpdated() override;
  251. float GetOpacity() const;
  252. bool updating_bounds() const { return phase_ == ShelfLayoutPhase::kMoving; }
  253. ShelfAutoHideState auto_hide_state() const { return state_.auto_hide_state; }
  254. HotseatState hotseat_state() const {
  255. return shelf_widget_->hotseat_widget()->state();
  256. }
  257. DragWindowFromShelfController* window_drag_controller_for_testing() {
  258. return window_drag_controller_.get();
  259. }
  260. SwipeHomeToOverviewController*
  261. swipe_home_to_overview_controller_for_testing() {
  262. return swipe_home_to_overview_controller_.get();
  263. }
  264. HomeToOverviewNudgeController*
  265. home_to_overview_nudge_controller_for_testing() {
  266. return home_to_overview_nudge_controller_.get();
  267. }
  268. DragStatus drag_status_for_test() const { return drag_status_; }
  269. bool IsDraggingApplist() const {
  270. return drag_status_ == kDragAppListInProgress;
  271. }
  272. // Gets the target HotseatState based on the current state of HomeLauncher,
  273. // Overview, Shelf, and any active gestures.
  274. // TODO(manucornet): Move this to the hotseat class.
  275. HotseatState CalculateHotseatState(ShelfVisibilityState visibility_state,
  276. ShelfAutoHideState auto_hide_state) const;
  277. // Called when the visibility for a tray bubble in the shelf's status area
  278. // changes.
  279. void OnShelfTrayBubbleVisibilityChanged(bool bubble_shown);
  280. void UpdateWorkAreaInsetsAndNotifyObservers(
  281. const gfx::Rect& shelf_bounds_for_workarea_calculation,
  282. const gfx::Insets& shelf_insets,
  283. const gfx::Insets& in_session_shelf_insets);
  284. private:
  285. void UpdateWorkAreaInsetsAndNotifyObserversInternal(
  286. const gfx::Rect& shelf_bounds_for_workarea_calculation,
  287. const gfx::Insets& shelf_insets,
  288. const gfx::Insets& in_session_shelf_insets);
  289. class UpdateShelfObserver;
  290. friend class DimShelfLayoutManagerTestBase;
  291. friend class PanelLayoutManagerTest;
  292. friend class ShelfLayoutManagerTestBase;
  293. friend class ShelfLayoutManagerWindowDraggingTest;
  294. friend class NotificationTrayTest;
  295. friend class UnifiedSystemTrayTest;
  296. friend class TrayBackgroundViewTest;
  297. friend class Shelf;
  298. struct State {
  299. State();
  300. // Returns true when a secondary user is being added to an existing session.
  301. bool IsAddingSecondaryUser() const;
  302. bool IsScreenLocked() const;
  303. // Returns whether the session is in an active state.
  304. bool IsActiveSessionState() const;
  305. // Returns whether shelf is in auto-hide mode and is currently hidden.
  306. bool IsShelfAutoHidden() const;
  307. // Returns whether shelf is currently visible.
  308. bool IsShelfVisible() const;
  309. // Returns whether shelf is in auto-hide mode in session and suupposed to be
  310. // hidden.
  311. bool IsShelfAutoHiddenInSession() const;
  312. // Returns true if the two states are considered equal. As
  313. // |auto_hide_state| only matters if |visibility_state| is
  314. // |SHELF_AUTO_HIDE|, Equals() ignores the |auto_hide_state| as
  315. // appropriate.
  316. bool Equals(const State& other) const;
  317. ShelfVisibilityState visibility_state = SHELF_VISIBLE;
  318. ShelfAutoHideState auto_hide_state = SHELF_AUTO_HIDE_HIDDEN;
  319. WorkspaceWindowState window_state = WorkspaceWindowState::kDefault;
  320. // In session state.
  321. ShelfVisibilityState in_session_visibility_state = SHELF_VISIBLE;
  322. ShelfAutoHideState in_session_auto_hide_state = SHELF_AUTO_HIDE_HIDDEN;
  323. // True when the system is in the cancelable, pre-lock screen animation.
  324. bool pre_lock_screen_animation_active = false;
  325. session_manager::SessionState session_state =
  326. session_manager::SessionState::UNKNOWN;
  327. };
  328. // An enumration describing the various phases in which the shelf can be when
  329. // managing the bounds and opacity of its components.
  330. enum class ShelfLayoutPhase {
  331. kAtRest, // No activity
  332. kAiming, // Calculating target bounds
  333. kMoving, // Laying out and animating to target bounds
  334. };
  335. // Suspends/resumes work area updates.
  336. void SuspendWorkAreaUpdate();
  337. void ResumeWorkAreaUpdate();
  338. // Sets the visibility of the shelf to |state|.
  339. void SetState(ShelfVisibilityState visibility_state);
  340. // Returns shelf visibility state based on current value of auto-hide
  341. // behavior setting.
  342. ShelfVisibilityState CalculateShelfVisibility();
  343. // Updates the shelf dim state.
  344. void UpdateShelfIconOpacity();
  345. // Updates the bounds and opacity of the shelf and status widgets.
  346. void UpdateBoundsAndOpacity(bool animate);
  347. // Returns true if a maximized or fullscreen window is being dragged from the
  348. // top of the display or from the caption area. Note currently for this case
  349. // it's only allowed in tablet mode, not in laptop mode.
  350. bool IsDraggingWindowFromTopOrCaptionArea() const;
  351. // Calculates shelf target bounds assuming visibility of
  352. // |state.visibilty_state| and |hotseat_target_state|. Returns the desired
  353. // shelf insets.
  354. gfx::Insets UpdateTargetBoundsAndCalculateShelfInsets(
  355. const State& state,
  356. HotseatState hotseat_target_state);
  357. // Calculates the target bounds using |state_| and updates the
  358. // |user_work_area_bounds_|.
  359. void CalculateTargetBoundsAndUpdateWorkArea();
  360. // Updates the target bounds if a gesture-drag is in progress. This is only
  361. // used by |CalculateTargetBounds()|.
  362. void UpdateTargetBoundsForGesture(HotseatState target_hotseat_state);
  363. // Updates the auto-hide state for drag-drop actions.
  364. void UpdateAutoHideForDragDrop(const ui::DropTargetEvent* event);
  365. // Updates the auto-hide state immediately.
  366. void UpdateAutoHideStateNow();
  367. // Starts the auto-hide timer, so that the shelf will be hidden after the
  368. // timeout (unless something else happens to interrupt / reset it).
  369. void StartAutoHideTimer();
  370. // Stops the auto-hide timer and clears
  371. // |mouse_over_shelf_when_auto_hide_timer_started_|.
  372. void StopAutoHideTimer();
  373. // Returns the bounds of an additional region which can trigger showing the
  374. // shelf. This region exists to make it easier to trigger showing the shelf
  375. // when the shelf is auto hidden and the shelf is on the boundary between
  376. // two displays.
  377. gfx::Rect GetAutoHideShowShelfRegionInScreen() const;
  378. // Returns the auto-hide state. This value is determined from the shelf and
  379. // tray.
  380. ShelfAutoHideState CalculateAutoHideState(
  381. ShelfVisibilityState visibility_state) const;
  382. // Returns the auto-hide state based on the position of an ongoing drag-drop.
  383. ShelfAutoHideState CalculateAutoHideStateBasedOnDragLocation() const;
  384. // Returns the auto-hide state if the cursor's current position can be used to
  385. // make a decision, or no value if its position gives no useful information.
  386. absl::optional<ShelfAutoHideState>
  387. CalculateAutoHideStateBasedOnCursorLocation() const;
  388. // Returns true if |window| is a descendant of the shelf.
  389. bool IsShelfWindow(aura::Window* window);
  390. // Returns true if |window| is a descendant of the status area.
  391. bool IsStatusAreaWindow(aura::Window* window);
  392. // Called when the LoginUI changes from visible to invisible.
  393. void UpdateShelfVisibilityAfterLoginUIChange();
  394. // Compute |target_bounds| opacity based on gesture and shelf visibility.
  395. float ComputeTargetOpacity(const State& state) const;
  396. // Returns true if there is a fullscreen window open that causes the shelf
  397. // to be hidden.
  398. bool IsShelfHiddenForFullscreen() const;
  399. // Returns true if there is a fullscreen or maximized window open that causes
  400. // the shelf to be auto hidden.
  401. bool IsShelfAutoHideForFullscreenMaximized() const;
  402. // Returns whether the active window for the shelf is a defined stylus app
  403. // in `kStylusAppIds`.
  404. bool IsActiveWindowStylusApp() const;
  405. // Returns true if the home gesture handler should handle the event.
  406. bool ShouldHomeGestureHandleEvent(float scroll_y) const;
  407. // Gesture drag related functions:
  408. bool StartGestureDrag(const ui::GestureEvent& gesture_in_screen);
  409. void UpdateGestureDrag(const ui::GestureEvent& gesture_in_screen);
  410. // Mouse drag related functions:
  411. void AttemptToDragByMouse(const ui::MouseEvent& mouse_in_screen);
  412. void StartMouseDrag(const ui::MouseEvent& mouse_in_screen);
  413. void UpdateMouseDrag(const ui::MouseEvent& mouse_in_screen);
  414. void ReleaseMouseDrag(const ui::MouseEvent& mouse_in_screen);
  415. // Drag related functions, utilized by both gesture drag and mouse drag:
  416. bool IsDragAllowed() const;
  417. bool StartAppListDrag(const ui::LocatedEvent& event_in_screen,
  418. float scroll_y_hint);
  419. bool StartShelfDrag(const ui::LocatedEvent& event_in_screen,
  420. const gfx::Vector2dF& scroll_hint);
  421. // Sets the Hotseat up to be dragged, if applicable.
  422. void MaybeSetupHotseatDrag(const ui::LocatedEvent& event_in_screen);
  423. void UpdateDrag(const ui::LocatedEvent& event_in_screen,
  424. float scroll_x,
  425. float scroll_y);
  426. void CompleteDrag(const ui::LocatedEvent& event_in_screen);
  427. void CompleteAppListDrag(const ui::LocatedEvent& event_in_screen);
  428. void CompleteDragHomeToOverview(const ui::LocatedEvent& event_in_screen);
  429. void CancelDrag(absl::optional<ShelfWindowDragResult> window_drag_result);
  430. void CompleteDragWithChangedVisibility();
  431. float GetAppListBackgroundOpacityOnShelfOpacity();
  432. // Returns true if the gesture is swiping up on a hidden shelf or swiping down
  433. // on a visible shelf; other gestures should not change shelf visibility.
  434. bool IsSwipingCorrectDirection();
  435. // Returns true if should change the visibility of the shelf after drag.
  436. bool ShouldChangeVisibilityAfterDrag(
  437. const ui::LocatedEvent& gesture_in_screen);
  438. // Updates the mask to limit the content to the non lock screen container.
  439. // The mask will be removed if the workspace state is either in fullscreen
  440. // or maximized.
  441. void UpdateWorkspaceMask(WorkspaceWindowState window_state);
  442. // Sends a11y alert for entering/exiting
  443. // WorkspaceWindowState::kFullscreen workspace state.
  444. void SendA11yAlertForFullscreenWorkspaceState(
  445. WorkspaceWindowState current_workspace_window_state);
  446. // Maybe start/update/end the window drag when swiping up from the shelf.
  447. bool MaybeStartDragWindowFromShelf(const ui::LocatedEvent& event_in_screen,
  448. const gfx::Vector2dF& scroll);
  449. void MaybeUpdateWindowDrag(const ui::LocatedEvent& event_in_screen,
  450. const gfx::Vector2dF& scroll);
  451. absl::optional<ShelfWindowDragResult> MaybeEndWindowDrag(
  452. const ui::LocatedEvent& event_in_screen);
  453. // If overview session is active, goes to home screen if the gesture should
  454. // initiate transition to home. It handles the gesture only if the
  455. // |window_drag_controller_| is not handling a window drag (for example, in
  456. // split view mode).
  457. bool MaybeEndDragFromOverviewToHome(const ui::LocatedEvent& event_in_screen);
  458. void MaybeCancelWindowDrag();
  459. bool IsWindowDragInProgress() const;
  460. // Updates the visibility state because of the change on a status area tray.
  461. void UpdateVisibilityStateForTrayBubbleChange(bool bubble_shown);
  462. bool IsShelfContainerAnimating() const;
  463. bool in_shutdown_ = false;
  464. // True if the last mouse event was a mouse drag.
  465. bool in_mouse_drag_ = false;
  466. // True if a mouse or gesture drag is in progress.
  467. bool in_drag_drop_ = false;
  468. // Current state.
  469. State state_;
  470. ShelfLayoutPhase phase_ = ShelfLayoutPhase::kAtRest;
  471. float target_opacity_ = 0.0f;
  472. ShelfWidget* const shelf_widget_;
  473. Shelf* const shelf_;
  474. // Count of pending visibility update suspensions. Skip updating the shelf
  475. // visibility state if it is greater than 0.
  476. int suspend_visibility_update_ = 0;
  477. // Count of pending work area update suspensions. Skip updating the work
  478. // area if it is greater than 0.
  479. int suspend_work_area_update_ = 0;
  480. base::OneShotTimer auto_hide_timer_;
  481. // Whether the mouse was over the shelf when the auto-hide timer started.
  482. // False when neither the auto-hide timer nor the timer task are running.
  483. bool mouse_over_shelf_when_auto_hide_timer_started_ = false;
  484. // Whether a drag was over the shelf when the auto-hide timer started.
  485. // False when neither the auto-hide timer nor the timer task are running.
  486. bool drag_over_shelf_when_auto_hide_timer_started_ = false;
  487. // Whether the mouse pointer (not the touch pointer) was over the shelf last
  488. // time we saw it. This is used to differentiate between mouse and touch in
  489. // the shelf auto-hide behavior.
  490. bool last_seen_mouse_position_was_over_shelf_ = false;
  491. // Whether the last location update from a drag-drop was over the shelf.
  492. bool last_seen_drag_position_was_over_shelf_ = false;
  493. base::ObserverList<ShelfLayoutManagerObserver>::Unchecked observers_;
  494. // The enum keeps track of the present status of the drag (from gesture or
  495. // mouse). The shelf reacts to drags, and can be set to auto hide for certain
  496. // events. For example, swiping up from the shelf in tablet mode can open the
  497. // fullscreen app list. Some shelf behaviour (e.g. visibility state,
  498. // background color etc.) are affected by various stages of the drag.
  499. DragStatus drag_status_ = kDragNone;
  500. // Whether the hotseat is being dragged.
  501. bool hotseat_is_in_drag_ = false;
  502. // Whether the EXTENDED hotseat should be hidden. Set when HotseatEventHandler
  503. // detects that the background has been interacted with.
  504. bool should_hide_hotseat_ = false;
  505. // Whether the overview mode is about to start. This becomes false again
  506. // once the overview mode has actually started.
  507. bool overview_mode_will_start_ = false;
  508. // Tracks the amount of the drag. The value is only valid when
  509. // |drag_status_| is set to kDragInProgress.
  510. float drag_amount_ = 0.f;
  511. // The velocity of the last drag event. Used to determine final state of the
  512. // hotseat.
  513. int last_drag_velocity_ = 0;
  514. // Tracks the amount of launcher that above the shelf bottom during dragging.
  515. float launcher_above_shelf_bottom_amount_ = 0.f;
  516. // Manage the auto-hide state during drag.
  517. ShelfAutoHideState drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN;
  518. // Whether background blur is enabled.
  519. const bool is_background_blur_enabled_;
  520. // Whether the feature ProductivityLauncher is enabled.
  521. const bool is_productivity_launcher_enabled_;
  522. // Pretarget handler responsible for hiding the hotseat.
  523. std::unique_ptr<ui::EventHandler> hotseat_event_handler_;
  524. // Stores the previous workspace state. Used by
  525. // SendA11yAlertForFullscreenWorkspaceState to compare with current workspace
  526. // state to determite whether need to send an a11y alert.
  527. WorkspaceWindowState previous_workspace_window_state_ =
  528. WorkspaceWindowState::kDefault;
  529. // The display on which this shelf is shown.
  530. display::Display display_;
  531. // The current shelf background. Should not be assigned to directly, use
  532. // MaybeUpdateShelfBackground() instead.
  533. ShelfBackgroundType shelf_background_type_ = ShelfBackgroundType::kDefaultBg;
  534. // Shelf will become transparent if launcher is opened. Stores the shelf
  535. // background type before open the launcher when start to drag the launcher
  536. // from shelf.
  537. ShelfBackgroundType shelf_background_type_before_drag_ =
  538. ShelfBackgroundType::kDefaultBg;
  539. ScopedSessionObserver scoped_session_observer_{this};
  540. base::ScopedObservation<WallpaperController, WallpaperControllerObserver>
  541. wallpaper_controller_observation_{this};
  542. display::ScopedDisplayObserver display_observer_{this};
  543. // Observer that allows drag events to un-hide an auto-hidden shelf.
  544. std::unique_ptr<ScopedDragDropObserver> drag_drop_observer_;
  545. // Location of the most recent mouse drag event in screen coordinates.
  546. gfx::Point last_mouse_drag_position_in_screen_;
  547. // Location of the most recent drag-drop event in screen coordinates.
  548. gfx::Point last_drag_drop_position_in_screen_;
  549. // Location of the beginning of a drag in screen coordinates.
  550. gfx::Point drag_start_point_in_screen_;
  551. // When it is true, |CalculateAutoHideState| returns the current auto-hide
  552. // state.
  553. bool is_auto_hide_state_locked_ = false;
  554. // An optional ScopedSuspendWorkAreaUpdate that gets created when suspend
  555. // visibility update is requested for overview and resets when overview no
  556. // longer needs it. It is used because OnOverviewModeStarting() and
  557. // OnOverviewModeStartingAnimationComplete() calls are not balanced.
  558. absl::optional<ScopedSuspendWorkAreaUpdate>
  559. overview_suspend_work_area_update_;
  560. // The window drag controller that will be used when a window can be dragged
  561. // up from shelf to homescreen, overview or splitview.
  562. std::unique_ptr<DragWindowFromShelfController> window_drag_controller_;
  563. // The gesture controller that switches from home screen to overview when it
  564. // detects an upward swipe from the home launcher shelf area.
  565. std::unique_ptr<SwipeHomeToOverviewController>
  566. swipe_home_to_overview_controller_;
  567. std::unique_ptr<HomeToOverviewNudgeController>
  568. home_to_overview_nudge_controller_;
  569. // Controller for the visibility of the InAppToHome gesture contextual nudge.
  570. std::unique_ptr<InAppToHomeNudgeController> in_app_to_home_nudge_controller_;
  571. // Whether upward fling from shelf should be handled as potential gesture from
  572. // overview to home. This is set to false when the swipe is handled by
  573. // |window_drag_controller_|, when the swipe is associated with a window
  574. // to drag. Note that the gesture will be handled only when the overview
  575. // session is active.
  576. bool allow_fling_from_overview_to_home_ = true;
  577. // Indicates whether shelf drag gesture can start window drag from shelf to
  578. // overview or home when hotseat is in extended state (the window drag will
  579. // only be allowed if drag started within shelf bounds).
  580. bool allow_window_drag_on_extended_hotseat_ = false;
  581. // Tracks whether the shelf is currently dimmed for inactivity.
  582. bool dimmed_for_inactivity_ = false;
  583. // Tracks whether the shelf and hotseat have been asked to be shown and
  584. // extended by the back gesture.
  585. bool state_forced_by_back_gesture_ = false;
  586. // Callback to update the shelf's state when the visibility of system tray
  587. // changes.
  588. base::CancelableOnceClosure visibility_update_for_tray_callback_;
  589. // Records the presentation time for hotseat dragging.
  590. std::unique_ptr<ui::PresentationTimeRecorder>
  591. hotseat_presentation_time_recorder_;
  592. base::WeakPtrFactory<ShelfLayoutManager> weak_factory_{this};
  593. };
  594. } // namespace ash
  595. #endif // ASH_SHELF_SHELF_LAYOUT_MANAGER_H_