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

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

Issue 75253002: DevTools: [Elements] Implement "Copy CSS Path" context menu item for elements (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tentatively fix xpath test on Windows bot Created 7 years, 1 month 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 7db774ee6a7989212c67f35945a3f6f56668ca00..04ca87509f063a07182f77e803a733458b8d3203 100644
--- a/Source/devtools/front_end/DOMAgent.js
+++ b/Source/devtools/front_end/DOMAgent.js
@@ -120,24 +120,6 @@ WebInspector.DOMNode.ShadowRootTypes = {
Author: "author"
}
-/**
- * @constructor
- * @param {string} value
- * @param {boolean} optimized
- */
-WebInspector.DOMNode.XPathStep = function(value, optimized)
-{
- this.value = value;
- this.optimized = optimized;
-}
-
-WebInspector.DOMNode.XPathStep.prototype = {
- toString: function()
- {
- return this.value;
- }
-}
-
WebInspector.DOMNode.prototype = {
/**
* @return {Array.<WebInspector.DOMNode>}
@@ -428,14 +410,6 @@ WebInspector.DOMNode.prototype = {
},
/**
- * @param {boolean} optimized
- */
- copyXPath: function(optimized)
- {
- InspectorFrontendHost.copyText(this.xPath(optimized));
- },
-
- /**
* @param {string} objectGroupId
* @param {function(?Protocol.Error)=} callback
*/
@@ -655,121 +629,6 @@ WebInspector.DOMNode.prototype = {
return !!this.ownerDocument && !!this.ownerDocument.xmlVersion;
},
- /**
- * @param {boolean} optimized
- * @return {string}
- */
- xPath: function(optimized)
- {
- if (this._nodeType === Node.DOCUMENT_NODE)
- return "/";
-
- var steps = [];
- var contextNode = this;
- while (contextNode) {
- var step = contextNode._xPathValue(optimized);
- if (!step)
- break; // Error - bail out early.
- steps.push(step);
- if (step.optimized)
- break;
- contextNode = contextNode.parentNode;
- }
-
- steps.reverse();
- return (steps.length && steps[0].optimized ? "" : "/") + steps.join("/");
- },
-
- /**
- * @param {boolean} optimized
- * @return {WebInspector.DOMNode.XPathStep}
- */
- _xPathValue: function(optimized)
- {
- var ownValue;
- var ownIndex = this._xPathIndex();
- if (ownIndex === -1)
- return null; // Error.
-
- switch (this._nodeType) {
- case Node.ELEMENT_NODE:
- if (optimized && this.getAttribute("id"))
- return new WebInspector.DOMNode.XPathStep("//*[@id=\"" + this.getAttribute("id") + "\"]", true);
- ownValue = this._localName;
- break;
- case Node.ATTRIBUTE_NODE:
- ownValue = "@" + this._nodeName;
- break;
- case Node.TEXT_NODE:
- case Node.CDATA_SECTION_NODE:
- ownValue = "text()";
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- ownValue = "processing-instruction()";
- break;
- case Node.COMMENT_NODE:
- ownValue = "comment()";
- break;
- case Node.DOCUMENT_NODE:
- ownValue = "";
- break;
- default:
- ownValue = "";
- break;
- }
-
- if (ownIndex > 0)
- ownValue += "[" + ownIndex + "]";
-
- return new WebInspector.DOMNode.XPathStep(ownValue, this._nodeType === Node.DOCUMENT_NODE);
- },
-
- /**
- * @return {number}
- */
- _xPathIndex: function()
- {
- // Returns -1 in case of error, 0 if no siblings matching the same expression, <XPath index among the same expression-matching sibling nodes> otherwise.
- function areNodesSimilar(left, right)
- {
- if (left === right)
- return true;
-
- if (left._nodeType === Node.ELEMENT_NODE && right._nodeType === Node.ELEMENT_NODE)
- return left._localName === right._localName;
-
- if (left._nodeType === right._nodeType)
- return true;
-
- // XPath treats CDATA as text nodes.
- var leftType = left._nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : left._nodeType;
- var rightType = right._nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : right._nodeType;
- return leftType === rightType;
- }
-
- var siblings = this.parentNode ? this.parentNode._children : null;
- if (!siblings)
- return 0; // Root node - no siblings.
- var hasSameNamedElements;
- for (var i = 0; i < siblings.length; ++i) {
- if (areNodesSimilar(this, siblings[i]) && siblings[i] !== this) {
- hasSameNamedElements = true;
- break;
- }
- }
- if (!hasSameNamedElements)
- return 0;
- var ownIndex = 1; // XPath indices start with 1.
- for (var i = 0; i < siblings.length; ++i) {
- if (areNodesSimilar(this, siblings[i])) {
- if (siblings[i] === this)
- return ownIndex;
- ++ownIndex;
- }
- }
- return -1; // An error occurred: |this| not found in parent's children.
- },
-
_updateChildUserPropertyCountsOnRemoval: function(parentNode)
{
var result = {};
« no previous file with comments | « LayoutTests/inspector/elements/node-xpath-expected.txt ('k') | Source/devtools/front_end/DOMPresentationUtils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698