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_GeckoContentController_h 8 #define mozilla_layers_GeckoContentController_h 9 10 #include "GeckoContentControllerTypes.h" 11 #include "InputData.h" // for PinchGestureInput 12 #include "LayersTypes.h" // for ScrollDirection 13 #include "Units.h" // for CSSPoint, CSSRect, etc 14 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 15 #include "mozilla/Attributes.h" // for MOZ_CAN_RUN_SCRIPT 16 #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM 17 #include "mozilla/EventForwards.h" // for Modifiers 18 #include "mozilla/layers/APZThreadUtils.h" 19 #include "mozilla/layers/MatrixMessage.h" // for MatrixMessage 20 #include "mozilla/layers/ScrollableLayerGuid.h" // for ScrollableLayerGuid, etc 21 #include "nsISupportsImpl.h" 22 23 namespace mozilla { 24 25 class Runnable; 26 27 namespace layers { 28 29 struct RepaintRequest; 30 31 class GeckoContentController { 32 public: 33 using APZStateChange = GeckoContentController_APZStateChange; 34 using TapType = GeckoContentController_TapType; 35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GeckoContentController) 36 37 /** 38 * Notifies the content side of the most recently computed transforms for 39 * each layers subtree to the root. The nsTArray will contain one 40 * MatrixMessage for each layers id in the current APZ tree, along with the 41 * corresponding transform. 42 */ 43 virtual void NotifyLayerTransforms(nsTArray<MatrixMessage>&& aTransforms) = 0; 44 45 /** 46 * Requests a paint of the given RepaintRequest |aRequest| from Gecko. 47 * Implementations per-platform are responsible for actually handling this. 48 * 49 * This method must always be called on the repaint thread, which depends 50 * on the GeckoContentController. For ChromeProcessController it is the 51 * Gecko main thread, while for RemoteContentController it is the compositor 52 * thread where it can send IPDL messages. 53 */ 54 virtual void RequestContentRepaint(const RepaintRequest& aRequest) = 0; 55 56 /** 57 * Requests handling of a tap event. |aPoint| is in LD pixels, relative to the 58 * current scroll offset. 59 */ 60 MOZ_CAN_RUN_SCRIPT 61 virtual void HandleTap(TapType aType, const LayoutDevicePoint& aPoint, 62 Modifiers aModifiers, const ScrollableLayerGuid& aGuid, 63 uint64_t aInputBlockId) = 0; 64 65 /** 66 * When the apz.allow_zooming pref is set to false, the APZ will not 67 * translate pinch gestures to actual zooming. Instead, it will call this 68 * method to notify gecko of the pinch gesture, and allow it to deal with it 69 * however it wishes. Note that this function is not called if the pinch is 70 * prevented by content calling preventDefault() on the touch events, or via 71 * use of the touch-action property. 72 * @param aType One of PINCHGESTURE_START, PINCHGESTURE_SCALE, 73 * PINCHGESTURE_FINGERLIFTED, or PINCHGESTURE_END, indicating the phase 74 * of the pinch. 75 * @param aGuid The guid of the APZ that is detecting the pinch. This is 76 * generally the root APZC for the layers id. 77 * @param aFocusPoint The focus point of the pinch event. 78 * @param aSpanChange For the START or END event, this is always 0. 79 * For a SCALE event, this is the difference in span between the 80 * previous state and the new state. 81 * @param aModifiers The keyboard modifiers depressed during the pinch. 82 */ 83 virtual void NotifyPinchGesture(PinchGestureInput::PinchGestureType aType, 84 const ScrollableLayerGuid& aGuid, 85 const LayoutDevicePoint& aFocusPoint, 86 LayoutDeviceCoord aSpanChange, 87 Modifiers aModifiers) = 0; 88 89 /** 90 * Schedules a runnable to run on the controller thread at some time 91 * in the future. 92 * This method must always be called on the controller thread. 93 */ PostDelayedTask(already_AddRefed<Runnable> aRunnable,int aDelayMs)94 virtual void PostDelayedTask(already_AddRefed<Runnable> aRunnable, 95 int aDelayMs) { 96 APZThreadUtils::DelayedDispatch(std::move(aRunnable), aDelayMs); 97 } 98 99 /** 100 * Returns true if we are currently on the thread that can send repaint 101 * requests. 102 */ 103 virtual bool IsRepaintThread() = 0; 104 105 /** 106 * Runs the given task on the "repaint" thread. 107 */ 108 virtual void DispatchToRepaintThread(already_AddRefed<Runnable> aTask) = 0; 109 110 /** 111 * General notices of APZ state changes for consumers. 112 * |aGuid| identifies the APZC originating the state change. 113 * |aChange| identifies the type of state change 114 * |aArg| is used by some state changes to pass extra information (see 115 * the documentation for each state change above) 116 */ 117 virtual void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid, 118 APZStateChange aChange, int aArg = 0) {} 119 120 /** 121 * Notify content of a MozMouseScrollFailed event. 122 */ NotifyMozMouseScrollEvent(const ScrollableLayerGuid::ViewID & aScrollId,const nsString & aEvent)123 virtual void NotifyMozMouseScrollEvent( 124 const ScrollableLayerGuid::ViewID& aScrollId, const nsString& aEvent) {} 125 126 /** 127 * Notify content that the repaint requests have been flushed. 128 */ 129 virtual void NotifyFlushComplete() = 0; 130 131 /** 132 * If the async scrollbar-drag initiation code kicks in on the APZ side, then 133 * we need to let content know that we are dragging the scrollbar. Otherwise, 134 * by the time the mousedown events is handled by content, the scrollthumb 135 * could already have been moved via a RequestContentRepaint message at a 136 * new scroll position, and the mousedown might end up triggering a click-to- 137 * scroll on where the thumb used to be. 138 */ 139 virtual void NotifyAsyncScrollbarDragInitiated( 140 uint64_t aDragBlockId, const ScrollableLayerGuid::ViewID& aScrollId, 141 ScrollDirection aDirection) = 0; 142 virtual void NotifyAsyncScrollbarDragRejected( 143 const ScrollableLayerGuid::ViewID& aScrollId) = 0; 144 145 virtual void NotifyAsyncAutoscrollRejected( 146 const ScrollableLayerGuid::ViewID& aScrollId) = 0; 147 148 virtual void CancelAutoscroll(const ScrollableLayerGuid& aGuid) = 0; 149 UpdateOverscrollVelocity(const ScrollableLayerGuid & aGuid,float aX,float aY,bool aIsRootContent)150 virtual void UpdateOverscrollVelocity(const ScrollableLayerGuid& aGuid, 151 float aX, float aY, 152 bool aIsRootContent) {} UpdateOverscrollOffset(const ScrollableLayerGuid & aGuid,float aX,float aY,bool aIsRootContent)153 virtual void UpdateOverscrollOffset(const ScrollableLayerGuid& aGuid, 154 float aX, float aY, bool aIsRootContent) { 155 } 156 157 GeckoContentController() = default; 158 159 /** 160 * Needs to be called on the main thread. 161 */ Destroy()162 virtual void Destroy() {} 163 164 /** 165 * Whether this is RemoteContentController. 166 */ IsRemote()167 virtual bool IsRemote() { return false; } 168 GetTopLevelPresShell()169 virtual PresShell* GetTopLevelPresShell() const { return nullptr; }; 170 171 protected: 172 // Protected destructor, to discourage deletion outside of Release(): 173 virtual ~GeckoContentController() = default; 174 }; 175 176 } // namespace layers 177 } // namespace mozilla 178 179 #endif // mozilla_layers_GeckoContentController_h 180