Back to index

lightning-sunbird  0.9+nobinonly
nsMathMLmspaceFrame.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla MathML Project.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * The University Of Queensland.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Roger B. Sidje <rbs@maths.uq.edu.au>
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 
00038 
00039 #include "nsCOMPtr.h"
00040 #include "nsFrame.h"
00041 #include "nsPresContext.h"
00042 #include "nsUnitConversion.h"
00043 #include "nsStyleContext.h"
00044 #include "nsStyleConsts.h"
00045 #include "nsIRenderingContext.h"
00046 #include "nsIFontMetrics.h"
00047 
00048 #include "nsMathMLmspaceFrame.h"
00049 
00050 
00051 //
00052 // <mspace> -- space - implementation
00053 //
00054 
00055 nsresult
00056 NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00057 {
00058   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00059   if (nsnull == aNewFrame) {
00060     return NS_ERROR_NULL_POINTER;
00061   }
00062   nsMathMLmspaceFrame* it = new (aPresShell) nsMathMLmspaceFrame;
00063   if (nsnull == it) {
00064     return NS_ERROR_OUT_OF_MEMORY;
00065   }
00066   *aNewFrame = it;
00067   return NS_OK;
00068 }
00069 
00070 nsMathMLmspaceFrame::nsMathMLmspaceFrame()
00071 {
00072 }
00073 
00074 nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
00075 {
00076 }
00077 
00078 PRBool
00079 nsMathMLmspaceFrame::IsLeaf() const
00080 {
00081   return PR_TRUE;
00082 }
00083 
00084 void
00085 nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
00086 {
00087   /*
00088   parse the attributes
00089 
00090   width  = number h-unit 
00091   height = number v-unit 
00092   depth  = number v-unit 
00093   */
00094 
00095   nsAutoString value;
00096   nsCSSValue cssValue;
00097 
00098   // width 
00099   mWidth = 0;
00100   if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(mContent, mPresentationData.mstyle,
00101                    nsMathMLAtoms::width_, value)) {
00102     if ((ParseNumericValue(value, cssValue) ||
00103          ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
00104          cssValue.IsLengthUnit()) {
00105       mWidth = CalcLength(aPresContext, mStyleContext, cssValue);
00106     }
00107   }
00108 
00109   // height
00110   mHeight = 0;
00111   if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(mContent, mPresentationData.mstyle,
00112                    nsMathMLAtoms::height_, value)) {
00113     if ((ParseNumericValue(value, cssValue) ||
00114          ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
00115          cssValue.IsLengthUnit()) {
00116       mHeight = CalcLength(aPresContext, mStyleContext, cssValue);
00117     }
00118   }
00119 
00120   // depth
00121   mDepth = 0;
00122   if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(mContent, mPresentationData.mstyle,
00123                    nsMathMLAtoms::depth_, value)) {
00124     if ((ParseNumericValue(value, cssValue) ||
00125          ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
00126          cssValue.IsLengthUnit()) {
00127       mDepth = CalcLength(aPresContext, mStyleContext, cssValue);
00128     }
00129   }
00130 }
00131 
00132 NS_IMETHODIMP
00133 nsMathMLmspaceFrame::Reflow(nsPresContext*          aPresContext,
00134                             nsHTMLReflowMetrics&     aDesiredSize,
00135                             const nsHTMLReflowState& aReflowState,
00136                             nsReflowStatus&          aStatus)
00137 {
00138   ProcessAttributes(aPresContext);
00139 
00140   mBoundingMetrics.Clear();
00141   mBoundingMetrics.width = mWidth;
00142   mBoundingMetrics.ascent = mHeight;
00143   mBoundingMetrics.descent = mDepth;
00144 
00145   aDesiredSize.ascent = mHeight;
00146   aDesiredSize.descent = mDepth;
00147   aDesiredSize.width = mWidth;
00148   aDesiredSize.height = aDesiredSize.ascent + aDesiredSize.descent;
00149   if (aDesiredSize.mComputeMEW) {
00150     aDesiredSize.mMaxElementWidth = aDesiredSize.width;
00151   }
00152   // Also return our bounding metrics
00153   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
00154 
00155   aStatus = NS_FRAME_COMPLETE;
00156   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
00157   return NS_OK;
00158 }