Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLReflowMetrics.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsHTMLReflowMetrics_h___
00038 #define nsHTMLReflowMetrics_h___
00039 
00040 #include <stdio.h>
00041 #include "nsISupports.h"
00042 #include "nsMargin.h"
00043 #include "nsRect.h"
00044 // for MOZ_MATHML
00045 #include "nsIRenderingContext.h" //to get struct nsBoundingMetrics
00046 
00047 //----------------------------------------------------------------------
00048 
00049 // Option flags
00050 #define NS_REFLOW_CALC_MAX_WIDTH         0x0001
00051 #ifdef MOZ_MATHML
00052 #define NS_REFLOW_CALC_BOUNDING_METRICS  0x0002
00053 #endif
00054 
00064 struct nsCollapsingMargin {
00065   private:
00066     nscoord mMostPos;  // the largest positive margin included
00067     nscoord mMostNeg;  // the smallest negative margin included
00068 
00069   public:
00070     nsCollapsingMargin()
00071         : mMostPos(0),
00072           mMostNeg(0)
00073       {
00074       }
00075 
00076     nsCollapsingMargin(const nsCollapsingMargin& aOther)
00077         : mMostPos(aOther.mMostPos),
00078           mMostNeg(aOther.mMostNeg)
00079       {
00080       }
00081 
00082     PRBool operator==(const nsCollapsingMargin& aOther)
00083       {
00084         return mMostPos == aOther.mMostPos &&
00085           mMostNeg == aOther.mMostNeg;
00086       }
00087 
00088     PRBool operator!=(const nsCollapsingMargin& aOther)
00089       {
00090         return !(*this == aOther);
00091       }
00092 
00093     nsCollapsingMargin& operator=(const nsCollapsingMargin& aOther)
00094       {
00095         mMostPos = aOther.mMostPos;
00096         mMostNeg = aOther.mMostNeg;
00097         return *this;
00098       }
00099 
00100     void Include(nscoord aCoord)
00101       {
00102         if (aCoord > mMostPos)
00103           mMostPos = aCoord;
00104         else if (aCoord < mMostNeg)
00105           mMostNeg = aCoord;
00106       }
00107 
00108     void Include(const nsCollapsingMargin& aOther)
00109       {
00110         if (aOther.mMostPos > mMostPos)
00111           mMostPos = aOther.mMostPos;
00112         if (aOther.mMostNeg < mMostNeg)
00113           mMostNeg = aOther.mMostNeg;
00114       }
00115 
00116     void Zero()
00117       {
00118         mMostPos = 0;
00119         mMostNeg = 0;
00120       }
00121 
00122     PRBool IsZero() const
00123       {
00124         return (mMostPos == 0) && (mMostNeg == 0);
00125       }
00126 
00127     nscoord get() const
00128       {
00129         return mMostPos + mMostNeg;
00130       }
00131 };
00132 
00139 struct nsHTMLReflowMetrics {
00140   nscoord width, height;        // [OUT] desired width and height
00141   nscoord ascent, descent;      // [OUT] ascent and descent information
00142 
00143   nscoord mMaxElementWidth;     // [OUT]
00144 
00145   // Used for incremental reflow. If the NS_REFLOW_CALC_MAX_WIDTH flag is set,
00146   // then the caller is requesting that you update and return your maximum width
00147   nscoord mMaximumWidth;        // [OUT]
00148 
00149 #ifdef MOZ_MATHML
00150   // Metrics that _exactly_ enclose the text to allow precise MathML placements.
00151   // If the NS_REFLOW_CALC_BOUNDING_METRICS flag is set, then the caller is 
00152   // requesting that you also compute additional details about your inner
00153   // bounding box and italic correction. For example, the bounding box of
00154   // msup is the smallest rectangle that _exactly_ encloses both the text
00155   // of the base and the text of the superscript.
00156   nsBoundingMetrics mBoundingMetrics;  // [OUT]
00157 #endif
00158 
00159   // Carried out bottom margin values. This is the collapsed
00160   // (generational) bottom margin value.
00161   nsCollapsingMargin mCarriedOutBottomMargin;
00162   
00163   // For frames that have content that overflow their content area
00164   // (NS_FRAME_OUTSIDE_CHILDREN) this rectangle represents the total area
00165   // of the frame including visible overflow, i.e., don't include overflowing
00166   // content that is hidden.
00167   // The rect is in the local coordinate space of the frame, and should be at
00168   // least as big as the desired size. If there is no content that overflows,
00169   // then the overflow area is identical to the desired size and should be
00170   // {0, 0, mWidth, mHeight}.
00171   nsRect mOverflowArea;
00172 
00173   PRUint32 mFlags;
00174  
00175   // used by tables to optimize common cases
00176   PRPackedBool mNothingChanged;
00177 
00178   // Should we compute mMaxElementWidth?
00179   PRPackedBool mComputeMEW;
00180 
00181   nsHTMLReflowMetrics(PRBool aComputeMEW, PRUint32 aFlags = 0) {
00182     mComputeMEW = aComputeMEW;
00183     mMaxElementWidth = 0;
00184     mMaximumWidth = 0;
00185     mFlags = aFlags;
00186     mOverflowArea.x = 0;
00187     mOverflowArea.y = 0;
00188     mOverflowArea.width = 0;
00189     mOverflowArea.height = 0;
00190     mNothingChanged = PR_FALSE;
00191 #ifdef MOZ_MATHML
00192     mBoundingMetrics.Clear();
00193 #endif
00194 
00195     // XXX These are OUT parameters and so they shouldn't have to be
00196     // initialized, but there are some bad frame classes that aren't
00197     // properly setting them when returning from Reflow()...
00198     width = height = 0;
00199     ascent = descent = 0;
00200   }
00201 
00208   void SetMEWToActualWidth(nsStyleUnit aWidthUnit) {
00209     if (aWidthUnit != eStyleUnit_Percent) {
00210       mMaxElementWidth = width;
00211     } else {
00212       mMaxElementWidth = 0;
00213     }
00214   }
00215 
00216   nsHTMLReflowMetrics& operator=(const nsHTMLReflowMetrics& aOther)
00217   {
00218     mMaxElementWidth = aOther.mMaxElementWidth;
00219     mMaximumWidth = aOther.mMaximumWidth;
00220     mFlags = aOther.mFlags;
00221     mCarriedOutBottomMargin = aOther.mCarriedOutBottomMargin;
00222     mOverflowArea.x = aOther.mOverflowArea.x;
00223     mOverflowArea.y = aOther.mOverflowArea.y;
00224     mOverflowArea.width = aOther.mOverflowArea.width;
00225     mOverflowArea.height = aOther.mOverflowArea.height;
00226     mNothingChanged = aOther.mNothingChanged;
00227 #ifdef MOZ_MATHML
00228     mBoundingMetrics = aOther.mBoundingMetrics;
00229 #endif
00230 
00231     width = aOther.width;
00232     height = aOther.height;
00233     ascent = aOther.ascent;
00234     descent = aOther.descent;
00235     return *this;
00236   }
00237 
00238 };
00239 
00240 #endif /* nsHTMLReflowMetrics_h___ */