notification_swipe_control_view.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2018 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_MESSAGE_CENTER_NOTIFICATION_SWIPE_CONTROL_VIEW_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_NOTIFICATION_SWIPE_CONTROL_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "base/gtest_prod_util.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/observer_list_types.h"
  10. #include "third_party/skia/include/core/SkColor.h"
  11. #include "ui/gfx/animation/animation_delegate.h"
  12. #include "ui/views/controls/button/image_button.h"
  13. #include "ui/views/view.h"
  14. namespace message_center {
  15. class MessageView;
  16. } // namespace message_center
  17. namespace ash {
  18. // View containing 2 buttons that appears behind notification by swiping.
  19. class ASH_EXPORT NotificationSwipeControlView : public views::View {
  20. public:
  21. // Physical positions to show buttons in the swipe control. This is invariant
  22. // across RTL/LTR languages because buttons should be shown on one side which
  23. // is made uncovered by the overlapping view after user's swipe action.
  24. enum class ButtonPosition { RIGHT, LEFT };
  25. // String to be returned by GetClassName() method.
  26. static const char kViewClassName[];
  27. explicit NotificationSwipeControlView(
  28. message_center::MessageView* message_view);
  29. NotificationSwipeControlView(const NotificationSwipeControlView&) = delete;
  30. NotificationSwipeControlView& operator=(const NotificationSwipeControlView&) =
  31. delete;
  32. ~NotificationSwipeControlView() override;
  33. // views::View
  34. const char* GetClassName() const override;
  35. // Update the visibility of control buttons.
  36. void UpdateButtonsVisibility();
  37. // Update the radii of background corners.
  38. void UpdateCornerRadius(int top_radius, int bottom_radius);
  39. private:
  40. FRIEND_TEST_ALL_PREFIXES(NotificationSwipeControlViewTest,
  41. DeleteOnSettingsButtonPressed);
  42. FRIEND_TEST_ALL_PREFIXES(NotificationSwipeControlViewTest,
  43. DeleteOnSnoozeButtonPressed);
  44. FRIEND_TEST_ALL_PREFIXES(NotificationSwipeControlViewTest,
  45. SettingsButtonVisibility);
  46. enum class ButtonId {
  47. kSettings,
  48. kSnooze,
  49. };
  50. // Change the visibility of the settings and snooze button.
  51. void ShowButtons(ButtonPosition button_position,
  52. bool show_settings,
  53. bool show_snooze);
  54. void HideButtons();
  55. // Change the visibility of the settings button. True to show, false to hide.
  56. void ShowSettingsButton(bool show);
  57. // Change the visibility of the snooze button. True to show, false to hide.
  58. void ShowSnoozeButton(bool show);
  59. void ButtonPressed(ButtonId button, const ui::Event& event);
  60. message_center::MessageView* const message_view_;
  61. // Owned by views hierarchy.
  62. views::ImageButton* settings_button_ = nullptr;
  63. views::ImageButton* snooze_button_ = nullptr;
  64. base::WeakPtrFactory<NotificationSwipeControlView> weak_factory_{this};
  65. };
  66. } // namespace ash
  67. #endif // ASH_SYSTEM_MESSAGE_CENTER_NOTIFICATION_SWIPE_CONTROL_VIEW_H_