widget/windows/winrt/APZController.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "APZController.h"
michael@0 6 #include "base/message_loop.h"
michael@0 7 #include "mozilla/layers/GeckoContentController.h"
michael@0 8 #include "nsThreadUtils.h"
michael@0 9 #include "MetroUtils.h"
michael@0 10 #include "nsPrintfCString.h"
michael@0 11 #include "nsIWidgetListener.h"
michael@0 12 #include "mozilla/layers/APZCCallbackHelper.h"
michael@0 13 #include "nsIDocument.h"
michael@0 14 #include "nsPresContext.h"
michael@0 15 #include "nsIDOMElement.h"
michael@0 16 #include "mozilla/dom/Element.h"
michael@0 17 #include "nsIDOMWindowUtils.h"
michael@0 18 #include "nsIInterfaceRequestorUtils.h"
michael@0 19 #include "nsLayoutUtils.h"
michael@0 20 #include "mozilla/TouchEvents.h"
michael@0 21
michael@0 22 //#define DEBUG_CONTROLLER 1
michael@0 23
michael@0 24 #ifdef DEBUG_CONTROLLER
michael@0 25 #include "WinUtils.h"
michael@0 26 using namespace mozilla::widget;
michael@0 27 #endif
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 namespace widget {
michael@0 31 namespace winrt {
michael@0 32
michael@0 33 nsRefPtr<mozilla::layers::APZCTreeManager> APZController::sAPZC;
michael@0 34
michael@0 35 /*
michael@0 36 * Metro layout specific - test to see if a sub document is a
michael@0 37 * tab.
michael@0 38 */
michael@0 39 static bool
michael@0 40 IsTab(nsCOMPtr<nsIDocument>& aSubDocument)
michael@0 41 {
michael@0 42 nsRefPtr<nsIDocument> parent = aSubDocument->GetParentDocument();
michael@0 43 if (!parent) {
michael@0 44 NS_WARNING("huh? IsTab should always get a sub document for a parameter");
michael@0 45 return false;
michael@0 46 }
michael@0 47 return parent->IsRootDisplayDocument();
michael@0 48 }
michael@0 49
michael@0 50 /*
michael@0 51 * Returns the sub document associated with the scroll id.
michael@0 52 */
michael@0 53 static bool
michael@0 54 GetDOMTargets(uint64_t aScrollId,
michael@0 55 nsCOMPtr<nsIDocument>& aSubDocument,
michael@0 56 nsCOMPtr<nsIContent>& aTargetContent)
michael@0 57 {
michael@0 58 // For tabs and subframes this will return the HTML sub document
michael@0 59 aTargetContent = nsLayoutUtils::FindContentFor(aScrollId);
michael@0 60 if (!aTargetContent) {
michael@0 61 return false;
michael@0 62 }
michael@0 63 nsCOMPtr<mozilla::dom::Element> domElement = do_QueryInterface(aTargetContent);
michael@0 64 if (!domElement) {
michael@0 65 return false;
michael@0 66 }
michael@0 67
michael@0 68 aSubDocument = domElement->OwnerDoc();
michael@0 69
michael@0 70 if (!aSubDocument) {
michael@0 71 return false;
michael@0 72 }
michael@0 73
michael@0 74 // If the root element equals domElement, FindElementWithViewId found
michael@0 75 // a document, vs. an element within a document.
michael@0 76 if (aSubDocument->GetRootElement() == domElement && IsTab(aSubDocument)) {
michael@0 77 aTargetContent = nullptr;
michael@0 78 }
michael@0 79
michael@0 80 return true;
michael@0 81 }
michael@0 82
michael@0 83 class RequestContentRepaintEvent : public nsRunnable
michael@0 84 {
michael@0 85 typedef mozilla::layers::FrameMetrics FrameMetrics;
michael@0 86
michael@0 87 public:
michael@0 88 RequestContentRepaintEvent(const FrameMetrics& aFrameMetrics,
michael@0 89 nsIWidgetListener* aListener) :
michael@0 90 mFrameMetrics(aFrameMetrics),
michael@0 91 mWidgetListener(aListener)
michael@0 92 {
michael@0 93 }
michael@0 94
michael@0 95 NS_IMETHOD Run() {
michael@0 96 // This must be on the gecko thread since we access the dom
michael@0 97 MOZ_ASSERT(NS_IsMainThread());
michael@0 98
michael@0 99 #ifdef DEBUG_CONTROLLER
michael@0 100 WinUtils::Log("APZController: mScrollOffset: %f %f", mFrameMetrics.mScrollOffset.x,
michael@0 101 mFrameMetrics.mScrollOffset.y);
michael@0 102 #endif
michael@0 103
michael@0 104 nsCOMPtr<nsIDocument> subDocument;
michael@0 105 nsCOMPtr<nsIContent> targetContent;
michael@0 106 if (!GetDOMTargets(mFrameMetrics.GetScrollId(),
michael@0 107 subDocument, targetContent)) {
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 // If we're dealing with a sub frame or content editable element,
michael@0 112 // call UpdateSubFrame.
michael@0 113 if (targetContent) {
michael@0 114 #ifdef DEBUG_CONTROLLER
michael@0 115 WinUtils::Log("APZController: detected subframe or content editable");
michael@0 116 #endif
michael@0 117 mozilla::layers::APZCCallbackHelper::UpdateSubFrame(targetContent, mFrameMetrics);
michael@0 118 return NS_OK;
michael@0 119 }
michael@0 120
michael@0 121 #ifdef DEBUG_CONTROLLER
michael@0 122 WinUtils::Log("APZController: detected tab");
michael@0 123 #endif
michael@0 124
michael@0 125 // We're dealing with a tab, call UpdateRootFrame.
michael@0 126 nsCOMPtr<nsIDOMWindowUtils> utils;
michael@0 127 nsCOMPtr<nsIDOMWindow> window = subDocument->GetDefaultView();
michael@0 128 if (window) {
michael@0 129 utils = do_GetInterface(window);
michael@0 130 if (utils) {
michael@0 131 mozilla::layers::APZCCallbackHelper::UpdateRootFrame(utils, mFrameMetrics);
michael@0 132
michael@0 133 #ifdef DEBUG_CONTROLLER
michael@0 134 WinUtils::Log("APZController: %I64d mDisplayPortMargins: %0.2f %0.2f %0.2f %0.2f",
michael@0 135 mFrameMetrics.GetScrollId(),
michael@0 136 mFrameMetrics.GetDisplayPortMargins().left,
michael@0 137 mFrameMetrics.GetDisplayPortMargins().top,
michael@0 138 mFrameMetrics.GetDisplayPortMargins().right,
michael@0 139 mFrameMetrics.GetDisplayPortMargins().bottom);
michael@0 140 #endif
michael@0 141 }
michael@0 142 }
michael@0 143 return NS_OK;
michael@0 144 }
michael@0 145 protected:
michael@0 146 FrameMetrics mFrameMetrics;
michael@0 147 nsIWidgetListener* mWidgetListener;
michael@0 148 };
michael@0 149
michael@0 150 void
michael@0 151 APZController::SetWidgetListener(nsIWidgetListener* aWidgetListener)
michael@0 152 {
michael@0 153 mWidgetListener = aWidgetListener;
michael@0 154 }
michael@0 155
michael@0 156 void
michael@0 157 APZController::ContentReceivedTouch(const ScrollableLayerGuid& aGuid, bool aPreventDefault)
michael@0 158 {
michael@0 159 if (!sAPZC) {
michael@0 160 return;
michael@0 161 }
michael@0 162 sAPZC->ContentReceivedTouch(aGuid, aPreventDefault);
michael@0 163 }
michael@0 164
michael@0 165 bool
michael@0 166 APZController::HitTestAPZC(ScreenIntPoint& aPoint)
michael@0 167 {
michael@0 168 if (!sAPZC) {
michael@0 169 return false;
michael@0 170 }
michael@0 171 return sAPZC->HitTestAPZC(aPoint);
michael@0 172 }
michael@0 173
michael@0 174 void
michael@0 175 APZController::TransformCoordinateToGecko(const ScreenIntPoint& aPoint,
michael@0 176 LayoutDeviceIntPoint* aRefPointOut)
michael@0 177 {
michael@0 178 if (!sAPZC || !aRefPointOut) {
michael@0 179 return;
michael@0 180 }
michael@0 181 sAPZC->TransformCoordinateToGecko(aPoint, aRefPointOut);
michael@0 182 }
michael@0 183
michael@0 184 nsEventStatus
michael@0 185 APZController::ReceiveInputEvent(WidgetInputEvent* aEvent,
michael@0 186 ScrollableLayerGuid* aOutTargetGuid)
michael@0 187 {
michael@0 188 MOZ_ASSERT(aEvent);
michael@0 189
michael@0 190 if (!sAPZC) {
michael@0 191 return nsEventStatus_eIgnore;
michael@0 192 }
michael@0 193 return sAPZC->ReceiveInputEvent(*aEvent->AsInputEvent(), aOutTargetGuid);
michael@0 194 }
michael@0 195
michael@0 196 // APZC sends us this request when we need to update the display port on
michael@0 197 // the scrollable frame the apzc is managing.
michael@0 198 void
michael@0 199 APZController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
michael@0 200 {
michael@0 201 if (!mWidgetListener) {
michael@0 202 NS_WARNING("Can't update display port, !mWidgetListener");
michael@0 203 return;
michael@0 204 }
michael@0 205
michael@0 206 #ifdef DEBUG_CONTROLLER
michael@0 207 WinUtils::Log("APZController::RequestContentRepaint scrollid=%I64d",
michael@0 208 aFrameMetrics.GetScrollId());
michael@0 209 #endif
michael@0 210 nsCOMPtr<nsIRunnable> r1 = new RequestContentRepaintEvent(aFrameMetrics,
michael@0 211 mWidgetListener);
michael@0 212 if (!NS_IsMainThread()) {
michael@0 213 NS_DispatchToMainThread(r1);
michael@0 214 } else {
michael@0 215 r1->Run();
michael@0 216 }
michael@0 217 }
michael@0 218
michael@0 219 void
michael@0 220 APZController::AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
michael@0 221 const uint32_t& aScrollGeneration)
michael@0 222 {
michael@0 223 #ifdef DEBUG_CONTROLLER
michael@0 224 WinUtils::Log("APZController::AcknowledgeScrollUpdate scrollid=%I64d gen=%lu",
michael@0 225 aScrollId, aScrollGeneration);
michael@0 226 #endif
michael@0 227 mozilla::layers::APZCCallbackHelper::AcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
michael@0 228 }
michael@0 229
michael@0 230 void
michael@0 231 APZController::HandleDoubleTap(const CSSPoint& aPoint,
michael@0 232 int32_t aModifiers,
michael@0 233 const ScrollableLayerGuid& aGuid)
michael@0 234 {
michael@0 235 }
michael@0 236
michael@0 237 void
michael@0 238 APZController::HandleSingleTap(const CSSPoint& aPoint,
michael@0 239 int32_t aModifiers,
michael@0 240 const ScrollableLayerGuid& aGuid)
michael@0 241 {
michael@0 242 }
michael@0 243
michael@0 244 void
michael@0 245 APZController::HandleLongTap(const CSSPoint& aPoint,
michael@0 246 int32_t aModifiers,
michael@0 247 const ScrollableLayerGuid& aGuid)
michael@0 248 {
michael@0 249 }
michael@0 250
michael@0 251 void
michael@0 252 APZController::HandleLongTapUp(const CSSPoint& aPoint,
michael@0 253 int32_t aModifiers,
michael@0 254 const ScrollableLayerGuid& aGuid)
michael@0 255 {
michael@0 256 }
michael@0 257
michael@0 258 // requests that we send a mozbrowserasyncscroll domevent. not in use.
michael@0 259 void
michael@0 260 APZController::SendAsyncScrollDOMEvent(bool aIsRoot,
michael@0 261 const CSSRect &aContentRect,
michael@0 262 const CSSSize &aScrollableSize)
michael@0 263 {
michael@0 264 }
michael@0 265
michael@0 266 void
michael@0 267 APZController::PostDelayedTask(Task* aTask, int aDelayMs)
michael@0 268 {
michael@0 269 MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
michael@0 270 }
michael@0 271
michael@0 272 bool
michael@0 273 APZController::GetRootZoomConstraints(ZoomConstraints* aOutConstraints)
michael@0 274 {
michael@0 275 if (aOutConstraints) {
michael@0 276 // Until we support the meta-viewport tag properly allow zooming
michael@0 277 // from 1/4 to 4x by default.
michael@0 278 aOutConstraints->mAllowZoom = true;
michael@0 279 aOutConstraints->mAllowDoubleTapZoom = false;
michael@0 280 aOutConstraints->mMinZoom = CSSToScreenScale(0.25f);
michael@0 281 aOutConstraints->mMaxZoom = CSSToScreenScale(4.0f);
michael@0 282 return true;
michael@0 283 }
michael@0 284 return false;
michael@0 285 }
michael@0 286
michael@0 287 // apzc notifications
michael@0 288
michael@0 289 class TransformedStartEvent : public nsRunnable
michael@0 290 {
michael@0 291 NS_IMETHOD Run() {
michael@0 292 MetroUtils::FireObserver("apzc-transform-start", L"");
michael@0 293 return NS_OK;
michael@0 294 }
michael@0 295 };
michael@0 296
michael@0 297 class TransformedEndEvent : public nsRunnable
michael@0 298 {
michael@0 299 NS_IMETHOD Run() {
michael@0 300 MetroUtils::FireObserver("apzc-transform-end", L"");
michael@0 301 return NS_OK;
michael@0 302 }
michael@0 303 };
michael@0 304
michael@0 305 void
michael@0 306 APZController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
michael@0 307 APZStateChange aChange,
michael@0 308 int aArg)
michael@0 309 {
michael@0 310 switch (aChange) {
michael@0 311 case APZStateChange::TransformBegin:
michael@0 312 {
michael@0 313 if (NS_IsMainThread()) {
michael@0 314 MetroUtils::FireObserver("apzc-transform-begin", L"");
michael@0 315 return;
michael@0 316 }
michael@0 317 nsCOMPtr<nsIRunnable> runnable = new TransformedStartEvent();
michael@0 318 NS_DispatchToMainThread(runnable);
michael@0 319 break;
michael@0 320 }
michael@0 321 case APZStateChange::TransformEnd:
michael@0 322 {
michael@0 323 if (NS_IsMainThread()) {
michael@0 324 MetroUtils::FireObserver("apzc-transform-end", L"");
michael@0 325 return;
michael@0 326 }
michael@0 327 nsCOMPtr<nsIRunnable> runnable = new TransformedEndEvent();
michael@0 328 NS_DispatchToMainThread(runnable);
michael@0 329 break;
michael@0 330 }
michael@0 331 default:
michael@0 332 {
michael@0 333 // We don't currently care about other state changes.
michael@0 334 break;
michael@0 335 }
michael@0 336 }
michael@0 337 }
michael@0 338
michael@0 339 } } }

mercurial