1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* base class for rendering objects that do not have child lists */
41 #include "nsLeafFrame.h"
42 #include "nsHTMLContainerFrame.h"
43 #include "nsHTMLParts.h"
44 #include "nsPresContext.h"
46 nsLeafFrame::~nsLeafFrame()
50 NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame
)
53 nsLeafFrame::GetMinWidth(nsIRenderingContext
*aRenderingContext
)
56 DISPLAY_MIN_WIDTH(this, result
);
58 result
= GetIntrinsicWidth();
63 nsLeafFrame::GetPrefWidth(nsIRenderingContext
*aRenderingContext
)
66 DISPLAY_PREF_WIDTH(this, result
);
67 result
= GetIntrinsicWidth();
72 nsLeafFrame::ComputeAutoSize(nsIRenderingContext
*aRenderingContext
,
73 nsSize aCBSize
, nscoord aAvailableWidth
,
74 nsSize aMargin
, nsSize aBorder
,
75 nsSize aPadding
, PRBool aShrinkWrap
)
77 return nsSize(GetIntrinsicWidth(), GetIntrinsicHeight());
81 nsLeafFrame::Reflow(nsPresContext
* aPresContext
,
82 nsHTMLReflowMetrics
& aMetrics
,
83 const nsHTMLReflowState
& aReflowState
,
84 nsReflowStatus
& aStatus
)
86 DO_GLOBAL_REFLOW_COUNT("nsLeafFrame");
87 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS
,
88 ("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
89 aReflowState
.availableWidth
, aReflowState
.availableHeight
));
91 NS_PRECONDITION(mState
& NS_FRAME_IN_REFLOW
, "frame is not in reflow");
93 DoReflow(aPresContext
, aMetrics
, aReflowState
, aStatus
);
95 FinishAndStoreOverflow(&aMetrics
);
100 nsLeafFrame::DoReflow(nsPresContext
* aPresContext
,
101 nsHTMLReflowMetrics
& aMetrics
,
102 const nsHTMLReflowState
& aReflowState
,
103 nsReflowStatus
& aStatus
)
105 NS_ASSERTION(aReflowState
.ComputedWidth() != NS_UNCONSTRAINEDSIZE
,
106 "Shouldn't have unconstrained stuff here "
107 "Thanks to the rules of reflow");
108 NS_ASSERTION(NS_INTRINSICSIZE
!= aReflowState
.ComputedHeight(),
109 "Shouldn't have unconstrained stuff here "
110 "thanks to ComputeAutoSize");
112 aMetrics
.width
= aReflowState
.ComputedWidth();
113 aMetrics
.height
= aReflowState
.ComputedHeight();
115 AddBordersAndPadding(aReflowState
, aMetrics
);
116 aStatus
= NS_FRAME_COMPLETE
;
118 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS
,
119 ("exit nsLeafFrame::DoReflow: size=%d,%d",
120 aMetrics
.width
, aMetrics
.height
));
121 NS_FRAME_SET_TRUNCATION(aStatus
, aReflowState
, aMetrics
);
123 aMetrics
.SetOverflowAreasToDesiredBounds();
129 nsLeafFrame::GetIntrinsicHeight()
131 NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
135 // XXX how should border&padding effect baseline alignment?
136 // => descent = borderPadding.bottom for example
138 nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState
& aReflowState
,
139 nsHTMLReflowMetrics
& aMetrics
)
141 aMetrics
.width
+= aReflowState
.mComputedBorderPadding
.LeftRight();
142 aMetrics
.height
+= aReflowState
.mComputedBorderPadding
.TopBottom();
146 nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState
& aReflowState
,
147 nsHTMLReflowMetrics
& aDesiredSize
)
149 aDesiredSize
.width
= aReflowState
.availableWidth
; // FRAME
150 aDesiredSize
.height
= aReflowState
.availableHeight
;
151 aDesiredSize
.SetOverflowAreasToDesiredBounds();
152 FinishAndStoreOverflow(&aDesiredSize
);