|
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/. */ |
|
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 "nsHTMLReflowMetrics.h" |
|
14 |
|
15 class nsBlockReflowState; |
|
16 struct nsHTMLReflowState; |
|
17 class nsLineBox; |
|
18 class nsPresContext; |
|
19 class nsLineLayout; |
|
20 struct nsBlockHorizontalAlign; |
|
21 |
|
22 /** |
|
23 * An encapsulation of the state and algorithm for reflowing block frames. |
|
24 */ |
|
25 class nsBlockReflowContext { |
|
26 public: |
|
27 nsBlockReflowContext(nsPresContext* aPresContext, |
|
28 const nsHTMLReflowState& aParentRS); |
|
29 ~nsBlockReflowContext() { } |
|
30 |
|
31 nsresult ReflowBlock(const nsRect& aSpace, |
|
32 bool aApplyTopMargin, |
|
33 nsCollapsingMargin& aPrevMargin, |
|
34 nscoord aClearance, |
|
35 bool aIsAdjacentWithTop, |
|
36 nsLineBox* aLine, |
|
37 nsHTMLReflowState& aReflowState, |
|
38 nsReflowStatus& aReflowStatus, |
|
39 nsBlockReflowState& aState); |
|
40 |
|
41 bool PlaceBlock(const nsHTMLReflowState& aReflowState, |
|
42 bool aForceFit, |
|
43 nsLineBox* aLine, |
|
44 nsCollapsingMargin& aBottomMarginResult /* out */, |
|
45 nsOverflowAreas& aOverflowAreas, |
|
46 nsReflowStatus aReflowStatus, |
|
47 nscoord aContainerWidth); |
|
48 |
|
49 nsCollapsingMargin& GetCarriedOutBottomMargin() { |
|
50 return mMetrics.mCarriedOutBottomMargin; |
|
51 } |
|
52 |
|
53 nscoord GetTopMargin() const { |
|
54 return mTopMargin.get(); |
|
55 } |
|
56 |
|
57 const nsHTMLReflowMetrics& GetMetrics() const { |
|
58 return mMetrics; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Computes the collapsed top margin for a block whose reflow state is in aRS. |
|
63 * The computed margin is added into aMargin. |
|
64 * If aClearanceFrame is null then this is the first optimistic pass which shall assume |
|
65 * that no frames have clearance, and we clear the HasClearance on all frames encountered. |
|
66 * If non-null, this is the second pass and |
|
67 * the caller has decided aClearanceFrame needs clearance (and we will |
|
68 * therefore stop collapsing there); also, this function is responsible for marking |
|
69 * it with SetHasClearance. |
|
70 * If in the optimistic pass any frame is encountered that might possibly need |
|
71 * clearance (i.e., if we really needed the optimism assumption) then we set aMayNeedRetry |
|
72 * to true. |
|
73 * We return true if we changed the clearance state of any line and marked it dirty. |
|
74 */ |
|
75 static bool ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS, |
|
76 nsCollapsingMargin* aMargin, nsIFrame* aClearanceFrame, |
|
77 bool* aMayNeedRetry, bool* aIsEmpty = nullptr); |
|
78 |
|
79 protected: |
|
80 nsPresContext* mPresContext; |
|
81 const nsHTMLReflowState& mOuterReflowState; |
|
82 |
|
83 nsIFrame* mFrame; |
|
84 nsRect mSpace; |
|
85 |
|
86 nscoord mX, mY; |
|
87 nsHTMLReflowMetrics mMetrics; |
|
88 nsCollapsingMargin mTopMargin; |
|
89 }; |
|
90 |
|
91 #endif /* nsBlockReflowContext_h___ */ |