File indexing completed on 2024-04-28 15:22:57
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright 1999 Lars Knoll (knoll@kde.org) 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 * 0021 * This file includes excerpts from the Document Object Model (DOM) 0022 * Level 1 Specification (Recommendation) 0023 * https://www.w3.org/TR/REC-DOM-Level-1/ 0024 * Copyright © World Wide Web Consortium , (Massachusetts Institute of 0025 * Technology , Institut National de Recherche en Informatique et en 0026 * Automatique , Keio University ). All Rights Reserved. 0027 * 0028 */ 0029 #ifndef _DOM_Node_h_ 0030 #define _DOM_Node_h_ 0031 0032 #include <khtml_export.h> 0033 #include <QString> 0034 0035 class QRect; 0036 0037 namespace KJS 0038 { 0039 class HTMLDocument; 0040 class Window; 0041 } 0042 namespace DOM 0043 { 0044 0045 class Node; 0046 class DOMString; 0047 class NodeImpl; 0048 class NamedNodeMapImpl; 0049 class EventListener; 0050 class Event; 0051 0052 /** 0053 * Objects implementing the \c NamedNodeMap interface are 0054 * used to represent collections of nodes that can be accessed by 0055 * name. Note that \c NamedNodeMap does not inherit from 0056 * \c NodeList ; \c NamedNodeMap s are not 0057 * maintained in any particular order. Objects contained in an object 0058 * implementing \c NamedNodeMap may also be accessed by an 0059 * ordinal index, but this is simply to allow convenient enumeration 0060 * of the contents of a \c NamedNodeMap , and does not 0061 * imply that the DOM specifies an order to these Nodes. 0062 * 0063 */ 0064 class KHTML_EXPORT NamedNodeMap 0065 { 0066 public: 0067 NamedNodeMap(); 0068 NamedNodeMap(const NamedNodeMap &other); 0069 0070 NamedNodeMap &operator = (const NamedNodeMap &other); 0071 0072 ~NamedNodeMap(); 0073 0074 /** 0075 * The number of nodes in the map. The range of valid child node 0076 * indices is 0 to \c length-1 inclusive. 0077 * 0078 */ 0079 unsigned long length() const; 0080 0081 /** 0082 * Retrieves a node specified by name. 0083 * 0084 * @param name Name of a node to retrieve. 0085 * 0086 * @return A \c Node (of any type) with the specified 0087 * name, or \c null if the specified name did not 0088 * identify any node in the map. 0089 * 0090 */ 0091 Node getNamedItem(const DOMString &name) const; 0092 0093 /** 0094 * Adds a node using its \c nodeName attribute. 0095 * 0096 * As the \c nodeName attribute is used to derive the 0097 * name which the node must be stored under, multiple nodes of 0098 * certain types (those that have a "special" string value) cannot 0099 * be stored as the names would clash. This is seen as preferable 0100 * to allowing nodes to be aliased. 0101 * 0102 * @param arg A node to store in a named node map. The node will 0103 * later be accessible using the value of the \c nodeName 0104 * attribute of the node. If a node with that name is 0105 * already present in the map, it is replaced by the new one. 0106 * 0107 * @return If the new \c Node replaces an existing 0108 * node with the same name the previously existing \c Node 0109 * is returned, otherwise \c null is returned. 0110 * 0111 * @exception DOMException 0112 * WRONG_DOCUMENT_ERR: Raised if \c arg was created 0113 * from a different document than the one that created the 0114 * \c NamedNodeMap . 0115 * 0116 * NO_MODIFICATION_ALLOWED_ERR: Raised if this 0117 * \c NamedNodeMap is readonly. 0118 * 0119 * INUSE_ATTRIBUTE_ERR: Raised if \c arg is an 0120 * \c Attr that is already an attribute of another 0121 * \c Element object. The DOM user must explicitly clone 0122 * \c Attr nodes to re-use them in other elements. 0123 * 0124 */ 0125 Node setNamedItem(const Node &arg); 0126 0127 /** 0128 * Removes a node specified by name. If the removed node is an 0129 * \c Attr with a default value it is immediately 0130 * replaced. 0131 * 0132 * @param name The name of a node to remove. 0133 * 0134 * @return The node removed from the map or \c null if 0135 * no node with such a name exists. 0136 * 0137 * @exception DOMException 0138 * NOT_FOUND_ERR: Raised if there is no node named \c name 0139 * in the map. 0140 * 0141 */ 0142 Node removeNamedItem(const DOMString &name); 0143 0144 /** 0145 * Returns the \c index th item in the map. If 0146 * \c index is greater than or equal to the number of nodes 0147 * in the map, this returns \c null . 0148 * 0149 * @param index Index into the map. 0150 * 0151 * @return The node at the \c index th position in the 0152 * \c NamedNodeMap , or \c null if that is 0153 * not a valid index. 0154 * 0155 */ 0156 Node item(unsigned long index) const; 0157 0158 /** 0159 * Introduced in DOM Level 2 0160 * 0161 * Retrieves a node specified by local name and namespace URI. HTML-only 0162 * DOM implementations do not need to implement this method. 0163 * 0164 * @param namespaceURI The namespace URI of the node to retrieve. 0165 * 0166 * @param localName The local name of the node to retrieve. 0167 * 0168 * @return A Node (of any type) with the specified local name and namespace 0169 * URI, or null if they do not identify any node in this map. 0170 */ 0171 Node getNamedItemNS(const DOMString &namespaceURI, 0172 const DOMString &localName) const; 0173 0174 /** 0175 * Introduced in DOM Level 2 0176 * 0177 * Adds a node using its namespaceURI and localName. If a node with that 0178 * namespace URI and that local name is already present in this map, it is 0179 * replaced by the new one. 0180 * HTML-only DOM implementations do not need to implement this method. 0181 * 0182 * @param arg A node to store in this map. The node will later be 0183 * accessible using the value of its namespaceURI and localName attributes. 0184 * 0185 * @return If the new Node replaces an existing node the replaced Node is 0186 * returned, otherwise null is returned. 0187 * 0188 * @exception DOMException 0189 * WRONG_DOCUMENT_ERR: Raised if arg was created from a different document 0190 * than the one that created this map. 0191 * 0192 * NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 0193 * 0194 * INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an 0195 * attribute of another Element object. The DOM user must explicitly clone 0196 * Attr nodes to re-use them in other elements. 0197 */ 0198 Node setNamedItemNS(const Node &arg); 0199 0200 /** 0201 * Introduced in DOM Level 2 0202 * 0203 * Removes a node specified by local name and namespace URI. A removed 0204 * attribute may be known to have a default value when this map contains 0205 * the attributes attached to an element, as returned by the attributes 0206 * attribute of the Node interface. If so, an attribute immediately appears 0207 * containing the default value as well as the corresponding namespace URI, 0208 * local name, and prefix when applicable. 0209 * HTML-only DOM implementations do not need to implement this method. 0210 * 0211 * @param namespaceURI The namespace URI of the node to remove. 0212 * 0213 * @param localName The local name of the node to remove. 0214 * 0215 * @return The node removed from this map if a node with such a local name 0216 * and namespace URI exists. 0217 * 0218 * @exception DOMException 0219 * NOT_FOUND_ERR: Raised if there is no node with the specified 0220 * namespaceURI and localName in this map. 0221 * 0222 * NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 0223 */ 0224 Node removeNamedItemNS(const DOMString &namespaceURI, 0225 const DOMString &localName); 0226 0227 /** 0228 * @internal 0229 * not part of the DOM 0230 */ 0231 NamedNodeMapImpl *handle() const 0232 { 0233 return impl; 0234 } 0235 bool isNull() const 0236 { 0237 return !impl; 0238 } 0239 0240 protected: 0241 NamedNodeMap(NamedNodeMapImpl *i); 0242 NamedNodeMapImpl *impl; 0243 0244 friend class Node; 0245 friend class DocumentType; 0246 friend class NodeImpl; 0247 }; 0248 0249 class NamedNodeMap; 0250 class NodeList; 0251 class Document; 0252 class DOMString; 0253 class StyleSheet; 0254 0255 class NodeImpl; 0256 0257 /** 0258 * The \c Node interface is the primary datatype for the 0259 * entire Document Object Model. It represents a single node in the 0260 * document tree. While all objects implementing the \c Node 0261 * interface expose methods for dealing with children, not all 0262 * objects implementing the \c Node interface may have 0263 * children. For example, \c Text nodes may not have 0264 * children, and adding children to such nodes results in a 0265 * \c DOMException being raised. 0266 * 0267 * The attributes \c nodeName , \c nodeValue 0268 * and \c attributes are included as a mechanism to get at 0269 * node information without casting down to the specific derived 0270 * interface. In cases where there is no obvious mapping of these 0271 * attributes for a specific \c nodeType (e.g., 0272 * \c nodeValue for an Element or \c attributes for a 0273 * Comment), this returns \c null . Note that the 0274 * specialized interfaces may contain additional and more convenient 0275 * mechanisms to get and set the relevant information. 0276 * 0277 */ 0278 class KHTML_EXPORT Node 0279 { 0280 friend class NamedNodeMap; 0281 friend class NodeList; 0282 friend class HTMLCollection; 0283 friend class StyleSheet; 0284 0285 public: 0286 Node() : impl(nullptr) {} 0287 Node(const Node &other); 0288 0289 /** 0290 * @internal 0291 */ 0292 Node(NodeImpl *_impl); 0293 0294 Node &operator = (const Node &other); 0295 0296 bool operator == (const Node &other) const; 0297 0298 bool operator != (const Node &other) const; 0299 0300 virtual ~Node(); 0301 /** 0302 * An integer indicating which type of node this is. 0303 * 0304 * 0305 * <p>The values of \c nodeName, \c nodeValue, 0306 * and \c attributes vary according to the node type as follows: 0307 * <table border="1"> 0308 * <tr> 0309 * <td></td> 0310 * <td>nodeName</td> 0311 * <td>nodeValue</td> 0312 * <td>attributes</td> 0313 * </tr> 0314 * <tr> 0315 * <td>Element</td> 0316 * <td>tagName</td> 0317 * <td>null</td> 0318 * <td>NamedNodeMap</td> 0319 * </tr> 0320 * <tr> 0321 * <td>Attr</td> 0322 * <td>name of attribute</td> 0323 * <td>value of attribute</td> 0324 * <td>null</td> 0325 * </tr> 0326 * <tr> 0327 * <td>Text</td> 0328 * <td>#text</td> 0329 * <td>content of the text node</td> 0330 * <td>null</td> 0331 * </tr> 0332 * <tr> 0333 * <td>CDATASection</td> 0334 * <td>#cdata-section</td> 0335 * <td>content of the CDATA Section</td> 0336 * <td>null</td> 0337 * </tr> 0338 * <tr> 0339 * <td>EntityReference</td> 0340 * <td>name of entity referenced</td> 0341 * <td>null</td> 0342 * <td>null</td> 0343 * </tr> 0344 * <tr> 0345 * <td>Entity</td> 0346 * <td>entity name</td> 0347 * <td>null</td> 0348 * <td>null</td> 0349 * </tr> 0350 * <tr> 0351 * <td>ProcessingInstruction</td> 0352 * <td>target</td> 0353 * <td>entire content excluding the target</td> 0354 * <td>null</td> 0355 * </tr> 0356 * <tr> 0357 * <td>Comment</td> 0358 * <td>#comment</td> 0359 * <td>content of the comment</td> 0360 * <td>null</td> 0361 * </tr> 0362 * <tr> 0363 * <td>Document</td> 0364 * <td>#document</td> 0365 * <td>null</td> 0366 * <td>null</td> 0367 * </tr> 0368 * <tr> 0369 * <td>DocumentType</td> 0370 * <td>document type name</td> 0371 * <td>null</td> 0372 * <td>null</td> 0373 * </tr> 0374 * <tr> 0375 * <td>DocumentFragment</td> 0376 * <td>#document-fragment</td> 0377 * <td>null</td> 0378 * <td>null</td> 0379 * </tr> 0380 * <tr> 0381 * <td>Notation</td> 0382 * <td>notation name</td> 0383 * <td>null</td> 0384 * <td>null</td> 0385 * </tr> 0386 * </table> 0387 * </p> 0388 */ 0389 enum NodeType { 0390 ELEMENT_NODE = 1, 0391 ATTRIBUTE_NODE = 2, 0392 TEXT_NODE = 3, 0393 CDATA_SECTION_NODE = 4, 0394 ENTITY_REFERENCE_NODE = 5, 0395 ENTITY_NODE = 6, 0396 PROCESSING_INSTRUCTION_NODE = 7, 0397 COMMENT_NODE = 8, 0398 DOCUMENT_NODE = 9, 0399 DOCUMENT_TYPE_NODE = 10, 0400 DOCUMENT_FRAGMENT_NODE = 11, 0401 NOTATION_NODE = 12, 0402 XPATH_NAMESPACE_NODE = 13 //< Part of DOM L3 XPath, @since 4.5 0403 }; 0404 0405 /** 0406 * The name of this node, depending on its type; see the table 0407 * above. 0408 * 0409 */ 0410 DOMString nodeName() const; 0411 0412 /** 0413 * The value of this node, depending on its type; see the table 0414 * above. 0415 * 0416 * @exception DOMException 0417 * DOMSTRING_SIZE_ERR: Raised when it would return more characters 0418 * than fit in a \c DOMString variable on the 0419 * implementation platform. 0420 * 0421 */ 0422 DOMString nodeValue() const; 0423 0424 /** 0425 * see nodeValue 0426 * @exception DOMException 0427 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 0428 * 0429 */ 0430 void setNodeValue(const DOMString &); 0431 0432 /** 0433 * A code representing the type of the underlying object, as 0434 * defined above. 0435 * 0436 */ 0437 unsigned short nodeType() const; 0438 0439 /** 0440 * The parent of this node. All nodes, except \c Document 0441 * , \c DocumentFragment , and \c Attr 0442 * may have a parent. However, if a node has just been 0443 * created and not yet added to the tree, or if it has been 0444 * removed from the tree, this is \c null . 0445 * 0446 */ 0447 Node parentNode() const; 0448 0449 /** 0450 * A \c NodeList that contains all children of this 0451 * node. If there are no children, this is a \c NodeList 0452 * containing no nodes. The content of the returned 0453 * \c NodeList is "live" in the sense that, for 0454 * instance, changes to the children of the node object that it 0455 * was created from are immediately reflected in the nodes 0456 * returned by the \c NodeList accessors; it is not a 0457 * static snapshot of the content of the node. This is true for 0458 * every \c NodeList , including the ones returned by 0459 * the \c getElementsByTagName method. 0460 * 0461 */ 0462 NodeList childNodes() const; 0463 0464 /** 0465 * The first child of this node. If there is no such node, this 0466 * returns \c null . 0467 * 0468 */ 0469 Node firstChild() const; 0470 0471 /** 0472 * The last child of this node. If there is no such node, this 0473 * returns \c null . 0474 * 0475 */ 0476 Node lastChild() const; 0477 0478 /** 0479 * The node immediately preceding this node. If there is no such 0480 * node, this returns \c null . 0481 * 0482 */ 0483 Node previousSibling() const; 0484 0485 /** 0486 * The node immediately following this node. If there is no such 0487 * node, this returns \c null . 0488 * 0489 */ 0490 Node nextSibling() const; 0491 0492 /** 0493 * A \c NamedNodeMap containing the attributes of this 0494 * node (if it is an \c Element ) or \c null 0495 * otherwise. 0496 * 0497 */ 0498 NamedNodeMap attributes() const; 0499 0500 /** 0501 * The \c Document object associated with this node. 0502 * This is also the \c Document object used to create 0503 * new nodes. When this node is a \c Document this is 0504 * \c null . 0505 * 0506 */ 0507 Document ownerDocument() const; 0508 0509 /** 0510 * Inserts the node \c newChild before the existing 0511 * child node \c refChild . If \c refChild 0512 * is \c null , insert \c newChild at the 0513 * end of the list of children. 0514 * 0515 * If \c newChild is a \c DocumentFragment 0516 * object, all of its children are inserted, in the same 0517 * order, before \c refChild . If the \c newChild 0518 * is already in the tree, it is first removed. 0519 * 0520 * @param newChild The node to insert. 0521 * 0522 * @param refChild The reference node, i.e., the node before which 0523 * the new node must be inserted. 0524 * 0525 * @return The node being inserted. 0526 * 0527 * @exception DOMException 0528 * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that 0529 * does not allow children of the type of the \c newChild 0530 * node, or if the node to insert is one of this node's 0531 * ancestors. 0532 * 0533 * WRONG_DOCUMENT_ERR: Raised if \c newChild was 0534 * created from a different document than the one that created 0535 * this node. 0536 * 0537 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0538 * 0539 * NOT_FOUND_ERR: Raised if \c refChild is not a 0540 * child of this node. 0541 * 0542 */ 0543 Node insertBefore(const Node &newChild, const Node &refChild); 0544 0545 /** 0546 * Replaces the child node \c oldChild with 0547 * \c newChild in the list of children, and returns the 0548 * \c oldChild node. If the \c newChild is 0549 * already in the tree, it is first removed. 0550 * 0551 * @param newChild The new node to put in the child list. 0552 * 0553 * @param oldChild The node being replaced in the list. 0554 * 0555 * @return The node replaced. 0556 * 0557 * @exception DOMException 0558 * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that 0559 * does not allow children of the type of the \c newChild 0560 * node, or it the node to put in is one of this node's 0561 * ancestors. 0562 * 0563 * WRONG_DOCUMENT_ERR: Raised if \c newChild was 0564 * created from a different document than the one that created 0565 * this node. 0566 * 0567 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0568 * 0569 * NOT_FOUND_ERR: Raised if \c oldChild is not a 0570 * child of this node. 0571 * 0572 */ 0573 Node replaceChild(const Node &newChild, const Node &oldChild); 0574 0575 /** 0576 * Removes the child node indicated by \c oldChild 0577 * from the list of children, and returns it. 0578 * 0579 * @param oldChild The node being removed. 0580 * 0581 * @return The node removed. 0582 * 0583 * @exception DOMException 0584 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0585 * 0586 * NOT_FOUND_ERR: Raised if \c oldChild is not a 0587 * child of this node. 0588 * 0589 */ 0590 Node removeChild(const Node &oldChild); 0591 0592 /** 0593 * Adds the node \c newChild to the end of the list of 0594 * children of this node. If the \c newChild is 0595 * already in the tree, it is first removed. 0596 * 0597 * @param newChild The node to add. 0598 * 0599 * If it is a \c DocumentFragment object, the entire 0600 * contents of the document fragment are moved into the child list 0601 * of this node 0602 * 0603 * @return The node added. 0604 * 0605 * @exception DOMException 0606 * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that 0607 * does not allow children of the type of the \c newChild 0608 * node, or if the node to append is one of this node's 0609 * ancestors. 0610 * 0611 * WRONG_DOCUMENT_ERR: Raised if \c newChild was 0612 * created from a different document than the one that created 0613 * this node. 0614 * 0615 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0616 * 0617 */ 0618 Node appendChild(const Node &newChild); 0619 0620 /** 0621 * This is a convenience method to allow easy determination of 0622 * whether a node has any children. 0623 * 0624 * @return \c true if the node has any children, 0625 * \c false if the node has no children. 0626 * 0627 */ 0628 bool hasChildNodes(); 0629 0630 /** 0631 * Returns a duplicate of this node, i.e., serves as a generic 0632 * copy constructor for nodes. The duplicate node has no parent ( 0633 * \c parentNode returns \c null .). 0634 * 0635 * Cloning an \c Element copies all attributes and 0636 * their values, including those generated by the XML processor to 0637 * represent defaulted attributes, but this method does not copy 0638 * any text it contains unless it is a deep clone, since the text 0639 * is contained in a child \c Text node. Cloning any 0640 * other type of node simply returns a copy of this node. 0641 * 0642 * @param deep If \c true , recursively clone the 0643 * subtree under the specified node; if \c false , 0644 * clone only the node itself (and its attributes, if it is an 0645 * \c Element ). 0646 * 0647 * @return The duplicate node. 0648 * 0649 */ 0650 Node cloneNode(bool deep); 0651 0652 /** 0653 * Modified in DOM Level 2 0654 * 0655 * Puts all Text nodes in the full depth of the sub-tree underneath this 0656 * Node, including attribute nodes, into a "normal" form where only 0657 * structure (e.g., elements, comments, processing instructions, CDATA 0658 * sections, and entity references) separates Text nodes, i.e., there are 0659 * neither adjacent Text nodes nor empty Text nodes. This can be used to 0660 * ensure that the DOM view of a document is the same as if it were saved 0661 * and re-loaded, and is useful when operations (such as XPointer 0662 * [XPointer] lookups) that depend on a particular document tree structure 0663 * are to be used. 0664 * 0665 * Note: In cases where the document contains CDATASections, the normalize 0666 * operation alone may not be sufficient, since XPointers do not 0667 * differentiate between Text nodes and CDATASection nodes. 0668 */ 0669 void normalize(); 0670 0671 /** 0672 * Introduced in DOM Level 2 0673 * 0674 * Tests whether the DOM implementation implements a specific feature and 0675 * that feature is supported by this node. 0676 * 0677 * @param feature The name of the feature to test. This is the same name 0678 * which can be passed to the method hasFeature on DOMImplementation. 0679 * 0680 * @param version This is the version number of the feature to test. In 0681 * Level 2, version 1, this is the string "2.0". If the version is not 0682 * specified, supporting any version of the feature will cause the method 0683 * to return true. 0684 * 0685 * @return Returns true if the specified feature is supported on this node, 0686 * false otherwise. 0687 */ 0688 bool isSupported(const DOMString &feature, 0689 const DOMString &version) const; 0690 0691 /** 0692 * Introduced in DOM Level 2 0693 * 0694 * The namespace URI of this node, or null if it is unspecified. 0695 * This is not a computed value that is the result of a namespace lookup 0696 * based on an examination of the namespace declarations in scope. It is 0697 * merely the namespace URI given at creation time. For nodes of any type 0698 * other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM 0699 * Level 1 method, such as createElement from the Document interface, this 0700 * is always null. 0701 * 0702 * Note: Per the Namespaces in XML Specification [Namespaces] an attribute 0703 * does not inherit its namespace from the element it is attached to. If an 0704 * attribute is not explicitly given a namespace, it simply has no 0705 * namespace. 0706 */ 0707 DOMString namespaceURI() const; 0708 0709 /** 0710 * Introduced in DOM Level 2 0711 * 0712 * The namespace prefix of this node, or null if it is unspecified. 0713 * Note that setting this attribute, when permitted, changes the nodeName 0714 * attribute, which holds the qualified name, as well as the tagName and 0715 * name attributes of the Element and Attr interfaces, when applicable. 0716 * Note also that changing the prefix of an attribute that is known to have 0717 * a default value, does not make a new attribute with the default value 0718 * and the original prefix appear, since the namespaceURI and localName do 0719 * not change. 0720 * For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and 0721 * nodes created with a DOM Level 1 method, such as createElement from the 0722 * Document interface, this is always null. 0723 */ 0724 DOMString prefix() const; 0725 0726 /** 0727 * see prefix 0728 * 0729 * @exception DOMException 0730 * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an 0731 * illegal character. 0732 * 0733 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0734 * 0735 * NAMESPACE_ERR: Raised if the specified prefix is malformed, if the 0736 * namespaceURI of this node is null, if the specified prefix is "xml" and 0737 * the namespaceURI of this node is different from 0738 * "http://www.w3.org/XML/1998/namespace", if this node is an attribute and 0739 * the specified prefix is "xmlns" and the namespaceURI of this node is 0740 * different from "http://www.w3.org/2000/xmlns/", or if this node is an 0741 * attribute and the qualifiedName of this node is "xmlns" [Namespaces]. 0742 */ 0743 void setPrefix(const DOMString &prefix); 0744 0745 /** 0746 * Introduced in DOM Level 2 0747 * 0748 * Returns the local part of the qualified name of this node. 0749 * For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and 0750 * nodes created with a DOM Level 1 method, such as createElement from the 0751 * Document interface, this is always null. 0752 */ 0753 DOMString localName() const; 0754 0755 /** 0756 * Returns whether this node (if it is an element) has any attributes. 0757 * @return a boolean. True if this node has any attributes, false otherwise. 0758 * Introduced in DOM Level 2 0759 */ 0760 bool hasAttributes(); 0761 0762 /** 0763 * Introduced in DOM Level 2 0764 * This method is from the EventTarget interface 0765 * 0766 * This method allows the registration of event listeners on the event 0767 * target. If an EventListener is added to an EventTarget while it is 0768 * processing an event, it will not be triggered by the current actions but 0769 * may be triggered during a later stage of event flow, such as the 0770 * bubbling phase. 0771 * 0772 * If multiple identical EventListeners are registered on the same 0773 * EventTarget with the same parameters the duplicate instances are 0774 * discarded. They do not cause the EventListener to be called twice and 0775 * since they are discarded they do not need to be removed with the 0776 * removeEventListener method. Parameters 0777 * 0778 * @param type The event type for which the user is registering 0779 * 0780 * @param listener The listener parameter takes an interface implemented by 0781 * the user which contains the methods to be called when the event occurs. 0782 * 0783 * @param useCapture If true, useCapture indicates that the user wishes to 0784 * initiate capture. After initiating capture, all events of the specified 0785 * type will be dispatched to the registered EventListener before being 0786 * dispatched to any EventTargets beneath them in the tree. Events which 0787 * are bubbling upward through the tree will not trigger an EventListener 0788 * designated to use capture. 0789 */ 0790 void addEventListener(const DOMString &type, 0791 EventListener *listener, 0792 const bool useCapture); 0793 0794 /** 0795 * Introduced in DOM Level 2 0796 * This method is from the EventTarget interface 0797 * 0798 * This method allows the removal of event listeners from the event target. 0799 * If an EventListener is removed from an EventTarget while it is 0800 * processing an event, it will not be triggered by the current actions. 0801 * 0802 * EventListeners can never be invoked after being removed. 0803 * 0804 * Calling removeEventListener with arguments which do not identify any 0805 * currently registered EventListener on the EventTarget has no effect. 0806 * 0807 * @param type Specifies the event type of the EventListener being removed. 0808 * 0809 * @param listener The EventListener parameter indicates the EventListener 0810 * to be removed. 0811 * 0812 * @param useCapture Specifies whether the EventListener being removed was 0813 * registered as a capturing listener or not. If a listener was registered 0814 * twice, one with capture and one without, each must be removed 0815 * separately. Removal of a capturing listener does not affect a 0816 * non-capturing version of the same listener, and vice versa. 0817 */ 0818 0819 void removeEventListener(const DOMString &type, 0820 EventListener *listener, 0821 bool useCapture); 0822 0823 /** 0824 * Introduced in DOM Level 2 0825 * This method is from the EventTarget interface 0826 * 0827 * This method allows the dispatch of events into the implementations event 0828 * model. Events dispatched in this manner will have the same capturing and 0829 * bubbling behavior as events dispatched directly by the implementation. 0830 * The target of the event is the EventTarget on which dispatchEvent is 0831 * called. 0832 * 0833 * @param evt Specifies the event type, behavior, and contextual 0834 * information to be used in processing the event. 0835 * 0836 * @return The return value of dispatchEvent indicates whether any of the 0837 * listeners which handled the event called preventDefault. If 0838 * preventDefault was called the value is false, else the value is true. 0839 * 0840 * @exception EventException 0841 * UNSPECIFIED_EVENT_TYPE_ERR: Raised if the Event's type was not specified 0842 * by initializing the event before dispatchEvent was called. Specification 0843 * of the Event's type as null or an empty string will also trigger this 0844 * exception. 0845 */ 0846 bool dispatchEvent(const Event &evt); 0847 0848 /** 0849 * Introduced in DOM Level 3 0850 * 0851 * This attribute returns the text content of this node and its 0852 * descendants. When it is defined to be null, setting it has no 0853 * effect. On setting, any possible children this node may have 0854 * are removed and, if it the new string is not empty or null, 0855 * replaced by a single Text node containing the string this 0856 * attribute is set to. 0857 * On getting, no serialization is performed, the returned string 0858 * does not contain any markup. No whitespace normalization is 0859 * performed and the returned string does not contain the white 0860 * spaces in element content (see the attribute 0861 * Text.isElementContentWhitespace). Similarly, on setting, no 0862 * parsing is performed either, the input string is taken as pure 0863 * textual content. 0864 */ 0865 DOMString textContent() const; 0866 0867 /** 0868 * see textContent() 0869 * 0870 * @exception DOMException 0871 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 0872 */ 0873 void setTextContent(const DOMString &text); 0874 0875 /** 0876 * Introduced in DOM Level 3. 0877 * 0878 * These constants represent bitflags returned by the compareDocumentPosition 0879 * method. 0880 * 0881 * @since 4.2.4 0882 */ 0883 enum DocumentPosition { 0884 DOCUMENT_POSITION_DISCONNECTED = 0x01, 0885 DOCUMENT_POSITION_PRECEDING = 0x02, 0886 DOCUMENT_POSITION_FOLLOWING = 0x04, 0887 DOCUMENT_POSITION_CONTAINS = 0x08, 0888 DOCUMENT_POSITION_CONTAINED_BY = 0x10, 0889 DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20 0890 }; 0891 0892 /** 0893 * Introduced in DOM Level 3. 0894 * 0895 * This method compares the current node's position with that of 'other' 0896 * and returns it as a combination of DocumentPosition bitfields. 0897 * Here DOCUMENT_POSITION_FOLLOWING means that the 'other' is 0898 * after the current. 0899 * 0900 * The notion of order here is a logical one; for example attributes 0901 * are viewed as if they were children of an element inserted 0902 * right before the real children. The method will also assign 0903 * some total order even if the nodes are not connected. 0904 * 0905 * @since 4.2.4 0906 */ 0907 unsigned compareDocumentPosition(const DOM::Node &other); 0908 0909 /** 0910 * @internal 0911 * not part of the DOM. 0912 * @returns the element id, in case this is an element, 0 otherwise 0913 */ 0914 quint32 elementId() const; 0915 0916 /** 0917 * tests if this Node is 0. Useful especially, if casting to a derived 0918 * class: 0919 * 0920 * \code 0921 * Node n = .....; 0922 * // try to convert into an Element: 0923 * Element e = n; 0924 * if( e.isNull() ) 0925 * qCDebug(KHTML_LOG) << "node isn't an element node"; 0926 * \endcode 0927 */ 0928 bool isNull() const 0929 { 0930 return !impl; 0931 } 0932 0933 /** 0934 * @internal handle to the implementation object 0935 */ 0936 NodeImpl *handle() const 0937 { 0938 return impl; 0939 } 0940 0941 /** 0942 * @internal returns the index of a node 0943 */ 0944 unsigned long index() const; 0945 #ifndef KHTML_NO_DEPRECATED 0946 KHTML_DEPRECATED QString toHTML(); 0947 #endif 0948 void applyChanges(); 0949 /** 0950 * @deprecated without substitution since 3.2 0951 */ 0952 #ifndef KHTML_NO_DEPRECATED 0953 KHTML_DEPRECATED void getCursor(int offset, int &_x, int &_y, int &height); 0954 #endif 0955 /** 0956 * not part of the DOM. 0957 * @returns the exact coordinates and size of this element. 0958 */ 0959 QRect getRect(); 0960 0961 protected: 0962 NodeImpl *impl; 0963 }; 0964 0965 class NodeListImpl; 0966 0967 /** 0968 * The \c NodeList interface provides the abstraction of 0969 * an ordered collection of nodes, without defining or constraining 0970 * how this collection is implemented. 0971 * 0972 * The items in the \c NodeList are accessible via an 0973 * integral index, starting from 0. 0974 * 0975 */ 0976 class KHTML_EXPORT NodeList 0977 { 0978 friend class Element; 0979 friend class Node; 0980 friend class Document; 0981 friend class DocumentFragment; 0982 friend class HTMLDocument; 0983 friend class KJS::HTMLDocument; 0984 friend class KJS::Window; 0985 0986 public: 0987 NodeList(); 0988 NodeList(const NodeList &other); 0989 0990 NodeList &operator = (const NodeList &other); 0991 0992 ~NodeList(); 0993 0994 /** 0995 * The number of nodes in the list. The range of valid child node 0996 * indices is 0 to \c length-1 inclusive. 0997 * 0998 */ 0999 unsigned long length() const; 1000 1001 /** 1002 * Returns the \c index th item in the collection. If 1003 * \c index is greater than or equal to the number of 1004 * nodes in the list, this returns \c null . 1005 * 1006 * @param index Index into the collection. 1007 * 1008 * @return The node at the \c index th position in the 1009 * \c NodeList , or \c null if that is not 1010 * a valid index. 1011 * 1012 */ 1013 Node item(unsigned long index) const; 1014 1015 /** 1016 * @internal 1017 * not part of the DOM 1018 */ 1019 NodeListImpl *handle() const 1020 { 1021 return impl; 1022 } 1023 bool isNull() const 1024 { 1025 return !impl; 1026 } 1027 1028 protected: 1029 NodeList(const NodeListImpl *i); 1030 NodeListImpl *impl; 1031 }; 1032 1033 /** 1034 * A DOMTimeStamp represents a number of milliseconds. 1035 * 1036 */ 1037 typedef unsigned long long DOMTimeStamp; 1038 1039 } //namespace 1040 #endif