michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_layers_APZCCallbackHelper_h michael@0: #define mozilla_layers_APZCCallbackHelper_h michael@0: michael@0: #include "FrameMetrics.h" michael@0: #include "nsIContent.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIDOMWindowUtils.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: /* This class contains some helper methods that facilitate implementing the michael@0: GeckoContentController callback interface required by the AsyncPanZoomController. michael@0: Since different platforms need to implement this interface in similar-but- michael@0: not-quite-the-same ways, this utility class provides some helpful methods michael@0: to hold code that can be shared across the different platform implementations. michael@0: */ michael@0: class APZCCallbackHelper michael@0: { michael@0: typedef mozilla::layers::FrameMetrics FrameMetrics; michael@0: typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; michael@0: michael@0: public: michael@0: /* Checks to see if the pres shell that the given FrameMetrics object refers michael@0: to is still the valid pres shell for the DOMWindowUtils. This can help michael@0: guard against apply stale updates (updates meant for a pres shell that has michael@0: since been torn down and replaced). */ michael@0: static bool HasValidPresShellId(nsIDOMWindowUtils* aUtils, michael@0: const FrameMetrics& aMetrics); michael@0: michael@0: /* Applies the scroll and zoom parameters from the given FrameMetrics object to michael@0: the root frame corresponding to the given DOMWindowUtils. If tiled thebes michael@0: layers are enabled, this will align the displayport to tile boundaries. michael@0: Setting the scroll position can cause some small adjustments to be made michael@0: to the actual scroll position. aMetrics' display port and scroll position michael@0: will be updated with any modifications made. */ michael@0: static void UpdateRootFrame(nsIDOMWindowUtils* aUtils, michael@0: FrameMetrics& aMetrics); michael@0: michael@0: /* Applies the scroll parameters from the given FrameMetrics object to the subframe michael@0: corresponding to the given content object. If tiled thebes michael@0: layers are enabled, this will align the displayport to tile boundaries. michael@0: Setting the scroll position can cause some small adjustments to be made michael@0: to the actual scroll position. aMetrics' display port and scroll position michael@0: will be updated with any modifications made. */ michael@0: static void UpdateSubFrame(nsIContent* aContent, michael@0: FrameMetrics& aMetrics); michael@0: michael@0: /* Get the DOMWindowUtils for the window corresponding to the given document. */ michael@0: static already_AddRefed GetDOMWindowUtils(const nsIDocument* aDoc); michael@0: michael@0: /* Get the DOMWindowUtils for the window corresponding to the givent content michael@0: element. This might be an iframe inside the tab, for instance. */ michael@0: static already_AddRefed GetDOMWindowUtils(const nsIContent* aContent); michael@0: michael@0: /* Get the presShellId and view ID for the given content element, if they can be michael@0: found. Returns false if the values could not be found, true if they could. */ michael@0: static bool GetScrollIdentifiers(const nsIContent* aContent, michael@0: uint32_t* aPresShellIdOut, michael@0: FrameMetrics::ViewID* aViewIdOut); michael@0: michael@0: /* Tell layout that we received the scroll offset update for the given view ID, so michael@0: that it accepts future scroll offset updates from APZ. */ michael@0: static void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId, michael@0: const uint32_t& aScrollGeneration); michael@0: michael@0: /* Save an "input transform" property on the content element corresponding to michael@0: the scrollable content. This is needed because in some cases when the APZ code michael@0: sends a paint request via the GeckoContentController interface, we don't always michael@0: apply the scroll offset that was requested. Since the APZ code doesn't know michael@0: that we didn't apply it, it will transform inputs assuming that we had applied michael@0: it, and so we need to apply a fixup to the input to account for the fact that michael@0: we didn't. michael@0: The |aApzcMetrics| argument are the metrics that the APZ sent us, and the michael@0: |aActualMetrics| argument are the metrics representing the gecko state after we michael@0: applied some or all of the APZ metrics. */ michael@0: static void UpdateCallbackTransform(const FrameMetrics& aApzcMetrics, michael@0: const FrameMetrics& aActualMetrics); michael@0: michael@0: /* Apply an "input transform" to the given |aInput| and return the transformed value. michael@0: The input transform applied is the one for the content element corresponding to michael@0: |aGuid|; this is populated in a previous call to UpdateCallbackTransform. See that michael@0: method's documentations for details. */ michael@0: static CSSPoint ApplyCallbackTransform(const CSSPoint& aInput, michael@0: const ScrollableLayerGuid& aGuid); michael@0: michael@0: /* Same as above, but operates on nsIntPoint that are assumed to be in LayoutDevice michael@0: pixel space. Requires an additonal |aScale| parameter to convert between CSS and michael@0: LayoutDevice space. */ michael@0: static nsIntPoint ApplyCallbackTransform(const nsIntPoint& aPoint, michael@0: const ScrollableLayerGuid& aGuid, michael@0: const CSSToLayoutDeviceScale& aScale); michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* mozilla_layers_APZCCallbackHelper_h */