<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[200994] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/200994">200994</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-05-16 21:11:34 -0700 (Mon, 16 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add RenderDescendantIterator to traverse a RenderObject's descendants
https://bugs.webkit.org/show_bug.cgi?id=157785
Reviewed by Zalan Bujtas.
Add RenderDescendantIterator to traverse a RenderObject's descendants. I
am planning to use it in the iOS Text Autosizing code (See Bug 157784).
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderDescendantIterator.h: Added.
(WebCore::RenderDescendantIterator<T>::RenderDescendantIterator):
(WebCore::RenderDescendantIterator<T>::operator):
(WebCore::RenderDescendantConstIterator<T>::RenderDescendantConstIterator):
(WebCore::RenderDescendantConstIterator<T>::operator):
(WebCore::RenderDescendantIteratorAdapter<T>::RenderDescendantIteratorAdapter):
(WebCore::RenderDescendantIteratorAdapter<T>::begin):
(WebCore::RenderDescendantIteratorAdapter<T>::end):
(WebCore::RenderDescendantConstIteratorAdapter<T>::RenderDescendantConstIteratorAdapter):
(WebCore::RenderDescendantConstIteratorAdapter<T>::begin):
(WebCore::RenderDescendantConstIteratorAdapter<T>::end):
(WebCore::descendantsOfType):
* rendering/RenderIterator.h:
(WebCore::RenderObjectTraversal::firstChild):
(WebCore::RenderObjectTraversal::nextAncestorSibling):
(WebCore::RenderObjectTraversal::next):
(WebCore::RenderTraversal::firstChild):
(WebCore::RenderTraversal::lastChild):
(WebCore::RenderTraversal::nextSibling):
(WebCore::RenderTraversal::previousSibling):
(WebCore::RenderTraversal::findAncestorOfType):
(WebCore::RenderTraversal::firstWithin):
(WebCore::RenderTraversal::next):
(WebCore::RenderIterator<T>::traverseNext):
(WebCore::RenderConstIterator<T>::traverseNext):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderIteratorh">trunk/Source/WebCore/rendering/RenderIterator.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorerenderingRenderDescendantIteratorh">trunk/Source/WebCore/rendering/RenderDescendantIterator.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200993 => 200994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-17 04:02:40 UTC (rev 200993)
+++ trunk/Source/WebCore/ChangeLog        2016-05-17 04:11:34 UTC (rev 200994)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-05-16 Chris Dumez <cdumez@apple.com>
+
+ Add RenderDescendantIterator to traverse a RenderObject's descendants
+ https://bugs.webkit.org/show_bug.cgi?id=157785
+
+ Reviewed by Zalan Bujtas.
+
+ Add RenderDescendantIterator to traverse a RenderObject's descendants. I
+ am planning to use it in the iOS Text Autosizing code (See Bug 157784).
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * rendering/RenderDescendantIterator.h: Added.
+ (WebCore::RenderDescendantIterator<T>::RenderDescendantIterator):
+ (WebCore::RenderDescendantIterator<T>::operator):
+ (WebCore::RenderDescendantConstIterator<T>::RenderDescendantConstIterator):
+ (WebCore::RenderDescendantConstIterator<T>::operator):
+ (WebCore::RenderDescendantIteratorAdapter<T>::RenderDescendantIteratorAdapter):
+ (WebCore::RenderDescendantIteratorAdapter<T>::begin):
+ (WebCore::RenderDescendantIteratorAdapter<T>::end):
+ (WebCore::RenderDescendantConstIteratorAdapter<T>::RenderDescendantConstIteratorAdapter):
+ (WebCore::RenderDescendantConstIteratorAdapter<T>::begin):
+ (WebCore::RenderDescendantConstIteratorAdapter<T>::end):
+ (WebCore::descendantsOfType):
+ * rendering/RenderIterator.h:
+ (WebCore::RenderObjectTraversal::firstChild):
+ (WebCore::RenderObjectTraversal::nextAncestorSibling):
+ (WebCore::RenderObjectTraversal::next):
+ (WebCore::RenderTraversal::firstChild):
+ (WebCore::RenderTraversal::lastChild):
+ (WebCore::RenderTraversal::nextSibling):
+ (WebCore::RenderTraversal::previousSibling):
+ (WebCore::RenderTraversal::findAncestorOfType):
+ (WebCore::RenderTraversal::firstWithin):
+ (WebCore::RenderTraversal::next):
+ (WebCore::RenderIterator<T>::traverseNext):
+ (WebCore::RenderConstIterator<T>::traverseNext):
+
</ins><span class="cx"> 2016-05-16 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Remove YouTube site-specific hack
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (200993 => 200994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-05-17 04:02:40 UTC (rev 200993)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-05-17 04:11:34 UTC (rev 200994)
</span><span class="lines">@@ -2883,6 +2883,7 @@
</span><span class="cx">                 836CB1F71BD1E41800AF1591 /* JSHTMLTableHeaderCellElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836CB1F31BD1E41800AF1591 /* JSHTMLTableHeaderCellElement.cpp */; };
</span><span class="cx">                 836CB1F81BD1E41800AF1591 /* JSHTMLTableDataCellElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 836CB1F41BD1E41800AF1591 /* JSHTMLTableDataCellElement.h */; };
</span><span class="cx">                 836CB1F91BD1E41800AF1591 /* JSHTMLTableDataCellElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836CB1F51BD1E41800AF1591 /* JSHTMLTableDataCellElement.cpp */; };
</span><ins>+                836DAA061CEAB80D00A2B707 /* RenderDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 836DAA051CEAB7CD00A2B707 /* RenderDescendantIterator.h */; };
</ins><span class="cx">                 836FBCEA178C113200B21A15 /* SVGAnimatedTypeAnimator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836FBCE9178C113200B21A15 /* SVGAnimatedTypeAnimator.cpp */; };
</span><span class="cx">                 836FBCEC178C117F00B21A15 /* SVGAnimatedProperty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836FBCEB178C117F00B21A15 /* SVGAnimatedProperty.cpp */; };
</span><span class="cx">                 8372DB311A6780A800C697C5 /* DiagnosticLoggingResultType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -10565,6 +10566,7 @@
</span><span class="cx">                 836CB1F31BD1E41800AF1591 /* JSHTMLTableHeaderCellElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTableHeaderCellElement.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 836CB1F41BD1E41800AF1591 /* JSHTMLTableDataCellElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableDataCellElement.h; sourceTree = "<group>"; };
</span><span class="cx">                 836CB1F51BD1E41800AF1591 /* JSHTMLTableDataCellElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTableDataCellElement.cpp; sourceTree = "<group>"; };
</span><ins>+                836DAA051CEAB7CD00A2B707 /* RenderDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderDescendantIterator.h; sourceTree = "<group>"; };
</ins><span class="cx">                 836FBCE9178C113200B21A15 /* SVGAnimatedTypeAnimator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGAnimatedTypeAnimator.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 836FBCEB178C117F00B21A15 /* SVGAnimatedProperty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGAnimatedProperty.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingResultType.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -24037,6 +24039,7 @@
</span><span class="cx">                                 9392F1410AD185F400691BD4 /* RenderCounter.h */,
</span><span class="cx">                                 BCEA482E097D93020094C9E4 /* RenderDeprecatedFlexibleBox.cpp */,
</span><span class="cx">                                 BCEA482F097D93020094C9E4 /* RenderDeprecatedFlexibleBox.h */,
</span><ins>+                                836DAA051CEAB7CD00A2B707 /* RenderDescendantIterator.h */,
</ins><span class="cx">                                 D302754512A5FE84004BD828 /* RenderDetailsMarker.cpp */,
</span><span class="cx">                                 D302754612A5FE84004BD828 /* RenderDetailsMarker.h */,
</span><span class="cx">                                 E43A023C17EB3713004CDD25 /* RenderElement.cpp */,
</span><span class="lines">@@ -28205,6 +28208,7 @@
</span><span class="cx">                                 0854B0211255E4E600B9CDD0 /* SVGInlineTextBox.h in Headers */,
</span><span class="cx">                                 B2227A300D00BF220071B782 /* SVGLangSpace.h in Headers */,
</span><span class="cx">                                 B2227A330D00BF220071B782 /* SVGLength.h in Headers */,
</span><ins>+                                836DAA061CEAB80D00A2B707 /* RenderDescendantIterator.h in Headers */,
</ins><span class="cx">                                 7134496E146941B300720312 /* SVGLengthContext.h in Headers */,
</span><span class="cx">                                 B2227A360D00BF220071B782 /* SVGLengthList.h in Headers */,
</span><span class="cx">                                 B2227A390D00BF220071B782 /* SVGLinearGradientElement.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderDescendantIteratorh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/RenderDescendantIterator.h (0 => 200994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderDescendantIterator.h         (rev 0)
+++ trunk/Source/WebCore/rendering/RenderDescendantIterator.h        2016-05-17 04:11:34 UTC (rev 200994)
</span><span class="lines">@@ -0,0 +1,167 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "RenderIterator.h"
+
+namespace WebCore {
+
+template <typename T>
+class RenderDescendantIterator : public RenderIterator<T> {
+public:
+ RenderDescendantIterator(const RenderElement& root);
+ RenderDescendantIterator(const RenderElement& root, T* current);
+ RenderDescendantIterator& operator++();
+};
+
+template <typename T>
+class RenderDescendantConstIterator : public RenderConstIterator<T> {
+public:
+ RenderDescendantConstIterator(const RenderElement& root);
+ RenderDescendantConstIterator(const RenderElement& root, const T* current);
+ RenderDescendantConstIterator& operator++();
+};
+
+template <typename T>
+class RenderDescendantIteratorAdapter {
+public:
+ RenderDescendantIteratorAdapter(RenderElement& root);
+ RenderDescendantIterator<T> begin();
+ RenderDescendantIterator<T> end();
+
+private:
+ RenderElement& m_root;
+};
+
+template <typename T>
+class RenderDescendantConstIteratorAdapter {
+public:
+ RenderDescendantConstIteratorAdapter(const RenderElement& root);
+ RenderDescendantConstIterator<T> begin() const;
+ RenderDescendantConstIterator<T> end() const;
+
+private:
+ const RenderElement& m_root;
+};
+
+template <typename T> RenderDescendantIteratorAdapter<T> descendantsOfType(RenderElement&);
+template <typename T> RenderDescendantConstIteratorAdapter<T> descendantsOfType(const RenderElement&);
+
+// RenderDescendantIterator
+
+template <typename T>
+inline RenderDescendantIterator<T>::RenderDescendantIterator(const RenderElement& root)
+ : RenderIterator<T>(&root)
+{
+}
+
+template <typename T>
+inline RenderDescendantIterator<T>::RenderDescendantIterator(const RenderElement& root, T* current)
+ : RenderIterator<T>(&root, current)
+{
+}
+
+template <typename T>
+inline RenderDescendantIterator<T>& RenderDescendantIterator<T>::operator++()
+{
+ return static_cast<RenderDescendantIterator<T>&>(RenderIterator<T>::traverseNext());
+}
+
+// RenderDescendantConstIterator
+
+template <typename T>
+inline RenderDescendantConstIterator<T>::RenderDescendantConstIterator(const RenderElement& root)
+ : RenderConstIterator<T>(&root)
+{
+}
+
+template <typename T>
+inline RenderDescendantConstIterator<T>::RenderDescendantConstIterator(const RenderElement& root, const T* current)
+ : RenderConstIterator<T>(&root, current)
+{
+}
+
+template <typename T>
+inline RenderDescendantConstIterator<T>& RenderDescendantConstIterator<T>::operator++()
+{
+ return static_cast<RenderDescendantConstIterator<T>&>(RenderConstIterator<T>::traverseNext());
+}
+
+// RenderDescendantIteratorAdapter
+
+template <typename T>
+inline RenderDescendantIteratorAdapter<T>::RenderDescendantIteratorAdapter(RenderElement& root)
+ : m_root(root)
+{
+}
+
+template <typename T>
+inline RenderDescendantIterator<T> RenderDescendantIteratorAdapter<T>::begin()
+{
+ return RenderDescendantIterator<T>(m_root, RenderTraversal::firstWithin<T>(m_root));
+}
+
+template <typename T>
+inline RenderDescendantIterator<T> RenderDescendantIteratorAdapter<T>::end()
+{
+ return RenderDescendantIterator<T>(m_root);
+}
+
+// RenderDescendantConstIteratorAdapter
+
+template <typename T>
+inline RenderDescendantConstIteratorAdapter<T>::RenderDescendantConstIteratorAdapter(const RenderElement& root)
+ : m_root(root)
+{
+}
+
+template <typename T>
+inline RenderDescendantConstIterator<T> RenderDescendantConstIteratorAdapter<T>::begin() const
+{
+ return RenderDescendantConstIterator<T>(m_root, RenderTraversal::firstWithin<T>(m_root));
+}
+
+template <typename T>
+inline RenderDescendantConstIterator<T> RenderDescendantConstIteratorAdapter<T>::end() const
+{
+ return RenderDescendantConstIterator<T>(m_root);
+}
+
+// Standalone functions
+
+template <typename T>
+inline RenderDescendantIteratorAdapter<T> descendantsOfType(RenderElement& root)
+{
+ return RenderDescendantIteratorAdapter<T>(root);
+}
+
+template <typename T>
+inline RenderDescendantConstIteratorAdapter<T> descendantsOfType(const RenderElement& root)
+{
+ return RenderDescendantConstIteratorAdapter<T>(root);
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderIterator.h (200993 => 200994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderIterator.h        2016-05-17 04:02:40 UTC (rev 200993)
+++ trunk/Source/WebCore/rendering/RenderIterator.h        2016-05-17 04:11:34 UTC (rev 200994)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> bool operator==(const RenderIterator& other) const;
</span><span class="cx"> bool operator!=(const RenderIterator& other) const;
</span><span class="cx">
</span><ins>+ RenderIterator& traverseNext();
</ins><span class="cx"> RenderIterator& traverseNextSibling();
</span><span class="cx"> RenderIterator& traversePreviousSibling();
</span><span class="cx"> RenderIterator& traverseAncestor();
</span><span class="lines">@@ -63,6 +64,7 @@
</span><span class="cx"> bool operator==(const RenderConstIterator& other) const;
</span><span class="cx"> bool operator!=(const RenderConstIterator& other) const;
</span><span class="cx">
</span><ins>+ RenderConstIterator& traverseNext();
</ins><span class="cx"> RenderConstIterator& traverseNextSibling();
</span><span class="cx"> RenderConstIterator& traversePreviousSibling();
</span><span class="cx"> RenderConstIterator& traverseAncestor();
</span><span class="lines">@@ -78,12 +80,58 @@
</span><span class="cx">
</span><span class="cx"> // Traversal helpers
</span><span class="cx">
</span><ins>+namespace RenderObjectTraversal {
+
+template <typename U>
+inline RenderObject* firstChild(U& object)
+{
+ return object.firstChild();
+}
+
+inline RenderObject* firstChild(RenderObject& object)
+{
+ return object.firstChildSlow();
+}
+
+inline RenderObject* firstChild(RenderText&)
+{
+ return nullptr;
+}
+
+inline RenderObject* nextAncestorSibling(RenderObject& current, const RenderObject* stayWithin)
+{
+ for (auto* ancestor = current.parent(); ancestor; ancestor = ancestor->parent()) {
+ if (ancestor == stayWithin)
+ return nullptr;
+ if (auto* sibling = ancestor->nextSibling())
+ return sibling;
+ }
+ return nullptr;
+}
+
+template <typename U>
+inline RenderObject* next(U& current, const RenderObject* stayWithin)
+{
+ if (auto* child = firstChild(current))
+ return child;
+
+ if (&current == stayWithin)
+ return nullptr;
+
+ if (auto* sibling = current.nextSibling())
+ return sibling;
+
+ return nextAncestorSibling(current, stayWithin);
+}
+
+}
+
</ins><span class="cx"> namespace RenderTraversal {
</span><span class="cx">
</span><span class="cx"> template <typename T, typename U>
</span><span class="cx"> inline T* firstChild(U& current)
</span><span class="cx"> {
</span><del>- RenderObject* object = current.firstChild();
</del><ins>+ RenderObject* object = RenderObjectTraversal::firstChild(current);
</ins><span class="cx"> while (object && !isRendererOfType<T>(*object))
</span><span class="cx"> object = object->nextSibling();
</span><span class="cx"> return static_cast<T*>(object);
</span><span class="lines">@@ -126,6 +174,24 @@
</span><span class="cx"> return nullptr;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+template <typename T, typename U>
+inline T* firstWithin(U& current)
+{
+ auto* descendant = RenderObjectTraversal::firstChild(current);
+ while (descendant && !isRendererOfType<T>(*descendant))
+ descendant = RenderObjectTraversal::next(*descendant, &current);
+ return static_cast<T*>(descendant);
+}
+
+template <typename T, typename U>
+inline T* next(U& current, const RenderObject* stayWithin)
+{
+ auto* descendant = RenderObjectTraversal::next(current, stayWithin);
+ while (descendant && !isRendererOfType<T>(*descendant))
+ descendant = RenderObjectTraversal::next(*descendant, stayWithin);
+ return static_cast<T*>(descendant);
+}
+
</ins><span class="cx"> } // namespace WebCore::RenderTraversal
</span><span class="cx">
</span><span class="cx"> // RenderIterator
</span><span class="lines">@@ -153,6 +219,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <typename T>
</span><ins>+inline RenderIterator<T>& RenderIterator<T>::traverseNext()
+{
+ ASSERT(m_current);
+ m_current = RenderTraversal::next<T>(*m_current, m_root);
+ return *this;
+}
+
+template <typename T>
</ins><span class="cx"> inline RenderIterator<T>& RenderIterator<T>::traversePreviousSibling()
</span><span class="cx"> {
</span><span class="cx"> ASSERT(m_current);
</span><span class="lines">@@ -221,6 +295,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> template <typename T>
</span><ins>+inline RenderConstIterator<T>& RenderConstIterator<T>::traverseNext()
+{
+ ASSERT(m_current);
+ m_current = RenderTraversal::next<T>(*m_current, m_root);
+ return *this;
+}
+
+template <typename T>
</ins><span class="cx"> inline RenderConstIterator<T>& RenderConstIterator<T>::traversePreviousSibling()
</span><span class="cx"> {
</span><span class="cx"> ASSERT(m_current);
</span></span></pre>
</div>
</div>
</body>
</html>