Bug 913114 - Fix ref counting in winrt widget's GeckoContentController. r=bbondy
[gecko.git] / widget / windows / winrt / APZController.cpp
bloba9bad89671ab4fb040b0b9c87daa6f022a2e5780
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"
12 namespace mozilla {
13 namespace widget {
14 namespace winrt {
16 class RequestContentRepaintEvent : public nsRunnable
18 typedef mozilla::layers::FrameMetrics FrameMetrics;
20 public:
21 RequestContentRepaintEvent(const FrameMetrics& aFrameMetrics) : mFrameMetrics(aFrameMetrics)
25 NS_IMETHOD Run() {
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 }" \
38 "}",
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());
51 return NS_OK;
53 protected:
54 const FrameMetrics mFrameMetrics;
57 void
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);
64 } else {
65 r1->Run();
69 void
70 APZController::HandleDoubleTap(const CSSIntPoint& aPoint)
74 void
75 APZController::HandleSingleTap(const CSSIntPoint& aPoint)
79 void
80 APZController::HandleLongTap(const CSSIntPoint& aPoint)
84 void
85 APZController::SendAsyncScrollDOMEvent(FrameMetrics::ViewID aScrollId, const CSSRect &aContentRect, const CSSSize &aScrollableSize)
89 void
90 APZController::PostDelayedTask(Task* aTask, int aDelayMs)
92 MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
95 void
96 APZController::HandlePanBegin()
98 MetroUtils::FireObserver("apzc-handle-pan-begin", L"");
101 void
102 APZController::HandlePanEnd()
104 MetroUtils::FireObserver("apzc-handle-pan-end", L"");
107 } } }