RenderMathMLPadded.cpp [plain text]
#include "config.h"
#include "RenderMathMLPadded.h"
#if ENABLE(MATHML)
#include "MathMLNames.h"
#include <cmath>
namespace WebCore {
using namespace MathMLNames;
RenderMathMLPadded::RenderMathMLPadded(Element& element, RenderStyle&& style)
: RenderMathMLRow(element, WTFMove(style))
{
}
void RenderMathMLPadded::resolveWidth(LayoutUnit& width)
{
auto& paddedElement = element();
width = toUserUnits(paddedElement.width(), style(), width);
if (width < 0)
width = 0;
}
void RenderMathMLPadded::resolveAttributes(LayoutUnit& width, LayoutUnit& height, LayoutUnit& depth, LayoutUnit& lspace, LayoutUnit& voffset)
{
resolveWidth(width);
auto& paddedElement = element();
height = toUserUnits(paddedElement.height(), style(), height);
depth = toUserUnits(paddedElement.depth(), style(), depth);
lspace = toUserUnits(paddedElement.lspace(), style(), lspace);
voffset = toUserUnits(paddedElement.voffset(), style(), voffset);
if (height < 0)
height = 0;
if (depth < 0)
depth = 0;
if (lspace < 0)
lspace = 0;
}
void RenderMathMLPadded::computePreferredLogicalWidths()
{
ASSERT(preferredLogicalWidthsDirty());
RenderMathMLRow::computePreferredLogicalWidths();
LayoutUnit width = m_maxPreferredLogicalWidth;
resolveWidth(width);
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = width;
setPreferredLogicalWidthsDirty(false);
}
void RenderMathMLPadded::layoutBlock(bool relayoutChildren, LayoutUnit)
{
ASSERT(needsLayout());
if (!relayoutChildren && simplifiedLayout())
return;
LayoutUnit contentAscent, contentDescent, contentWidth;
contentAscent = contentDescent = 0;
RenderMathMLRow::computeLineVerticalStretch(contentAscent, contentDescent);
RenderMathMLRow::layoutRowItems(contentAscent, contentDescent);
contentWidth = logicalWidth();
LayoutUnit width = contentWidth;
LayoutUnit ascent = contentAscent;
LayoutUnit descent = contentDescent;
LayoutUnit lspace = 0;
LayoutUnit voffset = 0;
resolveAttributes(width, ascent, descent, lspace, voffset);
LayoutPoint contentLocation(lspace, ascent - contentAscent - voffset);
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
child->setLocation(child->location() + contentLocation);
setLogicalWidth(width);
m_ascent = ascent;
setLogicalHeight(ascent + descent);
clearNeedsLayout();
}
void RenderMathMLPadded::updateFromElement()
{
RenderMathMLRow::updateFromElement();
setNeedsLayoutAndPrefWidthsRecalc();
}
void RenderMathMLPadded::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderMathMLRow::styleDidChange(diff, oldStyle);
setNeedsLayoutAndPrefWidthsRecalc();
}
Optional<int> RenderMathMLPadded::firstLineBaseline() const
{
return Optional<int>(std::lround(static_cast<float>(m_ascent)));
}
}
#endif