File indexing completed on 2024-05-05 16:11:42
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 0005 * (C) 2001-2003 Dirk Mueller (mueller@kde.org) 0006 * (C) 1999 Antti Koivisto (koivisto@kde.org) 0007 * (C) 2003 Apple Computer, Inc 0008 * 0009 * This library is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU Library General Public 0011 * License as published by the Free Software Foundation; either 0012 * version 2 of the License, or (at your option) any later version. 0013 * 0014 * This library is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 * Library General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Library General Public License 0020 * along with this library; see the file COPYING.LIB. If not, write to 0021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 * Boston, MA 02110-1301, USA. 0023 * 0024 */ 0025 #ifndef _DOM_CharacterDataImpl_h_ 0026 #define _DOM_CharacterDataImpl_h_ 0027 0028 #include "xml/dom_nodeimpl.h" 0029 #include "dom/dom_string.h" 0030 0031 namespace DOM 0032 { 0033 0034 class DocumentImpl; 0035 class CharacterData; 0036 class Text; 0037 0038 class CharacterDataImpl : public NodeImpl 0039 { 0040 public: 0041 CharacterDataImpl(DocumentImpl *doc, DOMStringImpl *_text); 0042 0043 virtual ~CharacterDataImpl(); 0044 0045 // DOM methods & attributes for CharacterData 0046 0047 virtual void setData(const DOMString &_data, int &exceptioncode); 0048 virtual unsigned long length() const; 0049 virtual DOMString substringData(const unsigned long offset, const unsigned long count, int &exceptioncode); 0050 virtual void appendData(const DOMString &arg, int &exceptioncode); 0051 virtual void insertData(const unsigned long offset, const DOMString &arg, int &exceptioncode); 0052 virtual void deleteData(const unsigned long offset, const unsigned long count, int &exceptioncode); 0053 virtual void replaceData(const unsigned long offset, const unsigned long count, const DOMString &arg, int &exceptioncode); 0054 0055 bool containsOnlyWhitespace() const override; 0056 0057 // DOM methods overridden from parent classes 0058 0059 DOMString nodeValue() const override; 0060 void setNodeValue(const DOMString &_nodeValue, int &exceptioncode) override; 0061 0062 // Other methods (not part of DOM) 0063 0064 DOMStringImpl *string() const 0065 { 0066 return str; 0067 } 0068 DOMString data() const 0069 { 0070 return str; 0071 } 0072 0073 virtual void checkCharDataOperation(const unsigned long offset, int &exceptioncode); 0074 0075 bool offsetInCharacters() const override 0076 { 0077 return true; 0078 } 0079 int maxCharacterOffset() const override 0080 { 0081 return static_cast<int>(length()); 0082 } 0083 0084 long maxOffset() const override; 0085 long caretMinOffset() const override; 0086 long caretMaxOffset() const override; 0087 unsigned long caretMaxRenderedOffset() const override; 0088 0089 bool rendererIsNeeded(khtml::RenderStyle *) override; 0090 0091 protected: 0092 // note: since DOMStrings are shared, str should always be copied when making 0093 // a change or returning a string 0094 DOMStringImpl *str; 0095 0096 void dispatchModifiedEvent(DOMStringImpl *prevValue); 0097 }; 0098 0099 // ---------------------------------------------------------------------------- 0100 0101 class CommentImpl : public CharacterDataImpl 0102 { 0103 public: 0104 CommentImpl(DocumentImpl *doc, DOMStringImpl *_text) 0105 : CharacterDataImpl(doc, _text) {} 0106 CommentImpl(DocumentImpl *doc) 0107 : CharacterDataImpl(doc, nullptr) {} 0108 // DOM methods overridden from parent classes 0109 DOMString nodeName() const override; 0110 unsigned short nodeType() const override; 0111 WTF::PassRefPtr<NodeImpl> cloneNode(bool deep) override; 0112 0113 // Other methods (not part of DOM) 0114 0115 Id id() const override; 0116 bool childTypeAllowed(unsigned short type) override; 0117 0118 DOMString toString() const override; 0119 }; 0120 0121 // ---------------------------------------------------------------------------- 0122 0123 class TextImpl : public CharacterDataImpl 0124 { 0125 public: 0126 TextImpl(DocumentImpl *impl, DOMStringImpl *_text) 0127 : CharacterDataImpl(impl, _text) {} 0128 TextImpl(DocumentImpl *impl) 0129 : CharacterDataImpl(impl, nullptr) {} 0130 0131 // DOM methods & attributes for CharacterData 0132 0133 TextImpl *splitText(const unsigned long offset, int &exceptioncode); 0134 0135 // DOM Level 3: https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772 0136 DOMString wholeText() const; 0137 TextImpl *replaceWholeText(const DOMString &newText, int &ec); 0138 0139 // DOM methods overridden from parent classes 0140 DOMString nodeName() const override; 0141 unsigned short nodeType() const override; 0142 WTF::PassRefPtr<NodeImpl> cloneNode(bool deep) override; 0143 0144 // Other methods (not part of DOM) 0145 0146 bool isTextNode() const override 0147 { 0148 return true; 0149 } 0150 Id id() const override; 0151 void attach() override; 0152 bool rendererIsNeeded(khtml::RenderStyle *) override; 0153 khtml::RenderObject *createRenderer(khtml::RenderArena *, khtml::RenderStyle *) override; 0154 void recalcStyle(StyleChange = NoChange) override; 0155 bool affectedByNoInherit() const override 0156 { 0157 return true; 0158 } 0159 bool childTypeAllowed(unsigned short type) override; 0160 0161 DOMStringImpl *renderString() const; 0162 0163 DOMString toString() const override; 0164 /** Return the text for the node, with < replaced with < and so on. 0165 * @param startOffset The number of characters counted from the left, zero indexed, counting "<" as one character, to start from. Use -1 to start from 0. 0166 * @param endOffset The number of characters counted from the left, zero indexed, counting "<" as one character, to end on. Use -1 to end at the end of the string. 0167 * @return An html escaped version of the substring. 0168 */ 0169 DOMString toString(long long startOffset, long long endOffset) const; 0170 protected: 0171 virtual TextImpl *createNew(DOMStringImpl *_str); 0172 }; 0173 0174 // ---------------------------------------------------------------------------- 0175 0176 class CDATASectionImpl : public TextImpl 0177 { 0178 public: 0179 CDATASectionImpl(DocumentImpl *impl, DOMStringImpl *_text) 0180 : TextImpl(impl, _text) {} 0181 CDATASectionImpl(DocumentImpl *impl) 0182 : TextImpl(impl) {} 0183 0184 // DOM methods overridden from parent classes 0185 DOMString nodeName() const override; 0186 unsigned short nodeType() const override; 0187 WTF::PassRefPtr<NodeImpl> cloneNode(bool deep) override; 0188 0189 // Other methods (not part of DOM) 0190 0191 bool childTypeAllowed(unsigned short type) override; 0192 0193 DOMString toString() const override; 0194 0195 protected: 0196 TextImpl *createNew(DOMStringImpl *_str) override; 0197 }; 0198 0199 // ---------------------------------------------------------------------------- 0200 0201 class EditingTextImpl : public TextImpl 0202 { 0203 public: 0204 EditingTextImpl(DocumentImpl *impl, const DOMString &text); 0205 EditingTextImpl(DocumentImpl *impl); 0206 virtual ~EditingTextImpl(); 0207 0208 bool rendererIsNeeded(khtml::RenderStyle *) override; 0209 }; 0210 0211 } //namespace 0212 #endif