Commit 2c2f19bc authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

[mathml] Support scriptlevel attribute

Implement scriptlevel attribute mapping to the math-depth CSS property
as described here [1].
Adapt attribute-mapping-002.html to expect strings rather than numbers.

[1] https://mathml-refresh.github.io/mathml-core/#dfn-scriptlevel

Bug: 6606
Change-Id: I9bd59bcca840762ee1278ec064e5b81d96dda91c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2474780
Commit-Queue: Rob Buis <rbuis@igalia.com>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarFrédéric Wang <fwang@igalia.com>
Cr-Commit-Position: refs/heads/master@{#820720}
parent dd173a9d
......@@ -11,6 +11,8 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/platform/wtf/text/character_visitor.h"
#include "third_party/blink/renderer/platform/wtf/text/string_to_number.h"
namespace blink {
......@@ -40,12 +42,36 @@ bool MathMLElement::IsPresentationAttribute(const QualifiedName& name) const {
name == mathml_names::kMathcolorAttr ||
name == mathml_names::kMathbackgroundAttr ||
name == mathml_names::kMathvariantAttr ||
name == mathml_names::kScriptlevelAttr ||
name == mathml_names::kDisplayAttr ||
name == mathml_names::kDisplaystyleAttr)
return true;
return Element::IsPresentationAttribute(name);
}
namespace {
bool ParseScriptLevel(const AtomicString& attributeValue,
unsigned& scriptLevel,
bool& add) {
String value = attributeValue;
if (value.StartsWith("+") || value.StartsWith("-")) {
add = true;
value = value.Right(1);
}
return WTF::VisitCharacters(
value, [&](const auto* position, unsigned length) {
WTF::NumberParsingResult result;
WTF::NumberParsingOptions options(
WTF::NumberParsingOptions::kAcceptMinusZeroForUnsigned);
scriptLevel = CharactersToUInt(position, length, options, &result);
return result == WTF::NumberParsingResult::kSuccess;
});
}
} // namespace
void MathMLElement::CollectStyleForPresentationAttribute(
const QualifiedName& name,
const AtomicString& value,
......@@ -66,6 +92,19 @@ void MathMLElement::CollectStyleForPresentationAttribute(
} else if (name == mathml_names::kMathcolorAttr) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kColor,
value);
} else if (name == mathml_names::kScriptlevelAttr) {
unsigned scriptLevel = 0;
bool add = false;
if (ParseScriptLevel(value, scriptLevel, add)) {
if (add) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMathDepth, "add(" + value + ")");
} else {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMathDepth, scriptLevel,
CSSPrimitiveValue::UnitType::kNumber);
}
}
} else if (name == mathml_names::kDisplayAttr &&
HasTagName(mathml_names::kMathTag)) {
if (EqualIgnoringASCIICase(value, "inline")) {
......
......@@ -1211,7 +1211,6 @@ crbug.com/6606 external/wpt/mathml/presentation-markup/spaces/space-like-004.htm
crbug.com/6606 external/wpt/mathml/presentation-markup/tables/table-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/tables/table-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/tables/table-axis-height.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/attribute-mapping-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/displaystyle-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/ignored-properties-001.html [ Failure Timeout ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathvariant-bold-fraktur.html [ Failure ]
......
This is a testharness.js-based test.
Found 128 tests; 94 PASS, 34 FAIL, 0 TIMEOUT, 0 NOTRUN.
FAIL mathvariant on the math element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the math element is mapped to math-depth(...)
PASS invalid scriptlevel values on the math element are not mapped to math-depth(...)
PASS displaystyle on the math element is mapped to CSS math-style
FAIL mathvariant on the annotation element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the annotation element is mapped to math-depth(...)
PASS invalid scriptlevel values on the annotation element are not mapped to math-depth(...)
PASS displaystyle on the annotation element is mapped to CSS math-style
FAIL mathvariant on the annotation-xml element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the annotation-xml element is mapped to math-depth(...)
PASS invalid scriptlevel values on the annotation-xml element are not mapped to math-depth(...)
PASS displaystyle on the annotation-xml element is mapped to CSS math-style
FAIL mathvariant on the maction element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the maction element is mapped to math-depth(...)
PASS invalid scriptlevel values on the maction element are not mapped to math-depth(...)
PASS displaystyle on the maction element is mapped to CSS math-style
FAIL mathvariant on the menclose element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the menclose element is mapped to math-depth(...)
PASS invalid scriptlevel values on the menclose element are not mapped to math-depth(...)
PASS displaystyle on the menclose element is mapped to CSS math-style
FAIL mathvariant on the merror element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the merror element is mapped to math-depth(...)
PASS invalid scriptlevel values on the merror element are not mapped to math-depth(...)
PASS displaystyle on the merror element is mapped to CSS math-style
FAIL mathvariant on the mfrac element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mfrac element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mfrac element are not mapped to math-depth(...)
PASS displaystyle on the mfrac element is mapped to CSS math-style
FAIL mathvariant on the mi element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "math-auto"
PASS scriptlevel on the mi element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mi element are not mapped to math-depth(...)
PASS displaystyle on the mi element is mapped to CSS math-style
FAIL mathvariant on the mmultiscripts element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mmultiscripts element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mmultiscripts element are not mapped to math-depth(...)
PASS displaystyle on the mmultiscripts element is mapped to CSS math-style
FAIL mathvariant on the mn element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mn element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mn element are not mapped to math-depth(...)
PASS displaystyle on the mn element is mapped to CSS math-style
FAIL mathvariant on the mo element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mo element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mo element are not mapped to math-depth(...)
PASS displaystyle on the mo element is mapped to CSS math-style
FAIL mathvariant on the mover element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mover element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mover element are not mapped to math-depth(...)
PASS displaystyle on the mover element is mapped to CSS math-style
FAIL mathvariant on the mpadded element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mpadded element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mpadded element are not mapped to math-depth(...)
PASS displaystyle on the mpadded element is mapped to CSS math-style
FAIL mathvariant on the mphantom element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mphantom element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mphantom element are not mapped to math-depth(...)
PASS displaystyle on the mphantom element is mapped to CSS math-style
FAIL mathvariant on the mprescripts element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mprescripts element is mapped to math-depth(...)
FAIL invalid scriptlevel values on the mprescripts element are not mapped to math-depth(...) assert_equals: invalid scriptlevel value expected "0" but got "1"
PASS displaystyle on the mprescripts element is mapped to CSS math-style
FAIL mathvariant on the mroot element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mroot element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mroot element are not mapped to math-depth(...)
PASS displaystyle on the mroot element is mapped to CSS math-style
FAIL mathvariant on the mrow element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mrow element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mrow element are not mapped to math-depth(...)
PASS displaystyle on the mrow element is mapped to CSS math-style
FAIL mathvariant on the ms element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the ms element is mapped to math-depth(...)
PASS invalid scriptlevel values on the ms element are not mapped to math-depth(...)
PASS displaystyle on the ms element is mapped to CSS math-style
FAIL mathvariant on the mspace element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mspace element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mspace element are not mapped to math-depth(...)
PASS displaystyle on the mspace element is mapped to CSS math-style
FAIL mathvariant on the msqrt element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the msqrt element is mapped to math-depth(...)
PASS invalid scriptlevel values on the msqrt element are not mapped to math-depth(...)
PASS displaystyle on the msqrt element is mapped to CSS math-style
FAIL mathvariant on the mstyle element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mstyle element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mstyle element are not mapped to math-depth(...)
PASS displaystyle on the mstyle element is mapped to CSS math-style
FAIL mathvariant on the msub element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the msub element is mapped to math-depth(...)
PASS invalid scriptlevel values on the msub element are not mapped to math-depth(...)
PASS displaystyle on the msub element is mapped to CSS math-style
FAIL mathvariant on the msubsup element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the msubsup element is mapped to math-depth(...)
PASS invalid scriptlevel values on the msubsup element are not mapped to math-depth(...)
PASS displaystyle on the msubsup element is mapped to CSS math-style
FAIL mathvariant on the msup element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the msup element is mapped to math-depth(...)
PASS invalid scriptlevel values on the msup element are not mapped to math-depth(...)
PASS displaystyle on the msup element is mapped to CSS math-style
FAIL mathvariant on the mtable element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mtable element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mtable element are not mapped to math-depth(...)
PASS displaystyle on the mtable element is mapped to CSS math-style
FAIL mathvariant on the mtd element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mtd element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mtd element are not mapped to math-depth(...)
PASS displaystyle on the mtd element is mapped to CSS math-style
FAIL mathvariant on the mtext element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mtext element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mtext element are not mapped to math-depth(...)
PASS displaystyle on the mtext element is mapped to CSS math-style
FAIL mathvariant on the mtr element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the mtr element is mapped to math-depth(...)
PASS invalid scriptlevel values on the mtr element are not mapped to math-depth(...)
PASS displaystyle on the mtr element is mapped to CSS math-style
FAIL mathvariant on the munder element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the munder element is mapped to math-depth(...)
PASS invalid scriptlevel values on the munder element are not mapped to math-depth(...)
PASS displaystyle on the munder element is mapped to CSS math-style
FAIL mathvariant on the munderover element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the munderover element is mapped to math-depth(...)
PASS invalid scriptlevel values on the munderover element are not mapped to math-depth(...)
PASS displaystyle on the munderover element is mapped to CSS math-style
FAIL mathvariant on the none element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the none element is mapped to math-depth(...)
FAIL invalid scriptlevel values on the none element are not mapped to math-depth(...) assert_equals: invalid scriptlevel value expected "0" but got "1"
PASS displaystyle on the none element is mapped to CSS math-style
FAIL mathvariant on the semantics element is mapped to CSS text-transform assert_equals: attribute specified expected "math-fraktur" but got "none"
PASS scriptlevel on the semantics element is mapped to math-depth(...)
PASS invalid scriptlevel values on the semantics element are not mapped to math-depth(...)
PASS displaystyle on the semantics element is mapped to CSS math-style
Harness: the test ran to completion.
......@@ -44,26 +44,52 @@
test(function() {
// none and mprescripts appear as scripts
assert_equals(style.getPropertyValue("math-depth"), tag === "none" || tag === "mprescripts" ? 1 : 0, "no attribute");
assert_equals(style.getPropertyValue("math-depth"), tag === "none" || tag === "mprescripts" ? "1" : "0", "no attribute");
var absoluteScriptlevel = 2;
element.setAttribute("scriptlevel", absoluteScriptlevel);
assert_equals(style.getPropertyValue("math-depth"), absoluteScriptlevel, "attribute specified (<U>)");
assert_equals(style.getPropertyValue("math-depth"), "" + absoluteScriptlevel, "attribute specified <U>");
var positiveScriptlevelDelta = 1;
element.setAttribute("scriptlevel", `+${positiveScriptlevelDelta}`);
assert_equals(style.getPropertyValue("math-depth"), positiveScriptlevelDelta, epsilon, "attribute specified (+<U>)");
assert_equals(style.getPropertyValue("math-depth"), "" + positiveScriptlevelDelta, "attribute specified +<U>");
var negativeScriptlevelDelta = -3;
element.setAttribute("scriptlevel", negativeScriptlevelDelta);
assert_approx_equals(style.getPropertyValue("math-depth"), negativeScriptlevelDelta, "attribute specified (-<U>)");
element.setAttribute("scriptlevel", `${negativeScriptlevelDelta}`);
assert_equals(style.getPropertyValue("math-depth"), "" + negativeScriptlevelDelta, "attribute specified -<U>");
element.setAttribute("scriptlevel", absoluteScriptlevel);
element.setAttribute("mathsize", "42px");
assert_approx_equals(fontSize(style), 42, epsilon, "mathsize wins over scriptlevel");
assert_approx_equals(fontSize(style), 42, 1, "mathsize wins over scriptlevel");
}, `scriptlevel on the ${tag} element is mapped to math-depth(...)`);
test(function() {
// none and mprescripts appear as scripts
let expected = 0;
element.setAttribute("scriptlevel", "" + expected);
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "no attribute");
element.setAttribute("scriptlevel", " +1");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
element.setAttribute("scriptlevel", " + 1");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
element.setAttribute("scriptlevel", "2.0");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
element.setAttribute("scriptlevel", "-3\"");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
element.setAttribute("scriptlevel", "200px");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
element.setAttribute("scriptlevel", "add(2)");
assert_equals(style.getPropertyValue("math-depth"), "" + expected, "invalid scriptlevel value");
}, `invalid scriptlevel values on the ${tag} element are not mapped to math-depth(...)`);
test(function() {
assert_equals(style.getPropertyValue("math-style"), "compact", "no attribute");
element.setAttribute("displaystyle", "true");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment