File indexing completed on 2024-05-05 12:16:51
0001 /* 0002 * util.h - Copyright 2005 Frerich Raabe <raabe@kde.org> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 #ifndef UTIL_H 0026 #define UTIL_H 0027 0028 #include <QList> 0029 #include <misc/shared.h> 0030 #include <dom/dom_string.h> 0031 0032 namespace DOM 0033 { 0034 class NodeImpl; 0035 class StaticNodeListImpl; 0036 } 0037 0038 namespace khtml 0039 { 0040 namespace XPath 0041 { 0042 0043 // ### removeme 0044 typedef SharedPtr<DOM::StaticNodeListImpl> DomNodeList; 0045 0046 /* @return whether the given node is the root node. 0047 */ 0048 bool isRootDomNode(DOM::NodeImpl *node); 0049 0050 /* @return the 'string-value' of the given node as specified by 0051 https://www.w3.org/TR/xpath 0052 */ 0053 DOM::DOMString stringValue(DOM::NodeImpl *node); 0054 0055 /* @return append all descendant nodes of the given node, in document order, 0056 to the given set 0057 */ 0058 void collectChildrenRecursively(SharedPtr<DOM::StaticNodeListImpl> out, 0059 DOM::NodeImpl *root); 0060 0061 /* this one is in reverse order */ 0062 void collectChildrenReverse(SharedPtr<DOM::StaticNodeListImpl> out, 0063 DOM::NodeImpl *root); 0064 0065 /* @return whether the given node is a valid context node 0066 */ 0067 bool isValidContextNode(DOM::NodeImpl *node); 0068 0069 /* @returns the parent node of the given node under the XPath model 0070 (which has some additional links that DOM doesn't 0071 */ 0072 DOM::NodeImpl *xpathParentNode(DOM::NodeImpl *node); 0073 0074 /* @returns the first/last kid of the given node under the XPath model, 0075 which doesn't have text nodes or the likes under attributes 0076 */ 0077 DOM::NodeImpl *xpathFirstChild(DOM::NodeImpl *node); 0078 DOM::NodeImpl *xpathLastChild(DOM::NodeImpl *node); 0079 0080 /* @returns a slightly generalized notion of a sibling needed to implement 0081 the following axis. Essentially, for that axis, and only that axis, 0082 if we have something like this: 0083 <node attr1 attr2><kid></node> 0084 the <kid> is considered to be the next thing following attr1 0085 */ 0086 DOM::NodeImpl *nextSiblingForFollowing(DOM::NodeImpl *node); 0087 0088 // Enable for some low debug output. 0089 // #define XPATH_VERBOSE 0090 0091 } // namespace XPath 0092 0093 } // namespace khtml 0094 0095 #endif // UTIL_H 0096