Commit 6a1f2487 authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

[mathml] Map global MathML attributes to CSS

The following mappings are performed:
dir => direction
mathbackground => background-color
mathcolor => color
mathsize => font-size

See https://mathml-refresh.github.io/mathml-core/#global-attributes

Note that the mapping of display, displaystyle, mathvariant and
scriptlevel will be added later.

Bug: 6606
Change-Id: I1b00c2981071dc1127570a5f7351f8b8e2b89357
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1908533
Commit-Queue: Rob Buis <rbuis@igalia.com>
Reviewed-by: default avatarFrédéric Wang <fwang@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714469}
parent 36b830a8
......@@ -9,5 +9,8 @@
data: [
"definitionURL",
"encoding",
"mathbackground",
"mathcolor",
"mathsize",
],
}
......@@ -5,6 +5,8 @@
#include "third_party/blink/renderer/core/mathml/mathml_element.h"
#include "third_party/blink/renderer/bindings/core/v8/script_event_listener.h"
#include "third_party/blink/renderer/core/css/css_property_name.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/html/html_element.h"
namespace blink {
......@@ -16,6 +18,57 @@ MathMLElement::MathMLElement(const QualifiedName& tagName,
MathMLElement::~MathMLElement() {}
static inline bool IsValidDirAttribute(const AtomicString& value) {
return DeprecatedEqualIgnoringCase(value, "ltr") ||
DeprecatedEqualIgnoringCase(value, "rtl");
}
// Keywords from MathML3 and CSS font-size are skipped.
static inline bool IsDisallowedMathSizeAttribute(const AtomicString& value) {
return DeprecatedEqualIgnoringCase(value, "medium") ||
value.EndsWith("large", kTextCaseASCIIInsensitive) ||
value.EndsWith("small", kTextCaseASCIIInsensitive) ||
DeprecatedEqualIgnoringCase(value, "smaller") ||
DeprecatedEqualIgnoringCase(value, "larger");
}
bool MathMLElement::IsPresentationAttribute(const QualifiedName& name) const {
// TODO(crbug.com/1023292, crbug.com/1023296): add support for display,
// displaystyle and scriptlevel.
if (name == html_names::kDirAttr || name == mathml_names::kMathsizeAttr ||
name == mathml_names::kMathcolorAttr ||
name == mathml_names::kMathbackgroundAttr)
return true;
return Element::IsPresentationAttribute(name);
}
void MathMLElement::CollectStyleForPresentationAttribute(
const QualifiedName& name,
const AtomicString& value,
MutableCSSPropertyValueSet* style) {
// TODO(crbug.com/1023292, crbug.com/1023296): add support for display,
// displaystyle and scriptlevel.
if (name == html_names::kDirAttr) {
if (IsValidDirAttribute(value)) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kDirection,
value);
}
} else if (name == mathml_names::kMathsizeAttr) {
if (!IsDisallowedMathSizeAttribute(value)) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kFontSize,
value);
}
} else if (name == mathml_names::kMathbackgroundAttr) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kBackgroundColor, value);
} else if (name == mathml_names::kMathcolorAttr) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kColor,
value);
} else {
Element::CollectStyleForPresentationAttribute(name, value, style);
}
}
void MathMLElement::ParseAttribute(const AttributeModificationParams& param) {
const AtomicString& event_name =
HTMLElement::EventNameForAttributeName(param.name);
......
......@@ -26,6 +26,11 @@ class CORE_EXPORT MathMLElement : public Element {
}
private:
bool IsPresentationAttribute(const QualifiedName&) const final;
void CollectStyleForPresentationAttribute(const QualifiedName&,
const AtomicString&,
MutableCSSPropertyValueSet*) final;
void ParseAttribute(const AttributeModificationParams&) final;
bool IsMathMLElement() const =
......
......@@ -1480,12 +1480,7 @@ crbug.com/875235 virtual/layout_ng_fieldset/fast/forms/fieldset/legend-small-aft
# ====== MathMLCore-only tests from here ======
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-006.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-007.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-008.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-009.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-010.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-overall.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-token.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-bar-001.html [ Failure ]
......@@ -1566,7 +1561,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-001.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/color-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/color-003.html [ Failure ]
......@@ -1579,21 +1573,11 @@ crbug.com/6606 external/wpt/mathml/relations/css-styling/displaystyle-014.html [
crbug.com/6606 external/wpt/mathml/relations/css-styling/displaystyle-015.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/displaystyle-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/displaystyle-2.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/dynamic-dir-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/ignored-properties-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/lengths-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/lengths-2.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathbackground-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathbackground-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathbackground-003.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathbackground-004.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathcolor-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathcolor-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathcolor-003.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathcolor-004.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathsize-attribute-css-keywords.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathsize-attribute-legacy-values.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathsize-attribute.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathvariant-auto.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathvariant-bold-fraktur.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/mathvariant-bold-italic.html [ Failure ]
......@@ -1627,7 +1611,6 @@ crbug.com/6606 external/wpt/mathml/relations/css-styling/visibility-004.html [ F
crbug.com/6606 external/wpt/mathml/relations/css-styling/width-height-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/writing-mode/writing-mode-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/css-styling/writing-mode/writing-mode-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/html5-tree/color-attributes-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/html5-tree/display-1.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/html5-tree/display-2.html [ Failure ]
crbug.com/6606 external/wpt/mathml/relations/html5-tree/href-click-1.html [ Failure ]
......
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