system_nudge_label.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2022 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_SYSTEM_NUDGE_LABEL_H_
  5. #define ASH_SYSTEM_TRAY_SYSTEM_NUDGE_LABEL_H_
  6. #include "base/containers/flat_map.h"
  7. #include "ui/gfx/range/range.h"
  8. #include "ui/views/controls/styled_label.h"
  9. #include "ui/views/view.h"
  10. namespace ash {
  11. // A label for system nudges which automatically updates text color on theme
  12. // changes and supports inline embedding of custom views.
  13. class SystemNudgeLabel : public views::View {
  14. public:
  15. SystemNudgeLabel(std::u16string text, int fixed_width);
  16. SystemNudgeLabel(const SystemNudgeLabel&) = delete;
  17. SystemNudgeLabel& operator=(const SystemNudgeLabel&) = delete;
  18. ~SystemNudgeLabel() override;
  19. // Passes ownership of a custom view, so that the system nudge can have a
  20. // custom view within its text located at the `offset`.
  21. void AddCustomView(std::unique_ptr<View> custom_view, size_t offset);
  22. const std::u16string& GetText() const;
  23. void set_font_size_delta(int font_size_delta) {
  24. font_size_delta_ = font_size_delta;
  25. }
  26. // views::View:
  27. void OnThemeChanged() override;
  28. private:
  29. views::StyledLabel* const styled_label_;
  30. base::flat_map<size_t, views::StyledLabel::RangeStyleInfo>
  31. custom_view_styles_by_offset_;
  32. int font_size_delta_ = 0;
  33. };
  34. } // namespace ash
  35. #endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_LABEL_H_