2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2001 Peter Kelly (pmk@post.com)
7 * (C) 2001 Dirk Mueller (mueller@kde.org)
8 * Copyright (C) 2004 Apple Computer, Inc.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 #include "dom/dom_exception.h"
28 #include "dom/dom_node.h"
29 #include "xml/dom_textimpl.h"
30 #include "xml/dom_docimpl.h"
31 #include "xml/dom2_eventsimpl.h"
32 #include "xml/dom_elementimpl.h"
34 #include "khtml_part.h"
37 #include "html/htmlparser.h"
39 #include "rendering/render_canvas.h"
40 #include "misc/htmlhashes.h"
41 #include "css/css_valueimpl.h"
42 #include "css/css_stylesheetimpl.h"
43 #include "css/cssstyleselector.h"
44 #include "xml/dom_xmlimpl.h"
46 #include <qtextstream.h>
50 using namespace khtml;
52 AttributeImpl* AttributeImpl::clone(bool) const
54 AttributeImpl* result = new AttributeImpl(m_id, _value);
55 result->setPrefix(_prefix);
59 void AttributeImpl::allocateImpl(ElementImpl* e) {
60 _impl = new AttrImpl(e, e->docPtr(), this);
63 AttrImpl::AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a)
64 : NodeBaseImpl(docPtr),
68 assert(!m_attribute->_impl);
69 m_attribute->_impl = this;
76 assert(m_attribute->_impl == this);
77 m_attribute->_impl = 0;
81 DOMString AttrImpl::nodeName() const
83 return getDocument()->attrName(m_attribute->id());
86 unsigned short AttrImpl::nodeType() const
88 return Node::ATTRIBUTE_NODE;
91 DOMString AttrImpl::prefix() const
93 return m_attribute->prefix();
96 void AttrImpl::setPrefix(const DOMString &_prefix, int &exceptioncode )
98 checkSetPrefix(_prefix, exceptioncode);
102 m_attribute->setPrefix(_prefix.implementation());
105 DOMString AttrImpl::nodeValue() const {
106 return m_attribute->value();
109 void AttrImpl::setValue( const DOMString &v, int &exceptioncode )
113 // ### according to the DOM docs, we should create an unparsed Text child
115 // do not interprete entities in the string, its literal!
117 // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
119 exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
123 // ### what to do on 0 ?
125 exceptioncode = DOMException::DOMSTRING_SIZE_ERR;
129 m_attribute->setValue(v.implementation());
131 m_element->attributeChanged(m_attribute);
134 void AttrImpl::setNodeValue( const DOMString &v, int &exceptioncode )
137 // NO_MODIFICATION_ALLOWED_ERR: taken care of by setValue()
138 setValue(v, exceptioncode);
141 NodeImpl *AttrImpl::cloneNode ( bool /*deep*/)
143 return new AttrImpl(0, docPtr(), m_attribute->clone());
147 bool AttrImpl::childAllowed( NodeImpl *newChild )
152 return childTypeAllowed(newChild->nodeType());
155 bool AttrImpl::childTypeAllowed( unsigned short type )
158 case Node::TEXT_NODE:
159 case Node::ENTITY_REFERENCE_NODE:
167 DOMString AttrImpl::toString() const
171 result += nodeName();
173 // FIXME: substitute entities for any instances of " or ' --
174 // maybe easier to just use text value and ignore existing
177 if (firstChild() != NULL) {
180 for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
181 result += child->toString();
190 // -------------------------------------------------------------------------
192 ElementImpl::ElementImpl(DocumentPtr *doc)
199 ElementImpl::~ElementImpl()
202 namedAttrMap->detachFromElement();
203 namedAttrMap->deref();
210 void ElementImpl::removeAttribute( NodeImpl::Id id, int &exceptioncode )
213 namedAttrMap->removeNamedItem(id, exceptioncode);
214 if (exceptioncode == DOMException::NOT_FOUND_ERR) {
220 void ElementImpl::setAttribute(NodeImpl::Id id, const DOMString &value)
222 int exceptioncode = 0;
223 setAttribute(id,value.implementation(),exceptioncode);
226 NamedAttrMapImpl* ElementImpl::attributes(bool readonly) const
228 updateStyleAttributeIfNeeded();
230 if (!readonly && !namedAttrMap) createAttributeMap();
234 unsigned short ElementImpl::nodeType() const
236 return Node::ELEMENT_NODE;
239 const AtomicStringList* ElementImpl::getClassList() const
244 const AtomicString& ElementImpl::getIDAttribute() const
246 return namedAttrMap ? namedAttrMap->id() : nullAtom;
249 const AtomicString& ElementImpl::getAttribute(NodeImpl::Id id) const
251 if (id == ATTR_STYLE)
252 updateStyleAttributeIfNeeded();
255 AttributeImpl* a = namedAttrMap->getAttributeItem(id);
256 if (a) return a->value();
261 const AtomicString& ElementImpl::getAttributeNS(const DOMString &namespaceURI,
262 const DOMString &localName) const
264 NodeImpl::Id id = getDocument()->attrId(namespaceURI.implementation(),
265 localName.implementation(), true);
266 if (!id) return nullAtom;
267 return getAttribute(id);
270 void ElementImpl::setAttribute(NodeImpl::Id id, DOMStringImpl* value, int &exceptioncode )
273 getDocument()->incDOMTreeVersion();
275 // allocate attributemap if necessary
276 AttributeImpl* old = attributes(false)->getAttributeItem(id);
278 // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
279 if (namedAttrMap->isReadOnly()) {
280 exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
285 updateId(old ? old->value() : nullAtom, value);
289 namedAttrMap->removeAttribute(id);
290 else if (!old && value)
291 namedAttrMap->addAttribute(createAttribute(id, value));
292 else if (old && value) {
293 old->setValue(value);
294 attributeChanged(old);
298 AttributeImpl* ElementImpl::createAttribute(NodeImpl::Id id, DOMStringImpl* value)
300 return new AttributeImpl(id, value);
303 void ElementImpl::setAttributeMap( NamedAttrMapImpl* list )
306 getDocument()->incDOMTreeVersion();
308 // If setting the whole map changes the id attribute, we need to
311 AttributeImpl *oldId = namedAttrMap ? namedAttrMap->getAttributeItem(ATTR_ID) : 0;
312 AttributeImpl *newId = list ? list->getAttributeItem(ATTR_ID) : 0;
314 if (oldId || newId) {
315 updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom);
319 namedAttrMap->deref();
325 namedAttrMap->element = this;
326 unsigned int len = namedAttrMap->length();
327 for(unsigned int i = 0; i < len; i++)
328 attributeChanged(namedAttrMap->attrs[i]);
332 bool ElementImpl::hasAttributes() const
334 updateStyleAttributeIfNeeded();
336 return namedAttrMap && namedAttrMap->length() > 0;
339 DOMString ElementImpl::nodeName() const
344 DOMString ElementImpl::tagName() const
346 DOMString tn = getDocument()->tagName(id());
349 return DOMString(m_prefix) + ":" + tn;
354 void ElementImpl::setPrefix( const DOMString &_prefix, int &exceptioncode )
356 checkSetPrefix(_prefix, exceptioncode);
362 m_prefix = _prefix.implementation();
367 void ElementImpl::createAttributeMap() const
369 namedAttrMap = new NamedAttrMapImpl(const_cast<ElementImpl*>(this));
373 bool ElementImpl::isURLAttribute(AttributeImpl *attr) const
379 RenderStyle *ElementImpl::styleForRenderer(RenderObject *parentRenderer)
381 return getDocument()->styleSelector()->styleForElement(this);
384 RenderObject *ElementImpl::createRenderer(RenderArena *arena, RenderStyle *style)
386 if (getDocument()->documentElement() == this && style->display() == NONE) {
387 // Ignore display: none on root elements. Force a display of block in that case.
388 RenderBlock* result = new (arena) RenderBlock(this);
389 if (result) result->setStyle(style);
392 return RenderObject::createObject(this, style);
396 void ElementImpl::insertedIntoDocument()
398 // need to do superclass processing first so inDocument() is true
399 // by the time we reach updateId
400 NodeBaseImpl::insertedIntoDocument();
403 NamedAttrMapImpl *attrs = attributes(true);
405 AttributeImpl *idAttr = attrs->getAttributeItem(ATTR_ID);
406 if (idAttr && !idAttr->isNull()) {
407 updateId(nullAtom, idAttr->value());
413 void ElementImpl::removedFromDocument()
416 NamedAttrMapImpl *attrs = attributes(true);
418 AttributeImpl *idAttr = attrs->getAttributeItem(ATTR_ID);
419 if (idAttr && !idAttr->isNull()) {
420 updateId(idAttr->value(), nullAtom);
425 NodeBaseImpl::removedFromDocument();
428 void ElementImpl::attach()
431 createRendererIfNeeded();
433 NodeBaseImpl::attach();
436 void ElementImpl::recalcStyle( StyleChange change )
438 // ### should go away and be done in renderobject
439 RenderStyle* _style = m_render ? m_render->style() : 0;
440 bool hasParentRenderer = parent() ? parent()->renderer() : false;
445 case NoChange: debug = "NoChange";
447 case NoInherit: debug= "NoInherit";
449 case Inherit: debug = "Inherit";
451 case Force: debug = "Force";
454 qDebug("recalcStyle(%d: %s)[%p: %s]", change, debug, this, tagName().string().latin1());
456 if ( hasParentRenderer && (change >= Inherit || changed()) ) {
457 RenderStyle *newStyle = getDocument()->styleSelector()->styleForElement(this);
459 StyleChange ch = diff( _style, newStyle );
461 if (attached()) detach();
462 // ### Suboptimal. Style gets calculated again.
464 // attach recalulates the style for all children. No need to do it twice.
466 setHasChangedChild( false );
467 newStyle->deref(getDocument()->renderArena());
470 else if (ch != NoChange) {
471 if( m_render && newStyle ) {
472 //qDebug("--> setting style on render element bgcolor=%s", newStyle->backgroundColor().name().latin1());
473 m_render->setStyle(newStyle);
476 else if (changed() && m_render && newStyle && (getDocument()->usesSiblingRules() || getDocument()->usesDescendantRules())) {
477 // Although no change occurred, we use the new style so that the cousin style sharing code won't get
478 // fooled into believing this style is the same. This is only necessary if the document actually uses
479 // sibling/descendant rules, since otherwise it isn't possible for ancestor styles to affect sharing of
481 m_render->setStyleInternal(newStyle);
484 newStyle->deref(getDocument()->renderArena());
486 if ( change != Force) {
487 if (getDocument()->usesDescendantRules())
495 for (n = _first; n; n = n->nextSibling()) {
496 //qDebug(" (%p) calling recalcStyle on child %s/%p, change=%d", this, n, n->isElementNode() ? ((ElementImpl *)n)->tagName().string().latin1() : n->isTextNode() ? "text" : "unknown", change );
497 if ( change >= Inherit || n->isTextNode() ||
498 n->hasChangedChild() || n->changed() )
499 n->recalcStyle( change );
503 setHasChangedChild( false );
507 bool ElementImpl::childAllowed( NodeImpl *newChild )
509 if (!childTypeAllowed(newChild->nodeType()))
512 // For XML documents, we are non-validating and do not check against a DTD, even for HTML elements.
513 if (getDocument()->isHTMLDocument())
514 return checkChild(id(), newChild->id(), !getDocument()->inCompatMode());
518 bool ElementImpl::childTypeAllowed( unsigned short type )
521 case Node::ELEMENT_NODE:
522 case Node::TEXT_NODE:
523 case Node::COMMENT_NODE:
524 case Node::PROCESSING_INSTRUCTION_NODE:
525 case Node::CDATA_SECTION_NODE:
526 case Node::ENTITY_REFERENCE_NODE:
534 void ElementImpl::dispatchAttrRemovalEvent(AttributeImpl *attr)
536 if (!getDocument()->hasListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER))
538 //int exceptioncode = 0;
539 // dispatchEvent(new MutationEventImpl(EventImpl::DOMATTRMODIFIED_EVENT,true,false,attr,attr->value(),
540 // attr->value(), getDocument()->attrName(attr->id()),MutationEvent::REMOVAL),exceptioncode);
543 void ElementImpl::dispatchAttrAdditionEvent(AttributeImpl *attr)
545 if (!getDocument()->hasListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER))
547 // int exceptioncode = 0;
548 // dispatchEvent(new MutationEventImpl(EventImpl::DOMATTRMODIFIED_EVENT,true,false,attr,attr->value(),
549 // attr->value(),getDocument()->attrName(attr->id()),MutationEvent::ADDITION),exceptioncode);
552 DOMString ElementImpl::openTagStartToString() const
554 DOMString result = DOMString("<") + tagName();
556 NamedAttrMapImpl *attrMap = attributes(true);
559 unsigned long numAttrs = attrMap->length();
560 for (unsigned long i = 0; i < numAttrs; i++) {
563 AttributeImpl *attribute = attrMap->attributeItem(i);
564 AttrImpl *attr = attribute->attrImpl();
567 result += attr->toString();
569 result += getDocument()->attrName(attribute->id());
570 if (!attribute->value().isNull()) {
572 // FIXME: substitute entities for any instances of " or '
573 result += attribute->value();
583 DOMString ElementImpl::toString() const
585 DOMString result = openTagStartToString();
587 if (hasChildNodes()) {
590 for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
591 result += child->toString();
604 void ElementImpl::updateId(const AtomicString& oldId, const AtomicString& newId)
612 DocumentImpl* doc = getDocument();
613 if (!oldId.isEmpty())
614 doc->removeElementById(oldId, this);
615 if (!newId.isEmpty())
616 doc->addElementById(newId, this);
620 void ElementImpl::dump(QTextStream *stream, QString ind) const
622 updateStyleAttributeIfNeeded();
624 for (uint i = 0; i < namedAttrMap->length(); i++) {
625 AttributeImpl *attr = namedAttrMap->attributeItem(i);
626 *stream << " " << DOMString(getDocument()->attrName(attr->id())).string().ascii()
627 << "=\"" << DOMString(attr->value()).string().ascii() << "\"";
631 NodeBaseImpl::dump(stream,ind);
636 void ElementImpl::formatForDebugger(char *buffer, unsigned length) const
642 if (s.length() > 0) {
646 s = getAttribute(ATTR_ID);
647 if (s.length() > 0) {
648 if (result.length() > 0)
654 s = getAttribute(ATTR_CLASS);
655 if (s.length() > 0) {
656 if (result.length() > 0)
662 strncpy(buffer, result.string().latin1(), length - 1);
666 // -------------------------------------------------------------------------
668 XMLElementImpl::XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_tagName)
671 m_id = doc->document()->tagId(0 /* no namespace */, _tagName, false /* allocate */);
674 XMLElementImpl::XMLElementImpl(DocumentPtr *doc, DOMStringImpl *_qualifiedName, DOMStringImpl *_namespaceURI)
678 for (uint i = 0; i < _qualifiedName->l; ++i)
679 if (_qualifiedName->s[i] == ':') {
686 DOMStringImpl* localName = _qualifiedName->copy();
688 localName->remove(0,colonpos+1);
689 m_id = doc->document()->tagId(_namespaceURI, localName, false /* allocate */);
691 m_prefix = _qualifiedName->copy();
693 m_prefix->truncate(colonpos);
697 m_id = doc->document()->tagId(_namespaceURI, _qualifiedName, false /* allocate */);
702 XMLElementImpl::~XMLElementImpl()
706 DOMString XMLElementImpl::localName() const
708 return getDocument()->tagName(m_id);
711 DOMString XMLElementImpl::namespaceURI() const
713 return getDocument()->namespaceURI(m_id);
716 NodeImpl *XMLElementImpl::cloneNode ( bool deep )
718 // ### we loose namespace here FIXME
719 // should pass id around
720 XMLElementImpl *clone = new XMLElementImpl(docPtr(), getDocument()->tagName(m_id).implementation());
725 *clone->attributes() = *namedAttrMap;
728 cloneChildNodes(clone);
733 // -------------------------------------------------------------------------
735 NamedAttrMapImpl::NamedAttrMapImpl(ElementImpl *e)
742 NamedAttrMapImpl::~NamedAttrMapImpl()
744 NamedAttrMapImpl::clearAttributes(); // virtual method, so qualify just to be explicit
747 bool NamedAttrMapImpl::isHTMLAttributeMap() const
752 AttrImpl *NamedAttrMapImpl::getNamedItem ( NodeImpl::Id id ) const
754 AttributeImpl* a = getAttributeItem(id);
758 a->allocateImpl(element);
760 return a->attrImpl();
763 Node NamedAttrMapImpl::setNamedItem ( NodeImpl* arg, int &exceptioncode )
766 exceptioncode = DOMException::NOT_FOUND_ERR;
770 // NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
772 exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
776 // WRONG_DOCUMENT_ERR: Raised if arg was created from a different document than the one that created this map.
777 if (arg->getDocument() != element->getDocument()) {
778 exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
782 // Not mentioned in spec: throw a HIERARCHY_REQUEST_ERROR if the user passes in a non-attribute node
783 if (!arg->isAttributeNode()) {
784 exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
787 AttrImpl *attr = static_cast<AttrImpl*>(arg);
789 AttributeImpl* a = attr->attrImpl();
790 AttributeImpl* old = getAttributeItem(a->id());
791 if (old == a) return arg; // we know about it already
793 // INUSE_ATTRIBUTE_ERR: Raised if arg is an Attr that is already an attribute of another Element object.
794 // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
795 if (attr->ownerElement()) {
796 exceptioncode = DOMException::INUSE_ATTRIBUTE_ERR;
800 if (a->id() == ATTR_ID) {
801 element->updateId(old ? old->value() : nullAtom, a->value());
804 // ### slightly inefficient - resizes attribute array twice.
807 if (!old->attrImpl())
808 old->allocateImpl(element);
810 removeAttribute(a->id());
817 // The DOM2 spec doesn't say that removeAttribute[NS] throws NOT_FOUND_ERR
818 // if the attribute is not found, but at this level we have to throw NOT_FOUND_ERR
819 // because of removeNamedItem, removeNamedItemNS, and removeAttributeNode.
820 Node NamedAttrMapImpl::removeNamedItem ( NodeImpl::Id id, int &exceptioncode )
822 // ### should this really be raised when the attribute to remove isn't there at all?
823 // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
825 exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
829 AttributeImpl* a = getAttributeItem(id);
831 exceptioncode = DOMException::NOT_FOUND_ERR;
835 if (!a->attrImpl()) a->allocateImpl(element);
836 Node r(a->attrImpl());
839 element->updateId(a->value(), nullAtom);
846 AttrImpl *NamedAttrMapImpl::item ( unsigned long index ) const
851 if (!attrs[index]->attrImpl())
852 attrs[index]->allocateImpl(element);
854 return attrs[index]->attrImpl();
857 AttributeImpl* NamedAttrMapImpl::getAttributeItem(NodeImpl::Id id) const
859 bool matchAnyNamespace = (namespacePart(id) == anyNamespace);
860 for (unsigned long i = 0; i < len; ++i) {
861 if (attrs[i]->id() == id)
863 else if (matchAnyNamespace) {
864 if (localNamePart(attrs[i]->id()) == localNamePart(id))
871 NodeImpl::Id NamedAttrMapImpl::mapId(const DOMString& namespaceURI,
872 const DOMString& localName, bool readonly)
875 if (!element) return 0;
876 return element->getDocument()->attrId(namespaceURI.implementation(),
877 localName.implementation(), readonly);
880 void NamedAttrMapImpl::clearAttributes()
884 for (i = 0; i < len; i++) {
886 attrs[i]->_impl->m_element = 0;
889 main_thread_free(attrs);
895 void NamedAttrMapImpl::detachFromElement()
897 // we allow a NamedAttrMapImpl w/o an element in case someone still has a reference
898 // to if after the element gets deleted - but the map is now invalid
903 NamedAttrMapImpl& NamedAttrMapImpl::operator=(const NamedAttrMapImpl& other)
905 // clone all attributes in the other map, but attach to our element
906 if (!element) return *this;
908 // If assigning the map changes the id attribute, we need to call
911 AttributeImpl *oldId = getAttributeItem(ATTR_ID);
912 AttributeImpl *newId = other.getAttributeItem(ATTR_ID);
914 if (oldId || newId) {
915 element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom);
920 attrs = static_cast<AttributeImpl **>(main_thread_malloc(len * sizeof(AttributeImpl *)));
922 // first initialize attrs vector, then call attributeChanged on it
923 // this allows attributeChanged to use getAttribute
924 for (uint i = 0; i < len; i++) {
925 attrs[i] = other.attrs[i]->clone();
929 // FIXME: This is wasteful. The class list could be preserved on a copy, and we
930 // wouldn't have to waste time reparsing the attribute.
931 // The derived class, HTMLNamedAttrMapImpl, which manages a parsed class list for the CLASS attribute,
932 // will update its member variable when parse attribute is called.
933 for(uint i = 0; i < len; i++)
934 element->attributeChanged(attrs[i], true);
939 void NamedAttrMapImpl::addAttribute(AttributeImpl *attr)
941 // Add the attribute to the list
942 AttributeImpl **newAttrs = static_cast<AttributeImpl **>(main_thread_malloc((len + 1) * sizeof(AttributeImpl *)));
944 for (uint i = 0; i < len; i++)
945 newAttrs[i] = attrs[i];
946 main_thread_free(attrs);
952 AttrImpl * const attrImpl = attr->_impl;
954 attrImpl->m_element = element;
956 // Notify the element that the attribute has been added, and dispatch appropriate mutation events
957 // Note that element may be null here if we are called from insertAttr() during parsing
959 element->attributeChanged(attr);
960 element->dispatchAttrAdditionEvent(attr);
961 element->dispatchSubtreeModifiedEvent(false);
965 void NamedAttrMapImpl::removeAttribute(NodeImpl::Id id)
967 unsigned long index = len+1;
968 for (unsigned long i = 0; i < len; ++i)
969 if (attrs[i]->id() == id) {
974 if (index >= len) return;
976 // Remove the attribute from the list
977 AttributeImpl* attr = attrs[index];
978 if (attrs[index]->_impl)
979 attrs[index]->_impl->m_element = 0;
981 main_thread_free(attrs);
986 AttributeImpl **newAttrs = static_cast<AttributeImpl **>(main_thread_malloc((len - 1) * sizeof(AttributeImpl *)));
988 for (i = 0; i < uint(index); i++)
989 newAttrs[i] = attrs[i];
992 newAttrs[i] = attrs[i+1];
993 main_thread_free(attrs);
997 // Notify the element that the attribute has been removed
998 // dispatch appropriate mutation events
999 if (element && !attr->_value.isNull()) {
1000 AtomicString value = attr->_value;
1001 attr->_value = nullAtom;
1002 element->attributeChanged(attr);
1003 attr->_value = value;
1006 element->dispatchAttrRemovalEvent(attr);
1007 element->dispatchSubtreeModifiedEvent(false);