Web Inspector: DOMAttrModified should not be fired if the attribute value remains...
authorapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Feb 2012 13:11:40 +0000 (13:11 +0000)
committerapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Feb 2012 13:11:40 +0000 (13:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79025

Reviewed by Pavel Feldman.

Source/WebCore:

* dom/Element.cpp:
(WebCore::Element::willModifyAttribute):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::InspectorDOMAgent):
(WebCore::InspectorDOMAgent::willModifyDOMAttr):
(WebCore):
(WebCore::InspectorDOMAgent::didModifyDOMAttr):
* inspector/InspectorDOMAgent.h:
(InspectorDOMAgent):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willModifyDOMAttrImpl):
* inspector/InspectorInstrumentation.h:
(InspectorInstrumentation):
(WebCore::InspectorInstrumentation::willModifyDOMAttr):

LayoutTests:

* inspector/elements/set-attribute-expected.txt:
* inspector/elements/set-attribute.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108235 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/elements/set-attribute-expected.txt
LayoutTests/inspector/elements/set-attribute.html
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h

index 10b2a0d..bb42acb 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-20  Alexander Pavlov  <apavlov@chromium.org>
+
+        Web Inspector: DOMAttrModified should not be fired if the attribute value remains the same
+        https://bugs.webkit.org/show_bug.cgi?id=79025
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/elements/set-attribute-expected.txt:
+        * inspector/elements/set-attribute.html:
+
 2012-02-20  Yosifumi Inoue  <yosin@chromium.org>
 
         [Forms] Spin buttons of number input type should fire both input and change event
index b2c1497..4521ad5 100644 (file)
@@ -9,6 +9,10 @@ Running: testAttributeUpdated
 ===== On attribute set =====
   <div id="node" name="value"></div>
 
+Running: testAttributeSameValueNotUpdated
+===== On attribute modified (should be 'newValue') =====
+  <div id="node" name="newValue"></div>
+
 Running: testAttributeRemoved
 === On attribute removed ===
   <div id="node"></div>
index 164c252..130a7b0 100644 (file)
@@ -46,6 +46,22 @@ function test()
             InspectorTest.evaluateInPage("setAttribute('name', 'value')");
         },
 
+        function testAttributeSameValueNotUpdated(next)
+        {
+            function callback()
+            {
+                InspectorTest.addResult("===== On attribute modified (should be 'newValue') =====");
+                InspectorTest.dumpElementsTree(targetNode);
+                WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+                next();
+            }
+            WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+            // Setting the same property value should not result in the AttrModified event.
+            InspectorTest.evaluateInPage("setAttribute('name', 'value')");
+            InspectorTest.evaluateInPage("setAttribute('name', 'value')");
+            InspectorTest.evaluateInPage("setAttribute('name', 'newValue')");
+        },
+
         function testAttributeRemoved(next)
         {
             function callback()
index ebd946b..3c3aa53 100644 (file)
@@ -1,3 +1,25 @@
+2012-02-20  Alexander Pavlov  <apavlov@chromium.org>
+
+        Web Inspector: DOMAttrModified should not be fired if the attribute value remains the same
+        https://bugs.webkit.org/show_bug.cgi?id=79025
+
+        Reviewed by Pavel Feldman.
+
+        * dom/Element.cpp:
+        (WebCore::Element::willModifyAttribute):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::InspectorDOMAgent):
+        (WebCore::InspectorDOMAgent::willModifyDOMAttr):
+        (WebCore):
+        (WebCore::InspectorDOMAgent::didModifyDOMAttr):
+        * inspector/InspectorDOMAgent.h:
+        (InspectorDOMAgent):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willModifyDOMAttrImpl):
+        * inspector/InspectorInstrumentation.h:
+        (InspectorInstrumentation):
+        (WebCore::InspectorInstrumentation::willModifyDOMAttr):
+
 2012-02-20  Kwonjin Jeong  <gram@company100.net>
 
         Correct a typo error in ScrollingCoordinator.h
index 4fc4d86..23010a0 100644 (file)
@@ -2005,7 +2005,7 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
 
 #if ENABLE(INSPECTOR)
     if (!isSynchronizingStyleAttribute())
-        InspectorInstrumentation::willModifyDOMAttr(document(), this);
+        InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
 #endif
 }
 
index 6ea68a5..e9a10d0 100644 (file)
@@ -197,6 +197,7 @@ InspectorDOMAgent::InspectorDOMAgent(InstrumentingAgents* instrumentingAgents, I
     , m_domListener(0)
     , m_lastNodeId(1)
     , m_searchingForNode(false)
+    , m_suppressAttributeModifiedEvent(false)
 {
 }
 
@@ -1401,8 +1402,18 @@ void InspectorDOMAgent::didRemoveDOMNode(Node* node)
     unbind(node, &m_documentNodeToIdMap);
 }
 
+void InspectorDOMAgent::willModifyDOMAttr(Element* element, const AtomicString& oldValue, const AtomicString& newValue)
+{
+    m_suppressAttributeModifiedEvent = (oldValue == newValue);
+}
+
 void InspectorDOMAgent::didModifyDOMAttr(Element* element, const AtomicString& name, const AtomicString& value)
 {
+    bool shouldSuppressEvent = m_suppressAttributeModifiedEvent;
+    m_suppressAttributeModifiedEvent = false;
+    if (shouldSuppressEvent)
+        return;
+
     int id = boundNodeId(element);
     // If node is not mapped yet -> ignore the event.
     if (!id)
index 6b8337b..e45d463 100644 (file)
@@ -161,6 +161,7 @@ public:
 
     void didInsertDOMNode(Node*);
     void didRemoveDOMNode(Node*);
+    void willModifyDOMAttr(Element*, const AtomicString& oldValue, const AtomicString& newValue);
     void didModifyDOMAttr(Element*, const AtomicString& name, const AtomicString& value);
     void didRemoveDOMAttr(Element*, const AtomicString& name);
     void styleAttributeInvalidated(const Vector<Element*>& elements);
@@ -250,6 +251,7 @@ private:
     bool m_searchingForNode;
     OwnPtr<InspectorHistory> m_history;
     OwnPtr<DOMEditor> m_domEditor;
+    bool m_suppressAttributeModifiedEvent;
 };
 
 #endif // ENABLE(INSPECTOR)
index 95d6f30..ab94944 100644 (file)
@@ -154,11 +154,13 @@ void InspectorInstrumentation::didRemoveDOMNodeImpl(InstrumentingAgents* instrum
         domAgent->didRemoveDOMNode(node);
 }
 
-void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element)
+void InspectorInstrumentation::willModifyDOMAttrImpl(InstrumentingAgents* instrumentingAgents, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
 {
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     if (InspectorDOMDebuggerAgent* domDebuggerAgent = instrumentingAgents->inspectorDOMDebuggerAgent())
         domDebuggerAgent->willModifyDOMAttr(element);
+    if (InspectorDOMAgent* domAgent = instrumentingAgents->inspectorDOMAgent())
+        domAgent->willModifyDOMAttr(element, oldValue, newValue);
 #endif
 }
 
index da7dfe0..a14ca20 100644 (file)
@@ -85,7 +85,7 @@ public:
     static void willInsertDOMNode(Document*, Node*, Node* parent);
     static void didInsertDOMNode(Document*, Node*);
     static void willRemoveDOMNode(Document*, Node*);
-    static void willModifyDOMAttr(Document*, Element*);
+    static void willModifyDOMAttr(Document*, Element*, const AtomicString& oldValue, const AtomicString& newValue);
     static void didModifyDOMAttr(Document*, Element*, const AtomicString& name, const AtomicString& value);
     static void didRemoveDOMAttr(Document*, Element*, const AtomicString& name);
     static void characterDataModified(Document*, CharacterData*);
@@ -235,7 +235,7 @@ private:
     static void didInsertDOMNodeImpl(InstrumentingAgents*, Node*);
     static void willRemoveDOMNodeImpl(InstrumentingAgents*, Node*);
     static void didRemoveDOMNodeImpl(InstrumentingAgents*, Node*);
-    static void willModifyDOMAttrImpl(InstrumentingAgents*, Element*);
+    static void willModifyDOMAttrImpl(InstrumentingAgents*, Element*, const AtomicString& oldValue, const AtomicString& newValue);
     static void didModifyDOMAttrImpl(InstrumentingAgents*, Element*, const AtomicString& name, const AtomicString& value);
     static void didRemoveDOMAttrImpl(InstrumentingAgents*, Element*, const AtomicString& name);
     static void characterDataModifiedImpl(InstrumentingAgents*, CharacterData*);
@@ -424,12 +424,12 @@ inline void InspectorInstrumentation::willRemoveDOMNode(Document* document, Node
 #endif
 }
 
-inline void InspectorInstrumentation::willModifyDOMAttr(Document* document, Element* element)
+inline void InspectorInstrumentation::willModifyDOMAttr(Document* document, Element* element, const AtomicString& oldValue, const AtomicString& newValue)
 {
 #if ENABLE(INSPECTOR)
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
-        willModifyDOMAttrImpl(instrumentingAgents, element);
+        willModifyDOMAttrImpl(instrumentingAgents, element, oldValue, newValue);
 #endif
 }