Changeset 102695 in webkit
- Timestamp:
- Dec 13, 2011 12:40:51 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102691 r102695 1 2011-12-13 Adam Klein <adamk@chromium.org> 2 3 Reduce code duplication in Element::setAttribute methods 4 https://bugs.webkit.org/show_bug.cgi?id=74425 5 6 Reviewed by Ryosuke Niwa. 7 8 Two overloads of Element::setAttribute share almost all their code, 9 including tricky logic around updating the appropriate Attribute and 10 Attr objects and notifying the Inspector and MutationObservers. 11 12 This patch puts the common logic in a new setAttributeInternal method 13 which is called by the other two. 14 15 No new tests, refactoring only. 16 17 * dom/Element.cpp: 18 (WebCore::Element::setAttribute): 19 (WebCore::Element::setAttributeInternal): 20 * dom/Element.h: 21 1 22 2011-12-13 Brady Eidson <beidson@apple.com> 2 23 -
trunk/Source/WebCore/dom/Element.cpp
r102423 r102695 636 636 } 637 637 638 const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 639 640 // Allocate attribute map if necessary. 641 Attribute* old = attributes(false)->getAttributeItem(localName, false); 642 setAttributeInternal(old, old ? old->name() : QualifiedName(nullAtom, localName, nullAtom), value); 643 } 644 645 void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&) 646 { 647 // Allocate attribute map if necessary. 648 Attribute* old = attributes(false)->getAttributeItem(name); 649 setAttributeInternal(old, name, value); 650 } 651 652 void Element::setAttributeInternal(Attribute* old, const QualifiedName& name, const AtomicString& value) 653 { 638 654 #if ENABLE(INSPECTOR) 639 655 if (!isSynchronizingStyleAttribute()) … … 641 657 #endif 642 658 643 const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;644 QualifiedName attributeName(nullAtom, localName, nullAtom);645 646 // Allocate attribute map if necessary.647 Attribute* old = attributes(false)->getAttributeItem(localName, false);648 649 659 document()->incDOMTreeVersion(); 650 651 #if ENABLE(MUTATION_OBSERVERS)652 // The call to attributeChanged below may dispatch DOMSubtreeModified, so it's important to enqueue a MutationRecord now.653 if (!isSynchronizingStyleAttribute())654 enqueueAttributesMutationRecord(this, attributeName, old ? old->value() : nullAtom);655 #endif656 657 if (isIdAttributeName(old ? old->name() : attributeName))658 updateId(old ? old->value() : nullAtom, value);659 660 if (old && value.isNull())661 m_attributeMap->removeAttribute(old->name());662 else if (!old && !value.isNull())663 m_attributeMap->addAttribute(createAttribute(attributeName, value));664 else if (old && !value.isNull()) {665 if (Attr* attrNode = old->attr())666 attrNode->setValue(value);667 else668 old->setValue(value);669 attributeChanged(old);670 }671 672 #if ENABLE(INSPECTOR)673 if (!isSynchronizingStyleAttribute())674 InspectorInstrumentation::didModifyDOMAttr(document(), this, name, value);675 #endif676 }677 678 void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&)679 {680 #if ENABLE(INSPECTOR)681 if (!isSynchronizingStyleAttribute())682 InspectorInstrumentation::willModifyDOMAttr(document(), this);683 #endif684 685 document()->incDOMTreeVersion();686 687 // Allocate attribute map if necessary.688 Attribute* old = attributes(false)->getAttributeItem(name);689 660 690 661 #if ENABLE(MUTATION_OBSERVERS) -
trunk/Source/WebCore/dom/Element.h
r102081 r102695 396 396 virtual bool childTypeAllowed(NodeType) const; 397 397 398 void setAttributeInternal(Attribute* old, const QualifiedName&, const AtomicString& value); 398 399 virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value); 399 400
Note: See TracChangeset
for help on using the changeset viewer.