Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  * Copyright (C) 2004, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  */
     22 
     23 #include "config.h"
     24 #include "core/dom/LiveNodeList.h"
     25 
     26 namespace blink {
     27 
     28 namespace {
     29 
     30 class IsMatch {
     31 public:
     32     IsMatch(const LiveNodeList& list)
     33         : m_list(list)
     34     { }
     35 
     36     bool operator() (const Element& element) const
     37     {
     38         return m_list.elementMatches(element);
     39     }
     40 
     41 private:
     42     const LiveNodeList& m_list;
     43 };
     44 
     45 } // namespace
     46 
     47 Node* LiveNodeList::virtualOwnerNode() const
     48 {
     49     return &ownerNode();
     50 }
     51 
     52 void LiveNodeList::invalidateCache(Document*) const
     53 {
     54     m_collectionItemsCache.invalidate();
     55 }
     56 
     57 unsigned LiveNodeList::length() const
     58 {
     59     return m_collectionItemsCache.nodeCount(*this);
     60 }
     61 
     62 Element* LiveNodeList::item(unsigned offset) const
     63 {
     64     return m_collectionItemsCache.nodeAt(*this, offset);
     65 }
     66 
     67 Element* LiveNodeList::traverseToFirst() const
     68 {
     69     return ElementTraversal::firstWithin(rootNode(), IsMatch(*this));
     70 }
     71 
     72 Element* LiveNodeList::traverseToLast() const
     73 {
     74     return ElementTraversal::lastWithin(rootNode(), IsMatch(*this));
     75 }
     76 
     77 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset) const
     78 {
     79     return traverseMatchingElementsForwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this));
     80 }
     81 
     82 Element* LiveNodeList::traverseBackwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset) const
     83 {
     84     return traverseMatchingElementsBackwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this));
     85 }
     86 
     87 void LiveNodeList::trace(Visitor* visitor)
     88 {
     89     visitor->trace(m_collectionItemsCache);
     90     LiveNodeListBase::trace(visitor);
     91     NodeList::trace(visitor);
     92 }
     93 
     94 } // namespace blink
     95