1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_layers_IAPZCTreeManager_h
8 #define mozilla_layers_IAPZCTreeManager_h
9 
10 #include <stdint.h>  // for uint64_t, uint32_t
11 
12 #include "FrameMetrics.h"             // for FrameMetrics, etc
13 #include "mozilla/EventForwards.h"    // for WidgetInputEvent, nsEventStatus
14 #include "mozilla/layers/APZUtils.h"  // for TouchBehaviorFlags, etc
15 #include "nsTArrayForwardDeclare.h"   // for nsTArray, nsTArray_Impl, etc
16 #include "nsISupportsImpl.h"          // for MOZ_COUNT_CTOR, etc
17 #include "Units.h"                    // for CSSPoint, CSSRect, etc
18 
19 namespace mozilla {
20 class InputData;
21 
22 namespace layers {
23 
24 class KeyboardMap;
25 
26 enum AllowedTouchBehavior {
27   NONE = 0,
28   VERTICAL_PAN = 1 << 0,
29   HORIZONTAL_PAN = 1 << 1,
30   PINCH_ZOOM = 1 << 2,
31   DOUBLE_TAP_ZOOM = 1 << 3,
32   UNKNOWN = 1 << 4
33 };
34 
35 enum ZoomToRectBehavior : uint32_t {
36   DEFAULT_BEHAVIOR = 0,
37   DISABLE_ZOOM_OUT = 1 << 0,
38   PAN_INTO_VIEW_ONLY = 1 << 1,
39   ONLY_ZOOM_TO_DEFAULT_SCALE = 1 << 2
40 };
41 
42 class AsyncDragMetrics;
43 
44 class IAPZCTreeManager {
45   NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING(IAPZCTreeManager)
46 
47  public:
48   /**
49    * General handler for incoming input events. Manipulates the frame metrics
50    * based on what type of input it is. For example, a PinchGestureEvent will
51    * cause scaling. This should only be called externally to this class, and
52    * must be called on the controller thread.
53    *
54    * This function transforms |aEvent| to have its coordinates in DOM space.
55    * This is so that the event can be passed through the DOM and content can
56    * handle them. The event may need to be converted to a WidgetInputEvent
57    * by the caller if it wants to do this.
58    *
59    * The following values may be returned by this function:
60    * nsEventStatus_eConsumeNoDefault is returned to indicate the
61    *   APZ is consuming this event and the caller should discard the event with
62    *   extreme prejudice. The exact scenarios under which this is returned is
63    *   implementation-dependent and may vary.
64    * nsEventStatus_eIgnore is returned to indicate that the APZ code didn't
65    *   use this event. This might be because it was directed at a point on
66    *   the screen where there was no APZ, or because the thing the user was
67    *   trying to do was not allowed. (For example, attempting to pan a
68    *   non-pannable document).
69    * nsEventStatus_eConsumeDoDefault is returned to indicate that the APZ
70    *   code may have used this event to do some user-visible thing. Note that
71    *   in some cases CONSUMED is returned even if the event was NOT used. This
72    *   is because we cannot always know at the time of event delivery whether
73    *   the event will be used or not. So we err on the side of sending
74    *   CONSUMED when we are uncertain.
75    *
76    * @param aEvent input event object; is modified in-place
77    * @param aOutTargetGuid returns the guid of the apzc this event was
78    * delivered to. May be null.
79    * @param aOutInputBlockId returns the id of the input block that this event
80    * was added to, if that was the case. May be null.
81    */
82   virtual nsEventStatus ReceiveInputEvent(InputData& aEvent,
83                                           ScrollableLayerGuid* aOutTargetGuid,
84                                           uint64_t* aOutInputBlockId) = 0;
85 
86   /**
87    * WidgetInputEvent handler. Transforms |aEvent| (which is assumed to be an
88    * already-existing instance of an WidgetInputEvent which may be an
89    * WidgetTouchEvent) to have its coordinates in DOM space. This is so that the
90    * event can be passed through the DOM and content can handle them.
91    *
92    * NOTE: Be careful of invoking the WidgetInputEvent variant. This can only be
93    * called on the main thread. See widget/InputData.h for more information on
94    * why we have InputData and WidgetInputEvent separated. If this function is
95    * used, the controller thread must be the main thread, or undefined behaviour
96    * may occur.
97    * NOTE: On unix, mouse events are treated as touch and are forwarded
98    * to the appropriate apz as such.
99    *
100    * See documentation for other ReceiveInputEvent above.
101    */
102   nsEventStatus ReceiveInputEvent(WidgetInputEvent& aEvent,
103                                   ScrollableLayerGuid* aOutTargetGuid,
104                                   uint64_t* aOutInputBlockId);
105 
106   /**
107    * Set the keyboard shortcuts to use for translating keyboard events.
108    */
109   virtual void SetKeyboardMap(const KeyboardMap& aKeyboardMap) = 0;
110 
111   /**
112    * Kicks an animation to zoom to a rect. This may be either a zoom out or zoom
113    * in. The actual animation is done on the sampler thread after being set
114    * up. |aRect| must be given in CSS pixels, relative to the document.
115    * |aFlags| is a combination of the ZoomToRectBehavior enum values.
116    */
117   virtual void ZoomToRect(const ScrollableLayerGuid& aGuid,
118                           const CSSRect& aRect,
119                           const uint32_t aFlags = DEFAULT_BEHAVIOR) = 0;
120 
121   /**
122    * If we have touch listeners, this should always be called when we know
123    * definitively whether or not content has preventDefaulted any touch events
124    * that have come in. If |aPreventDefault| is true, any touch events in the
125    * queue will be discarded. This function must be called on the controller
126    * thread.
127    */
128   virtual void ContentReceivedInputBlock(uint64_t aInputBlockId,
129                                          bool aPreventDefault) = 0;
130 
131   /**
132    * When the event regions code is enabled, this function should be invoked to
133    * to confirm the target of the input block. This is only needed in cases
134    * where the initial input event of the block hit a dispatch-to-content region
135    * but is safe to call for all input blocks. This function should always be
136    * invoked on the controller thread.
137    * The different elements in the array of targets correspond to the targets
138    * for the different touch points. In the case where the touch point has no
139    * target, or the target is not a scrollable frame, the target's |mScrollId|
140    * should be set to FrameMetrics::NULL_SCROLL_ID.
141    */
142   virtual void SetTargetAPZC(uint64_t aInputBlockId,
143                              const nsTArray<ScrollableLayerGuid>& aTargets) = 0;
144 
145   /**
146    * Updates any zoom constraints contained in the <meta name="viewport"> tag.
147    * If the |aConstraints| is Nothing() then previously-provided constraints for
148    * the given |aGuid| are cleared.
149    */
150   virtual void UpdateZoomConstraints(
151       const ScrollableLayerGuid& aGuid,
152       const Maybe<ZoomConstraints>& aConstraints) = 0;
153 
154   virtual void SetDPI(float aDpiValue) = 0;
155 
156   /**
157    * Sets allowed touch behavior values for current touch-session for specific
158    * input block (determined by aInputBlock).
159    * Should be invoked by the widget. Each value of the aValues arrays
160    * corresponds to the different touch point that is currently active.
161    * Must be called after receiving the TOUCH_START event that starts the
162    * touch-session.
163    * This must be called on the controller thread.
164    */
165   virtual void SetAllowedTouchBehavior(
166       uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aValues) = 0;
167 
168   virtual void StartScrollbarDrag(const ScrollableLayerGuid& aGuid,
169                                   const AsyncDragMetrics& aDragMetrics) = 0;
170 
171   virtual bool StartAutoscroll(const ScrollableLayerGuid& aGuid,
172                                const ScreenPoint& aAnchorLocation) = 0;
173 
174   virtual void StopAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
175 
176   /**
177    * Function used to disable LongTap gestures.
178    *
179    * On slow running tests, drags and touch events can be misinterpreted
180    * as a long tap. This allows tests to disable long tap gesture detection.
181    */
182   virtual void SetLongTapEnabled(bool aTapGestureEnabled) = 0;
183 
184   /**
185    * Process touch velocity.
186    * Sometimes the touch move event will have a velocity even though no
187    * scrolling is occurring such as when the toolbar is being hidden/shown in
188    * Fennec. This function can be called to have the y axis' velocity queue
189    * updated.
190    */
191   virtual void ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY) = 0;
192 
193   // Returns whether or not a wheel event action will be (or was) performed by
194   // APZ. If this returns true, the event must not perform a synchronous
195   // scroll.
196   //
197   // Even if this returns false, all wheel events in APZ-aware widgets must
198   // be sent through APZ so they are transformed correctly for TabParent.
199   static bool WillHandleWheelEvent(WidgetWheelEvent* aEvent);
200 
201  protected:
202   // Methods to help process WidgetInputEvents (or manage conversion to/from
203   // InputData)
204 
205   virtual void ProcessUnhandledEvent(LayoutDeviceIntPoint* aRefPoint,
206                                      ScrollableLayerGuid* aOutTargetGuid,
207                                      uint64_t* aOutFocusSequenceNumber) = 0;
208 
209   virtual void UpdateWheelTransaction(LayoutDeviceIntPoint aRefPoint,
210                                       EventMessage aEventMessage) = 0;
211 
212   // Discourage destruction outside of decref
213 
~IAPZCTreeManager()214   virtual ~IAPZCTreeManager() {}
215 };
216 
217 }  // namespace layers
218 }  // namespace mozilla
219 
220 #endif  // mozilla_layers_IAPZCTreeManager_h
221