RenderMathMLRow.cpp [plain text]
#include "config.h"
#if ENABLE(MATHML)
#include "RenderMathMLRow.h"
#include "MathMLNames.h"
#include "RenderIterator.h"
#include "RenderMathMLOperator.h"
#include "RenderMathMLRoot.h"
namespace WebCore {
using namespace MathMLNames;
RenderMathMLRow::RenderMathMLRow(Element& element, RenderStyle&& style)
: RenderMathMLBlock(element, WTFMove(style))
{
}
void RenderMathMLRow::updateOperatorProperties()
{
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
if (is<RenderMathMLBlock>(*child)) {
if (auto* renderOperator = downcast<RenderMathMLBlock>(*child).unembellishedOperator())
renderOperator->updateOperatorProperties();
}
}
setNeedsLayoutAndPrefWidthsRecalc();
}
Optional<int> RenderMathMLRow::firstLineBaseline() const
{
auto* baselineChild = firstChildBox();
if (!baselineChild)
return Optional<int>();
return Optional<int>(static_cast<int>(lroundf(ascentForChild(*baselineChild) + baselineChild->logicalTop())));
}
void RenderMathMLRow::computeLineVerticalStretch(LayoutUnit& ascent, LayoutUnit& descent)
{
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
if (is<RenderMathMLBlock>(child)) {
auto* renderOperator = downcast<RenderMathMLBlock>(child)->unembellishedOperator();
if (renderOperator && renderOperator->hasOperatorFlag(MathMLOperatorDictionary::Stretchy))
continue;
}
child->layoutIfNeeded();
LayoutUnit childHeightAboveBaseline = ascentForChild(*child);
LayoutUnit childDepthBelowBaseline = child->logicalHeight() - childHeightAboveBaseline;
ascent = std::max(ascent, childHeightAboveBaseline);
descent = std::max(descent, childDepthBelowBaseline);
}
if (ascent + descent <= 0) {
ascent = style().fontSize();
descent = 0;
}
}
void RenderMathMLRow::computePreferredLogicalWidths()
{
ASSERT(preferredLogicalWidthsDirty());
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0;
LayoutUnit preferredWidth = 0;
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
preferredWidth += child->maxPreferredLogicalWidth() + child->marginLogicalWidth();
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = preferredWidth + borderAndPaddingLogicalWidth();
setPreferredLogicalWidthsDirty(false);
}
void RenderMathMLRow::layoutRowItems(LayoutUnit& ascent, LayoutUnit& descent)
{
LayoutUnit width = borderAndPaddingStart();
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
if (child->isOutOfFlowPositioned())
continue;
if (is<RenderMathMLBlock>(child)) {
auto renderOperator = downcast<RenderMathMLBlock>(child)->unembellishedOperator();
if (renderOperator && renderOperator->hasOperatorFlag(MathMLOperatorDictionary::Stretchy) && renderOperator->isVertical())
renderOperator->stretchTo(ascent, descent);
}
child->layoutIfNeeded();
width += child->marginStart() + child->logicalWidth() + child->marginEnd();
}
width += borderEnd() + paddingEnd();
if ((!isRenderMathMLMath() || style().display() == INLINE))
setLogicalWidth(width);
LayoutUnit verticalOffset = borderTop() + paddingTop();
LayoutUnit maxAscent = 0, maxDescent = 0; LayoutUnit horizontalOffset = borderAndPaddingStart();
bool shouldFlipHorizontal = !style().isLeftToRightDirection();
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
if (child->isOutOfFlowPositioned()) {
child->containingBlock()->insertPositionedObject(*child);
continue;
}
LayoutUnit childHorizontalExtent = child->logicalWidth();
LayoutUnit ascent = ascentForChild(*child);
LayoutUnit descent = child->verticalMarginExtent() + child->logicalHeight() - ascent;
maxAscent = std::max(maxAscent, ascent);
maxDescent = std::max(maxDescent, descent);
LayoutUnit childVerticalMarginBoxExtent = maxAscent + maxDescent;
horizontalOffset += child->marginStart();
setLogicalHeight(std::max(logicalHeight(), verticalOffset + borderBottom() + paddingBottom() + childVerticalMarginBoxExtent + horizontalScrollbarHeight()));
LayoutPoint childLocation(shouldFlipHorizontal ? logicalWidth() - horizontalOffset - childHorizontalExtent : horizontalOffset, verticalOffset + child->marginTop());
child->setLocation(childLocation);
horizontalOffset += childHorizontalExtent + child->marginEnd();
}
LayoutUnit centerBlockOffset = 0;
if (style().display() == BLOCK)
centerBlockOffset = std::max<LayoutUnit>(0, (logicalWidth() - (horizontalOffset + borderEnd() + paddingEnd())) / 2);
if (shouldFlipHorizontal && centerBlockOffset > 0)
centerBlockOffset = -centerBlockOffset;
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
LayoutUnit ascent = ascentForChild(*child);
LayoutUnit startOffset = maxAscent - ascent;
child->setLocation(child->location() + LayoutPoint(centerBlockOffset, startOffset));
}
ascent = maxAscent;
descent = maxDescent;
}
void RenderMathMLRow::layoutBlock(bool relayoutChildren, LayoutUnit)
{
ASSERT(needsLayout());
if (!relayoutChildren && simplifiedLayout())
return;
LayoutUnit ascent = 0;
LayoutUnit descent = 0;
computeLineVerticalStretch(ascent, descent);
recomputeLogicalWidth();
setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight());
layoutRowItems(ascent, descent);
updateLogicalHeight();
clearNeedsLayout();
}
}
#endif // ENABLE(MATHML)