APZCTreeManagerChild.cpp (6798B)
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 #include "mozilla/layers/APZCTreeManagerChild.h" 8 9 #include "InputData.h" // for InputData 10 #include "mozilla/dom/BrowserParent.h" // for BrowserParent 11 #include "mozilla/layers/APZCCallbackHelper.h" // for APZCCallbackHelper 12 #include "mozilla/layers/APZInputBridgeChild.h" // for APZInputBridgeChild 13 #include "mozilla/layers/GeckoContentController.h" // for GeckoContentController 14 #include "mozilla/layers/DoubleTapToZoom.h" // for DoubleTapToZoomMetrics 15 #include "mozilla/layers/RemoteCompositorSession.h" // for RemoteCompositorSession 16 #ifdef MOZ_WIDGET_ANDROID 17 # include "mozilla/jni/Utils.h" // for DispatchToGeckoPriorityQueue 18 #endif 19 20 namespace mozilla { 21 namespace layers { 22 23 APZCTreeManagerChild::APZCTreeManagerChild() 24 : mCompositorSession(nullptr), mIPCOpen(false) {} 25 26 APZCTreeManagerChild::~APZCTreeManagerChild() = default; 27 28 void APZCTreeManagerChild::SetCompositorSession( 29 RemoteCompositorSession* aSession) { 30 // Exactly one of mCompositorSession and aSession must be null (i.e. either 31 // we're setting mCompositorSession or we're clearing it). 32 MOZ_ASSERT(!mCompositorSession ^ !aSession); 33 mCompositorSession = aSession; 34 if (mInputBridge) { 35 mInputBridge->SetCompositorSession(aSession); 36 } 37 } 38 39 void APZCTreeManagerChild::SetInputBridge(APZInputBridgeChild* aInputBridge) { 40 // The input bridge only exists from the UI process to the GPU process. 41 MOZ_ASSERT(XRE_IsParentProcess()); 42 MOZ_ASSERT(!mInputBridge); 43 44 mInputBridge = aInputBridge; 45 } 46 47 void APZCTreeManagerChild::Destroy() { 48 MOZ_ASSERT(NS_IsMainThread()); 49 if (mInputBridge) { 50 mInputBridge->Destroy(); 51 mInputBridge = nullptr; 52 } 53 } 54 55 void APZCTreeManagerChild::SetKeyboardMap(const KeyboardMap& aKeyboardMap) { 56 MOZ_ASSERT(NS_IsMainThread()); 57 SendSetKeyboardMap(aKeyboardMap); 58 } 59 60 void APZCTreeManagerChild::ZoomToRect(const ScrollableLayerGuid& aGuid, 61 const ZoomTarget& aZoomTarget, 62 const uint32_t aFlags) { 63 MOZ_ASSERT(NS_IsMainThread()); 64 SendZoomToRect(aGuid, aZoomTarget, aFlags); 65 } 66 67 void APZCTreeManagerChild::ContentReceivedInputBlock(uint64_t aInputBlockId, 68 bool aPreventDefault) { 69 MOZ_ASSERT(NS_IsMainThread()); 70 SendContentReceivedInputBlock(aInputBlockId, aPreventDefault); 71 } 72 73 void APZCTreeManagerChild::SetTargetAPZC( 74 uint64_t aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) { 75 MOZ_ASSERT(NS_IsMainThread()); 76 SendSetTargetAPZC(aInputBlockId, aTargets); 77 } 78 79 void APZCTreeManagerChild::UpdateZoomConstraints( 80 const ScrollableLayerGuid& aGuid, 81 const Maybe<ZoomConstraints>& aConstraints) { 82 MOZ_ASSERT(NS_IsMainThread()); 83 if (mIPCOpen) { 84 SendUpdateZoomConstraints(aGuid, aConstraints); 85 } 86 } 87 88 void APZCTreeManagerChild::SetDPI(float aDpiValue) { 89 MOZ_ASSERT(NS_IsMainThread()); 90 SendSetDPI(aDpiValue); 91 } 92 93 void APZCTreeManagerChild::SetAllowedTouchBehavior( 94 uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aValues) { 95 MOZ_ASSERT(NS_IsMainThread()); 96 SendSetAllowedTouchBehavior(aInputBlockId, aValues); 97 } 98 99 void APZCTreeManagerChild::SetBrowserGestureResponse( 100 uint64_t aInputBlockId, BrowserGestureResponse aResponse) { 101 MOZ_ASSERT(NS_IsMainThread()); 102 SendSetBrowserGestureResponse(aInputBlockId, aResponse); 103 } 104 105 void APZCTreeManagerChild::StartScrollbarDrag( 106 const ScrollableLayerGuid& aGuid, const AsyncDragMetrics& aDragMetrics) { 107 MOZ_ASSERT(NS_IsMainThread()); 108 SendStartScrollbarDrag(aGuid, aDragMetrics); 109 } 110 111 bool APZCTreeManagerChild::StartAutoscroll(const ScrollableLayerGuid& aGuid, 112 const ScreenPoint& aAnchorLocation) { 113 MOZ_ASSERT(NS_IsMainThread()); 114 return SendStartAutoscroll(aGuid, aAnchorLocation); 115 } 116 117 void APZCTreeManagerChild::StopAutoscroll(const ScrollableLayerGuid& aGuid) { 118 MOZ_ASSERT(NS_IsMainThread()); 119 SendStopAutoscroll(aGuid); 120 } 121 122 void APZCTreeManagerChild::SetLongTapEnabled(bool aTapGestureEnabled) { 123 MOZ_ASSERT(NS_IsMainThread()); 124 SendSetLongTapEnabled(aTapGestureEnabled); 125 } 126 127 APZInputBridge* APZCTreeManagerChild::InputBridge() { 128 MOZ_ASSERT(XRE_IsParentProcess()); 129 MOZ_ASSERT(mInputBridge); 130 131 return mInputBridge.get(); 132 } 133 134 void APZCTreeManagerChild::AddIPDLReference() { 135 MOZ_ASSERT(mIPCOpen == false); 136 mIPCOpen = true; 137 AddRef(); 138 } 139 140 void APZCTreeManagerChild::ReleaseIPDLReference() { 141 mIPCOpen = false; 142 Release(); 143 } 144 145 void APZCTreeManagerChild::ActorDestroy(ActorDestroyReason aWhy) { 146 mIPCOpen = false; 147 } 148 149 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvNotifyPinchGesture( 150 const PinchGestureType& aType, const ScrollableLayerGuid& aGuid, 151 const LayoutDevicePoint& aFocusPoint, const LayoutDeviceCoord& aSpanChange, 152 const Modifiers& aModifiers) { 153 // This will only get sent from the GPU process to the parent process, so 154 // this function should never get called in the content process. 155 MOZ_ASSERT(XRE_IsParentProcess()); 156 MOZ_ASSERT(NS_IsMainThread()); 157 158 // We want to handle it in this process regardless of what the target guid 159 // of the pinch is. This may change in the future. 160 if (mCompositorSession && mCompositorSession->GetWidget()) { 161 APZCCallbackHelper::NotifyPinchGesture(aType, aFocusPoint, aSpanChange, 162 aModifiers, 163 mCompositorSession->GetWidget()); 164 } 165 return IPC_OK(); 166 } 167 168 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvCancelAutoscroll( 169 const ScrollableLayerGuid::ViewID& aScrollId) { 170 // This will only get sent from the GPU process to the parent process, so 171 // this function should never get called in the content process. 172 MOZ_ASSERT(XRE_IsParentProcess()); 173 MOZ_ASSERT(NS_IsMainThread()); 174 175 APZCCallbackHelper::CancelAutoscroll(aScrollId); 176 return IPC_OK(); 177 } 178 179 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvNotifyScaleGestureComplete( 180 const ScrollableLayerGuid::ViewID& aScrollId, float aScale) { 181 // This will only get sent from the GPU process to the parent process, so 182 // this function should never get called in the content process. 183 MOZ_ASSERT(XRE_IsParentProcess()); 184 MOZ_ASSERT(NS_IsMainThread()); 185 186 if (mCompositorSession && mCompositorSession->GetWidget()) { 187 APZCCallbackHelper::NotifyScaleGestureComplete( 188 mCompositorSession->GetWidget(), aScale); 189 } 190 return IPC_OK(); 191 } 192 193 } // namespace layers 194 } // namespace mozilla