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