Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / StickyScrollContainer.h
blobeb818d5bc9e567760c779fb1b435c52d7e74f27a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 * compute sticky positioning, both during reflow and when the scrolling
9 * container scrolls
12 #ifndef StickyScrollContainer_h
13 #define StickyScrollContainer_h
15 #include "nsPoint.h"
16 #include "nsTArray.h"
17 #include "nsIScrollPositionListener.h"
19 struct nsRect;
20 class nsIFrame;
21 class nsIScrollableFrame;
23 namespace mozilla {
25 class StickyScrollContainer MOZ_FINAL : public nsIScrollPositionListener
27 public:
28 /**
29 * Find (and create if necessary) the StickyScrollContainer associated with
30 * the scroll container of the given frame, if a scroll container exists.
32 static StickyScrollContainer* GetStickyScrollContainerForFrame(nsIFrame* aFrame);
34 /**
35 * Find the StickyScrollContainer associated with the given scroll frame,
36 * if it exists.
38 static StickyScrollContainer* GetStickyScrollContainerForScrollFrame(nsIFrame* aScrollFrame);
40 /**
41 * aFrame may have moved into or out of a scroll frame's frame subtree.
43 static void NotifyReparentedFrameAcrossScrollFrameBoundary(nsIFrame* aFrame,
44 nsIFrame* aOldParent);
46 void AddFrame(nsIFrame* aFrame) {
47 mFrames.AppendElement(aFrame);
49 void RemoveFrame(nsIFrame* aFrame) {
50 mFrames.RemoveElement(aFrame);
53 nsIScrollableFrame* ScrollFrame() const {
54 return mScrollFrame;
57 // Compute the offsets for a sticky position element
58 static void ComputeStickyOffsets(nsIFrame* aFrame);
60 /**
61 * Compute the position of a sticky positioned frame, based on information
62 * stored in its properties along with our scroll frame and scroll position.
64 nsPoint ComputePosition(nsIFrame* aFrame) const;
66 /**
67 * Compute where a frame should not scroll with the page, represented by the
68 * difference of two rectangles.
70 void GetScrollRanges(nsIFrame* aFrame, nsRect* aOuter, nsRect* aInner) const;
72 /**
73 * Compute and set the position of a frame and its following continuations.
75 void PositionContinuations(nsIFrame* aFrame);
77 /**
78 * Compute and set the position of all sticky frames, given the current
79 * scroll position of the scroll frame. If not in reflow, aSubtreeRoot should
80 * be null; otherwise, overflow-area updates will be limited to not affect
81 * aSubtreeRoot or its ancestors.
83 void UpdatePositions(nsPoint aScrollPosition, nsIFrame* aSubtreeRoot);
85 // nsIScrollPositionListener
86 virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
87 virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
89 private:
90 explicit StickyScrollContainer(nsIScrollableFrame* aScrollFrame);
91 ~StickyScrollContainer();
93 /**
94 * Compute two rectangles that determine sticky positioning: |aStick|, based
95 * on the scroll container, and |aContain|, based on the containing block.
96 * Sticky positioning keeps the frame position (its upper-left corner) always
97 * within |aContain| and secondarily within |aStick|.
99 void ComputeStickyLimits(nsIFrame* aFrame, nsRect* aStick,
100 nsRect* aContain) const;
102 friend void DestroyStickyScrollContainer(void* aPropertyValue);
104 nsIScrollableFrame* const mScrollFrame;
105 nsTArray<nsIFrame*> mFrames;
106 nsPoint mScrollPosition;
109 } // namespace mozilla
111 #endif /* StickyScrollContainer_h */