Fixed textfield rendering in nsNativeThemeQt
[mozilla-central.git] / layout / generic / nsHTMLReflowMetrics.h
blobde2e26fbfaabd4f608a7bc533eac3fa2cefce421
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 /* struct containing the output from nsIFrame::Reflow */
40 #ifndef nsHTMLReflowMetrics_h___
41 #define nsHTMLReflowMetrics_h___
43 #include <stdio.h>
44 #include "nsISupports.h"
45 #include "nsMargin.h"
46 #include "nsRect.h"
47 // for MOZ_MATHML
48 #include "nsIRenderingContext.h" //to get struct nsBoundingMetrics
50 //----------------------------------------------------------------------
52 // Option flags
53 #ifdef MOZ_MATHML
54 #define NS_REFLOW_CALC_BOUNDING_METRICS 0x0001
55 #endif
57 /**
58 * An nsCollapsingMargin represents a vertical collapsing margin between
59 * blocks as described in section 8.3.1 of CSS2,
60 * <URL: http://www.w3.org/TR/REC-CSS2/box.html#collapsing-margins >.
62 * All adjacent vertical margins collapse, and the resulting margin is
63 * the sum of the largest positive margin included and the smallest (most
64 * negative) negative margin included.
66 struct nsCollapsingMargin {
67 private:
68 nscoord mMostPos; // the largest positive margin included
69 nscoord mMostNeg; // the smallest negative margin included
71 public:
72 nsCollapsingMargin()
73 : mMostPos(0),
74 mMostNeg(0)
78 nsCollapsingMargin(const nsCollapsingMargin& aOther)
79 : mMostPos(aOther.mMostPos),
80 mMostNeg(aOther.mMostNeg)
84 PRBool operator==(const nsCollapsingMargin& aOther)
86 return mMostPos == aOther.mMostPos &&
87 mMostNeg == aOther.mMostNeg;
90 PRBool operator!=(const nsCollapsingMargin& aOther)
92 return !(*this == aOther);
95 nsCollapsingMargin& operator=(const nsCollapsingMargin& aOther)
97 mMostPos = aOther.mMostPos;
98 mMostNeg = aOther.mMostNeg;
99 return *this;
102 void Include(nscoord aCoord)
104 if (aCoord > mMostPos)
105 mMostPos = aCoord;
106 else if (aCoord < mMostNeg)
107 mMostNeg = aCoord;
110 void Include(const nsCollapsingMargin& aOther)
112 if (aOther.mMostPos > mMostPos)
113 mMostPos = aOther.mMostPos;
114 if (aOther.mMostNeg < mMostNeg)
115 mMostNeg = aOther.mMostNeg;
118 void Zero()
120 mMostPos = 0;
121 mMostNeg = 0;
124 PRBool IsZero() const
126 return (mMostPos == 0) && (mMostNeg == 0);
129 nscoord get() const
131 return mMostPos + mMostNeg;
136 * Reflow metrics used to return the frame's desired size and alignment
137 * information.
139 * @see #Reflow()
141 struct nsHTMLReflowMetrics {
142 nscoord width, height; // [OUT] desired width and height (border-box)
143 nscoord ascent; // [OUT] baseline (from top), or ASK_FOR_BASELINE
145 enum { ASK_FOR_BASELINE = nscoord_MAX };
147 #ifdef MOZ_MATHML
148 // Metrics that _exactly_ enclose the text to allow precise MathML placements.
149 // If the NS_REFLOW_CALC_BOUNDING_METRICS flag is set, then the caller is
150 // requesting that you also compute additional details about your inner
151 // bounding box and italic correction. For example, the bounding box of
152 // msup is the smallest rectangle that _exactly_ encloses both the text
153 // of the base and the text of the superscript.
154 nsBoundingMetrics mBoundingMetrics; // [OUT]
155 #endif
157 // Carried out bottom margin values. This is the collapsed
158 // (generational) bottom margin value.
159 nsCollapsingMargin mCarriedOutBottomMargin;
161 // For frames that have content that overflow their content area
162 // (NS_FRAME_OUTSIDE_CHILDREN) this rectangle represents the total area
163 // of the frame including visible overflow, i.e., don't include overflowing
164 // content that is hidden.
165 // The rect is in the local coordinate space of the frame, and should be at
166 // least as big as the desired size. If there is no content that overflows,
167 // then the overflow area is identical to the desired size and should be
168 // {0, 0, mWidth, mHeight}.
169 nsRect mOverflowArea;
171 PRUint32 mFlags;
173 // XXXldb Should |aFlags| generally be passed from parent to child?
174 // Some places do it, and some don't. |aFlags| should perhaps go away
175 // entirely.
176 nsHTMLReflowMetrics(PRUint32 aFlags = 0) {
177 mFlags = aFlags;
178 mOverflowArea.x = 0;
179 mOverflowArea.y = 0;
180 mOverflowArea.width = 0;
181 mOverflowArea.height = 0;
182 #ifdef MOZ_MATHML
183 mBoundingMetrics.Clear();
184 #endif
186 // XXX These are OUT parameters and so they shouldn't have to be
187 // initialized, but there are some bad frame classes that aren't
188 // properly setting them when returning from Reflow()...
189 width = height = 0;
190 ascent = ASK_FOR_BASELINE;
193 nsHTMLReflowMetrics& operator=(const nsHTMLReflowMetrics& aOther)
195 mFlags = aOther.mFlags;
196 mCarriedOutBottomMargin = aOther.mCarriedOutBottomMargin;
197 mOverflowArea.x = aOther.mOverflowArea.x;
198 mOverflowArea.y = aOther.mOverflowArea.y;
199 mOverflowArea.width = aOther.mOverflowArea.width;
200 mOverflowArea.height = aOther.mOverflowArea.height;
201 #ifdef MOZ_MATHML
202 mBoundingMetrics = aOther.mBoundingMetrics;
203 #endif
205 width = aOther.width;
206 height = aOther.height;
207 ascent = aOther.ascent;
208 return *this;
213 #endif /* nsHTMLReflowMetrics_h___ */