Commit f6ea03ef authored by kocienda's avatar kocienda

WebCore:

        Reviewed by Hyatt

        Implemented DOM traversal objects, NodeIterator and TreeWalker.

        * WebCore-combined.exp: Regenerate
        * WebCore.exp: Export DOMNodeFilter protocol
        * khtml/dom/dom2_traversal.cpp: Completed half-done implementation pulled from KDE tree.
        * khtml/dom/dom2_traversal.h: Ditto.
        * khtml/dom/dom_doc.cpp:
        (DOM::Document::createNodeIterator): Ditto.
        (DOM::Document::createTreeWalker): Ditto.
        * khtml/dom/dom_doc.h: Ditto.
        * khtml/ecma/kjs_dom.cpp:
        (DOMDocumentProtoFunc::tryCall): Fix cases that create traversal objects.
        * khtml/ecma/kjs_traversal.cpp:
        (DOMNodeIterator::getValueProperty): Add referenceNode and pointerBeforeReferenceNode
        properties to node interator.
        (DOMTreeWalkerProtoFunc::tryCall): Fix typo where DOMTreeWalker::PreviousNode case called previousSibling function.
        (JSNodeFilterCondition::JSNodeFilterCondition): Implement JS glue class for node filter conditions.
        (JSNodeFilterCondition::acceptNode): Ditto.
        * khtml/ecma/kjs_traversal.h:
        (KJS::DOMNodeIterator::): Add ReferenceNode and PointerBeforeReferenceNode constants.
        * khtml/ecma/kjs_traversal.lut.h:
        (KJS::): Regenerated
        * khtml/xml/dom2_traversalimpl.cpp: Completed half-done implementation pulled from KDE tree.
        * khtml/xml/dom2_traversalimpl.h: Ditto.
        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::createNodeIterator): Ditto.
        (DocumentImpl::createTreeWalker): Ditto.
        * khtml/xml/dom_docimpl.h: Ditto.
        * khtml/xml/dom_nodeimpl.cpp:
        (NodeImpl::checkAddChild): Patched due to change in isAncestor function. This was the one pre-existing caller.
        (NodeImpl::isAncestor): Changed so that it does not return true for itself: node->isAncestor(node) now returns false.
        * khtml/xml/dom_nodeimpl.h: Made isAncestor const.
        * kwq/DOM.mm: Implemented obj-c glue for traversal objects.
        * kwq/DOMInternal.h: Ditto.
        * kwq/DOMTraversal.h: Ditto.

WebKit:

        Reviewed by Hyatt

        * DOM.subproj/DOMTraversal.h: File coppied from WebCore


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6535 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0f8f2530
2004-05-04 Ken Kocienda <kocienda@apple.com>
Reviewed by Hyatt
Implemented DOM traversal objects, NodeIterator and TreeWalker.
* WebCore-combined.exp: Regenerate
* WebCore.exp: Export DOMNodeFilter protocol
* khtml/dom/dom2_traversal.cpp: Completed half-done implementation pulled from KDE tree.
* khtml/dom/dom2_traversal.h: Ditto.
* khtml/dom/dom_doc.cpp:
(DOM::Document::createNodeIterator): Ditto.
(DOM::Document::createTreeWalker): Ditto.
* khtml/dom/dom_doc.h: Ditto.
* khtml/ecma/kjs_dom.cpp:
(DOMDocumentProtoFunc::tryCall): Fix cases that create traversal objects.
* khtml/ecma/kjs_traversal.cpp:
(DOMNodeIterator::getValueProperty): Add referenceNode and pointerBeforeReferenceNode
properties to node interator.
(DOMTreeWalkerProtoFunc::tryCall): Fix typo where DOMTreeWalker::PreviousNode case called previousSibling function.
(JSNodeFilterCondition::JSNodeFilterCondition): Implement JS glue class for node filter conditions.
(JSNodeFilterCondition::acceptNode): Ditto.
* khtml/ecma/kjs_traversal.h:
(KJS::DOMNodeIterator::): Add ReferenceNode and PointerBeforeReferenceNode constants.
* khtml/ecma/kjs_traversal.lut.h:
(KJS::): Regenerated
* khtml/xml/dom2_traversalimpl.cpp: Completed half-done implementation pulled from KDE tree.
* khtml/xml/dom2_traversalimpl.h: Ditto.
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::createNodeIterator): Ditto.
(DocumentImpl::createTreeWalker): Ditto.
* khtml/xml/dom_docimpl.h: Ditto.
* khtml/xml/dom_nodeimpl.cpp:
(NodeImpl::checkAddChild): Patched due to change in isAncestor function. This was the one pre-existing caller.
(NodeImpl::isAncestor): Changed so that it does not return true for itself: node->isAncestor(node) now returns false.
* khtml/xml/dom_nodeimpl.h: Made isAncestor const.
* kwq/DOM.mm: Implemented obj-c glue for traversal objects.
* kwq/DOMInternal.h: Ditto.
* kwq/DOMTraversal.h: Ditto.
2004-05-04 Darin Adler <darin@apple.com>
Reviewed by Ken.
......
.objc_class_name_DOMImplementation
.objc_class_name_DOMNode
.objc_class_name_DOMNodeFilter
.objc_class_name_DOMNodeList
.objc_class_name_DOMNamedNodeMap
.objc_class_name_DOMCharacterData
......
......@@ -865,7 +865,7 @@
isa = PBXShellScriptBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ -f ../Tools/Scripts/embed-into-alex ]; then sh ../Tools/Scripts/embed-into-alex; fi";
shellScript = "#if [ -f ../Tools/Scripts/embed-into-alex ]; then sh ../Tools/Scripts/embed-into-alex; fi";
};
//250
//251
......
......@@ -20,360 +20,330 @@
*
*/
#include "dom/dom2_traversal.h"
#include "dom/dom_exception.h"
#include "dom/dom_string.h"
#include "xml/dom2_traversalimpl.h"
using namespace DOM;
NodeIterator::NodeIterator()
{
impl = 0;
}
NodeIterator::NodeIterator(const NodeIterator &other)
{
impl = other.impl;
if (impl) impl->ref();
}
namespace DOM {
NodeIterator::NodeIterator(NodeIteratorImpl *i)
{
impl = i;
if (impl) impl->ref();
}
NodeIterator &NodeIterator::operator = (const NodeIterator &other)
{
if ( impl != other.impl ) {
if (impl) impl->deref();
impl = other.impl;
if (impl) impl->ref();
}
return *this;
}
NodeIterator::~NodeIterator()
{
if (impl) impl->deref();
}
// --------------------------------------------------------------
Node NodeIterator::root()
short NodeFilterCondition::acceptNode(const Node &) const
{
if (impl) return impl->root();
return 0;
return NodeFilter::FILTER_ACCEPT;
}
unsigned long NodeIterator::whatToShow()
{
if (impl) return impl->whatToShow();
return 0;
}
// --------------------------------------------------------------
NodeFilter NodeIterator::filter()
NodeFilter::NodeFilter() : impl(0)
{
if (impl) return impl->filter();
return 0;
}
bool NodeIterator::expandEntityReferences()
NodeFilter::NodeFilter(NodeFilterCondition *condition)
{
if (impl) return impl->expandEntityReferences();
return 0;
impl = new NodeFilterImpl(condition);
impl->ref();
}
Node NodeIterator::nextNode( )
NodeFilter::NodeFilter(const NodeFilter &other)
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
int exceptioncode = 0;
NodeImpl *r = impl->nextNode(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return r;
impl = other.impl;
if (impl)
impl->ref();
}
Node NodeIterator::previousNode( )
NodeFilter::NodeFilter(NodeFilterImpl *i)
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
int exceptioncode = 0;
NodeImpl *r = impl->previousNode(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return r;
impl = i;
if (impl)
impl->ref();
}
void NodeIterator::detach()
NodeFilter &NodeFilter::operator=(const NodeFilter &other)
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
if (impl == other.impl)
return *this;
NodeFilterImpl *old = impl;
impl = other.impl;
if (impl)
impl->ref();
if (old)
old->deref();
int exceptioncode = 0;
impl->detach(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return *this;
}
NodeIteratorImpl *NodeIterator::handle() const
NodeFilter::~NodeFilter()
{
return impl;
if (impl)
impl->deref();
}
bool NodeIterator::isNull() const
short NodeFilter::acceptNode(const Node &node) const
{
return (impl == 0);
if (impl)
return impl->acceptNode(node.handle());
return FILTER_ACCEPT;
}
// -----------------------------------------------------------
// --------------------------------------------------------------
NodeFilter::NodeFilter()
NodeIterator::NodeIterator()
{
impl = 0;
}
NodeFilter::NodeFilter(const NodeFilter &other)
NodeIterator::NodeIterator(const NodeIterator &other)
{
impl = other.impl;
if (impl) impl->ref();
if (impl)
impl->ref();
}
NodeFilter::NodeFilter(NodeFilterImpl *i)
NodeIterator::NodeIterator(NodeIteratorImpl *i)
{
impl = i;
if (impl) impl->ref();
if (impl)
impl->ref();
}
NodeFilter &NodeFilter::operator = (const NodeFilter &other)
NodeIterator &NodeIterator::operator=(const NodeIterator &other)
{
if ( impl != other.impl ) {
if (impl) impl->deref();
impl = other.impl;
if (impl) impl->ref();
}
if (impl == other.impl)
return *this;
NodeIteratorImpl *old = impl;
impl = other.impl;
if (impl)
impl->ref();
if (old)
old->deref();
return *this;
}
NodeFilter::~NodeFilter()
NodeIterator::~NodeIterator()
{
if (impl) impl->deref();
if (impl)
impl->deref();
}
short NodeFilter::acceptNode(const Node &n)
Node NodeIterator::root() const
{
if (impl) return impl->acceptNode(n);
if (impl)
return impl->root();
return 0;
}
void NodeFilter::setCustomNodeFilter(CustomNodeFilter *custom)
unsigned long NodeIterator::whatToShow() const
{
if (impl) impl->setCustomNodeFilter(custom);
}
CustomNodeFilter *NodeFilter::customNodeFilter()
{
if (impl) return impl->customNodeFilter();
if (impl)
return impl->whatToShow();
return 0;
}
NodeFilterImpl *NodeFilter::handle() const
NodeFilter NodeIterator::filter() const
{
return impl;
if (impl)
return impl->filter();
return NodeFilter();
}
bool NodeFilter::isNull() const
bool NodeIterator::expandEntityReferences() const
{
return (impl == 0);
if (impl)
return impl->expandEntityReferences();
return 0;
}
NodeFilter NodeFilter::createCustom(CustomNodeFilter *custom)
Node NodeIterator::nextNode()
{
NodeFilterImpl *i = new NodeFilterImpl();
i->setCustomNodeFilter(custom);
return i;
}
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
// --------------------------------------------------------------
CustomNodeFilter::CustomNodeFilter()
{
impl = 0;
int exceptioncode = 0;
NodeImpl *result = impl->nextNode(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return result;
}
CustomNodeFilter::~CustomNodeFilter()
Node NodeIterator::previousNode()
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
int exceptioncode = 0;
NodeImpl *result = impl->previousNode(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return result;
}
short CustomNodeFilter::acceptNode (const Node &/*n*/)
void NodeIterator::detach()
{
return NodeFilter::FILTER_ACCEPT;
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
int exceptioncode = 0;
impl->detach(exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
}
bool CustomNodeFilter::isNull()
Node NodeIterator::referenceNode() const
{
return false;
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
return impl->referenceNode();
}
DOMString CustomNodeFilter::customNodeFilterType()
bool NodeIterator::pointerBeforeReferenceNode() const
{
return "";
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
return impl->pointerBeforeReferenceNode();
}
// --------------------------------------------------------------
TreeWalker::TreeWalker() {
TreeWalker::TreeWalker()
{
impl = 0;
}
TreeWalker::TreeWalker(const TreeWalker &other) {
TreeWalker::TreeWalker(const TreeWalker &other)
{
impl = other.impl;
if (impl) impl->ref();
if (impl)
impl->ref();
}
TreeWalker::TreeWalker(TreeWalkerImpl *i)
{
impl = i;
if (impl) impl->ref();
if (impl)
impl->ref();
}
TreeWalker & TreeWalker::operator = (const TreeWalker &other)
TreeWalker &TreeWalker::operator=(const TreeWalker &other)
{
if ( impl != other.impl ) {
if (impl) impl->deref();
impl = other.impl;
if (impl) impl->ref();
}
if (impl == other.impl)
return *this;
TreeWalkerImpl *old = impl;
impl = other.impl;
if (impl)
impl->ref();
if (old)
old->deref();
return *this;
}
TreeWalker::~TreeWalker()
{
if (impl) impl->deref();
if (impl)
impl->deref();
}
Node TreeWalker::root()
Node TreeWalker::root() const
{
if (impl) return impl->getRoot();
if (impl)
return impl->root();
return 0;
}
unsigned long TreeWalker::whatToShow()
unsigned long TreeWalker::whatToShow() const
{
if (impl) return impl->getWhatToShow();
if (impl)
return impl->whatToShow();
return 0;
}
NodeFilter TreeWalker::filter()
NodeFilter TreeWalker::filter() const
{
if (impl) return impl->getFilter();
return 0;
if (impl)
return impl->filter();
return NodeFilter();
}
bool TreeWalker::expandEntityReferences()
bool TreeWalker::expandEntityReferences() const
{
if (impl) return impl->getExpandEntityReferences();
if (impl) return impl->expandEntityReferences();
return false;
}
Node TreeWalker::currentNode()
Node TreeWalker::currentNode() const
{
if (impl) return impl->getCurrentNode();
if (impl)
return impl->currentNode();
return 0;
}
void TreeWalker::setCurrentNode(const Node _currentNode)
void TreeWalker::setCurrentNode(const Node &node)
{
if (impl) impl->setCurrentNode(_currentNode);
if (impl) {
int exceptioncode = 0;
impl->setCurrentNode(node.handle(), exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
}
}
Node TreeWalker::parentNode()
{
if (impl) return impl->parentNode();
if (impl)
return impl->parentNode();
return 0;
}
Node TreeWalker::firstChild()
{
if (impl) return impl->firstChild();
if (impl)
return impl->firstChild();
return 0;
}
Node TreeWalker::lastChild()
{
if (impl) return impl->lastChild();
if (impl)
return impl->lastChild();
return 0;
}
Node TreeWalker::previousSibling()
{
if (impl) return impl->previousSibling();
if (impl)
return impl->previousSibling();
return 0;
}
Node TreeWalker::nextSibling()
{
if (impl) return impl->nextSibling();
if (impl)
return impl->nextSibling();
return 0;
}
Node TreeWalker::previousNode()
{
if (impl) return impl->previousNode();
if (impl)
return impl->previousNode();
return 0;
}
Node TreeWalker::nextNode()
{
if (impl) return impl->nextNode();
if (impl)
return impl->nextNode();
return 0;
}
TreeWalkerImpl *TreeWalker::handle() const
{
return impl;
}
bool TreeWalker::isNull() const
{
return (impl == 0);
}
// -----------------------------------------------------------------------
/*DocumentTraversal::DocumentTraversal()
{
}
DocumentTraversal::DocumentTraversal(const DocumentTraversal &other)
{
}
DocumentTraversal &DocumentTraversal::operator = (const DocumentTraversal &other)
{
DocumentTraversal::operator = (other);
return *this;
}
DocumentTraversal::~DocumentTraversal()
{
}
NodeIterator DocumentTraversal::createNodeIterator( const Node &root, long whatToShow,
const NodeFilter &filter,
bool entityReferenceExpansion )
{
return NodeIterator();
}
TreeWalker DocumentTraversal::createTreeWalker( const Node &root, long whatToShow,
const NodeFilter &filter,
bool entityReferenceExpansion )
{
return TreeWalker();
}
*/
} // namespace DOM
This diff is collapsed.
......@@ -367,25 +367,32 @@ Range Document::createRange()
return 0;
}
NodeIterator Document::createNodeIterator(Node root, unsigned long whatToShow,
NodeFilter filter, bool entityReferenceExpansion)
NodeIterator Document::createNodeIterator(const Node &root, unsigned long whatToShow,
const NodeFilter &filter, bool expandEntityReferences)
{
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);
throw DOMException(DOMException::INVALID_STATE_ERR);
int exceptioncode = 0;
NodeIteratorImpl *r = static_cast<DocumentImpl*>(impl)->createNodeIterator(root.handle(),
whatToShow,filter,entityReferenceExpansion,exceptioncode);
NodeIteratorImpl *result = static_cast<DocumentImpl*>(impl)->createNodeIterator(root.handle(), whatToShow,
filter.handle(), expandEntityReferences, exceptioncode);
if (exceptioncode)
throw DOMException(exceptioncode);
return r;
throw DOMException(exceptioncode);
return result;
}
TreeWalker Document::createTreeWalker(Node root, unsigned long whatToShow, NodeFilter filter,
bool entityReferenceExpansion)
TreeWalker Document::createTreeWalker(const Node &root, unsigned long whatToShow,
const NodeFilter &filter, bool expandEntityReferences)
{
if (impl) return ((DocumentImpl *)impl)->createTreeWalker(root,whatToShow,filter,entityReferenceExpansion);
return 0;
if (!impl)
throw DOMException(DOMException::INVALID_STATE_ERR);