[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
kocienda
kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:48:54 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit ad863eeda1cff4bdd79bc178792b06e2aa1fa9be
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jul 6 17:04:45 2004 +0000
Reviewed by Trey
Fixed several problems with traversal classes. For one, NodeIterators treat
FILTER_REJECT and FILTER_SKIP the same, since it treats the DOM tree as a
flat collection of nodes free of hierarchy. The code before this change did
not do this correctly. It sure pays to go back and read the specs. :)
Also, the code to traverse from node to node when filters were applied was
not working correctly. My first attemmpt to implement this was just plain
buggy, as I discovered when I tried to write tests for my WWDC talk. I have
settled on an implementation which is much simpler and worked for all the
tests I threw at it.
* khtml/xml/dom2_traversalimpl.cpp:
(DOM::NodeIteratorImpl::findNextNode):
(DOM::NodeIteratorImpl::nextNode):
(DOM::NodeIteratorImpl::findPreviousNode):
(DOM::NodeIteratorImpl::previousNode):
(DOM::TreeWalkerImpl::parentNode):
(DOM::TreeWalkerImpl::firstChild):
(DOM::TreeWalkerImpl::lastChild):
(DOM::TreeWalkerImpl::previousSibling):
(DOM::TreeWalkerImpl::nextSibling):
(DOM::TreeWalkerImpl::previousNode):
(DOM::TreeWalkerImpl::nextNode):
(DOM::TreeWalkerImpl::ancestorRejected):
* khtml/xml/dom2_traversalimpl.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index db32449..1a24a00 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,33 @@
+2004-07-06 Ken Kocienda <kocienda at apple.com>
+
+ Reviewed by Trey
+
+ Fixed several problems with traversal classes. For one, NodeIterators treat
+ FILTER_REJECT and FILTER_SKIP the same, since it treats the DOM tree as a
+ flat collection of nodes free of hierarchy. The code before this change did
+ not do this correctly. It sure pays to go back and read the specs. :)
+
+ Also, the code to traverse from node to node when filters were applied was
+ not working correctly. My first attemmpt to implement this was just plain
+ buggy, as I discovered when I tried to write tests for my WWDC talk. I have
+ settled on an implementation which is much simpler and worked for all the
+ tests I threw at it.
+
+ * khtml/xml/dom2_traversalimpl.cpp:
+ (DOM::NodeIteratorImpl::findNextNode):
+ (DOM::NodeIteratorImpl::nextNode):
+ (DOM::NodeIteratorImpl::findPreviousNode):
+ (DOM::NodeIteratorImpl::previousNode):
+ (DOM::TreeWalkerImpl::parentNode):
+ (DOM::TreeWalkerImpl::firstChild):
+ (DOM::TreeWalkerImpl::lastChild):
+ (DOM::TreeWalkerImpl::previousSibling):
+ (DOM::TreeWalkerImpl::nextSibling):
+ (DOM::TreeWalkerImpl::previousNode):
+ (DOM::TreeWalkerImpl::nextNode):
+ (DOM::TreeWalkerImpl::ancestorRejected):
+ * khtml/xml/dom2_traversalimpl.h:
+
2004-07-06 Vicki Murley <vicki at apple.com>
Reviewed by kocienda.
diff --git a/WebCore/khtml/xml/dom2_traversalimpl.cpp b/WebCore/khtml/xml/dom2_traversalimpl.cpp
index f01228b..bed709d 100644
--- a/WebCore/khtml/xml/dom2_traversalimpl.cpp
+++ b/WebCore/khtml/xml/dom2_traversalimpl.cpp
@@ -79,163 +79,6 @@ short TraversalImpl::acceptNode(NodeImpl *node) const
return NodeFilter::FILTER_SKIP;
}
-NodeImpl *TraversalImpl::findParentNode(NodeImpl *node, short accept) const
-{
- if (!node || node == root())
- return 0;
- NodeImpl *n = node->parentNode();
- while (n) {
- if (acceptNode(n) & accept)
- return n;
- if (n == root())
- return 0;
- n = n->parentNode();
- }
- return 0;
-}
-
-NodeImpl *TraversalImpl::findFirstChild(NodeImpl *node) const
-{
- if (!node || acceptNode(node) == NodeFilter::FILTER_REJECT)
- return 0;
- NodeImpl *n = node->firstChild();
- while (n) {
- if (acceptNode(n) == NodeFilter::FILTER_ACCEPT)
- return n;
- n = n->nextSibling();
- }
- return 0;
-}
-
-NodeImpl *TraversalImpl::findLastChild(NodeImpl *node) const
-{
- if (!node || acceptNode(node) == NodeFilter::FILTER_REJECT)
- return 0;
- NodeImpl *n = node->lastChild();
- while (n) {
- if (acceptNode(n) == NodeFilter::FILTER_ACCEPT)
- return n;
- n = n->previousSibling();
- }
- return 0;
-}
-
-NodeImpl *TraversalImpl::findPreviousSibling(NodeImpl *node) const
-{
- if (!node)
- return 0;
- NodeImpl *n = node->previousSibling();
- while (n) {
- if (acceptNode(n) == NodeFilter::FILTER_ACCEPT)
- return n;
- n = n->previousSibling();
- }
- return 0;
-}
-
-NodeImpl *TraversalImpl::findNextSibling(NodeImpl *node) const
-{
- if (!node)
- return 0;
- NodeImpl *n = node->nextSibling();
- while (n) {
- if (acceptNode(n) == NodeFilter::FILTER_ACCEPT)
- return n;
- n = n->nextSibling();
- }
- return 0;
-}
-
-NodeImpl *TraversalImpl::findLastDescendant(NodeImpl *node) const
-{
- NodeImpl *n = node;
- NodeImpl *r = node;
- while (n) {
- short accepted = acceptNode(n);
- if (accepted != NodeFilter::FILTER_REJECT) {
- if (accepted == NodeFilter::FILTER_ACCEPT)
- r = n;
- if (n->lastChild())
- n = n->lastChild();
- else if (n != node && n->previousSibling())
- n = n->previousSibling();
- else
- break;
- }
- else
- break;
- }
- return r;
-}
-
-NodeImpl *TraversalImpl::findPreviousNode(NodeImpl *node) const
-{
- NodeImpl *n = node->previousSibling();
- while (n) {
- short accepted = acceptNode(n);
- if (accepted != NodeFilter::FILTER_REJECT) {
- NodeImpl *d = findLastDescendant(n);
- if (acceptNode(d) == NodeFilter::FILTER_ACCEPT)
- return d;
- // else FILTER_SKIP
- }
- n = n->previousSibling();
- }
- return findParentNode(node);
-}
-
-NodeImpl *TraversalImpl::findNextNode(NodeImpl *node) const
-{
- NodeImpl *n = node->firstChild();
- while (n) {
- switch (acceptNode(n)) {
- case NodeFilter::FILTER_ACCEPT:
- return n;
- case NodeFilter::FILTER_SKIP:
- if (n->firstChild())
- n = n->firstChild();
- else
- n = n->nextSibling();
- break;
- case NodeFilter::FILTER_REJECT:
- n = n->nextSibling();
- break;
- }
- }
-
- n = node->nextSibling();
- while (n) {
- switch (acceptNode(n)) {
- case NodeFilter::FILTER_ACCEPT:
- return n;
- case NodeFilter::FILTER_SKIP:
- return findNextNode(n);
- case NodeFilter::FILTER_REJECT:
- n = n->nextSibling();
- break;
- }
- }
-
- NodeImpl *parent = findParentNode(node, NodeFilter::FILTER_ACCEPT | NodeFilter::FILTER_SKIP);
- while (parent) {
- n = parent->nextSibling();
- while (n) {
- switch (acceptNode(n)) {
- case NodeFilter::FILTER_ACCEPT:
- return n;
- case NodeFilter::FILTER_SKIP:
- return findNextNode(n);
- case NodeFilter::FILTER_REJECT:
- n = n->nextSibling();
- break;
- }
- }
- parent = findParentNode(parent, NodeFilter::FILTER_ACCEPT | NodeFilter::FILTER_SKIP);
- }
-
- return 0;
-}
-
// --------------------------------------------------------------
NodeIteratorImpl::NodeIteratorImpl(NodeImpl *rootNode, long whatToShow, NodeFilterImpl *filter, bool expandEntityReferences)
@@ -260,6 +103,18 @@ NodeIteratorImpl::~NodeIteratorImpl()
}
}
+NodeImpl *NodeIteratorImpl::findNextNode(NodeImpl *node) const
+{
+ while ((node = node->traverseNextNode())) {
+ // NodeIterators treat the DOM tree as a flat list of nodes.
+ // In other words, FILTER_REJECT does not pass over descendants
+ // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP.
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT)
+ break;
+ }
+ return node;
+}
+
NodeImpl *NodeIteratorImpl::nextNode(int &exceptioncode)
{
if (detached()) {
@@ -267,41 +122,36 @@ NodeImpl *NodeIteratorImpl::nextNode(int &exceptioncode)
return 0;
}
- NodeImpl *result = 0;
- NodeImpl *refNode = referenceNode() ? referenceNode() : root();
-
- if (pointerBeforeReferenceNode() && acceptNode(refNode) == NodeFilter::FILTER_ACCEPT)
- result = refNode;
- else
- result = findNextNode(refNode);
-
- if (result)
- setReferenceNode(result);
+ NodeImpl *node = referenceNode() ? referenceNode() : root();
+ if (!pointerBeforeReferenceNode() || acceptNode(node) != NodeFilter::FILTER_ACCEPT)
+ node = findNextNode(node);
+ if (node)
+ setReferenceNode(node);
setPointerBeforeReferenceNode(false);
-
- return result;
+ return node;
}
-NodeImpl *NodeIteratorImpl::previousNode(int &exceptioncode)
+NodeImpl *NodeIteratorImpl::findPreviousNode(NodeImpl *node) const
{
- if (detached()) {
- exceptioncode = DOMException::INVALID_STATE_ERR;
- return 0;
+ while ((node = node->traversePreviousNode())) {
+ // NodeIterators treat the DOM tree as a flat list of nodes.
+ // In other words, FILTER_REJECT does not pass over descendants
+ // of the rejected node. Hence, FILTER_REJECT is the same as FILTER_SKIP.
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT)
+ break;
}
+ return node;
+}
- NodeImpl *result = 0;
- NodeImpl *refNode = referenceNode() ? referenceNode() : root();
-
- if (!pointerBeforeReferenceNode() && acceptNode(refNode) == NodeFilter::FILTER_ACCEPT)
- result = refNode;
- else
- result = findPreviousNode(refNode);
-
- if (result)
- setReferenceNode(result);
+NodeImpl *NodeIteratorImpl::previousNode(int &exceptioncode)
+{
+ NodeImpl *node = referenceNode() ? referenceNode() : root();
+ if (pointerBeforeReferenceNode() || acceptNode(node) != NodeFilter::FILTER_ACCEPT)
+ node = findPreviousNode(node);
+ if (node)
+ setReferenceNode(node);
setPointerBeforeReferenceNode();
-
- return result;
+ return node;
}
void NodeIteratorImpl::detach(int &/*exceptioncode*/)
@@ -447,58 +297,101 @@ void TreeWalkerImpl::setCurrentNode(NodeImpl *node)
NodeImpl *TreeWalkerImpl::parentNode()
{
- NodeImpl *node = findParentNode(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->parentNode(); node && node != root(); node = node->parentNode()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::firstChild()
{
- NodeImpl *node = findFirstChild(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->firstChild(); node; node = node->nextSibling()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::lastChild()
{
- NodeImpl *node = findLastChild(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->lastChild(); node; node = node->previousSibling()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::previousSibling()
{
- NodeImpl *node = findPreviousSibling(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->previousSibling(); node; node = node->previousSibling()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::nextSibling()
{
- NodeImpl *node = findNextSibling(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->nextSibling(); node; node = node->nextSibling()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::previousNode()
{
- NodeImpl *node = findPreviousNode(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->traversePreviousNode(); node; node = node->traversePreviousNode()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT && !ancestorRejected(node)) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
}
NodeImpl *TreeWalkerImpl::nextNode()
{
- NodeImpl *node = findNextNode(currentNode());
- if (node)
- setCurrentNode(node);
- return node;
+ NodeImpl *result = 0;
+ for (NodeImpl *node = currentNode()->traverseNextNode(); node; node = node->traverseNextNode()) {
+ if (acceptNode(node) == NodeFilter::FILTER_ACCEPT && !ancestorRejected(node)) {
+ setCurrentNode(node);
+ result = node;
+ break;
+ }
+ }
+ return result;
+}
+
+bool TreeWalkerImpl::ancestorRejected(const NodeImpl *node) const
+{
+ for (NodeImpl *a = node->parentNode(); a && a != root(); a = a->parentNode())
+ if (acceptNode(a) == NodeFilter::FILTER_REJECT)
+ return true;
+ return false;
}
} // namespace DOM
diff --git a/WebCore/khtml/xml/dom2_traversalimpl.h b/WebCore/khtml/xml/dom2_traversalimpl.h
index 7d3db19..5cc0e19 100644
--- a/WebCore/khtml/xml/dom2_traversalimpl.h
+++ b/WebCore/khtml/xml/dom2_traversalimpl.h
@@ -62,14 +62,6 @@ public:
NodeFilterImpl *filter() const { return m_filter; }
bool expandEntityReferences() const { return m_expandEntityReferences; }
- NodeImpl *findParentNode(NodeImpl *, short accept=NodeFilter::FILTER_ACCEPT) const;
- NodeImpl *findFirstChild(NodeImpl *) const;
- NodeImpl *findLastChild(NodeImpl *) const;
- NodeImpl *findNextSibling(NodeImpl *) const;
- NodeImpl *findPreviousSibling(NodeImpl *) const;
- NodeImpl *findNextNode(NodeImpl *) const;
- NodeImpl *findLastDescendant(NodeImpl *node) const;
- NodeImpl *findPreviousNode(NodeImpl *) const;
short acceptNode(NodeImpl *) const;
private:
@@ -112,6 +104,8 @@ private:
void setDetached(bool flag=true) { m_detached = flag; }
DocumentImpl * document() const { return m_doc; }
void setDocument(DocumentImpl *);
+ NodeImpl *findNextNode(NodeImpl *) const;
+ NodeImpl *findPreviousNode(NodeImpl *) const;
NodeImpl *m_referenceNode;
bool m_beforeReferenceNode;
@@ -143,6 +137,8 @@ private:
// convenience for when it is known there will be no exception
void setCurrentNode(NodeImpl *);
+ bool ancestorRejected(const NodeImpl *) const;
+
NodeImpl *m_current;
};
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list