shelf_config.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // Copyright (c) 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_PUBLIC_CPP_SHELF_CONFIG_H_
  5. #define ASH_PUBLIC_CPP_SHELF_CONFIG_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/app_list/app_list_controller_observer.h"
  8. #include "ash/public/cpp/session/session_observer.h"
  9. #include "ash/public/cpp/shelf_types.h"
  10. #include "ash/public/cpp/tablet_mode_observer.h"
  11. #include "ash/style/ash_color_provider.h"
  12. #include "ash/system/model/virtual_keyboard_model.h"
  13. #include "ash/wm/overview/overview_observer.h"
  14. #include "ash/wm/splitview/split_view_observer.h"
  15. #include "base/observer_list.h"
  16. #include "base/observer_list_types.h"
  17. #include "third_party/abseil-cpp/absl/types/optional.h"
  18. #include "third_party/skia/include/core/SkColor.h"
  19. #include "ui/display/display_observer.h"
  20. #include "ui/gfx/animation/tween.h"
  21. namespace base {
  22. class TimeDelta;
  23. }
  24. namespace session_manager {
  25. enum class SessionState;
  26. } // namespace session_manager
  27. namespace ash {
  28. // Provides layout and drawing config for the Shelf. Note That some of these
  29. // values could change at runtime.
  30. class ASH_EXPORT ShelfConfig : public TabletModeObserver,
  31. public SessionObserver,
  32. public AppListControllerObserver,
  33. public display::DisplayObserver,
  34. public VirtualKeyboardModel::Observer,
  35. public OverviewObserver {
  36. public:
  37. class Observer : public base::CheckedObserver {
  38. public:
  39. // Invoked when shelf config values are changed.
  40. virtual void OnShelfConfigUpdated() {}
  41. };
  42. ShelfConfig();
  43. ShelfConfig(const ShelfConfig&) = delete;
  44. ShelfConfig& operator=(const ShelfConfig&) = delete;
  45. ~ShelfConfig() override;
  46. static ShelfConfig* Get();
  47. void AddObserver(Observer* observer);
  48. void RemoveObserver(Observer* observer);
  49. // Add observers to this objects's dependencies.
  50. void Init();
  51. // Remove observers from this object's dependencies.
  52. void Shutdown();
  53. // OverviewObserver:
  54. void OnOverviewModeWillStart() override;
  55. void OnOverviewModeEnding(OverviewSession* overview_session) override;
  56. void OnSplitViewStateChanged(SplitViewController::State previous_state,
  57. SplitViewController::State state);
  58. // TabletModeObserver:
  59. void OnTabletModeStarting() override;
  60. void OnTabletModeEnding() override;
  61. // SessionObserver:
  62. void OnSessionStateChanged(session_manager::SessionState state) override;
  63. // DisplayObserver:
  64. void OnDisplayMetricsChanged(const display::Display& display,
  65. uint32_t changed_metrics) override;
  66. // VirtualKeyboardModel::Observer:
  67. void OnVirtualKeyboardVisibilityChanged() override;
  68. // AppListControllerObserver:
  69. void OnAppListVisibilityWillChange(bool shown, int64_t display_id) override;
  70. // Whether the shelf control buttons must be shown for accessibility
  71. // reasons.
  72. bool ShelfControlsForcedShownForAccessibility() const;
  73. // Returns the optimal shelf button size for the given hotseat density.
  74. int GetShelfButtonSize(HotseatDensity density) const;
  75. // Returns the optimal shelf icon size for the given hotseat density.
  76. int GetShelfButtonIconSize(HotseatDensity density) const;
  77. // Returns the hotseat height for the given hotseat density.
  78. // NOTE: This may not match the actual hotseat size, as hotseat may get scaled
  79. // down if it does not fit in available bounds within the shelf. Use
  80. // HotseatWidget::GetHotseatSize() to get the actual widget size.
  81. int GetHotseatSize(HotseatDensity density) const;
  82. // Size of the shelf when visible (height when the shelf is horizontal and
  83. // width when the shelf is vertical).
  84. int shelf_size() const;
  85. // Size of the shelf when an app is visible in tablet mode.
  86. int in_app_shelf_size() const;
  87. // Size of the shelf when not in tablet mode, or when no apps are visible.
  88. int system_shelf_size() const;
  89. // The shelf size within which the drag handle should be centered.
  90. int shelf_drag_handle_centering_size() const;
  91. // The size of the gap between the hotseat and shelf when the hotseat is
  92. // extended.
  93. int hotseat_bottom_padding() const;
  94. // Size of the space between buttons on the shelf.
  95. int button_spacing() const;
  96. // Size for controls like the home button, back button, etc.
  97. int control_size() const;
  98. // The radius of shelf control buttons.
  99. int control_border_radius() const;
  100. // The spacing between the edge of the shelf and the control buttons. When
  101. // shelf is horizontal, the left/right edges of the shelf are considered a
  102. // primary axis edge. When shelf is vertical, the top/bottom edges are
  103. // considered the primary axis edge.
  104. int control_button_edge_spacing(bool is_primary_axis_edge) const;
  105. // The duration of the hotseat background animations in ms.
  106. base::TimeDelta hotseat_background_animation_duration() const;
  107. // The duration of the shelf show/hide animation in ms.
  108. base::TimeDelta shelf_animation_duration() const;
  109. // The extra padding added to status area tray buttons on the shelf.
  110. int status_area_hit_region_padding() const;
  111. // The threshold relative to the size of the shelf that is used to determine
  112. // if the shelf visibility should change during a drag.
  113. float drag_hide_ratio_threshold() const;
  114. int workspace_area_visible_inset() const {
  115. return workspace_area_visible_inset_;
  116. }
  117. int workspace_area_auto_hide_inset() const {
  118. return workspace_area_auto_hide_inset_;
  119. }
  120. int hidden_shelf_in_screen_portion() const {
  121. return hidden_shelf_in_screen_portion_;
  122. }
  123. int status_indicator_offset_from_shelf_edge() const {
  124. return status_indicator_offset_from_shelf_edge_;
  125. }
  126. int scrollable_shelf_ripple_padding() const {
  127. return scrollable_shelf_ripple_padding_;
  128. }
  129. int shelf_tooltip_preview_height() const {
  130. return shelf_tooltip_preview_height_;
  131. }
  132. int shelf_tooltip_preview_max_width() const {
  133. return shelf_tooltip_preview_max_width_;
  134. }
  135. float shelf_tooltip_preview_max_ratio() const {
  136. return shelf_tooltip_preview_max_ratio_;
  137. }
  138. float shelf_tooltip_preview_min_ratio() const {
  139. return shelf_tooltip_preview_min_ratio_;
  140. }
  141. int shelf_blur_radius() const { return shelf_blur_radius_; }
  142. int mousewheel_scroll_offset_threshold() const {
  143. return mousewheel_scroll_offset_threshold_;
  144. }
  145. int in_app_control_button_height_inset() const {
  146. return in_app_control_button_height_inset_;
  147. }
  148. bool is_dense() const { return is_dense_; }
  149. bool is_in_app() const { return is_in_app_; }
  150. bool in_split_view_with_overview() const {
  151. return in_split_view_with_overview_;
  152. }
  153. bool shelf_controls_shown() const { return shelf_controls_shown_; }
  154. bool is_virtual_keyboard_shown() const { return is_virtual_keyboard_shown_; }
  155. bool in_tablet_mode() const { return in_tablet_mode_; }
  156. bool in_overview_mode() const { return overview_mode_; }
  157. // Gets the current color for the shelf control buttons.
  158. SkColor GetShelfControlButtonColor() const;
  159. // Gets the shelf color when the app list is open, used in clamshell mode.
  160. SkColor GetShelfWithAppListColor() const;
  161. // Gets the shelf color when a window is maximized.
  162. SkColor GetMaximizedShelfColor() const;
  163. // Gets the base layer type for shelf color.
  164. AshColorProvider::BaseLayerType GetShelfBaseLayerType() const;
  165. // Gets the default shelf color, calculated using the wallpaper color if
  166. // available.
  167. SkColor GetDefaultShelfColor() const;
  168. // Returns the current blur radius to use for the control buttons.
  169. int GetShelfControlButtonBlurRadius() const;
  170. // The padding between the app icon and the end of the scrollable shelf.
  171. int GetAppIconEndPadding() const;
  172. // Returns the margin on either side of the group of app icons.
  173. int GetAppIconGroupMargin() const;
  174. // The animation time for dimming shelf icons, widgets, and buttons.
  175. base::TimeDelta DimAnimationDuration() const;
  176. // The tween type for dimming shelf icons, widgets, and buttons.
  177. gfx::Tween::Type DimAnimationTween() const;
  178. // The size of the shelf drag handle.
  179. gfx::Size DragHandleSize() const;
  180. private:
  181. friend class ShelfConfigTest;
  182. class ShelfAccessibilityObserver;
  183. class ShelfSplitViewObserver;
  184. // Called whenever something has changed in the shelf configuration. Notifies
  185. // all observers.
  186. void OnShelfConfigUpdated();
  187. // Updates |is_dense_|, |is_app_list_visible_|, and |shelf_controls_shown_|
  188. // and notifies all observers of the update if the state changes.
  189. // |new_is_app_list_visible| - The new app list visibility state.
  190. // |tablet_mode_changed| should be set to true if this config is being updated
  191. // as a result of a change in tablet mode state.
  192. void UpdateConfig(bool new_is_app_list_visible, bool tablet_mode_changed);
  193. // Gets the current shelf size.
  194. // |ignore_in_app_state| - Whether the returned shelf size should be
  195. // calculated as if is_in_app() returns false.
  196. int GetShelfSize(bool ignore_in_app_state) const;
  197. // Updates shelf config - called when the accessibility state changes.
  198. void UpdateConfigForAccessibilityState();
  199. // Calculates the intended in-app state with the provided app list and virtual
  200. // keyboard visibility.
  201. bool CalculateIsInApp(bool app_list_visible,
  202. bool virtual_keyboard_shown) const;
  203. // Whether the in app shelf should be shown in overview mode.
  204. bool use_in_app_shelf_in_overview_;
  205. // True if device is currently in overview mode.
  206. bool overview_mode_;
  207. // True if device is currently in tablet mode.
  208. bool in_tablet_mode_;
  209. // Whether shelf is currently standard or dense.
  210. bool is_dense_;
  211. // Whether the shelf is currently in in-app state.
  212. bool is_in_app_;
  213. // Whether the device is in split view. Only tracked in overview mode.
  214. bool in_split_view_with_overview_;
  215. // Whether the shelf buttons (navigation controls, and overview tray button)
  216. // should be shown.
  217. bool shelf_controls_shown_;
  218. // Whether virtual IME keyboard is shown.
  219. bool is_virtual_keyboard_shown_;
  220. // Whether the app list (or home launcher in tablet mode) is visible.
  221. bool is_app_list_visible_;
  222. // Size of the icons within shelf buttons.
  223. const int shelf_button_icon_size_;
  224. const int shelf_button_icon_size_median_;
  225. const int shelf_button_icon_size_dense_;
  226. // Size allocated for each app button on the shelf.
  227. const int shelf_button_size_;
  228. const int shelf_button_size_median_;
  229. const int shelf_button_size_dense_;
  230. // Size of the space between buttons on the shelf.
  231. const int shelf_button_spacing_;
  232. // The extra padding added to status area tray buttons on the shelf.
  233. const int shelf_status_area_hit_region_padding_;
  234. const int shelf_status_area_hit_region_padding_dense_;
  235. // The margin on either side of the group of app icons in tablet/clamshell.
  236. const int app_icon_group_margin_tablet_;
  237. const int app_icon_group_margin_clamshell_;
  238. // We reserve a small area on the edge of the workspace area to ensure that
  239. // the resize handle at the edge of the window can be hit.
  240. const int workspace_area_visible_inset_;
  241. // When autohidden we extend the touch hit target onto the screen so that the
  242. // user can drag the shelf out.
  243. const int workspace_area_auto_hide_inset_;
  244. // Portion of the shelf that's within the screen bounds when auto-hidden.
  245. const int hidden_shelf_in_screen_portion_;
  246. // The distance between the edge of the shelf and the status indicators.
  247. const int status_indicator_offset_from_shelf_edge_;
  248. // Padding between the shelf container view and the edging app icon in order
  249. // to show the app icon's ripple correctly.
  250. const int scrollable_shelf_ripple_padding_;
  251. // Dimensions for hover previews.
  252. const int shelf_tooltip_preview_height_;
  253. const int shelf_tooltip_preview_max_width_;
  254. const float shelf_tooltip_preview_max_ratio_;
  255. const float shelf_tooltip_preview_min_ratio_;
  256. // The blur radius used for the shelf.
  257. const int shelf_blur_radius_;
  258. // The threshold at which mousewheel and touchpad scrolls are either ignored
  259. // or acted upon.
  260. const int mousewheel_scroll_offset_threshold_;
  261. // The height inset on the control buttons when in-app shelf is shown.
  262. const int in_app_control_button_height_inset_;
  263. // The padding between the app icon and the end of the scrollable shelf in
  264. // tablet mode.
  265. const int app_icon_end_padding_;
  266. // Object responsible for observing accessibility settings relevant to shelf
  267. // config.
  268. std::unique_ptr<ShelfAccessibilityObserver> accessibility_observer_;
  269. // Object responsible for observing overview mode split state changes relevant
  270. // to shelf config.
  271. std::unique_ptr<ShelfSplitViewObserver> split_view_observer_;
  272. // Receive callbacks from DisplayObserver.
  273. absl::optional<display::ScopedDisplayObserver> display_observer_;
  274. base::ObserverList<Observer> observers_;
  275. };
  276. } // namespace ash
  277. #endif // ASH_PUBLIC_CPP_SHELF_CONFIG_H_