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