tray_popup_utils.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright 2016 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_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_
  5. #define ASH_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/ash_export.h"
  9. #include "ash/login_status.h"
  10. #include "ash/system/tray/tray_constants.h"
  11. #include "ash/system/tray/tray_popup_ink_drop_style.h"
  12. #include "ash/system/tray/tri_view.h"
  13. #include "ui/views/controls/button/button.h"
  14. namespace views {
  15. class Button;
  16. class ImageView;
  17. class Label;
  18. class LabelButton;
  19. class Painter;
  20. class Separator;
  21. } // namespace views
  22. namespace ash {
  23. class HoverHighlightView;
  24. class UnfocusableLabel;
  25. // Factory/utility functions used by the system menu.
  26. class ASH_EXPORT TrayPopupUtils {
  27. public:
  28. enum class FontStyle {
  29. // Topmost header rows for default view and detailed view.
  30. kTitle,
  31. // Topmost header for secondary tray bubbles
  32. kPodMenuHeader,
  33. // Small title used for selections in tray bubbles.
  34. kSmallTitle,
  35. // Text in sub-section header rows in detailed views.
  36. kSubHeader,
  37. // Main text used by detailed view rows.
  38. kDetailedViewLabel,
  39. // System information text (e.g. date/time, battery status, "Scanning for
  40. // devices..." seen in the Bluetooth detailed view, etc).
  41. kSystemInfo,
  42. };
  43. TrayPopupUtils() = delete;
  44. TrayPopupUtils(const TrayPopupUtils&) = delete;
  45. TrayPopupUtils& operator=(const TrayPopupUtils&) = delete;
  46. // Creates a default container view to be used by system menu rows that are
  47. // either a single targetable area or not targetable at all. The caller takes
  48. // over ownership of the created view.
  49. //
  50. // The returned view consists of 3 regions: START, CENTER, and END. Any child
  51. // Views added to the START and END containers will be added horizontally and
  52. // any Views added to the CENTER container will be added vertically.
  53. //
  54. // The START and END containers have a fixed minimum width but can grow into
  55. // the CENTER container if space is required and available.
  56. //
  57. // The CENTER container has a flexible width.
  58. static TriView* CreateDefaultRowView();
  59. // Creates a container view to be used by system menu sub-section header rows.
  60. // The caller takes over ownership of the created view.
  61. //
  62. // The returned view contains at least CENTER and END regions having the same
  63. // properties as when using |CreateMultiTargetRowView|. |start_visible|
  64. // determines whether the START region should be visible or not. If START is
  65. // not visible, extra padding is added to the left of the contents.
  66. //
  67. // The START (if visible) and END containers have a fixed minimum width but
  68. // can grow into the CENTER container if space is required and available. The
  69. // CENTER container has a flexible width.
  70. //
  71. // TODO(mohsen): Merge this into TrayDetailedView::AddScrollListSubHeader()
  72. // once network and VPN also use TrayDetailedView::AddScrollListSubHeader().
  73. static TriView* CreateSubHeaderRowView(bool start_visible);
  74. // Creates a container view to be used by system menu rows that want to embed
  75. // a targetable area within one (or more) of the containers OR by any row
  76. // that requires a non-default layout within the container views. The returned
  77. // view will have the following configurations:
  78. // - default minimum row height
  79. // - default minimum width for the START and END containers
  80. // - default left and right insets
  81. // - default container flex values
  82. // - Each container view will have a FillLayout installed on it
  83. //
  84. // The caller takes over ownership of the created view.
  85. //
  86. // The START and END containers have a fixed minimum width but can grow into
  87. // the CENTER container if space is required and available. The CENTER
  88. // container has a flexible width.
  89. //
  90. // Clients can use ConfigureContainer() to configure their own container views
  91. // before adding them to the returned TriView.
  92. static TriView* CreateMultiTargetRowView();
  93. // Returns a label that has been configured for system menu layout. This
  94. // should be used by all rows that require a label, i.e. both default and
  95. // detailed rows should use this.
  96. //
  97. // TODO(bruthig): Update all system menu rows to use this.
  98. static views::Label* CreateDefaultLabel();
  99. // Returns a label that has been configured for system menu layout and does
  100. // not allow accessibility focus.
  101. static UnfocusableLabel* CreateUnfocusableLabel();
  102. // Returns an image view to be used in the main image region of a system menu
  103. // row. This should be used by all rows that have a main image, i.e. both
  104. // default and detailed rows should use this.
  105. //
  106. // TODO(bruthig): Update all system menu rows to use this.
  107. static views::ImageView* CreateMainImageView();
  108. // Creates a default focus painter used for most things in tray popups.
  109. static std::unique_ptr<views::Painter> CreateFocusPainter();
  110. // Sets up |view| to be a sticky header in a tray detail scroll view.
  111. static void ConfigureAsStickyHeader(views::View* view);
  112. // Configures |container_view| just like CreateDefaultRowView() would
  113. // configure |container| on its returned TriView. To be used when mutliple
  114. // targetable areas are required within a single row.
  115. static void ConfigureContainer(TriView::Container container,
  116. views::View* container_view);
  117. // Creates a button for use in the system menu. For MD, this is a prominent
  118. // text
  119. // button. For non-MD, this does the same thing as the above. Caller assumes
  120. // ownership.
  121. static views::LabelButton* CreateTrayPopupButton(
  122. views::Button::PressedCallback callback,
  123. const std::u16string& text);
  124. // Creates and returns a vertical separator to be used between two items in a
  125. // material design system menu row. The caller assumes ownership of the
  126. // returned separator.
  127. static views::Separator* CreateVerticalSeparator();
  128. // Installs a HighlightPathGenerator matching the TrayPopupInkDropStyle.
  129. static void InstallHighlightPathGenerator(
  130. views::View* host,
  131. TrayPopupInkDropStyle ink_drop_style);
  132. // Create a horizontal separator line to be drawn between rows in a detailed
  133. // view above the sub-header rows. Caller assumes ownership of the returned
  134. // view.
  135. static views::Separator* CreateListSubHeaderSeparator();
  136. // Creates and returns a horizontal separator line to be drawn between rows
  137. // in a detailed view. If |left_inset| is true, then the separator is inset on
  138. // the left by the width normally occupied by an icon. Caller assumes
  139. // ownership of the returned separator.
  140. static views::Separator* CreateListItemSeparator(bool left_inset);
  141. // Returns true if it is possible to open WebUI settings in a browser window,
  142. // i.e. the user is logged in, not on the lock screen, not adding a secondary
  143. // user, and not in the supervised user creation flow.
  144. static bool CanOpenWebUISettings();
  145. // Initializes a row in the system menu as checkable and update the check mark
  146. // status of this row. If |enterprise_managed| is true, adds an enterprise
  147. // managed icon to the row.
  148. static void InitializeAsCheckableRow(HoverHighlightView* container,
  149. bool checked,
  150. bool enterprise_managed);
  151. // Updates the visibility and a11y state of the checkable row |container|.
  152. static void UpdateCheckMarkVisibility(HoverHighlightView* container,
  153. bool visible);
  154. // Sets the font list for |label| based on |style|.
  155. static void SetLabelFontList(views::Label* label, FontStyle style);
  156. };
  157. } // namespace ash
  158. #endif // ASH_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_