Commit 8c86fa01 authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

[mathml] Fix logic errors in linethickness interpretation

The linethickness property should be parsed as length-percentage [1, 2],
so add a method to CSSParser to parse length-percentage. Negative
values are allowed as length-percentage but are clamped to zero by
the FractionLineThickness method.
Finally, for now we do not accept calc() expressions.

[1] https://mathml-refresh.github.io/mathml-core/#dfn-linethickness
[2] https://mathml-refresh.github.io/mathml-core/#dfn-length-percentage

Bug: 6606
Change-Id: I621d17d6e69cc113016fe1c809f55776c7e357d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098728Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarFrédéric Wang <fwang@igalia.com>
Commit-Queue: Rob Buis <rbuis@igalia.com>
Cr-Commit-Position: refs/heads/master@{#754546}
parent 0676deec
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/css/parser/css_parser_fast_paths.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_impl.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
#include "third_party/blink/renderer/core/css/parser/css_selector_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_supports_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
......@@ -275,4 +276,16 @@ const CSSValue* CSSParser::ParseFontFaceDescriptor(
return value;
}
CSSPrimitiveValue* CSSParser::ParseLengthPercentage(
const String& string,
const CSSParserContext* context) {
if (string.IsEmpty() || !context)
return nullptr;
CSSTokenizer tokenizer(string);
const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange range(tokens);
return css_property_parser_helpers::ConsumeLengthOrPercent(range, *context,
kValueRangeAll);
}
} // namespace blink
......@@ -23,6 +23,7 @@ class StyleRuleBase;
class StyleRuleKeyframe;
class StyleSheetContents;
class CSSValue;
class CSSPrimitiveValue;
enum class ParseSheetResult;
enum class SecureContextMode;
......@@ -112,6 +113,9 @@ class CORE_EXPORT CSSParser {
const String&,
CSSParserObserver&);
static CSSPrimitiveValue* ParseLengthPercentage(const String&,
const CSSParserContext*);
private:
static MutableCSSPropertyValueSet::SetResult ParseValue(
MutableCSSPropertyValueSet*,
......
......@@ -111,14 +111,12 @@ base::Optional<Length> MathMLElement::AddMathLengthToComputedStyle(
const QualifiedName& attr_name) {
if (!FastHasAttribute(attr_name))
return base::nullopt;
auto string = FastGetAttribute(attr_name);
const CSSValue* parsed = CSSParser::ParseSingleValue(
CSSPropertyID::kHeight, string,
StrictCSSParserContext(GetDocument().GetSecureContextMode()));
const auto* new_value = DynamicTo<CSSPrimitiveValue>(parsed);
if (!new_value || !new_value->IsLength())
auto value = FastGetAttribute(attr_name);
const CSSPrimitiveValue* parsed_value = CSSParser::ParseLengthPercentage(
value, StrictCSSParserContext(GetDocument().GetSecureContextMode()));
if (!parsed_value || parsed_value->IsCalculated())
return base::nullopt;
return new_value->ConvertToLength(conversion_data);
return parsed_value->ConvertToLength(conversion_data);
}
} // namespace blink
......@@ -1627,7 +1627,6 @@ crbug.com/875235 virtual/layout_ng_fieldset/fast/forms/fieldset/legend-after-mar
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction-006.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.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-linethickness-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-parameters-gap-001.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-parameters-gap-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-parameters-gap-003.html [ Failure ]
......
......@@ -56,6 +56,12 @@
assert_approx_equals(LineThickness("namedspace"), defaultRuleThickness, epsilon);
}, "Named space");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
/* Calc() expressions are invalid in MathML Core. */
assert_approx_equals(LineThickness("calc"), defaultRuleThickness, epsilon);
}, "Calc() expression");
done();
}
</script>
......@@ -85,5 +91,11 @@
<mspace width="20px" height="10px" style="background: cyan"></mspace>
</mfrac>
</math>
<math>
<mfrac id="calc" linethickness="calc(20px)">
<mspace width="20px" height="10px" style="background: blue"></mspace>
<mspace width="20px" height="10px" style="background: cyan"></mspace>
</mfrac>
</math>
</body>
</html>
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