diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
commit | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (patch) | |
tree | b34b0daceb7c8e7fdde4b4ec43650ab7caadb0a9 /Source/WebCore/rendering/mathml | |
parent | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (diff) | |
download | qtwebkit-ad0d549d4cc13433f77c1ac8f0ab379c83d93f28.tar.gz |
Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790)
Diffstat (limited to 'Source/WebCore/rendering/mathml')
20 files changed, 163 insertions, 208 deletions
diff --git a/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp b/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp index 2bdccec2c..167eeb21a 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp @@ -49,7 +49,7 @@ bool RenderMathMLBlock::isChildAllowed(RenderObject* child, RenderStyle*) const return child->node() && child->node()->nodeType() == Node::ELEMENT_NODE; } -PassRefPtr<RenderStyle> RenderMathMLBlock::makeBlockStyle() +PassRefPtr<RenderStyle> RenderMathMLBlock::createBlockStyle() { RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); @@ -57,14 +57,6 @@ PassRefPtr<RenderStyle> RenderMathMLBlock::makeBlockStyle() return newStyle; } -int RenderMathMLBlock::nonOperatorHeight() const -{ - if (!isRenderMathMLOperator()) - return offsetHeight(); - - return 0; -} - void RenderMathMLBlock::stretchToHeight(int height) { for (RenderObject* current = firstChild(); current; current = current->nextSibling()) @@ -82,7 +74,7 @@ void RenderMathMLBlock::paint(PaintInfo& info, const LayoutPoint& paintOffset) if (info.context->paintingDisabled() || info.phase != PaintPhaseForeground) return; - LayoutPoint adjustedPaintOffset = paintOffset + location(); + IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location()); GraphicsContextStateSaver stateSaver(*info.context); diff --git a/Source/WebCore/rendering/mathml/RenderMathMLBlock.h b/Source/WebCore/rendering/mathml/RenderMathMLBlock.h index 4d8184bcf..5d4d780ed 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLBlock.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLBlock.h @@ -34,6 +34,8 @@ namespace WebCore { +class RenderMathMLOperator; + class RenderMathMLBlock : public RenderBlock { public: RenderMathMLBlock(Node* container); @@ -43,8 +45,15 @@ public: virtual bool isRenderMathMLOperator() const { return false; } virtual bool isRenderMathMLRow() const { return false; } virtual bool isRenderMathMLMath() const { return false; } - virtual bool hasBase() const { return false; } - virtual int nonOperatorHeight() const; + + // MathML defines an "embellished operator" as roughly an <mo> that may have subscripts, + // superscripts, underscripts, overscripts, or a denominator (as in d/dx, where "d" is some + // differential operator). The padding, precedence, and stretchiness of the base <mo> should + // apply to the embellished operator as a whole. unembellishedOperator() checks for being an + // embellished operator, and omits any embellishments. + // FIXME: We don't yet handle all the cases in the MathML spec. See + // https://bugs.webkit.org/show_bug.cgi?id=78617. + virtual RenderMathMLOperator* unembellishedOperator() { return 0; } virtual void stretchToHeight(int height); #if ENABLE(DEBUG_MATH_LAYOUT) @@ -70,7 +79,7 @@ protected: return 0; } - virtual PassRefPtr<RenderStyle> makeBlockStyle(); + virtual PassRefPtr<RenderStyle> createBlockStyle(); private: virtual const char* renderName() const { return isAnonymous() ? "RenderMathMLBlock (anonymous)" : "RenderMathMLBlock"; } diff --git a/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp b/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp index 55da1a5ec..c2f67ea93 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp @@ -44,8 +44,8 @@ enum Braces { OpeningBraceChar = 0x28, ClosingBraceChar = 0x29 }; static const float gOperatorPadding = 0.1f; -RenderMathMLFenced::RenderMathMLFenced(Node* fenced) - : RenderMathMLRow(fenced) +RenderMathMLFenced::RenderMathMLFenced(Element* element) + : RenderMathMLRow(element) , m_open(OpeningBraceChar) , m_close(ClosingBraceChar) { @@ -63,7 +63,7 @@ void RenderMathMLFenced::updateFromElement() if (closeValue.length() > 0) m_close = closeValue[0]; - AtomicString separators = static_cast<Element*>(fenced)->getAttribute(MathMLNames::separatorsAttr); + AtomicString separators = fenced->getAttribute(MathMLNames::separatorsAttr); if (!separators.isNull()) { StringBuilder characters; for (unsigned int i = 0; i < separators.length(); i++) { @@ -80,22 +80,22 @@ void RenderMathMLFenced::updateFromElement() makeFences(); } -RefPtr<RenderStyle> RenderMathMLFenced::makeOperatorStyle() +PassRefPtr<RenderStyle> RenderMathMLFenced::createOperatorStyle() { RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); newStyle->setDisplay(INLINE_BLOCK); newStyle->setPaddingRight(Length(static_cast<int>(gOperatorPadding * style()->fontSize()), Fixed)); - return newStyle; + return newStyle.release(); } void RenderMathMLFenced::makeFences() { RenderObject* openFence = new (renderArena()) RenderMathMLOperator(node(), m_open); - openFence->setStyle(makeOperatorStyle().release()); + openFence->setStyle(createOperatorStyle()); RenderBlock::addChild(openFence, firstChild()); RenderObject* closeFence = new (renderArena()) RenderMathMLOperator(node(), m_close); - closeFence->setStyle(makeOperatorStyle().release()); + closeFence->setStyle(createOperatorStyle()); RenderBlock::addChild(closeFence); } @@ -122,7 +122,7 @@ void RenderMathMLFenced::addChild(RenderObject* child, RenderObject*) separator = (*m_separators.get())[count - 2]; RenderObject* separatorObj = new (renderArena()) RenderMathMLOperator(node(), separator); - separatorObj->setStyle(makeOperatorStyle().release()); + separatorObj->setStyle(createOperatorStyle()); RenderBlock::addChild(separatorObj, lastChild()); } } diff --git a/Source/WebCore/rendering/mathml/RenderMathMLFenced.h b/Source/WebCore/rendering/mathml/RenderMathMLFenced.h index 9707b3ae6..b2bca9971 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLFenced.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLFenced.h @@ -34,15 +34,16 @@ namespace WebCore { class RenderMathMLFenced : public RenderMathMLRow { public: - RenderMathMLFenced(Node *fraction); + RenderMathMLFenced(Element*); virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); virtual void updateFromElement(); private: virtual const char* renderName() const { return "RenderMathMLFenced"; } + PassRefPtr<RenderStyle> createOperatorStyle(); void makeFences(); - RefPtr<RenderStyle> makeOperatorStyle(); + UChar m_open; UChar m_close; RefPtr<StringImpl> m_separators; diff --git a/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp b/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp index aeaab20f7..dd59bb998 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp @@ -46,8 +46,8 @@ static const float gLineThick = 3.f; static const float gFractionBarWidth = 0.05f; static const float gDenominatorPad = 0.1f; -RenderMathMLFraction::RenderMathMLFraction(Element* fraction) - : RenderMathMLBlock(fraction) +RenderMathMLFraction::RenderMathMLFraction(Element* element) + : RenderMathMLBlock(element) , m_lineThickness(gLineMedium) { setChildrenInline(false); @@ -101,7 +101,7 @@ void RenderMathMLFraction::updateFromElement() void RenderMathMLFraction::addChild(RenderObject* child, RenderObject* beforeChild) { RenderBlock* row = new (renderArena()) RenderMathMLBlock(node()); - RefPtr<RenderStyle> rowStyle = makeBlockStyle(); + RefPtr<RenderStyle> rowStyle = createBlockStyle(); rowStyle->setTextAlign(CENTER); Length pad(static_cast<int>(rowStyle->fontSize() * gHorizontalPad), Fixed); @@ -119,6 +119,17 @@ void RenderMathMLFraction::addChild(RenderObject* child, RenderObject* beforeChi updateFromElement(); } +RenderMathMLOperator* RenderMathMLFraction::unembellishedOperator() +{ + RenderObject* numeratorWrapper = firstChild(); + if (!numeratorWrapper) + return 0; + RenderObject* numerator = numeratorWrapper->firstChild(); + if (!numerator || !numerator->isRenderMathMLBlock()) + return 0; + return toRenderMathMLBlock(numerator)->unembellishedOperator(); +} + void RenderMathMLFraction::layout() { updateFromElement(); @@ -153,7 +164,7 @@ void RenderMathMLFraction::paint(PaintInfo& info, const LayoutPoint& paintOffset verticalOffset = numerator->offsetHeight(); } - LayoutPoint adjustedPaintOffset = paintOffset + location(); + IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location()); adjustedPaintOffset.setY(adjustedPaintOffset.y() + verticalOffset); GraphicsContextStateSaver stateSaver(*info.context); diff --git a/Source/WebCore/rendering/mathml/RenderMathMLFraction.h b/Source/WebCore/rendering/mathml/RenderMathMLFraction.h index 3971a1e13..4756583b6 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLFraction.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLFraction.h @@ -35,15 +35,20 @@ namespace WebCore { class RenderMathMLFraction : public RenderMathMLBlock { public: - RenderMathMLFraction(Element* fraction); + RenderMathMLFraction(Element*); virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); virtual void updateFromElement(); + + virtual RenderMathMLOperator* unembellishedOperator(); + virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; virtual void paint(PaintInfo&, const LayoutPoint&); protected: virtual void layout(); + private: virtual const char* renderName() const { return "RenderMathMLFraction"; } + float m_lineThickness; }; diff --git a/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp b/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp index 006fea31c..15e2bbdbe 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLMath.cpp @@ -35,8 +35,8 @@ namespace WebCore { using namespace MathMLNames; -RenderMathMLMath::RenderMathMLMath(Node* math) - : RenderMathMLRow(math) +RenderMathMLMath::RenderMathMLMath(Element* element) + : RenderMathMLRow(element) { } diff --git a/Source/WebCore/rendering/mathml/RenderMathMLMath.h b/Source/WebCore/rendering/mathml/RenderMathMLMath.h index a81d5a890..aaa2f4f12 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLMath.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLMath.h @@ -34,7 +34,7 @@ namespace WebCore { class RenderMathMLMath : public RenderMathMLRow { public: - RenderMathMLMath(Node* container); + RenderMathMLMath(Element*); virtual bool isRenderMathMLMath() const { return true; } private: diff --git a/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp b/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp index 2702c0656..ad11d8bac 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp @@ -38,15 +38,15 @@ namespace WebCore { using namespace MathMLNames; -RenderMathMLOperator::RenderMathMLOperator(Node* container) - : RenderMathMLBlock(container) +RenderMathMLOperator::RenderMathMLOperator(Element* element) + : RenderMathMLBlock(element) , m_stretchHeight(0) , m_operator(0) { } -RenderMathMLOperator::RenderMathMLOperator(Node* container, UChar operatorChar) - : RenderMathMLBlock(container) +RenderMathMLOperator::RenderMathMLOperator(Node* node, UChar operatorChar) + : RenderMathMLBlock(node) , m_stretchHeight(0) , m_operator(convertHyphenMinusToMinusSign(operatorChar)) { @@ -139,7 +139,7 @@ void RenderMathMLOperator::updateFromElement() // This boolean indicates whether stretching is disabled via the markup. bool stretchDisabled = false; - // We made need the element later if we can't stretch. + // We may need the element later if we can't stretch. if (node()->nodeType() == Node::ELEMENT_NODE) { if (Element* mo = static_cast<Element*>(node())) { AtomicString stretchyAttr = mo->getAttribute(MathMLNames::stretchyAttr); @@ -282,7 +282,7 @@ void RenderMathMLOperator::updateFromElement() } } -RefPtr<RenderStyle> RenderMathMLOperator::createStackableStyle(int size, int topRelative) +PassRefPtr<RenderStyle> RenderMathMLOperator::createStackableStyle(int size, int topRelative) { RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); @@ -307,13 +307,13 @@ RefPtr<RenderStyle> RenderMathMLOperator::createStackableStyle(int size, int top newStyle->setPosition(RelativePosition); } - return newStyle; + return newStyle.release(); } RenderBlock* RenderMathMLOperator::createGlyph(UChar glyph, int size, int charRelative, int topRelative) { RenderBlock* container = new (renderArena()) RenderMathMLBlock(node()); - container->setStyle(createStackableStyle(size, topRelative).release()); + container->setStyle(createStackableStyle(size, topRelative)); addChild(container); RenderBlock* parent = container; if (charRelative) { diff --git a/Source/WebCore/rendering/mathml/RenderMathMLOperator.h b/Source/WebCore/rendering/mathml/RenderMathMLOperator.h index 5ee0660f5..42708724a 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLOperator.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLOperator.h @@ -35,9 +35,10 @@ namespace WebCore { class RenderMathMLOperator : public RenderMathMLBlock { public: - RenderMathMLOperator(Node* container); - RenderMathMLOperator(Node* container, UChar operatorChar); + RenderMathMLOperator(Element*); + RenderMathMLOperator(Node*, UChar operatorChar); virtual bool isRenderMathMLOperator() const { return true; } + virtual RenderMathMLOperator* unembellishedOperator() { return this; } virtual void stretchToHeight(int pixelHeight); virtual void updateFromElement(); virtual bool isChildAllowed(RenderObject*, RenderStyle*) const; @@ -45,7 +46,7 @@ public: protected: virtual void layout(); - virtual RefPtr<RenderStyle> createStackableStyle(int size, int topRelative); + virtual PassRefPtr<RenderStyle> createStackableStyle(int size, int topRelative); virtual RenderBlock* createGlyph(UChar glyph, int size = 0, int charRelative = 0, int topRelative = 0); private: diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp b/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp index 24e79ba7e..07e8ff911 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp @@ -64,8 +64,8 @@ const float gRadicalLineThickness = 0.02f; // Radical thick line thickness (%) const float gRadicalThickLineThickness = 0.1f; -RenderMathMLRoot::RenderMathMLRoot(Node *expression) -: RenderMathMLBlock(expression) +RenderMathMLRoot::RenderMathMLRoot(Element* element) + : RenderMathMLBlock(element) { } @@ -74,7 +74,7 @@ void RenderMathMLRoot::addChild(RenderObject* child, RenderObject* ) if (isEmpty()) { // Add a block for the index RenderBlock* block = new (renderArena()) RenderBlock(node()); - RefPtr<RenderStyle> indexStyle = makeBlockStyle(); + RefPtr<RenderStyle> indexStyle = createBlockStyle(); indexStyle->setDisplay(INLINE_BLOCK); block->setStyle(indexStyle.release()); RenderBlock::addChild(block); @@ -82,7 +82,7 @@ void RenderMathMLRoot::addChild(RenderObject* child, RenderObject* ) // FIXME: the wrapping does not seem to be needed anymore. // this is the base, so wrap it so we can pad it block = new (renderArena()) RenderBlock(node()); - RefPtr<RenderStyle> baseStyle = makeBlockStyle(); + RefPtr<RenderStyle> baseStyle = createBlockStyle(); baseStyle->setDisplay(INLINE_BLOCK); baseStyle->setPaddingLeft(Length(5 * gRadicalWidth , Percent)); block->setStyle(baseStyle.release()); @@ -104,7 +104,7 @@ void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset) if (!firstChild() || !lastChild()) return; - LayoutPoint adjustedPaintOffset = paintOffset + location(); + IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location()); RenderBoxModelObject* indexBox = toRenderBoxModelObject(lastChild()); @@ -232,7 +232,8 @@ void RenderMathMLRoot::layout() LayoutUnit indexShift = indexBox->offsetWidth() + topStartShift; LayoutUnit radicalHeight = static_cast<LayoutUnit>((1 - gRadicalTopLeftPointYPos) * maxHeight); - LayoutUnit rootMarginTop = radicalHeight + style()->paddingBottom().value() + indexBox->offsetHeight() - (maxHeight + static_cast<LayoutUnit>(gRootPadding * style()->fontSize())); + LayoutUnit rootMarginTop = radicalHeight + style()->paddingBottom().value() + indexBox->offsetHeight() + - (maxHeight + static_cast<LayoutUnit>(gRootPadding * style()->fontSize())); style()->setPaddingLeft(Length(indexShift, Fixed)); if (rootMarginTop > 0) diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRoot.h b/Source/WebCore/rendering/mathml/RenderMathMLRoot.h index ab3e4f057..19b2ec6ec 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLRoot.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLRoot.h @@ -34,7 +34,7 @@ namespace WebCore { class RenderMathMLRoot : public RenderMathMLBlock { public: - RenderMathMLRoot(Node* fraction); + RenderMathMLRoot(Element*); virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); virtual void paint(PaintInfo&, const LayoutPoint&); protected: diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp b/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp index 922fa9245..203d194de 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLRow.cpp @@ -36,57 +36,23 @@ namespace WebCore { using namespace MathMLNames; -RenderMathMLRow::RenderMathMLRow(Node* row) - : RenderMathMLBlock(row) +RenderMathMLRow::RenderMathMLRow(Element* element) + : RenderMathMLBlock(element) { } -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(); - // Check to see if this box has a larger height - if (blockHeight > maxHeight) - maxHeight = blockHeight; - } else if (current->isBoxModelObject()) { - RenderBoxModelObject* box = toRenderBoxModelObject(current); - // Check to see if this box has a larger height - if (box->offsetHeight() > maxHeight) - maxHeight = box->offsetHeight(); - } - - } - return maxHeight; -} - void RenderMathMLRow::layout() { RenderBlock::layout(); LayoutUnit maxHeight = 0; - int childCount = 0; - int operatorCount = 0; // Calculate the non-operator max height of the row. - LayoutUnit operatorHeight = 0; for (RenderObject* current = firstChild(); current; current = current->nextSibling()) { - childCount++; if (current->isRenderMathMLBlock()) { RenderMathMLBlock* block = toRenderMathMLBlock(current); - // Check to see if the non-operator block has a greater height. - if (!block->hasBase() && !block->isRenderMathMLOperator() && block->offsetHeight() > maxHeight) + if (!block->unembellishedOperator() && block->offsetHeight() > maxHeight) maxHeight = block->offsetHeight(); - if (block->hasBase() && block->nonOperatorHeight() > maxHeight) - maxHeight = block->nonOperatorHeight(); - // If the block is an operator, capture the maximum height and increment the count. - if (block->isRenderMathMLOperator()) { - if (block->offsetHeight() > operatorHeight) - operatorHeight = block->offsetHeight(); - operatorCount++; - } } else if (current->isBoxModelObject()) { RenderBoxModelObject* box = toRenderBoxModelObject(current); // Check to see if this box has a larger height. @@ -95,10 +61,8 @@ void RenderMathMLRow::layout() } } - if (childCount > 0 && childCount == operatorCount) { - // We have only operators and so set the max height to the operator height. - maxHeight = operatorHeight; - } + if (!maxHeight) + maxHeight = style()->fontSize(); // Stretch everything to the same height (blocks can ignore the request). if (maxHeight > 0) { @@ -118,17 +82,6 @@ void RenderMathMLRow::layout() } } - -LayoutUnit 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); -} } diff --git a/Source/WebCore/rendering/mathml/RenderMathMLRow.h b/Source/WebCore/rendering/mathml/RenderMathMLRow.h index 73c5a26e5..2a520d07b 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLRow.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLRow.h @@ -34,10 +34,8 @@ namespace WebCore { class RenderMathMLRow : public RenderMathMLBlock { public: - RenderMathMLRow(Node* container); + RenderMathMLRow(Element*); virtual bool isRenderMathMLRow() const { return true; } - virtual int nonOperatorHeight() const; - virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; virtual void stretchToHeight(int) {} protected: virtual void layout(); diff --git a/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp b/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp index 38ab1c1c0..206426a13 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp @@ -61,8 +61,8 @@ const float gRadicalLineThickness = 0.02f; // Radical thick line thickness (%) const float gRadicalThickLineThickness = 0.1f; -RenderMathMLSquareRoot::RenderMathMLSquareRoot(Node *expression) - : RenderMathMLBlock(expression) +RenderMathMLSquareRoot::RenderMathMLSquareRoot(Element* element) + : RenderMathMLBlock(element) { } @@ -73,7 +73,7 @@ void RenderMathMLSquareRoot::paint(PaintInfo& info, const LayoutPoint& paintOffs if (info.context->paintingDisabled()) return; - LayoutPoint adjustedPaintOffset = paintOffset + location(); + IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location()); LayoutUnit maxHeight = 0; LayoutUnit width = 0; diff --git a/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h b/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h index c8e41cdfb..ad81fdc56 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h @@ -34,7 +34,7 @@ namespace WebCore { class RenderMathMLSquareRoot : public RenderMathMLBlock { public: - RenderMathMLSquareRoot(Node* fraction); + RenderMathMLSquareRoot(Element*); virtual void paint(PaintInfo&, const LayoutPoint&); protected: virtual void layout(); 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(); } } diff --git a/Source/WebCore/rendering/mathml/RenderMathMLSubSup.h b/Source/WebCore/rendering/mathml/RenderMathMLSubSup.h index 2ba466cb4..9c7d02c89 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLSubSup.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLSubSup.h @@ -34,10 +34,10 @@ namespace WebCore { class RenderMathMLSubSup : public RenderMathMLBlock { public: - RenderMathMLSubSup(Element* fraction); + RenderMathMLSubSup(Element*); virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); - virtual bool hasBase() const { return true; } - virtual int nonOperatorHeight() const; + + virtual RenderMathMLOperator* unembellishedOperator(); virtual void stretchToHeight(int pixelHeight); virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; @@ -47,6 +47,10 @@ protected: private: virtual const char* renderName() const { return "RenderMathMLSubSup"; } + // Omit our subscript and/or superscript. This may return 0 for a non-MathML base (which + // won't occur in valid MathML). + RenderBoxModelObject* base() const; + enum SubSupType { Sub, Sup, SubSup }; SubSupType m_kind; RenderBlock* m_scripts; @@ -57,4 +61,3 @@ private: #endif // ENABLE(MATHML) #endif // RenderMathMLSubSup_h - diff --git a/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp b/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp index 75911036a..0621cd6dd 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp +++ b/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp @@ -38,27 +38,37 @@ using namespace MathMLNames; static const double gOverSpacingAdjustment = 0.5; -RenderMathMLUnderOver::RenderMathMLUnderOver(Node* expression) - : RenderMathMLBlock(expression) +RenderMathMLUnderOver::RenderMathMLUnderOver(Element* element) + : RenderMathMLBlock(element) { - Element* element = static_cast<Element*>(expression); // Determine what kind of under/over expression we have by element name - if (element->hasLocalName(MathMLNames::munderTag)) m_kind = Under; else if (element->hasLocalName(MathMLNames::moverTag)) m_kind = Over; - else if (element->hasLocalName(MathMLNames::munderoverTag)) + else { + ASSERT(element->hasLocalName(MathMLNames::munderoverTag)); m_kind = UnderOver; - else - m_kind = Under; - + } +} + +RenderBoxModelObject* RenderMathMLUnderOver::base() const +{ + RenderObject* baseWrapper = firstChild(); + if ((m_kind == Over || m_kind == UnderOver) && baseWrapper) + baseWrapper = baseWrapper->nextSibling(); + if (!baseWrapper) + return 0; + RenderObject* base = baseWrapper->firstChild(); + if (!base || !base->isBoxModelObject()) + return 0; + return toRenderBoxModelObject(base); } void RenderMathMLUnderOver::addChild(RenderObject* child, RenderObject* beforeChild) { RenderMathMLBlock* row = new (renderArena()) RenderMathMLBlock(node()); - RefPtr<RenderStyle> rowStyle = makeBlockStyle(); + RefPtr<RenderStyle> rowStyle = createBlockStyle(); row->setStyle(rowStyle.release()); row->setIsAnonymous(true); @@ -109,6 +119,14 @@ void RenderMathMLUnderOver::addChild(RenderObject* child, RenderObject* beforeCh row->addChild(child); } +RenderMathMLOperator* RenderMathMLUnderOver::unembellishedOperator() +{ + RenderBoxModelObject* base = this->base(); + if (!base || !base->isRenderMathMLBlock()) + return 0; + return toRenderMathMLBlock(base)->unembellishedOperator(); +} + inline int getOffsetHeight(RenderObject* obj) { if (obj->isBoxModelObject()) { @@ -121,21 +139,7 @@ inline int getOffsetHeight(RenderObject* obj) void RenderMathMLUnderOver::stretchToHeight(int height) { - - RenderObject* base = firstChild(); - if (!base) - return; - - // For over or underover, the base is the sibling of the first child - if (m_kind != Under) - base = base->nextSibling(); - - if (!base) - return; - - // use the child of the row which is the actual base - base = base->firstChild(); - + RenderBoxModelObject* base = this->base(); if (base && base->isRenderMathMLBlock()) { RenderMathMLBlock* block = toRenderMathMLBlock(base); block->stretchToHeight(height); @@ -275,21 +279,6 @@ LayoutUnit RenderMathMLUnderOver::baselinePosition(FontBaseline, bool firstLine, return baseline; } - -int RenderMathMLUnderOver::nonOperatorHeight() const -{ - int nonOperators = 0; - for (RenderObject* current = firstChild(); current; current = current->nextSibling()) { - if (current->firstChild() && current->firstChild()->isRenderMathMLBlock()) { - RenderMathMLBlock* block = toRenderMathMLBlock(current->firstChild()); - if (!block->isRenderMathMLOperator()) - nonOperators += getOffsetHeight(current); - } else - nonOperators += getOffsetHeight(current); - } - return nonOperators; -} - } #endif // ENABLE(MATHML) diff --git a/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h b/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h index 2fe619821..e25e94768 100644 --- a/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h +++ b/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h @@ -34,16 +34,21 @@ namespace WebCore { class RenderMathMLUnderOver : public RenderMathMLBlock { public: - RenderMathMLUnderOver(Node* expression); + RenderMathMLUnderOver(Element*); virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0); + + virtual RenderMathMLOperator* unembellishedOperator(); virtual void layout(); - virtual bool hasBase() const { return true; } - virtual int nonOperatorHeight() const; virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; virtual void stretchToHeight(int pixelHeight); + private: virtual const char* renderName() const { return "RenderMathMLUnderOver"; } + // Omit our underscript and/or overscript. This may return 0 for a non-MathML base (which + // won't occur in valid MathML). + RenderBoxModelObject* base() const; + enum UnderOverType { Under, Over, UnderOver }; UnderOverType m_kind; }; |