1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* base class for rendering objects that do not have child lists */
8 #include "nsLeafFrame.h"
9 #include "nsPresContext.h"
11 using namespace mozilla
;
13 nsLeafFrame::~nsLeafFrame()
17 NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame
)
20 nsLeafFrame::GetMinISize(nsRenderingContext
*aRenderingContext
)
23 DISPLAY_MIN_WIDTH(this, result
);
25 result
= GetIntrinsicISize();
30 nsLeafFrame::GetPrefISize(nsRenderingContext
*aRenderingContext
)
33 DISPLAY_PREF_WIDTH(this, result
);
34 result
= GetIntrinsicISize();
40 nsLeafFrame::ComputeAutoSize(nsRenderingContext
*aRenderingContext
,
42 const LogicalSize
& aCBSize
,
43 nscoord aAvailableISize
,
44 const LogicalSize
& aMargin
,
45 const LogicalSize
& aBorder
,
46 const LogicalSize
& aPadding
,
49 const WritingMode wm
= GetWritingMode();
50 LogicalSize
result(wm
, GetIntrinsicISize(), GetIntrinsicBSize());
51 return result
.ConvertTo(aWM
, wm
);
55 nsLeafFrame::Reflow(nsPresContext
* aPresContext
,
56 nsHTMLReflowMetrics
& aMetrics
,
57 const nsHTMLReflowState
& aReflowState
,
58 nsReflowStatus
& aStatus
)
60 DO_GLOBAL_REFLOW_COUNT("nsLeafFrame");
61 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS
,
62 ("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
63 aReflowState
.AvailableWidth(), aReflowState
.AvailableHeight()));
65 NS_PRECONDITION(mState
& NS_FRAME_IN_REFLOW
, "frame is not in reflow");
67 DoReflow(aPresContext
, aMetrics
, aReflowState
, aStatus
);
69 FinishAndStoreOverflow(&aMetrics
);
73 nsLeafFrame::DoReflow(nsPresContext
* aPresContext
,
74 nsHTMLReflowMetrics
& aMetrics
,
75 const nsHTMLReflowState
& aReflowState
,
76 nsReflowStatus
& aStatus
)
78 NS_ASSERTION(aReflowState
.ComputedWidth() != NS_UNCONSTRAINEDSIZE
,
79 "Shouldn't have unconstrained stuff here "
80 "Thanks to the rules of reflow");
81 NS_ASSERTION(NS_INTRINSICSIZE
!= aReflowState
.ComputedHeight(),
82 "Shouldn't have unconstrained stuff here "
83 "thanks to ComputeAutoSize");
85 WritingMode wm
= aReflowState
.GetWritingMode();
86 LogicalSize
finalSize(wm
,
87 aReflowState
.ComputedISize(),
88 aReflowState
.ComputedBSize());
90 AddBordersAndPadding(aReflowState
, finalSize
);
91 aMetrics
.SetSize(wm
, finalSize
);
93 aStatus
= NS_FRAME_COMPLETE
;
95 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS
,
96 ("exit nsLeafFrame::DoReflow: size=%d,%d",
97 aMetrics
.ISize(wm
), aMetrics
.BSize(wm
)));
98 NS_FRAME_SET_TRUNCATION(aStatus
, aReflowState
, aMetrics
);
100 aMetrics
.SetOverflowAreasToDesiredBounds();
104 nsLeafFrame::GetIntrinsicBSize()
106 NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
110 // XXX how should border&padding effect baseline alignment?
111 // => descent = borderPadding.bottom for example
113 nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState
& aReflowState
,
116 WritingMode wm
= aReflowState
.GetWritingMode();
117 aSize
.ISize(wm
) += aReflowState
.ComputedLogicalBorderPadding().IStartEnd(wm
);
118 aSize
.BSize(wm
) += aReflowState
.ComputedLogicalBorderPadding().BStartEnd(wm
);
122 nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState
& aReflowState
,
123 nsHTMLReflowMetrics
& aDesiredSize
)
125 WritingMode wm
= aReflowState
.GetWritingMode();
126 LogicalSize
size(wm
, aReflowState
.AvailableISize(), // FRAME
127 aReflowState
.AvailableBSize());
128 aDesiredSize
.SetSize(wm
, size
);
129 aDesiredSize
.SetOverflowAreasToDesiredBounds();
130 FinishAndStoreOverflow(&aDesiredSize
);