actionable_view.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2013 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_ACTIONABLE_VIEW_H_
  5. #define ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/tray/tray_popup_ink_drop_style.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. #include "ui/views/controls/button/button.h"
  10. namespace ash {
  11. // A focusable view that performs an action when user clicks on it, or presses
  12. // enter or space when focused. Note that the action is triggered on mouse-up,
  13. // instead of on mouse-down. So if user presses the mouse on the view, then
  14. // moves the mouse out of the view and then releases, then the action will not
  15. // be performed.
  16. // Exported for SystemTray.
  17. //
  18. // TODO(bruthig): Consider removing ActionableView and make clients use
  19. // Buttons instead. (See crbug.com/614453)
  20. class ASH_EXPORT ActionableView : public views::Button {
  21. public:
  22. static const char kViewClassName[];
  23. explicit ActionableView(TrayPopupInkDropStyle ink_drop_style);
  24. ActionableView(const ActionableView&) = delete;
  25. ActionableView& operator=(const ActionableView&) = delete;
  26. ~ActionableView() override;
  27. protected:
  28. // Performs an action when user clicks on the view (on mouse-press event), or
  29. // presses a key when this view is in focus. Returns true if the event has
  30. // been handled and an action was performed. Returns false otherwise.
  31. virtual bool PerformAction(const ui::Event& event) = 0;
  32. // Called after PerformAction() to act upon its result, including showing
  33. // appropriate ink drop ripple. This will not get called if the view is
  34. // destroyed during PerformAction(). Default implementation shows triggered
  35. // ripple if action is performed or hides existing ripple if no action is
  36. // performed. Subclasses can override to change the default behavior.
  37. virtual void HandlePerformActionResult(bool action_performed,
  38. const ui::Event& event);
  39. // Overridden from views::Button.
  40. const char* GetClassName() const override;
  41. bool OnKeyPressed(const ui::KeyEvent& event) override;
  42. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  43. private:
  44. void ButtonPressed(const ui::Event& event);
  45. // Used by ButtonPressed() to determine whether |this| has been destroyed as a
  46. // result of performing the associated action. This is necessary because in
  47. // the not-destroyed case ButtonPressed() uses member variables.
  48. bool* destroyed_ = nullptr;
  49. // Defines the flavor of ink drop ripple/highlight that should be constructed.
  50. const TrayPopupInkDropStyle ink_drop_style_;
  51. };
  52. } // namespace ash
  53. #endif // ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_