diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /layout/generic/StickyScrollContainer.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/generic/StickyScrollContainer.h')
-rw-r--r-- | layout/generic/StickyScrollContainer.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/layout/generic/StickyScrollContainer.h b/layout/generic/StickyScrollContainer.h new file mode 100644 index 0000000000..64f2aea508 --- /dev/null +++ b/layout/generic/StickyScrollContainer.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * compute sticky positioning, both during reflow and when the scrolling + * container scrolls + */ + +#ifndef StickyScrollContainer_h +#define StickyScrollContainer_h + +#include "nsPoint.h" +#include "nsRectAbsolute.h" +#include "nsTArray.h" +#include "nsIScrollPositionListener.h" + +struct nsRect; +class nsIFrame; +class nsIScrollableFrame; + +namespace mozilla { + +class StickyScrollContainer final : public nsIScrollPositionListener { + public: + /** + * Find (and create if necessary) the StickyScrollContainer associated with + * the scroll container of the given frame, if a scroll container exists. + */ + static StickyScrollContainer* GetStickyScrollContainerForFrame( + nsIFrame* aFrame); + + /** + * Find the StickyScrollContainer associated with the given scroll frame, + * if it exists. + */ + static StickyScrollContainer* GetStickyScrollContainerForScrollFrame( + nsIFrame* aScrollFrame); + + /** + * aFrame may have moved into or out of a scroll frame's frame subtree. + */ + static void NotifyReparentedFrameAcrossScrollFrameBoundary( + nsIFrame* aFrame, nsIFrame* aOldParent); + + void AddFrame(nsIFrame* aFrame) { mFrames.AppendElement(aFrame); } + void RemoveFrame(nsIFrame* aFrame) { mFrames.RemoveElement(aFrame); } + + nsIScrollableFrame* ScrollFrame() const { return mScrollFrame; } + + // Compute the offsets for a sticky position element + static void ComputeStickyOffsets(nsIFrame* aFrame); + + /** + * Compute the position of a sticky positioned frame, based on information + * stored in its properties along with our scroll frame and scroll position. + */ + nsPoint ComputePosition(nsIFrame* aFrame) const; + + /** + * Compute where a frame should not scroll with the page, represented by the + * difference of two rectangles. + */ + void GetScrollRanges(nsIFrame* aFrame, nsRectAbsolute* aOuter, + nsRectAbsolute* aInner) const; + + /** + * Compute and set the position of a frame and its following continuations. + */ + void PositionContinuations(nsIFrame* aFrame); + + /** + * Compute and set the position of all sticky frames, given the current + * scroll position of the scroll frame. If not in reflow, aSubtreeRoot should + * be null; otherwise, overflow-area updates will be limited to not affect + * aSubtreeRoot or its ancestors. + */ + void UpdatePositions(nsPoint aScrollPosition, nsIFrame* aSubtreeRoot); + + // nsIScrollPositionListener + virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override; + virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override; + + ~StickyScrollContainer(); + + const nsTArray<nsIFrame*>& GetFrames() const { return mFrames; } + + /** + * Returns true if the frame is "stuck" in the y direction, ie it's acting + * like fixed position. aFrame should be in GetFrames(). + */ + bool IsStuckInYDirection(nsIFrame* aFrame) const; + + private: + explicit StickyScrollContainer(nsIScrollableFrame* aScrollFrame); + + /** + * Compute two rectangles that determine sticky positioning: |aStick|, based + * on the scroll container, and |aContain|, based on the containing block. + * Sticky positioning keeps the frame position (its upper-left corner) always + * within |aContain| and secondarily within |aStick|. + */ + void ComputeStickyLimits(nsIFrame* aFrame, nsRect* aStick, + nsRect* aContain) const; + + nsIScrollableFrame* const mScrollFrame; + nsTArray<nsIFrame*> mFrames; + nsPoint mScrollPosition; +}; + +} // namespace mozilla + +#endif /* StickyScrollContainer_h */ |