Bug 1399314 - Move getBindingElementAndPseudo into shared/inspector/css-logic.js. r?ochameau
MozReview-Commit-ID: 4Ka61REglh
--- a/devtools/server/css-logic.js
+++ b/devtools/server/css-logic.js
@@ -27,17 +27,24 @@
* reference to the selected element.
*/
"use strict";
const { Cc, Ci, Cu } = require("chrome");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const nodeConstants = require("devtools/shared/dom-node-constants");
-const {l10n, isContentStylesheet, shortSource, FILTER, STATUS} = require("devtools/shared/inspector/css-logic");
+const {
+ getBindingElementAndPseudo,
+ l10n,
+ isContentStylesheet,
+ shortSource,
+ FILTER,
+ STATUS
+} = require("devtools/shared/inspector/css-logic");
/**
* @param {function} isInherited A function that determines if the CSS property
* is inherited.
*/
function CssLogic(isInherited) {
// The cache of examined CSS properties.
this._isInherited = isInherited;
@@ -649,31 +656,17 @@ CssLogic.getSelectors = function (domRul
* If so, return the node that is accessible from within the document
* (the parent of the anonymous node), along with which pseudo element
* it was. Otherwise, return the node itself.
*
* @returns {Object}
* - {DOMNode} node The non-anonymous node
* - {string} pseudo One of ':before', ':after', or null.
*/
-CssLogic.getBindingElementAndPseudo = function (node) {
- let bindingElement = node;
- let pseudo = null;
- if (node.nodeName == "_moz_generated_content_before") {
- bindingElement = node.parentNode;
- pseudo = ":before";
- } else if (node.nodeName == "_moz_generated_content_after") {
- bindingElement = node.parentNode;
- pseudo = ":after";
- }
- return {
- bindingElement: bindingElement,
- pseudo: pseudo
- };
-};
+CssLogic.getBindingElementAndPseudo = getBindingElementAndPseudo;
/**
* Get the computed style on a node. Automatically handles reading
* computed styles on a ::before/::after element by reading on the
* parent node with the proper pseudo argument.
*
* @param {Node}
* @returns {CSSStyleDeclaration}
--- a/devtools/shared/inspector/css-logic.js
+++ b/devtools/shared/inspector/css-logic.js
@@ -466,8 +466,35 @@ function getXPath(ele) {
parts.push(prefix + ele.localName + nth);
ele = ele.parentNode;
}
return parts.length ? "/" + parts.reverse().join("/") : "";
}
exports.getXPath = getXPath;
+
+/**
+ * Given a node, check to see if it is a ::before or ::after element.
+ * If so, return the node that is accessible from within the document
+ * (the parent of the anonymous node), along with which pseudo element
+ * it was. Otherwise, return the node itself.
+ *
+ * @returns {Object}
+ * - {DOMNode} node The non-anonymous node
+ * - {string} pseudo One of ':before', ':after', or null.
+ */
+function getBindingElementAndPseudo(node) {
+ let bindingElement = node;
+ let pseudo = null;
+ if (node.nodeName == "_moz_generated_content_before") {
+ bindingElement = node.parentNode;
+ pseudo = ":before";
+ } else if (node.nodeName == "_moz_generated_content_after") {
+ bindingElement = node.parentNode;
+ pseudo = ":after";
+ }
+ return {
+ bindingElement: bindingElement,
+ pseudo: pseudo
+ };
+}
+exports.getBindingElementAndPseudo = getBindingElementAndPseudo;