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 "mozilla/layers/LayersTypes.h" // for TouchBehaviorFlags 13 #include "mozilla/layers/ScrollableLayerGuid.h" // for ScrollableLayerGuid, etc 14 #include "mozilla/layers/ZoomConstraints.h" // for ZoomConstraints 15 #include "nsTArrayForwardDeclare.h" // for nsTArray, nsTArray_Impl, etc 16 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc 17 #include "Units.h" // for CSSRect, etc 18 19 namespace mozilla { 20 namespace layers { 21 22 class APZInputBridge; 23 class KeyboardMap; 24 struct ZoomTarget; 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 // If we are asked to zoom out but cannot (due to zoom constraints, etc), then 41 // zoom in some small amount to provide feedback to the user. 42 ZOOM_IN_IF_CANT_ZOOM_OUT = 1 << 3 43 }; 44 45 class AsyncDragMetrics; 46 struct APZHandledResult; 47 48 class IAPZCTreeManager { 49 NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING(IAPZCTreeManager) 50 51 public: 52 /** 53 * Set the keyboard shortcuts to use for translating keyboard events. 54 */ 55 virtual void SetKeyboardMap(const KeyboardMap& aKeyboardMap) = 0; 56 57 /** 58 * Kicks an animation to zoom to a rect. This may be either a zoom out or zoom 59 * in. The actual animation is done on the sampler thread after being set 60 * up. |aRect| must be given in CSS pixels, relative to the document. 61 * |aFlags| is a combination of the ZoomToRectBehavior enum values. 62 */ 63 virtual void ZoomToRect(const ScrollableLayerGuid& aGuid, 64 const ZoomTarget& aZoomTarget, 65 const uint32_t aFlags = DEFAULT_BEHAVIOR) = 0; 66 67 /** 68 * If we have touch listeners, this should always be called when we know 69 * definitively whether or not content has preventDefaulted any touch events 70 * that have come in. If |aPreventDefault| is true, any touch events in the 71 * queue will be discarded. This function must be called on the controller 72 * thread. 73 */ 74 virtual void ContentReceivedInputBlock(uint64_t aInputBlockId, 75 bool aPreventDefault) = 0; 76 77 /** 78 * When the event regions code is enabled, this function should be invoked to 79 * to confirm the target of the input block. This is only needed in cases 80 * where the initial input event of the block hit a dispatch-to-content region 81 * but is safe to call for all input blocks. This function should always be 82 * invoked on the controller thread. 83 * The different elements in the array of targets correspond to the targets 84 * for the different touch points. In the case where the touch point has no 85 * target, or the target is not a scrollable frame, the target's |mScrollId| 86 * should be set to ScrollableLayerGuid::NULL_SCROLL_ID. 87 */ 88 virtual void SetTargetAPZC(uint64_t aInputBlockId, 89 const nsTArray<ScrollableLayerGuid>& aTargets) = 0; 90 91 /** 92 * Updates any zoom constraints contained in the <meta name="viewport"> tag. 93 * If the |aConstraints| is Nothing() then previously-provided constraints for 94 * the given |aGuid| are cleared. 95 */ 96 virtual void UpdateZoomConstraints( 97 const ScrollableLayerGuid& aGuid, 98 const Maybe<ZoomConstraints>& aConstraints) = 0; 99 100 virtual void SetDPI(float aDpiValue) = 0; 101 102 /** 103 * Sets allowed touch behavior values for current touch-session for specific 104 * input block (determined by aInputBlock). 105 * Should be invoked by the widget. Each value of the aValues arrays 106 * corresponds to the different touch point that is currently active. 107 * Must be called after receiving the TOUCH_START event that starts the 108 * touch-session. 109 * This must be called on the controller thread. 110 */ 111 virtual void SetAllowedTouchBehavior( 112 uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aValues) = 0; 113 114 virtual void StartScrollbarDrag(const ScrollableLayerGuid& aGuid, 115 const AsyncDragMetrics& aDragMetrics) = 0; 116 117 virtual bool StartAutoscroll(const ScrollableLayerGuid& aGuid, 118 const ScreenPoint& aAnchorLocation) = 0; 119 120 virtual void StopAutoscroll(const ScrollableLayerGuid& aGuid) = 0; 121 122 /** 123 * Function used to disable LongTap gestures. 124 * 125 * On slow running tests, drags and touch events can be misinterpreted 126 * as a long tap. This allows tests to disable long tap gesture detection. 127 */ 128 virtual void SetLongTapEnabled(bool aTapGestureEnabled) = 0; 129 130 /** 131 * Returns an APZInputBridge interface that can be used to send input 132 * events to APZ in a synchronous manner. This will always be non-null, and 133 * the returned object's lifetime will match the lifetime of this 134 * IAPZCTreeManager implementation. 135 * It is only valid to call this function in the UI process. 136 */ 137 virtual APZInputBridge* InputBridge() = 0; 138 139 /** 140 * Add a callback to be invoked when |aInputBlockId| is ready for handling, 141 * with a boolean indicating whether the APZC handling the input block is 142 * the root content APZC. 143 * 144 * Should only be used for input blocks that are not yet ready for handling 145 * at the time this is called. If the input block was already handled, 146 * the callback will never be called. 147 * 148 * Only one callback can be registered for an input block at a time. 149 * Subsequent attempts to register a callback for an input block will be 150 * ignored until the existing callback is triggered. 151 * 152 * This is only implemented when the caller is in the same process as 153 * the APZCTreeManager. 154 */ 155 using InputBlockCallback = std::function<void( 156 uint64_t aInputBlockId, const APZHandledResult& aHandledResult)>; 157 virtual void AddInputBlockCallback(uint64_t aInputBlockId, 158 InputBlockCallback&& aCallback) = 0; 159 160 protected: 161 // Discourage destruction outside of decref 162 163 virtual ~IAPZCTreeManager() = default; 164 }; 165 166 } // namespace layers 167 } // namespace mozilla 168 169 #endif // mozilla_layers_IAPZCTreeManager_h 170