Changeset 163285 in webkit


Ignore:
Timestamp:
Feb 2, 2014 9:04:57 PM (10 years ago)
Author:
akling@apple.com
Message:

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):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r163283 r163285  
     12014-02-02  Andreas Kling  <akling@apple.com>
     2
     3        Modernize RenderSVGText::locateRenderSVGTextAncestor().
     4        <https://webkit.org/b/128093>
     5
     6        Make locateRenderSVGTextAncestor() take a reference, and simplify it
     7        internally with lineageOfType.
     8
     9        Switched callers to use 'auto' for the return type so we get some
     10        devirtualization freebies.
     11
     12        Reviewed by Anders Carlsson.
     13
     14        * rendering/svg/RenderSVGInline.cpp:
     15        (WebCore::RenderSVGInline::objectBoundingBox):
     16        (WebCore::RenderSVGInline::strokeBoundingBox):
     17        (WebCore::RenderSVGInline::repaintRectInLocalCoordinates):
     18        (WebCore::RenderSVGInline::absoluteQuads):
     19        (WebCore::RenderSVGInline::addChild):
     20        (WebCore::RenderSVGInline::removeChild):
     21        * rendering/svg/RenderSVGInlineText.cpp:
     22        (WebCore::RenderSVGInlineText::setTextInternal):
     23        (WebCore::RenderSVGInlineText::styleDidChange):
     24        * rendering/svg/RenderSVGResourceGradient.cpp:
     25        (WebCore::createMaskAndSwapContextForTextGradient):
     26        (WebCore::clipToTextMask):
     27        * rendering/svg/RenderSVGText.cpp:
     28        (WebCore::RenderSVGText::locateRenderSVGTextAncestor):
     29        * rendering/svg/RenderSVGText.h:
     30        (WebCore::RenderSVGText>):
     31        * rendering/svg/SVGTextLayoutAttributesBuilder.cpp:
     32        (WebCore::SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer):
     33        * rendering/svg/SVGTextMetricsBuilder.cpp:
     34        (WebCore::SVGTextMetricsBuilder::measureTextRenderer):
     35        * svg/SVGTextPositioningElement.cpp:
     36        (WebCore::SVGTextPositioningElement::svgAttributeChanged):
     37
    1382014-02-02  Andreas Kling  <akling@apple.com>
    239
  • trunk/Source/WebCore/rendering/svg/RenderSVGInline.cpp

    r158999 r163285  
    4848FloatRect RenderSVGInline::objectBoundingBox() const
    4949{
    50     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
    51         return object->objectBoundingBox();
     50    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     51        return textAncestor->objectBoundingBox();
    5252
    5353    return FloatRect();
     
    5656FloatRect RenderSVGInline::strokeBoundingBox() const
    5757{
    58     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
    59         return object->strokeBoundingBox();
     58    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     59        return textAncestor->strokeBoundingBox();
    6060
    6161    return FloatRect();
     
    6464FloatRect RenderSVGInline::repaintRectInLocalCoordinates() const
    6565{
    66     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
    67         return object->repaintRectInLocalCoordinates();
     66    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     67        return textAncestor->repaintRectInLocalCoordinates();
    6868
    6969    return FloatRect();
     
    9292void RenderSVGInline::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
    9393{
    94     const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this);
    95     if (!object)
     94    auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
     95    if (!textAncestor)
    9696        return;
    9797
    98     FloatRect textBoundingBox = object->strokeBoundingBox();
     98    FloatRect textBoundingBox = textAncestor->strokeBoundingBox();
    9999    for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
    100100        quads.append(localToAbsoluteQuad(FloatRect(textBoundingBox.x() + box->x(), textBoundingBox.y() + box->y(), box->logicalWidth(), box->logicalHeight()), false, wasFixed));
     
    120120    SVGResourcesCache::clientWasAddedToTree(*child);
    121121
    122     if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
    123         textRenderer->subtreeChildWasAdded(child);
     122    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     123        textAncestor->subtreeChildWasAdded(child);
    124124}
    125125
     
    128128    SVGResourcesCache::clientWillBeRemovedFromTree(child);
    129129
    130     RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this);
    131     if (!textRenderer) {
     130    auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
     131    if (!textAncestor) {
    132132        RenderInline::removeChild(child);
    133133        return;
    134134    }
    135135    Vector<SVGTextLayoutAttributes*, 2> affectedAttributes;
    136     textRenderer->subtreeChildWillBeRemoved(&child, affectedAttributes);
     136    textAncestor->subtreeChildWillBeRemoved(&child, affectedAttributes);
    137137    RenderInline::removeChild(child);
    138     textRenderer->subtreeChildWasRemoved(affectedAttributes);
     138    textAncestor->subtreeChildWasRemoved(affectedAttributes);
    139139}
    140140
  • trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp

    r163276 r163285  
    8383{
    8484    RenderText::setTextInternal(text);
    85     if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
    86         textRenderer->subtreeTextDidChange(this);
     85    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     86        textAncestor->subtreeTextDidChange(this);
    8787}
    8888
     
    108108
    109109    // The text metrics may be influenced by style changes.
    110     if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
    111         textRenderer->subtreeStyleDidChange(this);
     110    if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
     111        textAncestor->subtreeStyleDidChange(this);
    112112}
    113113
  • trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp

    r163276 r163285  
    5858static inline bool createMaskAndSwapContextForTextGradient(GraphicsContext*& context, GraphicsContext*& savedContext, std::unique_ptr<ImageBuffer>& imageBuffer, RenderObject* object)
    5959{
    60     RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
     60    auto* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(*object);
    6161    ASSERT(textRootBlock);
    6262
     
    8080static inline AffineTransform clipToTextMask(GraphicsContext* context, std::unique_ptr<ImageBuffer>& imageBuffer, FloatRect& targetRect, RenderObject* object, bool boundingBoxMode, const AffineTransform& gradientTransform)
    8181{
    82     RenderObject* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(object);
     82    auto* textRootBlock = RenderSVGText::locateRenderSVGTextAncestor(*object);
    8383    ASSERT(textRootBlock);
    8484
  • trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp

    r161630 r163285  
    3737#include "LayoutRepainter.h"
    3838#include "PointerEventsHitRules.h"
     39#include "RenderIterator.h"
    3940#include "RenderSVGInlineText.h"
    4041#include "RenderSVGResource.h"
     
    7879}
    7980
    80 RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(RenderObject* start)
    81 {
    82     ASSERT(start);
    83     while (start && !start->isSVGText())
    84         start = start->parent();
    85     if (!start || !start->isSVGText())
    86         return 0;
    87     return toRenderSVGText(start);
    88 }
    89 
    90 const RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(const RenderObject* start)
    91 {
    92     ASSERT(start);
    93     while (start && !start->isSVGText())
    94         start = start->parent();
    95     if (!start || !start->isSVGText())
    96         return 0;
    97     return toRenderSVGText(start);
     81RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(RenderObject& start)
     82{
     83    return lineageOfType<RenderSVGText>(start).first();
     84}
     85
     86const RenderSVGText* RenderSVGText::locateRenderSVGTextAncestor(const RenderObject& start)
     87{
     88    return lineageOfType<RenderSVGText>(start).first();
    9889}
    9990
  • trunk/Source/WebCore/rendering/svg/RenderSVGText.h

    r162198 r163285  
    4848    virtual FloatRect repaintRectInLocalCoordinates() const;
    4949
    50     static RenderSVGText* locateRenderSVGTextAncestor(RenderObject*);
    51     static const RenderSVGText* locateRenderSVGTextAncestor(const RenderObject*);
     50    static RenderSVGText* locateRenderSVGTextAncestor(RenderObject&);
     51    static const RenderSVGText* locateRenderSVGTextAncestor(const RenderObject&);
    5252
    5353    bool needsReordering() const { return m_needsReordering; }
     
    5959    void subtreeStyleDidChange(RenderSVGInlineText*);
    6060    void subtreeTextDidChange(RenderSVGInlineText*);
     61
     62    virtual FloatRect objectBoundingBox() const override { return frameRect(); }
     63    virtual FloatRect strokeBoundingBox() const override;
    6164
    6265private:
     
    8689    virtual void willBeDestroyed() override;
    8790
    88     virtual FloatRect objectBoundingBox() const { return frameRect(); }
    89     virtual FloatRect strokeBoundingBox() const;
    90 
    9191    virtual const AffineTransform& localToParentTransform() const { return m_localTransform; }
    9292    virtual AffineTransform localTransform() const { return m_localTransform; }
     
    107107};
    108108
     109template<> inline bool isRendererOfType<const RenderSVGText>(const RenderObject& renderer) { return renderer.isSVGText(); }
    109110RENDER_OBJECT_TYPE_CASTS(RenderSVGText, isSVGText())
    110111
  • trunk/Source/WebCore/rendering/svg/SVGTextLayoutAttributesBuilder.cpp

    r163248 r163285  
    3636void SVGTextLayoutAttributesBuilder::buildLayoutAttributesForTextRenderer(RenderSVGInlineText& text)
    3737{
    38     RenderSVGText* textRoot = RenderSVGText::locateRenderSVGTextAncestor(&text);
     38    auto* textRoot = RenderSVGText::locateRenderSVGTextAncestor(text);
    3939    if (!textRoot)
    4040        return;
  • trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp

    r161851 r163285  
    208208    ASSERT(text);
    209209
    210     RenderSVGText* textRoot = RenderSVGText::locateRenderSVGTextAncestor(text);
     210    auto* textRoot = RenderSVGText::locateRenderSVGTextAncestor(*text);
    211211    if (!textRoot)
    212212        return;
  • trunk/Source/WebCore/svg/SVGTextPositioningElement.cpp

    r160651 r163285  
    141141
    142142    if (updateRelativeLengths || attrName == SVGNames::rotateAttr) {
    143         if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(renderer))
    144             textRenderer->setNeedsPositioningValuesUpdate();
     143        if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*renderer))
     144            textAncestor->setNeedsPositioningValuesUpdate();
    145145        RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
    146146        return;
Note: See TracChangeset for help on using the changeset viewer.