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 */
40 #ifndef nsLeafFrame_h___
41 #define nsLeafFrame_h___
44 #include "nsDisplayList.h"
47 * Abstract class that provides simple fixed-size layout for leaf objects
48 * (e.g. images, form elements, etc.). Deriviations provide the implementation
49 * of the GetDesiredSize method. The rendering method knows how to render
50 * borders and backgrounds.
52 class nsLeafFrame
: public nsFrame
{
55 // nsIFrame replacements
56 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
57 const nsRect
& aDirtyRect
,
58 const nsDisplayListSet
& aLists
) {
59 DO_GLOBAL_REFLOW_COUNT_DSP("nsLeafFrame");
60 return DisplayBorderBackgroundOutline(aBuilder
, aLists
);
64 * Both GetMinWidth and GetPrefWidth will return whatever GetIntrinsicWidth
67 virtual nscoord
GetMinWidth(nsIRenderingContext
*aRenderingContext
);
68 virtual nscoord
GetPrefWidth(nsIRenderingContext
*aRenderingContext
);
71 * Our auto size is just intrinsic width and intrinsic height.
73 virtual nsSize
ComputeAutoSize(nsIRenderingContext
*aRenderingContext
,
74 nsSize aCBSize
, nscoord aAvailableWidth
,
75 nsSize aMargin
, nsSize aBorder
,
76 nsSize aPadding
, PRBool aShrinkWrap
);
79 * Reflow our frame. This will use the computed width plus borderpadding for
80 * the desired width, and use the return value of GetIntrinsicHeight plus
81 * borderpadding for the desired height. Ascent will be set to the height,
82 * and descent will be set to 0.
84 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
85 nsHTMLReflowMetrics
& aDesiredSize
,
86 const nsHTMLReflowState
& aReflowState
,
87 nsReflowStatus
& aStatus
);
90 * This method does most of the work that Reflow() above need done.
92 NS_IMETHOD
DoReflow(nsPresContext
* aPresContext
,
93 nsHTMLReflowMetrics
& aDesiredSize
,
94 const nsHTMLReflowState
& aReflowState
,
95 nsReflowStatus
& aStatus
);
97 virtual PRBool
IsFrameOfType(PRUint32 aFlags
) const
99 // We don't actually contain a block, but we do always want a
100 // computed width, so tell a little white lie here.
101 return nsFrame::IsFrameOfType(aFlags
& ~(nsIFrame::eReplacedContainsBlock
));
105 nsLeafFrame(nsStyleContext
* aContext
) : nsFrame(aContext
) {}
106 virtual ~nsLeafFrame();
109 * Return the intrinsic width of the frame's content area. Note that this
110 * should not include borders or padding and should not depend on the applied
113 virtual nscoord
GetIntrinsicWidth() = 0;
116 * Return the intrinsic height of the frame's content area. This should not
117 * include border or padding. This will only matter if the specified height
118 * is auto. Note that subclasses must either implement this or override
119 * Reflow and ComputeAutoSize; the default Reflow and ComputeAutoSize impls
122 virtual nscoord
GetIntrinsicHeight();
125 * Subroutine to add in borders and padding
127 void AddBordersAndPadding(const nsHTMLReflowState
& aReflowState
,
128 nsHTMLReflowMetrics
& aDesiredSize
);
131 * Set aDesiredSize to be the available size
133 void SizeToAvailSize(const nsHTMLReflowState
& aReflowState
,
134 nsHTMLReflowMetrics
& aDesiredSize
);
137 #endif /* nsLeafFrame_h___ */