File indexing completed on 2024-04-21 14:57:02
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_CharacterData_h_ 0030 #define _DOM_CharacterData_h_ 0031 0032 #include <dom/dom_node.h> 0033 0034 namespace DOM 0035 { 0036 0037 class DOMString; 0038 class CharacterDataImpl; 0039 0040 /** 0041 * The \c CharacterData interface extends Node with a set 0042 * of attributes and methods for accessing character data in the DOM. 0043 * For clarity this set is defined here rather than on each object 0044 * that uses these attributes and methods. No DOM objects correspond 0045 * directly to \c CharacterData , though \c Text 0046 * and others do inherit the interface from it. All 0047 * <code>offset</code>s in this interface start from 0. 0048 * 0049 */ 0050 class KHTML_EXPORT CharacterData : public Node 0051 { 0052 friend class CharacterDataImpl; 0053 0054 public: 0055 CharacterData(); 0056 CharacterData(const CharacterData &other); 0057 CharacterData(const Node &other) : Node() 0058 { 0059 (*this) = other; 0060 } 0061 0062 CharacterData &operator = (const Node &other); 0063 CharacterData &operator = (const CharacterData &other); 0064 0065 ~CharacterData(); 0066 0067 /** 0068 * The character data of the node that implements this interface. 0069 * The DOM implementation may not put arbitrary limits on the 0070 * amount of data that may be stored in a \c CharacterData 0071 * node. However, implementation limits may mean that the 0072 * entirety of a node's data may not fit into a single 0073 * \c DOMString . In such cases, the user may call 0074 * \c substringData to retrieve the data in appropriately 0075 * sized pieces. 0076 * 0077 * @exception DOMException 0078 * DOMSTRING_SIZE_ERR: Raised when it would return more characters 0079 * than fit in a \c DOMString variable on the 0080 * implementation platform. 0081 * 0082 */ 0083 DOMString data() const; 0084 0085 /** 0086 * see data 0087 * @exception DOMException 0088 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 0089 * 0090 */ 0091 void setData(const DOMString &); 0092 0093 /** 0094 * The number of characters that are available through \c data 0095 * and the \c substringData method below. This 0096 * may have the value zero, i.e., \c CharacterData 0097 * nodes may be empty. 0098 * 0099 */ 0100 unsigned long length() const; 0101 0102 /** 0103 * Extracts a range of data from the node. 0104 * 0105 * @param offset Start offset of substring to extract. 0106 * 0107 * @param count The number of characters to extract. 0108 * 0109 * @return The specified substring. If the sum of \c offset 0110 * and \c count exceeds the \c length 0111 * , then all characters to the end of the data are 0112 * returned. 0113 * 0114 * @exception DOMException 0115 * INDEX_SIZE_ERR: Raised if the specified offset is negative or 0116 * greater than the number of characters in \c data , 0117 * or if the specified \c count is negative. 0118 * 0119 * DOMSTRING_SIZE_ERR: Raised if the specified range of text does 0120 * not fit into a \c DOMString . 0121 * 0122 */ 0123 DOMString substringData(const unsigned long offset, const unsigned long count); 0124 0125 /** 0126 * Append the string to the end of the character data of the node. 0127 * Upon success, \c data provides access to the 0128 * concatenation of \c data and the \c DOMString 0129 * specified. 0130 * 0131 * @param arg The \c DOMString to append. 0132 * 0133 * @return 0134 * 0135 * @exception DOMException 0136 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0137 * 0138 */ 0139 void appendData(const DOMString &arg); 0140 0141 /** 0142 * Insert a string at the specified character offset. 0143 * 0144 * @param offset The character offset at which to insert. 0145 * 0146 * @param arg The \c DOMString to insert. 0147 * 0148 * @return 0149 * 0150 * @exception DOMException 0151 * INDEX_SIZE_ERR: Raised if the specified offset is negative or 0152 * greater than the number of characters in \c data . 0153 * 0154 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0155 * 0156 */ 0157 void insertData(const unsigned long offset, const DOMString &arg); 0158 0159 /** 0160 * Remove a range of characters from the node. Upon success, 0161 * \c data and \c length reflect the 0162 * change. 0163 * 0164 * @param offset The offset from which to remove characters. 0165 * 0166 * @param count The number of characters to delete. If the sum of 0167 * \c offset and \c count exceeds 0168 * \c length then all characters from \c offset 0169 * to the end of the data are deleted. 0170 * 0171 * @return 0172 * 0173 * @exception DOMException 0174 * INDEX_SIZE_ERR: Raised if the specified offset is negative or 0175 * greater than the number of characters in \c data , 0176 * or if the specified \c count is negative. 0177 * 0178 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0179 * 0180 */ 0181 void deleteData(const unsigned long offset, const unsigned long count); 0182 0183 /** 0184 * Replace the characters starting at the specified character 0185 * offset with the specified string. 0186 * 0187 * @param offset The offset from which to start replacing. 0188 * 0189 * @param count The number of characters to replace. If the sum of 0190 * \c offset and \c count exceeds 0191 * \c length , then all characters to the end of the data are 0192 * replaced (i.e., the effect is the same as a \c remove 0193 * method call with the same range, followed by an 0194 * \c append method invocation). 0195 * 0196 * @param arg The \c DOMString with which the range 0197 * must be replaced. 0198 * 0199 * @return 0200 * 0201 * @exception DOMException 0202 * INDEX_SIZE_ERR: Raised if the specified offset is negative or 0203 * greater than the number of characters in \c data , 0204 * or if the specified \c count is negative. 0205 * 0206 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0207 * 0208 */ 0209 void replaceData(const unsigned long offset, const unsigned long count, const DOMString &arg); 0210 0211 protected: 0212 CharacterData(CharacterDataImpl *i); 0213 }; 0214 0215 class CommentImpl; 0216 0217 /** 0218 * This represents the content of a comment, i.e., all the characters 0219 * between the starting ' \c <!-- ' and ending ' 0220 * \c --> '. Note that this is the definition of a comment in 0221 * XML, and, in practice, HTML, although some HTML tools may implement 0222 * the full SGML comment structure. 0223 * 0224 */ 0225 class KHTML_EXPORT Comment : public CharacterData 0226 { 0227 friend class Document; 0228 friend class TextImpl; 0229 0230 public: 0231 Comment(); 0232 Comment(const Comment &other); 0233 Comment(const Node &other) : CharacterData() 0234 { 0235 (*this) = other; 0236 } 0237 0238 Comment &operator = (const Node &other); 0239 Comment &operator = (const Comment &other); 0240 0241 ~Comment(); 0242 0243 protected: 0244 Comment(CommentImpl *i); 0245 }; 0246 0247 class TextImpl; 0248 0249 /** 0250 * The \c Text interface represents the textual content 0251 * (termed <a href="&xml-spec;#syntax"> character data </a> in XML) of 0252 * an \c Element or \c Attr . If there is no 0253 * markup inside an element's content, the text is contained in a 0254 * single object implementing the \c Text interface that 0255 * is the only child of the element. If there is markup, it is parsed 0256 * into a list of elements and \c Text nodes that form the 0257 * list of children of the element. 0258 * 0259 * When a document is first made available via the DOM, there is only 0260 * one \c Text node for each block of text. Users may 0261 * create adjacent \c Text nodes that represent the 0262 * contents of a given element without any intervening markup, but 0263 * should be aware that there is no way to represent the separations 0264 * between these nodes in XML or HTML, so they will not (in general) 0265 * persist between DOM editing sessions. The \c normalize() 0266 * method on \c Element merges any such adjacent 0267 * \c Text objects into a single node for each block of 0268 * text; this is recommended before employing operations that depend 0269 * on a particular document structure, such as navigation with 0270 * \c XPointers. 0271 * 0272 */ 0273 class KHTML_EXPORT Text : public CharacterData 0274 { 0275 friend class Document; 0276 friend class TextImpl; 0277 0278 public: 0279 Text(); 0280 Text(const Text &other); 0281 Text(const Node &other) : CharacterData() 0282 { 0283 (*this) = other; 0284 } 0285 0286 Text &operator = (const Node &other); 0287 Text &operator = (const Text &other); 0288 0289 ~Text(); 0290 0291 /** 0292 * Breaks this \c Text node into two Text nodes at the 0293 * specified offset, keeping both in the tree as siblings. This 0294 * node then only contains all the content up to the \c offset 0295 * point. And a new \c Text node, which is 0296 * inserted as the next sibling of this node, contains all the 0297 * content at and after the \c offset point. 0298 * 0299 * @param offset The offset at which to split, starting from 0. 0300 * 0301 * @return The new \c Text node. 0302 * 0303 * @exception DOMException 0304 * INDEX_SIZE_ERR: Raised if the specified offset is negative or 0305 * greater than the number of characters in \c data . 0306 * 0307 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. 0308 * 0309 */ 0310 Text splitText(const unsigned long offset); 0311 0312 protected: 0313 Text(TextImpl *i); 0314 0315 }; 0316 0317 } //namespace 0318 #endif