Diff
Modified: trunk/LayoutTests/ChangeLog (89438 => 89439)
--- trunk/LayoutTests/ChangeLog 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/LayoutTests/ChangeLog 2011-06-22 16:24:52 UTC (rev 89439)
@@ -1,3 +1,13 @@
+2011-06-22 Pavel Feldman <pfeld...@google.com>
+
+ Reviewed by Yury Semikhatsky.
+
+ Web Inspector: split setAttributes and setAttributeValue.
+ https://bugs.webkit.org/show_bug.cgi?id=63138
+
+ * inspector/elements/set-attribute.html:
+ * inspector/elements/set-attribute-expected.txt:
+
2011-06-22 Eric Carlson <eric.carl...@apple.com>
Reviewed by Dan Bernstein.
Modified: trunk/LayoutTests/inspector/elements/set-attribute-expected.txt (89438 => 89439)
--- trunk/LayoutTests/inspector/elements/set-attribute-expected.txt 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/LayoutTests/inspector/elements/set-attribute-expected.txt 2011-06-22 16:24:52 UTC (rev 89439)
@@ -5,11 +5,23 @@
========= Original ========
<div id="node"></div>
-Running: testSetAttribute
-===== Set attribute =====
+Running: testAttributeUpdated
+===== On attribute set =====
<div id="node" name="value"></div>
-Running: testRemoveAttribute
-=== Removed attribute ===
+Running: testAttributeRemoved
+=== On attribute removed ===
<div id="node"></div>
+Running: testSetAttributeValue
+=== Set attribute value ===
+ <div id="node" foo="bar"></div>
+
+Running: testSetAttributeText
+=== Set attribute as text ===
+ <div id="node" foo2="baz2" foo3="baz3"></div>
+
+Running: testRemoveAttributeAsText
+=== Remove attribute as text ===
+ <div id="node" foo2="baz2"></div>
+
Modified: trunk/LayoutTests/inspector/elements/set-attribute.html (89438 => 89439)
--- trunk/LayoutTests/inspector/elements/set-attribute.html 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/LayoutTests/inspector/elements/set-attribute.html 2011-06-22 16:24:52 UTC (rev 89439)
@@ -33,27 +33,69 @@
InspectorTest.selectNodeWithId("node", callback);
},
- function testSetAttribute(next)
+ function testAttributeUpdated(next)
{
function callback()
{
- InspectorTest.addResult("===== Set attribute =====");
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ InspectorTest.addResult("===== On attribute set =====");
InspectorTest.dumpElementsTree(targetNode);
next();
}
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
InspectorTest.evaluateInPage("setAttribute('name', 'value')");
- InspectorTest.addSniffer(WebInspector.StylesSidebarPane.prototype, "_rebuildUpdate", callback);
},
- function testRemoveAttribute(next) {
+ function testAttributeRemoved(next)
+ {
function callback()
{
- InspectorTest.addResult("=== Removed attribute ===");
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ InspectorTest.addResult("=== On attribute removed ===");
InspectorTest.dumpElementsTree(targetNode);
next();
}
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
InspectorTest.evaluateInPage("removeAttribute('name')");
- InspectorTest.addSniffer(WebInspector.StylesSidebarPane.prototype, "_rebuildUpdate", callback);
+ },
+
+ function testSetAttributeValue(next)
+ {
+ function callback()
+ {
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ InspectorTest.addResult("=== Set attribute value ===");
+ InspectorTest.dumpElementsTree(targetNode);
+ next();
+ }
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ targetNode.setAttributeValue("foo", "bar");
+ },
+
+ function testSetAttributeText(next)
+ {
+ function callback()
+ {
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ InspectorTest.addResult("=== Set attribute as text ===");
+ InspectorTest.dumpElementsTree(targetNode);
+ next();
+ }
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ targetNode.setAttribute("foo", "foo2='baz2' foo3='baz3'");
+ },
+
+ function testRemoveAttributeAsText(next)
+ {
+ function callback()
+ {
+ WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ InspectorTest.addResult("=== Remove attribute as text ===");
+ InspectorTest.dumpElementsTree(targetNode);
+ next();
+ }
+ WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, callback);
+ targetNode.setAttribute("foo3", "");
}
]);
}
Modified: trunk/Source/WebCore/ChangeLog (89438 => 89439)
--- trunk/Source/WebCore/ChangeLog 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/Source/WebCore/ChangeLog 2011-06-22 16:24:52 UTC (rev 89439)
@@ -1,3 +1,19 @@
+2011-06-22 Pavel Feldman <pfeld...@google.com>
+
+ Reviewed by Yury Semikhatsky.
+
+ Web Inspector: split setAttributes and setAttributeValue.
+ https://bugs.webkit.org/show_bug.cgi?id=63138
+
+ * inspector/Inspector.json:
+ * inspector/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::setAttributeValue):
+ (WebCore::InspectorDOMAgent::setAttributesText):
+ * inspector/InspectorDOMAgent.h:
+ * inspector/front-end/DOMAgent.js:
+ (WebInspector.DOMNode.prototype.setAttribute):
+ (WebInspector.DOMNode.prototype.setAttributeValue):
+
2011-06-22 Dirk Schulze <k...@webkit.org>
Reviewed by Nikolas Zimmermann.
Modified: trunk/Source/WebCore/inspector/Inspector.json (89438 => 89439)
--- trunk/Source/WebCore/inspector/Inspector.json 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/Source/WebCore/inspector/Inspector.json 2011-06-22 16:24:52 UTC (rev 89439)
@@ -867,7 +867,7 @@
"description": "Removes node with given id."
},
{
- "name": "setAttribute",
+ "name": "setAttributeValue",
"parameters": [
{ "name": "nodeId", "type": "integer", "description": "Id of the element to set attribute for." },
{ "name": "name", "type": "string", "description": "Attribute name." },
@@ -876,6 +876,15 @@
"description": "Sets attribute for an element with given id."
},
{
+ "name": "setAttributesText",
+ "parameters": [
+ { "name": "nodeId", "type": "integer", "description": "Id of the element to set attributes for." },
+ { "name": "name", "type": "string", "optional": true, "description": "Attribute name to replace with new attributes derived from text in case text parsed successfully." },
+ { "name": "text", "type": "string", "description": "Text with a number of attributes. Will parse this text using HTML parser." }
+ ],
+ "description": "Sets attributes on element with given id. This method is useful when user edits some existing attribute value and types in several attribute name/value pairs."
+ },
+ {
"name": "removeAttribute",
"parameters": [
{ "name": "nodeId", "type": "integer", "description": "Id of the element to remove attribute from." },
Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (89438 => 89439)
--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2011-06-22 16:24:52 UTC (rev 89439)
@@ -572,28 +572,40 @@
return m_documentNodeToIdMap.get(node);
}
-void InspectorDOMAgent::setAttribute(ErrorString* errorString, int elementId, const String& name, const String& value)
+void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, int elementId, const String& name, const String& value)
{
Element* element = assertElement(errorString, elementId);
if (!element)
return;
ExceptionCode ec = 0;
+ element->setAttribute(name, value, ec);
+ if (ec)
+ *errorString = "Internal error: could not set attribute value.";
+}
+
+void InspectorDOMAgent::setAttributesText(ErrorString* errorString, int elementId, const String* const name, const String& text)
+{
+ Element* element = assertElement(errorString, elementId);
+ if (!element)
+ return;
+
+ ExceptionCode ec = 0;
RefPtr<Element> parsedElement = element->document()->createElement("span", ec);
if (ec) {
*errorString = "Internal error: could not set attribute value.";
return;
}
- toHTMLElement(parsedElement.get())->setInnerHTML("<span " + value + "></span>", ec);
+ toHTMLElement(parsedElement.get())->setInnerHTML("<span " + text + "></span>", ec);
if (ec) {
*errorString = "Could not parse value as attributes.";
return;
}
const NamedNodeMap* attrMap = toHTMLElement(parsedElement->firstChild())->attributes(true);
- if (!attrMap) {
- element->removeAttribute(name, ec);
+ if (!attrMap && name) {
+ element->removeAttribute(*name, ec);
if (ec)
*errorString = "Could not remove attribute.";
return;
@@ -604,7 +616,7 @@
for (unsigned i = 0; i < numAttrs; ++i) {
// Add attribute pair
const Attribute *attribute = attrMap->attributeItem(i);
- foundOriginalAttribute = foundOriginalAttribute || attribute->name().toString() == name;
+ foundOriginalAttribute = foundOriginalAttribute || (name && attribute->name().toString() == *name);
element->setAttribute(attribute->name(), attribute->value(), ec);
if (ec) {
*errorString = "Internal error: could not set attribute value.";
@@ -612,8 +624,8 @@
}
}
- if (!foundOriginalAttribute) {
- element->removeAttribute(name, ec);
+ if (!foundOriginalAttribute && name) {
+ element->removeAttribute(*name, ec);
if (ec)
*errorString = "Could not remove attribute.";
return;
Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.h (89438 => 89439)
--- trunk/Source/WebCore/inspector/InspectorDOMAgent.h 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.h 2011-06-22 16:24:52 UTC (rev 89439)
@@ -115,7 +115,8 @@
void querySelectorAll(ErrorString*, int nodeId, const String& selectors, RefPtr<InspectorArray>* result);
void getDocument(ErrorString*, RefPtr<InspectorObject>* root);
void getChildNodes(ErrorString*, int nodeId);
- void setAttribute(ErrorString*, int elementId, const String& name, const String& value);
+ void setAttributeValue(ErrorString*, int elementId, const String& name, const String& value);
+ void setAttributesText(ErrorString*, int elementId, const String* const name, const String& text);
void removeAttribute(ErrorString*, int elementId, const String& name);
void removeNode(ErrorString*, int nodeId);
void setNodeName(ErrorString*, int nodeId, const String& name, int* newId);
Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (89438 => 89439)
--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2011-06-22 16:21:33 UTC (rev 89438)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2011-06-22 16:24:52 UTC (rev 89439)
@@ -127,11 +127,16 @@
return attr ? attr.value : undefined;
},
- setAttribute: function(name, value, callback)
+ setAttribute: function(name, text, callback)
{
- DOMAgent.setAttribute(this.id, name, value, callback);
+ DOMAgent.setAttributesText(this.id, name, text, callback);
},
+ setAttributeValue: function(name, value, callback)
+ {
+ DOMAgent.setAttributeValue(this.id, name, value, callback);
+ },
+
attributes: function()
{
return this._attributes;