layout/generic/StickyScrollContainer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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
    10  */
    12 #ifndef StickyScrollContainer_h
    13 #define StickyScrollContainer_h
    15 #include "nsPoint.h"
    16 #include "nsTArray.h"
    17 #include "nsIScrollPositionListener.h"
    19 class nsRect;
    20 class nsIFrame;
    21 class nsIScrollableFrame;
    23 namespace mozilla {
    25 class StickyScrollContainer MOZ_FINAL : public nsIScrollPositionListener
    26 {
    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.
    31    */
    32   static StickyScrollContainer* GetStickyScrollContainerForFrame(nsIFrame* aFrame);
    34   /**
    35    * Find the StickyScrollContainer associated with the given scroll frame,
    36    * if it exists.
    37    */
    38   static StickyScrollContainer* GetStickyScrollContainerForScrollFrame(nsIFrame* aScrollFrame);
    40   /**
    41    * aFrame may have moved into or out of a scroll frame's frame subtree.
    42    */
    43   static void NotifyReparentedFrameAcrossScrollFrameBoundary(nsIFrame* aFrame,
    44                                                              nsIFrame* aOldParent);
    46   void AddFrame(nsIFrame* aFrame) {
    47     mFrames.AppendElement(aFrame);
    48   }
    49   void RemoveFrame(nsIFrame* aFrame) {
    50     mFrames.RemoveElement(aFrame);
    51   }
    53   nsIScrollableFrame* ScrollFrame() const {
    54     return mScrollFrame;
    55   }
    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.
    63    */
    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.
    69    */
    70   void GetScrollRanges(nsIFrame* aFrame, nsRect* aOuter, nsRect* aInner) const;
    72   /**
    73    * Compute and set the position of a frame and its following continuations.
    74    */
    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.
    82    */
    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   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|.
    98    */
    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;
   107 };
   109 } // namespace mozilla
   111 #endif /* StickyScrollContainer_h */

mercurial