Modernize RenderSVGText::locateRenderSVGTextAncestor().
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 05:04:57 +0000 (05:04 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 05:04:57 +0000 (05:04 +0000)
<https://webkit.org/b/128093>

Make locateRenderSVGTextAncestor() take a reference, and simplify it
internally with lineageOfType.

Switched callers to use 'auto' for the return type so we get some
devirtualization freebies.

Reviewed by Anders Carlsson.

* rendering/svg/RenderSVGInline.cpp:
(WebCore::RenderSVGInline::objectBoundingBox):
(WebCore::RenderSVGInline::strokeBoundingBox):
(WebCore::RenderSVGInline::repaintRectInLocalCoordinates):
(WebCore::RenderSVGInline::absoluteQuads):
(WebCore::RenderSVGInline::addChild):
(WebCore::RenderSVGInline::removeChild):
* rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::setTextInternal):
(WebCore::RenderSVGInlineText::styleDidChange):
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::createMaskAndSwapContextForTextGradient):
(WebCore::clipToTextMask):
* rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::locateRenderSVGTextAncestor):
* rendering/svg/RenderSVGText.h:
(WebCore::RenderSVGText>):
* rendering/svg/SVGTextLayoutAttributesBuilder.cpp:
(WebCore::SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer):
* rendering/svg/SVGTextMetricsBuilder.cpp:
(WebCore::SVGTextMetricsBuilder::measureTextRenderer):
* svg/SVGTextPositioningElement.cpp:
(WebCore::SVGTextPositioningElement::svgAttributeChanged):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163285 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/svg/RenderSVGInline.cpp
Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp
Source/WebCore/rendering/svg/RenderSVGText.cpp
Source/WebCore/rendering/svg/RenderSVGText.h
Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp
Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp
Source/WebCore/svg/SVGTextPositioningElement.cpp

index 00cf9bb..f6cc44d 100644 (file)
@@ -1,5 +1,42 @@
 2014-02-02  Andreas Kling  <akling@apple.com>
 
+        Modernize RenderSVGText::locateRenderSVGTextAncestor().
+        <https://webkit.org/b/128093>
+
+        Make locateRenderSVGTextAncestor() take a reference, and simplify it
+        internally with lineageOfType.
+
+        Switched callers to use 'auto' for the return type so we get some
+        devirtualization freebies.
+
+        Reviewed by Anders Carlsson.
+
+        * rendering/svg/RenderSVGInline.cpp:
+        (WebCore::RenderSVGInline::objectBoundingBox):
+        (WebCore::RenderSVGInline::strokeBoundingBox):
+        (WebCore::RenderSVGInline::repaintRectInLocalCoordinates):
+        (WebCore::RenderSVGInline::absoluteQuads):
+        (WebCore::RenderSVGInline::addChild):
+        (WebCore::RenderSVGInline::removeChild):
+        * rendering/svg/RenderSVGInlineText.cpp:
+        (WebCore::RenderSVGInlineText::setTextInternal):
+        (WebCore::RenderSVGInlineText::styleDidChange):
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::createMaskAndSwapContextForTextGradient):
+        (WebCore::clipToTextMask):
+        * rendering/svg/RenderSVGText.cpp:
+        (WebCore::RenderSVGText::locateRenderSVGTextAncestor):
+        * rendering/svg/RenderSVGText.h:
+        (WebCore::RenderSVGText>):
+        * rendering/svg/SVGTextLayoutAttributesBuilder.cpp:
+        (WebCore::SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer):
+        * rendering/svg/SVGTextMetricsBuilder.cpp:
+        (WebCore::SVGTextMetricsBuilder::measureTextRenderer):
+        * svg/SVGTextPositioningElement.cpp:
+        (WebCore::SVGTextPositioningElement::svgAttributeChanged):
+
+2014-02-02  Andreas Kling  <akling@apple.com>
+
         Modernize the toRenderSVGResourceContainer() helper.
         <https://webkit.org/b/128091>
 
index f1f384e..490771d 100644 (file)
@@ -47,24 +47,24 @@ std::unique_ptr<InlineFlowBox> RenderSVGInline::createInlineFlowBox()
 
 FloatRect RenderSVGInline::objectBoundingBox() const
 {
-    if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
-        return object->objectBoundingBox();
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        return textAncestor->objectBoundingBox();
 
     return FloatRect();
 }
 
 FloatRect RenderSVGInline::strokeBoundingBox() const
 {
-    if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
-        return object->strokeBoundingBox();
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        return textAncestor->strokeBoundingBox();
 
     return FloatRect();
 }
 
 FloatRect RenderSVGInline::repaintRectInLocalCoordinates() const
 {
-    if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
-        return object->repaintRectInLocalCoordinates();
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        return textAncestor->repaintRectInLocalCoordinates();
 
     return FloatRect();
 }
@@ -91,11 +91,11 @@ const RenderObject* RenderSVGInline::pushMappingToContainer(const RenderLayerMod
 
 void RenderSVGInline::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
 {
-    const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this);
-    if (!object)
+    auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
+    if (!textAncestor)
         return;
 
-    FloatRect textBoundingBox = object->strokeBoundingBox();
+    FloatRect textBoundingBox = textAncestor->strokeBoundingBox();
     for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
         quads.append(localToAbsoluteQuad(FloatRect(textBoundingBox.x() + box->x(), textBoundingBox.y() + box->y(), box->logicalWidth(), box->logicalHeight()), false, wasFixed));
 }
@@ -119,23 +119,23 @@ void RenderSVGInline::addChild(RenderObject* child, RenderObject* beforeChild)
     RenderInline::addChild(child, beforeChild);
     SVGResourcesCache::clientWasAddedToTree(*child);
 
-    if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
-        textRenderer->subtreeChildWasAdded(child);
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        textAncestor->subtreeChildWasAdded(child);
 }
 
 void RenderSVGInline::removeChild(RenderObject& child)
 {
     SVGResourcesCache::clientWillBeRemovedFromTree(child);
 
-    RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this);
-    if (!textRenderer) {
+    auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
+    if (!textAncestor) {
         RenderInline::removeChild(child);
         return;
     }
     Vector<SVGTextLayoutAttributes*, 2> affectedAttributes;
-    textRenderer->subtreeChildWillBeRemoved(&child, affectedAttributes);
+    textAncestor->subtreeChildWillBeRemoved(&child, affectedAttributes);
     RenderInline::removeChild(child);
-    textRenderer->subtreeChildWasRemoved(affectedAttributes);
+    textAncestor->subtreeChildWasRemoved(affectedAttributes);
 }
 
 }
index afa18aa..17419bc 100644 (file)
@@ -82,8 +82,8 @@ String RenderSVGInlineText::originalText() const
 void RenderSVGInlineText::setTextInternal(const String& text)
 {
     RenderText::setTextInternal(text);
-    if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
-        textRenderer->subtreeTextDidChange(this);
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        textAncestor->subtreeTextDidChange(this);
 }
 
 void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
@@ -107,8 +107,8 @@ void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle
         return;
 
     // The text metrics may be influenced by style changes.
-    if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
-        textRenderer->subtreeStyleDidChange(this);
+    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
+        textAncestor->subtreeStyleDidChange(this);
 }
 
 std::unique_ptr<InlineTextBox> RenderSVGInlineText::createTextBox()
index 6639dff..43263e7 100644 (file)
@@ -57,7 +57,7 @@ void RenderSVGResourceGradient::removeClientFromCache(RenderObject& client, bool
 #if USE(CG)
 static inline bool createMaskAndSwapContextForTextGradient(GraphicsContext*& context, GraphicsContext*& savedContext, std::unique_ptr<ImageBuffer>& imageBuffer, RenderObject* object)
 {
-    RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
+    auto* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(*object);
     ASSERT(textRootBlock);
 
     AffineTransform absoluteTransform;
@@ -79,7 +79,7 @@ static inline bool createMaskAndSwapContextForTextGradient(GraphicsContext*& con
 
 static inline AffineTransform clipToTextMask(GraphicsContext* context, std::unique_ptr<ImageBuffer>& imageBuffer, FloatRect& targetRect, RenderObject* object, bool boundingBoxMode, const AffineTransform& gradientTransform)
 {
-    RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
+    auto* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(*object);
     ASSERT(textRootBlock);
 
     AffineTransform absoluteTransform;
index 22c1cda..22e0954 100644 (file)
@@ -36,6 +36,7 @@
 #include "HitTestResult.h"
 #include "LayoutRepainter.h"
 #include "PointerEventsHitRules.h"
+#include "RenderIterator.h"
 #include "RenderSVGInlineText.h"
 #include "RenderSVGResource.h"
 #include "RenderSVGRoot.h"
@@ -77,24 +78,14 @@ bool RenderSVGText::isChildAllowed(const RenderObject& child, const RenderStyle&
     return child.isInline();
 }
 
-RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(RenderObject* start)
+RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(RenderObject& start)
 {
-    ASSERT(start);
-    while (start && !start->isSVGText())
-        start = start->parent();
-    if (!start || !start->isSVGText())
-        return 0;
-    return toRenderSVGText(start);
+    return lineageOfType<RenderSVGText>(start).first();
 }
 
-const RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(const RenderObject* start)
+const RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(const RenderObject& start)
 {
-    ASSERT(start);
-    while (start && !start->isSVGText())
-        start = start->parent();
-    if (!start || !start->isSVGText())
-        return 0;
-    return toRenderSVGText(start);
+    return lineageOfType<RenderSVGText>(start).first();
 }
 
 LayoutRect RenderSVGText::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
index 93ac442..01b9a0f 100644 (file)
@@ -47,8 +47,8 @@ public:
     void setNeedsTextMetricsUpdate() { m_needsTextMetricsUpdate = true; }
     virtual FloatRect repaintRectInLocalCoordinates() const;
 
-    static RenderSVGText* locateRenderSVGTextAncestor(RenderObject*);
-    static const RenderSVGText* locateRenderSVGTextAncestor(const RenderObject*);
+    static RenderSVGText* locateRenderSVGTextAncestor(RenderObject&);
+    static const RenderSVGText* locateRenderSVGTextAncestor(const RenderObject&);
 
     bool needsReordering() const { return m_needsReordering; }
     Vector<SVGTextLayoutAttributes*>& layoutAttributes() { return m_layoutAttributes; }
@@ -59,6 +59,9 @@ public:
     void subtreeStyleDidChange(RenderSVGInlineText*);
     void subtreeTextDidChange(RenderSVGInlineText*);
 
+    virtual FloatRect objectBoundingBox() const override { return frameRect(); }
+    virtual FloatRect strokeBoundingBox() const override;
+
 private:
     void graphicsElement() const = delete;
 
@@ -85,9 +88,6 @@ private:
     virtual void removeChild(RenderObject&) override;
     virtual void willBeDestroyed() override;
 
-    virtual FloatRect objectBoundingBox() const { return frameRect(); }
-    virtual FloatRect strokeBoundingBox() const;
-
     virtual const AffineTransform& localToParentTransform() const { return m_localTransform; }
     virtual AffineTransform localTransform() const { return m_localTransform; }
     virtual std::unique_ptr<RootInlineBox> createRootInlineBox() override;
@@ -106,6 +106,7 @@ private:
     Vector<SVGTextLayoutAttributes*> m_layoutAttributes;
 };
 
+template<> inline bool isRendererOfType<const RenderSVGText>(const RenderObject& renderer) { return renderer.isSVGText(); }
 RENDER_OBJECT_TYPE_CASTS(RenderSVGText, isSVGText())
 
 }
index 6528a96..572db82 100644 (file)
@@ -35,7 +35,7 @@ SVGTextLayoutAttributesBuilder::SVGTextLayoutAttributesBuilder()
 
 void SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer(RenderSVGInlineText& text)
 {
-    RenderSVGText* textRoot = RenderSVGText::locateRenderSVGTextAncestor(&text);
+    auto* textRoot = RenderSVGText::locateRenderSVGTextAncestor(text);
     if (!textRoot)
         return;
 
index 86009e6..17344e8 100644 (file)
@@ -207,7 +207,7 @@ void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text)
 {
     ASSERT(text);
 
-    RenderSVGText* textRoot = RenderSVGText::locateRenderSVGTextAncestor(text);
+    auto* textRoot = RenderSVGText::locateRenderSVGTextAncestor(*text);
     if (!textRoot)
         return;
 
index 82e7063..403869c 100644 (file)
@@ -140,8 +140,8 @@ void SVGTextPositioningElement::svgAttributeChanged(const QualifiedName& attrNam
         return;
 
     if (updateRelativeLengths || attrName == SVGNames::rotateAttr) {
-        if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(renderer))
-            textRenderer->setNeedsPositioningValuesUpdate();
+        if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*renderer))
+            textAncestor->setNeedsPositioningValuesUpdate();
         RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
         return;
     }