Bug 411227 - Update ParseNumericValue behavior and change tests to support unitless values in script(min)size. r=fredw

This commit is contained in:
James Kitchener 2013-01-06 22:24:13 -05:00
Родитель 88ee0c8a27
Коммит e8bb715f83
20 изменённых файлов: 211 добавлений и 42 удалений

Просмотреть файл

@ -408,13 +408,18 @@ nsMathMLElement::ParseNumericValue(const nsString& aString,
if (unit.IsEmpty()) {
if (aFlags & PARSE_ALLOW_UNITLESS) {
// no explicit unit, this is a number that will act as a multiplier
cssUnit = eCSSUnit_Number;
if (!(aFlags & PARSE_SUPPRESS_WARNINGS)) {
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
"MathML", aDocument,
nsContentUtils::eMATHML_PROPERTIES,
"UnitlessValuesAreDeprecated");
}
if (aFlags & CONVERT_UNITLESS_TO_PERCENT) {
aCSSValue.SetPercentValue(floatValue);
return true;
}
else
cssUnit = eCSSUnit_Number;
} else {
// We are supposed to have a unit, but there isn't one.
// If the value is 0 we can just call it "pixels" otherwise
@ -496,15 +501,20 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
// default: 8pt
//
// We don't allow negative values.
// XXXfredw Should we allow unitless values? (bug 411227)
// XXXfredw Does a relative unit give a multiple of the default value?
// Unitless and percent values give a multiple of the default value.
//
value = aAttributes->GetAttr(nsGkAtoms::scriptminsize_);
nsCSSValue* scriptMinSize = aData->ValueForScriptMinSize();
if (value && value->Type() == nsAttrValue::eString &&
scriptMinSize->GetUnit() == eCSSUnit_Null) {
ParseNumericValue(value->GetStringValue(), *scriptMinSize, 0,
ParseNumericValue(value->GetStringValue(), *scriptMinSize,
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
aData->mPresContext->Document());
if (scriptMinSize->GetUnit() == eCSSUnit_Percent) {
scriptMinSize->SetFloatValue(8.0 * scriptMinSize->GetPercentValue(),
eCSSUnit_Point);
}
}
// scriptlevel
@ -565,8 +575,7 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
// default: inherited
//
// In both cases, we don't allow negative values.
// XXXfredw Should we allow unitless values? (bug 411227)
// XXXfredw Does a relative unit give a multiple of the default value?
// Unitless values give a multiple of the default value.
//
bool parseSizeKeywords = true;
value = aAttributes->GetAttr(nsGkAtoms::mathsize_);
@ -583,7 +592,9 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
if (value && value->Type() == nsAttrValue::eString &&
fontSize->GetUnit() == eCSSUnit_Null) {
nsAutoString str(value->GetStringValue());
if (!ParseNumericValue(str, *fontSize, PARSE_SUPPRESS_WARNINGS, nullptr)
if (!ParseNumericValue(str, *fontSize, PARSE_SUPPRESS_WARNINGS |
PARSE_ALLOW_UNITLESS | CONVERT_UNITLESS_TO_PERCENT,
nullptr)
&& parseSizeKeywords) {
static const char sizes[3][7] = { "small", "normal", "big" };
static const int32_t values[NS_ARRAY_LENGTH(sizes)] = {

Просмотреть файл

@ -54,7 +54,8 @@ public:
enum {
PARSE_ALLOW_UNITLESS = 0x01, // unitless 0 will be turned into 0px
PARSE_ALLOW_NEGATIVE = 0x02,
PARSE_SUPPRESS_WARNINGS = 0x04
PARSE_SUPPRESS_WARNINGS = 0x04,
CONVERT_UNITLESS_TO_PERCENT = 0x08
};
static bool ParseNamedSpaceValue(const nsString& aString,
nsCSSValue& aCSSValue,

Просмотреть файл

@ -94,15 +94,14 @@ nsMathMLmmultiscriptsFrame::ProcessAttributes()
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
nsAutoString value;
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::subscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &mSubScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &mSubScriptShift, 0, PresContext(),
mStyleContext);
}
// superscriptshift
//
@ -113,14 +112,13 @@ nsMathMLmmultiscriptsFrame::ProcessAttributes()
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::superscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &mSupScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &mSupScriptShift, 0, PresContext(),
mStyleContext);
}
}

Просмотреть файл

@ -396,10 +396,10 @@ nsMathMLmoFrame::ProcessOperatorData()
// values: length
// default: set by dictionary (thickmathspace)
//
// XXXfredw Should we allow negative values? (bug 411227) They will be made
// positive by the rounding below.
// XXXfredw Should we allow relative values? They will give a multiple of the
// current leading space, which is not necessarily the default one.
// XXXfredw Support for negative and relative values is not implemented
// (bug 805926).
// Relative values will give a multiple of the current leading space,
// which is not necessarily the default one.
//
nscoord leadingSpace = mEmbellishData.leadingSpace;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::lspace_,
@ -423,10 +423,10 @@ nsMathMLmoFrame::ProcessOperatorData()
// values: length
// default: set by dictionary (thickmathspace)
//
// XXXfredw Should we allow negative values? (bug 411227) They will be made
// positive by the rounding below.
// XXXfredw Should we allow relative values? They will give a multiple of the
// current trailing space, which is not necessarily the default one.
// XXXfredw Support for negative and relative values is not implemented
// (bug 805926).
// Relative values will give a multiple of the current leading space,
// which is not necessarily the default one.
//
nscoord trailingSpace = mEmbellishData.trailingSpace;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::rspace_,

Просмотреть файл

@ -63,16 +63,14 @@ nsMathMLmsubFrame::Place (nsRenderingContext& aRenderingContext,
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
nscoord subScriptShift = 0;
nsAutoString value;
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::subscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &subScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &subScriptShift, 0, PresContext(), mStyleContext);
}
return nsMathMLmsubFrame::PlaceSubScript(PresContext(),

Просмотреть файл

@ -69,16 +69,14 @@ nsMathMLmsubsupFrame::Place(nsRenderingContext& aRenderingContext,
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
nsAutoString value;
nscoord subScriptShift = 0;
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::subscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &subScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &subScriptShift, 0, PresContext(), mStyleContext);
}
// superscriptshift
//
@ -89,15 +87,13 @@ nsMathMLmsubsupFrame::Place(nsRenderingContext& aRenderingContext,
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
nscoord supScriptShift = 0;
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::superscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &supScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &supScriptShift, 0, PresContext(), mStyleContext);
}
return nsMathMLmsubsupFrame::PlaceSubSupScript(PresContext(),

Просмотреть файл

@ -63,16 +63,14 @@ nsMathMLmsupFrame::Place(nsRenderingContext& aRenderingContext,
// default: automatic
//
// We use 0 as the default value so unitless values can be ignored.
// XXXfredw Should we forbid negative values? (bug 411227)
// As a minimum, negative values can be ignored.
//
nsAutoString value;
nscoord supScriptShift = 0;
GetAttribute(mContent, mPresentationData.mstyle,
nsGkAtoms::superscriptshift_, value);
if (!value.IsEmpty()) {
ParseNumericValue(value, &supScriptShift,
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
PresContext(), mStyleContext);
ParseNumericValue(value, &supScriptShift, 0, PresContext(), mStyleContext);
}
return nsMathMLmsupFrame::PlaceSuperScript(PresContext(),

Просмотреть файл

@ -50,7 +50,6 @@
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:48px;">Id</m:mi></m:mstyle>
</m:math></p>
<p><m:math>
@ -58,6 +57,7 @@
<m:mstyle><m:mi style="font-size:24px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:24px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:24px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:24px;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:0;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:0;">Id</m:mi></m:mstyle>
<m:mstyle><m:mi style="font-size:0;">Id</m:mi></m:mstyle>

Просмотреть файл

@ -57,7 +57,6 @@
<!-- test invalid values for MathML length attributes -->
<m:mstyle mathsize="20 px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="20PX"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="20"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize=".px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="..px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="+20px"><m:mi>Id</m:mi></m:mstyle>
@ -68,6 +67,7 @@
<m:mstyle mathsize=" 24px "><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="24.0px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="24.px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="0.5"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="50%"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize=".0px"><m:mi>Id</m:mi></m:mstyle>
<m:mstyle mathsize="-0px"><m:mi>Id</m:mi></m:mstyle>

Просмотреть файл

@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac linethickness="200%">
<mi>x</mi>
<mn>2</mn>
</mfrac>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac linethickness="2">
<mi>x</mi>
<mn>2</mn>
</mfrac>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,25 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mi>x</mi>
<mn>2</mn>
</mfrac>
<mo>=</mo>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>=</mo>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>=</mo>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,25 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac linethickness="2km">
<mi>x</mi>
<mn>2</mn>
</mfrac>
<mo>=</mo>
<mfrac linethickness = "cat">
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>=</mo>
<mfrac linethickness = "-2px">
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>=</mo>
<mfrac linethickness="1">
<mi>a</mi>
<mi>b</mi>
</mfrac>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn mathsize="200%">2</mn>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn mathsize="2">2</mn>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,9 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn>3</mn>
<mo>+</mo>
<mn>2</mn>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,9 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn>3</mn>
<mo lspace="-5pt" rspace="-4pt">+</mo>
<mn>2</mn>
</math>
</body>
</html>

Просмотреть файл

@ -94,6 +94,8 @@ fails == mstyle-5.xhtml mstyle-5-ref.xhtml # Bug 787215
== munder-mover-align-accent-true.html munder-mover-align-accent-true-ref.html
== munder-mover-align-accent-false.html munder-mover-align-accent-false-ref.html
== mfrac-linethickness-1.xhtml mfrac-linethickness-1-ref.xhtml
== mfrac-linethickness-2.xhtml mfrac-linethickness-2-ref.xhtml
== mfrac-linethickness-3.xhtml mfrac-linethickness-3-ref.xhtml
== mathml-negativespace.html mathml-negativespace-ref.html
!= link-1.xhtml link-ref.xhtml
== munderover-empty-scripts.html munderover-empty-scripts-ref.html
@ -111,3 +113,6 @@ fails == mstyle-5.xhtml mstyle-5-ref.xhtml # Bug 787215
== whitespace-trim-3.html whitespace-trim-3-ref.html
fails == whitespace-trim-4.html whitespace-trim-4-ref.html # Bug 787215
== whitespace-trim-5.html whitespace-trim-5-ref.html
== operator-1.xhtml operator-1-ref.xhtml
== scriptshift-1.xhtml scriptshift-1-ref.xhtml
== number-size-1.xhtml number-size-1-ref.xhtml

Просмотреть файл

@ -0,0 +1,30 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<msub>
<mi>x</mi>
<mn>2</mn>
</msub>
<mo>+</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<msubsup>
<mi>x</mi>
<mn>2</mn>
<mn>3</mn>
</msubsup>
<mo>+</mo>
<mmultiscripts>
<mi> x </mi>
<mn>2</mn>
<mn>3</mn>
<mprescripts/>
<mn>4</mn>
<mn>5</mn>
</mmultiscripts>
</math>
</body>
</html>

Просмотреть файл

@ -0,0 +1,30 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<msub subscriptshift="-5px">
<mi>x</mi>
<mn>2</mn>
</msub>
<mo>+</mo>
<msup superscriptshift="-5px">
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<msubsup subscriptshift="-5px" superscriptshift="-5px">
<mi>x</mi>
<mn>2</mn>
<mn>3</mn>
</msubsup>
<mo>+</mo>
<mmultiscripts subscriptshift="-5px" superscriptshift="-5px">
<mi> x </mi>
<mn>2</mn>
<mn>3</mn>
<mprescripts/>
<mn>4</mn>
<mn>5</mn>
</mmultiscripts>
</math>
</body>
</html>