/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * StyleRuleFront, the front for the StyleRule actor.
*/ class StyleRuleFront extends FrontClassWithSpec(styleRuleSpec) {
constructor(client, targetFront, parentFront) { super(client, targetFront, parentFront);
/** * Ensure _form is updated when location-changed is emitted.
*/
_locationChangedPre(line, column) { this._form.line = line; this._form.column = column;
}
/** * Return a new RuleModificationList or RuleRewriter for this node. * A RuleRewriter will be returned when the rule's canSetRuleText * trait is true; otherwise a RuleModificationList will be * returned. * * @param {CssPropertiesFront} cssProperties * This is needed by the RuleRewriter. * @return {RuleModificationList}
*/
startModifyingProperties(cssProperties) { if (this.canSetRuleText) { returnnew RuleRewriter(cssProperties.isKnown, this, this.authoredText);
} returnnew RuleModificationList(this);
}
get type() { returnthis._form.type;
}
get line() { returnthis._form.line || -1;
}
get column() { returnthis._form.column || -1;
}
get cssText() { returnthis._form.cssText;
}
get isNestedDeclarations() { return !!this._form.isNestedDeclarations;
}
get authoredText() { returntypeofthis._form.authoredText === "string"
? this._form.authoredText
: this._form.cssText;
}
get declarations() { returnthis._form.declarations || [];
}
get keyText() { returnthis._form.keyText;
}
get name() { returnthis._form.name;
}
get selectors() { returnthis._form.selectors;
}
get selectorsSpecificity() { returnthis._form.selectorsSpecificity;
}
/** * Returns a concatenation of the rule's selector and all its ancestor "selectors". * This is different from a "desugared" selector as what's returned is not an * actual selector, but some kind of key that represent the rule selectors. * This is used for the selector highlighter, where we need to know what's * being highlighted. * * @returns {String}
*/
get computedSelector() {
let selector = ""; for (const ancestor of this.ancestorData) {
let ancestorSelector; if (ancestor.selectors) {
ancestorSelector = ancestor.selectors.join(",");
} elseif (ancestor.type === "container") {
ancestorSelector =
ancestor.containerName + " " + ancestor.containerQuery;
} elseif (ancestor.type === "supports") {
ancestorSelector = ancestor.conditionText;
} elseif (ancestor.value) {
ancestorSelector = ancestor.value;
}
selector += "/" + (ancestor.type ? ancestor.type + " " : "") + ancestorSelector;
}
/** * Convenience API for building a list of attribute modifications * for the `modifyProperties` request. A RuleModificationList holds a * list of modifications that will be applied to a StyleRuleActor. * The modifications are processed in the order in which they are * added to the RuleModificationList. * * Objects of this type expose the same API as @see RuleRewriter. * This lets the inspector use (mostly) the same code, regardless of * whether the server implements setRuleText.
*/ class RuleModificationList { /** * Initialize a RuleModificationList. * @param {StyleRuleFront} rule the associated rule
*/
constructor(rule) { this.rule = rule; this.modifications = [];
}
/** * Apply the modifications in this object to the associated rule. * * @return {Promise} A promise which will be resolved when the modifications * are complete; @see StyleRuleActor.modifyProperties.
*/
apply() { returnthis.rule.modifyProperties(this.modifications);
}
/** * Add a "set" entry to the modification list. * * @param {Number} index index of the property in the rule. * This can be -1 in the case where * the rule does not support setRuleText; * generally for setting properties * on an element's style. * @param {String} name the property's name * @param {String} value the property's value * @param {String} priority the property's priority, either the empty * string or "important"
*/
setProperty(index, name, value, priority) { this.modifications.push({ type: "set", index, name, value, priority });
}
/** * Add a "remove" entry to the modification list. * * @param {Number} index index of the property in the rule. * This can be -1 in the case where * the rule does not support setRuleText; * generally for setting properties * on an element's style. * @param {String} name the name of the property to remove
*/
removeProperty(index, name) { this.modifications.push({ type: "remove", index, name });
}
/** * Rename a property. This implementation acts like * |removeProperty|, because |setRuleText| is not available. * * @param {Number} index index of the property in the rule. * This can be -1 in the case where * the rule does not support setRuleText; * generally for setting properties * on an element's style. * @param {String} name current name of the property * * This parameter is also passed, but as it is not used in this * implementation, it is omitted. It is documented here as this * code also defined the interface implemented by @see RuleRewriter. * @param {String} newName new name of the property
*/
renameProperty(index, name) { this.removeProperty(index, name);
}
/** * Enable or disable a property. This implementation acts like * a no-op when enabling, because |setRuleText| is not available. * * @param {Number} index index of the property in the rule. * This can be -1 in the case where * the rule does not support setRuleText; * generally for setting properties * on an element's style. * @param {String} name current name of the property * @param {Boolean} isEnabled true if the property should be enabled; * false if it should be disabled
*/
setPropertyEnabled(index, name, isEnabled) { if (!isEnabled) { this.modifications.push({ type: "disable", index, name });
}
}
/** * Create a new property. This implementation does nothing, because * |setRuleText| is not available. * * These parameters are passed, but as they are not used in this * implementation, they are omitted. They are documented here as * this code also defined the interface implemented by @see * RuleRewriter. * * @param {Number} index index of the property in the rule. * This can be -1 in the case where * the rule does not support setRuleText; * generally for setting properties * on an element's style. * @param {String} name name of the new property * @param {String} value value of the new property * @param {String} priority priority of the new property; either * the empty string or "important" * @param {Boolean} enabled True if the new property should be * enabled, false if disabled
*/
createProperty() { // Nothing.
}
}
¤ Dauer der Verarbeitung: 0.28 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.