work_area_insets.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // Copyright 2019 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_WORK_AREA_INSETS_H_
  5. #define ASH_WM_WORK_AREA_INSETS_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  8. #include "ui/gfx/geometry/insets.h"
  9. #include "ui/gfx/geometry/rect.h"
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace ash {
  14. class RootWindowController;
  15. // Insets of the work area associated with this root window.
  16. // Work area is the space left for user after removing areas occupied by
  17. // persistent system elements like shelf, keyboard and accessibility widgets.
  18. // Work area is assocciated with a single root window, because the configuration
  19. // of persistent elements can be different for different screens.
  20. // WorkAreaInsets class caches information about persistent system elements to
  21. // avoid frequent recalculations. It gathers work area related computations and
  22. // provides single interface to query work area details.
  23. class ASH_EXPORT WorkAreaInsets : public KeyboardControllerObserver {
  24. public:
  25. // Returns work area parameters associated with the given |window|.
  26. static WorkAreaInsets* ForWindow(const aura::Window* window);
  27. // Test API that updates work area through `ShelfLayoutManager`.
  28. static void UpdateWorkAreaInsetsForTest(
  29. aura::Window* window,
  30. const gfx::Rect& shelf_bounds_for_workarea_calculation,
  31. const gfx::Insets& shelf_insets,
  32. const gfx::Insets& in_session_shelf_insets);
  33. explicit WorkAreaInsets(RootWindowController* root_window_controller);
  34. WorkAreaInsets(const WorkAreaInsets&) = delete;
  35. WorkAreaInsets& operator=(const WorkAreaInsets&) = delete;
  36. ~WorkAreaInsets() override;
  37. // Returns cached height of the accessibility panel in DIPs for this root
  38. // window.
  39. int accessibility_panel_height() const { return accessibility_panel_height_; }
  40. // Returns cached height of the docked magnifier in DIPs for this root
  41. // window.
  42. int docked_magnifier_height() const { return docked_magnifier_height_; }
  43. // Returns cached user work area bounds in screen coordinates DIPs for this
  44. // root window.
  45. const gfx::Rect& user_work_area_bounds() const {
  46. return user_work_area_bounds_;
  47. }
  48. // Returns cached user work area insets in DIPs for this root window.
  49. const gfx::Insets& user_work_area_insets() const {
  50. return user_work_area_insets_;
  51. }
  52. // Returns cached user work area insets in DIPs for this root window in
  53. // session with true shelf alignment instead of `BottomLocked`.
  54. const gfx::Insets& in_session_user_work_area_insets() const {
  55. return in_session_user_work_area_insets_;
  56. }
  57. // Returns accessibility insets in DIPs.
  58. gfx::Insets GetAccessibilityInsets() const;
  59. // Returns the persistent desk bar insets in DIPs.
  60. gfx::Insets GetPersistentDeskBarInsets() const;
  61. // Returns bounds of the stable work area (work area when the shelf is
  62. // visible) in screen coordinates DIPs.
  63. gfx::Rect ComputeStableWorkArea() const;
  64. // Returns whether keyboard is shown for this root window.
  65. // TODO(agawronska): It would be nice to contain all keyboard related
  66. // functionality in this class and remove this method.
  67. bool IsKeyboardShown() const;
  68. // Sets height of the accessibility panel in DIPs for this root window.
  69. // Shell observers will be notified that accessibility insets changed.
  70. void SetDockedMagnifierHeight(int height);
  71. // Sets height of the docked magnifier in DIPs for this root window.
  72. // Shell observers will be notified that accessibility insets changed.
  73. void SetAccessibilityPanelHeight(int height);
  74. // Sets height of the persistent desk bar in DIPs for this root
  75. // window. Shell observers will be notified that persistent desk bar
  76. // insets changed.
  77. void SetPersistentDeskBarHeight(int height);
  78. // Indicates if the persistent desk bar height is in change. This is useful to
  79. // prevent circular call from the App List as it also observes the work area
  80. // value.
  81. bool PersistentDeskBarHeightInChange();
  82. // Sets bounds (in window coordinates) and insets of the shelf for this root
  83. // window. |bounds| and |insets| are passed separately, because insets depend
  84. // on shelf visibility and can be different than calculated from bounds.
  85. void SetShelfBoundsAndInsets(const gfx::Rect& bounds,
  86. const gfx::Insets& insets,
  87. const gfx::Insets& in_session_insets);
  88. // KeyboardControllerObserver:
  89. void OnKeyboardAppearanceChanged(
  90. const KeyboardStateDescriptor& state) override;
  91. void OnKeyboardVisibilityChanged(bool is_visible) override;
  92. private:
  93. // Updates cached values of work area bounds and insets.
  94. void UpdateWorkArea();
  95. // RootWindowController associated with this work area.
  96. RootWindowController* const root_window_controller_ = nullptr;
  97. // Cached bounds of user work area in screen coordinates DIPs.
  98. gfx::Rect user_work_area_bounds_;
  99. // Cached insets of user work area in DIPs.
  100. gfx::Insets user_work_area_insets_;
  101. // Cached insets of user work area in DIPs in session with true shelf
  102. // alignment instead of `BottomLocked`.
  103. gfx::Insets in_session_user_work_area_insets_;
  104. // Cached occluded bounds of the keyboard in window coordinates. It needs to
  105. // be removed from the available work area. See
  106. // ui/keyboard/keyboard_controller_observer.h for details.
  107. gfx::Rect keyboard_occluded_bounds_;
  108. // Cached displaced bounds of the keyboard in window coordinates.
  109. // See ui/keyboard/keyboard_controller_observer.h for details.
  110. gfx::Rect keyboard_displaced_bounds_;
  111. // Cached bounds of the shelf in window coordinates in DIPs.
  112. gfx::Rect shelf_bounds_;
  113. // Cached insets of the shelf in DIPs.
  114. gfx::Insets shelf_insets_;
  115. // Cached insets of the shelf in DIPs in session with true shelf alignment
  116. // instead of `BottomLocked`.
  117. gfx::Insets in_session_shelf_insets_;
  118. // Cached height of the docked magnifier in DIPs at the top of the screen.
  119. // It needs to be removed from the available work area.
  120. int docked_magnifier_height_ = 0;
  121. // Cached height of the accessibility panel in DIPs at the top of the
  122. // screen. It needs to be removed from the available work area.
  123. int accessibility_panel_height_ = 0;
  124. // Cached height of the persistent desk bar in DIPs at the top of the
  125. // screen. It needs to be removed from the available work area.
  126. int persistent_desk_bar_height_ = 0;
  127. // Indicates if the persistent desk bar height is in change.
  128. bool persistent_desk_bar_height_in_change_ = false;
  129. };
  130. } // namespace ash
  131. #endif // ASH_WM_WORK_AREA_INSETS_H_