compositor_input_interfaces.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2020 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 CC_INPUT_COMPOSITOR_INPUT_INTERFACES_H_
  5. #define CC_INPUT_COMPOSITOR_INPUT_INTERFACES_H_
  6. #include <memory>
  7. #include "base/time/time.h"
  8. #include "cc/input/actively_scrolling_type.h"
  9. #include "cc/paint/element_id.h"
  10. #include "ui/gfx/geometry/size.h"
  11. namespace viz {
  12. struct BeginFrameArgs;
  13. }
  14. namespace gfx {
  15. class Vector2dF;
  16. }
  17. namespace cc {
  18. struct CompositorCommitData;
  19. class LayerTreeHostImpl;
  20. class LayerTreeSettings;
  21. class ScrollTree;
  22. enum class ScrollbarOrientation;
  23. // This is the interface that LayerTreeHostImpl and the "graphics" side of the
  24. // compositor uses to talk to the compositor InputHandler. This interface is
  25. // two-way; it's used used both to communicate state changes from the LayerTree
  26. // to the input handler and also to query and update state in the input handler.
  27. class InputDelegateForCompositor {
  28. public:
  29. virtual ~InputDelegateForCompositor() = default;
  30. // Called during a commit to fill in the changes that have occurred since the
  31. // last commit.
  32. virtual void ProcessCommitDeltas(CompositorCommitData* commit_data) = 0;
  33. // Called to let the input handler perform animations.
  34. virtual void TickAnimations(base::TimeTicks monotonic_time) = 0;
  35. // Compositor lifecycle state observation.
  36. virtual void WillShutdown() = 0;
  37. virtual void WillDraw() = 0;
  38. virtual void WillBeginImplFrame(const viz::BeginFrameArgs& args) = 0;
  39. virtual void DidCommit() = 0;
  40. virtual void DidActivatePendingTree() = 0;
  41. // Called when the state of the "root layer" may have changed from outside
  42. // the input system. The state includes: scroll offset, scrollable size,
  43. // scroll limits, page scale, page scale limits.
  44. virtual void RootLayerStateMayHaveChanged() = 0;
  45. // Called to let the input handler know that a scrollbar for the given
  46. // elementId has been added.
  47. virtual void DidRegisterScrollbar(ElementId scroll_element_id,
  48. ScrollbarOrientation orientation) = 0;
  49. // Called to let the input handler know that a scrollbar for the given
  50. // elementId has been removed.
  51. virtual void DidUnregisterScrollbar(ElementId scroll_element_id,
  52. ScrollbarOrientation orientation) = 0;
  53. // Called to let the input handler know that a scroll offset animation has
  54. // completed.
  55. virtual void ScrollOffsetAnimationFinished() = 0;
  56. // Called to inform the input handler when prefers-reduced-motion changes.
  57. virtual void SetPrefersReducedMotion(bool prefers_reduced_motion) = 0;
  58. // Returns true if we're currently in a "gesture" (user-initiated) scroll.
  59. // That is, between a GestureScrollBegin and a GestureScrollEnd. Note, a
  60. // GestureScrollEnd is deferred if the gesture ended but we're still
  61. // animating the scroll to its final position (e.g. the user released their
  62. // finger from the touchscreen but we're scroll snapping).
  63. virtual bool IsCurrentlyScrolling() const = 0;
  64. // Indicates the type (Animated or Precise) of an active scroll, if there is
  65. // one, in progress. "Active" here means that it's been latched (i.e. we have
  66. // a CurrentlyScrollingNode()) but also that some ScrollUpdates have been
  67. // received and their delta consumed for scrolling. These can differ
  68. // significantly e.g. the page allows the touchstart but preventDefaults all
  69. // the touchmoves. In that case, we latch and have a CurrentlyScrollingNode()
  70. // but will never receive a ScrollUpdate.
  71. virtual ActivelyScrollingType GetActivelyScrollingType() const = 0;
  72. };
  73. // This is the interface that's exposed by the LayerTreeHostImpl to the input
  74. // handler.
  75. class CompositorDelegateForInput {
  76. public:
  77. virtual ~CompositorDelegateForInput() = default;
  78. virtual void BindToInputHandler(
  79. std::unique_ptr<InputDelegateForCompositor> delegate) = 0;
  80. virtual ScrollTree& GetScrollTree() const = 0;
  81. virtual bool HasAnimatedScrollbars() const = 0;
  82. virtual void SetNeedsCommit() = 0;
  83. virtual void SetNeedsFullViewportRedraw() = 0;
  84. virtual void SetDeferBeginMainFrame(bool defer_begin_main_frame) const = 0;
  85. virtual void DidUpdateScrollAnimationCurve() = 0;
  86. virtual void AccumulateScrollDeltaForTracing(const gfx::Vector2dF& delta) = 0;
  87. virtual void DidStartPinchZoom() = 0;
  88. virtual void DidUpdatePinchZoom() = 0;
  89. virtual void DidEndPinchZoom() = 0;
  90. virtual void DidStartScroll() = 0;
  91. virtual void DidEndScroll() = 0;
  92. virtual void DidMouseLeave() = 0;
  93. virtual bool IsInHighLatencyMode() const = 0;
  94. virtual void WillScrollContent(ElementId element_id) = 0;
  95. virtual void DidScrollContent(ElementId element_id, bool animated) = 0;
  96. virtual float DeviceScaleFactor() const = 0;
  97. virtual float PageScaleFactor() const = 0;
  98. virtual gfx::Size VisualDeviceViewportSize() const = 0;
  99. virtual const LayerTreeSettings& GetSettings() const = 0;
  100. // TODO(bokan): Temporary escape hatch for code that hasn't yet been
  101. // converted to use the input<->compositor interface. This will eventually be
  102. // removed.
  103. virtual LayerTreeHostImpl& GetImplDeprecated() = 0;
  104. virtual const LayerTreeHostImpl& GetImplDeprecated() const = 0;
  105. };
  106. } // namespace cc
  107. #endif // CC_INPUT_COMPOSITOR_INPUT_INTERFACES_H_