diff options
Diffstat (limited to 'Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp')
-rw-r--r-- | Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp | 95 |
1 files changed, 41 insertions, 54 deletions
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp b/Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp index 9a06b0236..631266258 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp @@ -43,20 +43,30 @@ RenderMathMLSubSup::RenderMathMLSubSup(Element* element) : RenderMathMLBlock(element) , m_scripts(0) { - // Determine what kind of under/over expression we have by element name + // Determine what kind of sub/sup expression we have by element name if (element->hasLocalName(MathMLNames::msubTag)) m_kind = Sub; else if (element->hasLocalName(MathMLNames::msupTag)) m_kind = Sup; - else if (element->hasLocalName(MathMLNames::msubsupTag)) - m_kind = SubSup; - else + else { + ASSERT(element->hasLocalName(MathMLNames::msubsupTag)); m_kind = SubSup; + } +} + +RenderBoxModelObject* RenderMathMLSubSup::base() const +{ + RenderObject* baseWrapper = firstChild(); + if (!baseWrapper) + return 0; + RenderObject* base = baseWrapper->firstChild(); + if (!base || !base->isBoxModelObject()) + return 0; + return toRenderBoxModelObject(base); } void RenderMathMLSubSup::addChild(RenderObject* child, RenderObject* beforeChild) { - // Note: The RenderMathMLBlock only allows element children to be added. Element* childElement = toElement(child->node()); @@ -105,72 +115,49 @@ void RenderMathMLSubSup::addChild(RenderObject* child, RenderObject* beforeChild } } +RenderMathMLOperator* RenderMathMLSubSup::unembellishedOperator() +{ + RenderBoxModelObject* base = this->base(); + if (!base || !base->isRenderMathMLBlock()) + return 0; + return toRenderMathMLBlock(base)->unembellishedOperator(); +} + void RenderMathMLSubSup::stretchToHeight(int height) { - RenderObject* base = firstChild(); - if (!base || !base->firstChild()) - return; - - if (base->firstChild() && base->firstChild()->isRenderMathMLBlock()) { - RenderMathMLBlock* block = toRenderMathMLBlock(base->firstChild()); - block->stretchToHeight(static_cast<int>(gSubSupStretch * height)); + RenderBoxModelObject* base = this->base(); + if (base && base->isRenderMathMLBlock()) { + toRenderMathMLBlock(base)->stretchToHeight(static_cast<int>(gSubSupStretch * height)); // Adjust the script placement after we stretch if (height > 0 && m_kind == SubSup && m_scripts) { - RenderObject* script = m_scripts->firstChild(); - if (script) { + RenderObject* supWrapper = m_scripts->firstChild(); + if (supWrapper) { // Calculate the script height without the container margins. - RenderObject* top = script; - int topHeight = getBoxModelObjectHeight(top->firstChild()); - int topAdjust = topHeight / gTopAdjustDivisor; - top->style()->setMarginTop(Length(-topAdjust, Fixed)); - top->style()->setMarginBottom(Length(height - topHeight + topAdjust, Fixed)); - if (top->isBoxModelObject()) { - RenderBoxModelObject* topBox = toRenderBoxModelObject(top); - topBox->updateBoxModelInfoFromStyle(); - } - m_scripts->setNeedsLayout(true); - setNeedsLayout(true); + int supHeight = getBoxModelObjectHeight(supWrapper->firstChild()); + int supTopAdjust = supHeight / gTopAdjustDivisor; + supWrapper->style()->setMarginTop(Length(-supTopAdjust, Fixed)); + supWrapper->style()->setMarginBottom(Length(height - supHeight + supTopAdjust, Fixed)); + supWrapper->setNeedsLayout(true); } } - } } -int RenderMathMLSubSup::nonOperatorHeight() const -{ - if (m_kind == SubSup) - return static_cast<int>(style()->fontSize()*gSubSupStretch); - return static_cast<int>(style()->fontSize()); -} - -void RenderMathMLSubSup::layout() +void RenderMathMLSubSup::layout() { - if (firstChild()) - firstChild()->setNeedsLayout(true); - if (m_scripts) - m_scripts->setNeedsLayout(true); - RenderBlock::layout(); - if (m_kind == SubSup) { - if (RenderObject* base = firstChild()) { - LayoutUnit maxHeight = 0; - RenderObject* current = base->firstChild(); - while (current) { - LayoutUnit height = getBoxModelObjectHeight(current); - if (height > maxHeight) - maxHeight = height; - current = current->nextSibling(); - } - LayoutUnit heightDiff = m_scripts ? (m_scripts->offsetHeight() - maxHeight) / 2 : 0; + if (m_kind == SubSup && m_scripts) { + if (RenderBoxModelObject* base = this->base()) { + LayoutUnit heightDiff = (m_scripts->offsetHeight() - base->offsetHeight()) / 2; if (heightDiff < 0) heightDiff = 0; - base->style()->setPaddingTop(Length(heightDiff, Fixed)); - base->setNeedsLayout(true); + RenderObject* baseWrapper = firstChild(); + baseWrapper->style()->setPaddingTop(Length(heightDiff, Fixed)); + baseWrapper->setNeedsLayout(true); + RenderBlock::layout(); } - setNeedsLayout(true); - RenderBlock::layout(); } } |