2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-09-06 17:35:16 +04:00
|
|
|
/* 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"
|
2018-03-06 02:08:18 +03:00
|
|
|
#include "nsRectAbsolute.h"
|
2013-09-06 17:35:16 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsIScrollPositionListener.h"
|
|
|
|
|
2014-06-19 04:57:51 +04:00
|
|
|
struct nsRect;
|
2013-09-06 17:35:16 +04:00
|
|
|
class nsIFrame;
|
|
|
|
class nsIScrollableFrame;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class StickyScrollContainer final : public nsIScrollPositionListener {
|
2013-09-06 17:35:16 +04:00
|
|
|
public:
|
|
|
|
/**
|
2013-09-12 03:30:56 +04:00
|
|
|
* Find (and create if necessary) the StickyScrollContainer associated with
|
|
|
|
* the scroll container of the given frame, if a scroll container exists.
|
2013-09-06 17:35:16 +04:00
|
|
|
*/
|
2013-09-12 03:30:56 +04:00
|
|
|
static StickyScrollContainer* GetStickyScrollContainerForFrame(
|
|
|
|
nsIFrame* aFrame);
|
2013-09-06 17:35:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the StickyScrollContainer associated with the given scroll frame,
|
|
|
|
* if it exists.
|
|
|
|
*/
|
|
|
|
static StickyScrollContainer* GetStickyScrollContainerForScrollFrame(
|
|
|
|
nsIFrame* aScrollFrame);
|
|
|
|
|
2013-11-23 13:48:26 +04:00
|
|
|
/**
|
|
|
|
* aFrame may have moved into or out of a scroll frame's frame subtree.
|
|
|
|
*/
|
|
|
|
static void NotifyReparentedFrameAcrossScrollFrameBoundary(
|
|
|
|
nsIFrame* aFrame, nsIFrame* aOldParent);
|
|
|
|
|
2013-09-06 17:35:16 +04:00
|
|
|
void AddFrame(nsIFrame* aFrame) { mFrames.AppendElement(aFrame); }
|
|
|
|
void RemoveFrame(nsIFrame* aFrame) { mFrames.RemoveElement(aFrame); }
|
|
|
|
|
2013-09-12 08:24:32 +04:00
|
|
|
nsIScrollableFrame* ScrollFrame() const { return mScrollFrame; }
|
|
|
|
|
2013-09-06 17:35:16 +04:00
|
|
|
// 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;
|
|
|
|
|
2013-09-12 08:24:32 +04:00
|
|
|
/**
|
|
|
|
* Compute where a frame should not scroll with the page, represented by the
|
|
|
|
* difference of two rectangles.
|
|
|
|
*/
|
2018-03-06 02:08:18 +03:00
|
|
|
void GetScrollRanges(nsIFrame* aFrame, nsRectAbsolute* aOuter,
|
|
|
|
nsRectAbsolute* aInner) const;
|
2013-09-12 08:24:32 +04:00
|
|
|
|
2013-09-14 03:53:48 +04:00
|
|
|
/**
|
|
|
|
* Compute and set the position of a frame and its following continuations.
|
|
|
|
*/
|
|
|
|
void PositionContinuations(nsIFrame* aFrame);
|
|
|
|
|
2013-09-06 17:35:16 +04:00
|
|
|
/**
|
|
|
|
* 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
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override;
|
2013-09-06 17:35:16 +04:00
|
|
|
|
2015-02-05 02:22:27 +03:00
|
|
|
~StickyScrollContainer();
|
|
|
|
|
2019-10-10 02:51:05 +03:00
|
|
|
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;
|
|
|
|
|
2013-09-06 17:35:16 +04:00
|
|
|
private:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit StickyScrollContainer(nsIScrollableFrame* aScrollFrame);
|
2013-09-06 17:35:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 */
|