CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / layout / generic / nsLeafFrame.cpp
blob170e81cc89ea72d5bf87a809b68a37cc80a71ec9
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
13 * License.
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.
22 * Contributor(s):
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 */
40 #include "nsCOMPtr.h"
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)
52 /* virtual */ nscoord
53 nsLeafFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
55 nscoord result;
56 DISPLAY_MIN_WIDTH(this, result);
58 result = GetIntrinsicWidth();
59 return result;
62 /* virtual */ nscoord
63 nsLeafFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
65 nscoord result;
66 DISPLAY_PREF_WIDTH(this, result);
67 result = GetIntrinsicWidth();
68 return result;
71 /* virtual */ nsSize
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());
80 NS_IMETHODIMP
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);
96 return NS_OK;
99 NS_IMETHODIMP
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();
125 return NS_OK;
128 nscoord
129 nsLeafFrame::GetIntrinsicHeight()
131 NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
132 return 0;
135 // XXX how should border&padding effect baseline alignment?
136 // => descent = borderPadding.bottom for example
137 void
138 nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState& aReflowState,
139 nsHTMLReflowMetrics& aMetrics)
141 aMetrics.width += aReflowState.mComputedBorderPadding.LeftRight();
142 aMetrics.height += aReflowState.mComputedBorderPadding.TopBottom();
145 void
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);