ink_drop_event_handler.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 UI_VIEWS_ANIMATION_INK_DROP_EVENT_HANDLER_H_
  5. #define UI_VIEWS_ANIMATION_INK_DROP_EVENT_HANDLER_H_
  6. #include <memory>
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/scoped_observation.h"
  9. #include "base/strings/string_piece.h"
  10. #include "ui/events/event_handler.h"
  11. #include "ui/views/view.h"
  12. #include "ui/views/view_observer.h"
  13. #include "ui/views/views_export.h"
  14. namespace ui {
  15. class LocatedEvent;
  16. class ScopedTargetHandler;
  17. } // namespace ui
  18. namespace views {
  19. class InkDrop;
  20. enum class InkDropState;
  21. struct ViewHierarchyChangedDetails;
  22. // This class handles ink-drop changes due to events on its host.
  23. class VIEWS_EXPORT InkDropEventHandler : public ui::EventHandler,
  24. public ViewObserver {
  25. public:
  26. // Delegate class that allows InkDropEventHandler to be used with InkDrops
  27. // that are hosted in multiple ways.
  28. class Delegate {
  29. public:
  30. // Gets the InkDrop (or stub) that should react to incoming events.
  31. virtual InkDrop* GetInkDrop() = 0;
  32. virtual bool HasInkDrop() const = 0;
  33. // Returns true if gesture events should affect the InkDrop.
  34. virtual bool SupportsGestureEvents() const = 0;
  35. };
  36. InkDropEventHandler(View* host_view, Delegate* delegate);
  37. InkDropEventHandler(const InkDropEventHandler&) = delete;
  38. InkDropEventHandler& operator=(const InkDropEventHandler&) = delete;
  39. ~InkDropEventHandler() override;
  40. void AnimateToState(InkDropState state, const ui::LocatedEvent* event);
  41. ui::LocatedEvent* GetLastRippleTriggeringEvent() const;
  42. private:
  43. // ui::EventHandler:
  44. void OnGestureEvent(ui::GestureEvent* event) override;
  45. void OnMouseEvent(ui::MouseEvent* event) override;
  46. base::StringPiece GetLogContext() const override;
  47. // ViewObserver:
  48. void OnViewVisibilityChanged(View* observed_view,
  49. View* starting_view) override;
  50. void OnViewHierarchyChanged(
  51. View* observed_view,
  52. const ViewHierarchyChangedDetails& details) override;
  53. void OnViewBoundsChanged(View* observed_view) override;
  54. void OnViewFocused(View* observed_view) override;
  55. void OnViewBlurred(View* observed_view) override;
  56. // Allows |this| to handle all GestureEvents on |host_view_|.
  57. std::unique_ptr<ui::ScopedTargetHandler> target_handler_;
  58. // The host view.
  59. const raw_ptr<View> host_view_;
  60. // Delegate used to get the InkDrop, etc.
  61. const raw_ptr<Delegate> delegate_;
  62. // The last user Event to trigger an InkDrop-ripple animation.
  63. std::unique_ptr<ui::LocatedEvent> last_ripple_triggering_event_;
  64. base::ScopedObservation<View, ViewObserver> observation_{this};
  65. };
  66. } // namespace views
  67. #endif // UI_VIEWS_ANIMATION_INK_DROP_EVENT_HANDLER_H_