Use lineageOfType to simplify two rendering helpers.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Jan 2014 11:45:54 +0000 (11:45 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Jan 2014 11:45:54 +0000 (11:45 +0000)
<https://webkit.org/b/126498>

Reviewed by Antti Koivisto.

* rendering/RenderRuby.cpp:
(WebCore::findRubyRunParent):
* rendering/svg/SVGRenderSupport.cpp:
(WebCore::SVGRenderSupport::findTreeRootObject):

    Simplify two functions that walk their parent chain to find the
    closest ancestor of a certain type.

* rendering/RenderRubyRun.h:

    Add requisite isRendererOfType<RenderRubyRun>().

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderRuby.cpp
Source/WebCore/rendering/RenderRubyRun.h
Source/WebCore/rendering/svg/SVGRenderSupport.cpp

index 10b3a0bd2825e16a2f1c8cd9623aa93f54ee67f4..47c292ef981d5118e46e2abbae312adf5bdbc861 100644 (file)
@@ -1,3 +1,22 @@
+2014-01-05  Andreas Kling  <akling@apple.com>
+
+        Use lineageOfType to simplify two rendering helpers.
+        <https://webkit.org/b/126498>
+
+        Reviewed by Antti Koivisto.
+
+        * rendering/RenderRuby.cpp:
+        (WebCore::findRubyRunParent):
+        * rendering/svg/SVGRenderSupport.cpp:
+        (WebCore::SVGRenderSupport::findTreeRootObject):
+
+            Simplify two functions that walk their parent chain to find the
+            closest ancestor of a certain type.
+
+        * rendering/RenderRubyRun.h:
+
+            Add requisite isRendererOfType<RenderRubyRun>().
+
 2014-01-05  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Fix the Mac build too.
index 9facf6fb6fb7455e08b01e54a52085eab35b30f6..f0344ca6aa51becec2d1c570e0dda523961c2430 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "RenderRuby.h"
 
+#include "RenderIterator.h"
 #include "RenderRubyRun.h"
 #include "RenderStyle.h"
 #include "StyleInheritedData.h"
@@ -101,11 +102,7 @@ static RenderRubyRun* lastRubyRun(const RenderElement* ruby)
 
 static inline RenderRubyRun& findRubyRunParent(RenderObject& child)
 {
-    RenderObject* ancestor = &child;
-    while (ancestor && !ancestor->isRubyRun())
-        ancestor = ancestor->parent();
-    ASSERT(ancestor);
-    return toRenderRubyRun(*ancestor);
+    return *lineageOfType<RenderRubyRun>(child).first();
 }
 
 //=== ruby as inline object ===
index 3e6456f12b10c1f605f7ace62e4cc170a324cd44..1c660acebc32e6f5a55bdf4952e1b8a1a7dba28e 100644 (file)
@@ -77,6 +77,8 @@ private:
     virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
 };
 
+template<> inline bool isRendererOfType<const RenderRubyRun>(const RenderObject& renderer) { return renderer.isRubyRun(); }
+
 RENDER_OBJECT_TYPE_CASTS(RenderRubyRun, isRubyRun())
 
 } // namespace WebCore
index 1d3f4718dcfc2b110e43a723254fe5a724f277bf..c49fc6f16bc254ca1f743893da267bc90ddfd42c 100644 (file)
@@ -28,7 +28,9 @@
 #include "SVGRenderSupport.h"
 
 #include "NodeRenderStyle.h"
+#include "RenderElement.h"
 #include "RenderGeometryMap.h"
+#include "RenderIterator.h"
 #include "RenderLayer.h"
 #include "RenderSVGResource.h"
 #include "RenderSVGResourceClipper.h"
@@ -182,12 +184,7 @@ bool SVGRenderSupport::paintInfoIntersectsRepaintRect(const FloatRect& localRepa
 
 const RenderSVGRoot& SVGRenderSupport::findTreeRootObject(const RenderElement& start)
 {
-    auto renderer = &start;
-    while (renderer && !renderer->isSVGRoot())
-        renderer = renderer->parent();
-
-    ASSERT(renderer);
-    return toRenderSVGRoot(*renderer);
+    return *lineageOfType<RenderSVGRoot>(start).first();
 }
 
 static inline void invalidateResourcesOfChildren(RenderObject& start)