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 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights
reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights
reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 void Attr::setValue(const AtomicString& value) | 105 void Attr::setValue(const AtomicString& value) |
106 { | 106 { |
107 EventQueueScope scope; | 107 EventQueueScope scope; |
108 m_ignoreChildrenChanged++; | 108 m_ignoreChildrenChanged++; |
109 // We don't fire the DOMSubtreeModified event for Attr Nodes. This matches t
he behavior | 109 // We don't fire the DOMSubtreeModified event for Attr Nodes. This matches t
he behavior |
110 // of IE and Firefox. This event is fired synchronously and is a source of t
rouble for | 110 // of IE and Firefox. This event is fired synchronously and is a source of t
rouble for |
111 // attributes as the JS callback could alter the attributes and leave us in
a bad state. | 111 // attributes as the JS callback could alter the attributes and leave us in
a bad state. |
112 removeChildren(OmitSubtreeModifiedEvent); | 112 removeChildren(OmitSubtreeModifiedEvent); |
113 if (m_element) | 113 if (m_element) |
114 elementAttribute().setValue(value); | 114 updateElementAttribute(value); |
115 else | 115 else |
116 m_standaloneValueOrAttachedLocalName = value; | 116 m_standaloneValueOrAttachedLocalName = value; |
117 createTextChild(); | 117 createTextChild(); |
118 m_ignoreChildrenChanged--; | 118 m_ignoreChildrenChanged--; |
119 | 119 |
120 QualifiedName name = qualifiedName(); | 120 QualifiedName name = qualifiedName(); |
121 invalidateNodeListCachesInAncestors(&name, m_element); | 121 invalidateNodeListCachesInAncestors(&name, m_element); |
122 } | 122 } |
123 | 123 |
124 void Attr::setValueInternal(const AtomicString& value) | 124 void Attr::setValueInternal(const AtomicString& value) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 for (Node *n = firstChild(); n; n = n->nextSibling()) { | 180 for (Node *n = firstChild(); n; n = n->nextSibling()) { |
181 if (n->isTextNode()) | 181 if (n->isTextNode()) |
182 valueBuilder.append(toText(n)->data()); | 182 valueBuilder.append(toText(n)->data()); |
183 } | 183 } |
184 | 184 |
185 AtomicString newValue = valueBuilder.toAtomicString(); | 185 AtomicString newValue = valueBuilder.toAtomicString(); |
186 if (m_element) | 186 if (m_element) |
187 m_element->willModifyAttribute(qualifiedName(), value(), newValue); | 187 m_element->willModifyAttribute(qualifiedName(), value(), newValue); |
188 | 188 |
189 if (m_element) | 189 if (m_element) |
190 elementAttribute().setValue(newValue); | 190 updateElementAttribute(newValue); |
191 else | 191 else |
192 m_standaloneValueOrAttachedLocalName = newValue; | 192 m_standaloneValueOrAttachedLocalName = newValue; |
193 | 193 |
194 if (m_element) | 194 if (m_element) |
195 m_element->attributeChanged(qualifiedName(), newValue); | 195 m_element->attributeChanged(qualifiedName(), newValue); |
196 } | 196 } |
197 | 197 |
198 const AtomicString& Attr::value() const | 198 const AtomicString& Attr::value() const |
199 { | 199 { |
200 if (m_element) | 200 if (m_element) |
201 return m_element->getAttribute(qualifiedName()); | 201 return m_element->getAttribute(qualifiedName()); |
202 return m_standaloneValueOrAttachedLocalName; | 202 return m_standaloneValueOrAttachedLocalName; |
203 } | 203 } |
204 | 204 |
205 Attribute& Attr::elementAttribute() | 205 void Attr::updateElementAttribute(const AtomicString& value) |
206 { | 206 { |
207 ASSERT(m_element); | 207 ASSERT(m_element); |
208 ASSERT(m_element->elementData()); | 208 ASSERT(m_element->elementData()); |
209 return *m_element->ensureUniqueElementData().attributes().find(qualifiedName
()); | 209 MutableAttributeCollection attributes = m_element->ensureUniqueElementData()
.attributes(); |
| 210 size_t index = attributes.findIndex(qualifiedName()); |
| 211 if (index == kNotFound) { |
| 212 // Element attributes with null values are not stored. |
| 213 if (!value.isNull()) |
| 214 attributes.append(qualifiedName(), value); |
| 215 return; |
| 216 } |
| 217 return attributes[index].setValue(value); |
210 } | 218 } |
211 | 219 |
212 void Attr::detachFromElementWithValue(const AtomicString& value) | 220 void Attr::detachFromElementWithValue(const AtomicString& value) |
213 { | 221 { |
214 ASSERT(m_element); | 222 ASSERT(m_element); |
215 m_standaloneValueOrAttachedLocalName = value; | 223 m_standaloneValueOrAttachedLocalName = value; |
216 m_element = nullptr; | 224 m_element = nullptr; |
217 } | 225 } |
218 | 226 |
219 void Attr::attachToElement(Element* element, const AtomicString& attachedLocalNa
me) | 227 void Attr::attachToElement(Element* element, const AtomicString& attachedLocalNa
me) |
220 { | 228 { |
221 ASSERT(!m_element); | 229 ASSERT(!m_element); |
222 m_element = element; | 230 m_element = element; |
223 m_standaloneValueOrAttachedLocalName = attachedLocalName; | 231 m_standaloneValueOrAttachedLocalName = attachedLocalName; |
224 } | 232 } |
225 | 233 |
226 DEFINE_TRACE(Attr) | 234 DEFINE_TRACE(Attr) |
227 { | 235 { |
228 visitor->trace(m_element); | 236 visitor->trace(m_element); |
229 ContainerNode::trace(visitor); | 237 ContainerNode::trace(visitor); |
230 } | 238 } |
231 | 239 |
232 } | 240 } |
OLD | NEW |