RenderMathMLRow.cpp [plain text]
#include "config.h"
#if ENABLE(MATHML)
#include "RenderMathMLRow.h"
#include "MathMLNames.h"
#include "RenderMathMLOperator.h"
namespace WebCore {
using namespace MathMLNames;
RenderMathMLRow::RenderMathMLRow(Node* row)
: RenderMathMLBlock(row)
{
}
int RenderMathMLRow::nonOperatorHeight() const
{
int maxHeight = 0;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
int blockHeight = block->nonOperatorHeight();
if (blockHeight > maxHeight)
maxHeight = blockHeight;
} else if (current->isBoxModelObject()) {
RenderBoxModelObject* box = toRenderBoxModelObject(current);
if (box->offsetHeight() > maxHeight)
maxHeight = box->offsetHeight();
}
}
return maxHeight;
}
void RenderMathMLRow::layout()
{
RenderBlock::layout();
int maxHeight = 0;
int childCount = 0;
int operatorCount = 0;
int operatorHeight = 0;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
childCount++;
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
if (!block->hasBase() && !block->isRenderMathMLOperator() && block->offsetHeight() > maxHeight)
maxHeight = block->offsetHeight();
if (block->hasBase() && block->nonOperatorHeight() > maxHeight)
maxHeight = block->nonOperatorHeight();
if (block->isRenderMathMLOperator()) {
if (block->offsetHeight() > operatorHeight)
operatorHeight = block->offsetHeight();
operatorCount++;
}
} else if (current->isBoxModelObject()) {
RenderBoxModelObject* box = toRenderBoxModelObject(current);
if (box->offsetHeight() > maxHeight)
maxHeight = box->offsetHeight();
}
}
if (childCount > 0 && childCount == operatorCount) {
maxHeight = operatorHeight;
}
if (maxHeight > 0) {
bool didStretch = false;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
block->stretchToHeight(maxHeight);
didStretch = true;
}
}
if (didStretch) {
setNeedsLayout(true);
setPreferredLogicalWidthsDirty(true, false);
RenderBlock::layout();
}
}
}
int RenderMathMLRow::baselinePosition(FontBaseline, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
{
if (firstChild() && firstChild()->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(firstChild());
if (block->isRenderMathMLOperator())
return block->y() + block->baselinePosition(AlphabeticBaseline, firstLine, direction, linePositionMode);
}
return RenderBlock::baselinePosition(AlphabeticBaseline, firstLine, direction, linePositionMode);
}
}
#endif // ENABLE(MATHML)