1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/StickyScrollContainer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * compute sticky positioning, both during reflow and when the scrolling 1.12 + * container scrolls 1.13 + */ 1.14 + 1.15 +#ifndef StickyScrollContainer_h 1.16 +#define StickyScrollContainer_h 1.17 + 1.18 +#include "nsPoint.h" 1.19 +#include "nsTArray.h" 1.20 +#include "nsIScrollPositionListener.h" 1.21 + 1.22 +class nsRect; 1.23 +class nsIFrame; 1.24 +class nsIScrollableFrame; 1.25 + 1.26 +namespace mozilla { 1.27 + 1.28 +class StickyScrollContainer MOZ_FINAL : public nsIScrollPositionListener 1.29 +{ 1.30 +public: 1.31 + /** 1.32 + * Find (and create if necessary) the StickyScrollContainer associated with 1.33 + * the scroll container of the given frame, if a scroll container exists. 1.34 + */ 1.35 + static StickyScrollContainer* GetStickyScrollContainerForFrame(nsIFrame* aFrame); 1.36 + 1.37 + /** 1.38 + * Find the StickyScrollContainer associated with the given scroll frame, 1.39 + * if it exists. 1.40 + */ 1.41 + static StickyScrollContainer* GetStickyScrollContainerForScrollFrame(nsIFrame* aScrollFrame); 1.42 + 1.43 + /** 1.44 + * aFrame may have moved into or out of a scroll frame's frame subtree. 1.45 + */ 1.46 + static void NotifyReparentedFrameAcrossScrollFrameBoundary(nsIFrame* aFrame, 1.47 + nsIFrame* aOldParent); 1.48 + 1.49 + void AddFrame(nsIFrame* aFrame) { 1.50 + mFrames.AppendElement(aFrame); 1.51 + } 1.52 + void RemoveFrame(nsIFrame* aFrame) { 1.53 + mFrames.RemoveElement(aFrame); 1.54 + } 1.55 + 1.56 + nsIScrollableFrame* ScrollFrame() const { 1.57 + return mScrollFrame; 1.58 + } 1.59 + 1.60 + // Compute the offsets for a sticky position element 1.61 + static void ComputeStickyOffsets(nsIFrame* aFrame); 1.62 + 1.63 + /** 1.64 + * Compute the position of a sticky positioned frame, based on information 1.65 + * stored in its properties along with our scroll frame and scroll position. 1.66 + */ 1.67 + nsPoint ComputePosition(nsIFrame* aFrame) const; 1.68 + 1.69 + /** 1.70 + * Compute where a frame should not scroll with the page, represented by the 1.71 + * difference of two rectangles. 1.72 + */ 1.73 + void GetScrollRanges(nsIFrame* aFrame, nsRect* aOuter, nsRect* aInner) const; 1.74 + 1.75 + /** 1.76 + * Compute and set the position of a frame and its following continuations. 1.77 + */ 1.78 + void PositionContinuations(nsIFrame* aFrame); 1.79 + 1.80 + /** 1.81 + * Compute and set the position of all sticky frames, given the current 1.82 + * scroll position of the scroll frame. If not in reflow, aSubtreeRoot should 1.83 + * be null; otherwise, overflow-area updates will be limited to not affect 1.84 + * aSubtreeRoot or its ancestors. 1.85 + */ 1.86 + void UpdatePositions(nsPoint aScrollPosition, nsIFrame* aSubtreeRoot); 1.87 + 1.88 + // nsIScrollPositionListener 1.89 + virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE; 1.90 + virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE; 1.91 + 1.92 +private: 1.93 + StickyScrollContainer(nsIScrollableFrame* aScrollFrame); 1.94 + ~StickyScrollContainer(); 1.95 + 1.96 + /** 1.97 + * Compute two rectangles that determine sticky positioning: |aStick|, based 1.98 + * on the scroll container, and |aContain|, based on the containing block. 1.99 + * Sticky positioning keeps the frame position (its upper-left corner) always 1.100 + * within |aContain| and secondarily within |aStick|. 1.101 + */ 1.102 + void ComputeStickyLimits(nsIFrame* aFrame, nsRect* aStick, 1.103 + nsRect* aContain) const; 1.104 + 1.105 + friend void DestroyStickyScrollContainer(void* aPropertyValue); 1.106 + 1.107 + nsIScrollableFrame* const mScrollFrame; 1.108 + nsTArray<nsIFrame*> mFrames; 1.109 + nsPoint mScrollPosition; 1.110 +}; 1.111 + 1.112 +} // namespace mozilla 1.113 + 1.114 +#endif /* StickyScrollContainer_h */