Bug 1399314 - Move getBindingElementAndPseudo into shared/inspector/css-logic.js. r?ochameau draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 13 Oct 2017 07:19:54 +0900
changeset 679618 ce8e5a062a057cd664157705a45c41a7839f2498
parent 679617 cb5f4236d080bb250f7f485a584216f014a18fba
child 679619 9e81e0a0e731aae802e27d7fb975bf066e8961d2
push id84276
push userhikezoe@mozilla.com
push dateThu, 12 Oct 2017 22:20:47 +0000
reviewersochameau
bugs1399314
milestone58.0a1
Bug 1399314 - Move getBindingElementAndPseudo into shared/inspector/css-logic.js. r?ochameau MozReview-Commit-ID: 4Ka61REglh
devtools/server/css-logic.js
devtools/shared/inspector/css-logic.js
--- 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;