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