Back to index

lightning-sunbird  0.9+nobinonly
nsMathMLForeignFrameWrapper.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 // a helper frame class to wrap non-MathML frames so that foreign elements 
00040 // (e.g., html:img) can mix better with other surrounding MathML markups
00041 //
00042 
00043 #include "nsCOMPtr.h"
00044 #include "nsHTMLParts.h"
00045 #include "nsFrame.h"
00046 #include "nsAreaFrame.h"
00047 #include "nsLineLayout.h"
00048 #include "nsPresContext.h"
00049 #include "nsHTMLAtoms.h"
00050 #include "nsUnitConversion.h"
00051 #include "nsStyleContext.h"
00052 #include "nsStyleConsts.h"
00053 #include "nsIRenderingContext.h"
00054 #include "nsIFontMetrics.h"
00055 
00056 #include "nsMathMLForeignFrameWrapper.h"
00057 
00058 NS_IMPL_ADDREF_INHERITED(nsMathMLForeignFrameWrapper, nsMathMLFrame)
00059 NS_IMPL_RELEASE_INHERITED(nsMathMLForeignFrameWrapper, nsMathMLFrame)
00060 NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLForeignFrameWrapper, nsBlockFrame, nsMathMLFrame)
00061 
00062 nsresult
00063 NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00064 {
00065   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00066   if (nsnull == aNewFrame) {
00067     return NS_ERROR_NULL_POINTER;
00068   }
00069   nsMathMLForeignFrameWrapper* it = new (aPresShell) nsMathMLForeignFrameWrapper;
00070   if (nsnull == it) {
00071     return NS_ERROR_OUT_OF_MEMORY;
00072   }
00073   *aNewFrame = it;
00074   return NS_OK;
00075 }
00076 
00077 NS_IMETHODIMP
00078 nsMathMLForeignFrameWrapper::Init(nsPresContext*  aPresContext,
00079                                   nsIContent*      aContent,
00080                                   nsIFrame*        aParent,
00081                                   nsStyleContext*  aContext,
00082                                   nsIFrame*        aPrevInFlow)
00083 {
00084   return nsBlockFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
00085 }
00086 
00087 NS_IMETHODIMP
00088 nsMathMLForeignFrameWrapper::Reflow(nsPresContext*          aPresContext,
00089                                     nsHTMLReflowMetrics&     aDesiredSize,
00090                                     const nsHTMLReflowState& aReflowState,
00091                                     nsReflowStatus&          aStatus)
00092 {
00093   // Let the base class do the reflow
00094   nsresult rv = nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
00095 
00096   mReference.x = 0;
00097   mReference.y = aDesiredSize.ascent;
00098 
00099   // just make-up a bounding metrics
00100   mBoundingMetrics.Clear();
00101   mBoundingMetrics.ascent = aDesiredSize.ascent;
00102   mBoundingMetrics.descent = aDesiredSize.descent;
00103   mBoundingMetrics.width = aDesiredSize.width;
00104   mBoundingMetrics.leftBearing = 0;
00105   mBoundingMetrics.rightBearing = aDesiredSize.width;
00106   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
00107 
00108   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
00109   return rv;
00110 }