summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLCollection.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-07-18 13:59:13 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-07-18 13:59:28 +0200
commit4d6084feccab99c0a7b3ecef26bb49c41dd50201 (patch)
treefd1195897f551eee6d5a15d07ff5733b15aa2a5c /Source/WebCore/html/HTMLCollection.cpp
parentae901828d4689ab9e89113f6b6ea8042b37a9fda (diff)
downloadqtwebkit-4d6084feccab99c0a7b3ecef26bb49c41dd50201.tar.gz
Imported WebKit commit ff52235a78888e5cb8e286a828a8698042200e67 (http://svn.webkit.org/repository/webkit/trunk@122948)
New snapshot that should fix the rendering issues recently introduced
Diffstat (limited to 'Source/WebCore/html/HTMLCollection.cpp')
-rw-r--r--Source/WebCore/html/HTMLCollection.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/Source/WebCore/html/HTMLCollection.cpp b/Source/WebCore/html/HTMLCollection.cpp
index ef5f270a7..2b53edd98 100644
--- a/Source/WebCore/html/HTMLCollection.cpp
+++ b/Source/WebCore/html/HTMLCollection.cpp
@@ -246,13 +246,29 @@ static Node* nextNode(Node* base, Node* previous, bool onlyIncludeDirectChildren
return onlyIncludeDirectChildren ? previous->previousSibling() : previous->traversePreviousNode(base);
}
+static inline Node* lastDescendent(Node* node)
+{
+ node = node->lastChild();
+ for (Node* current = node; current; current = current->lastChild())
+ node = current;
+ return node;
+}
+
template<bool forward>
static Element* itemBeforeOrAfter(CollectionType type, Node* base, unsigned& offsetInArray, Node* previous)
{
ASSERT_UNUSED(offsetInArray, !offsetInArray);
bool onlyIncludeDirectChildren = shouldOnlyIncludeDirectChildren(type);
Node* rootNode = base;
- Node* current = previous ? nextNode<forward>(rootNode, previous, onlyIncludeDirectChildren) : (forward ? base->firstChild() : base->lastChild());
+ Node* current;
+ if (previous)
+ current = nextNode<forward>(rootNode, previous, onlyIncludeDirectChildren);
+ else {
+ if (forward)
+ current = rootNode->firstChild();
+ else
+ current = onlyIncludeDirectChildren ? rootNode->lastChild() : lastDescendent(rootNode);
+ }
for (; current; current = nextNode<forward>(rootNode, current, onlyIncludeDirectChildren)) {
if (current->isElementNode() && isAcceptableElement(type, toElement(current)))
@@ -308,8 +324,8 @@ unsigned HTMLCollection::length() const
do {
offset++;
} while (itemBeforeOrAfterCachedItem(offset));
+ ASSERT(isLengthCacheValid());
- setLengthCache(offset);
return offset;
}
@@ -381,7 +397,8 @@ Element* HTMLCollection::itemBeforeOrAfterCachedItem(unsigned offset) const
}
}
- setLengthCache(currentOffset);
+ unsigned offsetOfLastItem = currentOffset;
+ setLengthCache(offsetOfLastItem + 1);
return 0;
}