shelf_shutdown_confirmation_bubble.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_SHELF_SHELF_SHUTDOWN_CONFIRMATION_BUBBLE_H_
  5. #define ASH_SHELF_SHELF_SHUTDOWN_CONFIRMATION_BUBBLE_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/shelf_types.h"
  8. #include "ash/shelf/shelf_bubble.h"
  9. #include "ash/style/default_colors.h"
  10. #include "base/callback_forward.h"
  11. #include "base/time/time.h"
  12. #include "ui/gfx/geometry/size.h"
  13. #include "ui/views/controls/button/label_button.h"
  14. #include "ui/views/controls/image_view.h"
  15. #include "ui/views/controls/label.h"
  16. #include "ui/views/view.h"
  17. namespace views {
  18. class BubbleDialogDelegateView;
  19. class View;
  20. } // namespace views
  21. namespace ash {
  22. // The implementation of tooltip bubbles for the shelf.
  23. class ASH_EXPORT ShelfShutdownConfirmationBubble : public ShelfBubble {
  24. public:
  25. enum class ButtonId {
  26. // We start from 1 because 0 is the default view ID.
  27. kShutdown = 1, // Shut down the device.
  28. kCancel, // Cancel shutdown.
  29. };
  30. // Enum used for UMA. Do NOT reorder or remove entry. Don't forget to
  31. // update ShutdownConfirmationBubbleAction enum in enums.xml when adding new
  32. // entries.
  33. enum BubbleAction {
  34. kOpened = 0,
  35. kCancelled = 1,
  36. kConfirmed = 2,
  37. kDismissed = 3,
  38. kMaxValue
  39. };
  40. ShelfShutdownConfirmationBubble(views::View* anchor,
  41. ShelfAlignment alignment,
  42. base::OnceClosure on_confirm_callback,
  43. base::OnceClosure on_cancel_callback);
  44. ShelfShutdownConfirmationBubble(const ShelfShutdownConfirmationBubble&) =
  45. delete;
  46. ShelfShutdownConfirmationBubble& operator=(
  47. const ShelfShutdownConfirmationBubble&) = delete;
  48. ~ShelfShutdownConfirmationBubble() override;
  49. // views::View:
  50. void OnThemeChanged() override;
  51. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  52. std::u16string GetAccessibleWindowTitle() const override;
  53. protected:
  54. // ShelfBubble:
  55. bool ShouldCloseOnPressDown() override;
  56. bool ShouldCloseOnMouseExit() override;
  57. private:
  58. // BubbleDialogDelegateView overrides:
  59. gfx::Size CalculatePreferredSize() const override;
  60. // Callback functions of cancel and confirm buttons
  61. void OnCancelled();
  62. void OnConfirmed();
  63. void OnClosed();
  64. base::OnceClosure confirm_callback_;
  65. base::OnceClosure cancel_callback_;
  66. // Report bubble action metrics
  67. void ReportBubbleAction(BubbleAction action);
  68. views::ImageView* icon_ = nullptr;
  69. views::Label* title_ = nullptr;
  70. views::LabelButton* cancel_ = nullptr;
  71. views::LabelButton* confirm_ = nullptr;
  72. enum class DialogResult { kNone, kCancelled, kConfirmed };
  73. // A simple state machine to keep track of the dialog result.
  74. DialogResult dialog_result_{DialogResult::kNone};
  75. // Track time delta between bubble opened to an action taken
  76. base::TimeTicks bubble_opened_timestamp_;
  77. };
  78. } // namespace ash
  79. #endif // ASH_SHELF_SHELF_SHUTDOWN_CONFIRMATION_BUBBLE_H_