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 @@ ...@@ -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_fast_paths.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_impl.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.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_selector_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_supports_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" #include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
...@@ -275,4 +276,16 @@ const CSSValue* CSSParser::ParseFontFaceDescriptor( ...@@ -275,4 +276,16 @@ const CSSValue* CSSParser::ParseFontFaceDescriptor(
return value; 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 } // namespace blink
...@@ -23,6 +23,7 @@ class StyleRuleBase; ...@@ -23,6 +23,7 @@ class StyleRuleBase;
class StyleRuleKeyframe; class StyleRuleKeyframe;
class StyleSheetContents; class StyleSheetContents;
class CSSValue; class CSSValue;
class CSSPrimitiveValue;
enum class ParseSheetResult; enum class ParseSheetResult;
enum class SecureContextMode; enum class SecureContextMode;
...@@ -112,6 +113,9 @@ class CORE_EXPORT CSSParser { ...@@ -112,6 +113,9 @@ class CORE_EXPORT CSSParser {
const String&, const String&,
CSSParserObserver&); CSSParserObserver&);
static CSSPrimitiveValue* ParseLengthPercentage(const String&,
const CSSParserContext*);
private: private:
static MutableCSSPropertyValueSet::SetResult ParseValue( static MutableCSSPropertyValueSet::SetResult ParseValue(
MutableCSSPropertyValueSet*, MutableCSSPropertyValueSet*,
......
...@@ -111,14 +111,12 @@ base::Optional<Length> MathMLElement::AddMathLengthToComputedStyle( ...@@ -111,14 +111,12 @@ base::Optional<Length> MathMLElement::AddMathLengthToComputedStyle(
const QualifiedName& attr_name) { const QualifiedName& attr_name) {
if (!FastHasAttribute(attr_name)) if (!FastHasAttribute(attr_name))
return base::nullopt; return base::nullopt;
auto string = FastGetAttribute(attr_name); auto value = FastGetAttribute(attr_name);
const CSSValue* parsed = CSSParser::ParseSingleValue( const CSSPrimitiveValue* parsed_value = CSSParser::ParseLengthPercentage(
CSSPropertyID::kHeight, string, value, StrictCSSParserContext(GetDocument().GetSecureContextMode()));
StrictCSSParserContext(GetDocument().GetSecureContextMode())); if (!parsed_value || parsed_value->IsCalculated())
const auto* new_value = DynamicTo<CSSPrimitiveValue>(parsed);
if (!new_value || !new_value->IsLength())
return base::nullopt; return base::nullopt;
return new_value->ConvertToLength(conversion_data); return parsed_value->ConvertToLength(conversion_data);
} }
} // namespace blink } // namespace blink
...@@ -1627,7 +1627,6 @@ crbug.com/875235 virtual/layout_ng_fieldset/fast/forms/fieldset/legend-after-mar ...@@ -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-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-009.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/direction/direction.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-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-002.html [ Failure ]
crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-parameters-gap-003.html [ Failure ] crbug.com/6606 external/wpt/mathml/presentation-markup/fractions/frac-parameters-gap-003.html [ Failure ]
......
...@@ -56,6 +56,12 @@ ...@@ -56,6 +56,12 @@
assert_approx_equals(LineThickness("namedspace"), defaultRuleThickness, epsilon); assert_approx_equals(LineThickness("namedspace"), defaultRuleThickness, epsilon);
}, "Named space"); }, "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(); done();
} }
</script> </script>
...@@ -85,5 +91,11 @@ ...@@ -85,5 +91,11 @@
<mspace width="20px" height="10px" style="background: cyan"></mspace> <mspace width="20px" height="10px" style="background: cyan"></mspace>
</mfrac> </mfrac>
</math> </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> </body>
</html> </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