/work/obj-fuzz/dist/include/mozilla/dom/CharacterData.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* |
8 | | * Base class for DOM Core's Comment, DocumentType, Text, |
9 | | * CDATASection, and ProcessingInstruction nodes. |
10 | | */ |
11 | | |
12 | | #ifndef mozilla_dom_CharacterData_h |
13 | | #define mozilla_dom_CharacterData_h |
14 | | |
15 | | #include "mozilla/Attributes.h" |
16 | | #include "nsIContent.h" |
17 | | |
18 | | #include "nsTextFragment.h" |
19 | | #include "nsError.h" |
20 | | #include "mozilla/dom/Element.h" |
21 | | #include "nsCycleCollectionParticipant.h" |
22 | | |
23 | | #include "nsISMILAttr.h" |
24 | | #include "mozilla/dom/ShadowRoot.h" |
25 | | |
26 | | class nsIDocument; |
27 | | |
28 | | namespace mozilla { |
29 | | namespace dom { |
30 | | class HTMLSlotElement; |
31 | | } // namespace dom |
32 | | } // namespace mozilla |
33 | | |
34 | | #define CHARACTER_DATA_FLAG_BIT(n_) NODE_FLAG_BIT(NODE_TYPE_SPECIFIC_BITS_OFFSET + (n_)) |
35 | | |
36 | | // Data node specific flags |
37 | | enum { |
38 | | // This bit is set to indicate that if the text node changes to |
39 | | // non-whitespace, we may need to create a frame for it. This bit must |
40 | | // not be set on nodes that already have a frame. |
41 | | NS_CREATE_FRAME_IF_NON_WHITESPACE = CHARACTER_DATA_FLAG_BIT(0), |
42 | | |
43 | | // This bit is set to indicate that if the text node changes to |
44 | | // whitespace, we may need to reframe it (or its ancestors). |
45 | | NS_REFRAME_IF_WHITESPACE = CHARACTER_DATA_FLAG_BIT(1), |
46 | | |
47 | | // This bit is set to indicate that we have a cached |
48 | | // TextIsOnlyWhitespace value |
49 | | NS_CACHED_TEXT_IS_ONLY_WHITESPACE = CHARACTER_DATA_FLAG_BIT(2), |
50 | | |
51 | | // This bit is only meaningful if the NS_CACHED_TEXT_IS_ONLY_WHITESPACE |
52 | | // bit is set, and if so it indicates whether we're only whitespace or |
53 | | // not. |
54 | | NS_TEXT_IS_ONLY_WHITESPACE = CHARACTER_DATA_FLAG_BIT(3), |
55 | | |
56 | | // This bit is set if there is a NewlineProperty attached to the node |
57 | | // (used by nsTextFrame). |
58 | | NS_HAS_NEWLINE_PROPERTY = CHARACTER_DATA_FLAG_BIT(4), |
59 | | |
60 | | // This bit is set if there is a FlowLengthProperty attached to the node |
61 | | // (used by nsTextFrame). |
62 | | NS_HAS_FLOWLENGTH_PROPERTY = CHARACTER_DATA_FLAG_BIT(5), |
63 | | |
64 | | // This bit is set if the node may be modified frequently. This is typically |
65 | | // specified if the instance is in <input> or <textarea>. |
66 | | NS_MAYBE_MODIFIED_FREQUENTLY = CHARACTER_DATA_FLAG_BIT(6), |
67 | | }; |
68 | | |
69 | | // Make sure we have enough space for those bits |
70 | | ASSERT_NODE_FLAGS_SPACE(NODE_TYPE_SPECIFIC_BITS_OFFSET + 7); |
71 | | |
72 | | #undef CHARACTER_DATA_FLAG_BIT |
73 | | |
74 | | namespace mozilla { |
75 | | namespace dom { |
76 | | |
77 | | class CharacterData : public nsIContent |
78 | | { |
79 | | public: |
80 | | // We want to avoid the overhead of extra function calls for |
81 | | // refcounting when we're not doing refcount logging, so we can't |
82 | | // NS_DECL_ISUPPORTS_INHERITED. |
83 | | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; |
84 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(CharacterData, nsIContent); |
85 | | |
86 | | NS_DECL_ADDSIZEOFEXCLUDINGTHIS |
87 | | |
88 | | explicit CharacterData(already_AddRefed<dom::NodeInfo>&& aNodeInfo); |
89 | | |
90 | | void MarkAsMaybeModifiedFrequently() |
91 | 0 | { |
92 | 0 | SetFlags(NS_MAYBE_MODIFIED_FREQUENTLY); |
93 | 0 | } |
94 | | |
95 | | NS_IMPL_FROMNODE_HELPER(CharacterData, IsCharacterData()) |
96 | | |
97 | | virtual void GetNodeValueInternal(nsAString& aNodeValue) override; |
98 | | virtual void SetNodeValueInternal(const nsAString& aNodeValue, |
99 | | ErrorResult& aError) override; |
100 | | |
101 | | void GetTextContentInternal(nsAString& aTextContent, OOMReporter&) final |
102 | 0 | { |
103 | 0 | GetNodeValue(aTextContent); |
104 | 0 | } |
105 | | |
106 | | void SetTextContentInternal(const nsAString& aTextContent, |
107 | | nsIPrincipal* aSubjectPrincipal, |
108 | | ErrorResult& aError) final |
109 | 0 | { |
110 | 0 | // Batch possible DOMSubtreeModified events. |
111 | 0 | mozAutoSubtreeModified subtree(OwnerDoc(), nullptr); |
112 | 0 | return SetNodeValue(aTextContent, aError); |
113 | 0 | } |
114 | | |
115 | | // Implementation for nsIContent |
116 | | nsresult BindToTree(nsIDocument* aDocument, |
117 | | nsIContent* aParent, |
118 | | nsIContent* aBindingParent) override; |
119 | | |
120 | | void UnbindFromTree(bool aDeep = true, bool aNullParent = true) override; |
121 | | |
122 | | already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) final |
123 | 0 | { |
124 | 0 | return nullptr; |
125 | 0 | } |
126 | | |
127 | | const nsTextFragment* GetText() override |
128 | 0 | { |
129 | 0 | return &mText; |
130 | 0 | } |
131 | | |
132 | | const nsTextFragment& TextFragment() const |
133 | 0 | { |
134 | 0 | return mText; |
135 | 0 | } |
136 | | |
137 | | uint32_t TextLength() const final |
138 | 0 | { |
139 | 0 | return TextDataLength(); |
140 | 0 | } |
141 | | |
142 | | /** |
143 | | * Set the text to the given value. If aNotify is true then |
144 | | * the document is notified of the content change. |
145 | | */ |
146 | | nsresult SetText(const char16_t* aBuffer, |
147 | | uint32_t aLength, |
148 | | bool aNotify); |
149 | | /** |
150 | | * Append the given value to the current text. If aNotify is true then |
151 | | * the document is notified of the content change. |
152 | | */ |
153 | | nsresult SetText(const nsAString& aStr, bool aNotify) |
154 | 0 | { |
155 | 0 | return SetText(aStr.BeginReading(), aStr.Length(), aNotify); |
156 | 0 | } |
157 | | |
158 | | /** |
159 | | * Append the given value to the current text. If aNotify is true then |
160 | | * the document is notified of the content change. |
161 | | */ |
162 | | nsresult AppendText(const char16_t* aBuffer, |
163 | | uint32_t aLength, |
164 | | bool aNotify); |
165 | | |
166 | | bool TextIsOnlyWhitespace() final; |
167 | | bool ThreadSafeTextIsOnlyWhitespace() const final; |
168 | | |
169 | | /** |
170 | | * Append the text content to aResult. |
171 | | */ |
172 | | void AppendTextTo(nsAString& aResult) const |
173 | 0 | { |
174 | 0 | mText.AppendTo(aResult); |
175 | 0 | } |
176 | | |
177 | | /** |
178 | | * Append the text content to aResult. |
179 | | */ |
180 | | MOZ_MUST_USE |
181 | | bool AppendTextTo(nsAString& aResult, const fallible_t& aFallible) const |
182 | 0 | { |
183 | 0 | return mText.AppendTo(aResult, aFallible); |
184 | 0 | } |
185 | | |
186 | | void SaveSubtreeState() final |
187 | 0 | { |
188 | 0 | } |
189 | | |
190 | | #ifdef DEBUG |
191 | | void List(FILE* out, int32_t aIndent) const override |
192 | | { |
193 | | } |
194 | | |
195 | | void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const override |
196 | | { |
197 | | } |
198 | | #endif |
199 | | |
200 | | nsXBLBinding* DoGetXBLBinding() const final |
201 | 0 | { |
202 | 0 | return nullptr; |
203 | 0 | } |
204 | | |
205 | | bool IsNodeOfType(uint32_t aFlags) const override |
206 | 0 | { |
207 | 0 | return false; |
208 | 0 | } |
209 | | |
210 | | bool IsLink(nsIURI** aURI) const final |
211 | 0 | { |
212 | 0 | *aURI = nullptr; |
213 | 0 | return false; |
214 | 0 | } |
215 | | |
216 | | nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const override |
217 | 0 | { |
218 | 0 | RefPtr<CharacterData> result = CloneDataNode(aNodeInfo, true); |
219 | 0 | result.forget(aResult); |
220 | 0 |
|
221 | 0 | if (!*aResult) { |
222 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
223 | 0 | } |
224 | 0 | |
225 | 0 | return NS_OK; |
226 | 0 | } |
227 | | |
228 | | // WebIDL API |
229 | | void GetData(nsAString& aData) const; |
230 | | virtual void SetData(const nsAString& aData, ErrorResult& rv); |
231 | | // nsINode::Length() returns the right thing for our length attribute |
232 | | void SubstringData(uint32_t aStart, uint32_t aCount, nsAString& aReturn, |
233 | | ErrorResult& rv); |
234 | | void AppendData(const nsAString& aData, ErrorResult& rv); |
235 | | void InsertData(uint32_t aOffset, const nsAString& aData, ErrorResult& rv); |
236 | | void DeleteData(uint32_t aOffset, uint32_t aCount, ErrorResult& rv); |
237 | | void ReplaceData(uint32_t aOffset, uint32_t aCount, const nsAString& aData, |
238 | | ErrorResult& rv); |
239 | | |
240 | | uint32_t TextDataLength() const |
241 | 0 | { |
242 | 0 | return mText.GetLength(); |
243 | 0 | } |
244 | | |
245 | | //---------------------------------------- |
246 | | |
247 | | #ifdef DEBUG |
248 | | void ToCString(nsAString& aBuf, int32_t aOffset, int32_t aLen) const; |
249 | | #endif |
250 | | |
251 | | NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(CharacterData, |
252 | | nsIContent) |
253 | | |
254 | | protected: |
255 | | virtual ~CharacterData(); |
256 | | |
257 | | Element* GetNameSpaceElement() final |
258 | 0 | { |
259 | 0 | return Element::FromNodeOrNull(GetParentNode()); |
260 | 0 | } |
261 | | |
262 | | nsresult SetTextInternal(uint32_t aOffset, uint32_t aCount, |
263 | | const char16_t* aBuffer, uint32_t aLength, |
264 | | bool aNotify, |
265 | | CharacterDataChangeInfo::Details* aDetails = nullptr); |
266 | | |
267 | | /** |
268 | | * Method to clone this node. This needs to be overriden by all derived |
269 | | * classes. If aCloneText is true the text content will be cloned too. |
270 | | * |
271 | | * @param aOwnerDocument the ownerDocument of the clone |
272 | | * @param aCloneText if true the text content will be cloned too |
273 | | * @return the clone |
274 | | */ |
275 | | virtual already_AddRefed<CharacterData> |
276 | | CloneDataNode(dom::NodeInfo* aNodeInfo, bool aCloneText) const = 0; |
277 | | |
278 | | nsTextFragment mText; |
279 | | |
280 | | private: |
281 | | already_AddRefed<nsAtom> GetCurrentValueAtom(); |
282 | | }; |
283 | | |
284 | | } // namespace dom |
285 | | } // namespace mozilla |
286 | | |
287 | | #endif /* mozilla_dom_CharacterData_h */ |