From 9b8c1dff66adbdab08a44a755ebea6a47f3bd5cc Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 13 Oct 2017 07:19:54 +0900 Subject: [PATCH] Bug 1399314 - Move getBindingElementAndPseudo into shared/inspector/css-logic.js. r=ochameau MozReview-Commit-ID: 4Ka61REglh --HG-- extra : rebase_source : a48319dd7614ae79cdda1ba1b06d1558cc371fe4 --- devtools/server/css-logic.js | 25 +++++++++--------------- devtools/shared/inspector/css-logic.js | 27 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/devtools/server/css-logic.js b/devtools/server/css-logic.js index ca6521f14a81..6b3d3ee12fc7 100644 --- a/devtools/server/css-logic.js +++ b/devtools/server/css-logic.js @@ -32,7 +32,14 @@ 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 @@ -654,21 +661,7 @@ CssLogic.getSelectors = function (domRule) { * - {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 diff --git a/devtools/shared/inspector/css-logic.js b/devtools/shared/inspector/css-logic.js index 59771b879a87..1c42d7c68f06 100644 --- a/devtools/shared/inspector/css-logic.js +++ b/devtools/shared/inspector/css-logic.js @@ -471,3 +471,30 @@ function getXPath(ele) { 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;