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/TabParent.h" // for TabParent
11 #include "mozilla/layers/APZCCallbackHelper.h" // for APZCCallbackHelper
12 #include "mozilla/layers/RemoteCompositorSession.h" // for RemoteCompositorSession
13
14 namespace mozilla {
15 namespace layers {
16
APZCTreeManagerChild()17 APZCTreeManagerChild::APZCTreeManagerChild() : mCompositorSession(nullptr) {}
18
SetCompositorSession(RemoteCompositorSession * aSession)19 void APZCTreeManagerChild::SetCompositorSession(
20 RemoteCompositorSession* aSession) {
21 // Exactly one of mCompositorSession and aSession must be null (i.e. either
22 // we're setting mCompositorSession or we're clearing it).
23 MOZ_ASSERT(!mCompositorSession ^ !aSession);
24 mCompositorSession = aSession;
25 }
26
ReceiveInputEvent(InputData & aEvent,ScrollableLayerGuid * aOutTargetGuid,uint64_t * aOutInputBlockId)27 nsEventStatus APZCTreeManagerChild::ReceiveInputEvent(
28 InputData& aEvent, ScrollableLayerGuid* aOutTargetGuid,
29 uint64_t* aOutInputBlockId) {
30 switch (aEvent.mInputType) {
31 case MULTITOUCH_INPUT: {
32 MultiTouchInput& event = aEvent.AsMultiTouchInput();
33 MultiTouchInput processedEvent;
34
35 nsEventStatus res;
36 SendReceiveMultiTouchInputEvent(event, &res, &processedEvent,
37 aOutTargetGuid, aOutInputBlockId);
38
39 event = processedEvent;
40 return res;
41 }
42 case MOUSE_INPUT: {
43 MouseInput& event = aEvent.AsMouseInput();
44 MouseInput processedEvent;
45
46 nsEventStatus res;
47 SendReceiveMouseInputEvent(event, &res, &processedEvent, aOutTargetGuid,
48 aOutInputBlockId);
49
50 event = processedEvent;
51 return res;
52 }
53 case PANGESTURE_INPUT: {
54 PanGestureInput& event = aEvent.AsPanGestureInput();
55 PanGestureInput processedEvent;
56
57 nsEventStatus res;
58 SendReceivePanGestureInputEvent(event, &res, &processedEvent,
59 aOutTargetGuid, aOutInputBlockId);
60
61 event = processedEvent;
62 return res;
63 }
64 case PINCHGESTURE_INPUT: {
65 PinchGestureInput& event = aEvent.AsPinchGestureInput();
66 PinchGestureInput processedEvent;
67
68 nsEventStatus res;
69 SendReceivePinchGestureInputEvent(event, &res, &processedEvent,
70 aOutTargetGuid, aOutInputBlockId);
71
72 event = processedEvent;
73 return res;
74 }
75 case TAPGESTURE_INPUT: {
76 TapGestureInput& event = aEvent.AsTapGestureInput();
77 TapGestureInput processedEvent;
78
79 nsEventStatus res;
80 SendReceiveTapGestureInputEvent(event, &res, &processedEvent,
81 aOutTargetGuid, aOutInputBlockId);
82
83 event = processedEvent;
84 return res;
85 }
86 case SCROLLWHEEL_INPUT: {
87 ScrollWheelInput& event = aEvent.AsScrollWheelInput();
88 ScrollWheelInput processedEvent;
89
90 nsEventStatus res;
91 SendReceiveScrollWheelInputEvent(event, &res, &processedEvent,
92 aOutTargetGuid, aOutInputBlockId);
93
94 event = processedEvent;
95 return res;
96 }
97 case KEYBOARD_INPUT: {
98 KeyboardInput& event = aEvent.AsKeyboardInput();
99 KeyboardInput processedEvent;
100
101 nsEventStatus res;
102 SendReceiveKeyboardInputEvent(event, &res, &processedEvent,
103 aOutTargetGuid, aOutInputBlockId);
104
105 event = processedEvent;
106 return res;
107 }
108 default: {
109 MOZ_ASSERT_UNREACHABLE("Invalid InputData type.");
110 return nsEventStatus_eConsumeNoDefault;
111 }
112 }
113 }
114
SetKeyboardMap(const KeyboardMap & aKeyboardMap)115 void APZCTreeManagerChild::SetKeyboardMap(const KeyboardMap& aKeyboardMap) {
116 SendSetKeyboardMap(aKeyboardMap);
117 }
118
ZoomToRect(const ScrollableLayerGuid & aGuid,const CSSRect & aRect,const uint32_t aFlags)119 void APZCTreeManagerChild::ZoomToRect(const ScrollableLayerGuid& aGuid,
120 const CSSRect& aRect,
121 const uint32_t aFlags) {
122 SendZoomToRect(aGuid, aRect, aFlags);
123 }
124
ContentReceivedInputBlock(uint64_t aInputBlockId,bool aPreventDefault)125 void APZCTreeManagerChild::ContentReceivedInputBlock(uint64_t aInputBlockId,
126 bool aPreventDefault) {
127 SendContentReceivedInputBlock(aInputBlockId, aPreventDefault);
128 }
129
SetTargetAPZC(uint64_t aInputBlockId,const nsTArray<ScrollableLayerGuid> & aTargets)130 void APZCTreeManagerChild::SetTargetAPZC(
131 uint64_t aInputBlockId, const nsTArray<ScrollableLayerGuid>& aTargets) {
132 SendSetTargetAPZC(aInputBlockId, aTargets);
133 }
134
UpdateZoomConstraints(const ScrollableLayerGuid & aGuid,const Maybe<ZoomConstraints> & aConstraints)135 void APZCTreeManagerChild::UpdateZoomConstraints(
136 const ScrollableLayerGuid& aGuid,
137 const Maybe<ZoomConstraints>& aConstraints) {
138 SendUpdateZoomConstraints(aGuid, aConstraints);
139 }
140
SetDPI(float aDpiValue)141 void APZCTreeManagerChild::SetDPI(float aDpiValue) { SendSetDPI(aDpiValue); }
142
SetAllowedTouchBehavior(uint64_t aInputBlockId,const nsTArray<TouchBehaviorFlags> & aValues)143 void APZCTreeManagerChild::SetAllowedTouchBehavior(
144 uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aValues) {
145 SendSetAllowedTouchBehavior(aInputBlockId, aValues);
146 }
147
StartScrollbarDrag(const ScrollableLayerGuid & aGuid,const AsyncDragMetrics & aDragMetrics)148 void APZCTreeManagerChild::StartScrollbarDrag(
149 const ScrollableLayerGuid& aGuid, const AsyncDragMetrics& aDragMetrics) {
150 SendStartScrollbarDrag(aGuid, aDragMetrics);
151 }
152
StartAutoscroll(const ScrollableLayerGuid & aGuid,const ScreenPoint & aAnchorLocation)153 bool APZCTreeManagerChild::StartAutoscroll(const ScrollableLayerGuid& aGuid,
154 const ScreenPoint& aAnchorLocation) {
155 return SendStartAutoscroll(aGuid, aAnchorLocation);
156 }
157
StopAutoscroll(const ScrollableLayerGuid & aGuid)158 void APZCTreeManagerChild::StopAutoscroll(const ScrollableLayerGuid& aGuid) {
159 SendStopAutoscroll(aGuid);
160 }
161
SetLongTapEnabled(bool aTapGestureEnabled)162 void APZCTreeManagerChild::SetLongTapEnabled(bool aTapGestureEnabled) {
163 SendSetLongTapEnabled(aTapGestureEnabled);
164 }
165
ProcessTouchVelocity(uint32_t aTimestampMs,float aSpeedY)166 void APZCTreeManagerChild::ProcessTouchVelocity(uint32_t aTimestampMs,
167 float aSpeedY) {
168 SendProcessTouchVelocity(aTimestampMs, aSpeedY);
169 }
170
UpdateWheelTransaction(LayoutDeviceIntPoint aRefPoint,EventMessage aEventMessage)171 void APZCTreeManagerChild::UpdateWheelTransaction(
172 LayoutDeviceIntPoint aRefPoint, EventMessage aEventMessage) {
173 SendUpdateWheelTransaction(aRefPoint, aEventMessage);
174 }
175
ProcessUnhandledEvent(LayoutDeviceIntPoint * aRefPoint,ScrollableLayerGuid * aOutTargetGuid,uint64_t * aOutFocusSequenceNumber)176 void APZCTreeManagerChild::ProcessUnhandledEvent(
177 LayoutDeviceIntPoint* aRefPoint, ScrollableLayerGuid* aOutTargetGuid,
178 uint64_t* aOutFocusSequenceNumber) {
179 SendProcessUnhandledEvent(*aRefPoint, aRefPoint, aOutTargetGuid,
180 aOutFocusSequenceNumber);
181 }
182
RecvHandleTap(const TapType & aType,const LayoutDevicePoint & aPoint,const Modifiers & aModifiers,const ScrollableLayerGuid & aGuid,const uint64_t & aInputBlockId)183 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvHandleTap(
184 const TapType& aType, const LayoutDevicePoint& aPoint,
185 const Modifiers& aModifiers, const ScrollableLayerGuid& aGuid,
186 const uint64_t& aInputBlockId) {
187 MOZ_ASSERT(XRE_IsParentProcess());
188 if (mCompositorSession &&
189 mCompositorSession->RootLayerTreeId() == aGuid.mLayersId &&
190 mCompositorSession->GetContentController()) {
191 mCompositorSession->GetContentController()->HandleTap(
192 aType, aPoint, aModifiers, aGuid, aInputBlockId);
193 return IPC_OK();
194 }
195 dom::TabParent* tab =
196 dom::TabParent::GetTabParentFromLayersId(aGuid.mLayersId);
197 if (tab) {
198 tab->SendHandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId);
199 }
200 return IPC_OK();
201 }
202
RecvNotifyPinchGesture(const PinchGestureType & aType,const ScrollableLayerGuid & aGuid,const LayoutDeviceCoord & aSpanChange,const Modifiers & aModifiers)203 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvNotifyPinchGesture(
204 const PinchGestureType& aType, const ScrollableLayerGuid& aGuid,
205 const LayoutDeviceCoord& aSpanChange, const Modifiers& aModifiers) {
206 // This will only get sent from the GPU process to the parent process, so
207 // this function should never get called in the content process.
208 MOZ_ASSERT(XRE_IsParentProcess());
209 MOZ_ASSERT(NS_IsMainThread());
210
211 // We want to handle it in this process regardless of what the target guid
212 // of the pinch is. This may change in the future.
213 if (mCompositorSession && mCompositorSession->GetWidget()) {
214 APZCCallbackHelper::NotifyPinchGesture(aType, aSpanChange, aModifiers,
215 mCompositorSession->GetWidget());
216 }
217 return IPC_OK();
218 }
219
RecvCancelAutoscroll(const FrameMetrics::ViewID & aScrollId)220 mozilla::ipc::IPCResult APZCTreeManagerChild::RecvCancelAutoscroll(
221 const FrameMetrics::ViewID& aScrollId) {
222 // This will only get sent from the GPU process to the parent process, so
223 // this function should never get called in the content process.
224 MOZ_ASSERT(XRE_IsParentProcess());
225 MOZ_ASSERT(NS_IsMainThread());
226
227 APZCCallbackHelper::CancelAutoscroll(aScrollId);
228 return IPC_OK();
229 }
230
231 } // namespace layers
232 } // namespace mozilla
233