Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Unified Diff: Source/devtools/front_end/DOMAgent.js

Issue 27204002: Implement copy css path in elements panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Removing duplicate code. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/DOMAgent.js
diff --git a/Source/devtools/front_end/DOMAgent.js b/Source/devtools/front_end/DOMAgent.js
index 45467bc785d2b124fa86413c1df121a4feaaf940..1061e1c13f5344a4908ba84e9d1227936fccd822 100644
--- a/Source/devtools/front_end/DOMAgent.js
+++ b/Source/devtools/front_end/DOMAgent.js
@@ -413,6 +413,30 @@ WebInspector.DOMNode.prototype = {
DOMAgent.getOuterHTML(this.id, copy);
},
+ _cssPathValue: function() {
apavlov 2013/10/15 07:55:11 AFAIU, in general a "CSS path" should be as short
apavlov 2013/10/15 07:55:11 Please add a JSDoc
ericduran 2013/11/05 14:00:59 Hmm, Same assumption but that wasn't what I was go
apavlov 2013/11/05 14:05:51 Hmm, I'm not sure why Firebug does this, but as I
+ if (!this._localName)
+ return "null";
apavlov 2013/10/15 07:55:11 Blink indents are 4 spaces wide
apavlov 2013/10/15 07:55:11 I believe this should be return null;
+
+ var label = this.nodeNameInCorrectCase();
+
+ var id = this.getAttribute("id");
+ if (id)
+ label += "#" + id;
+
+ var className = this.getAttribute("class");
+ if (className) {
apavlov 2013/10/15 07:55:11 This will break for <span class=" ">. You should
+ var selector = "." + className.trim().replace(/\s+/g, ".");
+ label = label + selector;
+ }
+
+ return label;
+ },
+
+ copyCSSPath: function()
+ {
+ InspectorFrontendHost.copyText(this.cssPath());
+ },
+
/**
* @param {boolean} optimized
*/
@@ -421,6 +445,20 @@ WebInspector.DOMNode.prototype = {
InspectorFrontendHost.copyText(this.xPath(optimized));
},
+ cssPath: function() {
+
apavlov 2013/10/15 07:55:11 You should check if the node is Node.ELEMENT_NODE
+ var selectors = [],
+ contextNode = this;
apavlov 2013/10/15 07:55:11 DevTools use a "var" per each declaration. But in
+ for (; contextNode && contextNode._nodeType == Node.ELEMENT_NODE; contextNode = contextNode.parentNode) {
+ var selector = contextNode._cssPathValue();
apavlov 2013/10/15 07:55:11 You should check if the selector is valid (i.e. !=
+ selectors.push(selector);
+ }
+
+ selectors.reverse();
+ return selectors.length ? selectors.join(" ") : "";
apavlov 2013/10/15 07:55:11 If you implement the early bailout above, you shou
+
+ },
+
/**
* @param {string} objectGroupId
* @param {function(?Protocol.Error)=} callback
« no previous file with comments | « no previous file | Source/devtools/front_end/ElementsTreeOutline.js » ('j') | Source/devtools/front_end/ElementsTreeOutline.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698