workspace_layout_manager.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_WM_WORKSPACE_WORKSPACE_LAYOUT_MANAGER_H_
  5. #define ASH_WM_WORKSPACE_WORKSPACE_LAYOUT_MANAGER_H_
  6. #include <map>
  7. #include <memory>
  8. #include "ash/ash_export.h"
  9. #include "ash/public/cpp/app_list/app_list_controller_observer.h"
  10. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  11. #include "ash/shelf/shelf_observer.h"
  12. #include "ash/shell_observer.h"
  13. #include "ash/wm/window_state_observer.h"
  14. #include "ui/aura/layout_manager.h"
  15. #include "ui/aura/window_observer.h"
  16. #include "ui/display/display_observer.h"
  17. #include "ui/gfx/geometry/rect.h"
  18. #include "ui/wm/public/activation_change_observer.h"
  19. namespace ash {
  20. class RootWindowController;
  21. class BackdropController;
  22. class WMEvent;
  23. // LayoutManager used on the window created for a workspace.
  24. class ASH_EXPORT WorkspaceLayoutManager : public aura::LayoutManager,
  25. public aura::WindowObserver,
  26. public ::wm::ActivationChangeObserver,
  27. public KeyboardControllerObserver,
  28. public display::DisplayObserver,
  29. public ShellObserver,
  30. public WindowStateObserver,
  31. public ShelfObserver,
  32. public AppListControllerObserver {
  33. public:
  34. // |window| is the container for this layout manager.
  35. explicit WorkspaceLayoutManager(aura::Window* window);
  36. WorkspaceLayoutManager(const WorkspaceLayoutManager&) = delete;
  37. WorkspaceLayoutManager& operator=(const WorkspaceLayoutManager&) = delete;
  38. ~WorkspaceLayoutManager() override;
  39. BackdropController* backdrop_controller() {
  40. return backdrop_controller_.get();
  41. }
  42. bool is_fullscreen() { return is_fullscreen_; }
  43. // aura::LayoutManager:
  44. void OnWindowResized() override;
  45. void OnWindowAddedToLayout(aura::Window* child) override;
  46. void OnWillRemoveWindowFromLayout(aura::Window* child) override;
  47. void OnWindowRemovedFromLayout(aura::Window* child) override;
  48. void OnChildWindowVisibilityChanged(aura::Window* child,
  49. bool visible) override;
  50. void SetChildBounds(aura::Window* child,
  51. const gfx::Rect& requested_bounds) override;
  52. // aura::WindowObserver:
  53. void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
  54. void OnWindowAdded(aura::Window* window) override;
  55. void OnWindowPropertyChanged(aura::Window* window,
  56. const void* key,
  57. intptr_t old) override;
  58. void OnWindowStackingChanged(aura::Window* window) override;
  59. void OnWindowDestroying(aura::Window* window) override;
  60. void OnWindowBoundsChanged(aura::Window* window,
  61. const gfx::Rect& old_bounds,
  62. const gfx::Rect& new_bounds,
  63. ui::PropertyChangeReason reason) override;
  64. // wm::ActivationChangeObserver:
  65. void OnWindowActivating(ActivationReason reason,
  66. aura::Window* gaining_active,
  67. aura::Window* losing_active) override;
  68. void OnWindowActivated(
  69. ::wm::ActivationChangeObserver::ActivationReason reason,
  70. aura::Window* gained_active,
  71. aura::Window* lost_active) override;
  72. // KeyboardControllerObserver:
  73. void OnKeyboardVisibleBoundsChanged(const gfx::Rect& new_bounds) override;
  74. void OnKeyboardDisplacingBoundsChanged(const gfx::Rect& new_bounds) override;
  75. // WindowStateObserver:
  76. void OnPostWindowStateTypeChange(WindowState* window_state,
  77. chromeos::WindowStateType old_type) override;
  78. // display::DisplayObserver:
  79. void OnDisplayMetricsChanged(const display::Display& display,
  80. uint32_t changed_metrics) override;
  81. // ShellObserver:
  82. void OnFullscreenStateChanged(bool is_fullscreen,
  83. aura::Window* container) override;
  84. void OnPinnedStateChanged(aura::Window* pinned_window) override;
  85. void OnShellDestroying() override;
  86. // ShelfObserver:
  87. void OnAutoHideStateChanged(ShelfAutoHideState new_state) override;
  88. void OnHotseatStateChanged(HotseatState old_state,
  89. HotseatState new_state) override;
  90. // AppListControllerObserver:
  91. void OnAppListVisibilityChanged(bool shown, int64_t display_id) override;
  92. private:
  93. friend class WorkspaceControllerTestApi;
  94. typedef std::set<aura::Window*> WindowSet;
  95. // Observes changes in windows in the FloatingWindowObserver, and
  96. // notifies WorkspaceLayoutManager to send out system ui area change events.
  97. // This class currently observes windows in |settings_bubble_container_|,
  98. // |accessibility_bubble_container_|, and |shelf_container_|.
  99. class FloatingWindowObserver : public aura::WindowObserver {
  100. public:
  101. explicit FloatingWindowObserver(
  102. WorkspaceLayoutManager* workspace_layout_manager);
  103. FloatingWindowObserver(const FloatingWindowObserver&) = delete;
  104. FloatingWindowObserver& operator=(const FloatingWindowObserver&) = delete;
  105. ~FloatingWindowObserver() override;
  106. void ObserveWindow(aura::Window* window);
  107. // aura::WindowObserver:
  108. void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
  109. void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
  110. void OnWindowDestroying(aura::Window* window) override;
  111. void OnWindowBoundsChanged(aura::Window* window,
  112. const gfx::Rect& old_bounds,
  113. const gfx::Rect& new_bounds,
  114. ui::PropertyChangeReason reason) override;
  115. private:
  116. // WorkspaceLayoutManager has at least as long a lifetime as this class.
  117. const WorkspaceLayoutManager* workspace_layout_manager_;
  118. // The key is the window to be observed, and the value is the parent of the
  119. // window.
  120. std::map<aura::Window*, aura::Window*> observed_windows_;
  121. void StopOberservingWindow(aura::Window* window);
  122. };
  123. // Adjusts the bounds of all managed windows when the display area changes.
  124. // This happens when the display size, work area insets has changed.
  125. // If this is called for a display size change (i.e. |event|
  126. // is DISPLAY_RESIZED), the non-maximized/non-fullscreen
  127. // windows are readjusted to make sure the window is completely within the
  128. // display region. Otherwise, it makes sure at least some parts of the window
  129. // is on display.
  130. void AdjustAllWindowsBoundsForWorkAreaChange(const WMEvent* event);
  131. // Updates the visibility state of the shelf.
  132. void UpdateShelfVisibility();
  133. // Updates the fullscreen state of the workspace and notifies Shell if it
  134. // has changed.
  135. void UpdateFullscreenState();
  136. // Updates the always-on-top state for windows managed by this layout
  137. // manager.
  138. void UpdateAlwaysOnTop(aura::Window* active_desk_fullscreen_window);
  139. // Notifies windows about a change in a system ui area. This could be
  140. // the keyboard or any window in the SettingsBubbleContainer or
  141. // |accessibility_bubble_container_|. Windows will only be notified about
  142. // changes to system ui areas on the display they are on.
  143. void NotifySystemUiAreaChanged() const;
  144. // Notifies the accessibility controller about a workspace event. If autoclick
  145. // or stick keys is enabled, the autoclick bubble or sticky keys overlay may
  146. // need to move in response to that event.
  147. void NotifyAccessibilityWorkspaceChanged() const;
  148. // Updates the window workspace.
  149. void UpdateWindowWorkspace(aura::Window* window);
  150. bool IsPopupNotificationWindow(aura::Window* window) const;
  151. aura::Window* window_;
  152. aura::Window* root_window_;
  153. RootWindowController* root_window_controller_;
  154. FloatingWindowObserver floating_window_observer_;
  155. aura::Window* settings_bubble_container_;
  156. aura::Window* accessibility_bubble_container_;
  157. aura::Window* shelf_container_;
  158. display::ScopedDisplayObserver display_observer_{this};
  159. // Set of windows we're listening to.
  160. WindowSet windows_;
  161. // The work area in the coordinates of |window_|.
  162. gfx::Rect work_area_in_parent_;
  163. // True if this workspace is currently in fullscreen mode. Tracks the
  164. // fullscreen state of the container |window_| associated with this workspace
  165. // rather than the root window.
  166. // Note that in the case of a workspace of a PiP or always-on-top containers,
  167. // |is_fullscreen_| doesn't make sense since we don't allow windows on those
  168. // containers to go fullscreen. Hence, |is_fullscreen_| is always false on
  169. // those workspaces.
  170. bool is_fullscreen_;
  171. // A window which covers the full container and which gets inserted behind the
  172. // topmost visible window.
  173. std::unique_ptr<BackdropController> backdrop_controller_;
  174. };
  175. } // namespace ash
  176. #endif // ASH_WM_WORKSPACE_WORKSPACE_LAYOUT_MANAGER_H_