status_area_overflow_button_tray.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 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_SYSTEM_TRAY_STATUS_AREA_OVERFLOW_BUTTON_TRAY_H_
  5. #define ASH_SYSTEM_TRAY_STATUS_AREA_OVERFLOW_BUTTON_TRAY_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/status_area_widget.h"
  8. #include "ash/system/tray/tray_background_view.h"
  9. #include "ash/system/tray/tray_bubble_view.h"
  10. #include "ash/system/tray/tray_bubble_wrapper.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. #include "ui/gfx/animation/animation_delegate.h"
  13. #include "ui/gfx/canvas.h"
  14. #include "ui/gfx/geometry/transform.h"
  15. #include "ui/gfx/scoped_canvas.h"
  16. #include "ui/views/controls/image_view.h"
  17. namespace gfx {
  18. class SlideAnimation;
  19. } // namespace gfx
  20. namespace ash {
  21. // The collapse/expand tray button in tablet mode, which is shown when the
  22. // status area contains more buttons than the maximum width. Tapping on this
  23. // button will show/hide the overflown tray buttons.
  24. class ASH_EXPORT StatusAreaOverflowButtonTray : public TrayBackgroundView {
  25. public:
  26. explicit StatusAreaOverflowButtonTray(Shelf* shelf);
  27. StatusAreaOverflowButtonTray(const StatusAreaOverflowButtonTray&) = delete;
  28. StatusAreaOverflowButtonTray& operator=(const StatusAreaOverflowButtonTray&) =
  29. delete;
  30. ~StatusAreaOverflowButtonTray() override;
  31. enum State { CLICK_TO_EXPAND = 0, CLICK_TO_COLLAPSE };
  32. // TrayBackgroundView:
  33. void ClickedOutsideBubble() override;
  34. std::u16string GetAccessibleNameForTray() override;
  35. void HandleLocaleChange() override;
  36. void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
  37. void Initialize() override;
  38. bool PerformAction(const ui::Event& event) override;
  39. void SetVisiblePreferred(bool visible_preferred) override;
  40. void UpdateAfterStatusAreaCollapseChange() override;
  41. const char* GetClassName() const override;
  42. // Resets the state back to be collapsed (i.e. CLICK_TO_EXPAND).
  43. void ResetStateToCollapsed();
  44. State state() const { return state_; }
  45. private:
  46. // The button icon of an animating arrow based on the collapse/expand state.
  47. class IconView : public views::ImageView, public gfx::AnimationDelegate {
  48. public:
  49. IconView();
  50. ~IconView() override;
  51. void ToggleState(State state);
  52. private:
  53. // gfx::AnimationDelegate:
  54. void AnimationEnded(const gfx::Animation* animation) override;
  55. void AnimationProgressed(const gfx::Animation* animation) override;
  56. void AnimationCanceled(const gfx::Animation* animation) override;
  57. void UpdateRotation();
  58. const std::unique_ptr<gfx::SlideAnimation> slide_animation_;
  59. };
  60. State state_ = CLICK_TO_EXPAND;
  61. IconView* const icon_;
  62. };
  63. } // namespace ash
  64. #endif // ASH_SYSTEM_TRAY_STATUS_AREA_OVERFLOW_BUTTON_TRAY_H_