Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Unified Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 475023002: Use new match Functor ElementTraversal API in DOMSiblingTraversalStrategy (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix Windows build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/SiblingTraversalStrategies.h
diff --git a/Source/core/css/SiblingTraversalStrategies.h b/Source/core/css/SiblingTraversalStrategies.h
index 7861b70541f1033237db4173fe5416f42f111104..65063adbc667c232be0abff8e032db50b9be68ca 100644
--- a/Source/core/css/SiblingTraversalStrategies.h
+++ b/Source/core/css/SiblingTraversalStrategies.h
@@ -35,7 +35,8 @@
namespace blink {
-struct DOMSiblingTraversalStrategy {
+class DOMSiblingTraversalStrategy {
+public:
bool isFirstChild(Element&) const;
bool isLastChild(Element&) const;
bool isFirstOfType(Element&, const QualifiedName&) const;
@@ -45,6 +46,15 @@ struct DOMSiblingTraversalStrategy {
int countElementsAfter(Element&) const;
int countElementsOfTypeBefore(Element&, const QualifiedName&) const;
int countElementsOfTypeAfter(Element&, const QualifiedName&) const;
+
+private:
+ class HasTagName {
Inactive 2014/08/14 18:48:50 We could move this to Element.h if it is used in m
+ public:
+ explicit HasTagName(const QualifiedName& tagName) : m_tagName(tagName) { }
+ bool operator() (const Element& element) const { return element.hasTagName(m_tagName); }
+ private:
+ const QualifiedName& m_tagName;
+ };
};
inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) const
@@ -59,20 +69,12 @@ inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) const
inline bool DOMSiblingTraversalStrategy::isFirstOfType(Element& element, const QualifiedName& type) const
{
- for (const Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(*sibling)) {
- if (sibling->hasTagName(type))
- return false;
- }
- return true;
+ return !ElementTraversal::previousSibling(element, HasTagName(type));
}
inline bool DOMSiblingTraversalStrategy::isLastOfType(Element& element, const QualifiedName& type) const
{
- for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(*sibling)) {
- if (sibling->hasTagName(type))
- return false;
- }
- return true;
+ return !ElementTraversal::nextSibling(element, HasTagName(type));
}
inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) const
@@ -87,11 +89,8 @@ inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) co
inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& element, const QualifiedName& type) const
{
int count = 0;
- for (const Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(*sibling)) {
- if (sibling->hasTagName(type))
- ++count;
- }
-
+ for (const Element* sibling = ElementTraversal::previousSibling(element, HasTagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, HasTagName(type)))
+ ++count;
return count;
}
@@ -100,18 +99,14 @@ inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con
int count = 0;
for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(*sibling))
++count;
-
return count;
}
inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& element, const QualifiedName& type) const
{
int count = 0;
- for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(*sibling)) {
- if (sibling->hasTagName(type))
- ++count;
- }
-
+ for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagName(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagName(type)))
+ ++count;
return count;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698