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