File indexing completed on 2024-05-05 16:11:35
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 1999 Lars Knoll <knoll@kde.org> 0005 * Copyright (C) 2000 Frederik Holljen <frederik.holljen@hig.no> 0006 * Copyright (C) 2001 Peter Kelly <pmk@post.com> 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 * 0023 */ 0024 0025 #ifndef _DOM2_TraversalImpl_h_ 0026 #define _DOM2_TraversalImpl_h_ 0027 0028 #include "dom/dom_node.h" 0029 #include "dom/dom_misc.h" 0030 #include "misc/shared.h" 0031 #include "dom/dom2_traversal.h" 0032 0033 namespace DOM 0034 { 0035 0036 class NodeImpl; 0037 class DocumentImpl; 0038 0039 class NodeIteratorImpl : public khtml::Shared<NodeIteratorImpl> 0040 { 0041 public: 0042 NodeIteratorImpl(NodeImpl *_root, unsigned long _whatToShow, NodeFilterImpl *_filter, bool _entityReferenceExpansion); 0043 ~NodeIteratorImpl(); 0044 0045 NodeImpl *root(); 0046 unsigned long whatToShow(); 0047 NodeFilterImpl *filter(); 0048 bool expandEntityReferences(); 0049 0050 SharedPtr<NodeImpl> nextNode(int &exceptioncode, void *&propagatedExceptionObject); 0051 SharedPtr<NodeImpl> previousNode(int &exceptioncode, void *&propagatedExceptionObject); 0052 void detach(int &exceptioncode); 0053 0054 // pre-order traversal wrt to a node, captured w/in root 0055 NodeImpl *getNextNode(NodeImpl *in); 0056 NodeImpl *getPrevNode(NodeImpl *in); 0057 NodeImpl *getLastNode(NodeImpl *in); //Last node in a tree.. 0058 0059 /** 0060 * This function has to be called if you delete a node from the 0061 * document tree and you want the Iterator to react if there 0062 * are any changes concerning it. 0063 */ 0064 void notifyBeforeNodeRemoval(NodeImpl *removed); 0065 0066 short isAccepted(NodeImpl *n, void *&propagatedExceptionObject); 0067 protected: 0068 SharedPtr<NodeImpl> m_root; // must be kept alive for root() to be safe. 0069 long m_whatToShow; 0070 SharedPtr<NodeFilterImpl> m_filter; 0071 bool m_expandEntityReferences; 0072 0073 typedef enum { ITER_BEFORE_REF, ITER_AFTER_REF } Position; 0074 Position m_position; 0075 SharedPtr<NodeImpl> m_referenceNode; 0076 bool m_detached; 0077 DocumentImpl *m_doc; 0078 }; 0079 0080 class NodeFilterImpl : public khtml::Shared<NodeFilterImpl> 0081 { 0082 public: 0083 NodeFilterImpl(); 0084 virtual ~NodeFilterImpl(); 0085 0086 virtual bool isJSFilter() const; 0087 virtual short acceptNode(const Node &n, void *&bindingsException); 0088 0089 void setCustomNodeFilter(CustomNodeFilter *custom); 0090 CustomNodeFilter *customNodeFilter(); 0091 protected: 0092 CustomNodeFilter *m_customNodeFilter; 0093 0094 }; 0095 0096 class TreeWalkerImpl : public khtml::Shared<TreeWalkerImpl> 0097 { 0098 public: 0099 TreeWalkerImpl(); 0100 TreeWalkerImpl(const TreeWalkerImpl &other); 0101 TreeWalkerImpl(NodeImpl *n, NodeFilter f); 0102 TreeWalkerImpl(NodeImpl *n, long _whatToShow, NodeFilterImpl *f, 0103 bool entityReferenceExpansion); 0104 TreeWalkerImpl &operator = (const TreeWalkerImpl &other); 0105 0106 ~TreeWalkerImpl(); 0107 0108 NodeImpl *getRoot() const; 0109 0110 unsigned long getWhatToShow() const; 0111 0112 NodeFilterImpl *getFilter() const; 0113 0114 bool getExpandEntityReferences() const; 0115 0116 NodeImpl *getCurrentNode() const; 0117 0118 void setCurrentNode(NodeImpl *_currentNode, int &exceptionCode); 0119 0120 NodeImpl *parentNode(void *&filterException); 0121 0122 NodeImpl *firstChild(void *&filterException); 0123 0124 NodeImpl *lastChild(void *&filterException); 0125 0126 NodeImpl *previousSibling(void *&filterException); 0127 0128 NodeImpl *nextSibling(void *&filterException); 0129 0130 NodeImpl *previousNode(void *&filterException); 0131 0132 NodeImpl *nextNode(void *&filterException); 0133 0134 /** 0135 * Sets which node types are to be presented via the TreeWalker 0136 */ 0137 void setWhatToShow(long _whatToShow); 0138 void setFilter(NodeFilterImpl *_filter); 0139 void setExpandEntityReferences(bool value); 0140 0141 typedef SharedPtr<NodeImpl> NodePtr; // lazy Maks... 0142 0143 // These methods attempt to find the next node in given direction from 0144 // the given reference point, w/o affecting the current node. 0145 NodePtr getParentNode(NodePtr n, void *&filterException); 0146 NodePtr getFirstChild(NodePtr n, void *&filterException); 0147 NodePtr getLastChild(NodePtr n, void *&filterException); 0148 NodePtr getPreviousSibling(NodePtr n, void *&filterException); 0149 NodePtr getNextSibling(NodePtr n, void *&filterException); 0150 0151 NodePtr getNextNode(void *&filterException); 0152 NodePtr getPreviousNode(void *&filterException); 0153 0154 short isAccepted(NodePtr n, void *&filterException); 0155 0156 protected: 0157 /** 0158 * This attribute determines which node types are presented via 0159 * the TreeWalker. 0160 * 0161 */ 0162 long m_whatToShow; 0163 0164 /** 0165 * The filter used to screen nodes. 0166 * 0167 */ 0168 NodeFilterImpl *m_filter; 0169 0170 /** 0171 * The value of this flag determines whether entity reference 0172 * nodes are expanded. To produce a view of the document that has 0173 * entity references expanded and does not expose the entity 0174 * reference node itself, use the whatToShow flags to hide the 0175 * entity reference node and set expandEntityReferences to true 0176 * when creating the iterator. To produce a view of the document 0177 * that has entity reference nodes but no entity expansion, use 0178 * the whatToShow flags to show the entity reference node and set 0179 * expandEntityReferences to true. 0180 * 0181 * This is not implemented (always true) 0182 */ 0183 bool m_expandEntityReferences; 0184 0185 /** 0186 * The current node. 0187 * 0188 * The value must not be null. Attempting to set it to null will 0189 * raise a NOT_SUPPORTED_ERR exception. When setting a node, the 0190 * whatToShow flags and any Filter associated with the TreeWalker 0191 * are not checked. The currentNode may be set to any Node of any 0192 * type. 0193 * 0194 */ 0195 SharedPtr<NodeImpl> m_currentNode; 0196 SharedPtr<NodeImpl> m_rootNode; 0197 DocumentImpl *m_doc; // always alive as long as the root is... 0198 }; 0199 0200 } // namespace 0201 0202 #endif 0203