- Revision
- 112668
- Author
- [email protected]
- Date
- 2012-03-30 08:44:38 -0700 (Fri, 30 Mar 2012)
Log Message
Web Inspector: do not issue attributes modified event if actual values were not changed.
https://bugs.webkit.org/show_bug.cgi?id=82726
Reviewed by Yury Semikhatsky.
Source/WebCore:
When style attribute is invalidated, we re-fetch the attributes values. There is no
point in further dispatching attrs modified event if model stays the same.
Test: inspector/elements/edit-style-attribute.html
* inspector/front-end/DOMAgent.js:
(WebInspector.DOMNode.prototype._setAttributesPayload):
(WebInspector.DOMAgent.prototype._loadNodeAttributes):
LayoutTests:
* inspector/elements/edit-style-attribute-expected.txt: Added.
* inspector/elements/edit-style-attribute.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (112667 => 112668)
--- trunk/LayoutTests/ChangeLog 2012-03-30 15:37:16 UTC (rev 112667)
+++ trunk/LayoutTests/ChangeLog 2012-03-30 15:44:38 UTC (rev 112668)
@@ -1,3 +1,13 @@
+2012-03-30 Pavel Feldman <[email protected]>
+
+ Web Inspector: do not issue attributes modified event if actual values were not changed.
+ https://bugs.webkit.org/show_bug.cgi?id=82726
+
+ Reviewed by Yury Semikhatsky.
+
+ * inspector/elements/edit-style-attribute-expected.txt: Added.
+ * inspector/elements/edit-style-attribute.html: Added.
+
2012-03-30 Philip Rogers <[email protected]>
Add new renderer for circles and ellipses
Added: trunk/LayoutTests/inspector/elements/edit-style-attribute-expected.txt (0 => 112668)
--- trunk/LayoutTests/inspector/elements/edit-style-attribute-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/elements/edit-style-attribute-expected.txt 2012-03-30 15:44:38 UTC (rev 112668)
@@ -0,0 +1,11 @@
+Tests that style modification generates attribute updated event only when attribute is actually changed.
+
+
+Running: testSetUp
+
+Running: testSetNewValue
+WebInspector.DOMAgent.Events.StyleInvalidated should be issued
+
+Running: testSetSameValue
+WebInspector.DOMNode.prototype._setAttributesPayload should be called
+
Property changes on: trunk/LayoutTests/inspector/elements/edit-style-attribute-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/elements/edit-style-attribute.html (0 => 112668)
--- trunk/LayoutTests/inspector/elements/edit-style-attribute.html (rev 0)
+++ trunk/LayoutTests/inspector/elements/edit-style-attribute.html 2012-03-30 15:44:38 UTC (rev 112668)
@@ -0,0 +1,77 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function testSetNewValue()
+{
+ document.getElementById("node-set-new-value").style.setProperty("color", "blue");
+}
+
+function testSetSameValue()
+{
+ document.getElementById("node-set-same-value").style.setProperty("color", "red");
+}
+
+function test()
+{
+ // Save time on style updates.
+ WebInspector.StylesSidebarPane.prototype.update = function() {};
+ WebInspector.MetricsSidebarPane.prototype.update = function() {};
+
+ InspectorTest.runTestSuite([
+ function testSetUp(next)
+ {
+ InspectorTest.expandElementsTree(next);
+ },
+
+ function testSetNewValue(next)
+ {
+ InspectorTest.evaluateInPage("testSetNewValue()");
+
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.StyleInvalidated, listener);
+ function listener(event)
+ {
+ InspectorTest.addResult("WebInspector.DOMAgent.Events.StyleInvalidated should be issued");
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.StyleInvalidated, listener);
+ next();
+ }
+ },
+
+ function testSetSameValue(next)
+ {
+ InspectorTest.evaluateInPage("testSetSameValue()");
+
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.StyleInvalidated, listener);
+ function listener(event)
+ {
+ InspectorTest.addResult("WebInspector.DOMAgent.Events.StyleInvalidated should not be issued");
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.StyleInvalidated, listener);
+ }
+
+ InspectorTest.addSniffer(WebInspector.DOMNode.prototype, "_setAttributesPayload", callback);
+ function callback()
+ {
+ InspectorTest.addResult("WebInspector.DOMNode.prototype._setAttributesPayload should be called");
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.StyleInvalidated, listener);
+ next();
+ }
+ }
+ ]);
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that style modification generates attribute updated event only when attribute is actually changed.
+</p>
+
+<div id="container">
+ <div id="node-set-new-value" style="color:red"></div>
+ <div id="node-set-same-value" style="color:red"></div>
+</div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/elements/edit-style-attribute.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (112667 => 112668)
--- trunk/Source/WebCore/ChangeLog 2012-03-30 15:37:16 UTC (rev 112667)
+++ trunk/Source/WebCore/ChangeLog 2012-03-30 15:44:38 UTC (rev 112668)
@@ -1,3 +1,19 @@
+2012-03-30 Pavel Feldman <[email protected]>
+
+ Web Inspector: do not issue attributes modified event if actual values were not changed.
+ https://bugs.webkit.org/show_bug.cgi?id=82726
+
+ Reviewed by Yury Semikhatsky.
+
+ When style attribute is invalidated, we re-fetch the attributes values. There is no
+ point in further dispatching attrs modified event if model stays the same.
+
+ Test: inspector/elements/edit-style-attribute.html
+
+ * inspector/front-end/DOMAgent.js:
+ (WebInspector.DOMNode.prototype._setAttributesPayload):
+ (WebInspector.DOMAgent.prototype._loadNodeAttributes):
+
2012-03-30 Philip Rogers <[email protected]>
Add new renderer for circles and ellipses
Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (112667 => 112668)
--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-03-30 15:37:16 UTC (rev 112667)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-03-30 15:44:38 UTC (rev 112668)
@@ -404,13 +404,28 @@
/**
* @param {Array.<string>} attrs
+ * @return {boolean}
*/
_setAttributesPayload: function(attrs)
{
+ var attributesChanged = !this._attributes || attrs.length !== this._attributes.length * 2;
+ var oldAttributesMap = this._attributesMap || {};
+
this._attributes = [];
this._attributesMap = {};
- for (var i = 0; i < attrs.length; i += 2)
- this._addAttribute(attrs[i], attrs[i + 1]);
+
+ for (var i = 0; i < attrs.length; i += 2) {
+ var name = attrs[i];
+ var value = attrs[i + 1];
+ this._addAttribute(name, value);
+
+ if (attributesChanged)
+ continue;
+
+ if (!oldAttributesMap[name] || oldAttributesMap[name].value !== value)
+ attributesChanged = true;
+ }
+ return attributesChanged;
},
/**
@@ -768,8 +783,7 @@
return;
return function(error, result)
{
- if (error)
- console.error("Error during DOMAgent operation: " + error);
+ // Caller is responsible for handling the actual error.
callback(error ? null : result);
}
},
@@ -804,8 +818,12 @@
var node = this._idToDOMNode[nodeId];
if (!node)
return;
+ var issueStyleInvalidated = name === "style" && value !== node.getAttribute("style");
+
node._setAttribute(name, value);
this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrModified, { node: node, name: name });
+ if (issueStyleInvalidated)
+ this.dispatchEventToListeners(WebInspector.DOMAgent.Events.StyleInvalidated, node)
},
/**
@@ -844,14 +862,15 @@
function callback(nodeId, error, attributes)
{
if (error) {
- console.error("Error during DOMAgent operation: " + error);
+ // We are calling _loadNodeAttributes asynchronously, it is ok if node is not found.
return;
}
var node = this._idToDOMNode[nodeId];
if (node) {
- node._setAttributesPayload(attributes);
- this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrModified, { node: node, name: "style" });
- this.dispatchEventToListeners(WebInspector.DOMAgent.Events.StyleInvalidated, node);
+ if (node._setAttributesPayload(attributes)) {
+ this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrModified, { node: node, name: "style" });
+ this.dispatchEventToListeners(WebInspector.DOMAgent.Events.StyleInvalidated, node);
+ }
}
}