OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 { | 48 { |
49 const String& nonNullData = !data.isNull() ? data : emptyString(); | 49 const String& nonNullData = !data.isNull() ? data : emptyString(); |
50 if (m_data == nonNullData) | 50 if (m_data == nonNullData) |
51 return; | 51 return; |
52 | 52 |
53 RefPtr<CharacterData> protect = this; | 53 RefPtr<CharacterData> protect = this; |
54 | 54 |
55 unsigned oldLength = length(); | 55 unsigned oldLength = length(); |
56 | 56 |
57 setDataAndUpdate(nonNullData, 0, oldLength, nonNullData.length()); | 57 setDataAndUpdate(nonNullData, 0, oldLength, nonNullData.length()); |
58 document()->textRemoved(this, 0, oldLength); | 58 document().textRemoved(this, 0, oldLength); |
59 } | 59 } |
60 | 60 |
61 String CharacterData::substringData(unsigned offset, unsigned count, ExceptionSt
ate& es) | 61 String CharacterData::substringData(unsigned offset, unsigned count, ExceptionSt
ate& es) |
62 { | 62 { |
63 if (offset > length()) { | 63 if (offset > length()) { |
64 es.throwDOMException(IndexSizeError); | 64 es.throwDOMException(IndexSizeError); |
65 return String(); | 65 return String(); |
66 } | 66 } |
67 | 67 |
68 return m_data.substring(offset, count); | 68 return m_data.substring(offset, count); |
(...skipping 24 matching lines...) Expand all Loading... |
93 | 93 |
94 if (string.is8Bit()) | 94 if (string.is8Bit()) |
95 m_data.append(string.characters8() + offset, characterLengthLimit); | 95 m_data.append(string.characters8() + offset, characterLengthLimit); |
96 else | 96 else |
97 m_data.append(string.characters16() + offset, characterLengthLimit); | 97 m_data.append(string.characters16() + offset, characterLengthLimit); |
98 | 98 |
99 ASSERT(!renderer() || isTextNode()); | 99 ASSERT(!renderer() || isTextNode()); |
100 if (isTextNode()) | 100 if (isTextNode()) |
101 toText(this)->updateTextRenderer(oldLength, 0, DeprecatedAttachNow); | 101 toText(this)->updateTextRenderer(oldLength, 0, DeprecatedAttachNow); |
102 | 102 |
103 document()->incDOMTreeVersion(); | 103 document().incDOMTreeVersion(); |
104 | 104 |
105 if (parentNode()) | 105 if (parentNode()) |
106 parentNode()->childrenChanged(); | 106 parentNode()->childrenChanged(); |
107 | 107 |
108 return characterLengthLimit; | 108 return characterLengthLimit; |
109 } | 109 } |
110 | 110 |
111 void CharacterData::appendData(const String& data, AttachBehavior attachBehavior
) | 111 void CharacterData::appendData(const String& data, AttachBehavior attachBehavior
) |
112 { | 112 { |
113 String newStr = m_data + data; | 113 String newStr = m_data + data; |
114 | 114 |
115 setDataAndUpdate(newStr, m_data.length(), 0, data.length(), attachBehavior); | 115 setDataAndUpdate(newStr, m_data.length(), 0, data.length(), attachBehavior); |
116 | 116 |
117 // FIXME: Should we call textInserted here? | 117 // FIXME: Should we call textInserted here? |
118 } | 118 } |
119 | 119 |
120 void CharacterData::insertData(unsigned offset, const String& data, ExceptionSta
te& es, AttachBehavior attachBehavior) | 120 void CharacterData::insertData(unsigned offset, const String& data, ExceptionSta
te& es, AttachBehavior attachBehavior) |
121 { | 121 { |
122 if (offset > length()) { | 122 if (offset > length()) { |
123 es.throwDOMException(IndexSizeError); | 123 es.throwDOMException(IndexSizeError); |
124 return; | 124 return; |
125 } | 125 } |
126 | 126 |
127 String newStr = m_data; | 127 String newStr = m_data; |
128 newStr.insert(data, offset); | 128 newStr.insert(data, offset); |
129 | 129 |
130 setDataAndUpdate(newStr, offset, 0, data.length(), attachBehavior); | 130 setDataAndUpdate(newStr, offset, 0, data.length(), attachBehavior); |
131 | 131 |
132 document()->textInserted(this, offset, data.length()); | 132 document().textInserted(this, offset, data.length()); |
133 } | 133 } |
134 | 134 |
135 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState&
es, AttachBehavior attachBehavior) | 135 void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionState&
es, AttachBehavior attachBehavior) |
136 { | 136 { |
137 if (offset > length()) { | 137 if (offset > length()) { |
138 es.throwDOMException(IndexSizeError); | 138 es.throwDOMException(IndexSizeError); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 unsigned realCount; | 142 unsigned realCount; |
143 if (offset + count > length()) | 143 if (offset + count > length()) |
144 realCount = length() - offset; | 144 realCount = length() - offset; |
145 else | 145 else |
146 realCount = count; | 146 realCount = count; |
147 | 147 |
148 String newStr = m_data; | 148 String newStr = m_data; |
149 newStr.remove(offset, realCount); | 149 newStr.remove(offset, realCount); |
150 | 150 |
151 setDataAndUpdate(newStr, offset, count, 0, attachBehavior); | 151 setDataAndUpdate(newStr, offset, count, 0, attachBehavior); |
152 | 152 |
153 document()->textRemoved(this, offset, realCount); | 153 document().textRemoved(this, offset, realCount); |
154 } | 154 } |
155 | 155 |
156 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d
ata, ExceptionState& es, AttachBehavior attachBehavior) | 156 void CharacterData::replaceData(unsigned offset, unsigned count, const String& d
ata, ExceptionState& es, AttachBehavior attachBehavior) |
157 { | 157 { |
158 if (offset > length()) { | 158 if (offset > length()) { |
159 es.throwDOMException(IndexSizeError); | 159 es.throwDOMException(IndexSizeError); |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 unsigned realCount; | 163 unsigned realCount; |
164 if (offset + count > length()) | 164 if (offset + count > length()) |
165 realCount = length() - offset; | 165 realCount = length() - offset; |
166 else | 166 else |
167 realCount = count; | 167 realCount = count; |
168 | 168 |
169 String newStr = m_data; | 169 String newStr = m_data; |
170 newStr.remove(offset, realCount); | 170 newStr.remove(offset, realCount); |
171 newStr.insert(data, offset); | 171 newStr.insert(data, offset); |
172 | 172 |
173 setDataAndUpdate(newStr, offset, count, data.length(), attachBehavior); | 173 setDataAndUpdate(newStr, offset, count, data.length(), attachBehavior); |
174 | 174 |
175 // update the markers for spell checking and grammar checking | 175 // update the markers for spell checking and grammar checking |
176 document()->textRemoved(this, offset, realCount); | 176 document().textRemoved(this, offset, realCount); |
177 document()->textInserted(this, offset, data.length()); | 177 document().textInserted(this, offset, data.length()); |
178 } | 178 } |
179 | 179 |
180 String CharacterData::nodeValue() const | 180 String CharacterData::nodeValue() const |
181 { | 181 { |
182 return m_data; | 182 return m_data; |
183 } | 183 } |
184 | 184 |
185 bool CharacterData::containsOnlyWhitespace() const | 185 bool CharacterData::containsOnlyWhitespace() const |
186 { | 186 { |
187 return m_data.containsOnlyWhitespace(); | 187 return m_data.containsOnlyWhitespace(); |
188 } | 188 } |
189 | 189 |
190 void CharacterData::setNodeValue(const String& nodeValue) | 190 void CharacterData::setNodeValue(const String& nodeValue) |
191 { | 191 { |
192 setData(nodeValue); | 192 setData(nodeValue); |
193 } | 193 } |
194 | 194 |
195 void CharacterData::setDataAndUpdate(const String& newData, unsigned offsetOfRep
lacedData, unsigned oldLength, unsigned newLength, AttachBehavior attachBehavior
) | 195 void CharacterData::setDataAndUpdate(const String& newData, unsigned offsetOfRep
lacedData, unsigned oldLength, unsigned newLength, AttachBehavior attachBehavior
) |
196 { | 196 { |
197 String oldData = m_data; | 197 String oldData = m_data; |
198 m_data = newData; | 198 m_data = newData; |
199 | 199 |
200 ASSERT(!renderer() || isTextNode()); | 200 ASSERT(!renderer() || isTextNode()); |
201 if (isTextNode()) | 201 if (isTextNode()) |
202 toText(this)->updateTextRenderer(offsetOfReplacedData, oldLength, attach
Behavior); | 202 toText(this)->updateTextRenderer(offsetOfReplacedData, oldLength, attach
Behavior); |
203 | 203 |
204 if (nodeType() == PROCESSING_INSTRUCTION_NODE) | 204 if (nodeType() == PROCESSING_INSTRUCTION_NODE) |
205 toProcessingInstruction(this)->checkStyleSheet(); | 205 toProcessingInstruction(this)->checkStyleSheet(); |
206 | 206 |
207 if (document()->frame()) | 207 if (document().frame()) |
208 document()->frame()->selection()->textWasReplaced(this, offsetOfReplaced
Data, oldLength, newLength); | 208 document().frame()->selection()->textWasReplaced(this, offsetOfReplacedD
ata, oldLength, newLength); |
209 | 209 |
210 document()->incDOMTreeVersion(); | 210 document().incDOMTreeVersion(); |
211 didModifyData(oldData); | 211 didModifyData(oldData); |
212 } | 212 } |
213 | 213 |
214 void CharacterData::didModifyData(const String& oldData) | 214 void CharacterData::didModifyData(const String& oldData) |
215 { | 215 { |
216 if (OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObser
verInterestGroup::createForCharacterDataMutation(this)) | 216 if (OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObser
verInterestGroup::createForCharacterDataMutation(this)) |
217 mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacte
rData(this, oldData)); | 217 mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacte
rData(this, oldData)); |
218 | 218 |
219 if (parentNode()) | 219 if (parentNode()) |
220 parentNode()->childrenChanged(); | 220 parentNode()->childrenChanged(); |
221 | 221 |
222 if (!isInShadowTree()) { | 222 if (!isInShadowTree()) { |
223 if (document()->hasListenerType(Document::DOMCHARACTERDATAMODIFIED_LISTE
NER)) | 223 if (document().hasListenerType(Document::DOMCHARACTERDATAMODIFIED_LISTEN
ER)) |
224 dispatchScopedEvent(MutationEvent::create(eventNames().DOMCharacterD
ataModifiedEvent, true, 0, oldData, m_data)); | 224 dispatchScopedEvent(MutationEvent::create(eventNames().DOMCharacterD
ataModifiedEvent, true, 0, oldData, m_data)); |
225 dispatchSubtreeModifiedEvent(); | 225 dispatchSubtreeModifiedEvent(); |
226 } | 226 } |
227 InspectorInstrumentation::characterDataModified(document(), this); | 227 InspectorInstrumentation::characterDataModified(&document(), this); |
228 } | 228 } |
229 | 229 |
230 int CharacterData::maxCharacterOffset() const | 230 int CharacterData::maxCharacterOffset() const |
231 { | 231 { |
232 return static_cast<int>(length()); | 232 return static_cast<int>(length()); |
233 } | 233 } |
234 | 234 |
235 bool CharacterData::offsetInCharacters() const | 235 bool CharacterData::offsetInCharacters() const |
236 { | 236 { |
237 return true; | 237 return true; |
238 } | 238 } |
239 | 239 |
240 } // namespace WebCore | 240 } // namespace WebCore |
OLD | NEW |