Title: [102695] trunk/Source/WebCore
Revision
102695
Author
[email protected]
Date
2011-12-13 12:40:51 -0800 (Tue, 13 Dec 2011)

Log Message

Reduce code duplication in Element::setAttribute methods
https://bugs.webkit.org/show_bug.cgi?id=74425

Reviewed by Ryosuke Niwa.

Two overloads of Element::setAttribute share almost all their code,
including tricky logic around updating the appropriate Attribute and
Attr objects and notifying the Inspector and MutationObservers.

This patch puts the common logic in a new setAttributeInternal method
which is called by the other two.

No new tests, refactoring only.

* dom/Element.cpp:
(WebCore::Element::setAttribute):
(WebCore::Element::setAttributeInternal):
* dom/Element.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102694 => 102695)


--- trunk/Source/WebCore/ChangeLog	2011-12-13 19:49:49 UTC (rev 102694)
+++ trunk/Source/WebCore/ChangeLog	2011-12-13 20:40:51 UTC (rev 102695)
@@ -1,3 +1,24 @@
+2011-12-13  Adam Klein  <[email protected]>
+
+        Reduce code duplication in Element::setAttribute methods
+        https://bugs.webkit.org/show_bug.cgi?id=74425
+
+        Reviewed by Ryosuke Niwa.
+
+        Two overloads of Element::setAttribute share almost all their code,
+        including tricky logic around updating the appropriate Attribute and
+        Attr objects and notifying the Inspector and MutationObservers.
+
+        This patch puts the common logic in a new setAttributeInternal method
+        which is called by the other two.
+
+        No new tests, refactoring only.
+
+        * dom/Element.cpp:
+        (WebCore::Element::setAttribute):
+        (WebCore::Element::setAttributeInternal):
+        * dom/Element.h:
+
 2011-12-13  Brady Eidson  <[email protected]>
 
         <http://webkit.org/b/74420> Disable deprecation warnings around more code where we 

Modified: trunk/Source/WebCore/dom/Element.cpp (102694 => 102695)


--- trunk/Source/WebCore/dom/Element.cpp	2011-12-13 19:49:49 UTC (rev 102694)
+++ trunk/Source/WebCore/dom/Element.cpp	2011-12-13 20:40:51 UTC (rev 102695)
@@ -635,48 +635,22 @@
         return;
     }
 
-#if ENABLE(INSPECTOR)
-    if (!isSynchronizingStyleAttribute())
-        InspectorInstrumentation::willModifyDOMAttr(document(), this);
-#endif
-
     const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
-    QualifiedName attributeName(nullAtom, localName, nullAtom);
-    
+
     // Allocate attribute map if necessary.
     Attribute* old = attributes(false)->getAttributeItem(localName, false);
-
-    document()->incDOMTreeVersion();
-
-#if ENABLE(MUTATION_OBSERVERS)
-    // The call to attributeChanged below may dispatch DOMSubtreeModified, so it's important to enqueue a MutationRecord now.
-    if (!isSynchronizingStyleAttribute())
-        enqueueAttributesMutationRecord(this, attributeName, old ? old->value() : nullAtom);
-#endif
-
-    if (isIdAttributeName(old ? old->name() : attributeName))
-        updateId(old ? old->value() : nullAtom, value);
-
-    if (old && value.isNull())
-        m_attributeMap->removeAttribute(old->name());
-    else if (!old && !value.isNull())
-        m_attributeMap->addAttribute(createAttribute(attributeName, value));
-    else if (old && !value.isNull()) {
-        if (Attr* attrNode = old->attr())
-            attrNode->setValue(value);
-        else
-            old->setValue(value);
-        attributeChanged(old);
-    }
-
-#if ENABLE(INSPECTOR)
-    if (!isSynchronizingStyleAttribute())
-        InspectorInstrumentation::didModifyDOMAttr(document(), this, name, value);
-#endif
+    setAttributeInternal(old, old ? old->name() : QualifiedName(nullAtom, localName, nullAtom), value);
 }
 
 void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&)
 {
+    // Allocate attribute map if necessary.
+    Attribute* old = attributes(false)->getAttributeItem(name);
+    setAttributeInternal(old, name, value);
+}
+
+void Element::setAttributeInternal(Attribute* old, const QualifiedName& name, const AtomicString& value)
+{
 #if ENABLE(INSPECTOR)
     if (!isSynchronizingStyleAttribute())
         InspectorInstrumentation::willModifyDOMAttr(document(), this);
@@ -684,9 +658,6 @@
 
     document()->incDOMTreeVersion();
 
-    // Allocate attribute map if necessary.
-    Attribute* old = attributes(false)->getAttributeItem(name);
-
 #if ENABLE(MUTATION_OBSERVERS)
     // The call to attributeChanged below may dispatch DOMSubtreeModified, so it's important to enqueue a MutationRecord now.
     if (!isSynchronizingStyleAttribute())

Modified: trunk/Source/WebCore/dom/Element.h (102694 => 102695)


--- trunk/Source/WebCore/dom/Element.h	2011-12-13 19:49:49 UTC (rev 102694)
+++ trunk/Source/WebCore/dom/Element.h	2011-12-13 20:40:51 UTC (rev 102695)
@@ -395,6 +395,7 @@
     virtual NodeType nodeType() const;
     virtual bool childTypeAllowed(NodeType) const;
 
+    void setAttributeInternal(Attribute* old, const QualifiedName&, const AtomicString& value);
     virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
     
 #ifndef NDEBUG
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to