Make LiveNodeListBase use Elements instead of Nodes
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Nov 2013 21:31:27 +0000 (21:31 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Nov 2013 21:31:27 +0000 (21:31 +0000)
commitb05404b75454d22f7970926110e6502c40b12160
treeb52b93acab3a4963027eb613951b60a068476f38
parentb051bb313876cbb0bcb157a39119e41c3ae17543
Make LiveNodeListBase use Elements instead of Nodes
https://bugs.webkit.org/show_bug.cgi?id=123745

Reviewed by Anders Carlsson.

* WebCore.exp.in:
* dom/Element.cpp:
(WebCore::Element::firstElementChild):
(WebCore::Element::lastElementChild):

    Switch to correct calls. ElementTraversal::previous and previousChild are no longer equivalent.

* dom/ElementTraversal.h:
(WebCore::::lastWithinTemplate):
(WebCore::::previousTemplate):

    Fix ElementTraversal::lastWithin and previous. They had no real clients and didn't work correctly.
    With LiveNodeListBase starting to use these they get excellent test coverage.

* dom/LiveNodeList.cpp:
(WebCore::LiveNodeListBase::invalidateCache):
* dom/LiveNodeList.h:
(WebCore::LiveNodeListBase::LiveNodeListBase):
(WebCore::LiveNodeListBase::isElementCacheValid):
(WebCore::LiveNodeListBase::cachedElement):
(WebCore::LiveNodeListBase::cachedElementOffset):
(WebCore::LiveNodeListBase::setCachedElement):

    Make the cache Element based.
    Switch to Elements in all helpers.
    Rename item -> element for clarity.

* dom/NodeIterator.cpp:
(WebCore::NodeIterator::NodePointer::moveToPrevious):
(WebCore::NodeIterator::updateForNodeRemoval):

    This code expected the old inconsistent NodeTraversal::previous behavior where the traversal includes
    the root as the last item. Drop the stayWithin parameter and handle the one case where it is needed here.

* dom/NodeTraversal.cpp:
(WebCore::NodeTraversal::last):
(WebCore::NodeTraversal::deepLastChild):
* dom/NodeTraversal.h:

    Support ElementTraversal::previous/lastWithin.

(WebCore::NodeTraversal::previous):

    This was slightly wrong too.

* html/HTMLCollection.cpp:
(WebCore::previousElement):
(WebCore::lastElement):
(WebCore::LiveNodeListBase::iterateForPreviousElement):
(WebCore::LiveNodeListBase::itemBefore):
(WebCore::LiveNodeListBase::isLastItemCloserThanLastOrCachedItem):
(WebCore::LiveNodeListBase::isFirstItemCloserThanCachedItem):
(WebCore::LiveNodeListBase::setCachedElement):
(WebCore::LiveNodeListBase::item):
(WebCore::LiveNodeListBase::elementBeforeOrAfterCachedElement):
* html/HTMLCollection.h:
(WebCore::HTMLCollection::isEmpty):
(WebCore::HTMLCollection::hasExactlyOneItem):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158587 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/ElementTraversal.h
Source/WebCore/dom/LiveNodeList.cpp
Source/WebCore/dom/LiveNodeList.h
Source/WebCore/dom/NodeIterator.cpp
Source/WebCore/dom/NodeTraversal.cpp
Source/WebCore/dom/NodeTraversal.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h