summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/ElementIterator.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/ElementIterator.h')
-rw-r--r--Source/WebCore/dom/ElementIterator.h69
1 files changed, 46 insertions, 23 deletions
diff --git a/Source/WebCore/dom/ElementIterator.h b/Source/WebCore/dom/ElementIterator.h
index a155ed679..da7d935f8 100644
--- a/Source/WebCore/dom/ElementIterator.h
+++ b/Source/WebCore/dom/ElementIterator.h
@@ -23,8 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ElementIterator_h
-#define ElementIterator_h
+#pragma once
#include "ElementTraversal.h"
@@ -40,8 +39,8 @@ public:
ElementIterator(const ContainerNode* root);
ElementIterator(const ContainerNode* root, ElementType* current);
- ElementType& operator*();
- ElementType* operator->();
+ ElementType& operator*() const;
+ ElementType* operator->() const;
bool operator==(const ElementIterator& other) const;
bool operator!=(const ElementIterator& other) const;
@@ -53,6 +52,8 @@ public:
ElementIterator& traverseNextSkippingChildren();
ElementIterator& traverseAncestor();
+ void dropAssertions();
+
private:
const ContainerNode* m_root;
ElementType* m_current;
@@ -81,6 +82,8 @@ public:
ElementConstIterator& traverseNextSkippingChildren();
ElementConstIterator& traverseAncestor();
+ void dropAssertions();
+
private:
const ContainerNode* m_root;
const ElementType* m_current;
@@ -114,7 +117,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseNext(
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::next(m_current, m_root);
+ m_current = Traversal<ElementType>::next(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -128,7 +131,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traversePrevi
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::previous(m_current, m_root);
+ m_current = Traversal<ElementType>::previous(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -142,7 +145,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseNextS
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::nextSibling(m_current);
+ m_current = Traversal<ElementType>::nextSibling(*m_current);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -156,7 +159,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traversePrevi
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::previousSibling(m_current);
+ m_current = Traversal<ElementType>::previousSibling(*m_current);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -170,7 +173,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseNextS
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::nextSkippingChildren(m_current, m_root);
+ m_current = Traversal<ElementType>::nextSkippingChildren(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -180,15 +183,29 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseNextS
}
template <typename ElementType>
-inline ElementType* findElementAncestorOfType(const Element& current)
+inline void ElementIterator<ElementType>::dropAssertions()
+{
+#if !ASSERT_DISABLED
+ m_assertions.clear();
+#endif
+}
+
+template <typename ElementType>
+inline ElementType* findElementAncestorOfType(const Node& current)
{
for (Element* ancestor = current.parentElement(); ancestor; ancestor = ancestor->parentElement()) {
- if (isElementOfType<const ElementType>(*ancestor))
- return static_cast<ElementType*>(ancestor);
+ if (is<ElementType>(*ancestor))
+ return downcast<ElementType>(ancestor);
}
return nullptr;
}
+template <>
+inline Element* findElementAncestorOfType<Element>(const Node& current)
+{
+ return current.parentElement();
+}
+
template <typename ElementType>
inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseAncestor()
{
@@ -205,7 +222,7 @@ inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseAnces
}
template <typename ElementType>
-inline ElementType& ElementIterator<ElementType>::operator*()
+inline ElementType& ElementIterator<ElementType>::operator*() const
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
@@ -213,7 +230,7 @@ inline ElementType& ElementIterator<ElementType>::operator*()
}
template <typename ElementType>
-inline ElementType* ElementIterator<ElementType>::operator->()
+inline ElementType* ElementIterator<ElementType>::operator->() const
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
@@ -258,7 +275,7 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::next(m_current, m_root);
+ m_current = Traversal<ElementType>::next(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -272,7 +289,7 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::previous(m_current, m_root);
+ m_current = Traversal<ElementType>::previous(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -286,7 +303,7 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::nextSibling(m_current);
+ m_current = Traversal<ElementType>::nextSibling(*m_current);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -300,7 +317,7 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::previousSibling(m_current);
+ m_current = Traversal<ElementType>::previousSibling(*m_current);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -314,7 +331,7 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
{
ASSERT(m_current);
ASSERT(!m_assertions.domTreeHasMutated());
- m_current = Traversal<ElementType>::nextSkippingChildren(m_current, m_root);
+ m_current = Traversal<ElementType>::nextSkippingChildren(*m_current, m_root);
#if !ASSERT_DISABLED
// Drop the assertion when the iterator reaches the end.
if (!m_current)
@@ -339,6 +356,14 @@ inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::tra
}
template <typename ElementType>
+inline void ElementConstIterator<ElementType>::dropAssertions()
+{
+#if !ASSERT_DISABLED
+ m_assertions.clear();
+#endif
+}
+
+template <typename ElementType>
inline const ElementType& ElementConstIterator<ElementType>::operator*() const
{
ASSERT(m_current);
@@ -368,10 +393,8 @@ inline bool ElementConstIterator<ElementType>::operator!=(const ElementConstIter
return !(*this == other);
}
-}
+} // namespace WebCore
#include "ElementAncestorIterator.h"
#include "ElementChildIterator.h"
-#include "ElementDescendantIterator.h"
-
-#endif
+#include "TypedElementDescendantIterator.h"