2013-08-01 01:53:31 -07:00
|
|
|
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-08-30 05:12:02 -07:00
|
|
|
/* 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-08-30 05:12:02 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
const {Cc, Ci, Cu} = require("chrome");
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
let ToolDefinitions = require("main").Tools;
|
|
|
|
let {CssLogic} = require("devtools/styleinspector/css-logic");
|
2013-08-08 08:44:57 -07:00
|
|
|
let {ELEMENT_STYLE} = require("devtools/server/actors/styles");
|
|
|
|
let promise = require("sdk/core/promise");
|
|
|
|
let {EventEmitter} = require("devtools/shared/event-emitter");
|
2013-09-16 03:01:25 -07:00
|
|
|
let {colorUtils} = require("devtools/shared/css-color");
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/PluralForm.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-05-09 07:15:22 -07:00
|
|
|
Cu.import("resource://gre/modules/devtools/Templater.jsm");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-09-16 03:01:25 -07:00
|
|
|
let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
2013-04-11 13:59:08 -07:00
|
|
|
|
|
|
|
const FILTER_CHANGED_TIMEOUT = 300;
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-11-07 10:35:40 -08:00
|
|
|
/**
|
|
|
|
* Helper for long-running processes that should yield occasionally to
|
|
|
|
* the mainloop.
|
|
|
|
*
|
|
|
|
* @param {Window} aWin
|
|
|
|
* Timeouts will be set on this window when appropriate.
|
|
|
|
* @param {Generator} aGenerator
|
|
|
|
* Will iterate this generator.
|
|
|
|
* @param {object} aOptions
|
|
|
|
* Options for the update process:
|
|
|
|
* onItem {function} Will be called with the value of each iteration.
|
|
|
|
* onBatch {function} Will be called after each batch of iterations,
|
|
|
|
* before yielding to the main loop.
|
|
|
|
* onDone {function} Will be called when iteration is complete.
|
|
|
|
* onCancel {function} Will be called if the process is canceled.
|
|
|
|
* threshold {int} How long to process before yielding, in ms.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function UpdateProcess(aWin, aGenerator, aOptions)
|
|
|
|
{
|
|
|
|
this.win = aWin;
|
2013-05-01 09:27:24 -07:00
|
|
|
this.iter = _Iterator(aGenerator);
|
2011-11-07 10:35:40 -08:00
|
|
|
this.onItem = aOptions.onItem || function() {};
|
|
|
|
this.onBatch = aOptions.onBatch || function () {};
|
|
|
|
this.onDone = aOptions.onDone || function() {};
|
|
|
|
this.onCancel = aOptions.onCancel || function() {};
|
|
|
|
this.threshold = aOptions.threshold || 45;
|
|
|
|
|
|
|
|
this.canceled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateProcess.prototype = {
|
|
|
|
/**
|
|
|
|
* Schedule a new batch on the main loop.
|
|
|
|
*/
|
|
|
|
schedule: function UP_schedule()
|
|
|
|
{
|
2013-01-04 03:54:54 -08:00
|
|
|
if (this.canceled) {
|
2011-11-07 10:35:40 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._timeout = this.win.setTimeout(this._timeoutHandler.bind(this), 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel the running process. onItem will not be called again,
|
|
|
|
* and onCancel will be called.
|
|
|
|
*/
|
|
|
|
cancel: function UP_cancel()
|
|
|
|
{
|
|
|
|
if (this._timeout) {
|
|
|
|
this.win.clearTimeout(this._timeout);
|
|
|
|
this._timeout = 0;
|
|
|
|
}
|
|
|
|
this.canceled = true;
|
|
|
|
this.onCancel();
|
|
|
|
},
|
|
|
|
|
|
|
|
_timeoutHandler: function UP_timeoutHandler() {
|
|
|
|
this._timeout = null;
|
|
|
|
try {
|
|
|
|
this._runBatch();
|
|
|
|
this.schedule();
|
|
|
|
} catch(e) {
|
|
|
|
if (e instanceof StopIteration) {
|
|
|
|
this.onBatch();
|
|
|
|
this.onDone();
|
|
|
|
return;
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
console.error(e);
|
2011-11-07 10:35:40 -08:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_runBatch: function Y_runBatch()
|
|
|
|
{
|
|
|
|
let time = Date.now();
|
2013-01-04 03:54:54 -08:00
|
|
|
while(!this.canceled) {
|
2011-11-07 10:35:40 -08:00
|
|
|
// Continue until iter.next() throws...
|
|
|
|
let next = this.iter.next();
|
|
|
|
this.onItem(next[1]);
|
|
|
|
if ((Date.now() - time) > this.threshold) {
|
|
|
|
this.onBatch();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
/**
|
|
|
|
* CssHtmlTree is a panel that manages the display of a table sorted by style.
|
|
|
|
* There should be one instance of CssHtmlTree per style display (of which there
|
|
|
|
* will generally only be one).
|
|
|
|
*
|
2011-10-21 10:40:22 -07:00
|
|
|
* @params {StyleInspector} aStyleInspector The owner of this CssHtmlTree
|
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-08-30 05:12:02 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2013-08-08 08:44:57 -07:00
|
|
|
function CssHtmlTree(aStyleInspector, aPageStyle)
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
this.styleWindow = aStyleInspector.window;
|
|
|
|
this.styleDocument = aStyleInspector.window.document;
|
2011-10-21 10:40:22 -07:00
|
|
|
this.styleInspector = aStyleInspector;
|
2013-08-08 08:44:57 -07:00
|
|
|
this.pageStyle = aPageStyle;
|
2011-10-19 03:25:39 -07:00
|
|
|
this.propertyViews = [];
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry);
|
|
|
|
this.getRTLAttr = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr";
|
|
|
|
|
2012-03-11 07:01:38 -07:00
|
|
|
// Create bound methods.
|
2012-12-18 06:27:04 -08:00
|
|
|
this.siFocusWindow = this.focusWindow.bind(this);
|
2012-03-11 07:01:38 -07:00
|
|
|
this.siBoundCopy = this.computedViewCopy.bind(this);
|
|
|
|
|
|
|
|
this.styleDocument.addEventListener("copy", this.siBoundCopy);
|
2012-12-18 06:27:04 -08:00
|
|
|
this.styleDocument.addEventListener("mousedown", this.siFocusWindow);
|
2012-03-11 07:01:38 -07:00
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
// Nodes used in templating
|
|
|
|
this.root = this.styleDocument.getElementById("root");
|
|
|
|
this.templateRoot = this.styleDocument.getElementById("templateRoot");
|
2011-08-30 09:40:29 -07:00
|
|
|
this.propertyContainer = this.styleDocument.getElementById("propertyContainer");
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-11-06 02:36:38 -08:00
|
|
|
// No results text.
|
|
|
|
this.noResults = this.styleDocument.getElementById("noResults");
|
|
|
|
|
2013-09-16 03:01:25 -07:00
|
|
|
// Refresh panel when color unit changed.
|
|
|
|
this._handlePrefChange = this._handlePrefChange.bind(this);
|
|
|
|
gDevTools.on("pref-changed", this._handlePrefChange);
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
CssHtmlTree.processTemplate(this.templateRoot, this.root, this);
|
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
// The element that we're inspecting, and the document that it comes from.
|
|
|
|
this.viewedElement = null;
|
2011-08-30 09:40:29 -07:00
|
|
|
this.createStyleViews();
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-21 10:40:22 -07:00
|
|
|
* Memoized lookup of a l10n string from a string bundle.
|
2011-08-30 05:12:02 -07:00
|
|
|
* @param {string} aName The key to lookup.
|
|
|
|
* @returns A localized version of the given key.
|
|
|
|
*/
|
|
|
|
CssHtmlTree.l10n = function CssHtmlTree_l10n(aName)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return CssHtmlTree._strings.GetStringFromName(aName);
|
|
|
|
} catch (ex) {
|
|
|
|
Services.console.logStringMessage("Error reading '" + aName + "'");
|
|
|
|
throw new Error("l10n error with " + aName);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone the given template node, and process it by resolving ${} references
|
|
|
|
* in the template.
|
|
|
|
*
|
|
|
|
* @param {nsIDOMElement} aTemplate the template note to use.
|
|
|
|
* @param {nsIDOMElement} aDestination the destination node where the
|
|
|
|
* processed nodes will be displayed.
|
|
|
|
* @param {object} aData the data to pass to the template.
|
2011-08-30 09:40:29 -07:00
|
|
|
* @param {Boolean} aPreserveDestination If true then the template will be
|
|
|
|
* appended to aDestination's content else aDestination.innerHTML will be
|
|
|
|
* cleared before the template is appended.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2011-08-30 09:40:29 -07:00
|
|
|
CssHtmlTree.processTemplate = function CssHtmlTree_processTemplate(aTemplate,
|
|
|
|
aDestination, aData, aPreserveDestination)
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2011-08-30 09:40:29 -07:00
|
|
|
if (!aPreserveDestination) {
|
|
|
|
aDestination.innerHTML = "";
|
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
|
|
|
// All the templater does is to populate a given DOM tree with the given
|
|
|
|
// values, so we need to clone the template first.
|
|
|
|
let duplicated = aTemplate.cloneNode(true);
|
2011-12-08 04:39:04 -08:00
|
|
|
|
|
|
|
// See https://github.com/mozilla/domtemplate/blob/master/README.md
|
|
|
|
// for docs on the template() function
|
|
|
|
template(duplicated, aData, { allowEval: true });
|
2011-08-30 05:12:02 -07:00
|
|
|
while (duplicated.firstChild) {
|
|
|
|
aDestination.appendChild(duplicated.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(CssHtmlTree, "_strings", function() Services.strings
|
2011-10-27 08:35:13 -07:00
|
|
|
.createBundle("chrome://browser/locale/devtools/styleinspector.properties"));
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-03-11 07:01:38 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "clipboardHelper", function() {
|
|
|
|
return Cc["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Ci.nsIClipboardHelper);
|
|
|
|
});
|
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
CssHtmlTree.prototype = {
|
2013-01-29 09:05:17 -08:00
|
|
|
// Cache the list of properties that match the selected element.
|
2011-11-02 10:50:15 -07:00
|
|
|
_matchedProperties: null,
|
|
|
|
|
2011-09-20 02:59:13 -07:00
|
|
|
// Used for cancelling timeouts in the style filter.
|
2011-11-02 10:50:15 -07:00
|
|
|
_filterChangedTimeout: null,
|
2011-09-20 02:59:13 -07:00
|
|
|
|
|
|
|
// The search filter
|
|
|
|
searchField: null,
|
2011-11-04 10:12:58 -07:00
|
|
|
|
2013-02-05 08:45:01 -08:00
|
|
|
// Reference to the "Include browser styles" checkbox.
|
|
|
|
includeBrowserStylesCheckbox: null,
|
2011-09-20 02:35:01 -07:00
|
|
|
|
2011-10-19 03:25:39 -07:00
|
|
|
// Holds the ID of the panelRefresh timeout.
|
|
|
|
_panelRefreshTimeout: null,
|
|
|
|
|
2011-11-04 10:12:58 -07:00
|
|
|
// Toggle for zebra striping
|
|
|
|
_darkStripe: true,
|
|
|
|
|
2011-11-06 02:36:38 -08:00
|
|
|
// Number of visible properties
|
|
|
|
numVisibleProperties: 0,
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
setPageStyle: function(pageStyle) {
|
|
|
|
this.pageStyle = pageStyle;
|
|
|
|
},
|
|
|
|
|
2013-02-05 08:45:01 -08:00
|
|
|
get includeBrowserStyles()
|
2011-09-20 02:35:01 -07:00
|
|
|
{
|
2013-02-05 08:45:01 -08:00
|
|
|
return this.includeBrowserStylesCheckbox.checked;
|
2011-09-20 02:35:01 -07:00
|
|
|
},
|
2011-09-15 03:30:00 -07:00
|
|
|
|
2013-09-16 03:01:25 -07:00
|
|
|
_handlePrefChange: function(event, data) {
|
|
|
|
if (data.pref == "devtools.defaultColorUnit" && this._computed) {
|
|
|
|
this.refreshPanel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
/**
|
2011-09-15 03:30:00 -07:00
|
|
|
* Update the highlighted element. The CssHtmlTree panel will show the style
|
|
|
|
* information for the given element.
|
2011-08-30 05:12:02 -07:00
|
|
|
* @param {nsIDOMElement} aElement The highlighted node to get styles for.
|
2013-08-08 08:44:57 -07:00
|
|
|
*
|
|
|
|
* @returns a promise that will be resolved when highlighting is complete.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2013-08-08 08:44:57 -07:00
|
|
|
highlight: function(aElement) {
|
2013-01-04 03:54:54 -08:00
|
|
|
if (!aElement) {
|
|
|
|
if (this._refreshProcess) {
|
|
|
|
this._refreshProcess.cancel();
|
|
|
|
}
|
2013-09-16 03:01:25 -07:00
|
|
|
return promise.resolve(undefined);
|
2013-01-04 03:54:54 -08:00
|
|
|
}
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
if (aElement === this.viewedElement) {
|
|
|
|
return promise.resolve(undefined);
|
|
|
|
}
|
2011-09-20 02:35:01 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.viewedElement = aElement;
|
2012-04-19 11:04:46 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.refreshSourceFilter();
|
|
|
|
return this.refreshPanel();
|
|
|
|
},
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
_createPropertyViews: function()
|
|
|
|
{
|
|
|
|
if (this._createViewsPromise) {
|
|
|
|
return this._createViewsPromise;
|
2011-09-15 03:30:00 -07:00
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
let deferred = promise.defer();
|
|
|
|
this._createViewsPromise = deferred.promise;
|
|
|
|
|
|
|
|
this.refreshSourceFilter();
|
|
|
|
this.numVisibleProperties = 0;
|
|
|
|
let fragment = this.styleDocument.createDocumentFragment();
|
|
|
|
|
|
|
|
this._createViewsProcess = new UpdateProcess(this.styleWindow, CssHtmlTree.propertyNames, {
|
|
|
|
onItem: (aPropertyName) => {
|
|
|
|
// Per-item callback.
|
|
|
|
let propView = new PropertyView(this, aPropertyName);
|
|
|
|
fragment.appendChild(propView.buildMain());
|
|
|
|
fragment.appendChild(propView.buildSelectorContainer());
|
|
|
|
|
|
|
|
if (propView.visible) {
|
|
|
|
this.numVisibleProperties++;
|
|
|
|
}
|
|
|
|
this.propertyViews.push(propView);
|
|
|
|
},
|
|
|
|
onCancel: () => {
|
|
|
|
deferred.reject("_createPropertyViews cancelled");
|
|
|
|
},
|
|
|
|
onDone: () => {
|
|
|
|
// Completed callback.
|
|
|
|
this.propertyContainer.appendChild(fragment);
|
|
|
|
this.noResults.hidden = this.numVisibleProperties > 0;
|
|
|
|
deferred.resolve(undefined);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this._createViewsProcess.schedule();
|
|
|
|
return deferred.promise;
|
2011-09-15 03:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the panel content.
|
|
|
|
*/
|
|
|
|
refreshPanel: function CssHtmlTree_refreshPanel()
|
|
|
|
{
|
2013-08-08 08:44:57 -07:00
|
|
|
return promise.all([
|
|
|
|
this._createPropertyViews(),
|
|
|
|
this.pageStyle.getComputed(this.viewedElement, {
|
|
|
|
filter: this._sourceFilter,
|
|
|
|
onlyMatched: !this.includeBrowserStyles,
|
|
|
|
markMatched: true
|
|
|
|
})
|
|
|
|
]).then(([createViews, computed]) => {
|
|
|
|
this._matchedProperties = new Set;
|
|
|
|
for (let name in computed) {
|
|
|
|
if (computed[name].matched) {
|
|
|
|
this._matchedProperties.add(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._computed = computed;
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
if (this._refreshProcess) {
|
2013-08-08 08:44:57 -07:00
|
|
|
this._refreshProcess.cancel();
|
2012-04-19 11:04:46 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.noResults.hidden = true;
|
2011-10-19 03:25:39 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// Reset visible property count
|
|
|
|
this.numVisibleProperties = 0;
|
2011-11-06 02:36:38 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
// Reset zebra striping.
|
|
|
|
this._darkStripe = true;
|
2011-11-06 02:36:38 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
let display = this.propertyContainer.style.display;
|
2011-11-04 10:12:58 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
let deferred = promise.defer();
|
|
|
|
this._refreshProcess = new UpdateProcess(this.styleWindow, this.propertyViews, {
|
|
|
|
onItem: (aPropView) => {
|
|
|
|
aPropView.refresh();
|
|
|
|
},
|
|
|
|
onCancel: () => {
|
|
|
|
deferred.reject("refresh cancelled");
|
|
|
|
},
|
|
|
|
onDone: () => {
|
|
|
|
this._refreshProcess = null;
|
|
|
|
this.noResults.hidden = this.numVisibleProperties > 0;
|
|
|
|
this.styleInspector.inspector.emit("computed-view-refreshed");
|
|
|
|
deferred.resolve(undefined);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._refreshProcess.schedule();
|
|
|
|
return deferred.promise;
|
|
|
|
}).then(null, (err) => console.error(err));
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
|
|
|
|
2011-09-20 02:59:13 -07:00
|
|
|
/**
|
|
|
|
* Called when the user enters a search term.
|
|
|
|
*
|
|
|
|
* @param {Event} aEvent the DOM Event object.
|
|
|
|
*/
|
|
|
|
filterChanged: function CssHtmlTree_filterChanged(aEvent)
|
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
let win = this.styleWindow;
|
2011-11-02 10:50:15 -07:00
|
|
|
|
|
|
|
if (this._filterChangedTimeout) {
|
|
|
|
win.clearTimeout(this._filterChangedTimeout);
|
2011-09-20 02:59:13 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 10:50:15 -07:00
|
|
|
this._filterChangedTimeout = win.setTimeout(function() {
|
2011-09-20 02:59:13 -07:00
|
|
|
this.refreshPanel();
|
2011-11-02 10:50:15 -07:00
|
|
|
this._filterChangeTimeout = null;
|
2011-09-20 02:59:13 -07:00
|
|
|
}.bind(this), FILTER_CHANGED_TIMEOUT);
|
|
|
|
},
|
|
|
|
|
2011-09-20 02:35:01 -07:00
|
|
|
/**
|
2013-02-05 08:45:01 -08:00
|
|
|
* The change event handler for the includeBrowserStyles checkbox.
|
2011-09-20 02:35:01 -07:00
|
|
|
*
|
|
|
|
* @param {Event} aEvent the DOM Event object.
|
|
|
|
*/
|
2013-02-05 08:45:01 -08:00
|
|
|
includeBrowserStylesChanged:
|
|
|
|
function CssHtmltree_includeBrowserStylesChanged(aEvent)
|
2012-02-13 03:26:33 -08:00
|
|
|
{
|
|
|
|
this.refreshSourceFilter();
|
|
|
|
this.refreshPanel();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-05 08:45:01 -08:00
|
|
|
* When includeBrowserStyles.checked is false we only display properties that
|
|
|
|
* have matched selectors and have been included by the document or one of the
|
2012-02-13 03:26:33 -08:00
|
|
|
* document's stylesheets. If .checked is false we display all properties
|
|
|
|
* including those that come from UA stylesheets.
|
|
|
|
*/
|
|
|
|
refreshSourceFilter: function CssHtmlTree_setSourceFilter()
|
2011-09-20 02:35:01 -07:00
|
|
|
{
|
2011-11-02 10:50:15 -07:00
|
|
|
this._matchedProperties = null;
|
2013-08-08 08:44:57 -07:00
|
|
|
this._sourceFilter = this.includeBrowserStyles ?
|
2013-02-05 08:45:01 -08:00
|
|
|
CssLogic.FILTER.UA :
|
2013-08-07 09:27:22 -07:00
|
|
|
CssLogic.FILTER.USER;
|
2011-09-20 02:35:01 -07:00
|
|
|
},
|
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
/**
|
2011-08-30 09:40:29 -07:00
|
|
|
* The CSS as displayed by the UI.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2011-08-30 09:40:29 -07:00
|
|
|
createStyleViews: function CssHtmlTree_createStyleViews()
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2011-08-30 09:40:29 -07:00
|
|
|
if (CssHtmlTree.propertyNames) {
|
2011-08-30 05:12:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-30 09:40:29 -07:00
|
|
|
CssHtmlTree.propertyNames = [];
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-08-30 09:40:29 -07:00
|
|
|
// Here we build and cache a list of css properties supported by the browser
|
2011-11-05 12:31:00 -07:00
|
|
|
// We could use any element but let's use the main document's root element
|
2012-11-30 00:07:59 -08:00
|
|
|
let styles = this.styleWindow.getComputedStyle(this.styleDocument.documentElement);
|
2011-08-30 09:40:29 -07:00
|
|
|
let mozProps = [];
|
|
|
|
for (let i = 0, numStyles = styles.length; i < numStyles; i++) {
|
|
|
|
let prop = styles.item(i);
|
|
|
|
if (prop.charAt(0) == "-") {
|
|
|
|
mozProps.push(prop);
|
2011-08-30 05:12:02 -07:00
|
|
|
} else {
|
2011-08-30 09:40:29 -07:00
|
|
|
CssHtmlTree.propertyNames.push(prop);
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 09:40:29 -07:00
|
|
|
CssHtmlTree.propertyNames.sort();
|
|
|
|
CssHtmlTree.propertyNames.push.apply(CssHtmlTree.propertyNames,
|
|
|
|
mozProps.sort());
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
this._createPropertyViews();
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
2011-10-07 08:38:35 -07:00
|
|
|
|
2011-11-02 10:50:15 -07:00
|
|
|
/**
|
2013-08-08 08:44:57 -07:00
|
|
|
* Get a set of properties that have matched selectors.
|
2011-11-02 10:50:15 -07:00
|
|
|
*
|
2013-08-08 08:44:57 -07:00
|
|
|
* @return {Set} If a property name is in the set, it has matching selectors.
|
2011-11-02 10:50:15 -07:00
|
|
|
*/
|
|
|
|
get matchedProperties()
|
|
|
|
{
|
2013-08-08 08:44:57 -07:00
|
|
|
return this._matchedProperties || new Set;
|
2011-11-02 10:50:15 -07:00
|
|
|
},
|
|
|
|
|
2012-12-18 06:27:04 -08:00
|
|
|
/**
|
|
|
|
* Focus the window on mousedown.
|
|
|
|
*
|
|
|
|
* @param aEvent The event object
|
|
|
|
*/
|
|
|
|
focusWindow: function si_focusWindow(aEvent)
|
|
|
|
{
|
|
|
|
let win = this.styleDocument.defaultView;
|
|
|
|
win.focus();
|
|
|
|
},
|
|
|
|
|
2012-03-11 07:01:38 -07:00
|
|
|
/**
|
|
|
|
* Copy selected text.
|
|
|
|
*
|
|
|
|
* @param aEvent The event object
|
|
|
|
*/
|
|
|
|
computedViewCopy: function si_computedViewCopy(aEvent)
|
|
|
|
{
|
|
|
|
let win = this.styleDocument.defaultView;
|
|
|
|
let text = win.getSelection().toString();
|
|
|
|
|
|
|
|
// Tidy up block headings by moving CSS property names and their values onto
|
|
|
|
// the same line and inserting a colon between them.
|
2013-03-27 15:20:38 -07:00
|
|
|
text = text.replace(/(.+)\r\n(.+)/g, "$1: $2;");
|
|
|
|
text = text.replace(/(.+)\n(.+)/g, "$1: $2;");
|
2012-03-11 07:01:38 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
let outerDoc = this.styleInspector.outerIFrame.ownerDocument;
|
|
|
|
clipboardHelper.copyString(text, outerDoc);
|
2012-03-11 07:01:38 -07:00
|
|
|
|
|
|
|
if (aEvent) {
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-07 08:38:35 -07:00
|
|
|
/**
|
|
|
|
* Destructor for CssHtmlTree.
|
|
|
|
*/
|
|
|
|
destroy: function CssHtmlTree_destroy()
|
|
|
|
{
|
|
|
|
delete this.viewedElement;
|
|
|
|
|
2011-11-04 10:12:58 -07:00
|
|
|
// Remove event listeners
|
2013-02-05 08:45:01 -08:00
|
|
|
this.includeBrowserStylesCheckbox.removeEventListener("command",
|
|
|
|
this.includeBrowserStylesChanged);
|
2011-11-04 10:12:58 -07:00
|
|
|
this.searchField.removeEventListener("command", this.filterChanged);
|
2013-09-16 03:01:25 -07:00
|
|
|
gDevTools.off("pref-changed", this._handlePrefChange);
|
2011-11-04 10:12:58 -07:00
|
|
|
|
2011-11-16 01:51:05 -08:00
|
|
|
// Cancel tree construction
|
2013-08-08 08:44:57 -07:00
|
|
|
if (this._createViewsProcess) {
|
|
|
|
this._createViewsProcess.cancel();
|
|
|
|
}
|
2011-11-16 01:51:05 -08:00
|
|
|
if (this._refreshProcess) {
|
|
|
|
this._refreshProcess.cancel();
|
|
|
|
}
|
|
|
|
|
2012-03-11 07:01:38 -07:00
|
|
|
// Remove context menu
|
2012-11-30 00:07:59 -08:00
|
|
|
let outerDoc = this.styleInspector.outerIFrame.ownerDocument;
|
|
|
|
let menu = outerDoc.querySelector("#computed-view-context-menu");
|
2012-03-11 07:01:38 -07:00
|
|
|
if (menu) {
|
|
|
|
// Copy selected
|
2012-11-30 00:07:59 -08:00
|
|
|
let menuitem = outerDoc.querySelector("#computed-view-copy");
|
2012-03-11 07:01:38 -07:00
|
|
|
menuitem.removeEventListener("command", this.siBoundCopy);
|
|
|
|
|
|
|
|
// Copy property
|
2012-11-30 00:07:59 -08:00
|
|
|
menuitem = outerDoc.querySelector("#computed-view-copy-declaration");
|
2012-03-11 07:01:38 -07:00
|
|
|
menuitem.removeEventListener("command", this.siBoundCopyDeclaration);
|
|
|
|
|
|
|
|
// Copy property name
|
2012-11-30 00:07:59 -08:00
|
|
|
menuitem = outerDoc.querySelector("#computed-view-copy-property");
|
2012-03-11 07:01:38 -07:00
|
|
|
menuitem.removeEventListener("command", this.siBoundCopyProperty);
|
|
|
|
|
|
|
|
// Copy property value
|
2012-11-30 00:07:59 -08:00
|
|
|
menuitem = outerDoc.querySelector("#computed-view-copy-property-value");
|
2012-03-11 07:01:38 -07:00
|
|
|
menuitem.removeEventListener("command", this.siBoundCopyPropertyValue);
|
|
|
|
|
|
|
|
menu.removeEventListener("popupshowing", this.siBoundMenuUpdate);
|
|
|
|
menu.parentNode.removeChild(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove bound listeners
|
|
|
|
this.styleDocument.removeEventListener("copy", this.siBoundCopy);
|
2012-12-18 06:27:04 -08:00
|
|
|
this.styleDocument.removeEventListener("mousedown", this.siFocusWindow);
|
2012-03-11 07:01:38 -07:00
|
|
|
|
2011-10-07 08:38:35 -07:00
|
|
|
// Nodes used in templating
|
|
|
|
delete this.root;
|
|
|
|
delete this.propertyContainer;
|
|
|
|
delete this.panel;
|
|
|
|
|
2011-11-05 12:31:00 -07:00
|
|
|
// The document in which we display the results (csshtmltree.xul).
|
2011-10-07 08:38:35 -07:00
|
|
|
delete this.styleDocument;
|
|
|
|
|
|
|
|
// The element that we're inspecting, and the document that it comes from.
|
|
|
|
delete this.propertyViews;
|
2012-11-30 00:07:59 -08:00
|
|
|
delete this.styleWindow;
|
|
|
|
delete this.styleDocument;
|
2011-10-21 10:40:22 -07:00
|
|
|
delete this.styleInspector;
|
2011-10-07 08:38:35 -07:00
|
|
|
},
|
2011-08-30 05:12:02 -07:00
|
|
|
};
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
function PropertyInfo(aTree, aName) {
|
|
|
|
this.tree = aTree;
|
|
|
|
this.name = aName;
|
|
|
|
}
|
|
|
|
PropertyInfo.prototype = {
|
2013-09-16 03:01:25 -07:00
|
|
|
get value() {
|
|
|
|
if (this.tree._computed) {
|
|
|
|
let value = this.tree._computed[this.name].value;
|
|
|
|
return colorUtils.processCSSString(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-08-08 08:44:57 -07:00
|
|
|
|
2011-08-30 05:12:02 -07:00
|
|
|
/**
|
|
|
|
* A container to give easy access to property data from the template engine.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {CssHtmlTree} aTree the CssHtmlTree instance we are working with.
|
|
|
|
* @param {string} aName the CSS property name for which this PropertyView
|
|
|
|
* instance will render the rules.
|
|
|
|
*/
|
2013-04-11 13:59:08 -07:00
|
|
|
function PropertyView(aTree, aName)
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
|
|
|
this.tree = aTree;
|
|
|
|
this.name = aName;
|
2011-10-21 10:40:22 -07:00
|
|
|
this.getRTLAttr = aTree.getRTLAttr;
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-12-13 02:26:42 -08:00
|
|
|
this.link = "https://developer.mozilla.org/CSS/" + aName;
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
this.templateMatchedSelectors = aTree.styleDocument.getElementById("templateMatchedSelectors");
|
2013-08-08 08:44:57 -07:00
|
|
|
this._propertyInfo = new PropertyInfo(aTree, aName);
|
2011-09-15 03:30:00 -07:00
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
PropertyView.prototype = {
|
2011-08-30 05:12:02 -07:00
|
|
|
// The parent element which contains the open attribute
|
2011-09-15 03:30:00 -07:00
|
|
|
element: null,
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-11-04 10:12:58 -07:00
|
|
|
// Property header node
|
|
|
|
propertyHeader: null,
|
|
|
|
|
2011-12-19 05:57:42 -08:00
|
|
|
// Destination for property names
|
|
|
|
nameNode: null,
|
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
// Destination for property values
|
|
|
|
valueNode: null,
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
// Are matched rules expanded?
|
|
|
|
matchedExpanded: false,
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
// Matched selector container
|
|
|
|
matchedSelectorsContainer: null,
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
// Matched selector expando
|
|
|
|
matchedExpander: null,
|
|
|
|
|
|
|
|
// Cache for matched selector views
|
|
|
|
_matchedSelectorViews: null,
|
|
|
|
|
|
|
|
// The previously selected element used for the selector view caches
|
|
|
|
prevViewedElement: null,
|
2011-08-30 05:12:02 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the computed style for the current property.
|
|
|
|
*
|
|
|
|
* @return {string} the computed style for the current property of the
|
|
|
|
* currently highlighted element.
|
|
|
|
*/
|
|
|
|
get value()
|
|
|
|
{
|
|
|
|
return this.propertyInfo.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-09-15 03:30:00 -07:00
|
|
|
* An easy way to access the CssPropertyInfo behind this PropertyView.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
|
|
|
get propertyInfo()
|
|
|
|
{
|
2013-08-08 08:44:57 -07:00
|
|
|
return this._propertyInfo;
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
|
|
|
|
2011-10-13 02:28:52 -07:00
|
|
|
/**
|
|
|
|
* Does the property have any matched selectors?
|
|
|
|
*/
|
|
|
|
get hasMatchedSelectors()
|
|
|
|
{
|
2013-08-08 08:44:57 -07:00
|
|
|
return this.tree.matchedProperties.has(this.name);
|
2011-10-13 02:28:52 -07:00
|
|
|
},
|
|
|
|
|
2011-09-20 02:35:01 -07:00
|
|
|
/**
|
|
|
|
* Should this property be visible?
|
|
|
|
*/
|
|
|
|
get visible()
|
|
|
|
{
|
2013-02-05 08:45:01 -08:00
|
|
|
if (!this.tree.includeBrowserStyles && !this.hasMatchedSelectors) {
|
2011-09-20 02:35:01 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-20 02:59:13 -07:00
|
|
|
let searchTerm = this.tree.searchField.value.toLowerCase();
|
|
|
|
if (searchTerm && this.name.toLowerCase().indexOf(searchTerm) == -1 &&
|
|
|
|
this.value.toLowerCase().indexOf(searchTerm) == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-20 02:35:01 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the className that should be assigned to the propertyView.
|
2011-11-04 10:12:58 -07:00
|
|
|
*
|
|
|
|
* @return string
|
2011-09-20 02:35:01 -07:00
|
|
|
*/
|
2011-12-19 05:16:43 -08:00
|
|
|
get propertyHeaderClassName()
|
2011-09-20 02:35:01 -07:00
|
|
|
{
|
2011-11-04 10:12:58 -07:00
|
|
|
if (this.visible) {
|
|
|
|
this.tree._darkStripe = !this.tree._darkStripe;
|
|
|
|
let darkValue = this.tree._darkStripe ?
|
2013-03-27 15:20:38 -07:00
|
|
|
"property-view theme-bg-darker" : "property-view";
|
2011-11-04 10:12:58 -07:00
|
|
|
return darkValue;
|
|
|
|
}
|
|
|
|
return "property-view-hidden";
|
2011-09-20 02:35:01 -07:00
|
|
|
},
|
|
|
|
|
2011-12-19 05:16:43 -08:00
|
|
|
/**
|
|
|
|
* Returns the className that should be assigned to the propertyView content
|
|
|
|
* container.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
get propertyContentClassName()
|
|
|
|
{
|
|
|
|
if (this.visible) {
|
|
|
|
let darkValue = this.tree._darkStripe ?
|
2013-03-27 15:20:38 -07:00
|
|
|
"property-content theme-bg-darker" : "property-content";
|
2011-12-19 05:16:43 -08:00
|
|
|
return darkValue;
|
|
|
|
}
|
|
|
|
return "property-content-hidden";
|
|
|
|
},
|
|
|
|
|
|
|
|
buildMain: function PropertyView_buildMain()
|
2011-11-07 10:35:40 -08:00
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
let doc = this.tree.styleDocument;
|
2013-03-27 15:20:38 -07:00
|
|
|
this.element = doc.createElementNS(HTML_NS, "div");
|
2011-12-19 05:16:43 -08:00
|
|
|
this.element.setAttribute("class", this.propertyHeaderClassName);
|
2011-11-07 10:35:40 -08:00
|
|
|
|
|
|
|
this.matchedExpander = doc.createElementNS(HTML_NS, "div");
|
2013-03-27 15:20:38 -07:00
|
|
|
this.matchedExpander.className = "expander theme-twisty";
|
2012-03-11 07:01:38 -07:00
|
|
|
this.matchedExpander.setAttribute("tabindex", "0");
|
|
|
|
this.matchedExpander.addEventListener("click",
|
|
|
|
this.matchedExpanderClick.bind(this), false);
|
|
|
|
this.matchedExpander.addEventListener("keydown", function(aEvent) {
|
2011-12-19 05:57:42 -08:00
|
|
|
let keyEvent = Ci.nsIDOMKeyEvent;
|
|
|
|
if (aEvent.keyCode == keyEvent.DOM_VK_F1) {
|
|
|
|
this.mdnLinkClick();
|
|
|
|
}
|
|
|
|
if (aEvent.keyCode == keyEvent.DOM_VK_RETURN ||
|
2012-03-11 07:01:38 -07:00
|
|
|
aEvent.keyCode == keyEvent.DOM_VK_SPACE) {
|
|
|
|
this.matchedExpanderClick(aEvent);
|
2011-12-19 05:57:42 -08:00
|
|
|
}
|
|
|
|
}.bind(this), false);
|
2013-03-27 15:20:38 -07:00
|
|
|
this.element.appendChild(this.matchedExpander);
|
2011-12-19 05:57:42 -08:00
|
|
|
|
2013-03-27 15:20:38 -07:00
|
|
|
this.nameNode = doc.createElementNS(HTML_NS, "div");
|
2012-08-30 06:23:33 -07:00
|
|
|
this.element.appendChild(this.nameNode);
|
2013-03-27 15:20:38 -07:00
|
|
|
this.nameNode.setAttribute("class", "property-name theme-fg-color5");
|
|
|
|
this.nameNode.textContent = this.nameNode.title = this.name;
|
2012-03-11 07:01:38 -07:00
|
|
|
this.nameNode.addEventListener("click", function(aEvent) {
|
|
|
|
this.matchedExpander.focus();
|
|
|
|
}.bind(this), false);
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2013-03-27 15:20:38 -07:00
|
|
|
this.valueNode = doc.createElementNS(HTML_NS, "div");
|
2011-12-19 05:16:43 -08:00
|
|
|
this.element.appendChild(this.valueNode);
|
2013-03-27 15:20:38 -07:00
|
|
|
this.valueNode.setAttribute("class", "property-value theme-fg-color1");
|
2011-11-07 10:35:40 -08:00
|
|
|
this.valueNode.setAttribute("dir", "ltr");
|
2013-03-27 15:20:38 -07:00
|
|
|
this.valueNode.textContent = this.valueNode.title = this.value;
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2011-12-19 05:16:43 -08:00
|
|
|
return this.element;
|
|
|
|
},
|
|
|
|
|
|
|
|
buildSelectorContainer: function PropertyView_buildSelectorContainer()
|
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
let doc = this.tree.styleDocument;
|
2013-03-27 15:20:38 -07:00
|
|
|
let element = doc.createElementNS(HTML_NS, "div");
|
2011-12-19 05:16:43 -08:00
|
|
|
element.setAttribute("class", this.propertyContentClassName);
|
2013-03-27 15:20:38 -07:00
|
|
|
this.matchedSelectorsContainer = doc.createElementNS(HTML_NS, "div");
|
|
|
|
this.matchedSelectorsContainer.setAttribute("class", "matchedselectors");
|
2011-12-19 05:16:43 -08:00
|
|
|
element.appendChild(this.matchedSelectorsContainer);
|
2011-11-07 10:35:40 -08:00
|
|
|
|
2011-12-19 05:16:43 -08:00
|
|
|
return element;
|
2011-11-07 10:35:40 -08:00
|
|
|
},
|
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
/**
|
|
|
|
* Refresh the panel's CSS property value.
|
|
|
|
*/
|
|
|
|
refresh: function PropertyView_refresh()
|
|
|
|
{
|
2011-12-19 05:16:43 -08:00
|
|
|
this.element.className = this.propertyHeaderClassName;
|
|
|
|
this.element.nextElementSibling.className = this.propertyContentClassName;
|
2011-09-20 02:35:01 -07:00
|
|
|
|
|
|
|
if (this.prevViewedElement != this.tree.viewedElement) {
|
|
|
|
this._matchedSelectorViews = null;
|
|
|
|
this.prevViewedElement = this.tree.viewedElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.tree.viewedElement || !this.visible) {
|
2013-03-27 15:20:38 -07:00
|
|
|
this.valueNode.textContent = this.valueNode.title = "";
|
2011-12-19 05:16:43 -08:00
|
|
|
this.matchedSelectorsContainer.parentNode.hidden = true;
|
2012-10-29 17:29:24 -07:00
|
|
|
this.matchedSelectorsContainer.textContent = "";
|
2011-09-15 03:30:00 -07:00
|
|
|
this.matchedExpander.removeAttribute("open");
|
|
|
|
return;
|
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2011-11-06 02:36:38 -08:00
|
|
|
this.tree.numVisibleProperties++;
|
2013-03-27 15:20:38 -07:00
|
|
|
this.valueNode.textContent = this.valueNode.title = this.propertyInfo.value;
|
2013-01-29 09:05:17 -08:00
|
|
|
this.refreshMatchedSelectors();
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-09-15 03:30:00 -07:00
|
|
|
* Refresh the panel matched rules.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2011-09-15 03:30:00 -07:00
|
|
|
refreshMatchedSelectors: function PropertyView_refreshMatchedSelectors()
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2011-10-13 02:28:52 -07:00
|
|
|
let hasMatchedSelectors = this.hasMatchedSelectors;
|
2011-12-19 05:16:43 -08:00
|
|
|
this.matchedSelectorsContainer.parentNode.hidden = !hasMatchedSelectors;
|
2011-09-15 03:30:00 -07:00
|
|
|
|
2011-11-06 02:26:09 -08:00
|
|
|
if (hasMatchedSelectors) {
|
2012-03-11 07:01:38 -07:00
|
|
|
this.matchedExpander.classList.add("expandable");
|
2011-11-04 10:12:58 -07:00
|
|
|
} else {
|
2012-03-11 07:01:38 -07:00
|
|
|
this.matchedExpander.classList.remove("expandable");
|
2011-11-04 10:12:58 -07:00
|
|
|
}
|
|
|
|
|
2011-10-13 02:28:52 -07:00
|
|
|
if (this.matchedExpanded && hasMatchedSelectors) {
|
2013-08-08 08:44:57 -07:00
|
|
|
return this.tree.pageStyle.getMatchedSelectors(this.tree.viewedElement, this.name).then(matched => {
|
|
|
|
if (!this.matchedExpanded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._matchedSelectorResponse = matched;
|
|
|
|
CssHtmlTree.processTemplate(this.templateMatchedSelectors,
|
|
|
|
this.matchedSelectorsContainer, this);
|
|
|
|
this.matchedExpander.setAttribute("open", "");
|
|
|
|
this.tree.styleInspector.inspector.emit("computed-view-property-expanded");
|
|
|
|
}).then(null, console.error);
|
2011-09-15 03:30:00 -07:00
|
|
|
} else {
|
2011-11-04 10:12:58 -07:00
|
|
|
this.matchedSelectorsContainer.innerHTML = "";
|
2011-09-15 03:30:00 -07:00
|
|
|
this.matchedExpander.removeAttribute("open");
|
2013-08-08 08:44:57 -07:00
|
|
|
return promise.resolve(undefined);
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
get matchedSelectors()
|
|
|
|
{
|
|
|
|
return this._matchedSelectorResponse;
|
|
|
|
},
|
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
/**
|
|
|
|
* Provide access to the matched SelectorViews that we are currently
|
|
|
|
* displaying.
|
|
|
|
*/
|
|
|
|
get matchedSelectorViews()
|
|
|
|
{
|
|
|
|
if (!this._matchedSelectorViews) {
|
|
|
|
this._matchedSelectorViews = [];
|
2013-08-08 08:44:57 -07:00
|
|
|
this._matchedSelectorResponse.forEach(
|
2011-09-15 03:30:00 -07:00
|
|
|
function matchedSelectorViews_convert(aSelectorInfo) {
|
2011-10-21 10:40:22 -07:00
|
|
|
this._matchedSelectorViews.push(new SelectorView(this.tree, aSelectorInfo));
|
2011-09-15 03:30:00 -07:00
|
|
|
}, this);
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
2011-11-05 15:19:02 -07:00
|
|
|
|
2011-09-15 03:30:00 -07:00
|
|
|
return this._matchedSelectorViews;
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-09-15 03:30:00 -07:00
|
|
|
* The action when a user expands matched selectors.
|
2011-11-04 10:12:58 -07:00
|
|
|
*
|
|
|
|
* @param {Event} aEvent Used to determine the class name of the targets click
|
2012-03-11 07:01:38 -07:00
|
|
|
* event.
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2012-03-11 07:01:38 -07:00
|
|
|
matchedExpanderClick: function PropertyView_matchedExpanderClick(aEvent)
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2012-03-11 07:01:38 -07:00
|
|
|
this.matchedExpanded = !this.matchedExpanded;
|
2013-01-29 09:05:17 -08:00
|
|
|
this.refreshMatchedSelectors();
|
2011-11-05 15:19:02 -07:00
|
|
|
aEvent.preventDefault();
|
|
|
|
},
|
|
|
|
|
2011-11-04 10:12:58 -07:00
|
|
|
/**
|
|
|
|
* The action when a user clicks on the MDN help link for a property.
|
|
|
|
*/
|
|
|
|
mdnLinkClick: function PropertyView_mdnLinkClick(aEvent)
|
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
let inspector = this.tree.styleInspector.inspector;
|
|
|
|
|
|
|
|
if (inspector.target.tab) {
|
|
|
|
let browserWin = inspector.target.tab.ownerDocument.defaultView;
|
|
|
|
browserWin.openUILinkIn(this.link, "tab");
|
|
|
|
}
|
2011-11-04 10:12:58 -07:00
|
|
|
aEvent.preventDefault();
|
|
|
|
},
|
2011-08-30 05:12:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A container to view us easy access to display data from a CssRule
|
2011-10-21 10:40:22 -07:00
|
|
|
* @param CssHtmlTree aTree, the owning CssHtmlTree
|
|
|
|
* @param aSelectorInfo
|
2011-08-30 05:12:02 -07:00
|
|
|
*/
|
2011-10-21 10:40:22 -07:00
|
|
|
function SelectorView(aTree, aSelectorInfo)
|
2011-08-30 05:12:02 -07:00
|
|
|
{
|
2011-10-21 10:40:22 -07:00
|
|
|
this.tree = aTree;
|
2011-08-30 05:12:02 -07:00
|
|
|
this.selectorInfo = aSelectorInfo;
|
|
|
|
this._cacheStatusNames();
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
let rule = this.selectorInfo.rule;
|
|
|
|
if (rule && rule.parentStyleSheet) {
|
|
|
|
this.sheet = rule.parentStyleSheet;
|
|
|
|
this.source = CssLogic.shortSource(this.sheet) + ":" + rule.line;
|
|
|
|
} else {
|
|
|
|
this.source = CssLogic.l10n("rule.sourceElement");
|
|
|
|
this.href = "#";
|
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode for cssInfo.rule.status
|
|
|
|
* @see SelectorView.prototype._cacheStatusNames
|
|
|
|
* @see CssLogic.STATUS
|
|
|
|
*/
|
|
|
|
SelectorView.STATUS_NAMES = [
|
2013-01-29 09:05:17 -08:00
|
|
|
// "Parent Match", "Matched", "Best Match"
|
2011-08-30 05:12:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
SelectorView.CLASS_NAMES = [
|
2013-01-29 09:05:17 -08:00
|
|
|
"parentmatch", "matched", "bestmatch"
|
2011-08-30 05:12:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
SelectorView.prototype = {
|
|
|
|
/**
|
|
|
|
* Cache localized status names.
|
|
|
|
*
|
2011-08-30 09:40:29 -07:00
|
|
|
* These statuses are localized inside the styleinspector.properties string
|
|
|
|
* bundle.
|
2013-04-11 13:59:08 -07:00
|
|
|
* @see css-logic.js - the CssLogic.STATUS array.
|
2011-08-30 05:12:02 -07:00
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
_cacheStatusNames: function SelectorView_cacheStatusNames()
|
|
|
|
{
|
|
|
|
if (SelectorView.STATUS_NAMES.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let status in CssLogic.STATUS) {
|
|
|
|
let i = CssLogic.STATUS[status];
|
2013-01-29 09:05:17 -08:00
|
|
|
if (i > CssLogic.STATUS.UNMATCHED) {
|
2011-08-30 05:12:02 -07:00
|
|
|
let value = CssHtmlTree.l10n("rule.status." + status);
|
|
|
|
// Replace normal spaces with non-breaking spaces
|
|
|
|
SelectorView.STATUS_NAMES[i] = value.replace(/ /g, '\u00A0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A localized version of cssRule.status
|
|
|
|
*/
|
|
|
|
get statusText()
|
|
|
|
{
|
|
|
|
return SelectorView.STATUS_NAMES[this.selectorInfo.status];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get class name for selector depending on status
|
|
|
|
*/
|
|
|
|
get statusClass()
|
|
|
|
{
|
2013-03-27 15:20:38 -07:00
|
|
|
return SelectorView.CLASS_NAMES[this.selectorInfo.status - 1];
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
get href()
|
|
|
|
{
|
|
|
|
if (this._href) {
|
|
|
|
return this._href;
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
let sheet = this.selectorInfo.rule.parentStyleSheet;
|
|
|
|
this._href = sheet ? sheet.href : "#";
|
|
|
|
return this._href;
|
|
|
|
},
|
2011-10-21 10:40:22 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
get sourceText()
|
|
|
|
{
|
|
|
|
return this.selectorInfo.sourceText;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
get value()
|
|
|
|
{
|
2013-09-16 03:01:25 -07:00
|
|
|
let val = this.selectorInfo.value;
|
|
|
|
return colorUtils.processCSSString(val);
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
2012-02-10 05:39:47 -08:00
|
|
|
|
2012-03-11 07:01:38 -07:00
|
|
|
maybeOpenStyleEditor: function(aEvent)
|
|
|
|
{
|
|
|
|
let keyEvent = Ci.nsIDOMKeyEvent;
|
|
|
|
if (aEvent.keyCode == keyEvent.DOM_VK_RETURN) {
|
|
|
|
this.openStyleEditor();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-10 05:39:47 -08:00
|
|
|
/**
|
|
|
|
* When a css link is clicked this method is called in order to either:
|
2012-11-30 00:07:59 -08:00
|
|
|
* 1. Open the link in view source (for chrome stylesheets).
|
2012-02-10 05:39:47 -08:00
|
|
|
* 2. Open the link in the style editor.
|
|
|
|
*
|
2012-11-30 00:07:59 -08:00
|
|
|
* We can only view stylesheets contained in document.styleSheets inside the
|
|
|
|
* style editor.
|
2012-03-19 11:38:13 -07:00
|
|
|
*
|
2012-02-10 05:39:47 -08:00
|
|
|
* @param aEvent The click event
|
|
|
|
*/
|
|
|
|
openStyleEditor: function(aEvent)
|
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
let inspector = this.tree.styleInspector.inspector;
|
2013-08-08 08:44:57 -07:00
|
|
|
let rule = this.selectorInfo.rule;
|
|
|
|
let line = rule.line || 0;
|
2012-03-19 11:38:13 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
// The style editor can only display stylesheets coming from content because
|
|
|
|
// chrome stylesheets are not listed in the editor's stylesheet selector.
|
|
|
|
//
|
|
|
|
// If the stylesheet is a content stylesheet we send it to the style
|
|
|
|
// editor else we display it in the view source window.
|
|
|
|
//
|
2012-02-10 05:39:47 -08:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
let href = rule.href;
|
|
|
|
let sheet = rule.parentStyleSheet;
|
|
|
|
if (sheet && href && !sheet.isSystem) {
|
2012-11-30 00:07:59 -08:00
|
|
|
let target = inspector.target;
|
2013-04-11 13:59:08 -07:00
|
|
|
if (ToolDefinitions.styleEditor.isTargetSupported(target)) {
|
2012-12-13 05:03:55 -08:00
|
|
|
gDevTools.showToolbox(target, "styleeditor").then(function(toolbox) {
|
2013-08-08 08:44:57 -07:00
|
|
|
toolbox.getCurrentPanel().selectStyleSheet(href, line);
|
2012-11-30 00:07:59 -08:00
|
|
|
});
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-03-19 11:38:13 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
let contentDoc = null;
|
|
|
|
let rawNode = this.tree.viewedElement.rawNode();
|
|
|
|
if (rawNode) {
|
|
|
|
contentDoc = rawNode.ownerDocument;
|
2012-02-10 05:39:47 -08:00
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
let viewSourceUtils = inspector.viewSourceUtils;
|
|
|
|
viewSourceUtils.viewSource(href, null, contentDoc, line);
|
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
};
|
2013-04-11 13:59:08 -07:00
|
|
|
|
|
|
|
exports.CssHtmlTree = CssHtmlTree;
|
2013-08-07 09:27:22 -07:00
|
|
|
exports.PropertyView = PropertyView;
|