1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 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/. */
6 
7 /* class that a parent frame uses to reflow a block frame */
8 
9 #ifndef nsBlockReflowContext_h___
10 #define nsBlockReflowContext_h___
11 
12 #include "mozilla/ReflowOutput.h"
13 
14 class nsIFrame;
15 class nsLineBox;
16 class nsPresContext;
17 class nsReflowStatus;
18 namespace mozilla {
19 class BlockReflowState;
20 }  // namespace mozilla
21 
22 /**
23  * An encapsulation of the state and algorithm for reflowing block frames.
24  */
25 class nsBlockReflowContext {
26   using BlockReflowState = mozilla::BlockReflowState;
27   using ReflowInput = mozilla::ReflowInput;
28   using ReflowOutput = mozilla::ReflowOutput;
29 
30  public:
31   nsBlockReflowContext(nsPresContext* aPresContext,
32                        const ReflowInput& aParentRI);
33   ~nsBlockReflowContext() = default;
34 
35   void ReflowBlock(const mozilla::LogicalRect& aSpace, bool aApplyBStartMargin,
36                    nsCollapsingMargin& aPrevMargin, nscoord aClearance,
37                    bool aIsAdjacentWithBStart, nsLineBox* aLine,
38                    ReflowInput& aReflowInput, nsReflowStatus& aReflowStatus,
39                    BlockReflowState& aState);
40 
41   bool PlaceBlock(const ReflowInput& aReflowInput, bool aForceFit,
42                   nsLineBox* aLine,
43                   nsCollapsingMargin& aBEndMarginResult /* out */,
44                   mozilla::OverflowAreas& aOverflowAreas,
45                   const nsReflowStatus& aReflowStatus);
46 
GetCarriedOutBEndMargin()47   nsCollapsingMargin& GetCarriedOutBEndMargin() {
48     return mMetrics.mCarriedOutBEndMargin;
49   }
50 
GetMetrics()51   const ReflowOutput& GetMetrics() const { return mMetrics; }
52 
53   /**
54    * Computes the collapsed block-start margin (in the context's parent's
55    * writing mode) for a block whose reflow input is in aRI.
56    * The computed margin is added into aMargin, whose writing mode is the
57    * parent's mode as found in mMetrics.GetWritingMode(); note this may not be
58    * the block's own writing mode as found in aRI.
59    * If aClearanceFrame is null then this is the first optimistic pass which
60    * shall assume that no frames have clearance, and we clear the HasClearance
61    * on all frames encountered.
62    * If non-null, this is the second pass and the caller has decided
63    * aClearanceFrame needs clearance (and we will therefore stop collapsing
64    * there); also, this function is responsible for marking it with
65    * SetHasClearance.
66    * If in the optimistic pass any frame is encountered that might possibly
67    * need clearance (i.e., if we really needed the optimism assumption) then
68    * we set aMayNeedRetry to true.
69    * We return true if we changed the clearance state of any line and marked it
70    * dirty.
71    */
72   bool ComputeCollapsedBStartMargin(const ReflowInput& aRI,
73                                     nsCollapsingMargin* aMargin,
74                                     nsIFrame* aClearanceFrame,
75                                     bool* aMayNeedRetry,
76                                     bool* aIsEmpty = nullptr);
77 
78  protected:
79   nsPresContext* mPresContext;
80   const ReflowInput& mOuterReflowInput;
81 
82   nsIFrame* mFrame;
83   mozilla::LogicalRect mSpace;
84 
85   nscoord mICoord, mBCoord;
86   nsSize mContainerSize;
87   mozilla::WritingMode mWritingMode;
88   ReflowOutput mMetrics;
89   nsCollapsingMargin mBStartMargin;
90 };
91 
92 #endif /* nsBlockReflowContext_h___ */
93