1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/apz/util/APZCCallbackHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_layers_APZCCallbackHelper_h 1.10 +#define mozilla_layers_APZCCallbackHelper_h 1.11 + 1.12 +#include "FrameMetrics.h" 1.13 +#include "nsIContent.h" 1.14 +#include "nsIDocument.h" 1.15 +#include "nsIDOMWindowUtils.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace layers { 1.19 + 1.20 +/* This class contains some helper methods that facilitate implementing the 1.21 + GeckoContentController callback interface required by the AsyncPanZoomController. 1.22 + Since different platforms need to implement this interface in similar-but- 1.23 + not-quite-the-same ways, this utility class provides some helpful methods 1.24 + to hold code that can be shared across the different platform implementations. 1.25 + */ 1.26 +class APZCCallbackHelper 1.27 +{ 1.28 + typedef mozilla::layers::FrameMetrics FrameMetrics; 1.29 + typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; 1.30 + 1.31 +public: 1.32 + /* Checks to see if the pres shell that the given FrameMetrics object refers 1.33 + to is still the valid pres shell for the DOMWindowUtils. This can help 1.34 + guard against apply stale updates (updates meant for a pres shell that has 1.35 + since been torn down and replaced). */ 1.36 + static bool HasValidPresShellId(nsIDOMWindowUtils* aUtils, 1.37 + const FrameMetrics& aMetrics); 1.38 + 1.39 + /* Applies the scroll and zoom parameters from the given FrameMetrics object to 1.40 + the root frame corresponding to the given DOMWindowUtils. If tiled thebes 1.41 + layers are enabled, this will align the displayport to tile boundaries. 1.42 + Setting the scroll position can cause some small adjustments to be made 1.43 + to the actual scroll position. aMetrics' display port and scroll position 1.44 + will be updated with any modifications made. */ 1.45 + static void UpdateRootFrame(nsIDOMWindowUtils* aUtils, 1.46 + FrameMetrics& aMetrics); 1.47 + 1.48 + /* Applies the scroll parameters from the given FrameMetrics object to the subframe 1.49 + corresponding to the given content object. If tiled thebes 1.50 + layers are enabled, this will align the displayport to tile boundaries. 1.51 + Setting the scroll position can cause some small adjustments to be made 1.52 + to the actual scroll position. aMetrics' display port and scroll position 1.53 + will be updated with any modifications made. */ 1.54 + static void UpdateSubFrame(nsIContent* aContent, 1.55 + FrameMetrics& aMetrics); 1.56 + 1.57 + /* Get the DOMWindowUtils for the window corresponding to the given document. */ 1.58 + static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIDocument* aDoc); 1.59 + 1.60 + /* Get the DOMWindowUtils for the window corresponding to the givent content 1.61 + element. This might be an iframe inside the tab, for instance. */ 1.62 + static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIContent* aContent); 1.63 + 1.64 + /* Get the presShellId and view ID for the given content element, if they can be 1.65 + found. Returns false if the values could not be found, true if they could. */ 1.66 + static bool GetScrollIdentifiers(const nsIContent* aContent, 1.67 + uint32_t* aPresShellIdOut, 1.68 + FrameMetrics::ViewID* aViewIdOut); 1.69 + 1.70 + /* Tell layout that we received the scroll offset update for the given view ID, so 1.71 + that it accepts future scroll offset updates from APZ. */ 1.72 + static void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId, 1.73 + const uint32_t& aScrollGeneration); 1.74 + 1.75 + /* Save an "input transform" property on the content element corresponding to 1.76 + the scrollable content. This is needed because in some cases when the APZ code 1.77 + sends a paint request via the GeckoContentController interface, we don't always 1.78 + apply the scroll offset that was requested. Since the APZ code doesn't know 1.79 + that we didn't apply it, it will transform inputs assuming that we had applied 1.80 + it, and so we need to apply a fixup to the input to account for the fact that 1.81 + we didn't. 1.82 + The |aApzcMetrics| argument are the metrics that the APZ sent us, and the 1.83 + |aActualMetrics| argument are the metrics representing the gecko state after we 1.84 + applied some or all of the APZ metrics. */ 1.85 + static void UpdateCallbackTransform(const FrameMetrics& aApzcMetrics, 1.86 + const FrameMetrics& aActualMetrics); 1.87 + 1.88 + /* Apply an "input transform" to the given |aInput| and return the transformed value. 1.89 + The input transform applied is the one for the content element corresponding to 1.90 + |aGuid|; this is populated in a previous call to UpdateCallbackTransform. See that 1.91 + method's documentations for details. */ 1.92 + static CSSPoint ApplyCallbackTransform(const CSSPoint& aInput, 1.93 + const ScrollableLayerGuid& aGuid); 1.94 + 1.95 + /* Same as above, but operates on nsIntPoint that are assumed to be in LayoutDevice 1.96 + pixel space. Requires an additonal |aScale| parameter to convert between CSS and 1.97 + LayoutDevice space. */ 1.98 + static nsIntPoint ApplyCallbackTransform(const nsIntPoint& aPoint, 1.99 + const ScrollableLayerGuid& aGuid, 1.100 + const CSSToLayoutDeviceScale& aScale); 1.101 +}; 1.102 + 1.103 +} 1.104 +} 1.105 + 1.106 +#endif /* mozilla_layers_APZCCallbackHelper_h */