1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "APZController.h"
6 #include "base/message_loop.h"
7 #include "mozilla/layers/GeckoContentController.h"
8 #include "nsThreadUtils.h"
9 #include "MetroUtils.h"
10 #include "nsPrintfCString.h"
16 class RequestContentRepaintEvent
: public nsRunnable
18 typedef mozilla::layers::FrameMetrics FrameMetrics
;
21 RequestContentRepaintEvent(const FrameMetrics
& aFrameMetrics
) : mFrameMetrics(aFrameMetrics
)
26 // This event shuts down the worker thread and so must be main thread.
27 MOZ_ASSERT(NS_IsMainThread());
29 CSSToScreenScale resolution
= mFrameMetrics
.mZoom
;
30 CSSRect compositedRect
= mFrameMetrics
.CalculateCompositedRectInCssPixels();
32 NS_ConvertASCIItoUTF16
data(nsPrintfCString("{ " \
33 " \"resolution\": %.2f, " \
34 " \"scrollId\": %d, " \
35 " \"compositedRect\": { \"width\": %d, \"height\": %d }, " \
36 " \"displayPort\": { \"x\": %d, \"y\": %d, \"width\": %d, \"height\": %d }, " \
37 " \"scrollTo\": { \"x\": %d, \"y\": %d }" \
39 (float)(resolution
.scale
/ mFrameMetrics
.mDevPixelsPerCSSPixel
.scale
),
40 (int)mFrameMetrics
.mScrollId
,
41 (int)compositedRect
.width
,
42 (int)compositedRect
.height
,
43 (int)mFrameMetrics
.mDisplayPort
.x
,
44 (int)mFrameMetrics
.mDisplayPort
.y
,
45 (int)mFrameMetrics
.mDisplayPort
.width
,
46 (int)mFrameMetrics
.mDisplayPort
.height
,
47 (int)mFrameMetrics
.mScrollOffset
.x
,
48 (int)mFrameMetrics
.mScrollOffset
.y
));
50 MetroUtils::FireObserver("apzc-request-content-repaint", data
.get());
54 const FrameMetrics mFrameMetrics
;
58 APZController::RequestContentRepaint(const FrameMetrics
& aFrameMetrics
)
60 // Send the result back to the main thread so that it can shutdown
61 nsCOMPtr
<nsIRunnable
> r1
= new RequestContentRepaintEvent(aFrameMetrics
);
62 if (!NS_IsMainThread()) {
63 NS_DispatchToMainThread(r1
);
70 APZController::HandleDoubleTap(const CSSIntPoint
& aPoint
)
75 APZController::HandleSingleTap(const CSSIntPoint
& aPoint
)
80 APZController::HandleLongTap(const CSSIntPoint
& aPoint
)
85 APZController::SendAsyncScrollDOMEvent(FrameMetrics::ViewID aScrollId
, const CSSRect
&aContentRect
, const CSSSize
&aScrollableSize
)
90 APZController::PostDelayedTask(Task
* aTask
, int aDelayMs
)
92 MessageLoop::current()->PostDelayedTask(FROM_HERE
, aTask
, aDelayMs
);
96 APZController::HandlePanBegin()
98 MetroUtils::FireObserver("apzc-handle-pan-begin", L
"");
102 APZController::HandlePanEnd()
104 MetroUtils::FireObserver("apzc-handle-pan-end", L
"");