Commit 323e5a16 authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

[mathml] Implement basic operator support

Implement basic operator DOM and styling support.

Map lspace, rspace, minsize and maxsize attributes to
internal properties [1]. Since lspace is shared with
mpadded the MathPaddedLSpace internal property is renamed
to MathLSpace.

Note that this CL does not have a visual effect yet, that will
happen once we introduce the operator layout algorithm and
operator dictionary.

[1] https://mathml-refresh.github.io/mathml-core/#operator-fence-separator-or-accent-mo

Bug: 6606
Change-Id: I0999f26ec7f5765715fdf7ceab5a91296e6463bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340919Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Rob Buis <rbuis@igalia.com>
Cr-Commit-Position: refs/heads/master@{#800825}
parent de5b8c20
...@@ -54,9 +54,6 @@ ...@@ -54,9 +54,6 @@
#include "third_party/blink/renderer/core/layout/layout_replaced.h" #include "third_party/blink/renderer/core/layout/layout_replaced.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h" #include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/list_marker.h" #include "third_party/blink/renderer/core/layout/list_marker.h"
#include "third_party/blink/renderer/core/mathml/mathml_fraction_element.h"
#include "third_party/blink/renderer/core/mathml/mathml_padded_element.h"
#include "third_party/blink/renderer/core/mathml/mathml_space_element.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h" #include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h"
...@@ -732,20 +729,7 @@ void StyleAdjuster::AdjustComputedStyle(StyleResolverState& state, ...@@ -732,20 +729,7 @@ void StyleAdjuster::AdjustComputedStyle(StyleResolverState& state,
// https://drafts.csswg.org/css-display/#unbox-mathml // https://drafts.csswg.org/css-display/#unbox-mathml
style.SetDisplay(EDisplay::kNone); style.SetDisplay(EDisplay::kNone);
} }
if (auto* space = DynamicTo<MathMLSpaceElement>(*element)) {
space->AddMathBaselineIfNeeded(style, state.CssToLengthConversionData());
} else if (auto* padded = DynamicTo<MathMLPaddedElement>(*element)) {
padded->AddMathBaselineIfNeeded(style, state.CssToLengthConversionData());
padded->AddMathPaddedDepthIfNeeded(style,
state.CssToLengthConversionData());
padded->AddMathPaddedLSpaceIfNeeded(style,
state.CssToLengthConversionData());
padded->AddMathPaddedVOffsetIfNeeded(style,
state.CssToLengthConversionData());
} else if (auto* fraction = DynamicTo<MathMLFractionElement>(*element)) {
fraction->AddMathFractionBarThicknessIfNeeded(
style, state.CssToLengthConversionData());
}
if (style.GetWritingMode() != WritingMode::kHorizontalTb) { if (style.GetWritingMode() != WritingMode::kHorizontalTb) {
// TODO(rbuis): this will not work with logical CSS properties. // TODO(rbuis): this will not work with logical CSS properties.
// Disable vertical writing-mode for now. // Disable vertical writing-mode for now.
......
...@@ -80,6 +80,10 @@ ...@@ -80,6 +80,10 @@
#include "third_party/blink/renderer/core/html/track/vtt/vtt_cue.h" #include "third_party/blink/renderer/core/html/track/vtt/vtt_cue.h"
#include "third_party/blink/renderer/core/html/track/vtt/vtt_element.h" #include "third_party/blink/renderer/core/html/track/vtt/vtt_element.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/mathml/mathml_fraction_element.h"
#include "third_party/blink/renderer/core/mathml/mathml_operator_element.h"
#include "third_party/blink/renderer/core/mathml/mathml_padded_element.h"
#include "third_party/blink/renderer/core/mathml/mathml_space_element.h"
#include "third_party/blink/renderer/core/mathml_names.h" #include "third_party/blink/renderer/core/mathml_names.h"
#include "third_party/blink/renderer/core/media_type_names.h" #include "third_party/blink/renderer/core/media_type_names.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
...@@ -852,6 +856,9 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForElement( ...@@ -852,6 +856,9 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForElement(
state.Style()->GetCurrentColor()); state.Style()->GetCurrentColor());
} }
if (element->IsMathMLElement())
ApplyMathMLCustomStyleProperties(element, state);
SetAnimationUpdateIfNeeded(state, *element); SetAnimationUpdateIfNeeded(state, *element);
if (state.Style()->HasViewportUnits()) if (state.Style()->HasViewportUnits())
...@@ -917,6 +924,37 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element, ...@@ -917,6 +924,37 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element,
} }
} }
void StyleResolver::ApplyMathMLCustomStyleProperties(
Element* element,
StyleResolverState& state) {
DCHECK(element && element->IsMathMLElement());
ComputedStyle& style = state.StyleRef();
if (auto* space = DynamicTo<MathMLSpaceElement>(*element)) {
space->AddMathBaselineIfNeeded(style, state.CssToLengthConversionData());
} else if (auto* padded = DynamicTo<MathMLPaddedElement>(*element)) {
padded->AddMathBaselineIfNeeded(style, state.CssToLengthConversionData());
padded->AddMathPaddedDepthIfNeeded(style,
state.CssToLengthConversionData());
padded->AddMathPaddedLSpaceIfNeeded(style,
state.CssToLengthConversionData());
padded->AddMathPaddedVOffsetIfNeeded(style,
state.CssToLengthConversionData());
} else if (auto* fraction = DynamicTo<MathMLFractionElement>(*element)) {
fraction->AddMathFractionBarThicknessIfNeeded(
style, state.CssToLengthConversionData());
} else if (auto* operator_element =
DynamicTo<MathMLOperatorElement>(*element)) {
operator_element->AddMathLSpaceIfNeeded(style,
state.CssToLengthConversionData());
operator_element->AddMathRSpaceIfNeeded(style,
state.CssToLengthConversionData());
operator_element->AddMathMinSizeIfNeeded(style,
state.CssToLengthConversionData());
operator_element->AddMathMaxSizeIfNeeded(style,
state.CssToLengthConversionData());
}
}
void StyleResolver::ApplyBaseStyle( void StyleResolver::ApplyBaseStyle(
Element* element, Element* element,
StyleResolverState& state, StyleResolverState& state,
......
...@@ -195,6 +195,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> { ...@@ -195,6 +195,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
bool include_smil_properties); bool include_smil_properties);
void CollectTreeBoundaryCrossingRulesV0CascadeOrder(const Element&, void CollectTreeBoundaryCrossingRulesV0CascadeOrder(const Element&,
ElementRuleCollector&); ElementRuleCollector&);
void ApplyMathMLCustomStyleProperties(Element*, StyleResolverState&);
struct CacheSuccess { struct CacheSuccess {
STACK_ALLOCATED(); STACK_ALLOCATED();
......
...@@ -23,7 +23,7 @@ NGMathPaddedLayoutAlgorithm::NGMathPaddedLayoutAlgorithm( ...@@ -23,7 +23,7 @@ NGMathPaddedLayoutAlgorithm::NGMathPaddedLayoutAlgorithm(
LayoutUnit NGMathPaddedLayoutAlgorithm::RequestedLSpace() const { LayoutUnit NGMathPaddedLayoutAlgorithm::RequestedLSpace() const {
return std::max(LayoutUnit(), return std::max(LayoutUnit(),
ValueForLength(Style().GetMathPaddedLSpace(), LayoutUnit())); ValueForLength(Style().GetMathLSpace(), LayoutUnit()));
} }
LayoutUnit NGMathPaddedLayoutAlgorithm::RequestedVOffset() const { LayoutUnit NGMathPaddedLayoutAlgorithm::RequestedVOffset() const {
......
...@@ -10,6 +10,8 @@ blink_core_sources("mathml") { ...@@ -10,6 +10,8 @@ blink_core_sources("mathml") {
"mathml_element.h", "mathml_element.h",
"mathml_fraction_element.cc", "mathml_fraction_element.cc",
"mathml_fraction_element.h", "mathml_fraction_element.h",
"mathml_operator_element.cc",
"mathml_operator_element.h",
"mathml_padded_element.cc", "mathml_padded_element.cc",
"mathml_padded_element.h", "mathml_padded_element.h",
"mathml_radical_element.cc", "mathml_radical_element.cc",
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
"mathcolor", "mathcolor",
"mathsize", "mathsize",
"mathvariant", "mathvariant",
"maxsize",
"minsize",
"rspace",
"scriptlevel", "scriptlevel",
"voffset", "voffset",
"width", "width",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/mathml/mathml_operator_element.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
namespace blink {
MathMLOperatorElement::MathMLOperatorElement(Document& doc)
: MathMLElement(mathml_names::kMoTag, doc) {}
void MathMLOperatorElement::AddMathLSpaceIfNeeded(
ComputedStyle& style,
const CSSToLengthConversionData& conversion_data) {
if (auto length_or_percentage_value = AddMathLengthToComputedStyle(
conversion_data, mathml_names::kLspaceAttr)) {
style.SetMathLSpace(std::move(*length_or_percentage_value));
}
}
void MathMLOperatorElement::AddMathRSpaceIfNeeded(
ComputedStyle& style,
const CSSToLengthConversionData& conversion_data) {
if (auto length_or_percentage_value = AddMathLengthToComputedStyle(
conversion_data, mathml_names::kRspaceAttr)) {
style.SetMathLSpace(std::move(*length_or_percentage_value));
}
}
void MathMLOperatorElement::AddMathMinSizeIfNeeded(
ComputedStyle& style,
const CSSToLengthConversionData& conversion_data) {
if (auto length_or_percentage_value = AddMathLengthToComputedStyle(
conversion_data, mathml_names::kMinsizeAttr)) {
style.SetMathMinSize(std::move(*length_or_percentage_value));
}
}
void MathMLOperatorElement::AddMathMaxSizeIfNeeded(
ComputedStyle& style,
const CSSToLengthConversionData& conversion_data) {
if (auto length_or_percentage_value = AddMathLengthToComputedStyle(
conversion_data, mathml_names::kMaxsizeAttr)) {
style.SetMathMaxSize(std::move(*length_or_percentage_value));
}
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_MATHML_MATHML_OPERATOR_ELEMENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_MATHML_MATHML_OPERATOR_ELEMENT_H_
#include "third_party/blink/renderer/core/mathml/mathml_element.h"
namespace blink {
class ComputedStyle;
class CSSToLengthConversionData;
class Document;
class CORE_EXPORT MathMLOperatorElement final : public MathMLElement {
public:
explicit MathMLOperatorElement(Document&);
void AddMathLSpaceIfNeeded(ComputedStyle&, const CSSToLengthConversionData&);
void AddMathRSpaceIfNeeded(ComputedStyle&, const CSSToLengthConversionData&);
void AddMathMinSizeIfNeeded(ComputedStyle&, const CSSToLengthConversionData&);
void AddMathMaxSizeIfNeeded(ComputedStyle&, const CSSToLengthConversionData&);
private:
// FIXME: add operator dictionary.
// FIXME: add OperatorContent struct.
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_MATHML_MATHML_OPERATOR_ELEMENT_H_
...@@ -33,7 +33,7 @@ void MathMLPaddedElement::AddMathPaddedLSpaceIfNeeded( ...@@ -33,7 +33,7 @@ void MathMLPaddedElement::AddMathPaddedLSpaceIfNeeded(
const CSSToLengthConversionData& conversion_data) { const CSSToLengthConversionData& conversion_data) {
if (auto length_or_percentage_value = AddMathLengthToComputedStyle( if (auto length_or_percentage_value = AddMathLengthToComputedStyle(
conversion_data, mathml_names::kLspaceAttr)) conversion_data, mathml_names::kLspaceAttr))
style.SetMathPaddedLSpace(std::move(*length_or_percentage_value)); style.SetMathLSpace(std::move(*length_or_percentage_value));
} }
void MathMLPaddedElement::AddMathPaddedVOffsetIfNeeded( void MathMLPaddedElement::AddMathPaddedVOffsetIfNeeded(
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
}, },
{ {
name: "mo", name: "mo",
interfaceName: "MathMLElement", interfaceName: "MathMLOperatorElement",
}, },
{ {
name: "mpadded", name: "mpadded",
......
...@@ -1001,13 +1001,22 @@ ...@@ -1001,13 +1001,22 @@
getter: "GetMathFractionBarThickness", getter: "GetMathFractionBarThickness",
}, },
{ {
name: "MathPaddedLSpace", name: "MathLSpace",
field_template: "external", field_template: "external",
default_value: "Length()", default_value: "Length()",
include_paths: ["third_party/blink/renderer/platform/geometry/length.h"], include_paths: ["third_party/blink/renderer/platform/geometry/length.h"],
type_name: "Length", type_name: "Length",
field_group: "*", field_group: "*",
getter: "GetMathPaddedLSpace", getter: "GetMathLSpace",
},
{
name: "MathRSpace",
field_template: "external",
default_value: "Length()",
include_paths: ["third_party/blink/renderer/platform/geometry/length.h"],
type_name: "Length",
field_group: "*",
getter: "GetMathRSpace",
}, },
{ {
name: "MathPaddedVOffset", name: "MathPaddedVOffset",
...@@ -1027,6 +1036,25 @@ ...@@ -1027,6 +1036,25 @@
field_group: "*", field_group: "*",
getter: "GetMathPaddedDepth", getter: "GetMathPaddedDepth",
}, },
{
name: "MathMinSize",
field_template: "external",
default_value: "Length()",
include_paths: ["third_party/blink/renderer/platform/geometry/length.h"],
type_name: "Length",
field_group: "*",
getter: "GetMathMinSize",
},
{
name: "MathMaxSize",
field_template: "external",
default_value: "Length()",
include_paths: ["third_party/blink/renderer/platform/geometry/length.h"],
type_name: "Length",
field_group: "*",
getter: "GetMathMaxSize",
},
{ {
name: "MathScriptLevel", name: "MathScriptLevel",
inherited: true, inherited: 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