RenderMathMLUnderOver.cpp [plain text]
#include "config.h"
#if ENABLE(MATHML)
#include "RenderMathMLUnderOver.h"
#include "MathMLElement.h"
#include "MathMLNames.h"
#include "RenderIterator.h"
#include "RenderMathMLOperator.h"
namespace WebCore {
using namespace MathMLNames;
RenderMathMLUnderOver::RenderMathMLUnderOver(Element& element, PassRef<RenderStyle> style)
: RenderMathMLBlock(element, WTF::move(style))
{
if (element.hasTagName(MathMLNames::munderTag))
m_kind = Under;
else if (element.hasTagName(MathMLNames::moverTag))
m_kind = Over;
else {
ASSERT(element.hasTagName(MathMLNames::munderoverTag));
m_kind = UnderOver;
}
}
RenderMathMLOperator* RenderMathMLUnderOver::unembellishedOperator()
{
RenderObject* base = firstChild();
if (!base || !base->isRenderMathMLBlock())
return 0;
return toRenderMathMLBlock(base)->unembellishedOperator();
}
int RenderMathMLUnderOver::firstLineBaseline() const
{
RenderBox* base = firstChildBox();
if (!base)
return -1;
LayoutUnit baseline = base->firstLineBaseline();
if (baseline != -1)
baseline += base->logicalTop();
return baseline;
}
void RenderMathMLUnderOver::layout()
{
LayoutUnit stretchWidth = 0;
Vector<RenderMathMLOperator*, 2> renderOperators;
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->needsLayout()) {
if (child->isRenderMathMLBlock()) {
if (auto renderOperator = toRenderMathMLBlock(child)->unembellishedOperator()) {
renderOperator->resetStretchSize();
renderOperators.append(renderOperator);
}
}
toRenderElement(child)->layout();
}
if (child->isBox())
stretchWidth = std::max<LayoutUnit>(stretchWidth, toRenderBox(child)->logicalWidth());
}
for (auto& renderOperator : renderOperators)
renderOperator->stretchTo(stretchWidth);
RenderMathMLBlock::layout();
}
}
#endif // ENABLE(MATHML)