Index: Source/core/html/HTMLCollection.cpp |
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp |
index 8a81afed942ae52b576c675e400d6847f908be28..b66fa9d26d5ea5003523c4402deb4ef231e56878 100644 |
--- a/Source/core/html/HTMLCollection.cpp |
+++ b/Source/core/html/HTMLCollection.cpp |
@@ -276,11 +276,6 @@ template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c |
return collection.elementMatches(element); |
} |
-Element* HTMLCollection::itemBefore(const Element* previous) const |
-{ |
- return LiveNodeListBase::itemBefore(*this, previous); |
-} |
- |
Element* HTMLCollection::virtualItemAfter(Element*) const |
{ |
ASSERT_NOT_REACHED(); |
@@ -314,6 +309,14 @@ inline Element* firstMatchingChildElement(const HTMLCollection& nodeList) |
return element; |
} |
+inline Element* lastMatchingChildElement(const HTMLCollection& nodeList) |
+{ |
+ Element* element = ElementTraversal::lastChild(nodeList.rootNode()); |
+ while (element && !isMatchingElement(nodeList, *element)) |
+ element = ElementTraversal::previousSibling(*element); |
+ return element; |
+} |
+ |
inline Element* nextMatchingChildElement(const HTMLCollection& nodeList, Element& current) |
{ |
Element* next = ¤t; |
@@ -323,6 +326,15 @@ inline Element* nextMatchingChildElement(const HTMLCollection& nodeList, Element |
return next; |
} |
+inline Element* previousMatchingChildElement(const HTMLCollection& nodeList, Element& current) |
+{ |
+ Element* previous = ¤t; |
+ do { |
+ previous = ElementTraversal::previousSibling(*previous); |
+ } while (previous && !isMatchingElement(nodeList, *previous)); |
+ return previous; |
+} |
+ |
Element* HTMLCollection::traverseToFirstElement() const |
{ |
switch (type()) { |
@@ -339,6 +351,14 @@ Element* HTMLCollection::traverseToFirstElement() const |
} |
} |
+Element* HTMLCollection::traverseToLastElement() const |
+{ |
+ ASSERT(canTraverseBackward()); |
+ if (shouldOnlyIncludeDirectChildren()) |
+ return lastMatchingChildElement(*this); |
+ return lastMatchingElement(*this); |
+} |
+ |
inline Element* HTMLCollection::traverseNextElement(Element& previous) const |
{ |
if (overridesItemAfter()) |
@@ -377,6 +397,21 @@ Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& curre |
} |
} |
+Element* HTMLCollection::traverseBackwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset) const |
+{ |
+ ASSERT(currentOffset > offset); |
+ ASSERT(canTraverseBackward()); |
+ if (shouldOnlyIncludeDirectChildren()) { |
Inactive
2014/04/09 23:08:58
Now we do this check once and then traverse to the
|
+ Element* previous = ¤tElement; |
+ while ((previous = previousMatchingChildElement(*this, *previous))) { |
+ if (--currentOffset == offset) |
+ return previous; |
+ } |
+ return 0; |
+ } |
+ return traverseMatchingElementsBackwardToOffset(*this, offset, currentElement, currentOffset); |
+} |
+ |
Element* HTMLCollection::namedItem(const AtomicString& name) const |
{ |
// http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp |