+2007-12-25 Sam Weinig <sam@webkit.org>
+
+ Reviewed by Eric Seidel.
+
+ Clean up the files relating to NodeLists.
+
+ * dom/ChildNodeList.cpp:
+ (WebCore::ChildNodeList::ChildNodeList):
+ (WebCore::ChildNodeList::length):
+ (WebCore::ChildNodeList::item):
+ (WebCore::ChildNodeList::nodeMatches):
+ * dom/ChildNodeList.h:
+ * dom/DynamicNodeList.cpp:
+ (WebCore::DynamicNodeList::itemForwardsFromCurrent):
+ (WebCore::DynamicNodeList::itemBackwardsFromCurrent):
+ (WebCore::DynamicNodeList::itemWithName):
+ * dom/DynamicNodeList.h:
+ (WebCore::DynamicNodeList::needsNotifications):
+ * dom/NameNodeList.cpp:
+ (WebCore::NameNodeList::NameNodeList):
+ (WebCore::NameNodeList::rootNodeAttributeChanged):
+ (WebCore::NameNodeList::nodeMatches):
+ * dom/NameNodeList.h:
+ * dom/NodeList.h:
+ * dom/SelectorNodeList.h:
+
2007-12-25 Sam Weinig <sam@webkit.org>
Fix non-mac builds.
/**
- * This file is part of the DOM implementation for KDE.
- *
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "config.h"
#include "ChildNodeList.h"
-#include "Node.h"
-using namespace WebCore;
+#include "Node.h"
namespace WebCore {
-ChildNodeList::ChildNodeList(Node* n, DynamicNodeList::Caches* info)
- : DynamicNodeList(n, info, false)
+ChildNodeList::ChildNodeList(PassRefPtr<Node> rootNode, DynamicNodeList::Caches* info)
+ : DynamicNodeList(rootNode, info, false)
{
}
return m_caches->cachedLength;
unsigned len = 0;
- Node *n;
- for (n = m_rootNode->firstChild(); n != 0; n = n->nextSibling())
+ for (Node* n = m_rootNode->firstChild(); n; n = n->nextSibling())
len++;
m_caches->cachedLength = len;
}
}
- if (pos <= index)
+ if (pos <= index) {
while (n && pos < index) {
n = n->nextSibling();
++pos;
}
- else
+ } else {
while (n && pos > index) {
n = n->previousSibling();
--pos;
}
+ }
if (n) {
m_caches->lastItem = n;
return 0;
}
-bool ChildNodeList::nodeMatches(Node *testNode) const
+bool ChildNodeList::nodeMatches(Node* testNode) const
{
return testNode->parentNode() == m_rootNode;
}
ASSERT(!m_ownsCaches);
}
-}
+} // namespace WebCore
namespace WebCore {
-class ChildNodeList : public DynamicNodeList {
-public:
- ChildNodeList(Node*, DynamicNodeList::Caches*);
+ class ChildNodeList : public DynamicNodeList {
+ public:
+ ChildNodeList(PassRefPtr<Node> rootNode, DynamicNodeList::Caches*);
- virtual unsigned length() const;
- virtual Node* item(unsigned index) const;
+ virtual unsigned length() const;
+ virtual Node* item(unsigned index) const;
- virtual void rootNodeChildrenChanged();
+ virtual void rootNodeChildrenChanged();
-protected:
- virtual bool nodeMatches(Node* testNode) const;
-};
+ protected:
+ virtual bool nodeMatches(Node*) const;
+ };
} // namespace WebCore
Node* DynamicNodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
{
ASSERT(remainingOffset >= 0);
-
- for (Node *n = start; n; n = n->traverseNextNode(m_rootNode.get())) {
+ for (Node* n = start; n; n = n->traverseNextNode(m_rootNode.get())) {
if (n->isElementNode()) {
if (nodeMatches(n)) {
if (!remainingOffset) {
Node* DynamicNodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
{
ASSERT(remainingOffset < 0);
- for (Node *n = start; n; n = n->traversePreviousNode(m_rootNode.get())) {
+ for (Node* n = start; n; n = n->traversePreviousNode(m_rootNode.get())) {
if (n->isElementNode()) {
if (nodeMatches(n)) {
if (!remainingOffset) {
if (!node || !nodeMatches(node))
return 0;
- for (Node* p = node->parentNode(); p; p = p->parentNode())
+ for (Node* p = node->parentNode(); p; p = p->parentNode()) {
if (p == m_rootNode)
return node;
+ }
return 0;
}
isItemCacheValid = false;
}
-}
+} // namespace WebCore
namespace WebCore {
-class AtomicString;
-class Node;
+ class AtomicString;
+ class Node;
-class DynamicNodeList : public NodeList {
-public:
- struct Caches {
- Caches();
- void reset();
+ class DynamicNodeList : public NodeList {
+ public:
+ struct Caches {
+ Caches();
+ void reset();
- unsigned cachedLength;
- Node* lastItem;
- unsigned lastItemOffset;
- bool isLengthCacheValid : 1;
- bool isItemCacheValid : 1;
- };
+ unsigned cachedLength;
+ Node* lastItem;
+ unsigned lastItemOffset;
+ bool isLengthCacheValid : 1;
+ bool isItemCacheValid : 1;
+ };
- DynamicNodeList(PassRefPtr<Node> rootNode, bool needsNotifications);
- DynamicNodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications);
- virtual ~DynamicNodeList();
+ DynamicNodeList(PassRefPtr<Node> rootNode, bool needsNotifications);
+ DynamicNodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications);
+ virtual ~DynamicNodeList();
- bool needsNotifications() const { return m_needsNotifications; }
+ bool needsNotifications() const { return m_needsNotifications; }
- // DOM methods & attributes for NodeList
- virtual unsigned length() const;
- virtual Node* item(unsigned index) const;
- virtual Node* itemWithName(const AtomicString&) const;
+ // DOM methods & attributes for NodeList
+ virtual unsigned length() const;
+ virtual Node* item(unsigned index) const;
+ virtual Node* itemWithName(const AtomicString&) const;
- // Other methods (not part of DOM)
- virtual void rootNodeChildrenChanged();
- virtual void rootNodeAttributeChanged();
+ // Other methods (not part of DOM)
+ virtual void rootNodeChildrenChanged();
+ virtual void rootNodeAttributeChanged();
-protected:
- virtual bool nodeMatches(Node*) const = 0;
+ protected:
+ virtual bool nodeMatches(Node*) const = 0;
- RefPtr<Node> m_rootNode;
- mutable Caches* m_caches;
- bool m_ownsCaches;
- bool m_needsNotifications;
+ RefPtr<Node> m_rootNode;
+ mutable Caches* m_caches;
+ bool m_ownsCaches;
+ bool m_needsNotifications;
-private:
- Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const;
- Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const;
-};
+ private:
+ Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const;
+ Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const;
+ };
} // namespace WebCore
#include "Element.h"
#include "HTMLNames.h"
+#include <wtf/Assertions.h>
namespace WebCore {
using namespace HTMLNames;
-NameNodeList::NameNodeList(Node* root, const String& name, DynamicNodeList::Caches* caches)
- : DynamicNodeList(root, caches, true)
+NameNodeList::NameNodeList(PassRefPtr<Node> rootNode, const String& name, DynamicNodeList::Caches* caches)
+ : DynamicNodeList(rootNode, caches, true)
, m_nodeName(name)
{
}
+void NameNodeList::rootNodeAttributeChanged()
+{
+ DynamicNodeList::rootNodeChildrenChanged();
+}
+
bool NameNodeList::nodeMatches(Node* testNode) const
{
+ ASSERT(testNode->isElementNode());
return static_cast<Element*>(testNode)->getAttribute(nameAttr) == m_nodeName;
}
#define NameNodeList_h
#include "DynamicNodeList.h"
-#include "PlatformString.h"
+#include "AtomicString.h"
namespace WebCore {
-/**
- * NodeList which lists all Nodes in a Element with a given "name=" tag
- */
-class NameNodeList : public DynamicNodeList {
-public:
- NameNodeList(Node* root, const String& name, DynamicNodeList::Caches*);
+ class String;
+
+ // NodeList which lists all Nodes in a Element with a given "name" attribute
+ class NameNodeList : public DynamicNodeList {
+ public:
+ NameNodeList(PassRefPtr<Node> rootNode, const String& name, DynamicNodeList::Caches*);
- // Other methods (not part of DOM)
-
- virtual void rootNodeAttributeChanged() { DynamicNodeList::rootNodeChildrenChanged(); }
+ virtual void rootNodeAttributeChanged();
-private:
- virtual bool nodeMatches(Node*) const;
+ private:
+ virtual bool nodeMatches(Node*) const;
- String m_nodeName;
-};
+ AtomicString m_nodeName;
+ };
} // namespace WebCore
/*
- * This file is part of the DOM implementation for KDE.
- *
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#define NodeList_h
#include <wtf/RefCounted.h>
-#include <wtf/Forward.h>
namespace WebCore {
class SelectorNodeList : public StaticNodeList {
public:
- SelectorNodeList(PassRefPtr<Node> rootNode, CSSSelector* selector);
+ SelectorNodeList(PassRefPtr<Node> rootNode, CSSSelector*);
};
} // namespace WebCore