Skip to content

Commit

Permalink
Layout <mspace> elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Mar 16, 2017
1 parent a63d474 commit e081360
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 1 deletion.
4 changes: 4 additions & 0 deletions third_party/WebKit/Source/core/layout/mathml/BUILD.gn
Expand Up @@ -10,10 +10,14 @@ blink_core_sources("mathml") {
"layout_ng_mathml_block.h",
"layout_ng_mathml_math.cc",
"layout_ng_mathml_math.h",
"layout_ng_mathml_space.cc",
"layout_ng_mathml_space.h",
"ng_mathml_input_node.cc",
"ng_mathml_input_node.h",
"ng_mathml_math_node.cc",
"ng_mathml_math_node.h",
"ng_mathml_space_node.cc",
"ng_mathml_space_node.h",
]

configs += [
Expand Down
@@ -0,0 +1,28 @@
// Copyright 2017 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 "layout_ng_mathml_space.h"

#include "core/mathml/MathMLSpaceElement.h"

namespace blink {

LayoutNGMathMLSpace::LayoutNGMathMLSpace(MathMLSpaceElement* element)
: LayoutNGMathMLBlock(element) {
DCHECK(element);
}

void LayoutNGMathMLSpace::layoutBlock(bool relayoutChildren) {
ASSERT_NOT_REACHED(); // Should use LayoutNG instead
clearNeedsLayout();
}

NGMathMLSpaceNode* LayoutNGMathMLSpace::toNGLayoutInputNode(
const ComputedStyle& style) {
MathMLSpaceElement* spaceElement = toMathMLSpaceElement(node());
return new NGMathMLSpaceNode(this, spaceElement->width(),
spaceElement->height(), spaceElement->depth());
}

} // namespace blink
@@ -0,0 +1,28 @@
// Copyright 2017 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 LayoutNGMathMLSpace_h
#define LayoutNGMathMLSpace_h

#include "core/layout/mathml/ng_mathml_space_node.h"

#include "core/layout/LayoutBlock.h"
#include "core/layout/mathml/layout_ng_mathml_block.h"

namespace blink {

class MathMLSpaceElement;

class LayoutNGMathMLSpace final : public LayoutNGMathMLBlock {
public:
explicit LayoutNGMathMLSpace(MathMLSpaceElement*);
~LayoutNGMathMLSpace() override = default;
void layoutBlock(bool relayoutChildren) override;
const char* name() const override { return "LayoutNGMathMLSpace"; }

NGMathMLSpaceNode* toNGLayoutInputNode(const ComputedStyle&) override;
};
}

#endif // LayoutNGMathMLSpace_h
@@ -0,0 +1,30 @@
// Copyright 2017 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 "core/layout/mathml/ng_mathml_space_node.h"

#include "core/layout/ng/ng_fragment_builder.h"

namespace blink {

RefPtr<NGLayoutResult> NGMathMLSpaceNode::Layout(
NGConstraintSpace* constraint_space,
NGBreakToken* break_token) {
NGFragmentBuilder builder(NGPhysicalFragment::kFragmentBox, this);

// FIXME: We should use height & depth to set NGFragment's alignmentBaseline.
LayoutUnit blockSize = toUserUnits(m_height, LayoutUnit(0)) +
toUserUnits(m_depth, LayoutUnit(0));

RefPtr<NGLayoutResult> result =
builder.SetBlockSize(blockSize)
.SetInlineSize(toUserUnits(m_width, LayoutUnit(0)))
.ToBoxFragment();

CopyFragmentDataToLayoutBox(*constraint_space, result.get());

return result;
}

} // namespace blink
@@ -0,0 +1,43 @@
// Copyright 2017 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 NGMathMLSpaceNode_h
#define NGMathMLSpaceNode_h

#include "core/layout/mathml/ng_mathml_input_node.h"

#include "core/mathml/MathMLElement.h"

namespace blink {

// Let's assume we're a block so our parent can layout us as such, but override
// our layout algorithm so new we layout the children using a simplified
// algorithm for MathML.
//
// FIXME(emilio): This might need more care, but right now LayoutNG only does
// Block and a simplified version of inline layout, so making it quack like a
// block is probably ok.
class NGMathMLSpaceNode final : public NGMathMLInputNode {
public:
explicit NGMathMLSpaceNode(LayoutObject* flow,
const MathMLElement::Length& width,
const MathMLElement::Length& height,
const MathMLElement::Length& depth)
: NGMathMLInputNode(flow),
m_width(width),
m_height(height),
m_depth(depth) {}

RefPtr<NGLayoutResult> Layout(NGConstraintSpace* constraint_space,
NGBreakToken* break_token) final;

private:
const MathMLElement::Length& m_width;
const MathMLElement::Length& m_height;
const MathMLElement::Length& m_depth;
};

} // namespace blink

#endif
2 changes: 2 additions & 0 deletions third_party/WebKit/Source/core/mathml/BUILD.gn
Expand Up @@ -10,6 +10,8 @@ blink_core_sources("mathml") {
"MathMLElement.h",
"MathMLMathElement.cpp",
"MathMLMathElement.h",
"MathMLSpaceElement.cpp",
"MathMLSpaceElement.h",
"MathMLUnknownElement.cpp",
"MathMLUnknownElement.h",
]
Expand Down
42 changes: 42 additions & 0 deletions third_party/WebKit/Source/core/mathml/MathMLSpaceElement.cpp
@@ -0,0 +1,42 @@
/*
* Copyright 2017 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 "core/mathml/MathMLSpaceElement.h"

#include "core/layout/mathml/layout_ng_mathml_space.h"

namespace blink {

using namespace MathMLNames;

MathMLSpaceElement::MathMLSpaceElement(Document& doc)
: MathMLElement(MathMLNames::mspaceTag, doc) {}

DEFINE_NODE_FACTORY(MathMLSpaceElement)

void MathMLSpaceElement::parseAttribute(
const AttributeModificationParams& param) {
if (param.name == widthAttr)
m_width.dirty = true;
else if (param.name == heightAttr)
m_height.dirty = true;
else if (param.name == depthAttr)
m_depth.dirty = true;

MathMLElement::parseAttribute(param);
}

/*
* TODO(emilio): We could consider writing our custom paint code for MathML
* stuff, and then we'd only need to create LayoutNGNodes.
*
* But meanwhile...
*/
LayoutObject* MathMLSpaceElement::createLayoutObject(const ComputedStyle&) {
return new LayoutNGMathMLSpace(this);
}

} // namespace blink
46 changes: 46 additions & 0 deletions third_party/WebKit/Source/core/mathml/MathMLSpaceElement.h
@@ -0,0 +1,46 @@
/*
* Copyright 2017 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 MathMLMSpaceElement_h
#define MathMLMSpaceElement_h

#include "core/MathMLNames.h"
#include "core/mathml/MathMLElement.h"

namespace blink {

class LayoutObject;
class ComputedStyle;

class MathMLSpaceElement final : public MathMLElement {
public:
DECLARE_NODE_FACTORY(MathMLSpaceElement);

const Length& width() {
return cachedMathMLLength(MathMLNames::widthAttr, m_width);
}
const Length& height() {
return cachedMathMLLength(MathMLNames::heightAttr, m_height);
}
const Length& depth() {
return cachedMathMLLength(MathMLNames::depthAttr, m_depth);
}

protected:
explicit MathMLSpaceElement(Document&);

private:
LayoutObject* createLayoutObject(const ComputedStyle&) override;
virtual void parseAttribute(const AttributeModificationParams&);

Length m_width;
Length m_height;
Length m_depth;
};

} // namespace blink

#endif // MathMLMSpaceElement
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/core/mathml/MathMLTagNames.json5
Expand Up @@ -18,7 +18,7 @@
},
{
name: "mspace",
interfaceName: "MathMLElement",
interfaceName: "MathMLSpaceElement",
},
{
name: "mi",
Expand Down

0 comments on commit e081360

Please sign in to comment.