Skip to content

Commit

Permalink
[mathml] Implement the mmultiscripts element
Browse files Browse the repository at this point in the history
Implement mmultiscripts element [1] and its possible
children <mprescripts> and <none>.

[1] https://mathml-refresh.github.io/mathml-core/#prescripts-and-tensor-indices-mmultiscripts

Bug: 6606
Change-Id: Ia9e48d50902546d7527e4ba063838c4a9f0d2b9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264334
Commit-Queue: Rob Buis <rbuis@igalia.com>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785551}
  • Loading branch information
rwlbuis authored and Commit Bot committed Jul 6, 2020
1 parent 6a126ad commit 3d681bf
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 183 deletions.
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/css/mathml.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ math[display="block"] {
outline: auto 1px -webkit-focus-ring-color;
}

maction, merror, mfrac, mphantom, mrow, mspace, mstyle, msub, msup, msubsup, munder, mover, munderover, msqrt, mroot
maction, merror, mfrac, mphantom, mrow, mspace, mstyle, msub, msup, msubsup, munder, mover, munderover, msqrt, mroot, mmultiscripts, mprescripts, none
{
display: math;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ bool IsValidMathMLFraction(const NGBlockNode& node) {
return InFlowChildCountIs(node, 2);
}

static bool IsPrescriptDelimiter(const NGBlockNode& block_node) {
auto* node = block_node.GetLayoutBox()->GetNode();
return node && IsA<MathMLElement>(node) &&
node->HasTagName(mathml_names::kMprescriptsTag);
}

// Valid according to:
// https://mathml-refresh.github.io/mathml-core/#prescripts-and-tensor-indices-mmultiscripts
inline bool IsValidMultiscript(const NGBlockNode& node) {
auto child = To<NGBlockNode>(FirstChildInFlow(node));
if (!child || IsPrescriptDelimiter(child))
return false;
bool number_of_scripts_is_even = true;
while (child) {
child = To<NGBlockNode>(NextSiblingInFlow(child));
if (!child)
continue;
if (IsPrescriptDelimiter(child)) {
if (!number_of_scripts_is_even)
return false;
continue;
}
number_of_scripts_is_even = !number_of_scripts_is_even;
}
return number_of_scripts_is_even;
}

bool IsValidMathMLScript(const NGBlockNode& node) {
switch (node.ScriptType()) {
case MathScriptType::kUnder:
Expand All @@ -81,6 +108,8 @@ bool IsValidMathMLScript(const NGBlockNode& node) {
case MathScriptType::kSubSup:
case MathScriptType::kUnderOver:
return InFlowChildCountIs(node, 3);
case MathScriptType::kMultiscripts:
return IsValidMultiscript(node);
default:
return false;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@ class CORE_EXPORT NGMathScriptsLayoutAlgorithm
explicit NGMathScriptsLayoutAlgorithm(const NGLayoutAlgorithmParams& params);

private:
struct SubSupPair {
NGBlockNode sub = nullptr;
NGBlockNode sup = nullptr;
};

void GatherChildren(NGBlockNode* base,
NGBlockNode* sup,
NGBlockNode* sub,
Vector<SubSupPair>*,
NGBlockNode* prescripts,
unsigned* first_prescript_index,
NGBoxFragmentBuilder* = nullptr) const;

MinMaxSizesResult ComputeMinMaxSizes(const MinMaxSizesInput&) const final;

struct ChildAndMetrics {
STACK_ALLOCATED();
DISALLOW_NEW();

public:
scoped_refptr<const NGLayoutResult> result;
LayoutUnit ascent;
LayoutUnit descent;
LayoutUnit inline_size;
NGBoxStrut margins;
NGBlockNode node = nullptr;
};
typedef Vector<ChildAndMetrics, 4> ChildrenAndMetrics;

ChildAndMetrics LayoutAndGetMetrics(NGBlockNode child) const;

Expand All @@ -52,9 +60,10 @@ class CORE_EXPORT NGMathScriptsLayoutAlgorithm
LayoutUnit descent;
NGBoxStrut margins;
};
VerticalMetrics GetVerticalMetrics(const ChildAndMetrics& base_metrics,
const ChildAndMetrics& sub_metrics,
const ChildAndMetrics& sup_metrics) const;
VerticalMetrics GetVerticalMetrics(
const ChildAndMetrics& base_metrics,
const ChildrenAndMetrics& sub_metrics,
const ChildrenAndMetrics& sup_metrics) const;

scoped_refptr<const NGLayoutResult> Layout() final;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ static MathScriptType ScriptTypeOf(const QualifiedName& tagName) {
return MathScriptType::kUnder;
if (tagName == mathml_names::kMoverTag)
return MathScriptType::kOver;
DCHECK(tagName == mathml_names::kMunderoverTag);
return MathScriptType::kUnderOver;
if (tagName == mathml_names::kMunderoverTag)
return MathScriptType::kUnderOver;
DCHECK_EQ(tagName, mathml_names::kMmultiscriptsTag);
return MathScriptType::kMultiscripts;
}

MathMLScriptsElement::MathMLScriptsElement(const QualifiedName& tagName,
Expand Down
13 changes: 11 additions & 2 deletions third_party/blink/renderer/core/mathml/mathml_scripts_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ namespace blink {

class Document;

enum class MathScriptType { kSub, kSuper, kSubSup, kUnder, kOver, kUnderOver };
enum class MathScriptType {
kSub,
kSuper,
kSubSup,
kMultiscripts,
kUnder,
kOver,
kUnderOver
};

class CORE_EXPORT MathMLScriptsElement : public MathMLElement {
public:
Expand Down Expand Up @@ -39,7 +47,8 @@ struct DowncastTraits<MathMLScriptsElement> {
mathml_element.HasTagName(mathml_names::kMunderoverTag) ||
mathml_element.HasTagName(mathml_names::kMsubTag) ||
mathml_element.HasTagName(mathml_names::kMsupTag) ||
mathml_element.HasTagName(mathml_names::kMsubsupTag);
mathml_element.HasTagName(mathml_names::kMsubsupTag) ||
mathml_element.HasTagName(mathml_names::kMmultiscriptsTag);
}
};

Expand Down
12 changes: 12 additions & 0 deletions third_party/blink/renderer/core/mathml/mathml_tag_names.json5
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
name: "msubsup",
interfaceName: "MathMLScriptsElement",
},
{
name: "mmultiscripts",
interfaceName: "MathMLScriptsElement",
},
{
name: "mprescripts",
interfaceName: "MathMLRowElement",
},
{
name: "mi",
interfaceName: "MathMLElement",
Expand Down Expand Up @@ -111,5 +119,9 @@
name: "semantics",
interfaceName: "MathMLRowElement",
},
{
name: "none",
interfaceName: "MathMLRowElement",
},
]
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 3d681bf

Please sign in to comment.