system_toast_style.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2021 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_STYLE_SYSTEM_TOAST_STYLE_H_
  5. #define ASH_STYLE_SYSTEM_TOAST_STYLE_H_
  6. #include "ash/ash_export.h"
  7. #include "base/callback_forward.h"
  8. #include "ui/base/metadata/metadata_header_macros.h"
  9. #include "ui/views/view.h"
  10. namespace views {
  11. class ImageView;
  12. class Label;
  13. class LabelButton;
  14. } // namespace views
  15. namespace ash {
  16. class ScopedA11yOverrideWindowSetter;
  17. class SystemShadow;
  18. // A view that has rounded corner with label and button inside. The label shows
  19. // the information. The button inside is optional and has certain functionality
  20. // e.g. dismiss the view or retry. A managed icon will be put ahead of the label
  21. // inside if `is_managed` is true.
  22. // TODO(crbug/1289478): Migrate the `managed_icon_` to `Quick settings toast`,
  23. // which includes an icon on the left.
  24. class ASH_EXPORT SystemToastStyle : public views::View {
  25. public:
  26. METADATA_HEADER(SystemToastStyle);
  27. SystemToastStyle(base::RepeatingClosure dismiss_callback,
  28. const std::u16string& text,
  29. const std::u16string& dismiss_text,
  30. const bool is_managed);
  31. SystemToastStyle(const SystemToastStyle&) = delete;
  32. SystemToastStyle& operator=(const SystemToastStyle&) = delete;
  33. ~SystemToastStyle() override;
  34. bool is_dismiss_button_highlighted() const {
  35. return is_dismiss_button_highlighted_;
  36. }
  37. // Returns true if the toast has a dismiss button and was highlighted for
  38. // accessibility, false otherwise.
  39. bool ToggleA11yFocus();
  40. // Updates the toast label text.
  41. void SetText(const std::u16string& text);
  42. views::LabelButton* button() const { return button_; }
  43. private:
  44. // views::View:
  45. void AddedToWidget() override;
  46. void OnThemeChanged() override;
  47. views::Label* label_ = nullptr;
  48. views::LabelButton* button_ = nullptr;
  49. views::ImageView* managed_icon_ = nullptr;
  50. // Tells the toast if the dismiss button is already highlighted if one exists.
  51. bool is_dismiss_button_highlighted_ = false;
  52. std::unique_ptr<SystemShadow> shadow_;
  53. // Updates the current a11y override window when the dismiss button is being
  54. // highlighted.
  55. std::unique_ptr<ScopedA11yOverrideWindowSetter> scoped_a11y_overrider_;
  56. };
  57. } // namespace ash
  58. #endif // ASH_STYLE_SYSTEM_TOAST_STYLE_H_