RenderMathMLPadded.cpp [plain text]
#include "config.h"
#include "RenderMathMLPadded.h"
#if ENABLE(MATHML)
#include <cmath>
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLPadded);
RenderMathMLPadded::RenderMathMLPadded(MathMLPaddedElement& element, RenderStyle&& style)
: RenderMathMLRow(element, WTFMove(style))
{
}
LayoutUnit RenderMathMLPadded::voffset() const
{
return toUserUnits(element().voffset(), style(), 0);
}
LayoutUnit RenderMathMLPadded::lspace() const
{
LayoutUnit lspace = toUserUnits(element().lspace(), style(), 0);
return std::max<LayoutUnit>(0, lspace);
}
LayoutUnit RenderMathMLPadded::mpaddedWidth(LayoutUnit contentWidth) const
{
return std::max<LayoutUnit>(0, toUserUnits(element().width(), style(), contentWidth));
}
LayoutUnit RenderMathMLPadded::mpaddedHeight(LayoutUnit contentHeight) const
{
return std::max<LayoutUnit>(0, toUserUnits(element().height(), style(), contentHeight));
}
LayoutUnit RenderMathMLPadded::mpaddedDepth(LayoutUnit contentDepth) const
{
return std::max<LayoutUnit>(0, toUserUnits(element().depth(), style(), contentDepth));
}
void RenderMathMLPadded::computePreferredLogicalWidths()
{
ASSERT(preferredLogicalWidthsDirty());
RenderMathMLRow::computePreferredLogicalWidths();
m_maxPreferredLogicalWidth = mpaddedWidth(m_maxPreferredLogicalWidth);
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
setPreferredLogicalWidthsDirty(false);
}
void RenderMathMLPadded::layoutBlock(bool relayoutChildren, LayoutUnit)
{
ASSERT(needsLayout());
if (!relayoutChildren && simplifiedLayout())
return;
LayoutUnit contentWidth, contentAscent, contentDescent;
stretchVerticalOperatorsAndLayoutChildren();
getContentBoundingBox(contentWidth, contentAscent, contentDescent);
layoutRowItems(contentWidth, contentAscent);
LayoutUnit width = mpaddedWidth(contentWidth);
LayoutUnit ascent = mpaddedHeight(contentAscent);
LayoutUnit descent = mpaddedDepth(contentDescent);
LayoutPoint contentLocation(lspace(), ascent - contentAscent - voffset());
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
child->setLocation(child->location() + contentLocation);
setLogicalWidth(width);
setLogicalHeight(ascent + descent);
layoutPositionedObjects(relayoutChildren);
clearNeedsLayout();
}
std::optional<int> RenderMathMLPadded::firstLineBaseline() const
{
LayoutUnit ascent;
if (auto* baselineChild = firstChildBox())
ascent = ascentForChild(*baselineChild) + baselineChild->logicalTop() + voffset();
else
ascent = mpaddedHeight(0);
return std::optional<int>(std::lround(static_cast<float>(ascent)));
}
}
#endif