KHtml

dom2_traversalimpl.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll <[email protected]>
5  * Copyright (C) 2000 Frederik Holljen <[email protected]>
6  * Copyright (C) 2001 Peter Kelly <[email protected]>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #ifndef _DOM2_TraversalImpl_h_
26 #define _DOM2_TraversalImpl_h_
27 
28 #include "dom/dom_node.h"
29 #include "dom/dom_misc.h"
30 #include "misc/shared.h"
31 #include "dom/dom2_traversal.h"
32 
33 namespace DOM
34 {
35 
36 class NodeImpl;
37 class DocumentImpl;
38 
39 class NodeIteratorImpl : public khtml::Shared<NodeIteratorImpl>
40 {
41 public:
42  NodeIteratorImpl(NodeImpl *_root, unsigned long _whatToShow, NodeFilterImpl *_filter, bool _entityReferenceExpansion);
43  ~NodeIteratorImpl();
44 
45  NodeImpl *root();
46  unsigned long whatToShow();
47  NodeFilterImpl *filter();
48  bool expandEntityReferences();
49 
50  SharedPtr<NodeImpl> nextNode(int &exceptioncode, void *&propagatedExceptionObject);
51  SharedPtr<NodeImpl> previousNode(int &exceptioncode, void *&propagatedExceptionObject);
52  void detach(int &exceptioncode);
53 
54  // pre-order traversal wrt to a node, captured w/in root
55  NodeImpl *getNextNode(NodeImpl *in);
56  NodeImpl *getPrevNode(NodeImpl *in);
57  NodeImpl *getLastNode(NodeImpl *in); //Last node in a tree..
58 
59  /**
60  * This function has to be called if you delete a node from the
61  * document tree and you want the Iterator to react if there
62  * are any changes concerning it.
63  */
64  void notifyBeforeNodeRemoval(NodeImpl *removed);
65 
66  short isAccepted(NodeImpl *n, void *&propagatedExceptionObject);
67 protected:
68  SharedPtr<NodeImpl> m_root; // must be kept alive for root() to be safe.
69  long m_whatToShow;
70  SharedPtr<NodeFilterImpl> m_filter;
71  bool m_expandEntityReferences;
72 
73  typedef enum { ITER_BEFORE_REF, ITER_AFTER_REF } Position;
74  Position m_position;
75  SharedPtr<NodeImpl> m_referenceNode;
76  bool m_detached;
77  DocumentImpl *m_doc;
78 };
79 
80 class NodeFilterImpl : public khtml::Shared<NodeFilterImpl>
81 {
82 public:
83  NodeFilterImpl();
84  virtual ~NodeFilterImpl();
85 
86  virtual bool isJSFilter() const;
87  virtual short acceptNode(const Node &n, void *&bindingsException);
88 
89  void setCustomNodeFilter(CustomNodeFilter *custom);
90  CustomNodeFilter *customNodeFilter();
91 protected:
92  CustomNodeFilter *m_customNodeFilter;
93 
94 };
95 
96 class TreeWalkerImpl : public khtml::Shared<TreeWalkerImpl>
97 {
98 public:
99  TreeWalkerImpl();
100  TreeWalkerImpl(const TreeWalkerImpl &other);
101  TreeWalkerImpl(NodeImpl *n, NodeFilter f);
102  TreeWalkerImpl(NodeImpl *n, long _whatToShow, NodeFilterImpl *f,
103  bool entityReferenceExpansion);
104  TreeWalkerImpl &operator = (const TreeWalkerImpl &other);
105 
106  ~TreeWalkerImpl();
107 
108  NodeImpl *getRoot() const;
109 
110  unsigned long getWhatToShow() const;
111 
112  NodeFilterImpl *getFilter() const;
113 
114  bool getExpandEntityReferences() const;
115 
116  NodeImpl *getCurrentNode() const;
117 
118  void setCurrentNode(NodeImpl *_currentNode, int &exceptionCode);
119 
120  NodeImpl *parentNode(void *&filterException);
121 
122  NodeImpl *firstChild(void *&filterException);
123 
124  NodeImpl *lastChild(void *&filterException);
125 
126  NodeImpl *previousSibling(void *&filterException);
127 
128  NodeImpl *nextSibling(void *&filterException);
129 
130  NodeImpl *previousNode(void *&filterException);
131 
132  NodeImpl *nextNode(void *&filterException);
133 
134  /**
135  * Sets which node types are to be presented via the TreeWalker
136  */
137  void setWhatToShow(long _whatToShow);
138  void setFilter(NodeFilterImpl *_filter);
139  void setExpandEntityReferences(bool value);
140 
141  typedef SharedPtr<NodeImpl> NodePtr; // lazy Maks...
142 
143  // These methods attempt to find the next node in given direction from
144  // the given reference point, w/o affecting the current node.
145  NodePtr getParentNode(NodePtr n, void *&filterException);
146  NodePtr getFirstChild(NodePtr n, void *&filterException);
147  NodePtr getLastChild(NodePtr n, void *&filterException);
148  NodePtr getPreviousSibling(NodePtr n, void *&filterException);
149  NodePtr getNextSibling(NodePtr n, void *&filterException);
150 
151  NodePtr getNextNode(void *&filterException);
152  NodePtr getPreviousNode(void *&filterException);
153 
154  short isAccepted(NodePtr n, void *&filterException);
155 
156 protected:
157  /**
158  * This attribute determines which node types are presented via
159  * the TreeWalker.
160  *
161  */
162  long m_whatToShow;
163 
164  /**
165  * The filter used to screen nodes.
166  *
167  */
168  NodeFilterImpl *m_filter;
169 
170  /**
171  * The value of this flag determines whether entity reference
172  * nodes are expanded. To produce a view of the document that has
173  * entity references expanded and does not expose the entity
174  * reference node itself, use the whatToShow flags to hide the
175  * entity reference node and set expandEntityReferences to true
176  * when creating the iterator. To produce a view of the document
177  * that has entity reference nodes but no entity expansion, use
178  * the whatToShow flags to show the entity reference node and set
179  * expandEntityReferences to true.
180  *
181  * This is not implemented (always true)
182  */
183  bool m_expandEntityReferences;
184 
185  /**
186  * The current node.
187  *
188  * The value must not be null. Attempting to set it to null will
189  * raise a NOT_SUPPORTED_ERR exception. When setting a node, the
190  * whatToShow flags and any Filter associated with the TreeWalker
191  * are not checked. The currentNode may be set to any Node of any
192  * type.
193  *
194  */
195  SharedPtr<NodeImpl> m_currentNode;
196  SharedPtr<NodeImpl> m_rootNode;
197  DocumentImpl *m_doc; // always alive as long as the root is...
198 };
199 
200 } // namespace
201 
202 #endif
203 
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
This library provides a full-featured HTML parser and widget.
MESSAGECORE_EXPORT KMime::Content * nextSibling(const KMime::Content *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.