|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_layers_APZCCallbackHelper_h |
|
7 #define mozilla_layers_APZCCallbackHelper_h |
|
8 |
|
9 #include "FrameMetrics.h" |
|
10 #include "nsIContent.h" |
|
11 #include "nsIDocument.h" |
|
12 #include "nsIDOMWindowUtils.h" |
|
13 |
|
14 namespace mozilla { |
|
15 namespace layers { |
|
16 |
|
17 /* This class contains some helper methods that facilitate implementing the |
|
18 GeckoContentController callback interface required by the AsyncPanZoomController. |
|
19 Since different platforms need to implement this interface in similar-but- |
|
20 not-quite-the-same ways, this utility class provides some helpful methods |
|
21 to hold code that can be shared across the different platform implementations. |
|
22 */ |
|
23 class APZCCallbackHelper |
|
24 { |
|
25 typedef mozilla::layers::FrameMetrics FrameMetrics; |
|
26 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; |
|
27 |
|
28 public: |
|
29 /* Checks to see if the pres shell that the given FrameMetrics object refers |
|
30 to is still the valid pres shell for the DOMWindowUtils. This can help |
|
31 guard against apply stale updates (updates meant for a pres shell that has |
|
32 since been torn down and replaced). */ |
|
33 static bool HasValidPresShellId(nsIDOMWindowUtils* aUtils, |
|
34 const FrameMetrics& aMetrics); |
|
35 |
|
36 /* Applies the scroll and zoom parameters from the given FrameMetrics object to |
|
37 the root frame corresponding to the given DOMWindowUtils. If tiled thebes |
|
38 layers are enabled, this will align the displayport to tile boundaries. |
|
39 Setting the scroll position can cause some small adjustments to be made |
|
40 to the actual scroll position. aMetrics' display port and scroll position |
|
41 will be updated with any modifications made. */ |
|
42 static void UpdateRootFrame(nsIDOMWindowUtils* aUtils, |
|
43 FrameMetrics& aMetrics); |
|
44 |
|
45 /* Applies the scroll parameters from the given FrameMetrics object to the subframe |
|
46 corresponding to the given content object. If tiled thebes |
|
47 layers are enabled, this will align the displayport to tile boundaries. |
|
48 Setting the scroll position can cause some small adjustments to be made |
|
49 to the actual scroll position. aMetrics' display port and scroll position |
|
50 will be updated with any modifications made. */ |
|
51 static void UpdateSubFrame(nsIContent* aContent, |
|
52 FrameMetrics& aMetrics); |
|
53 |
|
54 /* Get the DOMWindowUtils for the window corresponding to the given document. */ |
|
55 static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIDocument* aDoc); |
|
56 |
|
57 /* Get the DOMWindowUtils for the window corresponding to the givent content |
|
58 element. This might be an iframe inside the tab, for instance. */ |
|
59 static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIContent* aContent); |
|
60 |
|
61 /* Get the presShellId and view ID for the given content element, if they can be |
|
62 found. Returns false if the values could not be found, true if they could. */ |
|
63 static bool GetScrollIdentifiers(const nsIContent* aContent, |
|
64 uint32_t* aPresShellIdOut, |
|
65 FrameMetrics::ViewID* aViewIdOut); |
|
66 |
|
67 /* Tell layout that we received the scroll offset update for the given view ID, so |
|
68 that it accepts future scroll offset updates from APZ. */ |
|
69 static void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId, |
|
70 const uint32_t& aScrollGeneration); |
|
71 |
|
72 /* Save an "input transform" property on the content element corresponding to |
|
73 the scrollable content. This is needed because in some cases when the APZ code |
|
74 sends a paint request via the GeckoContentController interface, we don't always |
|
75 apply the scroll offset that was requested. Since the APZ code doesn't know |
|
76 that we didn't apply it, it will transform inputs assuming that we had applied |
|
77 it, and so we need to apply a fixup to the input to account for the fact that |
|
78 we didn't. |
|
79 The |aApzcMetrics| argument are the metrics that the APZ sent us, and the |
|
80 |aActualMetrics| argument are the metrics representing the gecko state after we |
|
81 applied some or all of the APZ metrics. */ |
|
82 static void UpdateCallbackTransform(const FrameMetrics& aApzcMetrics, |
|
83 const FrameMetrics& aActualMetrics); |
|
84 |
|
85 /* Apply an "input transform" to the given |aInput| and return the transformed value. |
|
86 The input transform applied is the one for the content element corresponding to |
|
87 |aGuid|; this is populated in a previous call to UpdateCallbackTransform. See that |
|
88 method's documentations for details. */ |
|
89 static CSSPoint ApplyCallbackTransform(const CSSPoint& aInput, |
|
90 const ScrollableLayerGuid& aGuid); |
|
91 |
|
92 /* Same as above, but operates on nsIntPoint that are assumed to be in LayoutDevice |
|
93 pixel space. Requires an additonal |aScale| parameter to convert between CSS and |
|
94 LayoutDevice space. */ |
|
95 static nsIntPoint ApplyCallbackTransform(const nsIntPoint& aPoint, |
|
96 const ScrollableLayerGuid& aGuid, |
|
97 const CSSToLayoutDeviceScale& aScale); |
|
98 }; |
|
99 |
|
100 } |
|
101 } |
|
102 |
|
103 #endif /* mozilla_layers_APZCCallbackHelper_h */ |