tray_detailed_view.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_SYSTEM_TRAY_TRAY_DETAILED_VIEW_H_
  5. #define ASH_SYSTEM_TRAY_TRAY_DETAILED_VIEW_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/system/tray/tray_constants.h"
  9. #include "ash/system/tray/view_click_listener.h"
  10. #include "ui/views/controls/button/button.h"
  11. #include "ui/views/view.h"
  12. namespace gfx {
  13. struct VectorIcon;
  14. } // namespace gfx
  15. namespace views {
  16. class BoxLayout;
  17. class Button;
  18. class ImageView;
  19. class Label;
  20. class ProgressBar;
  21. class ScrollView;
  22. } // namespace views
  23. namespace ash {
  24. class DetailedViewDelegate;
  25. class HoverHighlightView;
  26. class ScrollBorder;
  27. class TriView;
  28. class ASH_EXPORT TrayDetailedView : public views::View,
  29. public ViewClickListener {
  30. public:
  31. explicit TrayDetailedView(DetailedViewDelegate* delegate);
  32. TrayDetailedView(const TrayDetailedView&) = delete;
  33. TrayDetailedView& operator=(const TrayDetailedView&) = delete;
  34. ~TrayDetailedView() override;
  35. // ViewClickListener:
  36. // Don't override this --- override HandleViewClicked.
  37. void OnViewClicked(views::View* sender) final;
  38. // Setter for `progress_bar_` accessibility label.
  39. void OverrideProgressBarAccessibleName(const std::u16string& name);
  40. protected:
  41. // views::View:
  42. void Layout() override;
  43. int GetHeightForWidth(int width) const override;
  44. const char* GetClassName() const override;
  45. void OnThemeChanged() override;
  46. // Exposes the layout manager of this view to give control to subclasses.
  47. views::BoxLayout* box_layout() { return box_layout_; }
  48. // Creates the row containing the back button and title. For material design
  49. // this appears at the top of the view, for non-material design it appears
  50. // at the bottom.
  51. void CreateTitleRow(int string_id);
  52. // Creates a scrollable list. The list has a border at the bottom if there is
  53. // any other view between the list and the footer row at the bottom.
  54. void CreateScrollableList();
  55. // Adds a targetable row to |scroll_content_| containing |icon| and |text|.
  56. HoverHighlightView* AddScrollListItem(const gfx::VectorIcon& icon,
  57. const std::u16string& text);
  58. // Add a child view to the scroll list.
  59. void AddScrollListChild(std::unique_ptr<views::View> child);
  60. // Adds a targetable row to |scroll_content_| containing |icon|, |text|, and a
  61. // checkbox. |checked| determines whether the checkbox is checked or not.
  62. // |enterprise_managed| determines whether or not there will be an enterprise
  63. // managed icon for that item.
  64. HoverHighlightView* AddScrollListCheckableItem(
  65. const gfx::VectorIcon& icon,
  66. const std::u16string& text,
  67. bool checked,
  68. bool enterprise_managed = false);
  69. // Adds a targetable row to |scroll_content_| containing |text| and a
  70. // checkbox. |checked| determines whether the checkbox is checked or not.
  71. // |enterprise_managed| determines whether or not there will be an enterprise
  72. // managed icon for that item.
  73. HoverHighlightView* AddScrollListCheckableItem(
  74. const std::u16string& text,
  75. bool checked,
  76. bool enterprise_managed = false);
  77. // Adds a sticky sub header to |scroll_content_| containing |icon| and a text
  78. // represented by |text_id| resource id.
  79. TriView* AddScrollListSubHeader(const gfx::VectorIcon& icon, int text_id);
  80. // Adds a sticky sub header to |scroll_content_| containing a text represented
  81. // by |text_id| resource id.
  82. TriView* AddScrollListSubHeader(int text_id);
  83. // Removes (and destroys) all child views.
  84. void Reset();
  85. // Shows or hides the progress bar below the title row. It occupies the same
  86. // space as the separator, so when shown the separator is hidden. If
  87. // |progress_bar_| doesn't already exist it will be created.
  88. void ShowProgress(double value, bool visible);
  89. // Helper functions which create and return the settings and help buttons,
  90. // respectively, used in the material design top-most header row. The caller
  91. // assumes ownership of the returned buttons.
  92. virtual views::Button* CreateInfoButton(
  93. views::Button::PressedCallback callback,
  94. int info_accessible_name_id);
  95. views::Button* CreateSettingsButton(views::Button::PressedCallback callback,
  96. int setting_accessible_name_id);
  97. views::Button* CreateHelpButton(views::Button::PressedCallback callback);
  98. // Closes the bubble that contains the detailed view.
  99. void CloseBubble();
  100. TriView* tri_view() { return tri_view_; }
  101. views::ScrollView* scroller() const { return scroller_; }
  102. views::View* scroll_content() const { return scroll_content_; }
  103. // Gets called in the constructor of the `CalendarView`, or any other views in
  104. // the future that don't have a separator to modify the value of
  105. // `has_separator` to false.
  106. void IgnoreSeparator();
  107. private:
  108. friend class TrayDetailedViewTest;
  109. // Overridden to handle clicks on subclass-specific views.
  110. virtual void HandleViewClicked(views::View* view);
  111. // Creates and adds subclass-specific buttons to the title row.
  112. virtual void CreateExtraTitleRowButtons();
  113. // Transition to main view from detailed view.
  114. void TransitionToMainView();
  115. DetailedViewDelegate* const delegate_;
  116. views::BoxLayout* box_layout_ = nullptr;
  117. views::ScrollView* scroller_ = nullptr;
  118. views::View* scroll_content_ = nullptr;
  119. views::ProgressBar* progress_bar_ = nullptr;
  120. ScrollBorder* scroll_border_ = nullptr; // Weak reference
  121. // The container view for the top-most title row in material design.
  122. TriView* tri_view_ = nullptr;
  123. // The back button that appears in the material design title row. Not owned.
  124. views::Button* back_button_ = nullptr;
  125. views::Label* sub_header_label_ = nullptr;
  126. views::ImageView* sub_header_image_view_ = nullptr;
  127. const gfx::VectorIcon* sub_header_icon_ = nullptr;
  128. // Gets modified to false in the constructor of the view if it doesn't have a
  129. // separator.
  130. bool has_separator_ = true;
  131. // The accessible name for the `progress_bar_`.
  132. absl::optional<std::u16string> progress_bar_accessible_name_;
  133. };
  134. } // namespace ash
  135. #endif // ASH_SYSTEM_TRAY_TRAY_DETAILED_VIEW_H_