2011-11-01 18:06:48 -07:00
|
|
|
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2012-02-10 05:39:47 -08:00
|
|
|
"use strict";
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
const {Cc, Ci, Cu} = require("chrome");
|
2013-08-08 08:44:57 -07:00
|
|
|
const promise = require("sdk/core/promise");
|
2013-11-15 18:46:59 -08:00
|
|
|
const {CssLogic} = require("devtools/styleinspector/css-logic");
|
|
|
|
const {InplaceEditor, editableField, editableItem} = require("devtools/shared/inplace-editor");
|
|
|
|
const {ELEMENT_STYLE, PSEUDO_ELEMENTS} = require("devtools/server/actors/styles");
|
|
|
|
const {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
|
|
|
const {Tooltip, SwatchColorPickerTooltip} = require("devtools/shared/widgets/Tooltip");
|
2013-10-18 07:01:20 -07:00
|
|
|
const {OutputParser} = require("devtools/output-parser");
|
2014-02-03 07:52:09 -08:00
|
|
|
const {PrefObserver, PREF_ORIG_SOURCES} = require("devtools/styleeditor/utils");
|
|
|
|
const {parseSingleValue, parseDeclarations} = require("devtools/styleinspector/css-parsing-utils");
|
2013-10-18 07:01:20 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These regular expressions are adapted from firebug's css.js, and are
|
|
|
|
* used to parse CSSStyleDeclaration's cssText attribute.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Used to split on css line separators
|
|
|
|
const CSS_LINE_RE = /(?:[^;\(]*(?:\([^\)]*?\))?[^;\(]*)*;?/g;
|
|
|
|
|
|
|
|
// Used to parse a single property line.
|
|
|
|
const CSS_PROP_RE = /\s*([^:\s]*)\s*:\s*(.*?)\s*(?:! (important))?;?$/;
|
|
|
|
|
2013-04-19 14:30:33 -07:00
|
|
|
// Used to parse an external resource from a property value
|
|
|
|
const CSS_RESOURCE_RE = /url\([\'\"]?(.*?)[\'\"]?\)/;
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
const IOService = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
function promiseWarn(err) {
|
|
|
|
console.error(err);
|
|
|
|
return promise.reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To figure out how shorthand properties are interpreted by the
|
|
|
|
* engine, we will set properties on a dummy element and observe
|
|
|
|
* how their .style attribute reflects them as computed values.
|
|
|
|
* This function creates the document in which those dummy elements
|
|
|
|
* will be created.
|
|
|
|
*/
|
|
|
|
var gDummyPromise;
|
|
|
|
function createDummyDocument() {
|
|
|
|
if (gDummyPromise) {
|
|
|
|
return gDummyPromise;
|
|
|
|
}
|
|
|
|
const { getDocShell, create: makeFrame } = require("sdk/frame/utils");
|
|
|
|
|
|
|
|
let frame = makeFrame(Services.appShell.hiddenDOMWindow.document, {
|
|
|
|
nodeName: "iframe",
|
|
|
|
namespaceURI: "http://www.w3.org/1999/xhtml",
|
|
|
|
allowJavascript: false,
|
|
|
|
allowPlugins: false,
|
|
|
|
allowAuth: false
|
|
|
|
});
|
|
|
|
let docShell = getDocShell(frame);
|
|
|
|
let eventTarget = docShell.chromeEventHandler;
|
|
|
|
docShell.createAboutBlankContentViewer(Cc["@mozilla.org/nullprincipal;1"].createInstance(Ci.nsIPrincipal));
|
|
|
|
let window = docShell.contentViewer.DOMDocument.defaultView;
|
|
|
|
window.location = "data:text/html,<html></html>";
|
2013-08-30 01:06:59 -07:00
|
|
|
let deferred = promise.defer();
|
2013-08-08 08:44:57 -07:00
|
|
|
eventTarget.addEventListener("DOMContentLoaded", function handler(event) {
|
|
|
|
eventTarget.removeEventListener("DOMContentLoaded", handler, false);
|
|
|
|
deferred.resolve(window.document);
|
2013-10-31 15:49:37 -07:00
|
|
|
frame.remove();
|
2013-08-08 08:44:57 -07:00
|
|
|
}, false);
|
|
|
|
gDummyPromise = deferred.promise;
|
|
|
|
return gDummyPromise;
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Our model looks like this:
|
|
|
|
*
|
|
|
|
* ElementStyle:
|
|
|
|
* Responsible for keeping track of which properties are overridden.
|
|
|
|
* Maintains a list of Rule objects that apply to the element.
|
|
|
|
* Rule:
|
|
|
|
* Manages a single style declaration or rule.
|
|
|
|
* Responsible for applying changes to the properties in a rule.
|
|
|
|
* Maintains a list of TextProperty objects.
|
|
|
|
* TextProperty:
|
|
|
|
* Manages a single property from the cssText attribute of the
|
|
|
|
* relevant declaration.
|
|
|
|
* Maintains a list of computed properties that come from this
|
|
|
|
* property declaration.
|
|
|
|
* Changes to the TextProperty are sent to its related Rule for
|
|
|
|
* application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ElementStyle maintains a list of Rule objects for a given element.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {Element} aElement
|
2011-11-07 10:35:40 -08:00
|
|
|
* The element whose style we are viewing.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {object} aStore
|
2011-11-07 10:35:40 -08:00
|
|
|
* The ElementStyle can use this object to store metadata
|
|
|
|
* that might outlast the rule view, particularly the current
|
|
|
|
* set of disabled properties.
|
2013-08-08 08:44:57 -07:00
|
|
|
* @param {PageStyleFront} aPageStyle
|
|
|
|
* Front for the page style actor that will be providing
|
|
|
|
* the style information.
|
2011-11-07 10:35:40 -08:00
|
|
|
*
|
2011-11-01 18:06:48 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function ElementStyle(aElement, aStore, aPageStyle) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element = aElement;
|
2011-11-07 10:35:40 -08:00
|
|
|
this.store = aStore || {};
|
2013-08-08 08:44:57 -07:00
|
|
|
this.pageStyle = aPageStyle;
|
2012-02-23 04:24:23 -08:00
|
|
|
|
|
|
|
// We don't want to overwrite this.store.userProperties so we only create it
|
|
|
|
// if it doesn't already exist.
|
|
|
|
if (!("userProperties" in this.store)) {
|
|
|
|
this.store.userProperties = new UserProperties();
|
|
|
|
}
|
|
|
|
|
2013-04-03 23:40:00 -07:00
|
|
|
if (!("disabled" in this.store)) {
|
|
|
|
this.store.disabled = new WeakMap();
|
2011-11-07 10:35:40 -08:00
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// To figure out how shorthand properties are interpreted by the
|
|
|
|
// engine, we will set properties on a dummy element and observe
|
|
|
|
// how their .style attribute reflects them as computed values.
|
2013-08-08 08:44:57 -07:00
|
|
|
this.dummyElementPromise = createDummyDocument().then(document => {
|
|
|
|
this.dummyElement = document.createElementNS(this.element.namespaceURI,
|
|
|
|
this.element.tagName);
|
|
|
|
document.documentElement.appendChild(this.dummyElement);
|
|
|
|
return this.dummyElement;
|
|
|
|
}).then(null, promiseWarn);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2014-02-05 02:53:46 -08:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// We're exporting _ElementStyle for unit tests.
|
2013-04-11 13:59:08 -07:00
|
|
|
exports._ElementStyle = ElementStyle;
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
ElementStyle.prototype = {
|
|
|
|
// The element we're looking at.
|
|
|
|
element: null,
|
|
|
|
|
|
|
|
// Empty, unconnected element of the same type as this node, used
|
|
|
|
// to figure out how shorthand properties will be parsed.
|
|
|
|
dummyElement: null,
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
destroy: function() {
|
2013-08-08 08:44:57 -07:00
|
|
|
this.dummyElement = null;
|
|
|
|
this.dummyElementPromise.then(dummyElement => {
|
|
|
|
if (dummyElement.parentNode) {
|
|
|
|
dummyElement.parentNode.removeChild(dummyElement);
|
|
|
|
}
|
|
|
|
this.dummyElementPromise = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-06 19:02:08 -08:00
|
|
|
/**
|
|
|
|
* Called by the Rule object when it has been changed through the
|
|
|
|
* setProperty* methods.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_changed: function() {
|
2011-11-06 19:02:08 -08:00
|
|
|
if (this.onChanged) {
|
|
|
|
this.onChanged();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Refresh the list of rules to be displayed for the active element.
|
|
|
|
* Upon completion, this.rules[] will hold a list of Rule objects.
|
2013-08-08 08:44:57 -07:00
|
|
|
*
|
|
|
|
* Returns a promise that will be resolved when the elementStyle is
|
|
|
|
* ready.
|
2011-11-01 18:06:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
populate: function() {
|
2013-08-08 08:44:57 -07:00
|
|
|
let populated = this.pageStyle.getApplied(this.element, {
|
|
|
|
inherited: true,
|
|
|
|
matchedSelectors: true
|
|
|
|
}).then(entries => {
|
|
|
|
// Make sure the dummy element has been created before continuing...
|
|
|
|
return this.dummyElementPromise.then(() => {
|
|
|
|
if (this.populated != populated) {
|
|
|
|
// Don't care anymore.
|
|
|
|
return promise.reject("unused");
|
|
|
|
}
|
2011-11-05 08:45:22 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// Store the current list of rules (if any) during the population
|
|
|
|
// process. They will be reused if possible.
|
|
|
|
this._refreshRules = this.rules;
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.rules = [];
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
for (let entry of entries) {
|
|
|
|
this._maybeAddRule(entry);
|
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// Mark overridden computed styles.
|
2013-09-04 08:43:40 -07:00
|
|
|
this.markOverriddenAll();
|
|
|
|
|
|
|
|
this._sortRulesForPseudoElement();
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// We're done with the previous list of rules.
|
|
|
|
delete this._refreshRules;
|
2011-11-05 08:45:22 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
return null;
|
2011-11-05 08:45:22 -07:00
|
|
|
});
|
2013-08-08 08:44:57 -07:00
|
|
|
}).then(null, promiseWarn);
|
|
|
|
this.populated = populated;
|
|
|
|
return this.populated;
|
2011-11-05 08:45:22 -07:00
|
|
|
},
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-09-04 08:43:40 -07:00
|
|
|
/**
|
|
|
|
* Put pseudo elements in front of others.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_sortRulesForPseudoElement: function() {
|
2013-09-04 08:43:40 -07:00
|
|
|
this.rules = this.rules.sort((a, b) => {
|
|
|
|
return (a.pseudoElement || "z") > (b.pseudoElement || "z");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-05 08:45:22 -07:00
|
|
|
/**
|
|
|
|
* Add a rule if it's one we care about. Filters out duplicates and
|
|
|
|
* inherited styles with no inherited properties.
|
|
|
|
*
|
|
|
|
* @param {object} aOptions
|
|
|
|
* Options for creating the Rule, see the Rule constructor.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @return {bool} true if we added the rule.
|
2011-11-05 08:45:22 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_maybeAddRule: function(aOptions) {
|
2011-11-05 08:45:22 -07:00
|
|
|
// If we've already included this domRule (for example, when a
|
|
|
|
// common selector is inherited), ignore it.
|
2013-08-08 08:44:57 -07:00
|
|
|
if (aOptions.rule &&
|
|
|
|
this.rules.some(function(rule) rule.domRule === aOptions.rule)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOptions.system) {
|
2011-11-05 08:45:22 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
let rule = null;
|
|
|
|
|
|
|
|
// If we're refreshing and the rule previously existed, reuse the
|
|
|
|
// Rule object.
|
2013-08-08 08:44:57 -07:00
|
|
|
if (this._refreshRules) {
|
|
|
|
for (let r of this._refreshRules) {
|
|
|
|
if (r.matches(aOptions)) {
|
|
|
|
rule = r;
|
|
|
|
rule.refresh(aOptions);
|
|
|
|
break;
|
|
|
|
}
|
2012-05-30 19:49:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a new rule, create its Rule object.
|
|
|
|
if (!rule) {
|
|
|
|
rule = new Rule(this, aOptions);
|
|
|
|
}
|
2011-11-05 08:45:22 -07:00
|
|
|
|
|
|
|
// Ignore inherited rules with no properties.
|
|
|
|
if (aOptions.inherited && rule.textProps.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rules.push(rule);
|
2013-08-08 08:44:57 -07:00
|
|
|
return true;
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-09-04 08:43:40 -07:00
|
|
|
* Calls markOverridden with all supported pseudo elements
|
2011-11-01 18:06:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
markOverriddenAll: function() {
|
2013-09-04 08:43:40 -07:00
|
|
|
this.markOverridden();
|
|
|
|
for (let pseudo of PSEUDO_ELEMENTS) {
|
|
|
|
this.markOverridden(pseudo);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the properties listed in this.rules for a given pseudo element
|
|
|
|
* with an overridden flag if an earlier property overrides it.
|
|
|
|
* @param {string} pseudo
|
|
|
|
* Which pseudo element to flag as overridden.
|
|
|
|
* Empty string or undefined will default to no pseudo element.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
markOverridden: function(pseudo="") {
|
2011-11-01 18:06:48 -07:00
|
|
|
// Gather all the text properties applied by these rules, ordered
|
|
|
|
// from more- to less-specific.
|
|
|
|
let textProps = [];
|
2013-09-04 08:43:40 -07:00
|
|
|
for (let rule of this.rules) {
|
|
|
|
if (rule.pseudoElement == pseudo) {
|
|
|
|
textProps = textProps.concat(rule.textProps.slice(0).reverse());
|
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gather all the computed properties applied by those text
|
|
|
|
// properties.
|
|
|
|
let computedProps = [];
|
2013-09-04 08:43:40 -07:00
|
|
|
for (let textProp of textProps) {
|
2011-11-01 18:06:48 -07:00
|
|
|
computedProps = computedProps.concat(textProp.computed);
|
2011-11-05 08:45:22 -07:00
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
// Walk over the computed properties. As we see a property name
|
|
|
|
// for the first time, mark that property's name as taken by this
|
|
|
|
// property.
|
|
|
|
//
|
|
|
|
// If we come across a property whose name is already taken, check
|
|
|
|
// its priority against the property that was found first:
|
|
|
|
//
|
|
|
|
// If the new property is a higher priority, mark the old
|
|
|
|
// property overridden and mark the property name as taken by
|
|
|
|
// the new property.
|
|
|
|
//
|
|
|
|
// If the new property is a lower or equal priority, mark it as
|
|
|
|
// overridden.
|
|
|
|
//
|
|
|
|
// _overriddenDirty will be set on each prop, indicating whether its
|
|
|
|
// dirty status changed during this pass.
|
|
|
|
let taken = {};
|
2013-09-04 08:43:40 -07:00
|
|
|
for (let computedProp of computedProps) {
|
2011-11-01 18:06:48 -07:00
|
|
|
let earlier = taken[computedProp.name];
|
|
|
|
let overridden;
|
2013-08-30 01:06:59 -07:00
|
|
|
if (earlier &&
|
|
|
|
computedProp.priority === "important" &&
|
|
|
|
earlier.priority !== "important") {
|
2011-11-01 18:06:48 -07:00
|
|
|
// New property is higher priority. Mark the earlier property
|
|
|
|
// overridden (which will reverse its dirty state).
|
|
|
|
earlier._overriddenDirty = !earlier._overriddenDirty;
|
|
|
|
earlier.overridden = true;
|
|
|
|
overridden = false;
|
|
|
|
} else {
|
|
|
|
overridden = !!earlier;
|
|
|
|
}
|
|
|
|
|
|
|
|
computedProp._overriddenDirty = (!!computedProp.overridden != overridden);
|
|
|
|
computedProp.overridden = overridden;
|
2011-11-04 09:42:26 -07:00
|
|
|
if (!computedProp.overridden && computedProp.textProp.enabled) {
|
2011-11-01 18:06:48 -07:00
|
|
|
taken[computedProp.name] = computedProp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each TextProperty, mark it overridden if all of its
|
|
|
|
// computed properties are marked overridden. Update the text
|
|
|
|
// property's associated editor, if any. This will clear the
|
|
|
|
// _overriddenDirty state on all computed properties.
|
2013-09-04 08:43:40 -07:00
|
|
|
for (let textProp of textProps) {
|
2011-11-01 18:06:48 -07:00
|
|
|
// _updatePropertyOverridden will return true if the
|
|
|
|
// overridden state has changed for the text property.
|
|
|
|
if (this._updatePropertyOverridden(textProp)) {
|
|
|
|
textProp.updateEditor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a given TextProperty as overridden or not depending on the
|
|
|
|
* state of its computed properties. Clears the _overriddenDirty state
|
|
|
|
* on all computed properties.
|
|
|
|
*
|
|
|
|
* @param {TextProperty} aProp
|
|
|
|
* The text property to update.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @return {bool} true if the TextProperty's overridden state (or any of its
|
2011-11-01 18:06:48 -07:00
|
|
|
* computed properties overridden state) changed.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_updatePropertyOverridden: function(aProp) {
|
2011-11-01 18:06:48 -07:00
|
|
|
let overridden = true;
|
|
|
|
let dirty = false;
|
|
|
|
for each (let computedProp in aProp.computed) {
|
|
|
|
if (!computedProp.overridden) {
|
|
|
|
overridden = false;
|
|
|
|
}
|
|
|
|
dirty = computedProp._overriddenDirty || dirty;
|
|
|
|
delete computedProp._overriddenDirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirty = (!!aProp.overridden != overridden) || dirty;
|
|
|
|
aProp.overridden = overridden;
|
|
|
|
return dirty;
|
|
|
|
}
|
2012-02-10 05:39:47 -08:00
|
|
|
};
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A single style rule or declaration.
|
|
|
|
*
|
|
|
|
* @param {ElementStyle} aElementStyle
|
|
|
|
* The ElementStyle to which this rule belongs.
|
|
|
|
* @param {object} aOptions
|
|
|
|
* The information used to construct this rule. Properties include:
|
2013-08-08 08:44:57 -07:00
|
|
|
* rule: A StyleRuleActor
|
2011-11-05 08:45:22 -07:00
|
|
|
* inherited: An element this rule was inherited from. If omitted,
|
|
|
|
* the rule applies directly to the current element.
|
2011-11-01 18:06:48 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function Rule(aElementStyle, aOptions) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.elementStyle = aElementStyle;
|
2013-08-08 08:44:57 -07:00
|
|
|
this.domRule = aOptions.rule || null;
|
|
|
|
this.style = aOptions.rule;
|
|
|
|
this.matchedSelectors = aOptions.matchedSelectors || [];
|
2013-09-04 08:43:40 -07:00
|
|
|
this.pseudoElement = aOptions.pseudoElement || "";
|
2013-08-08 08:44:57 -07:00
|
|
|
|
2011-11-05 08:45:22 -07:00
|
|
|
this.inherited = aOptions.inherited || null;
|
2013-08-08 08:44:57 -07:00
|
|
|
this._modificationDepth = 0;
|
2012-03-01 11:13:12 -08:00
|
|
|
|
|
|
|
if (this.domRule) {
|
|
|
|
let parentRule = this.domRule.parentRule;
|
|
|
|
if (parentRule && parentRule.type == Ci.nsIDOMCSSRule.MEDIA_RULE) {
|
2013-08-08 08:44:57 -07:00
|
|
|
this.mediaText = parentRule.mediaText;
|
2012-03-01 11:13:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
// Populate the text properties with the style's current cssText
|
|
|
|
// value, and add in any disabled properties from the store.
|
|
|
|
this.textProps = this._getTextProperties();
|
|
|
|
this.textProps = this.textProps.concat(this._getDisabledProperties());
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Rule.prototype = {
|
2012-03-01 11:13:12 -08:00
|
|
|
mediaText: "",
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
get title() {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (this._title) {
|
|
|
|
return this._title;
|
|
|
|
}
|
2012-02-10 05:39:47 -08:00
|
|
|
this._title = CssLogic.shortSource(this.sheet);
|
2013-08-08 08:44:57 -07:00
|
|
|
if (this.domRule.type !== ELEMENT_STYLE) {
|
2012-02-10 05:39:47 -08:00
|
|
|
this._title += ":" + this.ruleLine;
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2011-11-05 08:45:22 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this._title = this._title + (this.mediaText ? " @media " + this.mediaText : "");
|
|
|
|
return this._title;
|
2012-03-14 03:04:11 -07:00
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
get inheritedSource() {
|
2012-03-14 03:04:11 -07:00
|
|
|
if (this._inheritedSource) {
|
|
|
|
return this._inheritedSource;
|
|
|
|
}
|
|
|
|
this._inheritedSource = "";
|
2011-11-05 08:45:22 -07:00
|
|
|
if (this.inherited) {
|
|
|
|
let eltText = this.inherited.tagName.toLowerCase();
|
|
|
|
if (this.inherited.id) {
|
|
|
|
eltText += "#" + this.inherited.id;
|
|
|
|
}
|
2012-03-14 03:04:11 -07:00
|
|
|
this._inheritedSource =
|
2012-07-20 08:04:55 -07:00
|
|
|
CssLogic._strings.formatStringFromName("rule.inheritedFrom", [eltText], 1);
|
2011-11-05 08:45:22 -07:00
|
|
|
}
|
2012-03-14 03:04:11 -07:00
|
|
|
return this._inheritedSource;
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
get selectorText() {
|
2013-08-08 08:44:57 -07:00
|
|
|
return this.domRule.selectors ? this.domRule.selectors.join(", ") : CssLogic.l10n("rule.sourceElement");
|
|
|
|
},
|
|
|
|
|
2012-02-10 05:39:47 -08:00
|
|
|
/**
|
|
|
|
* The rule's stylesheet.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
get sheet() {
|
2012-02-10 05:39:47 -08:00
|
|
|
return this.domRule ? this.domRule.parentStyleSheet : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The rule's line within a stylesheet
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
get ruleLine() {
|
2013-08-08 08:44:57 -07:00
|
|
|
return this.domRule ? this.domRule.line : null;
|
2012-02-10 05:39:47 -08:00
|
|
|
},
|
|
|
|
|
2013-12-06 23:52:32 -08:00
|
|
|
/**
|
|
|
|
* The rule's column within a stylesheet
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
get ruleColumn() {
|
2013-12-06 23:52:32 -08:00
|
|
|
return this.domRule ? this.domRule.column : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get display name for this rule based on the original source
|
|
|
|
* for this rule's style sheet.
|
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
* Promise which resolves with location as a string.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
getOriginalSourceString: function() {
|
2013-12-06 23:52:32 -08:00
|
|
|
if (this._originalSourceString) {
|
|
|
|
return promise.resolve(this._originalSourceString);
|
|
|
|
}
|
|
|
|
return this.domRule.getOriginalLocation().then(({href, line}) => {
|
|
|
|
let string = CssLogic.shortSource({href: href}) + ":" + line;
|
|
|
|
this._originalSourceString = string;
|
|
|
|
return string;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the rule matches the creation options
|
|
|
|
* specified.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {object} aOptions
|
|
|
|
* Creation options. See the Rule constructor for documentation.
|
2012-05-30 19:49:10 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
matches: function(aOptions) {
|
2013-08-08 08:44:57 -07:00
|
|
|
return this.style === aOptions.rule;
|
2012-05-30 19:49:10 -07:00
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Create a new TextProperty to include in the rule.
|
|
|
|
*
|
|
|
|
* @param {string} aName
|
|
|
|
* The text property name (such as "background" or "border-top").
|
|
|
|
* @param {string} aValue
|
|
|
|
* The property's value (not including priority).
|
|
|
|
* @param {string} aPriority
|
|
|
|
* The property's priority (either "important" or an empty string).
|
2014-01-16 18:40:54 -08:00
|
|
|
* @param {TextProperty} aSiblingProp
|
|
|
|
* Optional, property next to which the new property will be added.
|
2011-11-01 18:06:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
createProperty: function(aName, aValue, aPriority, aSiblingProp) {
|
2011-11-01 18:06:48 -07:00
|
|
|
let prop = new TextProperty(this, aName, aValue, aPriority);
|
2014-01-16 18:40:54 -08:00
|
|
|
|
|
|
|
if (aSiblingProp) {
|
|
|
|
let ind = this.textProps.indexOf(aSiblingProp);
|
|
|
|
this.textProps.splice(ind + 1, 0, prop);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.textProps.push(prop);
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
this.applyProperties();
|
|
|
|
return prop;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reapply all the properties in this rule, and update their
|
2011-11-07 10:35:40 -08:00
|
|
|
* computed styles. Store disabled properties in the element
|
|
|
|
* style's store. Will re-mark overridden properties.
|
2012-04-17 02:35:12 -07:00
|
|
|
*
|
|
|
|
* @param {string} [aName]
|
|
|
|
* A text property name (such as "background" or "border-top") used
|
2012-05-30 19:49:10 -07:00
|
|
|
* when calling from setPropertyValue & setPropertyName to signify
|
|
|
|
* that the property should be saved in store.userProperties.
|
2011-11-01 18:06:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
applyProperties: function(aModifications, aName) {
|
2013-09-12 09:18:29 -07:00
|
|
|
this.elementStyle.markOverriddenAll();
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
if (!aModifications) {
|
|
|
|
aModifications = this.style.startModifyingProperties();
|
|
|
|
}
|
2011-11-07 10:35:40 -08:00
|
|
|
let disabledProps = [];
|
2012-02-23 04:24:23 -08:00
|
|
|
let store = this.elementStyle.store;
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
for (let prop of this.textProps) {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (!prop.enabled) {
|
2011-11-07 10:35:40 -08:00
|
|
|
disabledProps.push({
|
|
|
|
name: prop.name,
|
|
|
|
value: prop.value,
|
|
|
|
priority: prop.priority
|
|
|
|
});
|
2011-11-01 18:06:48 -07:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
if (prop.value.trim() === "") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
aModifications.setProperty(prop.name, prop.value, prop.priority);
|
2012-05-30 19:49:10 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
prop.updateComputed();
|
|
|
|
}
|
|
|
|
|
2011-11-07 10:35:40 -08:00
|
|
|
// Store disabled properties in the disabled store.
|
|
|
|
let disabled = this.elementStyle.store.disabled;
|
2012-07-26 12:59:00 -07:00
|
|
|
if (disabledProps.length > 0) {
|
|
|
|
disabled.set(this.style, disabledProps);
|
|
|
|
} else {
|
|
|
|
disabled.delete(this.style);
|
|
|
|
}
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
let promise = aModifications.apply().then(() => {
|
|
|
|
let cssProps = {};
|
2014-02-03 07:52:09 -08:00
|
|
|
for (let cssProp of parseDeclarations(this.style.cssText)) {
|
2013-08-08 08:44:57 -07:00
|
|
|
cssProps[cssProp.name] = cssProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let textProp of this.textProps) {
|
|
|
|
if (!textProp.enabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let cssProp = cssProps[textProp.name];
|
|
|
|
|
|
|
|
if (!cssProp) {
|
|
|
|
cssProp = {
|
|
|
|
name: textProp.name,
|
|
|
|
value: "",
|
|
|
|
priority: ""
|
2013-08-30 01:06:59 -07:00
|
|
|
};
|
2013-08-08 08:44:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aName && textProp.name == aName) {
|
|
|
|
store.userProperties.setProperty(
|
2013-08-30 01:06:59 -07:00
|
|
|
this.style,
|
|
|
|
textProp.name,
|
2013-11-12 04:58:57 -08:00
|
|
|
textProp.value);
|
2013-08-08 08:44:57 -07:00
|
|
|
}
|
|
|
|
textProp.priority = cssProp.priority;
|
|
|
|
}
|
|
|
|
|
2013-09-04 08:43:40 -07:00
|
|
|
this.elementStyle.markOverriddenAll();
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
if (promise === this._applyingModifications) {
|
|
|
|
this._applyingModifications = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.elementStyle._changed();
|
|
|
|
}).then(null, promiseWarn);
|
2013-11-11 07:17:41 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this._applyingModifications = promise;
|
|
|
|
return promise;
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renames a property.
|
|
|
|
*
|
|
|
|
* @param {TextProperty} aProperty
|
|
|
|
* The property to rename.
|
|
|
|
* @param {string} aName
|
|
|
|
* The new property name (such as "background" or "border-top").
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
setPropertyName: function(aProperty, aName) {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (aName === aProperty.name) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
let modifications = this.style.startModifyingProperties();
|
|
|
|
modifications.removeProperty(aProperty.name);
|
2011-11-01 18:06:48 -07:00
|
|
|
aProperty.name = aName;
|
2013-08-08 08:44:57 -07:00
|
|
|
this.applyProperties(modifications, aName);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value and priority of a property.
|
|
|
|
*
|
|
|
|
* @param {TextProperty} aProperty
|
|
|
|
* The property to manipulate.
|
|
|
|
* @param {string} aValue
|
|
|
|
* The property's value (not including priority).
|
|
|
|
* @param {string} aPriority
|
|
|
|
* The property's priority (either "important" or an empty string).
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
setPropertyValue: function(aProperty, aValue, aPriority) {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (aValue === aProperty.value && aPriority === aProperty.priority) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
aProperty.value = aValue;
|
|
|
|
aProperty.priority = aPriority;
|
2013-08-08 08:44:57 -07:00
|
|
|
this.applyProperties(null, aProperty.name);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables or enables given TextProperty.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
setPropertyEnabled: function(aProperty, aValue) {
|
2011-11-01 18:06:48 -07:00
|
|
|
aProperty.enabled = !!aValue;
|
2013-08-08 08:44:57 -07:00
|
|
|
let modifications = this.style.startModifyingProperties();
|
2011-11-01 18:06:48 -07:00
|
|
|
if (!aProperty.enabled) {
|
2013-08-08 08:44:57 -07:00
|
|
|
modifications.removeProperty(aProperty.name);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
this.applyProperties(modifications);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a given TextProperty from the rule and update the rule
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
removeProperty: function(aProperty) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.textProps = this.textProps.filter(function(prop) prop != aProperty);
|
2013-08-08 08:44:57 -07:00
|
|
|
let modifications = this.style.startModifyingProperties();
|
|
|
|
modifications.removeProperty(aProperty.name);
|
2011-11-01 18:06:48 -07:00
|
|
|
// Need to re-apply properties in case removing this TextProperty
|
|
|
|
// exposes another one.
|
2013-08-08 08:44:57 -07:00
|
|
|
this.applyProperties(modifications);
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Get the list of TextProperties from the style. Needs
|
|
|
|
* to parse the style's cssText.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_getTextProperties: function() {
|
2012-05-30 19:49:10 -07:00
|
|
|
let textProps = [];
|
2012-02-23 04:24:23 -08:00
|
|
|
let store = this.elementStyle.store;
|
2014-02-03 07:52:09 -08:00
|
|
|
let props = parseDeclarations(this.style.cssText);
|
2013-08-08 08:44:57 -07:00
|
|
|
for (let prop of props) {
|
|
|
|
let name = prop.name;
|
2013-02-04 08:29:30 -08:00
|
|
|
if (this.inherited && !domUtils.isInheritedProperty(name)) {
|
2011-11-05 08:45:22 -07:00
|
|
|
continue;
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
let value = store.userProperties.getProperty(this.style, name, prop.value);
|
|
|
|
let textProp = new TextProperty(this, name, value, prop.priority);
|
|
|
|
textProps.push(textProp);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
return textProps;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the list of disabled properties from the store for this rule.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_getDisabledProperties: function() {
|
2012-05-30 19:49:10 -07:00
|
|
|
let store = this.elementStyle.store;
|
|
|
|
|
2011-11-07 10:35:40 -08:00
|
|
|
// Include properties from the disabled property store, if any.
|
2012-05-30 19:49:10 -07:00
|
|
|
let disabledProps = store.disabled.get(this.style);
|
2011-11-07 10:35:40 -08:00
|
|
|
if (!disabledProps) {
|
2012-05-30 19:49:10 -07:00
|
|
|
return [];
|
2011-11-07 10:35:40 -08:00
|
|
|
}
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
let textProps = [];
|
|
|
|
|
2011-11-07 10:35:40 -08:00
|
|
|
for each (let prop in disabledProps) {
|
2012-02-23 04:24:23 -08:00
|
|
|
let value = store.userProperties.getProperty(this.style, prop.name, prop.value);
|
|
|
|
let textProp = new TextProperty(this, prop.name, value, prop.priority);
|
2011-11-07 10:35:40 -08:00
|
|
|
textProp.enabled = false;
|
2012-05-30 19:49:10 -07:00
|
|
|
textProps.push(textProp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return textProps;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reread the current state of the rules and rebuild text
|
|
|
|
* properties as needed.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
refresh: function(aOptions) {
|
2013-08-08 08:44:57 -07:00
|
|
|
this.matchedSelectors = aOptions.matchedSelectors || [];
|
2012-05-30 19:49:10 -07:00
|
|
|
let newTextProps = this._getTextProperties();
|
|
|
|
|
|
|
|
// Update current properties for each property present on the style.
|
|
|
|
// This will mark any touched properties with _visited so we
|
|
|
|
// can detect properties that weren't touched (because they were
|
|
|
|
// removed from the style).
|
|
|
|
// Also keep track of properties that didn't exist in the current set
|
|
|
|
// of properties.
|
|
|
|
let brandNewProps = [];
|
|
|
|
for (let newProp of newTextProps) {
|
|
|
|
if (!this._updateTextProperty(newProp)) {
|
|
|
|
brandNewProps.push(newProp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh editors and disabled state for all the properties that
|
|
|
|
// were updated.
|
|
|
|
for (let prop of this.textProps) {
|
|
|
|
// Properties that weren't touched during the update
|
|
|
|
// process must no longer exist on the node. Mark them disabled.
|
|
|
|
if (!prop._visited) {
|
|
|
|
prop.enabled = false;
|
|
|
|
prop.updateEditor();
|
|
|
|
} else {
|
|
|
|
delete prop._visited;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add brand new properties.
|
|
|
|
this.textProps = this.textProps.concat(brandNewProps);
|
|
|
|
|
|
|
|
// Refresh the editor if one already exists.
|
|
|
|
if (this.editor) {
|
|
|
|
this.editor.populate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the current TextProperties that match a given property
|
|
|
|
* from the cssText. Will choose one existing TextProperty to update
|
|
|
|
* with the new property's value, and will disable all others.
|
|
|
|
*
|
|
|
|
* When choosing the best match to reuse, properties will be chosen
|
|
|
|
* by assigning a rank and choosing the highest-ranked property:
|
|
|
|
* Name, value, and priority match, enabled. (6)
|
|
|
|
* Name, value, and priority match, disabled. (5)
|
|
|
|
* Name and value match, enabled. (4)
|
|
|
|
* Name and value match, disabled. (3)
|
|
|
|
* Name matches, enabled. (2)
|
|
|
|
* Name matches, disabled. (1)
|
|
|
|
*
|
|
|
|
* If no existing properties match the property, nothing happens.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {TextProperty} aNewProp
|
2012-05-30 19:49:10 -07:00
|
|
|
* The current version of the property, as parsed from the
|
|
|
|
* cssText in Rule._getTextProperties().
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @return {bool} true if a property was updated, false if no properties
|
|
|
|
* were updated.
|
2012-05-30 19:49:10 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_updateTextProperty: function(aNewProp) {
|
2012-05-30 19:49:10 -07:00
|
|
|
let match = { rank: 0, prop: null };
|
|
|
|
|
|
|
|
for each (let prop in this.textProps) {
|
|
|
|
if (prop.name != aNewProp.name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Mark this property visited.
|
|
|
|
prop._visited = true;
|
|
|
|
|
|
|
|
// Start at rank 1 for matching name.
|
|
|
|
let rank = 1;
|
|
|
|
|
|
|
|
// Value and Priority matches add 2 to the rank.
|
|
|
|
// Being enabled adds 1. This ranks better matches higher,
|
|
|
|
// with priority breaking ties.
|
|
|
|
if (prop.value === aNewProp.value) {
|
|
|
|
rank += 2;
|
|
|
|
if (prop.priority === aNewProp.priority) {
|
|
|
|
rank += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop.enabled) {
|
|
|
|
rank += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rank > match.rank) {
|
|
|
|
if (match.prop) {
|
|
|
|
// We outrank a previous match, disable it.
|
|
|
|
match.prop.enabled = false;
|
|
|
|
match.prop.updateEditor();
|
|
|
|
}
|
|
|
|
match.rank = rank;
|
|
|
|
match.prop = prop;
|
|
|
|
} else if (rank) {
|
|
|
|
// A previous match outranks us, disable ourself.
|
|
|
|
prop.enabled = false;
|
|
|
|
prop.updateEditor();
|
|
|
|
}
|
2011-11-07 10:35:40 -08:00
|
|
|
}
|
2012-05-30 19:49:10 -07:00
|
|
|
|
|
|
|
// If we found a match, update its value with the new text property
|
|
|
|
// value.
|
|
|
|
if (match.prop) {
|
|
|
|
match.prop.set(aNewProp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
2013-09-12 09:18:29 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Jump between editable properties in the UI. Will begin editing the next
|
|
|
|
* name, if possible. If this is the last element in the set, then begin
|
|
|
|
* editing the previous value. If this is the *only* element in the set,
|
|
|
|
* then settle for focusing the new property editor.
|
|
|
|
*
|
|
|
|
* @param {TextProperty} aTextProperty
|
|
|
|
* The text property that will be left to focus on a sibling.
|
|
|
|
*
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
editClosestTextProperty: function(aTextProperty) {
|
2013-09-12 09:18:29 -07:00
|
|
|
let index = this.textProps.indexOf(aTextProperty);
|
|
|
|
let previous = false;
|
|
|
|
|
|
|
|
// If this is the last element, move to the previous instead of next
|
|
|
|
if (index === this.textProps.length - 1) {
|
|
|
|
index = index - 1;
|
|
|
|
previous = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index = index + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
let nextProp = this.textProps[index];
|
|
|
|
|
|
|
|
// If possible, begin editing the next name or previous value.
|
|
|
|
// Otherwise, settle for focusing the new property element.
|
|
|
|
if (nextProp) {
|
|
|
|
if (previous) {
|
|
|
|
nextProp.editor.valueSpan.click();
|
|
|
|
} else {
|
|
|
|
nextProp.editor.nameSpan.click();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aTextProperty.rule.editor.closeBrace.focus();
|
|
|
|
}
|
|
|
|
}
|
2012-02-10 05:39:47 -08:00
|
|
|
};
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A single property in a rule's cssText.
|
|
|
|
*
|
|
|
|
* @param {Rule} aRule
|
|
|
|
* The rule this TextProperty came from.
|
|
|
|
* @param {string} aName
|
|
|
|
* The text property name (such as "background" or "border-top").
|
|
|
|
* @param {string} aValue
|
|
|
|
* The property's value (not including priority).
|
|
|
|
* @param {string} aPriority
|
|
|
|
* The property's priority (either "important" or an empty string).
|
|
|
|
*
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function TextProperty(aRule, aName, aValue, aPriority) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule = aRule;
|
|
|
|
this.name = aName;
|
2013-10-18 07:01:20 -07:00
|
|
|
this.value = aValue;
|
2011-11-01 18:06:48 -07:00
|
|
|
this.priority = aPriority;
|
|
|
|
this.enabled = true;
|
|
|
|
this.updateComputed();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextProperty.prototype = {
|
|
|
|
/**
|
|
|
|
* Update the editor associated with this text property,
|
|
|
|
* if any.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
updateEditor: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (this.editor) {
|
|
|
|
this.editor.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the list of computed properties for this text property.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
updateComputed: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (!this.name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a bit funky. To get the list of computed properties
|
|
|
|
// for this text property, we'll set the property on a dummy element
|
|
|
|
// and see what the computed style looks like.
|
|
|
|
let dummyElement = this.rule.elementStyle.dummyElement;
|
|
|
|
let dummyStyle = dummyElement.style;
|
|
|
|
dummyStyle.cssText = "";
|
|
|
|
dummyStyle.setProperty(this.name, this.value, this.priority);
|
|
|
|
|
|
|
|
this.computed = [];
|
|
|
|
for (let i = 0, n = dummyStyle.length; i < n; i++) {
|
|
|
|
let prop = dummyStyle.item(i);
|
|
|
|
this.computed.push({
|
2011-11-04 09:42:26 -07:00
|
|
|
textProp: this,
|
2011-11-01 18:06:48 -07:00
|
|
|
name: prop,
|
|
|
|
value: dummyStyle.getPropertyValue(prop),
|
|
|
|
priority: dummyStyle.getPropertyPriority(prop),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
/**
|
|
|
|
* Set all the values from another TextProperty instance into
|
|
|
|
* this TextProperty instance.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {TextProperty} aOther
|
2012-05-30 19:49:10 -07:00
|
|
|
* The other TextProperty instance.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
set: function(aOther) {
|
2012-05-30 19:49:10 -07:00
|
|
|
let changed = false;
|
|
|
|
for (let item of ["name", "value", "priority", "enabled"]) {
|
|
|
|
if (this[item] != aOther[item]) {
|
|
|
|
this[item] = aOther[item];
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
this.updateEditor();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
setValue: function(aValue, aPriority) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule.setPropertyValue(this, aValue, aPriority);
|
|
|
|
this.updateEditor();
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
setName: function(aName) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule.setPropertyName(this, aName);
|
|
|
|
this.updateEditor();
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
setEnabled: function(aValue) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule.setPropertyEnabled(this, aValue);
|
|
|
|
this.updateEditor();
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
remove: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule.removeProperty(this);
|
2014-02-05 02:53:46 -08:00
|
|
|
}
|
2012-02-10 05:39:47 -08:00
|
|
|
};
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View hierarchy mostly follows the model hierarchy.
|
|
|
|
*
|
|
|
|
* CssRuleView:
|
|
|
|
* Owns an ElementStyle and creates a list of RuleEditors for its
|
|
|
|
* Rules.
|
|
|
|
* RuleEditor:
|
|
|
|
* Owns a Rule object and creates a list of TextPropertyEditors
|
|
|
|
* for its TextProperties.
|
|
|
|
* Manages creation of new text properties.
|
|
|
|
* TextPropertyEditor:
|
|
|
|
* Owns a TextProperty object.
|
|
|
|
* Manages changes to the TextProperty.
|
|
|
|
* Can be expanded to display computed properties.
|
|
|
|
* Can mark a property disabled or enabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CssRuleView is a view of the style rules and declarations that
|
|
|
|
* apply to a given element. After construction, the 'element'
|
|
|
|
* property will be available with the user interface.
|
|
|
|
*
|
2013-10-25 12:21:01 -07:00
|
|
|
* @param {Inspector} aInspector
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {Document} aDoc
|
2011-11-01 18:06:48 -07:00
|
|
|
* The document that will contain the rule view.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {object} aStore
|
2011-11-07 10:35:40 -08:00
|
|
|
* The CSS rule view can use this object to store metadata
|
|
|
|
* that might outlast the rule view, particularly the current
|
|
|
|
* set of disabled properties.
|
2013-08-08 08:44:57 -07:00
|
|
|
* @param {PageStyleFront} aPageStyle
|
|
|
|
* The PageStyleFront for communicating with the remote server.
|
2011-11-01 18:06:48 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function CssRuleView(aInspector, aDoc, aStore, aPageStyle) {
|
2013-10-25 12:21:01 -07:00
|
|
|
this.inspector = aInspector;
|
2011-11-01 18:06:48 -07:00
|
|
|
this.doc = aDoc;
|
2013-08-30 01:06:59 -07:00
|
|
|
this.store = aStore || {};
|
2013-08-08 08:44:57 -07:00
|
|
|
this.pageStyle = aPageStyle;
|
2013-03-27 15:20:38 -07:00
|
|
|
this.element = this.doc.createElementNS(HTML_NS, "div");
|
2013-02-04 02:48:24 -08:00
|
|
|
this.element.className = "ruleview devtools-monospace";
|
2011-11-14 07:21:34 -08:00
|
|
|
this.element.flex = 1;
|
2012-04-04 09:36:35 -07:00
|
|
|
|
2013-10-18 07:01:20 -07:00
|
|
|
this._outputParser = new OutputParser();
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
this._buildContextMenu = this._buildContextMenu.bind(this);
|
|
|
|
this._contextMenuUpdate = this._contextMenuUpdate.bind(this);
|
|
|
|
this._onSelectAll = this._onSelectAll.bind(this);
|
|
|
|
this._onCopy = this._onCopy.bind(this);
|
2014-01-14 07:13:47 -08:00
|
|
|
this._onToggleOrigSources = this._onToggleOrigSources.bind(this);
|
2013-09-19 17:15:34 -07:00
|
|
|
|
|
|
|
this.element.addEventListener("copy", this._onCopy);
|
2012-04-04 09:36:35 -07:00
|
|
|
|
2013-09-16 03:01:25 -07:00
|
|
|
this._handlePrefChange = this._handlePrefChange.bind(this);
|
|
|
|
gDevTools.on("pref-changed", this._handlePrefChange);
|
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
this._onSourcePrefChanged = this._onSourcePrefChanged.bind(this);
|
|
|
|
this._prefObserver = new PrefObserver("devtools.");
|
|
|
|
this._prefObserver.on(PREF_ORIG_SOURCES, this._onSourcePrefChanged);
|
|
|
|
|
2013-07-25 16:05:05 -07:00
|
|
|
let options = {
|
|
|
|
autoSelect: true,
|
|
|
|
theme: "auto"
|
|
|
|
};
|
|
|
|
this.popup = new AutocompletePopup(aDoc.defaultView.parent.document, options);
|
|
|
|
|
2013-11-15 18:46:59 -08:00
|
|
|
// Create a tooltip for previewing things in the rule view (images for now)
|
|
|
|
this.previewTooltip = new Tooltip(this.inspector.panelDoc);
|
|
|
|
this.previewTooltip.startTogglingOnHover(this.element,
|
2014-02-05 02:53:46 -08:00
|
|
|
this._onTooltipTargetHover.bind(this));
|
2013-11-15 18:46:59 -08:00
|
|
|
|
|
|
|
// Also create a more complex tooltip for editing colors with the spectrum
|
|
|
|
// color picker
|
|
|
|
this.colorPicker = new SwatchColorPickerTooltip(this.inspector.panelDoc);
|
2013-10-25 12:21:01 -07:00
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
this._buildContextMenu();
|
2012-04-19 11:13:44 -07:00
|
|
|
this._showEmpty();
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
exports.CssRuleView = CssRuleView;
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
CssRuleView.prototype = {
|
|
|
|
// The element that we're inspecting.
|
|
|
|
_viewedElement: null,
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
/**
|
|
|
|
* Build the context menu.
|
|
|
|
*/
|
|
|
|
_buildContextMenu: function() {
|
|
|
|
let doc = this.doc.defaultView.parent.document;
|
|
|
|
|
|
|
|
this._contextmenu = doc.createElementNS(XUL_NS, "menupopup");
|
|
|
|
this._contextmenu.addEventListener("popupshowing", this._contextMenuUpdate);
|
|
|
|
this._contextmenu.id = "rule-view-context-menu";
|
|
|
|
|
|
|
|
this.menuitemSelectAll = createMenuItem(this._contextmenu, {
|
|
|
|
label: "ruleView.contextmenu.selectAll",
|
|
|
|
accesskey: "ruleView.contextmenu.selectAll.accessKey",
|
|
|
|
command: this._onSelectAll
|
|
|
|
});
|
|
|
|
this.menuitemCopy = createMenuItem(this._contextmenu, {
|
|
|
|
label: "ruleView.contextmenu.copy",
|
|
|
|
accesskey: "ruleView.contextmenu.copy.accessKey",
|
|
|
|
command: this._onCopy
|
|
|
|
});
|
2014-01-14 07:13:47 -08:00
|
|
|
this.menuitemSources= createMenuItem(this._contextmenu, {
|
|
|
|
label: "ruleView.contextmenu.showOrigSources",
|
|
|
|
accesskey: "ruleView.contextmenu.showOrigSources.accessKey",
|
|
|
|
command: this._onToggleOrigSources
|
|
|
|
});
|
2013-09-19 17:15:34 -07:00
|
|
|
|
|
|
|
let popupset = doc.documentElement.querySelector("popupset");
|
|
|
|
if (!popupset) {
|
|
|
|
popupset = doc.createElementNS(XUL_NS, "popupset");
|
|
|
|
doc.documentElement.appendChild(popupset);
|
|
|
|
}
|
|
|
|
|
|
|
|
popupset.appendChild(this._contextmenu);
|
|
|
|
},
|
|
|
|
|
2013-10-25 12:21:01 -07:00
|
|
|
/**
|
2014-02-05 02:53:46 -08:00
|
|
|
* Executed by the tooltip when the pointer hovers over an element of the view.
|
|
|
|
* Used to decide whether the tooltip should be shown or not and to actually
|
|
|
|
* put content in it.
|
|
|
|
* Checks if the hovered target is a css value we support tooltips for.
|
2013-10-25 12:21:01 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onTooltipTargetHover: function(target) {
|
2013-12-11 11:50:15 -08:00
|
|
|
let property = target.textProperty, def = promise.defer(), hasTooltip = false;
|
2013-11-15 18:46:59 -08:00
|
|
|
|
2013-12-11 11:50:15 -08:00
|
|
|
// Test for css transform
|
|
|
|
if (property && property.name === "transform") {
|
|
|
|
this.previewTooltip.setCssTransformContent(property.value, this.pageStyle,
|
2014-03-19 02:11:34 -07:00
|
|
|
this._viewedElement).then(def.resolve, def.reject);
|
2013-12-11 11:50:15 -08:00
|
|
|
hasTooltip = true;
|
2013-12-05 06:35:35 -08:00
|
|
|
}
|
2013-11-15 18:46:59 -08:00
|
|
|
|
2013-12-11 11:50:15 -08:00
|
|
|
// Test for image
|
2014-02-05 02:53:46 -08:00
|
|
|
if (this.inspector.hasUrlToImageDataResolver) {
|
|
|
|
let isImageHref = target.classList.contains("theme-link") &&
|
|
|
|
target.parentNode.classList.contains("ruleview-propertyvalue");
|
|
|
|
if (isImageHref) {
|
|
|
|
property = target.parentNode.textProperty;
|
|
|
|
|
|
|
|
let maxDim = Services.prefs.getIntPref("devtools.inspector.imagePreviewTooltipSize");
|
|
|
|
let uri = CssLogic.getBackgroundImageUriFromProperty(property.value,
|
|
|
|
property.rule.domRule.href);
|
|
|
|
this.previewTooltip.setRelativeImageContent(uri,
|
|
|
|
this.inspector.inspector, maxDim).then(def.resolve);
|
|
|
|
hasTooltip = true;
|
|
|
|
}
|
2013-12-11 11:50:15 -08:00
|
|
|
}
|
2013-12-06 05:50:05 -08:00
|
|
|
|
2014-03-10 06:24:58 -07:00
|
|
|
// Get the nodes containing the property name and property value,
|
|
|
|
// and test for font family
|
|
|
|
let propertyRoot = target.parentNode;
|
|
|
|
let propertyNameNode = propertyRoot.querySelector(".ruleview-propertyname");
|
|
|
|
|
|
|
|
if (!propertyNameNode) {
|
|
|
|
propertyRoot = propertyRoot.parentNode;
|
|
|
|
propertyNameNode = propertyRoot.querySelector(".ruleview-propertyname");
|
|
|
|
}
|
|
|
|
|
|
|
|
let propertyName;
|
|
|
|
if (propertyNameNode) {
|
|
|
|
propertyName = propertyNameNode.textContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertyName === "font-family" &&
|
|
|
|
target.classList.contains("ruleview-propertyvalue")) {
|
|
|
|
this.previewTooltip.setFontFamilyContent(target.textContent).then(def.resolve);
|
|
|
|
hasTooltip = true;
|
|
|
|
}
|
|
|
|
|
2014-03-19 02:11:34 -07:00
|
|
|
if (!hasTooltip) {
|
|
|
|
def.reject();
|
|
|
|
} else if (this.colorPicker.tooltip.isShown()) {
|
2013-12-11 11:50:15 -08:00
|
|
|
this.colorPicker.revert();
|
|
|
|
this.colorPicker.hide();
|
|
|
|
}
|
2013-12-06 05:50:05 -08:00
|
|
|
|
2013-12-11 11:50:15 -08:00
|
|
|
return def.promise;
|
2013-10-25 12:21:01 -07:00
|
|
|
},
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
/**
|
|
|
|
* Update the context menu. This means enabling or disabling menuitems as
|
|
|
|
* appropriate.
|
|
|
|
*/
|
|
|
|
_contextMenuUpdate: function() {
|
|
|
|
let win = this.doc.defaultView;
|
|
|
|
|
|
|
|
// Copy selection.
|
|
|
|
let selection = win.getSelection();
|
|
|
|
let copy;
|
|
|
|
|
|
|
|
if (selection.toString()) {
|
|
|
|
// Panel text selected
|
|
|
|
copy = true;
|
|
|
|
} else if (selection.anchorNode) {
|
|
|
|
// input type="text"
|
|
|
|
let { selectionStart, selectionEnd } = this.doc.popupNode;
|
|
|
|
|
|
|
|
if (isFinite(selectionStart) && isFinite(selectionEnd) &&
|
|
|
|
selectionStart !== selectionEnd) {
|
|
|
|
copy = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No text selected, disable copy.
|
|
|
|
copy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.menuitemCopy.disabled = !copy;
|
2014-01-14 07:13:47 -08:00
|
|
|
|
|
|
|
let label = "ruleView.contextmenu.showOrigSources";
|
|
|
|
if (Services.prefs.getBoolPref(PREF_ORIG_SOURCES)) {
|
|
|
|
label = "ruleView.contextmenu.showCSSSources";
|
|
|
|
}
|
|
|
|
this.menuitemSources.setAttribute("label",
|
|
|
|
_strings.GetStringFromName(label));
|
|
|
|
|
|
|
|
let accessKey = label + ".accessKey";
|
|
|
|
this.menuitemSources.setAttribute("accesskey",
|
|
|
|
_strings.GetStringFromName(accessKey));
|
2013-09-19 17:15:34 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select all text.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onSelectAll: function() {
|
2013-09-19 17:15:34 -07:00
|
|
|
let win = this.doc.defaultView;
|
|
|
|
let selection = win.getSelection();
|
|
|
|
|
|
|
|
selection.selectAllChildren(this.doc.documentElement);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy selected text from the rule view.
|
|
|
|
*
|
|
|
|
* @param {Event} event
|
|
|
|
* The event object.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onCopy: function(event) {
|
2013-09-19 17:15:34 -07:00
|
|
|
try {
|
|
|
|
let target = event.target;
|
|
|
|
let text;
|
|
|
|
|
|
|
|
if (event.target.nodeName === "menuitem") {
|
|
|
|
target = this.doc.popupNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target.nodeName == "input") {
|
|
|
|
let start = Math.min(target.selectionStart, target.selectionEnd);
|
|
|
|
let end = Math.max(target.selectionStart, target.selectionEnd);
|
|
|
|
let count = end - start;
|
|
|
|
text = target.value.substr(start, count);
|
|
|
|
} else {
|
|
|
|
let win = this.doc.defaultView;
|
2013-10-18 07:01:20 -07:00
|
|
|
let selection = win.getSelection();
|
2013-11-11 07:17:41 -08:00
|
|
|
|
2013-10-18 07:01:20 -07:00
|
|
|
text = selection.toString();
|
2013-09-19 17:15:34 -07:00
|
|
|
|
|
|
|
// Remove any double newlines.
|
|
|
|
text = text.replace(/(\r?\n)\r?\n/g, "$1");
|
|
|
|
|
|
|
|
// Remove "inline"
|
|
|
|
let inline = _strings.GetStringFromName("rule.sourceInline");
|
|
|
|
let rx = new RegExp("^" + inline + "\\r?\\n?", "g");
|
|
|
|
text = text.replace(rx, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboardHelper.copyString(text, this.doc);
|
|
|
|
event.preventDefault();
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
/**
|
|
|
|
* Toggle the original sources pref.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onToggleOrigSources: function() {
|
2014-01-14 07:13:47 -08:00
|
|
|
let isEnabled = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
|
|
|
|
Services.prefs.setBoolPref(PREF_ORIG_SOURCES, !isEnabled);
|
|
|
|
},
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
setPageStyle: function(aPageStyle) {
|
|
|
|
this.pageStyle = aPageStyle;
|
|
|
|
},
|
|
|
|
|
2012-06-02 15:18:33 -07:00
|
|
|
/**
|
2012-11-16 11:55:00 -08:00
|
|
|
* Return {bool} true if the rule view currently has an input editor visible.
|
2012-06-02 15:18:33 -07:00
|
|
|
*/
|
|
|
|
get isEditing() {
|
2013-11-15 18:46:59 -08:00
|
|
|
return this.element.querySelectorAll(".styleinspector-propertyeditor").length > 0
|
|
|
|
|| this.colorPicker.tooltip.isShown();
|
2012-06-02 15:18:33 -07:00
|
|
|
},
|
|
|
|
|
2013-09-16 03:01:25 -07:00
|
|
|
_handlePrefChange: function(event, data) {
|
|
|
|
if (data.pref == "devtools.defaultColorUnit") {
|
|
|
|
let element = this._viewedElement;
|
|
|
|
this._viewedElement = null;
|
|
|
|
this.highlight(element);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
_onSourcePrefChanged: function() {
|
2014-01-14 07:13:47 -08:00
|
|
|
if (this.menuitemSources) {
|
|
|
|
let isEnabled = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
|
|
|
|
this.menuitemSources.setAttribute("checked", isEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update text of source links
|
|
|
|
for (let rule of this._elementStyle.rules) {
|
|
|
|
if (rule.editor) {
|
|
|
|
rule.editor.updateSourceLink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
destroy: function() {
|
2012-04-04 09:36:35 -07:00
|
|
|
this.clear();
|
|
|
|
|
2013-10-31 15:49:37 -07:00
|
|
|
gDummyPromise = null;
|
2013-09-16 03:01:25 -07:00
|
|
|
gDevTools.off("pref-changed", this._handlePrefChange);
|
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
this._prefObserver.off(PREF_ORIG_SOURCES, this._onSourcePrefChanged);
|
|
|
|
this._prefObserver.destroy();
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
this.element.removeEventListener("copy", this._onCopy);
|
|
|
|
delete this._onCopy;
|
|
|
|
|
2013-10-18 07:01:20 -07:00
|
|
|
delete this._outputParser;
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
// Remove context menu
|
|
|
|
if (this._contextmenu) {
|
|
|
|
// Destroy the Select All menuitem.
|
|
|
|
this.menuitemSelectAll.removeEventListener("command", this._onSelectAll);
|
|
|
|
this.menuitemSelectAll = null;
|
|
|
|
|
|
|
|
// Destroy the Copy menuitem.
|
|
|
|
this.menuitemCopy.removeEventListener("command", this._onCopy);
|
|
|
|
this.menuitemCopy = null;
|
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
this.menuitemSources.removeEventListener("command", this._onToggleOrigSources);
|
|
|
|
this.menuitemSources = null;
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
// Destroy the context menu.
|
|
|
|
this._contextmenu.removeEventListener("popupshowing", this._contextMenuUpdate);
|
|
|
|
this._contextmenu.parentNode.removeChild(this._contextmenu);
|
|
|
|
this._contextmenu = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We manage the popupNode ourselves so we also need to destroy it.
|
|
|
|
this.doc.popupNode = null;
|
2012-04-04 09:36:35 -07:00
|
|
|
|
2013-11-15 18:46:59 -08:00
|
|
|
this.previewTooltip.stopTogglingOnHover(this.element);
|
|
|
|
this.previewTooltip.destroy();
|
|
|
|
this.colorPicker.destroy();
|
2013-10-25 12:21:01 -07:00
|
|
|
|
2012-04-04 09:36:35 -07:00
|
|
|
if (this.element.parentNode) {
|
|
|
|
this.element.parentNode.removeChild(this.element);
|
|
|
|
}
|
2013-07-25 16:05:05 -07:00
|
|
|
|
2013-09-08 03:23:00 -07:00
|
|
|
if (this.elementStyle) {
|
|
|
|
this.elementStyle.destroy();
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
|
2013-07-25 16:05:05 -07:00
|
|
|
this.popup.destroy();
|
2012-04-04 09:36:35 -07:00
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Update the highlighted element.
|
|
|
|
*
|
2013-12-11 11:50:15 -08:00
|
|
|
* @param {NodeActor} aElement
|
2011-11-01 18:06:48 -07:00
|
|
|
* The node whose style rules we'll inspect.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
highlight: function(aElement) {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (this._viewedElement === aElement) {
|
2013-08-08 08:44:57 -07:00
|
|
|
return promise.resolve(undefined);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this.clear();
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
if (this._elementStyle) {
|
|
|
|
delete this._elementStyle;
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
this._viewedElement = aElement;
|
|
|
|
if (!this._viewedElement) {
|
2012-04-19 11:13:44 -07:00
|
|
|
this._showEmpty();
|
2013-08-08 08:44:57 -07:00
|
|
|
return promise.resolve(undefined);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this._elementStyle = new ElementStyle(aElement, this.store, this.pageStyle);
|
|
|
|
return this._populate().then(() => {
|
|
|
|
this._elementStyle.onChanged = () => {
|
|
|
|
this._changed();
|
|
|
|
};
|
|
|
|
}).then(null, console.error);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
2012-03-08 18:27:37 -08:00
|
|
|
|
2012-02-24 16:01:29 -08:00
|
|
|
/**
|
|
|
|
* Update the rules for the currently highlighted element.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
nodeChanged: function() {
|
2013-05-10 07:29:11 -07:00
|
|
|
// Ignore refreshes during editing or when no element is selected.
|
|
|
|
if (this.isEditing || !this._elementStyle) {
|
2013-10-15 05:09:49 -07:00
|
|
|
return;
|
2012-06-02 15:18:33 -07:00
|
|
|
}
|
|
|
|
|
2012-03-14 03:04:11 -07:00
|
|
|
this._clearRules();
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
// Repopulate the element style.
|
2013-10-15 05:09:49 -07:00
|
|
|
this._populate();
|
2013-08-08 08:44:57 -07:00
|
|
|
},
|
2012-05-30 19:49:10 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
_populate: function() {
|
|
|
|
let elementStyle = this._elementStyle;
|
|
|
|
return this._elementStyle.populate().then(() => {
|
|
|
|
if (this._elementStyle != elementStyle) {
|
2014-01-09 03:36:01 -08:00
|
|
|
return;
|
2013-08-08 08:44:57 -07:00
|
|
|
}
|
|
|
|
this._createEditors();
|
2012-06-02 15:18:33 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// Notify anyone that cares that we refreshed.
|
|
|
|
var evt = this.doc.createEvent("Events");
|
|
|
|
evt.initEvent("CssRuleViewRefreshed", true, false);
|
|
|
|
this.element.dispatchEvent(evt);
|
|
|
|
return undefined;
|
|
|
|
}).then(null, promiseWarn);
|
2012-04-04 09:36:35 -07:00
|
|
|
},
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2012-04-19 11:13:44 -07:00
|
|
|
/**
|
|
|
|
* Show the user that the rule view has no node selected.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_showEmpty: function() {
|
2012-04-19 11:13:44 -07:00
|
|
|
if (this.doc.getElementById("noResults") > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
createChild(this.element, "div", {
|
|
|
|
id: "noResults",
|
|
|
|
textContent: CssLogic.l10n("rule.empty")
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
2012-02-24 16:01:29 -08:00
|
|
|
* Clear the rules.
|
2011-11-01 18:06:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_clearRules: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
while (this.element.hasChildNodes()) {
|
|
|
|
this.element.removeChild(this.element.lastChild);
|
|
|
|
}
|
2012-02-24 16:01:29 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the rule view.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
clear: function() {
|
2012-02-24 16:01:29 -08:00
|
|
|
this._clearRules();
|
2011-11-01 18:06:48 -07:00
|
|
|
this._viewedElement = null;
|
|
|
|
this._elementStyle = null;
|
2013-12-11 23:57:37 -08:00
|
|
|
|
|
|
|
this.previewTooltip.hide();
|
|
|
|
this.colorPicker.hide();
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
2011-11-06 19:02:08 -08:00
|
|
|
/**
|
|
|
|
* Called when the user has made changes to the ElementStyle.
|
|
|
|
* Emits an event that clients can listen to.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_changed: function() {
|
2011-11-06 19:02:08 -08:00
|
|
|
var evt = this.doc.createEvent("Events");
|
|
|
|
evt.initEvent("CssRuleViewChanged", true, false);
|
|
|
|
this.element.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2013-09-04 08:43:40 -07:00
|
|
|
/**
|
|
|
|
* Text for header that shows above rules for this element
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
get selectedElementLabel() {
|
2013-09-04 08:43:40 -07:00
|
|
|
if (this._selectedElementLabel) {
|
|
|
|
return this._selectedElementLabel;
|
|
|
|
}
|
|
|
|
this._selectedElementLabel = CssLogic.l10n("rule.selectedElement");
|
|
|
|
return this._selectedElementLabel;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text for header that shows above rules for pseudo elements
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
get pseudoElementLabel() {
|
2013-09-04 08:43:40 -07:00
|
|
|
if (this._pseudoElementLabel) {
|
|
|
|
return this._pseudoElementLabel;
|
|
|
|
}
|
|
|
|
this._pseudoElementLabel = CssLogic.l10n("rule.pseudoElement");
|
|
|
|
return this._pseudoElementLabel;
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
togglePseudoElementVisibility: function(value) {
|
2013-09-04 08:43:40 -07:00
|
|
|
this._showPseudoElements = !!value;
|
|
|
|
let isOpen = this.showPseudoElements;
|
|
|
|
|
|
|
|
Services.prefs.setBoolPref("devtools.inspector.show_pseudo_elements",
|
|
|
|
isOpen);
|
|
|
|
|
|
|
|
this.element.classList.toggle("show-pseudo-elements", isOpen);
|
|
|
|
|
|
|
|
if (this.pseudoElementTwisty) {
|
|
|
|
if (isOpen) {
|
|
|
|
this.pseudoElementTwisty.setAttribute("open", "true");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.pseudoElementTwisty.removeAttribute("open");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
get showPseudoElements() {
|
2013-09-04 08:43:40 -07:00
|
|
|
if (this._showPseudoElements === undefined) {
|
|
|
|
this._showPseudoElements =
|
|
|
|
Services.prefs.getBoolPref("devtools.inspector.show_pseudo_elements");
|
|
|
|
}
|
|
|
|
return this._showPseudoElements;
|
|
|
|
},
|
|
|
|
|
2013-09-09 20:22:00 -07:00
|
|
|
_getRuleViewHeaderClassName: function(isPseudo) {
|
|
|
|
let baseClassName = "theme-gutter ruleview-header";
|
|
|
|
return isPseudo ? baseClassName + " ruleview-expandable-header" : baseClassName;
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Creates editor UI for each of the rules in _elementStyle.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_createEditors: function() {
|
2012-05-30 19:49:10 -07:00
|
|
|
// Run through the current list of rules, attaching
|
|
|
|
// their editors in order. Create editors if needed.
|
2012-03-14 03:04:11 -07:00
|
|
|
let lastInheritedSource = "";
|
2013-09-04 08:43:40 -07:00
|
|
|
let seenPseudoElement = false;
|
|
|
|
let seenNormalElement = false;
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
for (let rule of this._elementStyle.rules) {
|
|
|
|
if (rule.domRule.system) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-14 03:04:11 -07:00
|
|
|
|
2013-09-04 08:43:40 -07:00
|
|
|
// Only print header for this element if there are pseudo elements
|
|
|
|
if (seenPseudoElement && !seenNormalElement && !rule.pseudoElement) {
|
|
|
|
seenNormalElement = true;
|
|
|
|
let div = this.doc.createElementNS(HTML_NS, "div");
|
2013-09-09 20:22:00 -07:00
|
|
|
div.className = this._getRuleViewHeaderClassName();
|
2013-09-04 08:43:40 -07:00
|
|
|
div.textContent = this.selectedElementLabel;
|
|
|
|
this.element.appendChild(div);
|
|
|
|
}
|
|
|
|
|
2012-03-14 03:04:11 -07:00
|
|
|
let inheritedSource = rule.inheritedSource;
|
|
|
|
if (inheritedSource != lastInheritedSource) {
|
2013-09-04 08:43:40 -07:00
|
|
|
let div = this.doc.createElementNS(HTML_NS, "div");
|
2013-09-09 20:22:00 -07:00
|
|
|
div.className = this._getRuleViewHeaderClassName();
|
2013-09-04 08:43:40 -07:00
|
|
|
div.textContent = inheritedSource;
|
2012-03-14 03:04:11 -07:00
|
|
|
lastInheritedSource = inheritedSource;
|
2013-09-04 08:43:40 -07:00
|
|
|
this.element.appendChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!seenPseudoElement && rule.pseudoElement) {
|
|
|
|
seenPseudoElement = true;
|
|
|
|
|
|
|
|
let div = this.doc.createElementNS(HTML_NS, "div");
|
2013-09-09 20:22:00 -07:00
|
|
|
div.className = this._getRuleViewHeaderClassName(true);
|
2013-09-04 08:43:40 -07:00
|
|
|
div.textContent = this.pseudoElementLabel;
|
2013-09-09 20:22:00 -07:00
|
|
|
div.addEventListener("dblclick", () => {
|
|
|
|
this.togglePseudoElementVisibility(!this.showPseudoElements);
|
|
|
|
}, false);
|
2013-09-04 08:43:40 -07:00
|
|
|
|
|
|
|
let twisty = this.pseudoElementTwisty =
|
|
|
|
this.doc.createElementNS(HTML_NS, "span");
|
|
|
|
twisty.className = "ruleview-expander theme-twisty";
|
|
|
|
twisty.addEventListener("click", () => {
|
|
|
|
this.togglePseudoElementVisibility(!this.showPseudoElements);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
div.insertBefore(twisty, div.firstChild);
|
|
|
|
this.element.appendChild(div);
|
2012-03-14 03:04:11 -07:00
|
|
|
}
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
if (!rule.editor) {
|
2013-09-12 09:18:29 -07:00
|
|
|
rule.editor = new RuleEditor(this, rule);
|
2012-05-30 19:49:10 -07:00
|
|
|
}
|
|
|
|
|
2012-03-14 03:04:11 -07:00
|
|
|
this.element.appendChild(rule.editor.element);
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2013-09-04 08:43:40 -07:00
|
|
|
|
|
|
|
this.togglePseudoElementVisibility(this.showPseudoElements);
|
2014-02-05 02:53:46 -08:00
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a RuleEditor.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {CssRuleView} aRuleView
|
2012-06-01 15:13:48 -07:00
|
|
|
* The CssRuleView containg the document holding this rule editor.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {Rule} aRule
|
2011-11-01 18:06:48 -07:00
|
|
|
* The Rule object we're editing.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function RuleEditor(aRuleView, aRule) {
|
2012-03-11 07:01:38 -07:00
|
|
|
this.ruleView = aRuleView;
|
|
|
|
this.doc = this.ruleView.doc;
|
2011-11-01 18:06:48 -07:00
|
|
|
this.rule = aRule;
|
|
|
|
|
|
|
|
this._onNewProperty = this._onNewProperty.bind(this);
|
2012-06-01 15:13:48 -07:00
|
|
|
this._newPropertyDestroy = this._newPropertyDestroy.bind(this);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
this._create();
|
|
|
|
}
|
|
|
|
|
|
|
|
RuleEditor.prototype = {
|
2014-02-05 02:53:46 -08:00
|
|
|
_create: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element = this.doc.createElementNS(HTML_NS, "div");
|
2013-03-27 15:20:38 -07:00
|
|
|
this.element.className = "ruleview-rule theme-separator";
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element._ruleEditor = this;
|
2013-09-04 08:43:40 -07:00
|
|
|
if (this.rule.pseudoElement) {
|
|
|
|
this.element.classList.add("ruleview-rule-pseudo-element");
|
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2011-11-15 16:47:14 -08:00
|
|
|
// Give a relative position for the inplace editor's measurement
|
|
|
|
// span to be placed absolutely against.
|
|
|
|
this.element.style.position = "relative";
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// Add the source link.
|
|
|
|
let source = createChild(this.element, "div", {
|
2013-04-11 09:08:33 -07:00
|
|
|
class: "ruleview-rule-source theme-link"
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
2012-02-10 05:39:47 -08:00
|
|
|
source.addEventListener("click", function() {
|
2013-08-08 08:44:57 -07:00
|
|
|
let rule = this.rule.domRule;
|
2012-02-10 05:39:47 -08:00
|
|
|
let evt = this.doc.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent("CssRuleViewCSSLinkClicked", true, false, {
|
|
|
|
rule: rule,
|
|
|
|
});
|
|
|
|
this.element.dispatchEvent(evt);
|
|
|
|
}.bind(this));
|
2013-04-11 09:08:33 -07:00
|
|
|
let sourceLabel = this.doc.createElementNS(XUL_NS, "label");
|
|
|
|
sourceLabel.setAttribute("crop", "center");
|
2014-01-14 07:13:47 -08:00
|
|
|
sourceLabel.classList.add("source-link-label");
|
2013-04-11 09:08:33 -07:00
|
|
|
source.appendChild(sourceLabel);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
this.updateSourceLink();
|
2013-12-06 23:52:32 -08:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
let code = createChild(this.element, "div", {
|
|
|
|
class: "ruleview-code"
|
|
|
|
});
|
|
|
|
|
|
|
|
let header = createChild(code, "div", {});
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
this.selectorText = createChild(header, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-selector theme-fg-color3"
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
2011-12-22 10:58:17 -08:00
|
|
|
|
|
|
|
this.openBrace = createChild(header, "span", {
|
|
|
|
class: "ruleview-ruleopen",
|
|
|
|
textContent: " {"
|
|
|
|
});
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
code.addEventListener("click", function() {
|
|
|
|
let selection = this.doc.defaultView.getSelection();
|
|
|
|
if (selection.isCollapsed) {
|
|
|
|
this.newProperty();
|
|
|
|
}
|
|
|
|
}.bind(this), false);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2012-10-31 09:25:08 -07:00
|
|
|
this.element.addEventListener("mousedown", function() {
|
2012-12-18 06:27:04 -08:00
|
|
|
this.doc.defaultView.focus();
|
2012-10-31 09:25:08 -07:00
|
|
|
}.bind(this), false);
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
this.element.addEventListener("contextmenu", event => {
|
|
|
|
try {
|
|
|
|
// In the sidebar we do not have this.doc.popupNode so we need to save
|
|
|
|
// the node ourselves.
|
|
|
|
this.doc.popupNode = event.explicitOriginalTarget;
|
|
|
|
let win = this.doc.defaultView;
|
|
|
|
win.focus();
|
|
|
|
|
2013-11-12 08:27:55 -08:00
|
|
|
this.ruleView._contextmenu.openPopupAtScreen(
|
|
|
|
event.screenX, event.screenY, true);
|
|
|
|
|
2013-09-19 17:15:34 -07:00
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
this.propertyList = createChild(code, "ul", {
|
|
|
|
class: "ruleview-propertylist"
|
|
|
|
});
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
this.populate();
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
this.closeBrace = createChild(code, "div", {
|
|
|
|
class: "ruleview-ruleclose",
|
|
|
|
tabindex: "0",
|
|
|
|
textContent: "}"
|
|
|
|
});
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
// Create a property editor when the close brace is clicked.
|
2014-01-16 18:40:54 -08:00
|
|
|
editableItem({ element: this.closeBrace }, (aElement) => {
|
2012-06-01 15:13:48 -07:00
|
|
|
this.newProperty();
|
2014-01-16 18:40:54 -08:00
|
|
|
});
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
2014-01-14 07:13:47 -08:00
|
|
|
updateSourceLink: function RuleEditor_updateSourceLink()
|
|
|
|
{
|
|
|
|
let sourceLabel = this.element.querySelector(".source-link-label");
|
|
|
|
sourceLabel.setAttribute("value", this.rule.title);
|
|
|
|
sourceLabel.setAttribute("tooltiptext", this.rule.title);
|
|
|
|
|
|
|
|
let showOrig = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
|
|
|
|
if (showOrig && this.rule.domRule.type != ELEMENT_STYLE) {
|
|
|
|
this.rule.getOriginalSourceString().then((string) => {
|
|
|
|
sourceLabel.setAttribute("value", string);
|
|
|
|
sourceLabel.setAttribute("tooltiptext", string);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-30 19:49:10 -07:00
|
|
|
/**
|
|
|
|
* Update the rule editor with the contents of the rule.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
populate: function() {
|
2012-09-20 12:54:39 -07:00
|
|
|
// Clear out existing viewers.
|
|
|
|
while (this.selectorText.hasChildNodes()) {
|
|
|
|
this.selectorText.removeChild(this.selectorText.lastChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If selector text comes from a css rule, highlight selectors that
|
|
|
|
// actually match. For custom selector text (such as for the 'element'
|
|
|
|
// style, just show the text directly.
|
2013-08-08 08:44:57 -07:00
|
|
|
if (this.rule.domRule.type === ELEMENT_STYLE) {
|
|
|
|
this.selectorText.textContent = this.rule.selectorText;
|
|
|
|
} else {
|
|
|
|
this.rule.domRule.selectors.forEach((selector, i) => {
|
2012-09-20 12:54:39 -07:00
|
|
|
if (i != 0) {
|
|
|
|
createChild(this.selectorText, "span", {
|
|
|
|
class: "ruleview-selector-separator",
|
|
|
|
textContent: ", "
|
|
|
|
});
|
|
|
|
}
|
2013-02-04 08:29:30 -08:00
|
|
|
let cls;
|
2013-08-08 08:44:57 -07:00
|
|
|
if (this.rule.matchedSelectors.indexOf(selector) > -1) {
|
2013-02-04 08:29:30 -08:00
|
|
|
cls = "ruleview-selector-matched";
|
|
|
|
} else {
|
|
|
|
cls = "ruleview-selector-unmatched";
|
|
|
|
}
|
2012-09-20 12:54:39 -07:00
|
|
|
createChild(this.selectorText, "span", {
|
|
|
|
class: cls,
|
|
|
|
textContent: selector
|
|
|
|
});
|
2013-08-08 08:44:57 -07:00
|
|
|
});
|
2012-09-20 12:54:39 -07:00
|
|
|
}
|
2012-05-30 19:49:10 -07:00
|
|
|
|
|
|
|
for (let prop of this.rule.textProps) {
|
|
|
|
if (!prop.editor) {
|
2013-09-12 09:18:29 -07:00
|
|
|
let editor = new TextPropertyEditor(this, prop);
|
|
|
|
this.propertyList.appendChild(editor.element);
|
2012-05-30 19:49:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Programatically add a new property to the rule.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} aName
|
2012-05-30 19:49:10 -07:00
|
|
|
* Property name.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} aValue
|
2012-05-30 19:49:10 -07:00
|
|
|
* Property value.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} aPriority
|
2012-05-30 19:49:10 -07:00
|
|
|
* Property priority.
|
2014-01-16 18:40:54 -08:00
|
|
|
* @param {TextProperty} aSiblingProp
|
|
|
|
* Optional, property next to which the new property will be added.
|
2013-09-04 08:43:40 -07:00
|
|
|
* @return {TextProperty}
|
|
|
|
* The new property
|
2012-05-30 19:49:10 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
addProperty: function(aName, aValue, aPriority, aSiblingProp) {
|
2014-01-16 18:40:54 -08:00
|
|
|
let prop = this.rule.createProperty(aName, aValue, aPriority, aSiblingProp);
|
|
|
|
let index = this.rule.textProps.indexOf(prop);
|
2012-05-30 19:49:10 -07:00
|
|
|
let editor = new TextPropertyEditor(this, prop);
|
2014-01-16 18:40:54 -08:00
|
|
|
|
|
|
|
// Insert this node before the DOM node that is currently at its new index
|
|
|
|
// in the property list. There is currently one less node in the DOM than
|
|
|
|
// in the property list, so this causes it to appear after aSiblingProp.
|
|
|
|
// If there is no node at its index, as is the case where this is the last
|
|
|
|
// node being inserted, then this behaves as appendChild.
|
|
|
|
this.propertyList.insertBefore(editor.element,
|
|
|
|
this.propertyList.children[index]);
|
|
|
|
|
2013-09-04 08:43:40 -07:00
|
|
|
return prop;
|
2012-05-30 19:49:10 -07:00
|
|
|
},
|
|
|
|
|
2014-01-16 18:40:54 -08:00
|
|
|
/**
|
|
|
|
* Programatically add a list of new properties to the rule. Focus the UI
|
|
|
|
* to the proper location after adding (either focus the value on the
|
|
|
|
* last property if it is empty, or create a new property and focus it).
|
|
|
|
*
|
|
|
|
* @param {Array} aProperties
|
|
|
|
* Array of properties, which are objects with this signature:
|
|
|
|
* {
|
|
|
|
* name: {string},
|
|
|
|
* value: {string},
|
|
|
|
* priority: {string}
|
|
|
|
* }
|
|
|
|
* @param {TextProperty} aSiblingProp
|
|
|
|
* Optional, the property next to which all new props should be added.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
addProperties: function(aProperties, aSiblingProp) {
|
2014-01-16 18:40:54 -08:00
|
|
|
if (!aProperties || !aProperties.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lastProp = aSiblingProp;
|
|
|
|
for (let p of aProperties) {
|
|
|
|
lastProp = this.addProperty(p.name, p.value, p.priority, lastProp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either focus on the last value if incomplete, or start a new one.
|
|
|
|
if (lastProp && lastProp.value.trim() === "") {
|
|
|
|
lastProp.editor.valueSpan.click();
|
|
|
|
} else {
|
|
|
|
this.newProperty();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Create a text input for a property name. If a non-empty property
|
|
|
|
* name is given, we'll create a real TextProperty and add it to the
|
|
|
|
* rule.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
newProperty: function() {
|
2012-06-01 15:13:48 -07:00
|
|
|
// If we're already creating a new property, ignore this.
|
|
|
|
if (!this.closeBrace.hasAttribute("tabindex")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// While we're editing a new property, it doesn't make sense to
|
|
|
|
// start a second new property editor, so disable focusing the
|
|
|
|
// close brace for now.
|
|
|
|
this.closeBrace.removeAttribute("tabindex");
|
|
|
|
|
|
|
|
this.newPropItem = createChild(this.propertyList, "li", {
|
|
|
|
class: "ruleview-property ruleview-newproperty",
|
|
|
|
});
|
|
|
|
|
|
|
|
this.newPropSpan = createChild(this.newPropItem, "span", {
|
2012-06-01 15:13:48 -07:00
|
|
|
class: "ruleview-propertyname",
|
|
|
|
tabindex: "0"
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
|
|
|
|
2014-01-16 18:40:54 -08:00
|
|
|
this.multipleAddedProperties = null;
|
|
|
|
|
|
|
|
this.editor = new InplaceEditor({
|
2011-11-01 18:06:48 -07:00
|
|
|
element: this.newPropSpan,
|
|
|
|
done: this._onNewProperty,
|
2012-06-01 15:13:48 -07:00
|
|
|
destroy: this._newPropertyDestroy,
|
2013-07-25 16:05:05 -07:00
|
|
|
advanceChars: ":",
|
|
|
|
contentType: InplaceEditor.CONTENT_TYPES.CSS_PROPERTY,
|
|
|
|
popup: this.ruleView.popup
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
2014-01-16 18:40:54 -08:00
|
|
|
|
|
|
|
// Auto-close the input if multiple rules get pasted into new property.
|
|
|
|
this.editor.input.addEventListener("paste",
|
|
|
|
blurOnMultipleProperties, false);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
/**
|
|
|
|
* Called when the new property input has been dismissed.
|
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} aValue
|
2012-06-01 15:13:48 -07:00
|
|
|
* The value in the editor.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {bool} aCommit
|
2012-06-01 15:13:48 -07:00
|
|
|
* True if the value should be committed.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onNewProperty: function(aValue, aCommit) {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (!aValue || !aCommit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
// parseDeclarations allows for name-less declarations, but in the present
|
|
|
|
// case, we're creating a new declaration, it doesn't make sense to accept
|
|
|
|
// these entries
|
|
|
|
this.multipleAddedProperties = parseDeclarations(aValue).filter(d => d.name);
|
2014-01-16 18:40:54 -08:00
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
// Blur the editor field now and deal with adding declarations later when
|
|
|
|
// the field gets destroyed (see _newPropertyDestroy)
|
2014-01-16 18:40:54 -08:00
|
|
|
this.editor.input.blur();
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
2012-06-01 15:13:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the new property editor is destroyed.
|
2014-01-16 18:40:54 -08:00
|
|
|
* This is where the properties (type TextProperty) are actually being
|
|
|
|
* added, since we want to wait until after the inplace editor `destroy`
|
|
|
|
* event has been fired to keep consistent UI state.
|
2012-06-01 15:13:48 -07:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_newPropertyDestroy: function() {
|
2012-06-01 15:13:48 -07:00
|
|
|
// We're done, make the close brace focusable again.
|
|
|
|
this.closeBrace.setAttribute("tabindex", "0");
|
|
|
|
|
|
|
|
this.propertyList.removeChild(this.newPropItem);
|
|
|
|
delete this.newPropItem;
|
|
|
|
delete this.newPropSpan;
|
2014-01-16 18:40:54 -08:00
|
|
|
|
|
|
|
// If properties were added, we want to focus the proper element.
|
|
|
|
// If the last new property has no value, focus the value on it.
|
|
|
|
// Otherwise, start a new property and focus that field.
|
|
|
|
if (this.multipleAddedProperties && this.multipleAddedProperties.length) {
|
|
|
|
this.addProperties(this.multipleAddedProperties);
|
|
|
|
}
|
2012-06-01 15:13:48 -07:00
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a TextPropertyEditor.
|
|
|
|
*
|
|
|
|
* @param {RuleEditor} aRuleEditor
|
|
|
|
* The rule editor that owns this TextPropertyEditor.
|
|
|
|
* @param {TextProperty} aProperty
|
|
|
|
* The text property to edit.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function TextPropertyEditor(aRuleEditor, aProperty) {
|
2013-08-27 04:34:17 -07:00
|
|
|
this.ruleEditor = aRuleEditor;
|
|
|
|
this.doc = this.ruleEditor.doc;
|
|
|
|
this.popup = this.ruleEditor.ruleView.popup;
|
2011-11-01 18:06:48 -07:00
|
|
|
this.prop = aProperty;
|
|
|
|
this.prop.editor = this;
|
2013-04-29 15:12:47 -07:00
|
|
|
this.browserWindow = this.doc.defaultView.top;
|
2013-09-12 09:18:29 -07:00
|
|
|
this.removeOnRevert = this.prop.value === "";
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2013-10-08 13:23:09 -07:00
|
|
|
let domRule = this.prop.rule.domRule;
|
|
|
|
let href = domRule ? domRule.href : null;
|
2013-04-19 14:30:33 -07:00
|
|
|
if (href) {
|
|
|
|
this.sheetURI = IOService.newURI(href, null, null);
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
this._onEnableClicked = this._onEnableClicked.bind(this);
|
|
|
|
this._onExpandClicked = this._onExpandClicked.bind(this);
|
|
|
|
this._onStartEditing = this._onStartEditing.bind(this);
|
|
|
|
this._onNameDone = this._onNameDone.bind(this);
|
|
|
|
this._onValueDone = this._onValueDone.bind(this);
|
2014-01-16 18:40:54 -08:00
|
|
|
this._onValidate = throttle(this._livePreview, 10, this);
|
|
|
|
this.update = this.update.bind(this);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
this._create();
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextPropertyEditor.prototype = {
|
2013-09-12 09:18:29 -07:00
|
|
|
/**
|
|
|
|
* Boolean indicating if the name or value is being currently edited.
|
|
|
|
*/
|
2011-11-01 18:06:48 -07:00
|
|
|
get editing() {
|
2013-11-15 18:46:59 -08:00
|
|
|
return !!(this.nameSpan.inplaceEditor || this.valueSpan.inplaceEditor ||
|
|
|
|
this.ruleEditor.ruleView.colorPicker.tooltip.isShown());
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the property editor's DOM.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_create: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element = this.doc.createElementNS(HTML_NS, "li");
|
|
|
|
this.element.classList.add("ruleview-property");
|
|
|
|
|
|
|
|
// The enable checkbox will disable or enable the rule.
|
2013-03-27 15:20:38 -07:00
|
|
|
this.enable = createChild(this.element, "div", {
|
|
|
|
class: "ruleview-enableproperty theme-checkbox",
|
2011-11-01 18:06:48 -07:00
|
|
|
tabindex: "-1"
|
|
|
|
});
|
|
|
|
this.enable.addEventListener("click", this._onEnableClicked, true);
|
|
|
|
|
|
|
|
// Click to expand the computed properties of the text property.
|
|
|
|
this.expander = createChild(this.element, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-expander theme-twisty"
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
|
|
|
this.expander.addEventListener("click", this._onExpandClicked, true);
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
this.nameContainer = createChild(this.element, "span", {
|
|
|
|
class: "ruleview-namecontainer"
|
|
|
|
});
|
2013-09-12 09:18:29 -07:00
|
|
|
this.nameContainer.addEventListener("click", (aEvent) => {
|
2012-06-19 10:22:29 -07:00
|
|
|
// Clicks within the name shouldn't propagate any further.
|
2012-06-01 15:13:48 -07:00
|
|
|
aEvent.stopPropagation();
|
2012-06-19 10:22:29 -07:00
|
|
|
if (aEvent.target === propertyContainer) {
|
|
|
|
this.nameSpan.click();
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
}, false);
|
2012-06-01 15:13:48 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// Property name, editable when focused. Property name
|
|
|
|
// is committed when the editor is unfocused.
|
2012-06-01 15:13:48 -07:00
|
|
|
this.nameSpan = createChild(this.nameContainer, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-propertyname theme-fg-color5",
|
2011-11-01 18:06:48 -07:00
|
|
|
tabindex: "0",
|
|
|
|
});
|
2012-06-01 15:13:48 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
editableField({
|
|
|
|
start: this._onStartEditing,
|
|
|
|
element: this.nameSpan,
|
|
|
|
done: this._onNameDone,
|
2014-01-16 18:40:54 -08:00
|
|
|
destroy: this.update,
|
2013-07-25 16:05:05 -07:00
|
|
|
advanceChars: ':',
|
|
|
|
contentType: InplaceEditor.CONTENT_TYPES.CSS_PROPERTY,
|
|
|
|
popup: this.popup
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
|
|
|
|
2014-01-16 18:40:54 -08:00
|
|
|
// Auto blur name field on multiple CSS rules get pasted in.
|
|
|
|
this.nameContainer.addEventListener("paste",
|
|
|
|
blurOnMultipleProperties, false);
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
appendText(this.nameContainer, ": ");
|
|
|
|
|
|
|
|
// Create a span that will hold the property and semicolon.
|
|
|
|
// Use this span to create a slightly larger click target
|
|
|
|
// for the value.
|
|
|
|
let propertyContainer = createChild(this.element, "span", {
|
|
|
|
class: "ruleview-propertycontainer"
|
|
|
|
});
|
2013-11-11 07:17:41 -08:00
|
|
|
|
2013-09-12 09:18:29 -07:00
|
|
|
propertyContainer.addEventListener("click", (aEvent) => {
|
2012-06-19 10:22:29 -07:00
|
|
|
// Clicks within the value shouldn't propagate any further.
|
2012-06-01 15:13:48 -07:00
|
|
|
aEvent.stopPropagation();
|
2013-11-11 07:17:41 -08:00
|
|
|
|
2012-06-19 10:22:29 -07:00
|
|
|
if (aEvent.target === propertyContainer) {
|
|
|
|
this.valueSpan.click();
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
}, false);
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
// Property value, editable when focused. Changes to the
|
|
|
|
// property value are applied as they are typed, and reverted
|
|
|
|
// if the user presses escape.
|
2012-06-01 15:13:48 -07:00
|
|
|
this.valueSpan = createChild(propertyContainer, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-propertyvalue theme-fg-color1",
|
2011-11-01 18:06:48 -07:00
|
|
|
tabindex: "0",
|
|
|
|
});
|
|
|
|
|
2013-11-11 07:17:41 -08:00
|
|
|
this.valueSpan.addEventListener("click", (event) => {
|
|
|
|
let target = event.target;
|
|
|
|
|
|
|
|
if (target.nodeName === "a") {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
this.browserWindow.openUILinkIn(target.href, "tab");
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2013-10-25 12:21:01 -07:00
|
|
|
// Storing the TextProperty on the valuespan for easy access
|
|
|
|
// (for instance by the tooltip)
|
|
|
|
this.valueSpan.textProperty = this.prop;
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// Save the initial value as the last committed value,
|
|
|
|
// for restoring after pressing escape.
|
|
|
|
this.committed = { name: this.prop.name,
|
|
|
|
value: this.prop.value,
|
|
|
|
priority: this.prop.priority };
|
|
|
|
|
2012-06-01 15:13:48 -07:00
|
|
|
appendText(propertyContainer, ";");
|
2011-11-01 18:06:48 -07:00
|
|
|
|
2012-02-25 07:30:51 -08:00
|
|
|
this.warning = createChild(this.element, "div", {
|
|
|
|
class: "ruleview-warning",
|
2013-09-12 09:18:29 -07:00
|
|
|
hidden: "",
|
2012-02-25 07:30:51 -08:00
|
|
|
title: CssLogic.l10n("rule.warning.title"),
|
|
|
|
});
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// Holds the viewers for the computed properties.
|
|
|
|
// will be populated in |_updateComputed|.
|
|
|
|
this.computed = createChild(this.element, "ul", {
|
|
|
|
class: "ruleview-computedlist",
|
|
|
|
});
|
2012-10-01 07:38:04 -07:00
|
|
|
|
|
|
|
editableField({
|
|
|
|
start: this._onStartEditing,
|
|
|
|
element: this.valueSpan,
|
|
|
|
done: this._onValueDone,
|
2014-01-16 18:40:54 -08:00
|
|
|
destroy: this.update,
|
2013-09-12 09:18:29 -07:00
|
|
|
validate: this._onValidate,
|
2013-07-27 16:50:38 -07:00
|
|
|
advanceChars: ';',
|
|
|
|
contentType: InplaceEditor.CONTENT_TYPES.CSS_VALUE,
|
|
|
|
property: this.prop,
|
|
|
|
popup: this.popup
|
2012-10-01 07:38:04 -07:00
|
|
|
});
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
2013-04-19 14:30:33 -07:00
|
|
|
/**
|
|
|
|
* Resolve a URI based on the rule stylesheet
|
|
|
|
* @param {string} relativePath the path to resolve
|
|
|
|
* @return {string} the resolved path.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
resolveURI: function(relativePath) {
|
2013-04-19 14:30:33 -07:00
|
|
|
if (this.sheetURI) {
|
|
|
|
relativePath = this.sheetURI.resolve(relativePath);
|
|
|
|
}
|
|
|
|
return relativePath;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the property value to find an external resource (if any).
|
|
|
|
* @return {string} the URI in the property value, or null if there is no match.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
getResourceURI: function() {
|
2013-04-19 14:30:33 -07:00
|
|
|
let val = this.prop.value;
|
|
|
|
let uriMatch = CSS_RESOURCE_RE.exec(val);
|
|
|
|
let uri = null;
|
|
|
|
|
|
|
|
if (uriMatch && uriMatch[1]) {
|
|
|
|
uri = uriMatch[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Populate the span based on changes to the TextProperty.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
update: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
if (this.prop.enabled) {
|
|
|
|
this.enable.style.removeProperty("visibility");
|
|
|
|
this.enable.setAttribute("checked", "");
|
|
|
|
} else {
|
|
|
|
this.enable.style.visibility = "visible";
|
|
|
|
this.enable.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
|
2013-09-12 09:18:29 -07:00
|
|
|
this.warning.hidden = this.editing || this.isValid();
|
|
|
|
|
|
|
|
if ((this.prop.overridden || !this.prop.enabled) && !this.editing) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element.classList.add("ruleview-overridden");
|
|
|
|
} else {
|
|
|
|
this.element.classList.remove("ruleview-overridden");
|
|
|
|
}
|
|
|
|
|
2012-04-17 02:35:12 -07:00
|
|
|
let name = this.prop.name;
|
|
|
|
this.nameSpan.textContent = name;
|
2011-11-01 18:06:48 -07:00
|
|
|
|
|
|
|
// Combine the property's value and priority into one string for
|
|
|
|
// the value.
|
|
|
|
let val = this.prop.value;
|
|
|
|
if (this.prop.priority) {
|
|
|
|
val += " !" + this.prop.priority;
|
|
|
|
}
|
2013-10-18 07:01:20 -07:00
|
|
|
|
|
|
|
let store = this.prop.rule.elementStyle.store;
|
|
|
|
let propDirty = store.userProperties.contains(this.prop.rule.style, name);
|
2013-11-11 07:17:41 -08:00
|
|
|
|
2013-10-18 07:01:20 -07:00
|
|
|
if (propDirty) {
|
|
|
|
this.element.setAttribute("dirty", "");
|
|
|
|
} else {
|
|
|
|
this.element.removeAttribute("dirty");
|
|
|
|
}
|
|
|
|
|
2013-11-15 18:46:59 -08:00
|
|
|
let swatchClass = "ruleview-colorswatch";
|
2013-11-11 07:17:41 -08:00
|
|
|
let outputParser = this.ruleEditor.ruleView._outputParser;
|
|
|
|
let frag = outputParser.parseCssProperty(name, val, {
|
2013-11-15 18:46:59 -08:00
|
|
|
colorSwatchClass: swatchClass,
|
2013-12-03 05:45:29 -08:00
|
|
|
colorClass: "ruleview-color",
|
2013-11-11 07:17:41 -08:00
|
|
|
defaultColorType: !propDirty,
|
|
|
|
urlClass: "theme-link",
|
|
|
|
baseURI: this.sheetURI
|
|
|
|
});
|
|
|
|
this.valueSpan.innerHTML = "";
|
|
|
|
this.valueSpan.appendChild(frag);
|
2012-04-17 02:35:12 -07:00
|
|
|
|
2013-11-15 18:46:59 -08:00
|
|
|
// Attach the color picker tooltip to the color swatches
|
|
|
|
this._swatchSpans = this.valueSpan.querySelectorAll("." + swatchClass);
|
|
|
|
if (this._swatchSpans.length) {
|
|
|
|
for (let span of this._swatchSpans) {
|
|
|
|
// Capture the original declaration value to be able to revert later
|
|
|
|
let originalValue = this.valueSpan.textContent;
|
|
|
|
// Adding this swatch to the list of swatches our colorpicker knows
|
|
|
|
// about.
|
|
|
|
this.ruleEditor.ruleView.colorPicker.addSwatch(span, {
|
|
|
|
onPreview: () => this._livePreview(this.valueSpan.textContent),
|
|
|
|
onCommit: () => this._applyNewValue(this.valueSpan.textContent),
|
|
|
|
onRevert: () => this._applyNewValue(originalValue)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
// Populate the computed styles.
|
|
|
|
this._updateComputed();
|
|
|
|
},
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
_onStartEditing: function() {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.element.classList.remove("ruleview-overridden");
|
2013-09-12 09:18:29 -07:00
|
|
|
this._livePreview(this.prop.value);
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the list of computed styles.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_updateComputed: function () {
|
2011-11-01 18:06:48 -07:00
|
|
|
// Clear out existing viewers.
|
|
|
|
while (this.computed.hasChildNodes()) {
|
|
|
|
this.computed.removeChild(this.computed.lastChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
let showExpander = false;
|
|
|
|
for each (let computed in this.prop.computed) {
|
|
|
|
// Don't bother to duplicate information already
|
|
|
|
// shown in the text property.
|
|
|
|
if (computed.name === this.prop.name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
showExpander = true;
|
|
|
|
|
|
|
|
let li = createChild(this.computed, "li", {
|
|
|
|
class: "ruleview-computed"
|
|
|
|
});
|
|
|
|
|
|
|
|
if (computed.overridden) {
|
|
|
|
li.classList.add("ruleview-overridden");
|
|
|
|
}
|
|
|
|
|
|
|
|
createChild(li, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-propertyname theme-fg-color5",
|
2011-11-01 18:06:48 -07:00
|
|
|
textContent: computed.name
|
|
|
|
});
|
|
|
|
appendText(li, ": ");
|
2012-03-14 03:04:11 -07:00
|
|
|
|
2013-10-18 07:01:20 -07:00
|
|
|
let outputParser = this.ruleEditor.ruleView._outputParser;
|
|
|
|
let frag = outputParser.parseCssProperty(
|
|
|
|
computed.name, computed.value, {
|
2013-11-11 07:17:41 -08:00
|
|
|
colorSwatchClass: "ruleview-colorswatch",
|
|
|
|
urlClass: "theme-link",
|
|
|
|
baseURI: this.sheetURI
|
2013-10-18 07:01:20 -07:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
createChild(li, "span", {
|
2013-03-27 15:20:38 -07:00
|
|
|
class: "ruleview-propertyvalue theme-fg-color1",
|
2013-10-18 07:01:20 -07:00
|
|
|
child: frag
|
2011-11-01 18:06:48 -07:00
|
|
|
});
|
2013-10-18 07:01:20 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
appendText(li, ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show or hide the expander as needed.
|
|
|
|
if (showExpander) {
|
|
|
|
this.expander.style.visibility = "visible";
|
|
|
|
} else {
|
|
|
|
this.expander.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicks on the disabled property.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onEnableClicked: function(aEvent) {
|
2013-03-27 15:20:38 -07:00
|
|
|
let checked = this.enable.hasAttribute("checked");
|
|
|
|
if (checked) {
|
|
|
|
this.enable.removeAttribute("checked");
|
|
|
|
} else {
|
|
|
|
this.enable.setAttribute("checked", "");
|
|
|
|
}
|
|
|
|
this.prop.setEnabled(!checked);
|
2012-06-01 15:13:48 -07:00
|
|
|
aEvent.stopPropagation();
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicks on the computed property expander.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onExpandClicked: function(aEvent) {
|
2011-11-01 18:06:48 -07:00
|
|
|
this.computed.classList.toggle("styleinspector-open");
|
2013-03-27 15:20:38 -07:00
|
|
|
if (this.computed.classList.contains("styleinspector-open")) {
|
|
|
|
this.expander.setAttribute("open", "true");
|
|
|
|
} else {
|
|
|
|
this.expander.removeAttribute("open");
|
|
|
|
}
|
2012-06-01 15:13:48 -07:00
|
|
|
aEvent.stopPropagation();
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the property name's inplace editor is closed.
|
|
|
|
* Ignores the change if the user pressed escape, otherwise
|
|
|
|
* commits it.
|
|
|
|
*
|
|
|
|
* @param {string} aValue
|
|
|
|
* The value contained in the editor.
|
|
|
|
* @param {boolean} aCommit
|
|
|
|
* True if the change should be applied.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onNameDone: function(aValue, aCommit) {
|
2013-09-12 09:18:29 -07:00
|
|
|
if (aCommit) {
|
2014-01-16 18:40:54 -08:00
|
|
|
// Unlike the value editor, if a name is empty the entire property
|
|
|
|
// should always be removed.
|
2013-09-12 09:18:29 -07:00
|
|
|
if (aValue.trim() === "") {
|
|
|
|
this.remove();
|
|
|
|
} else {
|
2014-01-16 18:40:54 -08:00
|
|
|
// Adding multiple rules inside of name field overwrites the current
|
|
|
|
// property with the first, then adds any more onto the property list.
|
2014-02-03 07:52:09 -08:00
|
|
|
let properties = parseDeclarations(aValue);
|
2014-01-16 18:40:54 -08:00
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
if (properties.length) {
|
|
|
|
this.prop.setName(properties[0].name);
|
|
|
|
if (properties.length > 1) {
|
|
|
|
this.prop.setValue(properties[0].value, properties[0].priority);
|
|
|
|
this.ruleEditor.addProperties(properties.slice(1), this.prop);
|
|
|
|
}
|
2014-01-16 18:40:54 -08:00
|
|
|
}
|
2012-06-19 10:22:29 -07:00
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2013-09-12 09:18:29 -07:00
|
|
|
/**
|
|
|
|
* Remove property from style and the editors from DOM.
|
|
|
|
* Begin editing next available property.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
remove: function() {
|
2013-11-15 18:46:59 -08:00
|
|
|
if (this._swatchSpans && this._swatchSpans.length) {
|
|
|
|
for (let span of this._swatchSpans) {
|
|
|
|
this.ruleEditor.ruleView.colorPicker.removeSwatch(span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 09:18:29 -07:00
|
|
|
this.element.parentNode.removeChild(this.element);
|
|
|
|
this.ruleEditor.rule.editClosestTextProperty(this.prop);
|
2013-10-25 12:21:01 -07:00
|
|
|
this.valueSpan.textProperty = null;
|
2013-09-12 09:18:29 -07:00
|
|
|
this.prop.remove();
|
|
|
|
},
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Called when a value editor closes. If the user pressed escape,
|
|
|
|
* revert to the value this property had before editing.
|
|
|
|
*
|
|
|
|
* @param {string} aValue
|
|
|
|
* The value contained in the editor.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {bool} aCommit
|
2011-11-01 18:06:48 -07:00
|
|
|
* True if the change should be applied.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_onValueDone: function(aValue, aCommit) {
|
2014-01-16 18:40:54 -08:00
|
|
|
if (!aCommit) {
|
|
|
|
// A new property should be removed when escape is pressed.
|
|
|
|
if (this.removeOnRevert) {
|
|
|
|
this.remove();
|
|
|
|
} else {
|
|
|
|
this.prop.setValue(this.committed.value, this.committed.priority);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let {propertiesToAdd,firstValue} = this._getValueAndExtraProperties(aValue);
|
|
|
|
|
|
|
|
// First, set this property value (common case, only modified a property)
|
2014-02-03 07:52:09 -08:00
|
|
|
let val = parseSingleValue(firstValue);
|
2014-01-16 18:40:54 -08:00
|
|
|
this.prop.setValue(val.value, val.priority);
|
|
|
|
this.removeOnRevert = false;
|
|
|
|
this.committed.value = this.prop.value;
|
|
|
|
this.committed.priority = this.prop.priority;
|
|
|
|
|
|
|
|
// If needed, add any new properties after this.prop.
|
|
|
|
this.ruleEditor.addProperties(propertiesToAdd, this.prop);
|
|
|
|
|
|
|
|
// If the name or value is not actively being edited, and the value is
|
|
|
|
// empty, then remove the whole property.
|
|
|
|
// A timeout is used here to accurately check the state, since the inplace
|
|
|
|
// editor `done` and `destroy` events fire before the next editor
|
|
|
|
// is focused.
|
|
|
|
if (val.value.trim() === "") {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (!this.editing) {
|
|
|
|
this.remove();
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a value string and break it into pieces, starting with the
|
|
|
|
* first value, and into an array of additional properties (if any).
|
|
|
|
*
|
|
|
|
* Example: Calling with "red; width: 100px" would return
|
|
|
|
* { firstValue: "red", propertiesToAdd: [{ name: "width", value: "100px" }] }
|
|
|
|
*
|
|
|
|
* @param {string} aValue
|
|
|
|
* The string to parse
|
|
|
|
* @return {object} An object with the following properties:
|
|
|
|
* firstValue: A string containing a simple value, like
|
|
|
|
* "red" or "100px!important"
|
|
|
|
* propertiesToAdd: An array with additional properties, following the
|
2014-02-03 07:52:09 -08:00
|
|
|
* parseDeclarations format of {name,value,priority}
|
2014-01-16 18:40:54 -08:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_getValueAndExtraProperties: function(aValue) {
|
2014-01-16 18:40:54 -08:00
|
|
|
// The inplace editor will prevent manual typing of multiple properties,
|
|
|
|
// but we need to deal with the case during a paste event.
|
|
|
|
// Adding multiple properties inside of value editor sets value with the
|
|
|
|
// first, then adds any more onto the property list (below this property).
|
|
|
|
let firstValue = aValue;
|
2014-02-03 07:52:09 -08:00
|
|
|
let propertiesToAdd = [];
|
2014-01-16 18:40:54 -08:00
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
let properties = parseDeclarations(aValue);
|
2014-01-16 18:40:54 -08:00
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
// Check to see if the input string can be parsed as multiple properties
|
|
|
|
if (properties.length) {
|
|
|
|
// Get the first property value (if any), and any remaining properties (if any)
|
|
|
|
if (!properties[0].name && properties[0].value) {
|
|
|
|
firstValue = properties[0].value;
|
|
|
|
propertiesToAdd = properties.slice(1);
|
|
|
|
}
|
|
|
|
// In some cases, the value could be a property:value pair itself.
|
|
|
|
// Join them as one value string and append potentially following properties
|
|
|
|
else if (properties[0].name && properties[0].value) {
|
|
|
|
firstValue = properties[0].name + ": " + properties[0].value;
|
|
|
|
propertiesToAdd = properties.slice(1);
|
2013-09-12 09:18:29 -07:00
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
}
|
2014-01-16 18:40:54 -08:00
|
|
|
|
|
|
|
return {
|
|
|
|
propertiesToAdd: propertiesToAdd,
|
|
|
|
firstValue: firstValue
|
|
|
|
};
|
2011-11-01 18:06:48 -07:00
|
|
|
},
|
2012-02-25 07:30:51 -08:00
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
_applyNewValue: function(aValue) {
|
2014-02-03 07:52:09 -08:00
|
|
|
let val = parseSingleValue(aValue);
|
2013-11-15 18:46:59 -08:00
|
|
|
// Any property should be removed if has an empty value.
|
|
|
|
if (val.value.trim() === "") {
|
|
|
|
this.remove();
|
|
|
|
} else {
|
|
|
|
this.prop.setValue(val.value, val.priority);
|
|
|
|
this.removeOnRevert = false;
|
|
|
|
this.committed.value = this.prop.value;
|
|
|
|
this.committed.priority = this.prop.priority;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-25 07:30:51 -08:00
|
|
|
/**
|
2013-09-12 09:18:29 -07:00
|
|
|
* Live preview this property, without committing changes.
|
2012-02-25 07:30:51 -08:00
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} [aValue]
|
2013-09-12 09:18:29 -07:00
|
|
|
* The value to set the current property to.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
_livePreview: function(aValue) {
|
2013-09-12 09:18:29 -07:00
|
|
|
// Since function call is throttled, we need to make sure we are still editing
|
|
|
|
if (!this.editing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-03 07:52:09 -08:00
|
|
|
let val = parseSingleValue(aValue);
|
2013-09-12 09:18:29 -07:00
|
|
|
|
|
|
|
// Live previewing the change without committing just yet, that'll be done in _onValueDone
|
|
|
|
// If it was not a valid value, apply an empty string to reset the live preview
|
|
|
|
this.ruleEditor.rule.setPropertyValue(this.prop, val.value, val.priority);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate this property. Does it make sense for this value to be assigned
|
|
|
|
* to this property name? This does not apply the property value
|
|
|
|
*
|
|
|
|
* @param {string} [aValue]
|
|
|
|
* The property value used for validation.
|
|
|
|
* Defaults to the current value for this.prop
|
2012-10-01 07:38:04 -07:00
|
|
|
*
|
2012-11-16 11:55:00 -08:00
|
|
|
* @return {bool} true if the property value is valid, false otherwise.
|
2012-02-25 07:30:51 -08:00
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
isValid: function(aValue) {
|
2012-02-25 07:30:51 -08:00
|
|
|
let name = this.prop.name;
|
2012-10-01 07:38:04 -07:00
|
|
|
let value = typeof aValue == "undefined" ? this.prop.value : aValue;
|
2014-02-03 07:52:09 -08:00
|
|
|
let val = parseSingleValue(value);
|
2013-08-27 04:34:17 -07:00
|
|
|
|
2012-02-25 07:30:51 -08:00
|
|
|
let style = this.doc.createElementNS(HTML_NS, "div").style;
|
2012-10-01 07:38:04 -07:00
|
|
|
let prefs = Services.prefs;
|
2012-02-25 07:30:51 -08:00
|
|
|
|
2012-10-01 07:38:04 -07:00
|
|
|
// We toggle output of errors whilst the user is typing a property value.
|
2013-09-12 09:18:29 -07:00
|
|
|
let prefVal = prefs.getBoolPref("layout.css.report_errors");
|
2012-10-01 07:38:04 -07:00
|
|
|
prefs.setBoolPref("layout.css.report_errors", false);
|
2012-02-25 07:30:51 -08:00
|
|
|
|
2013-09-12 09:18:29 -07:00
|
|
|
let validValue = false;
|
2012-10-01 07:38:04 -07:00
|
|
|
try {
|
|
|
|
style.setProperty(name, val.value, val.priority);
|
2013-09-12 09:18:29 -07:00
|
|
|
validValue = style.getPropertyValue(name) !== "" || val.value === "";
|
2012-10-01 07:38:04 -07:00
|
|
|
} finally {
|
|
|
|
prefs.setBoolPref("layout.css.report_errors", prefVal);
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
return validValue;
|
|
|
|
}
|
2011-11-01 18:06:48 -07:00
|
|
|
};
|
|
|
|
|
2012-02-23 04:24:23 -08:00
|
|
|
/**
|
|
|
|
* Store of CSSStyleDeclarations mapped to properties that have been changed by
|
|
|
|
* the user.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function UserProperties() {
|
2013-08-30 01:06:59 -07:00
|
|
|
this.map = new Map();
|
2012-02-23 04:24:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
UserProperties.prototype = {
|
|
|
|
/**
|
|
|
|
* Get a named property for a given CSSStyleDeclaration.
|
|
|
|
*
|
|
|
|
* @param {CSSStyleDeclaration} aStyle
|
|
|
|
* The CSSStyleDeclaration against which the property is mapped.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @param {string} aName
|
2012-02-23 04:24:23 -08:00
|
|
|
* The name of the property to get.
|
2013-08-30 01:06:59 -07:00
|
|
|
* @param {string} aDefault
|
|
|
|
* The value to return if the property is has been changed outside of
|
|
|
|
* the rule view.
|
2012-11-16 11:55:00 -08:00
|
|
|
* @return {string}
|
2012-02-23 04:24:23 -08:00
|
|
|
* The property value if it has previously been set by the user, null
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2013-08-30 01:06:59 -07:00
|
|
|
getProperty: function(aStyle, aName, aDefault) {
|
|
|
|
let key = this.getKey(aStyle);
|
|
|
|
let entry = this.map.get(key, null);
|
2012-02-23 04:24:23 -08:00
|
|
|
|
|
|
|
if (entry && aName in entry) {
|
2012-05-30 19:49:10 -07:00
|
|
|
let item = entry[aName];
|
2014-01-14 00:32:45 -08:00
|
|
|
if (item != aDefault) {
|
|
|
|
delete entry[aName];
|
|
|
|
return aDefault;
|
|
|
|
}
|
|
|
|
return item;
|
2012-02-23 04:24:23 -08:00
|
|
|
}
|
2013-08-30 01:06:59 -07:00
|
|
|
return aDefault;
|
2012-02-23 04:24:23 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a named property for a given CSSStyleDeclaration.
|
|
|
|
*
|
|
|
|
* @param {CSSStyleDeclaration} aStyle
|
|
|
|
* The CSSStyleDeclaration against which the property is to be mapped.
|
|
|
|
* @param {String} aName
|
|
|
|
* The name of the property to set.
|
2012-05-30 19:49:10 -07:00
|
|
|
* @param {String} aUserValue
|
2012-02-23 04:24:23 -08:00
|
|
|
* The value of the property to set.
|
|
|
|
*/
|
2013-08-30 01:06:59 -07:00
|
|
|
setProperty: function(aStyle, aName, aUserValue) {
|
|
|
|
let key = this.getKey(aStyle);
|
|
|
|
let entry = this.map.get(key, null);
|
2012-02-23 04:24:23 -08:00
|
|
|
if (entry) {
|
2013-08-30 01:06:59 -07:00
|
|
|
entry[aName] = aUserValue;
|
2012-02-23 04:24:23 -08:00
|
|
|
} else {
|
|
|
|
let props = {};
|
2013-08-30 01:06:59 -07:00
|
|
|
props[aName] = aUserValue;
|
|
|
|
this.map.set(key, props);
|
2012-02-23 04:24:23 -08:00
|
|
|
}
|
|
|
|
},
|
2012-04-17 02:35:12 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a named property for a given CSSStyleDeclaration is stored.
|
|
|
|
*
|
|
|
|
* @param {CSSStyleDeclaration} aStyle
|
|
|
|
* The CSSStyleDeclaration against which the property would be mapped.
|
|
|
|
* @param {String} aName
|
|
|
|
* The name of the property to check.
|
|
|
|
*/
|
2013-08-30 01:06:59 -07:00
|
|
|
contains: function(aStyle, aName) {
|
|
|
|
let key = this.getKey(aStyle);
|
|
|
|
let entry = this.map.get(key, null);
|
2012-04-17 02:35:12 -07:00
|
|
|
return !!entry && aName in entry;
|
|
|
|
},
|
2013-08-30 01:06:59 -07:00
|
|
|
|
|
|
|
getKey: function(aStyle) {
|
|
|
|
return aStyle.href + ":" + aStyle.line;
|
2014-02-05 02:53:46 -08:00
|
|
|
}
|
2012-02-23 04:24:23 -08:00
|
|
|
};
|
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Helper functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a child element with a set of attributes.
|
|
|
|
*
|
|
|
|
* @param {Element} aParent
|
|
|
|
* The parent node.
|
|
|
|
* @param {string} aTag
|
|
|
|
* The tag name.
|
|
|
|
* @param {object} aAttributes
|
|
|
|
* A set of attributes to set on the node.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function createChild(aParent, aTag, aAttributes) {
|
2011-11-01 18:06:48 -07:00
|
|
|
let elt = aParent.ownerDocument.createElementNS(HTML_NS, aTag);
|
|
|
|
for (let attr in aAttributes) {
|
|
|
|
if (aAttributes.hasOwnProperty(attr)) {
|
|
|
|
if (attr === "textContent") {
|
|
|
|
elt.textContent = aAttributes[attr];
|
2013-10-18 07:01:20 -07:00
|
|
|
} else if(attr === "child") {
|
|
|
|
elt.appendChild(aAttributes[attr]);
|
2011-11-01 18:06:48 -07:00
|
|
|
} else {
|
|
|
|
elt.setAttribute(attr, aAttributes[attr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aParent.appendChild(elt);
|
|
|
|
return elt;
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
function createMenuItem(aMenu, aAttributes) {
|
2012-04-04 09:36:35 -07:00
|
|
|
let item = aMenu.ownerDocument.createElementNS(XUL_NS, "menuitem");
|
2013-09-19 17:15:34 -07:00
|
|
|
|
2012-04-04 09:36:35 -07:00
|
|
|
item.setAttribute("label", _strings.GetStringFromName(aAttributes.label));
|
|
|
|
item.setAttribute("accesskey", _strings.GetStringFromName(aAttributes.accesskey));
|
|
|
|
item.addEventListener("command", aAttributes.command);
|
|
|
|
|
|
|
|
aMenu.appendChild(item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
function setTimeout() {
|
2014-01-16 18:40:54 -08:00
|
|
|
let window = Services.appShell.hiddenDOMWindow;
|
|
|
|
return window.setTimeout.apply(window, arguments);
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
function clearTimeout() {
|
2014-01-16 18:40:54 -08:00
|
|
|
let window = Services.appShell.hiddenDOMWindow;
|
|
|
|
return window.clearTimeout.apply(window, arguments);
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:53:46 -08:00
|
|
|
function throttle(func, wait, scope) {
|
2013-09-12 09:18:29 -07:00
|
|
|
var timer = null;
|
|
|
|
return function() {
|
|
|
|
if(timer) {
|
2014-01-16 18:40:54 -08:00
|
|
|
clearTimeout(timer);
|
2013-09-12 09:18:29 -07:00
|
|
|
}
|
|
|
|
var args = arguments;
|
2014-01-16 18:40:54 -08:00
|
|
|
timer = setTimeout(function() {
|
2013-09-12 09:18:29 -07:00
|
|
|
timer = null;
|
|
|
|
func.apply(scope, args);
|
|
|
|
}, wait);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-01-16 18:40:54 -08:00
|
|
|
/**
|
|
|
|
* Event handler that causes a blur on the target if the input has
|
|
|
|
* multiple CSS properties as the value.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function blurOnMultipleProperties(e) {
|
2014-01-16 18:40:54 -08:00
|
|
|
setTimeout(() => {
|
2014-02-03 07:52:09 -08:00
|
|
|
let props = parseDeclarations(e.target.value);
|
|
|
|
if (props.length > 1) {
|
2014-01-16 18:40:54 -08:00
|
|
|
e.target.blur();
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
2013-09-12 09:18:29 -07:00
|
|
|
|
2011-11-01 18:06:48 -07:00
|
|
|
/**
|
|
|
|
* Append a text node to an element.
|
|
|
|
*/
|
2014-02-05 02:53:46 -08:00
|
|
|
function appendText(aParent, aText) {
|
2011-11-01 18:06:48 -07:00
|
|
|
aParent.appendChild(aParent.ownerDocument.createTextNode(aText));
|
|
|
|
}
|
|
|
|
|
2012-04-04 09:36:35 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "clipboardHelper", function() {
|
|
|
|
return Cc["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Ci.nsIClipboardHelper);
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "_strings", function() {
|
|
|
|
return Services.strings.createBundle(
|
2013-11-19 06:15:46 -08:00
|
|
|
"chrome://global/locale/devtools/styleinspector.properties");
|
2012-04-04 09:36:35 -07:00
|
|
|
});
|
|
|
|
|
2013-02-04 08:29:30 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "domUtils", function() {
|
|
|
|
return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
|
|
|
|
});
|
2013-07-25 16:05:05 -07:00
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
loader.lazyGetter(this, "AutocompletePopup", () => require("devtools/shared/autocomplete-popup").AutocompletePopup);
|