shelf_button_delegate.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_SHELF_SHELF_BUTTON_DELEGATE_H_
  5. #define ASH_SHELF_SHELF_BUTTON_DELEGATE_H_
  6. #include "ui/events/event.h"
  7. namespace ui {
  8. class Event;
  9. }
  10. namespace views {
  11. class Button;
  12. class InkDrop;
  13. } // namespace views
  14. namespace ash {
  15. class ShelfButton;
  16. // ShelfButtonDelegate is an interface to allow ShelfButtons to notify their
  17. // host view when they are pressed.
  18. // TODO(mohsen): A better approach would be to return a value indicating the
  19. // type of action performed such that the button can animate the ink drop.
  20. // Currently, it is not possible because showing menu is synchronous and blocks
  21. // the call. Fix this after menu is converted to asynchronous.
  22. class ShelfButtonDelegate {
  23. public:
  24. class ScopedActiveInkDropCount {
  25. public:
  26. virtual ~ScopedActiveInkDropCount() = default;
  27. };
  28. ShelfButtonDelegate() {}
  29. ShelfButtonDelegate(const ShelfButtonDelegate&) = delete;
  30. ShelfButtonDelegate& operator=(const ShelfButtonDelegate&) = delete;
  31. ~ShelfButtonDelegate() = default;
  32. // Used to let the host view redirect focus.
  33. virtual void OnShelfButtonAboutToRequestFocusFromTabTraversal(
  34. ShelfButton* button,
  35. bool reverse) = 0;
  36. // Notify the host view that the button was pressed. |ink_drop| is used to do
  37. // appropriate ink drop animation based on the action performed.
  38. virtual void ButtonPressed(views::Button* sender,
  39. const ui::Event& event,
  40. views::InkDrop* ink_drop) = 0;
  41. // Called when the shelf button handles the accessible action with type of
  42. // kScrollToMakeVisible. |button| is the view receiving the accessibility
  43. // focus.
  44. virtual void HandleAccessibleActionScrollToMakeVisible(ShelfButton* button) {}
  45. // Returns a scoped count that indicates whether |button| has an active ink
  46. // drop. |button| calls this to get the scoped count when its ink drop is
  47. // activated. It holds on to the scoped count until the ink drop is no longer
  48. // active.
  49. virtual std::unique_ptr<ScopedActiveInkDropCount>
  50. CreateScopedActiveInkDropCount(const ShelfButton* button);
  51. // Notifies the host view that one button will be removed.
  52. virtual void OnButtonWillBeRemoved() {}
  53. // Notifies the host view that the app button `button` is activated.
  54. virtual void OnAppButtonActivated(const ShelfButton* button) {}
  55. };
  56. } // namespace ash
  57. #endif // ASH_SHELF_SHELF_BUTTON_DELEGATE_H_