KHtml

dom_nodelistimpl.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll ([email protected])
5  * (C) 1999 Antti Koivisto ([email protected])
6  * (C) 2001 Dirk Mueller ([email protected])
7  * (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
8  * (C) 2007 David Smith ([email protected])
9  * (C) 2005, 2009 Maksim Orlovich ([email protected])
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB. If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  *
26  * The code for ClassNodeListImpl was originally licensed under the following terms
27  * (but in this version is available only as above):
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions
30  * are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright
33  * notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  * notice, this list of conditions and the following disclaimer in the
36  * documentation and/or other materials provided with the distribution.
37  * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
38  * its contributors may be used to endorse or promote products derived
39  * from this software without specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
42  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
45  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
50  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  */
52 #ifndef _DOM_NodeListImpl_h_
53 #define _DOM_NodeListImpl_h_
54 
55 #include "dom/dom_string.h"
56 #include "misc/shared.h"
57 #include "misc/htmlnames.h"
58 #include "ClassNames.h"
59 
60 namespace DOM
61 {
62 
63 class NodeImpl;
64 class DocumentImpl;
65 
66 class NodeListImpl : public khtml::Shared<NodeListImpl>
67 {
68 public:
69  // DOM methods & attributes for NodeList
70  virtual unsigned long length() const = 0;
71  virtual NodeImpl *item(unsigned long index) const = 0;
72 
73  virtual ~NodeListImpl() {}
74 };
75 
76 class DynamicNodeListImpl : public NodeListImpl
77 {
78 public:
79  //Type of the item stored in the cache.
80  enum Type {
81  UNCACHEABLE, // Too complex to remember in document -- we still track the position
82  CHILD_NODES,
83  LAST_NODE_LIST = CHILD_NODES
84  };
85 
86  struct CacheKey {
87  NodeImpl *baseNode;
88  int type;
89 
90  CacheKey(): type(UNCACHEABLE) {}
91 
92  CacheKey(NodeImpl *_baseNode, int _type):
93  baseNode(_baseNode), type(_type)
94  {}
95 
96  int hash() const
97  {
98  return int(reinterpret_cast<quintptr>(baseNode) >> 2) ^
99  (unsigned(type) << 26);
100  }
101 
102  bool operator==(const CacheKey &other) const
103  {
104  return baseNode == other.baseNode &&
105  type == other.type;
106  }
107  };
108 
109  struct Cache: public khtml::Shared<Cache> {
110  static Cache *makeStructuralOnly();
111  static Cache *makeNameOrID();
112  static Cache *makeClassName();
113 
114  Cache(unsigned short relSecondaryVer);
115 
116  CacheKey key;//### We must store this in here due to QCache in Qt3 sucking
117 
118  unsigned int version; // structural version.
119  unsigned int secondaryVersion;
120  union {
121  NodeImpl *node;
122  unsigned int index;
123  } current;
124  unsigned int position;
125  unsigned int length;
126  bool hasLength;
127  unsigned short relevantSecondaryVer;
128 
129  void updateNodeListInfo(DocumentImpl *doc);
130 
131  virtual void clear(DocumentImpl *doc);
132  virtual ~Cache();
133  };
134 
135  typedef Cache *CacheFactory();
136 
137  DynamicNodeListImpl(NodeImpl *node, int type, CacheFactory *factory);
138  virtual ~DynamicNodeListImpl();
139 
140  // DOM methods & attributes for NodeList
141  unsigned long length() const override;
142  NodeImpl *item(unsigned long index) const override;
143 
144  // Other methods (not part of DOM)
145 
146 protected:
147  virtual unsigned long calcLength(NodeImpl *start) const;
148  // helper functions for searching all ElementImpls in a tree
149 
150  NodeImpl *recursiveItem(NodeImpl *absStart, NodeImpl *start, unsigned long &offset) const;
151  NodeImpl *recursiveItemBack(NodeImpl *absStart, NodeImpl *start, unsigned long &offset) const;
152 
153  // Override this to determine what nodes to return. Set doRecurse to
154  // false if the children of this node do not need to be entered.
155  virtual bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const = 0;
156 
157  NodeImpl *m_refNode;
158  mutable Cache *m_cache;
159 };
160 
161 class ChildNodeListImpl : public DynamicNodeListImpl
162 {
163 public:
164 
165  ChildNodeListImpl(NodeImpl *n);
166 
167 protected:
168  bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
169 };
170 
174 class TagNodeListImpl : public DynamicNodeListImpl
175 {
176 public:
177  TagNodeListImpl(NodeImpl *n, NamespaceName namespaceName, LocalName localName, PrefixName);
178  TagNodeListImpl(NodeImpl *n, const DOMString &namespaceURI, const DOMString &localName);
179 
180  // Other methods (not part of DOM)
181 
182 protected:
183  bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
184  NamespaceName m_namespace;
185  LocalName m_localName;
186  PrefixName m_prefix;
187 
188  bool m_namespaceAware;
189 };
190 
194 class NameNodeListImpl : public DynamicNodeListImpl
195 {
196 public:
197  NameNodeListImpl(NodeImpl *doc, const DOMString &t);
198 
199  // Other methods (not part of DOM)
200 
201 protected:
202  bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
203 
204  DOMString nodeName;
205 };
206 
208 class ClassNodeListImpl : public DynamicNodeListImpl
209 {
210 public:
211  ClassNodeListImpl(NodeImpl *rootNode, const DOMString &classNames);
212 
213 private:
214  bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
215 
216  ClassNames m_classNames;
217 };
218 
219 class StaticNodeListImpl : public NodeListImpl
220 {
221 public:
222  StaticNodeListImpl();
223  ~StaticNodeListImpl();
224 
225  // Implementation of the NodeList API
226  unsigned long length() const override;
227  NodeImpl *item(unsigned long index) const override;
228 
229  // Methods specific to StaticNodeList
230  void append(NodeImpl *n);
231  NodeImpl *first()
232  {
233  return item(0);
234  }
235  bool isEmpty() const
236  {
237  return length() == 0;
238  }
239 
240  // For XPath, we may have collection nodes that are either ordered
241  // by the axis, are in random order, or strongly normalized. We represent
242  // this knowledge by this enum
243  enum NormalizationKind {
244  Unnormalized,
245  AxisOrder,
246  DocumentOrder
247  };
248 
249  // If the list isn't up to the given level of normalization, put it into
250  // document order. Note that if we're asked for AxisOrder but have
251  // DocumentOrder already, it's left to be.
252  void normalizeUpto(NormalizationKind kind);
253 
254  // Reports to list outside knowledge of how normalized the data currently is.
255  void setKnownNormalization(NormalizationKind kind);
256 
257  NormalizationKind knownNormalization() const;
258 private:
259  WTF::Vector<SharedPtr<NodeImpl> > m_kids;
260  NormalizationKind m_knownNormalization;
261 };
262 
263 } //namespace
264 #endif
NodeList which lists all Nodes in a document with a given tag name.
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
Type type(const QSqlDatabase &db)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This library provides a full-featured HTML parser and widget.
For getElementsByClassName.
NodeList which lists all Nodes in a Element with a given "name=" tag.
KDB_EXPORT KDbVersionInfo version()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 22:46:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.