Bug 1261133 - Use pseudoClass for style editor transition. r=dbaron, r=pbro

MozReview-Commit-ID: Ck5JTXRR0mp

--HG--
extra : transplant_source : %95%0CQ%14%20%F0f%B84%E2%82%82%AB%F51%87%29%9EqL
This commit is contained in:
Rex Lee 2016-05-23 19:55:54 +08:00
parent 4062790276
commit d807a8a63e
4 changed files with 33 additions and 21 deletions

View File

@ -1610,10 +1610,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
}
}
sugs.classes.delete("");
// Editing the style editor may make the stylesheet have errors and
// thus the page's elements' styles start changing with a transition.
// That transition comes from the `moz-styleeditor-transitioning` class.
sugs.classes.delete("moz-styleeditor-transitioning");
sugs.classes.delete(HIDDEN_CLASS);
for (let [className, count] of sugs.classes) {
if (className.startsWith(completing)) {
@ -1685,10 +1681,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
id && result.push(["#" + id, count]);
}
sugs.classes.delete("");
// Editing the style editor may make the stylesheet have errors and
// thus the page's elements' styles start changing with a transition.
// That transition comes from the `moz-styleeditor-transitioning` class.
sugs.classes.delete("moz-styleeditor-transitioning");
sugs.classes.delete(HIDDEN_CLASS);
for (let [className, count] of sugs.classes) {
className && result.push(["." + className, count]);

View File

@ -17,6 +17,8 @@ const {listenOnce} = require("devtools/shared/async-utils");
const {originalSourceSpec, mediaRuleSpec, styleSheetSpec,
styleSheetsSpec} = require("devtools/shared/specs/stylesheets");
const {SourceMapConsumer} = require("source-map");
const { installHelperSheet,
addPseudoClassLock, removePseudoClassLock } = require("devtools/server/actors/highlighters/utils/markup");
loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic"));
@ -24,17 +26,17 @@ XPCOMUtils.defineLazyGetter(this, "DOMUtils", function () {
return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
});
var TRANSITION_CLASS = "moz-styleeditor-transitioning";
var TRANSITION_PSEUDO_CLASS = ":-moz-styleeditor-transitioning";
var TRANSITION_DURATION_MS = 500;
var TRANSITION_BUFFER_MS = 1000;
var TRANSITION_RULE_SELECTOR =
".moz-styleeditor-transitioning:root, .moz-styleeditor-transitioning:root *";
var TRANSITION_RULE = TRANSITION_RULE_SELECTOR + " {\
transition-duration: " + TRANSITION_DURATION_MS + "ms !important; \
transition-delay: 0ms !important;\
transition-timing-function: ease-out !important;\
transition-property: all !important;\
}";
`:root${TRANSITION_PSEUDO_CLASS}, :root${TRANSITION_PSEUDO_CLASS} *`;
var TRANSITION_RULE = `${TRANSITION_RULE_SELECTOR} {
transition-duration: ${TRANSITION_DURATION_MS}ms !important;
transition-delay: 0ms !important;
transition-timing-function: ease-out !important;
transition-property: all !important;
}`;
var LOAD_ERROR = "error-load";
@ -248,6 +250,22 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
return this._styleSheetIndex;
},
destroy: function () {
if (this._transitionTimeout) {
this.window.clearTimeout(this._transitionTimeout);
removePseudoClassLock(
this.document.documentElement, TRANSITION_PSEUDO_CLASS);
}
},
/**
* Since StyleSheetActor doesn't have a protocol.js parent actor that take
* care of its lifetime, implementing disconnect is required to cleanup.
*/
disconnect: function () {
this.destroy();
},
initialize: function (aStyleSheet, aParentActor, aWindow) {
protocol.Actor.prototype.initialize.call(this, null);
@ -260,8 +278,6 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
// text and index are unknown until source load
this.text = null;
this._styleSheetIndex = -1;
this._transitionRefCount = 0;
},
/**
@ -721,7 +737,7 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
* to remove the rule after a certain time.
*/
_insertTransistionRule: function (kind) {
this.document.documentElement.classList.add(TRANSITION_CLASS);
addPseudoClassLock(this.document.documentElement, TRANSITION_PSEUDO_CLASS);
// We always add the rule since we've just reset all the rules
this.rawSheet.insertRule(TRANSITION_RULE, this.rawSheet.cssRules.length);
@ -739,7 +755,8 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
*/
_onTransitionEnd: function (kind)
{
this.document.documentElement.classList.remove(TRANSITION_CLASS);
this._transitionTimeout = null;
removePseudoClassLock(this.document.documentElement, TRANSITION_PSEUDO_CLASS);
let index = this.rawSheet.cssRules.length - 1;
let rule = this.rawSheet.cssRules[index];

View File

@ -286,6 +286,8 @@ private:
#define NS_EVENT_STATE_DEVTOOLS_HIGHLIGHTED NS_DEFINE_EVENT_STATE_MACRO(45)
// Element is an unresolved custom element candidate
#define NS_EVENT_STATE_UNRESOLVED NS_DEFINE_EVENT_STATE_MACRO(46)
// Element is transitioning for rules changed by style editor
#define NS_EVENT_STATE_STYLEEDITOR_TRANSITIONING NS_DEFINE_EVENT_STATE_MACRO(47)
// Event state that is used for values that need to be parsed but do nothing.
#define NS_EVENT_STATE_IGNORE NS_DEFINE_EVENT_STATE_MACRO(63)
@ -304,4 +306,3 @@ private:
#define INTRINSIC_STATES (~ESM_MANAGED_STATES)
#endif // mozilla_EventStates_h_

View File

@ -161,6 +161,8 @@ CSS_STATE_PSEUDO_CLASS(indeterminate, ":indeterminate", 0, "",
CSS_STATE_PSEUDO_CLASS(mozDevtoolsHighlighted, ":-moz-devtools-highlighted", 0, "",
NS_EVENT_STATE_DEVTOOLS_HIGHLIGHTED)
CSS_STATE_PSEUDO_CLASS(mozStyleeditorTransitioning, ":-moz-styleeditor-transitioning", 0, "",
NS_EVENT_STATE_STYLEEDITOR_TRANSITIONING)
// Matches the element which is being displayed full-screen, and
// any containing frames.