layout/generic/nsBlockFrame.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:cindent:ts=2:et:sw=2:
     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  * rendering object for CSS display:block, inline-block, and list-item
     9  * boxes, also used for various anonymous boxes
    10  */
    12 #ifndef nsBlockFrame_h___
    13 #define nsBlockFrame_h___
    15 #include "nsContainerFrame.h"
    16 #include "nsHTMLParts.h"
    17 #include "nsLineBox.h"
    18 #include "nsCSSPseudoElements.h"
    19 #include "nsStyleSet.h"
    20 #include "nsFloatManager.h"
    22 enum LineReflowStatus {
    23   // The line was completely reflowed and fit in available width, and we should
    24   // try to pull up content from the next line if possible.
    25   LINE_REFLOW_OK,
    26   // The line was completely reflowed and fit in available width, but we should
    27   // not try to pull up content from the next line.
    28   LINE_REFLOW_STOP,
    29   // We need to reflow the line again at its current vertical position. The
    30   // new reflow should not try to pull up any frames from the next line.
    31   LINE_REFLOW_REDO_NO_PULL,
    32   // We need to reflow the line again using the floats from its height
    33   // this reflow, since its height made it hit floats that were not
    34   // adjacent to its top.
    35   LINE_REFLOW_REDO_MORE_FLOATS,
    36   // We need to reflow the line again at a lower vertical postion where there
    37   // may be more horizontal space due to different float configuration.
    38   LINE_REFLOW_REDO_NEXT_BAND,
    39   // The line did not fit in the available vertical space. Try pushing it to
    40   // the next page or column if it's not the first line on the current page/column.
    41   LINE_REFLOW_TRUNCATED
    42 };
    44 class nsBlockReflowState;
    45 class nsBlockInFlowLineIterator;
    46 class nsBulletFrame;
    47 class nsFirstLineFrame;
    49 /**
    50  * Some invariants:
    51  * -- The overflow out-of-flows list contains the out-of-
    52  * flow frames whose placeholders are in the overflow list.
    53  * -- A given piece of content has at most one placeholder
    54  * frame in a block's normal child list.
    55  * -- While a block is being reflowed, and from then until
    56  * its next-in-flow is reflowed it may have a
    57  * PushedFloatProperty frame property that points to
    58  * an nsFrameList. This list contains continuations for
    59  * floats whose prev-in-flow is in the block's regular float
    60  * list and first-in-flows of floats that did not fit, but
    61  * whose placeholders are in the block or one of its
    62  * prev-in-flows.
    63  * -- In all these frame lists, if there are two frames for
    64  * the same content appearing in the list, then the frames
    65  * appear with the prev-in-flow before the next-in-flow.
    66  * -- While reflowing a block, its overflow line list
    67  * will usually be empty but in some cases will have lines
    68  * (while we reflow the block at its shrink-wrap width).
    69  * In this case any new overflowing content must be
    70  * prepended to the overflow lines.
    71  */
    73 typedef nsContainerFrame nsBlockFrameSuper;
    75 /*
    76  * Base class for block and inline frames.
    77  * The block frame has an additional child list, kAbsoluteList, which
    78  * contains the absolutely positioned frames.
    79  */ 
    80 class nsBlockFrame : public nsBlockFrameSuper
    81 {
    82 public:
    83   NS_DECL_QUERYFRAME_TARGET(nsBlockFrame)
    84   NS_DECL_FRAMEARENA_HELPERS
    86   typedef nsLineList::iterator                  line_iterator;
    87   typedef nsLineList::const_iterator            const_line_iterator;
    88   typedef nsLineList::reverse_iterator          reverse_line_iterator;
    89   typedef nsLineList::const_reverse_iterator    const_reverse_line_iterator;
    91   line_iterator begin_lines() { return mLines.begin(); }
    92   line_iterator end_lines() { return mLines.end(); }
    93   const_line_iterator begin_lines() const { return mLines.begin(); }
    94   const_line_iterator end_lines() const { return mLines.end(); }
    95   reverse_line_iterator rbegin_lines() { return mLines.rbegin(); }
    96   reverse_line_iterator rend_lines() { return mLines.rend(); }
    97   const_reverse_line_iterator rbegin_lines() const { return mLines.rbegin(); }
    98   const_reverse_line_iterator rend_lines() const { return mLines.rend(); }
    99   line_iterator line(nsLineBox* aList) { return mLines.begin(aList); }
   100   reverse_line_iterator rline(nsLineBox* aList) { return mLines.rbegin(aList); }
   102   friend nsIFrame* NS_NewBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsFrameState aFlags);
   104   // nsQueryFrame
   105   NS_DECL_QUERYFRAME
   107   // nsIFrame
   108   virtual void Init(nsIContent*      aContent,
   109                     nsIFrame*        aParent,
   110                     nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
   111   virtual nsresult SetInitialChildList(ChildListID     aListID,
   112                                        nsFrameList&    aChildList) MOZ_OVERRIDE;
   113   virtual nsresult  AppendFrames(ChildListID     aListID,
   114                                  nsFrameList&    aFrameList) MOZ_OVERRIDE;
   115   virtual nsresult  InsertFrames(ChildListID     aListID,
   116                                  nsIFrame*       aPrevFrame,
   117                                  nsFrameList&    aFrameList) MOZ_OVERRIDE;
   118   virtual nsresult  RemoveFrame(ChildListID     aListID,
   119                                 nsIFrame*       aOldFrame) MOZ_OVERRIDE;
   120   virtual const nsFrameList& GetChildList(ChildListID aListID) const MOZ_OVERRIDE;
   121   virtual void GetChildLists(nsTArray<ChildList>* aLists) const MOZ_OVERRIDE;
   122   virtual nscoord GetBaseline() const MOZ_OVERRIDE;
   123   virtual nscoord GetCaretBaseline() const MOZ_OVERRIDE;
   124   virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
   125   virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
   126   virtual bool IsFloatContainingBlock() const MOZ_OVERRIDE;
   127   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   128                                 const nsRect&           aDirtyRect,
   129                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   130   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   131   virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   132   {
   133     return nsContainerFrame::IsFrameOfType(aFlags &
   134              ~(nsIFrame::eCanContainOverflowContainers |
   135                nsIFrame::eBlockFrame));
   136   }
   138   virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   139   virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   141 #ifdef DEBUG_FRAME_DUMP
   142   void List(FILE* out = stderr, const char* aPrefix = "", uint32_t aFlags = 0) const MOZ_OVERRIDE;
   143   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   144 #endif
   146 #ifdef DEBUG
   147   virtual nsFrameState GetDebugStateBits() const MOZ_OVERRIDE;
   148 #endif
   150 #ifdef ACCESSIBILITY
   151   virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
   152 #endif
   154   // line cursor methods to speed up searching for the line(s)
   155   // containing a point. The basic idea is that we set the cursor
   156   // property if the lines' overflowArea.VisualOverflow().ys and
   157   // overflowArea.VisualOverflow().yMosts are non-decreasing
   158   // (considering only non-empty overflowArea.VisualOverflow()s; empty
   159   // overflowArea.VisualOverflow()s never participate in event handling
   160   // or painting), and the block has sufficient number of lines. The
   161   // cursor property points to a "recently used" line. If we get a
   162   // series of requests that work on lines
   163   // "near" the cursor, then we can find those nearby lines quickly by
   164   // starting our search at the cursor.
   166   // Clear out line cursor because we're disturbing the lines (i.e., Reflow)
   167   void ClearLineCursor();
   168   // Get the first line that might contain y-coord 'y', or nullptr if you must search
   169   // all lines. If nonnull is returned then we guarantee that the lines'
   170   // combinedArea.ys and combinedArea.yMosts are non-decreasing.
   171   // The actual line returned might not contain 'y', but if not, it is guaranteed
   172   // to be before any line which does contain 'y'.
   173   nsLineBox* GetFirstLineContaining(nscoord y);
   174   // Set the line cursor to our first line. Only call this if you
   175   // guarantee that the lines' combinedArea.ys and combinedArea.yMosts
   176   // are non-decreasing.
   177   void SetupLineCursor();
   179   virtual void ChildIsDirty(nsIFrame* aChild) MOZ_OVERRIDE;
   180   virtual bool IsVisibleInSelection(nsISelection* aSelection) MOZ_OVERRIDE;
   182   virtual bool IsEmpty() MOZ_OVERRIDE;
   183   virtual bool CachedIsEmpty() MOZ_OVERRIDE;
   184   virtual bool IsSelfEmpty() MOZ_OVERRIDE;
   186   // Given that we have a bullet, does it actually draw something, i.e.,
   187   // do we have either a 'list-style-type' or 'list-style-image' that is
   188   // not 'none'?
   189   bool BulletIsEmpty() const;
   191   /**
   192    * Return the bullet text equivalent.
   193    */
   194   void GetBulletText(nsAString& aText) const;
   196   /**
   197    * Return true if there's a bullet.
   198    */
   199   bool HasBullet() const {
   200     return HasOutsideBullet() || HasInsideBullet();
   201   }
   203   /**
   204    * @return true if this frame has an inside bullet frame.
   205    */
   206   bool HasInsideBullet() const {
   207     return 0 != (mState & NS_BLOCK_FRAME_HAS_INSIDE_BULLET);
   208   }
   210   /**
   211    * @return true if this frame has an outside bullet frame.
   212    */
   213   bool HasOutsideBullet() const {
   214     return 0 != (mState & NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET);
   215   }
   217   /**
   218    * @return the bullet frame or nullptr if we don't have one.
   219    */
   220   nsBulletFrame* GetBullet() const {
   221     nsBulletFrame* outside = GetOutsideBullet();
   222     return outside ? outside : GetInsideBullet();
   223   }
   225   virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
   226 private:
   227   void CheckIntrinsicCacheAgainstShrinkWrapState();
   228 public:
   229   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   230   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   232   virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE;
   234   virtual nsresult GetPrefWidthTightBounds(nsRenderingContext* aContext,
   235                                            nscoord* aX,
   236                                            nscoord* aXMost) MOZ_OVERRIDE;
   238   /**
   239    * Compute the final height of this frame.
   240    *
   241    * @param aReflowState Data structure passed from parent during reflow.
   242    * @param aReflowStatus A pointed to the reflow status for when we're finished
   243    *        doing reflow. this will get set appropriately if the height causes
   244    *        us to exceed the current available (page) height.
   245    * @param aContentHeight The height of content, precomputed outside of this
   246    *        function. The final height that is used in aMetrics will be set to
   247    *        either this or the available height, whichever is larger, in the
   248    *        case where our available height is constrained, and we overflow that
   249    *        available height.
   250    * @param aBorderPadding The margins representing the border padding for block
   251    *        frames. Can be 0.
   252    * @param aMetrics Out parameter for final height. Taken as an
   253    *        nsHTMLReflowMetrics object so that aMetrics can be passed in
   254    *        directly during reflow.
   255    * @param aConsumed The height already consumed by our previous-in-flows.
   256    */
   257   void ComputeFinalHeight(const nsHTMLReflowState& aReflowState,
   258                           nsReflowStatus*          aStatus,
   259                           nscoord                  aContentHeight,
   260                           const nsMargin&          aBorderPadding,
   261                           nsHTMLReflowMetrics&     aMetrics,
   262                           nscoord                  aConsumed);
   264   virtual nsresult Reflow(nsPresContext*           aPresContext,
   265                           nsHTMLReflowMetrics&     aDesiredSize,
   266                           const nsHTMLReflowState& aReflowState,
   267                           nsReflowStatus&          aStatus) MOZ_OVERRIDE;
   269   virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
   270                                     nsIAtom*        aAttribute,
   271                                     int32_t         aModType) MOZ_OVERRIDE;
   273   /**
   274    * Move any frames on our overflow list to the end of our principal list.
   275    * @return true if there were any overflow frames
   276    */
   277   virtual bool DrainSelfOverflowList() MOZ_OVERRIDE;
   279   virtual nsresult StealFrame(nsIFrame* aChild,
   280                               bool      aForceNormal = false) MOZ_OVERRIDE;
   282   virtual void DeleteNextInFlowChild(nsIFrame* aNextInFlow,
   283                                      bool      aDeletingEmptyFrames) MOZ_OVERRIDE;
   285   /**
   286     * This is a special method that allows a child class of nsBlockFrame to
   287     * return a special, customized nsStyleText object to the nsLineLayout
   288     * constructor. It is used when the nsBlockFrame child needs to specify its
   289     * custom rendering style.
   290     */
   291   virtual const nsStyleText* StyleTextForLineLayout();
   293   /**
   294    * Determines whether the collapsed margin carried out of the last
   295    * line includes the margin-top of a line with clearance (in which
   296    * case we must avoid collapsing that margin with our bottom margin)
   297    */
   298   bool CheckForCollapsedBottomMarginFromClearanceLine();
   300   static nsresult GetCurrentLine(nsBlockReflowState *aState, nsLineBox **aOutCurrentLine);
   302   /**
   303    * Determine if this block is a margin root at the top/bottom edges.
   304    */
   305   void IsMarginRoot(bool* aTopMarginRoot, bool* aBottomMarginRoot);
   307   static bool BlockNeedsFloatManager(nsIFrame* aBlock);
   309   /**
   310    * Returns whether aFrame is a block frame that will wrap its contents
   311    * around floats intruding on it from the outside.  (aFrame need not
   312    * be a block frame, but if it's not, the result will be false.)
   313    */
   314   static bool BlockCanIntersectFloats(nsIFrame* aFrame);
   316   /**
   317    * Returns the width that needs to be cleared past floats for blocks
   318    * that cannot intersect floats.  aState must already have
   319    * GetAvailableSpace called on it for the vertical position that we
   320    * care about (which need not be its current mY)
   321    */
   322   struct ReplacedElementWidthToClear {
   323     nscoord marginLeft, borderBoxWidth, marginRight;
   324     nscoord MarginBoxWidth() const
   325       { return marginLeft + borderBoxWidth + marginRight; }
   326   };
   327   static ReplacedElementWidthToClear
   328     WidthToClearPastFloats(nsBlockReflowState& aState,
   329                            const nsRect& aFloatAvailableSpace,
   330                            nsIFrame* aFrame);
   332   /**
   333    * Creates a contination for aFloat and adds it to the list of overflow floats.
   334    * Also updates aState.mReflowStatus to include the float's incompleteness.
   335    * Must only be called while this block frame is in reflow.
   336    * aFloatStatus must be the float's true, unmodified reflow status.
   337    * 
   338    */
   339   nsresult SplitFloat(nsBlockReflowState& aState,
   340                       nsIFrame*           aFloat,
   341                       nsReflowStatus      aFloatStatus);
   343   /**
   344    * Walks up the frame tree, starting with aCandidate, and returns the first
   345    * block frame that it encounters.
   346    */
   347   static nsBlockFrame* GetNearestAncestorBlock(nsIFrame* aCandidate);
   349   struct FrameLines {
   350     nsLineList mLines;
   351     nsFrameList mFrames;
   352   };
   354 protected:
   355   nsBlockFrame(nsStyleContext* aContext)
   356     : nsContainerFrame(aContext)
   357     , mMinWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
   358     , mPrefWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
   359   {
   360 #ifdef DEBUG
   361   InitDebugFlags();
   362 #endif
   363   }
   364   virtual ~nsBlockFrame();
   366 #ifdef DEBUG
   367   already_AddRefed<nsStyleContext> GetFirstLetterStyle(nsPresContext* aPresContext)
   368   {
   369     return aPresContext->StyleSet()->
   370       ProbePseudoElementStyle(mContent->AsElement(),
   371                               nsCSSPseudoElements::ePseudo_firstLetter,
   372                               mStyleContext);
   373   }
   374 #endif
   376   NS_DECLARE_FRAME_PROPERTY(LineCursorProperty, nullptr)
   377   nsLineBox* GetLineCursor() {
   378     return (GetStateBits() & NS_BLOCK_HAS_LINE_CURSOR) ?
   379       static_cast<nsLineBox*>(Properties().Get(LineCursorProperty())) : nullptr;
   380   }
   382   nsLineBox* NewLineBox(nsIFrame* aFrame, bool aIsBlock) {
   383     return NS_NewLineBox(PresContext()->PresShell(), aFrame, aIsBlock);
   384   }
   385   nsLineBox* NewLineBox(nsLineBox* aFromLine, nsIFrame* aFrame, int32_t aCount) {
   386     return NS_NewLineBox(PresContext()->PresShell(), aFromLine, aFrame, aCount);
   387   }
   388   void FreeLineBox(nsLineBox* aLine) {
   389     if (aLine == GetLineCursor()) {
   390       ClearLineCursor();
   391     }
   392     aLine->Destroy(PresContext()->PresShell());
   393   }
   394   /**
   395    * Helper method for StealFrame.
   396    */
   397   void RemoveFrameFromLine(nsIFrame* aChild, nsLineList::iterator aLine,
   398                            nsFrameList& aFrameList, nsLineList& aLineList);
   400   void TryAllLines(nsLineList::iterator* aIterator,
   401                    nsLineList::iterator* aStartIterator,
   402                    nsLineList::iterator* aEndIterator,
   403                    bool*        aInOverflowLines,
   404                    FrameLines** aOverflowLines);
   406   void SetFlags(nsFrameState aFlags) {
   407     mState &= ~NS_BLOCK_FLAGS_MASK;
   408     mState |= aFlags;
   409   }
   411   /** move the frames contained by aLine by aDY
   412     * if aLine is a block, its child floats are added to the state manager
   413     */
   414   void SlideLine(nsBlockReflowState& aState,
   415                  nsLineBox* aLine, nscoord aDY);
   417   void ComputeFinalSize(const nsHTMLReflowState& aReflowState,
   418                         nsBlockReflowState&      aState,
   419                         nsHTMLReflowMetrics&     aMetrics,
   420                         nscoord*                 aBottomEdgeOfChildren);
   422   void ComputeOverflowAreas(const nsRect&         aBounds,
   423                             const nsStyleDisplay* aDisplay,
   424                             nscoord               aBottomEdgeOfChildren,
   425                             nsOverflowAreas&      aOverflowAreas);
   427   /**
   428    * Add the frames in aFrameList to this block after aPrevSibling.
   429    * This block thinks in terms of lines, but the frame construction code
   430    * knows nothing about lines at all so we need to find the line that
   431    * contains aPrevSibling and add aFrameList after aPrevSibling on that line.
   432    * New lines are created as necessary to handle block data in aFrameList.
   433    * This function will clear aFrameList.
   434    */
   435   void AddFrames(nsFrameList& aFrameList, nsIFrame* aPrevSibling);
   437   /**
   438    * Perform Bidi resolution on this frame
   439    */
   440   nsresult ResolveBidi();
   442   /**
   443    * Test whether the frame is a form control in a visual Bidi page.
   444    * This is necessary for backwards-compatibility, because most visual
   445    * pages use logical order for form controls so that they will
   446    * display correctly on native widgets in OSs with Bidi support
   447    * @param aPresContext the pres context
   448    * @return whether the frame is a BIDI form control
   449    */
   450   bool IsVisualFormControl(nsPresContext* aPresContext);
   452 public:
   453   /**
   454    * Does all the real work for removing aDeletedFrame
   455    * -- finds the line containing aDeletedFrame
   456    * -- removes all aDeletedFrame next-in-flows (or all continuations,
   457    * if REMOVE_FIXED_CONTINUATIONS is given)
   458    * -- marks lines dirty as needed
   459    * -- marks textruns dirty (unless FRAMES_ARE_EMPTY is given, in which
   460    * case textruns do not need to be dirtied)
   461    * -- destroys all removed frames
   462    */
   463   enum {
   464     REMOVE_FIXED_CONTINUATIONS = 0x02,
   465     FRAMES_ARE_EMPTY           = 0x04
   466   };
   467   nsresult DoRemoveFrame(nsIFrame* aDeletedFrame, uint32_t aFlags);
   469   void ReparentFloats(nsIFrame* aFirstFrame, nsBlockFrame* aOldParent,
   470                       bool aReparentSiblings);
   472   virtual bool UpdateOverflow() MOZ_OVERRIDE;
   474   /** Load all of aFrame's floats into the float manager iff aFrame is not a
   475    *  block formatting context. Handles all necessary float manager translations;
   476    *  assumes float manager is in aFrame's parent's coord system.
   477    *  Safe to call on non-blocks (does nothing).
   478    */
   479   static void RecoverFloatsFor(nsIFrame*       aFrame,
   480                                nsFloatManager& aFloatManager);
   482   /**
   483    * Determine if we have any pushed floats from a previous continuation.
   484    *
   485    * @returns true, if any of the floats at the beginning of our mFloats list
   486    *          have the NS_FRAME_IS_PUSHED_FLOAT bit set; false otherwise.
   487    */
   488   bool HasPushedFloatsFromPrevContinuation() const {
   489     if (!mFloats.IsEmpty()) {
   490       // If we have pushed floats, then they should be at the beginning of our
   491       // float list.
   492       if (mFloats.FirstChild()->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT) {
   493         return true;
   494       }
   495     }
   497 #ifdef DEBUG
   498     // Double-check the above assertion that pushed floats should be at the
   499     // beginning of our floats list.
   500     for (nsFrameList::Enumerator e(mFloats); !e.AtEnd(); e.Next()) {
   501       nsIFrame* f = e.get();
   502       NS_ASSERTION(!(f->GetStateBits() & NS_FRAME_IS_PUSHED_FLOAT),
   503         "pushed floats must be at the beginning of the float list");
   504     }
   505 #endif
   506     return false;
   507   }
   509 protected:
   511   /** grab overflow lines from this block's prevInFlow, and make them
   512     * part of this block's mLines list.
   513     * @return true if any lines were drained.
   514     */
   515   bool DrainOverflowLines();
   517   /**
   518    * @return false iff this block does not have a float on any child list.
   519    * This function is O(1).
   520    */
   521   bool MaybeHasFloats() const {
   522     if (!mFloats.IsEmpty()) {
   523       return true;
   524     }
   525     // XXX this could be replaced with HasPushedFloats() if we enforced
   526     // removing the property when the frame list becomes empty.
   527     nsFrameList* list = GetPushedFloats();
   528     if (list && !list->IsEmpty()) {
   529       return true;
   530     }
   531     // For the OverflowOutOfFlowsProperty I think we do enforce that, but it's
   532     // a mix of out-of-flow frames, so that's why the method name has "Maybe".
   533     return GetStateBits() & NS_BLOCK_HAS_OVERFLOW_OUT_OF_FLOWS;
   534   }
   536   /** grab pushed floats from this block's prevInFlow, and splice
   537     * them into this block's mFloats list.
   538     */
   539   void DrainPushedFloats(nsBlockReflowState& aState);
   541   /** Load all our floats into the float manager (without reflowing them).
   542    *  Assumes float manager is in our own coordinate system.
   543    */
   544   void RecoverFloats(nsFloatManager& aFloatManager);
   546   /** Reflow pushed floats
   547    */
   548   void ReflowPushedFloats(nsBlockReflowState& aState,
   549                           nsOverflowAreas&    aOverflowAreas,
   550                           nsReflowStatus&     aStatus);
   552   /** Find any trailing BR clear from the last line of the block (or its PIFs)
   553    */
   554   uint8_t FindTrailingClear();
   556   /**
   557    * Remove a float from our float list.
   558    */
   559   void RemoveFloat(nsIFrame* aFloat);
   560   /**
   561    * Remove a float from the float cache for the line its placeholder is on.
   562    */
   563   void RemoveFloatFromFloatCache(nsIFrame* aFloat);
   565   void CollectFloats(nsIFrame* aFrame, nsFrameList& aList,
   566                      bool aCollectFromSiblings) {
   567     if (MaybeHasFloats()) {
   568       DoCollectFloats(aFrame, aList, aCollectFromSiblings);
   569     }
   570   }
   571   void DoCollectFloats(nsIFrame* aFrame, nsFrameList& aList,
   572                        bool aCollectFromSiblings);
   574   // Remove a float, abs, rel positioned frame from the appropriate block's list
   575   static void DoRemoveOutOfFlowFrame(nsIFrame* aFrame);
   577   /** set up the conditions necessary for an resize reflow
   578     * the primary task is to mark the minimumly sufficient lines dirty. 
   579     */
   580   void PrepareResizeReflow(nsBlockReflowState& aState);
   582   /** reflow all lines that have been marked dirty */
   583   nsresult ReflowDirtyLines(nsBlockReflowState& aState);
   585   /** Mark a given line dirty due to reflow being interrupted on or before it */
   586   void MarkLineDirtyForInterrupt(nsLineBox* aLine);
   588   //----------------------------------------
   589   // Methods for line reflow
   590   /**
   591    * Reflow a line.  
   592    * @param aState           the current reflow state
   593    * @param aLine            the line to reflow.  can contain a single block frame
   594    *                         or contain 1 or more inline frames.
   595    * @param aKeepReflowGoing [OUT] indicates whether the caller should continue to reflow more lines
   596    */
   597   nsresult ReflowLine(nsBlockReflowState& aState,
   598                       line_iterator aLine,
   599                       bool* aKeepReflowGoing);
   601   // Return false if it needs another reflow because of reduced space
   602   // between floats that are next to it (but not next to its top), and
   603   // return true otherwise.
   604   bool PlaceLine(nsBlockReflowState& aState,
   605                    nsLineLayout&       aLineLayout,
   606                    line_iterator       aLine,
   607                    nsFloatManager::SavedState* aFloatStateBeforeLine,
   608                    nsRect&             aFloatAvailableSpace, /* in-out */
   609                    nscoord&            aAvailableSpaceHeight, /* in-out */
   610                    bool*             aKeepReflowGoing);
   612   /**
   613     * If NS_BLOCK_LOOK_FOR_DIRTY_FRAMES is set, call MarkLineDirty
   614     * on any line with a child frame that is dirty.
   615     */
   616   void LazyMarkLinesDirty();
   618   /**
   619    * Mark |aLine| dirty, and, if necessary because of possible
   620    * pull-up, mark the previous line dirty as well. Also invalidates textruns
   621    * on those lines because the text in the lines might have changed due to
   622    * addition/removal of frames.
   623    * @param aLine the line to mark dirty
   624    * @param aLineList the line list containing that line
   625    */
   626   void MarkLineDirty(line_iterator aLine, const nsLineList* aLineList);
   628   // XXX where to go
   629   bool IsLastLine(nsBlockReflowState& aState,
   630                   line_iterator aLine);
   632   void DeleteLine(nsBlockReflowState& aState,
   633                   nsLineList::iterator aLine,
   634                   nsLineList::iterator aLineEnd);
   636   //----------------------------------------
   637   // Methods for individual frame reflow
   639   bool ShouldApplyTopMargin(nsBlockReflowState& aState,
   640                               nsLineBox* aLine);
   642   nsresult ReflowBlockFrame(nsBlockReflowState& aState,
   643                             line_iterator aLine,
   644                             bool* aKeepGoing);
   646   nsresult ReflowInlineFrames(nsBlockReflowState& aState,
   647                               line_iterator aLine,
   648                               bool* aKeepLineGoing);
   650   nsresult DoReflowInlineFrames(nsBlockReflowState& aState,
   651                                 nsLineLayout& aLineLayout,
   652                                 line_iterator aLine,
   653                                 nsFlowAreaRect& aFloatAvailableSpace,
   654                                 nscoord& aAvailableSpaceHeight,
   655                                 nsFloatManager::SavedState*
   656                                   aFloatStateBeforeLine,
   657                                 bool* aKeepReflowGoing,
   658                                 LineReflowStatus* aLineReflowStatus,
   659                                 bool aAllowPullUp);
   661   nsresult ReflowInlineFrame(nsBlockReflowState& aState,
   662                              nsLineLayout& aLineLayout,
   663                              line_iterator aLine,
   664                              nsIFrame* aFrame,
   665                              LineReflowStatus* aLineReflowStatus);
   667   // Compute the available width for a float. 
   668   nsRect AdjustFloatAvailableSpace(nsBlockReflowState& aState,
   669                                    const nsRect&       aFloatAvailableSpace,
   670                                    nsIFrame*           aFloatFrame);
   671   // Computes the border-box width of the float
   672   nscoord ComputeFloatWidth(nsBlockReflowState& aState,
   673                             const nsRect&       aFloatAvailableSpace,
   674                             nsIFrame*           aFloat);
   675   // An incomplete aReflowStatus indicates the float should be split
   676   // but only if the available height is constrained.
   677   // aAdjustedAvailableSpace is the result of calling
   678   // nsBlockFrame::AdjustFloatAvailableSpace.
   679   nsresult ReflowFloat(nsBlockReflowState& aState,
   680                        const nsRect&       aAdjustedAvailableSpace,
   681                        nsIFrame*           aFloat,
   682                        nsMargin&           aFloatMargin,
   683                        nsMargin&           aFloatOffsets,
   684                        // Whether the float's position
   685                        // (aAdjustedAvailableSpace) has been pushed down
   686                        // due to the presence of other floats.
   687                        bool                aFloatPushedDown,
   688                        nsReflowStatus&     aReflowStatus);
   690   //----------------------------------------
   691   // Methods for pushing/pulling lines/frames
   693   /**
   694    * Create a next-in-flow, if necessary, for aFrame. If a new frame is
   695    * created, place it in aLine if aLine is not null.
   696    * @param aState the block reflow state
   697    * @param aLine where to put a new frame
   698    * @param aFrame the frame
   699    * @return true if a new frame was created, false if not
   700    */
   701   bool CreateContinuationFor(nsBlockReflowState& aState,
   702                              nsLineBox*          aLine,
   703                              nsIFrame*           aFrame);
   705   /**
   706    * Push aLine (and any after it), since it cannot be placed on this
   707    * page/column.  Set aKeepReflowGoing to false and set
   708    * flag aState.mReflowStatus as incomplete.
   709    */
   710   void PushTruncatedLine(nsBlockReflowState& aState,
   711                          line_iterator       aLine,
   712                          bool*               aKeepReflowGoing);
   714   void SplitLine(nsBlockReflowState& aState,
   715                  nsLineLayout& aLineLayout,
   716                  line_iterator aLine,
   717                  nsIFrame* aFrame,
   718                  LineReflowStatus* aLineReflowStatus);
   720   /**
   721    * Pull a frame from the next available location (one of our lines or
   722    * one of our next-in-flows lines).
   723    * @return the pulled frame or nullptr
   724    */
   725   nsIFrame* PullFrame(nsBlockReflowState& aState,
   726                       line_iterator       aLine);
   728   /**
   729    * Try to pull a frame out of a line pointed at by aFromLine.
   730    *
   731    * Note: pulling a frame from a line that is a place-holder frame
   732    * doesn't automatically remove the corresponding float from the
   733    * line's float array. This happens indirectly: either the line gets
   734    * emptied (and destroyed) or the line gets reflowed (because we mark
   735    * it dirty) and the code at the top of ReflowLine empties the
   736    * array. So eventually, it will be removed, just not right away.
   737    *
   738    * @return the pulled frame or nullptr
   739    */
   740   nsIFrame* PullFrameFrom(nsLineBox*           aLine,
   741                           nsBlockFrame*        aFromContainer,
   742                           nsLineList::iterator aFromLine);
   744   /**
   745    * Push the line after aLineBefore to the overflow line list.
   746    * @param aLineBefore a line in 'mLines' (or begin_lines() when
   747    *        pushing the first line)
   748    */
   749   void PushLines(nsBlockReflowState& aState,
   750                  nsLineList::iterator aLineBefore);
   752   void PropagateFloatDamage(nsBlockReflowState& aState,
   753                             nsLineBox* aLine,
   754                             nscoord aDeltaY);
   756   void CheckFloats(nsBlockReflowState& aState);
   758   //----------------------------------------
   759   // List handling kludge
   761   // If this returns true, the block it's called on should get the
   762   // NS_FRAME_HAS_DIRTY_CHILDREN bit set on it by the caller; either directly
   763   // if it's already in reflow, or via calling FrameNeedsReflow() to schedule a
   764   // reflow.
   765   bool RenumberLists(nsPresContext* aPresContext);
   767   static bool RenumberListsInBlock(nsPresContext* aPresContext,
   768                                    nsBlockFrame* aBlockFrame,
   769                                    int32_t* aOrdinal,
   770                                    int32_t aDepth,
   771                                    int32_t aIncrement);
   773   static bool RenumberListsFor(nsPresContext* aPresContext, nsIFrame* aKid,
   774                                int32_t* aOrdinal, int32_t aDepth,
   775                                int32_t aIncrement);
   777   static bool FrameStartsCounterScope(nsIFrame* aFrame);
   779   void ReflowBullet(nsIFrame* aBulletFrame,
   780                     nsBlockReflowState& aState,
   781                     nsHTMLReflowMetrics& aMetrics,
   782                     nscoord aLineTop);
   784   //----------------------------------------
   786   virtual nsILineIterator* GetLineIterator() MOZ_OVERRIDE;
   788 public:
   789   bool HasOverflowLines() const {
   790     return 0 != (GetStateBits() & NS_BLOCK_HAS_OVERFLOW_LINES);
   791   }
   792   FrameLines* GetOverflowLines() const;
   793 protected:
   794   FrameLines* RemoveOverflowLines();
   795   void SetOverflowLines(FrameLines* aOverflowLines);
   796   void DestroyOverflowLines();
   798   /**
   799    * This class is useful for efficiently modifying the out of flow
   800    * overflow list. It gives the client direct writable access to
   801    * the frame list temporarily but ensures that property is only
   802    * written back if absolutely necessary.
   803    */
   804   struct nsAutoOOFFrameList {
   805     nsFrameList mList;
   807     nsAutoOOFFrameList(nsBlockFrame* aBlock)
   808       : mPropValue(aBlock->GetOverflowOutOfFlows())
   809       , mBlock(aBlock) {
   810       if (mPropValue) {
   811         mList = *mPropValue;
   812       }
   813     }
   814     ~nsAutoOOFFrameList() {
   815       mBlock->SetOverflowOutOfFlows(mList, mPropValue);
   816     }
   817   protected:
   818     nsFrameList* const mPropValue;
   819     nsBlockFrame* const mBlock;
   820   };
   821   friend struct nsAutoOOFFrameList;
   823   nsFrameList* GetOverflowOutOfFlows() const;
   824   void SetOverflowOutOfFlows(const nsFrameList& aList, nsFrameList* aPropValue);
   826   /**
   827    * @return the inside bullet frame or nullptr if we don't have one.
   828    */
   829   nsBulletFrame* GetInsideBullet() const;
   831   /**
   832    * @return the outside bullet frame or nullptr if we don't have one.
   833    */
   834   nsBulletFrame* GetOutsideBullet() const;
   836   /**
   837    * @return the outside bullet frame list frame property.
   838    */
   839   nsFrameList* GetOutsideBulletList() const;
   841   /**
   842    * @return true if this frame has pushed floats.
   843    */
   844   bool HasPushedFloats() const {
   845     return 0 != (GetStateBits() & NS_BLOCK_HAS_PUSHED_FLOATS);
   846   }
   848   // Get the pushed floats list, which is used for *temporary* storage
   849   // of floats during reflow, between when we decide they don't fit in
   850   // this block until our next continuation takes them.
   851   nsFrameList* GetPushedFloats() const;
   852   // Get the pushed floats list, or if there is not currently one,
   853   // make a new empty one.
   854   nsFrameList* EnsurePushedFloats();
   855   // Remove and return the pushed floats list.
   856   nsFrameList* RemovePushedFloats();
   858 #ifdef DEBUG
   859   void VerifyLines(bool aFinalCheckOK);
   860   void VerifyOverflowSituation();
   861   int32_t GetDepth() const;
   862 #endif
   864   nscoord mMinWidth, mPrefWidth;
   866   nsLineList mLines;
   868   // List of all floats in this block
   869   // XXXmats blocks rarely have floats, make it a frame property
   870   nsFrameList mFloats;
   872   friend class nsBlockReflowState;
   873   friend class nsBlockInFlowLineIterator;
   875 #ifdef DEBUG
   876 public:
   877   static bool gLamePaintMetrics;
   878   static bool gLameReflowMetrics;
   879   static bool gNoisy;
   880   static bool gNoisyDamageRepair;
   881   static bool gNoisyIntrinsic;
   882   static bool gNoisyReflow;
   883   static bool gReallyNoisyReflow;
   884   static bool gNoisyFloatManager;
   885   static bool gVerifyLines;
   886   static bool gDisableResizeOpt;
   888   static int32_t gNoiseIndent;
   890   static const char* kReflowCommandType[];
   892 protected:
   893   static void InitDebugFlags();
   894 #endif
   895 };
   897 #ifdef DEBUG
   898 class AutoNoisyIndenter {
   899 public:
   900   AutoNoisyIndenter(bool aDoIndent) : mIndented(aDoIndent) {
   901     if (mIndented) {
   902       nsBlockFrame::gNoiseIndent++;
   903     }
   904   }
   905   ~AutoNoisyIndenter() {
   906     if (mIndented) {
   907       nsBlockFrame::gNoiseIndent--;
   908     }
   909   }
   910 private:
   911   bool mIndented;
   912 };
   913 #endif
   915 /**
   916  * Iterates over all lines in the prev-in-flows/next-in-flows of this block.
   917  */
   918 class nsBlockInFlowLineIterator {
   919 public:
   920   typedef nsBlockFrame::line_iterator line_iterator;
   921   /**
   922    * Set up the iterator to point to aLine which must be a normal line
   923    * in aFrame (not an overflow line).
   924    */
   925   nsBlockInFlowLineIterator(nsBlockFrame* aFrame, line_iterator aLine);
   926   /**
   927    * Set up the iterator to point to the first line found starting from
   928    * aFrame. Sets aFoundValidLine to false if there is no such line.
   929    * After aFoundValidLine has returned false, don't call any methods on this
   930    * object again.
   931    */
   932   nsBlockInFlowLineIterator(nsBlockFrame* aFrame, bool* aFoundValidLine);
   933   /**
   934    * Set up the iterator to point to the line that contains aFindFrame (either
   935    * directly or indirectly).  If aFrame is out of flow, or contained in an
   936    * out-of-flow, finds the line containing the out-of-flow's placeholder. If
   937    * the frame is not found, sets aFoundValidLine to false. After
   938    * aFoundValidLine has returned false, don't call any methods on this
   939    * object again.
   940    */
   941   nsBlockInFlowLineIterator(nsBlockFrame* aFrame, nsIFrame* aFindFrame,
   942                             bool* aFoundValidLine);
   944   line_iterator GetLine() { return mLine; }
   945   bool IsLastLineInList();
   946   nsBlockFrame* GetContainer() { return mFrame; }
   947   bool GetInOverflow() { return mLineList != &mFrame->mLines; }
   949   /**
   950    * Returns the current line list we're iterating, null means
   951    * we're iterating |mLines| of the container.
   952    */
   953   nsLineList* GetLineList() { return mLineList; }
   955   /**
   956    * Returns the end-iterator of whatever line list we're in.
   957    */
   958   line_iterator End();
   960   /**
   961    * Returns false if there are no more lines. After this has returned false,
   962    * don't call any methods on this object again.
   963    */
   964   bool Next();
   965   /**
   966    * Returns false if there are no more lines. After this has returned false,
   967    * don't call any methods on this object again.
   968    */
   969   bool Prev();
   971 private:
   972   friend class nsBlockFrame;
   973   // XXX nsBlockFrame uses this internally in one place.  Try to remove it.
   974   nsBlockInFlowLineIterator(nsBlockFrame* aFrame, line_iterator aLine, bool aInOverflow);
   976   nsBlockFrame* mFrame;
   977   line_iterator mLine;
   978   nsLineList*   mLineList;  // the line list mLine is in
   980   /**
   981    * Moves iterator to next valid line reachable from the current block.
   982    * Returns false if there are no valid lines.
   983    */
   984   bool FindValidLine();
   985 };
   987 #endif /* nsBlockFrame_h___ */

mercurial