From e8bb715f83bde244b8d92ae1e1e30349611c52c2 Mon Sep 17 00:00:00 2001
From: James Kitchener
Date: Sun, 6 Jan 2013 22:24:13 -0500
Subject: [PATCH] Bug 411227 - Update ParseNumericValue behavior and change
tests to support unitless values in script(min)size. r=fredw
---
.../mathml/content/src/nsMathMLElement.cpp | 25 +++++++++++-----
content/mathml/content/src/nsMathMLElement.h | 3 +-
layout/mathml/nsMathMLmmultiscriptsFrame.cpp | 14 ++++-----
layout/mathml/nsMathMLmoFrame.cpp | 16 +++++-----
layout/mathml/nsMathMLmsubFrame.cpp | 6 ++--
layout/mathml/nsMathMLmsubsupFrame.cpp | 12 +++-----
layout/mathml/nsMathMLmsupFrame.cpp | 6 ++--
layout/reftests/bugs/355548-3-ref.xml | 2 +-
layout/reftests/bugs/355548-3.xml | 2 +-
.../mathml/mfrac-linethickness-2-ref.xhtml | 10 +++++++
.../mathml/mfrac-linethickness-2.xhtml | 10 +++++++
.../mathml/mfrac-linethickness-3-ref.xhtml | 25 ++++++++++++++++
.../mathml/mfrac-linethickness-3.xhtml | 25 ++++++++++++++++
.../reftests/mathml/number-size-1-ref.xhtml | 7 +++++
layout/reftests/mathml/number-size-1.xhtml | 7 +++++
layout/reftests/mathml/operator-1-ref.xhtml | 9 ++++++
layout/reftests/mathml/operator-1.xhtml | 9 ++++++
layout/reftests/mathml/reftest.list | 5 ++++
.../reftests/mathml/scriptshift-1-ref.xhtml | 30 +++++++++++++++++++
layout/reftests/mathml/scriptshift-1.xhtml | 30 +++++++++++++++++++
20 files changed, 211 insertions(+), 42 deletions(-)
create mode 100644 layout/reftests/mathml/mfrac-linethickness-2-ref.xhtml
create mode 100644 layout/reftests/mathml/mfrac-linethickness-2.xhtml
create mode 100644 layout/reftests/mathml/mfrac-linethickness-3-ref.xhtml
create mode 100644 layout/reftests/mathml/mfrac-linethickness-3.xhtml
create mode 100644 layout/reftests/mathml/number-size-1-ref.xhtml
create mode 100644 layout/reftests/mathml/number-size-1.xhtml
create mode 100644 layout/reftests/mathml/operator-1-ref.xhtml
create mode 100644 layout/reftests/mathml/operator-1.xhtml
create mode 100644 layout/reftests/mathml/scriptshift-1-ref.xhtml
create mode 100644 layout/reftests/mathml/scriptshift-1.xhtml
diff --git a/content/mathml/content/src/nsMathMLElement.cpp b/content/mathml/content/src/nsMathMLElement.cpp
index 2b414bc8e6bf..b6110f62357a 100644
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -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)] = {
diff --git a/content/mathml/content/src/nsMathMLElement.h b/content/mathml/content/src/nsMathMLElement.h
index 82e24dd844c9..607f581e7e8d 100644
--- a/content/mathml/content/src/nsMathMLElement.h
+++ b/content/mathml/content/src/nsMathMLElement.h
@@ -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,
diff --git a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp
index da5b66d89582..029372ffcdfd 100644
--- a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp
+++ b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp
@@ -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);
}
}
diff --git a/layout/mathml/nsMathMLmoFrame.cpp b/layout/mathml/nsMathMLmoFrame.cpp
index 36b161b2d875..954abaa23503 100644
--- a/layout/mathml/nsMathMLmoFrame.cpp
+++ b/layout/mathml/nsMathMLmoFrame.cpp
@@ -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_,
diff --git a/layout/mathml/nsMathMLmsubFrame.cpp b/layout/mathml/nsMathMLmsubFrame.cpp
index 93756f07daa9..0e6cbdc54835 100644
--- a/layout/mathml/nsMathMLmsubFrame.cpp
+++ b/layout/mathml/nsMathMLmsubFrame.cpp
@@ -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(),
diff --git a/layout/mathml/nsMathMLmsubsupFrame.cpp b/layout/mathml/nsMathMLmsubsupFrame.cpp
index e81db6819833..8f0b3f313ae0 100644
--- a/layout/mathml/nsMathMLmsubsupFrame.cpp
+++ b/layout/mathml/nsMathMLmsubsupFrame.cpp
@@ -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(),
diff --git a/layout/mathml/nsMathMLmsupFrame.cpp b/layout/mathml/nsMathMLmsupFrame.cpp
index 1cf4234c399e..d9b8f89ef6e5 100644
--- a/layout/mathml/nsMathMLmsupFrame.cpp
+++ b/layout/mathml/nsMathMLmsupFrame.cpp
@@ -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(),
diff --git a/layout/reftests/bugs/355548-3-ref.xml b/layout/reftests/bugs/355548-3-ref.xml
index d4f2e9fb085e..76882f44813b 100644
--- a/layout/reftests/bugs/355548-3-ref.xml
+++ b/layout/reftests/bugs/355548-3-ref.xml
@@ -50,7 +50,6 @@
Id
Id
Id
- Id
@@ -58,6 +57,7 @@
Id
Id
Id
+ Id
Id
Id
Id
diff --git a/layout/reftests/bugs/355548-3.xml b/layout/reftests/bugs/355548-3.xml
index b1a6958b48c6..e4663ea7abd6 100644
--- a/layout/reftests/bugs/355548-3.xml
+++ b/layout/reftests/bugs/355548-3.xml
@@ -57,7 +57,6 @@
Id
Id
- Id
Id
Id
Id
@@ -68,6 +67,7 @@
Id
Id
Id
+ Id
Id
Id
Id
diff --git a/layout/reftests/mathml/mfrac-linethickness-2-ref.xhtml b/layout/reftests/mathml/mfrac-linethickness-2-ref.xhtml
new file mode 100644
index 000000000000..941edfcd1e61
--- /dev/null
+++ b/layout/reftests/mathml/mfrac-linethickness-2-ref.xhtml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/mfrac-linethickness-2.xhtml b/layout/reftests/mathml/mfrac-linethickness-2.xhtml
new file mode 100644
index 000000000000..2d9026f8d015
--- /dev/null
+++ b/layout/reftests/mathml/mfrac-linethickness-2.xhtml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/mfrac-linethickness-3-ref.xhtml b/layout/reftests/mathml/mfrac-linethickness-3-ref.xhtml
new file mode 100644
index 000000000000..63198a66f874
--- /dev/null
+++ b/layout/reftests/mathml/mfrac-linethickness-3-ref.xhtml
@@ -0,0 +1,25 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/mfrac-linethickness-3.xhtml b/layout/reftests/mathml/mfrac-linethickness-3.xhtml
new file mode 100644
index 000000000000..7a565cfe0a95
--- /dev/null
+++ b/layout/reftests/mathml/mfrac-linethickness-3.xhtml
@@ -0,0 +1,25 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/number-size-1-ref.xhtml b/layout/reftests/mathml/number-size-1-ref.xhtml
new file mode 100644
index 000000000000..6d38b4bb0217
--- /dev/null
+++ b/layout/reftests/mathml/number-size-1-ref.xhtml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/number-size-1.xhtml b/layout/reftests/mathml/number-size-1.xhtml
new file mode 100644
index 000000000000..40c7347adf40
--- /dev/null
+++ b/layout/reftests/mathml/number-size-1.xhtml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/operator-1-ref.xhtml b/layout/reftests/mathml/operator-1-ref.xhtml
new file mode 100644
index 000000000000..2befdf24406f
--- /dev/null
+++ b/layout/reftests/mathml/operator-1-ref.xhtml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/operator-1.xhtml b/layout/reftests/mathml/operator-1.xhtml
new file mode 100644
index 000000000000..e07da9e98220
--- /dev/null
+++ b/layout/reftests/mathml/operator-1.xhtml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/reftest.list b/layout/reftests/mathml/reftest.list
index b09b479634b7..765eb570be1a 100644
--- a/layout/reftests/mathml/reftest.list
+++ b/layout/reftests/mathml/reftest.list
@@ -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
diff --git a/layout/reftests/mathml/scriptshift-1-ref.xhtml b/layout/reftests/mathml/scriptshift-1-ref.xhtml
new file mode 100644
index 000000000000..04eb6ca55a57
--- /dev/null
+++ b/layout/reftests/mathml/scriptshift-1-ref.xhtml
@@ -0,0 +1,30 @@
+
+
+
+
+
diff --git a/layout/reftests/mathml/scriptshift-1.xhtml b/layout/reftests/mathml/scriptshift-1.xhtml
new file mode 100644
index 000000000000..67b7d201a3d0
--- /dev/null
+++ b/layout/reftests/mathml/scriptshift-1.xhtml
@@ -0,0 +1,30 @@
+
+
+
+
+