diff --git a/devtools/server/actors/resources/stylesheets.js b/devtools/server/actors/resources/stylesheets.js index 860a506a0a34..c42049dcc6aa 100644 --- a/devtools/server/actors/resources/stylesheets.js +++ b/devtools/server/actors/resources/stylesheets.js @@ -21,10 +21,46 @@ loader.lazyRequireGetter( "devtools/shared/inspector/css-logic" ); +loader.lazyRequireGetter( + this, + ["addPseudoClassLock", "removePseudoClassLock"], + "devtools/server/actors/highlighters/utils/markup", + true +); +loader.lazyRequireGetter( + this, + "loadSheet", + "devtools/shared/layout/utils", + true +); + +const TRANSITION_PSEUDO_CLASS = ":-moz-styleeditor-transitioning"; +const TRANSITION_DURATION_MS = 500; +const TRANSITION_BUFFER_MS = 1000; +const TRANSITION_RULE_SELECTOR = `:root${TRANSITION_PSEUDO_CLASS}, :root${TRANSITION_PSEUDO_CLASS} *`; +const TRANSITION_SHEET = + "data:text/css;charset=utf-8," + + encodeURIComponent(` + ${TRANSITION_RULE_SELECTOR} { + transition-duration: ${TRANSITION_DURATION_MS}ms !important; + transition-delay: 0ms !important; + transition-timing-function: ease-out !important; + transition-property: all !important; + } +`); + class StyleSheetWatcher { constructor() { this._resourceCount = 0; + // The _styleSheetMap maps resouceId and following value. + // { + // styleSheet: Raw StyleSheet object. + // modifiedText: Content of the stylesheet updated by update function. + // In case not updating, this value is undefined. + // } this._styleSheetMap = new Map(); + // List of all watched media queries. Change listeners are being registered from _getMediaRules. + this._mqlList = []; } /** @@ -62,7 +98,13 @@ class StyleSheetWatcher { * Protocol method to get the text of stylesheet of resourceId. */ async getText(resourceId) { - const styleSheet = this._styleSheetMap.get(resourceId); + const { styleSheet, modifiedText } = this._styleSheetMap.get(resourceId); + + // modifiedText is the content of the stylesheet updated by update function. + // In case not updating, this is undefined. + if (modifiedText !== undefined) { + return modifiedText; + } if (!styleSheet.href) { // this is an inline