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 = nonOperatorHeight();
style()->setHeight(Length(maxHeight, Fixed));
int childCount = 0;
int operatorCount = 0;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
childCount++;
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
block->stretchToHeight(maxHeight);
if (block->isRenderMathMLOperator())
operatorCount++;
}
}
setNeedsLayoutAndPrefWidthsRecalc();
markContainingBlocksForLayout();
RenderBlock::layout();
int operatorHeight = 0;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
if (!block->hasBase() && !block->isRenderMathMLOperator()) {
if (block->offsetHeight() > maxHeight)
maxHeight = block->offsetHeight();
}
if (block->isRenderMathMLOperator())
if (block->offsetHeight() > operatorHeight)
operatorHeight = block->offsetHeight();
} else if (current->isBoxModelObject()) {
RenderBoxModelObject* box = toRenderBoxModelObject(current);
if (box->offsetHeight() > maxHeight)
maxHeight = box->offsetHeight();
}
}
if (childCount > 0 && childCount == operatorCount) {
maxHeight = operatorHeight;
}
int stretchHeight = maxHeight;
for (RenderObject* current = firstChild(); current; current = current->nextSibling()) {
if (current->isRenderMathMLBlock()) {
RenderMathMLBlock* block = toRenderMathMLBlock(current);
if (block->isRenderMathMLOperator()) {
RenderMathMLOperator* mathop = toRenderMathMLOperator(block);
mathop->stretchToHeight(stretchHeight);
} else {
block->stretchToHeight(stretchHeight);
RenderBoxModelObject* box = toRenderBoxModelObject(current);
if (box->offsetHeight() > maxHeight)
maxHeight = box->offsetHeight();
}
} else if (current->isBoxModelObject()) {
RenderBoxModelObject* box = toRenderBoxModelObject(current);
if (box->offsetHeight() > maxHeight)
maxHeight = box->offsetHeight();
}
}
style()->setHeight(Length(maxHeight, Fixed));
setNeedsLayoutAndPrefWidthsRecalc();
markContainingBlocksForLayout();
RenderBlock::layout();
}
}
#endif // ENABLE(MATHML)