2007-06-12 10:10:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-18 18:30:37 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-01-27 15:35:30 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-01-27 15:35:30 +03:00
|
|
|
*
|
1999-09-21 06:12:01 +04:00
|
|
|
* The Original Code is Mozilla MathML Project.
|
2000-01-27 15:35:30 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The University Of Queensland.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-01-27 15:35:30 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-09-21 06:12:01 +04:00
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
|
2008-01-03 07:33:21 +03:00
|
|
|
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
|
2004-04-18 18:30:37 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2003-04-01 23:38:12 +04:00
|
|
|
#include "nsCRT.h" // to get NS_IS_SPACE
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
|
|
|
#include "nsMathMLmpaddedFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mpadded> -- adjust space around content - implementation
|
|
|
|
//
|
|
|
|
|
2000-01-27 15:35:30 +03:00
|
|
|
#define NS_MATHML_SIGN_INVALID -1 // if the attribute is not there
|
|
|
|
#define NS_MATHML_SIGN_UNSPECIFIED 0
|
|
|
|
#define NS_MATHML_SIGN_MINUS 1
|
|
|
|
#define NS_MATHML_SIGN_PLUS 2
|
|
|
|
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_UNSPECIFIED 0
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_ITSELF 1 // special
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_WIDTH 2
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_HEIGHT 3
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_DEPTH 4
|
|
|
|
#define NS_MATHML_PSEUDO_UNIT_LSPACE 5
|
2000-05-16 17:15:15 +04:00
|
|
|
#define NS_MATHML_PSEUDO_UNIT_NAMEDSPACE 6
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmpaddedFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmpaddedFrame(aContext);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmpaddedFrame)
|
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
nsMathMLmpaddedFrame::~nsMathMLmpaddedFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmpaddedFrame::InheritAutomaticData(nsIFrame* aParent)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2002-02-02 08:43:03 +03:00
|
|
|
// let the base class get the default from our parent
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::InheritAutomaticData(aParent);
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmpaddedFrame::ProcessAttributes()
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
2000-01-27 15:35:30 +03:00
|
|
|
/*
|
|
|
|
parse the attributes
|
|
|
|
|
2000-05-16 17:15:15 +04:00
|
|
|
width = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit | namedspace)
|
2000-01-27 15:35:30 +03:00
|
|
|
height= [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit)
|
|
|
|
depth = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit)
|
|
|
|
lspace= [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit)
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
/* The REC says:
|
|
|
|
There is one exceptional element, <mpadded>, whose attributes cannot be
|
|
|
|
set with <mstyle>. When the attributes width, height and depth are specified
|
|
|
|
on an <mstyle> element, they apply only to the <mspace/> element. Similarly,
|
|
|
|
when lspace is set with <mstyle>, it applies only to the <mo> element.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// See if attributes are local, don't access mstyle !
|
|
|
|
|
|
|
|
// width
|
|
|
|
mWidthSign = NS_MATHML_SIGN_INVALID;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttribute(mContent, nsnull, nsGkAtoms::width, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2000-01-27 15:35:30 +03:00
|
|
|
ParseAttribute(value, mWidthSign, mWidth, mWidthPseudoUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
|
|
|
mHeightSign = NS_MATHML_SIGN_INVALID;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttribute(mContent, nsnull, nsGkAtoms::height, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2000-01-27 15:35:30 +03:00
|
|
|
ParseAttribute(value, mHeightSign, mHeight, mHeightPseudoUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// depth
|
|
|
|
mDepthSign = NS_MATHML_SIGN_INVALID;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttribute(mContent, nsnull, nsGkAtoms::depth_, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2000-01-27 15:35:30 +03:00
|
|
|
ParseAttribute(value, mDepthSign, mDepth, mDepthPseudoUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// lspace
|
|
|
|
mLeftSpaceSign = NS_MATHML_SIGN_INVALID;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttribute(mContent, nsnull, nsGkAtoms::lspace_, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2000-01-27 15:35:30 +03:00
|
|
|
ParseAttribute(value, mLeftSpaceSign, mLeftSpace, mLeftSpacePseudoUnit);
|
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// parse an input string in the following format (see bug 148326 for testcases):
|
|
|
|
// [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | css-unit | namedspace)
|
2000-01-27 15:35:30 +03:00
|
|
|
PRBool
|
|
|
|
nsMathMLmpaddedFrame::ParseAttribute(nsString& aString,
|
|
|
|
PRInt32& aSign,
|
|
|
|
nsCSSValue& aCSSValue,
|
|
|
|
PRInt32& aPseudoUnit)
|
|
|
|
{
|
|
|
|
aCSSValue.Reset();
|
2002-06-15 03:20:03 +04:00
|
|
|
aSign = NS_MATHML_SIGN_INVALID;
|
|
|
|
aPseudoUnit = NS_MATHML_PSEUDO_UNIT_UNSPECIFIED;
|
2000-01-27 15:35:30 +03:00
|
|
|
aString.CompressWhitespace(); // aString is not a const in this code
|
|
|
|
|
|
|
|
PRInt32 stringLength = aString.Length();
|
2002-06-15 03:20:03 +04:00
|
|
|
if (!stringLength)
|
|
|
|
return PR_FALSE;
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
nsAutoString number, unit;
|
2000-01-27 15:35:30 +03:00
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// see if the sign is there
|
|
|
|
|
|
|
|
PRInt32 i = 0;
|
|
|
|
|
|
|
|
if (aString[0] == '+') {
|
|
|
|
aSign = NS_MATHML_SIGN_PLUS;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (aString[0] == '-') {
|
|
|
|
aSign = NS_MATHML_SIGN_MINUS;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aSign = NS_MATHML_SIGN_UNSPECIFIED;
|
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
// skip any space after the sign
|
2005-03-30 11:34:20 +04:00
|
|
|
if (i < stringLength && nsCRT::IsAsciiSpace(aString[i]))
|
2000-01-27 15:35:30 +03:00
|
|
|
i++;
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// get the number
|
|
|
|
PRBool gotDot = PR_FALSE, gotPercent = PR_FALSE;
|
|
|
|
for (; i < stringLength; i++) {
|
|
|
|
PRUnichar c = aString[i];
|
|
|
|
if (gotDot && c == '.') {
|
|
|
|
// error - two dots encountered
|
|
|
|
aSign = NS_MATHML_SIGN_INVALID;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
if (c == '.')
|
|
|
|
gotDot = PR_TRUE;
|
|
|
|
else if (!nsCRT::IsAsciiDigit(c)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
number.Append(c);
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
2002-06-15 03:20:03 +04:00
|
|
|
|
|
|
|
// catch error if we didn't enter the loop above... we could simply initialize
|
|
|
|
// floatValue = 1, to cater for cases such as width="height", but that wouldn't
|
|
|
|
// be in line with the spec which requires an explicit number
|
|
|
|
if (number.IsEmpty()) {
|
2000-01-27 15:35:30 +03:00
|
|
|
#ifdef NS_DEBUG
|
2001-10-16 07:53:44 +04:00
|
|
|
printf("mpadded: attribute with bad numeric value: %s\n",
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_LossyConvertUTF16toASCII(aString).get());
|
2000-01-27 15:35:30 +03:00
|
|
|
#endif
|
|
|
|
aSign = NS_MATHML_SIGN_INVALID;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
PRInt32 errorCode;
|
|
|
|
float floatValue = number.ToFloat(&errorCode);
|
|
|
|
if (errorCode) {
|
|
|
|
aSign = NS_MATHML_SIGN_INVALID;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip any space after the number
|
2005-03-30 11:34:20 +04:00
|
|
|
if (i < stringLength && nsCRT::IsAsciiSpace(aString[i]))
|
2000-01-27 15:35:30 +03:00
|
|
|
i++;
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// see if this is a percentage-based value
|
|
|
|
if (i < stringLength && aString[i] == '%') {
|
|
|
|
i++;
|
|
|
|
gotPercent = PR_TRUE;
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// skip any space after the '%' sign
|
2005-03-30 11:34:20 +04:00
|
|
|
if (i < stringLength && nsCRT::IsAsciiSpace(aString[i]))
|
2002-06-15 03:20:03 +04:00
|
|
|
i++;
|
|
|
|
}
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// the remainder now should be a css-unit, or a pseudo-unit, or a named-space
|
|
|
|
aString.Right(unit, stringLength - i);
|
|
|
|
|
|
|
|
if (unit.IsEmpty()) {
|
|
|
|
// also cater for the edge case of "0" for which the unit is optional
|
|
|
|
if (gotPercent || !floatValue) {
|
|
|
|
aCSSValue.SetPercentValue(floatValue / 100.0f);
|
|
|
|
aPseudoUnit = NS_MATHML_PSEUDO_UNIT_ITSELF;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
else {
|
|
|
|
// no explicit CSS unit and no explicit pseudo-unit...
|
2000-01-27 15:35:30 +03:00
|
|
|
// In this case, the MathML REC suggests taking ems for
|
|
|
|
// h-unit (width, lspace) or exs for v-unit (height, depth).
|
|
|
|
// Here, however, we explicitly request authors to specify
|
|
|
|
// the unit. This is more in line with the CSS REC (and
|
|
|
|
// it allows keeping the code simpler...)
|
|
|
|
}
|
2002-06-15 03:20:03 +04:00
|
|
|
*/
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
2004-04-30 17:23:43 +04:00
|
|
|
else if (unit.EqualsLiteral("width")) aPseudoUnit = NS_MATHML_PSEUDO_UNIT_WIDTH;
|
|
|
|
else if (unit.EqualsLiteral("height")) aPseudoUnit = NS_MATHML_PSEUDO_UNIT_HEIGHT;
|
|
|
|
else if (unit.EqualsLiteral("depth")) aPseudoUnit = NS_MATHML_PSEUDO_UNIT_DEPTH;
|
|
|
|
else if (unit.EqualsLiteral("lspace")) aPseudoUnit = NS_MATHML_PSEUDO_UNIT_LSPACE;
|
2002-06-15 03:20:03 +04:00
|
|
|
else if (!gotPercent) { // percentage can only apply to a pseudo-unit
|
|
|
|
|
|
|
|
// see if the unit is a named-space
|
|
|
|
// XXX nsnull in ParseNamedSpacedValue()? don't access mstyle?
|
|
|
|
if (ParseNamedSpaceValue(nsnull, unit, aCSSValue)) {
|
|
|
|
// re-scale properly, and we know that the unit of the named-space is 'em'
|
|
|
|
floatValue *= aCSSValue.GetFloatValue();
|
|
|
|
aCSSValue.SetFloatValue(floatValue, eCSSUnit_EM);
|
2000-05-16 17:15:15 +04:00
|
|
|
aPseudoUnit = NS_MATHML_PSEUDO_UNIT_NAMEDSPACE;
|
2002-06-15 03:20:03 +04:00
|
|
|
return PR_TRUE;
|
2000-05-16 17:15:15 +04:00
|
|
|
}
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// see if the input was just a CSS value
|
|
|
|
number.Append(unit); // leave the sign out if it was there
|
|
|
|
if (ParseNumericValue(number, aCSSValue))
|
|
|
|
return PR_TRUE;
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// if we enter here, we have a number that will act as a multiplier on a pseudo-unit
|
|
|
|
if (aPseudoUnit != NS_MATHML_PSEUDO_UNIT_UNSPECIFIED) {
|
|
|
|
if (gotPercent)
|
|
|
|
aCSSValue.SetPercentValue(floatValue / 100.0f);
|
|
|
|
else
|
|
|
|
aCSSValue.SetFloatValue(floatValue, eCSSUnit_Number);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("mpadded: attribute with bad numeric value: %s\n",
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_LossyConvertUTF16toASCII(aString).get());
|
2002-06-15 03:20:03 +04:00
|
|
|
#endif
|
|
|
|
// if we reach here, it means we encounter an unexpected input
|
|
|
|
aSign = NS_MATHML_SIGN_INVALID;
|
|
|
|
return PR_FALSE;
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-03 07:33:21 +03:00
|
|
|
nsMathMLmpaddedFrame::UpdateValue(PRInt32 aSign,
|
|
|
|
PRInt32 aPseudoUnit,
|
|
|
|
const nsCSSValue& aCSSValue,
|
|
|
|
nscoord aLeftSpace,
|
|
|
|
const nsBoundingMetrics& aBoundingMetrics,
|
|
|
|
nscoord& aValueToUpdate) const
|
2000-01-27 15:35:30 +03:00
|
|
|
{
|
|
|
|
nsCSSUnit unit = aCSSValue.GetUnit();
|
2002-06-15 03:20:03 +04:00
|
|
|
if (NS_MATHML_SIGN_INVALID != aSign && eCSSUnit_Null != unit) {
|
2002-02-19 02:16:33 +03:00
|
|
|
nscoord scaler = 0, amount = 0;
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
if (eCSSUnit_Percent == unit || eCSSUnit_Number == unit) {
|
|
|
|
switch(aPseudoUnit) {
|
2000-01-27 15:35:30 +03:00
|
|
|
case NS_MATHML_PSEUDO_UNIT_WIDTH:
|
2000-03-28 13:38:24 +04:00
|
|
|
scaler = aBoundingMetrics.width;
|
2000-01-27 15:35:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MATHML_PSEUDO_UNIT_HEIGHT:
|
2000-03-28 13:38:24 +04:00
|
|
|
scaler = aBoundingMetrics.ascent;
|
2000-01-27 15:35:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MATHML_PSEUDO_UNIT_DEPTH:
|
2000-03-28 13:38:24 +04:00
|
|
|
scaler = aBoundingMetrics.descent;
|
2000-01-27 15:35:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MATHML_PSEUDO_UNIT_LSPACE:
|
|
|
|
scaler = aLeftSpace;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// if we ever reach here, it would mean something is wrong
|
2000-03-28 13:38:24 +04:00
|
|
|
// somewhere with the setup and/or the caller
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("Unexpected Pseudo Unit");
|
2000-01-27 15:35:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSUnit_Number == unit)
|
2000-03-28 13:38:24 +04:00
|
|
|
amount = NSToCoordRound(float(scaler) * aCSSValue.GetFloatValue());
|
2000-01-27 15:35:30 +03:00
|
|
|
else if (eCSSUnit_Percent == unit)
|
2000-03-28 13:38:24 +04:00
|
|
|
amount = NSToCoordRound(float(scaler) * aCSSValue.GetPercentValue());
|
2000-01-27 15:35:30 +03:00
|
|
|
else
|
2007-12-29 02:04:19 +03:00
|
|
|
amount = CalcLength(PresContext(), mStyleContext, aCSSValue);
|
2000-01-27 15:35:30 +03:00
|
|
|
|
|
|
|
nscoord oldValue = aValueToUpdate;
|
|
|
|
if (NS_MATHML_SIGN_PLUS == aSign)
|
|
|
|
aValueToUpdate += amount;
|
|
|
|
else if (NS_MATHML_SIGN_MINUS == aSign)
|
|
|
|
aValueToUpdate -= amount;
|
|
|
|
else
|
|
|
|
aValueToUpdate = amount;
|
|
|
|
|
|
|
|
/* The REC says:
|
|
|
|
Dimensions that would be positive if the content was rendered normally
|
|
|
|
cannot be made negative using <mpadded>; a positive dimension is set
|
|
|
|
to 0 if it would otherwise become negative. Dimensions which are
|
|
|
|
initially 0 can be made negative
|
|
|
|
*/
|
2002-06-15 03:20:03 +04:00
|
|
|
if (0 < oldValue && 0 > aValueToUpdate)
|
|
|
|
aValueToUpdate = 0;
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLmpaddedFrame::Reflow(nsPresContext* aPresContext,
|
2000-01-27 15:35:30 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2005-02-07 04:57:50 +03:00
|
|
|
ProcessAttributes();
|
2000-01-27 15:35:30 +03:00
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Let the base class format our content like an inferred mrow
|
2002-02-07 07:38:08 +03:00
|
|
|
nsresult rv = nsMathMLContainerFrame::Reflow(aPresContext, aDesiredSize,
|
|
|
|
aReflowState, aStatus);
|
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");
|
2007-12-29 02:04:19 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2008-03-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2007-12-29 02:04:19 +03:00
|
|
|
nsMathMLmpaddedFrame::Place(nsIRenderingContext& aRenderingContext,
|
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
nsresult rv =
|
2008-01-03 07:33:21 +03:00
|
|
|
nsMathMLContainerFrame::Place(aRenderingContext, PR_FALSE, aDesiredSize);
|
2007-12-29 02:04:19 +03:00
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
|
|
|
|
DidReflowChildren(GetFirstChild(nsnull));
|
|
|
|
return rv;
|
|
|
|
}
|
2002-06-15 03:20:03 +04:00
|
|
|
|
2000-03-28 13:38:24 +04:00
|
|
|
nscoord height = mBoundingMetrics.ascent;
|
|
|
|
nscoord depth = mBoundingMetrics.descent;
|
2008-01-03 07:33:21 +03:00
|
|
|
// In MathML2 (http://www.w3.org/TR/MathML2/chapter3.html#presm.mpadded),
|
|
|
|
// lspace is "the amount of space between the left edge of a bounding box
|
|
|
|
// and the start of the rendering of its contents' bounding box" and the
|
|
|
|
// default is zero.
|
|
|
|
//
|
|
|
|
// In MathML3 draft
|
|
|
|
// http://www.w3.org/TR/2007/WD-MathML3-20070427/chapter3.html#id.3.3.6.2,
|
|
|
|
// lspace is "the amount of space between the left edge of the bounding box
|
|
|
|
// and the positioning poin [sic] of the mpadded element" and the default is
|
|
|
|
// "same as content".
|
|
|
|
//
|
|
|
|
// In both cases, "MathML renderers should ensure that, except for the
|
|
|
|
// effects of the attributes, relative spacing between the contents of
|
|
|
|
// mpadded and surrounding MathML elements is not modified by replacing an
|
|
|
|
// mpadded element with an mrow element with the same content."
|
|
|
|
nscoord lspace = 0;
|
|
|
|
// In MATHML3, "width" will be the bounding box width and "advancewidth" will
|
|
|
|
// refer "to the horizontal distance between the positioning point of the
|
|
|
|
// mpadded and the positioning point for the following content". MathML2
|
|
|
|
// doesn't make the distinction.
|
2000-03-28 13:38:24 +04:00
|
|
|
nscoord width = mBoundingMetrics.width;
|
2000-01-27 15:35:30 +03:00
|
|
|
|
|
|
|
PRInt32 pseudoUnit;
|
|
|
|
|
|
|
|
// update width
|
|
|
|
pseudoUnit = (mWidthPseudoUnit == NS_MATHML_PSEUDO_UNIT_ITSELF)
|
|
|
|
? NS_MATHML_PSEUDO_UNIT_WIDTH : mWidthPseudoUnit;
|
2007-12-29 02:04:19 +03:00
|
|
|
UpdateValue(mWidthSign, pseudoUnit, mWidth,
|
2000-03-28 13:38:24 +04:00
|
|
|
lspace, mBoundingMetrics, width);
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// update "height" (this is the ascent in the terminology of the REC)
|
2000-01-27 15:35:30 +03:00
|
|
|
pseudoUnit = (mHeightPseudoUnit == NS_MATHML_PSEUDO_UNIT_ITSELF)
|
|
|
|
? NS_MATHML_PSEUDO_UNIT_HEIGHT : mHeightPseudoUnit;
|
2007-12-29 02:04:19 +03:00
|
|
|
UpdateValue(mHeightSign, pseudoUnit, mHeight,
|
2000-03-28 13:38:24 +04:00
|
|
|
lspace, mBoundingMetrics, height);
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
// update "depth" (this is the descent in the terminology of the REC)
|
2000-01-27 15:35:30 +03:00
|
|
|
pseudoUnit = (mDepthPseudoUnit == NS_MATHML_PSEUDO_UNIT_ITSELF)
|
|
|
|
? NS_MATHML_PSEUDO_UNIT_DEPTH : mDepthPseudoUnit;
|
2007-12-29 02:04:19 +03:00
|
|
|
UpdateValue(mDepthSign, pseudoUnit, mDepth,
|
2000-03-28 13:38:24 +04:00
|
|
|
lspace, mBoundingMetrics, depth);
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2000-02-07 11:51:10 +03:00
|
|
|
// update lspace -- should be *last* because lspace is overwritten!!
|
2000-01-27 15:35:30 +03:00
|
|
|
pseudoUnit = (mLeftSpacePseudoUnit == NS_MATHML_PSEUDO_UNIT_ITSELF)
|
|
|
|
? NS_MATHML_PSEUDO_UNIT_LSPACE : mLeftSpacePseudoUnit;
|
2007-12-29 02:04:19 +03:00
|
|
|
UpdateValue(mLeftSpaceSign, pseudoUnit, mLeftSpace,
|
2000-03-28 13:38:24 +04:00
|
|
|
lspace, mBoundingMetrics, lspace);
|
2000-01-27 15:35:30 +03:00
|
|
|
|
|
|
|
// do the padding now that we have everything
|
2002-06-15 03:20:03 +04:00
|
|
|
// The idea here is to maintain the invariant that <mpadded>...</mpadded> (i.e.,
|
|
|
|
// with no attributes) looks the same as <mrow>...</mrow>. But when there are
|
|
|
|
// attributes, tweak our metrics and move children to achieve the desired visual
|
|
|
|
// effects.
|
2000-01-27 15:35:30 +03:00
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
if (mLeftSpaceSign != NS_MATHML_SIGN_INVALID) { // there was padding on the left
|
|
|
|
// dismiss the left italic correction now (so that our parent won't correct us)
|
2000-03-28 13:38:24 +04:00
|
|
|
mBoundingMetrics.leftBearing = 0;
|
|
|
|
}
|
|
|
|
|
2002-06-15 03:20:03 +04:00
|
|
|
if (mLeftSpaceSign != NS_MATHML_SIGN_INVALID ||
|
|
|
|
mWidthSign != NS_MATHML_SIGN_INVALID) { // there was padding on the right
|
|
|
|
// dismiss the right italic correction now (so that our parent won't correct us)
|
2009-09-16 19:01:36 +04:00
|
|
|
mBoundingMetrics.width = NS_MAX(0, lspace + width);
|
2002-06-15 03:20:03 +04:00
|
|
|
mBoundingMetrics.rightBearing = mBoundingMetrics.width;
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord dy = height - mBoundingMetrics.ascent;
|
2000-01-27 15:35:30 +03:00
|
|
|
nscoord dx = lspace;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
|
|
|
mBoundingMetrics.ascent = height;
|
|
|
|
mBoundingMetrics.descent = depth;
|
|
|
|
|
|
|
|
aDesiredSize.ascent += dy;
|
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height += dy + depth - mBoundingMetrics.descent;
|
2001-02-03 00:29:21 +03:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2007-12-29 02:04:19 +03:00
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
2002-06-15 03:20:03 +04:00
|
|
|
|
2008-01-03 07:33:21 +03:00
|
|
|
if (aPlaceOrigin) {
|
|
|
|
// Finish reflowing child frames, positioning their origins.
|
|
|
|
PositionRowChildFrames(dx, aDesiredSize.ascent);
|
2000-01-27 15:35:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|