Bug 1184746 - Fixed eslint errors in rule-view.js/computed-view.js, r=mikeratcliffe

Changes in computed-view.js
- Fixed curly braces formatting
- Added missing globals
- Removed named functions
- Removed unused code in openStyleEditor()
- Ensured consistent return in refreshMatchedSelectors()
- Ensured consistent return in refreshPanel()

Changes in rule-view.js
- Ensured consistent return in functions
- Refactored createExpandableContainer() to avoid shadowing
This commit is contained in:
Julian Descottes 2015-07-24 00:11:07 +02:00
Родитель 8f5503c1c0
Коммит d5b670185e
2 изменённых файлов: 148 добавлений и 178 удалений

Просмотреть файл

@ -4,7 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals overlays, StyleInspectorMenu */ /* globals overlays, StyleInspectorMenu, loader, clipboardHelper,
_Iterator, StopIteration */
"use strict"; "use strict";
@ -49,8 +50,7 @@ const HTML_NS = "http://www.w3.org/1999/xhtml";
* *
* @constructor * @constructor
*/ */
function UpdateProcess(aWin, aGenerator, aOptions) function UpdateProcess(aWin, aGenerator, aOptions) {
{
this.win = aWin; this.win = aWin;
this.iter = _Iterator(aGenerator); this.iter = _Iterator(aGenerator);
this.onItem = aOptions.onItem || function() {}; this.onItem = aOptions.onItem || function() {};
@ -66,8 +66,7 @@ UpdateProcess.prototype = {
/** /**
* Schedule a new batch on the main loop. * Schedule a new batch on the main loop.
*/ */
schedule: function UP_schedule() schedule: function() {
{
if (this.canceled) { if (this.canceled) {
return; return;
} }
@ -78,8 +77,7 @@ UpdateProcess.prototype = {
* Cancel the running process. onItem will not be called again, * Cancel the running process. onItem will not be called again,
* and onCancel will be called. * and onCancel will be called.
*/ */
cancel: function UP_cancel() cancel: function() {
{
if (this._timeout) { if (this._timeout) {
this.win.clearTimeout(this._timeout); this.win.clearTimeout(this._timeout);
this._timeout = 0; this._timeout = 0;
@ -88,7 +86,7 @@ UpdateProcess.prototype = {
this.onCancel(); this.onCancel();
}, },
_timeoutHandler: function UP_timeoutHandler() { _timeoutHandler: function() {
this._timeout = null; this._timeout = null;
try { try {
this._runBatch(); this._runBatch();
@ -104,10 +102,9 @@ UpdateProcess.prototype = {
} }
}, },
_runBatch: function Y_runBatch() _runBatch: function() {
{
let time = Date.now(); let time = Date.now();
while(!this.canceled) { while (!this.canceled) {
// Continue until iter.next() throws... // Continue until iter.next() throws...
let next = this.iter.next(); let next = this.iter.next();
this.onItem(next[1]); this.onItem(next[1]);
@ -120,9 +117,9 @@ UpdateProcess.prototype = {
}; };
/** /**
* CssComputedView is a panel that manages the display of a table sorted by style. * CssComputedView is a panel that manages the display of a table
* There should be one instance of CssComputedView per style display (of which there * sorted by style. There should be one instance of CssComputedView
* will generally only be one). * per style display (of which there will generally only be one).
* *
* @param {Inspector} inspector toolbox panel * @param {Inspector} inspector toolbox panel
* @param {Document} document The document that will contain the computed view. * @param {Document} document The document that will contain the computed view.
@ -142,8 +139,8 @@ function CssComputedView(inspector, document, pageStyle) {
this._outputParser = new OutputParser(); this._outputParser = new OutputParser();
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]. let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
getService(Ci.nsIXULChromeRegistry); .getService(Ci.nsIXULChromeRegistry);
this.getRTLAttr = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr"; this.getRTLAttr = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr";
// Create bound methods. // Create bound methods.
@ -211,8 +208,7 @@ function CssComputedView(inspector, document, pageStyle) {
* @param {string} aName The key to lookup. * @param {string} aName The key to lookup.
* @returns A localized version of the given key. * @returns A localized version of the given key.
*/ */
CssComputedView.l10n = function CssComputedView_l10n(aName) CssComputedView.l10n = function(aName) {
{
try { try {
return CssComputedView._strings.GetStringFromName(aName); return CssComputedView._strings.GetStringFromName(aName);
} catch (ex) { } catch (ex) {
@ -251,8 +247,7 @@ CssComputedView.prototype = {
this.pageStyle = pageStyle; this.pageStyle = pageStyle;
}, },
get includeBrowserStyles() get includeBrowserStyles() {
{
return this.includeBrowserStylesCheckbox.checked; return this.includeBrowserStylesCheckbox.checked;
}, },
@ -264,8 +259,9 @@ CssComputedView.prototype = {
}, },
/** /**
* Update the view with a new selected element. * Update the view with a new selected element. The CssComputedView panel
* The CssComputedView panel will show the style information for the given element. * will show the style information for the given element.
*
* @param {NodeFront} aElement The highlighted node to get styles for. * @param {NodeFront} aElement The highlighted node to get styles for.
* @returns a promise that will be resolved when highlighting is complete. * @returns a promise that will be resolved when highlighting is complete.
*/ */
@ -383,8 +379,7 @@ CssComputedView.prototype = {
return {type, value}; return {type, value};
}, },
_createPropertyViews: function() _createPropertyViews: function() {
{
if (this._createViewsPromise) { if (this._createViewsPromise) {
return this._createViewsPromise; return this._createViewsPromise;
} }
@ -396,7 +391,8 @@ CssComputedView.prototype = {
this.numVisibleProperties = 0; this.numVisibleProperties = 0;
let fragment = this.styleDocument.createDocumentFragment(); let fragment = this.styleDocument.createDocumentFragment();
this._createViewsProcess = new UpdateProcess(this.styleWindow, CssComputedView.propertyNames, { this._createViewsProcess = new UpdateProcess(
this.styleWindow, CssComputedView.propertyNames, {
onItem: (aPropertyName) => { onItem: (aPropertyName) => {
// Per-item callback. // Per-item callback.
let propView = new PropertyView(this, aPropertyName); let propView = new PropertyView(this, aPropertyName);
@ -426,8 +422,7 @@ CssComputedView.prototype = {
/** /**
* Refresh the panel content. * Refresh the panel content.
*/ */
refreshPanel: function CssComputedView_refreshPanel() refreshPanel: function() {
{
if (!this.viewedElement) { if (!this.viewedElement) {
return promise.resolve(); return promise.resolve();
} }
@ -443,12 +438,12 @@ CssComputedView.prototype = {
onlyMatched: !this.includeBrowserStyles, onlyMatched: !this.includeBrowserStyles,
markMatched: true markMatched: true
}) })
]).then(([createViews, computed]) => { ]).then(([, computed]) => {
if (viewedElement !== this.viewedElement) { if (viewedElement !== this.viewedElement) {
return; return promise.resolve();
} }
this._matchedProperties = new Set; this._matchedProperties = new Set();
for (let name in computed) { for (let name in computed) {
if (computed[name].matched) { if (computed[name].matched) {
this._matchedProperties.add(name); this._matchedProperties.add(name);
@ -469,7 +464,8 @@ CssComputedView.prototype = {
this._darkStripe = true; this._darkStripe = true;
let deferred = promise.defer(); let deferred = promise.defer();
this._refreshProcess = new UpdateProcess(this.styleWindow, this.propertyViews, { this._refreshProcess = new UpdateProcess(
this.styleWindow, this.propertyViews, {
onItem: (aPropView) => { onItem: (aPropView) => {
aPropView.refresh(); aPropView.refresh();
}, },
@ -511,8 +507,7 @@ CssComputedView.prototype = {
* *
* @param {Event} aEvent the DOM Event object. * @param {Event} aEvent the DOM Event object.
*/ */
_onFilterStyles: function(aEvent) _onFilterStyles: function(aEvent) {
{
let win = this.styleWindow; let win = this.styleWindow;
if (this._filterChangedTimeout) { if (this._filterChangedTimeout) {
@ -580,8 +575,7 @@ CssComputedView.prototype = {
* *
* @param {Event} aEvent the DOM Event object. * @param {Event} aEvent the DOM Event object.
*/ */
_onIncludeBrowserStyles: function(aEvent) _onIncludeBrowserStyles: function(aEvent) {
{
this.refreshSourceFilter(); this.refreshSourceFilter();
this.refreshPanel(); this.refreshPanel();
}, },
@ -592,16 +586,14 @@ CssComputedView.prototype = {
* document or one of thedocument's stylesheets. If .checked is false we * document or one of thedocument's stylesheets. If .checked is false we
* display all properties including those that come from UA stylesheets. * display all properties including those that come from UA stylesheets.
*/ */
refreshSourceFilter: function CssComputedView_setSourceFilter() refreshSourceFilter: function() {
{
this._matchedProperties = null; this._matchedProperties = null;
this._sourceFilter = this.includeBrowserStyles ? this._sourceFilter = this.includeBrowserStyles ?
CssLogic.FILTER.UA : CssLogic.FILTER.UA :
CssLogic.FILTER.USER; CssLogic.FILTER.USER;
}, },
_onSourcePrefChanged: function CssComputedView__onSourcePrefChanged() _onSourcePrefChanged: function() {
{
for (let propView of this.propertyViews) { for (let propView of this.propertyViews) {
propView.updateSourceLinks(); propView.updateSourceLinks();
} }
@ -611,8 +603,7 @@ CssComputedView.prototype = {
/** /**
* The CSS as displayed by the UI. * The CSS as displayed by the UI.
*/ */
createStyleViews: function CssComputedView_createStyleViews() createStyleViews: function() {
{
if (CssComputedView.propertyNames) { if (CssComputedView.propertyNames) {
return; return;
} }
@ -641,8 +632,8 @@ CssComputedView.prototype = {
this._createPropertyViews().then(null, e => { this._createPropertyViews().then(null, e => {
if (!this._isDestroyed) { if (!this._isDestroyed) {
console.warn("The creation of property views was cancelled because the " + console.warn("The creation of property views was cancelled because " +
"computed-view was destroyed before it was done creating views"); "the computed-view was destroyed before it was done creating views");
} else { } else {
console.error(e); console.error(e);
} }
@ -654,18 +645,16 @@ CssComputedView.prototype = {
* *
* @return {Set} If a property name is in the set, it has matching selectors. * @return {Set} If a property name is in the set, it has matching selectors.
*/ */
get matchedProperties() get matchedProperties() {
{ return this._matchedProperties || new Set();
return this._matchedProperties || new Set;
}, },
/** /**
* Focus the window on mousedown. * Focus the window on mousedown.
* *
* @param aEvent The event object * @param event The event object
*/ */
focusWindow: function(aEvent) focusWindow: function(event) {
{
let win = this.styleDocument.defaultView; let win = this.styleDocument.defaultView;
win.focus(); win.focus();
}, },
@ -707,8 +696,8 @@ CssComputedView.prototype = {
let win = this.styleDocument.defaultView; let win = this.styleDocument.defaultView;
let text = win.getSelection().toString().trim(); let text = win.getSelection().toString().trim();
// Tidy up block headings by moving CSS property names and their values onto // Tidy up block headings by moving CSS property names and their
// the same line and inserting a colon between them. // values onto the same line and inserting a colon between them.
let textArray = text.split(/[\r\n]+/); let textArray = text.split(/[\r\n]+/);
let result = ""; let result = "";
@ -737,8 +726,7 @@ CssComputedView.prototype = {
/** /**
* Destructor for CssComputedView. * Destructor for CssComputedView.
*/ */
destroy: function CssComputedView_destroy() destroy: function() {
{
this.viewedElement = null; this.viewedElement = null;
this._outputParser = null; this._outputParser = null;
@ -819,8 +807,7 @@ PropertyInfo.prototype = {
* @param {string} aName the CSS property name for which this PropertyView * @param {string} aName the CSS property name for which this PropertyView
* instance will render the rules. * instance will render the rules.
*/ */
function PropertyView(aTree, aName) function PropertyView(aTree, aName) {
{
this.tree = aTree; this.tree = aTree;
this.name = aName; this.name = aName;
this.getRTLAttr = aTree.getRTLAttr; this.getRTLAttr = aTree.getRTLAttr;
@ -864,32 +851,28 @@ PropertyView.prototype = {
* @return {string} the computed style for the current property of the * @return {string} the computed style for the current property of the
* currently highlighted element. * currently highlighted element.
*/ */
get value() get value() {
{
return this.propertyInfo.value; return this.propertyInfo.value;
}, },
/** /**
* An easy way to access the CssPropertyInfo behind this PropertyView. * An easy way to access the CssPropertyInfo behind this PropertyView.
*/ */
get propertyInfo() get propertyInfo() {
{
return this._propertyInfo; return this._propertyInfo;
}, },
/** /**
* Does the property have any matched selectors? * Does the property have any matched selectors?
*/ */
get hasMatchedSelectors() get hasMatchedSelectors() {
{
return this.tree.matchedProperties.has(this.name); return this.tree.matchedProperties.has(this.name);
}, },
/** /**
* Should this property be visible? * Should this property be visible?
*/ */
get visible() get visible() {
{
if (!this.tree.viewedElement) { if (!this.tree.viewedElement) {
return false; return false;
} }
@ -913,8 +896,7 @@ PropertyView.prototype = {
* Returns the className that should be assigned to the propertyView. * Returns the className that should be assigned to the propertyView.
* @return string * @return string
*/ */
get propertyHeaderClassName() get propertyHeaderClassName() {
{
if (this.visible) { if (this.visible) {
let isDark = this.tree._darkStripe = !this.tree._darkStripe; let isDark = this.tree._darkStripe = !this.tree._darkStripe;
return isDark ? "property-view row-striped" : "property-view"; return isDark ? "property-view row-striped" : "property-view";
@ -927,8 +909,7 @@ PropertyView.prototype = {
* container. * container.
* @return string * @return string
*/ */
get propertyContentClassName() get propertyContentClassName() {
{
if (this.visible) { if (this.visible) {
let isDark = this.tree._darkStripe; let isDark = this.tree._darkStripe;
return isDark ? "property-content row-striped" : "property-content"; return isDark ? "property-content row-striped" : "property-content";
@ -940,8 +921,7 @@ PropertyView.prototype = {
* Build the markup for on computed style * Build the markup for on computed style
* @return Element * @return Element
*/ */
buildMain: function PropertyView_buildMain() buildMain: function() {
{
let doc = this.tree.styleDocument; let doc = this.tree.styleDocument;
// Build the container element // Build the container element
@ -998,8 +978,7 @@ PropertyView.prototype = {
return this.element; return this.element;
}, },
buildSelectorContainer: function PropertyView_buildSelectorContainer() buildSelectorContainer: function() {
{
let doc = this.tree.styleDocument; let doc = this.tree.styleDocument;
let element = doc.createElementNS(HTML_NS, "div"); let element = doc.createElementNS(HTML_NS, "div");
element.setAttribute("class", this.propertyContentClassName); element.setAttribute("class", this.propertyContentClassName);
@ -1013,8 +992,7 @@ PropertyView.prototype = {
/** /**
* Refresh the panel's CSS property value. * Refresh the panel's CSS property value.
*/ */
refresh: function PropertyView_refresh() refresh: function() {
{
this.element.className = this.propertyHeaderClassName; this.element.className = this.propertyHeaderClassName;
this.element.nextElementSibling.className = this.propertyContentClassName; this.element.nextElementSibling.className = this.propertyContentClassName;
@ -1051,8 +1029,7 @@ PropertyView.prototype = {
/** /**
* Refresh the panel matched rules. * Refresh the panel matched rules.
*/ */
refreshMatchedSelectors: function PropertyView_refreshMatchedSelectors() refreshMatchedSelectors: function() {
{
let hasMatchedSelectors = this.hasMatchedSelectors; let hasMatchedSelectors = this.hasMatchedSelectors;
this.matchedSelectorsContainer.parentNode.hidden = !hasMatchedSelectors; this.matchedSelectorsContainer.parentNode.hidden = !hasMatchedSelectors;
@ -1063,28 +1040,29 @@ PropertyView.prototype = {
} }
if (this.matchedExpanded && hasMatchedSelectors) { if (this.matchedExpanded && hasMatchedSelectors) {
return this.tree.pageStyle.getMatchedSelectors(this.tree.viewedElement, this.name).then(matched => { return this.tree.pageStyle
if (!this.matchedExpanded) { .getMatchedSelectors(this.tree.viewedElement, this.name)
return; .then(matched => {
} if (!this.matchedExpanded) {
return promise.resolve(undefined);
}
this._matchedSelectorResponse = matched; this._matchedSelectorResponse = matched;
return this._buildMatchedSelectors().then(() => { return this._buildMatchedSelectors().then(() => {
this.matchedExpander.setAttribute("open", ""); this.matchedExpander.setAttribute("open", "");
this.tree.inspector.emit("computed-view-property-expanded"); this.tree.inspector.emit("computed-view-property-expanded");
}); });
}).then(null, console.error); }).then(null, console.error);
} else {
this.matchedSelectorsContainer.innerHTML = "";
this.matchedExpander.removeAttribute("open");
this.tree.inspector.emit("computed-view-property-collapsed");
return promise.resolve(undefined);
} }
this.matchedSelectorsContainer.innerHTML = "";
this.matchedExpander.removeAttribute("open");
this.tree.inspector.emit("computed-view-property-collapsed");
return promise.resolve(undefined);
}, },
get matchedSelectors() get matchedSelectors() {
{
return this._matchedSelectorResponse; return this._matchedSelectorResponse;
}, },
@ -1130,13 +1108,13 @@ PropertyView.prototype = {
* Provide access to the matched SelectorViews that we are currently * Provide access to the matched SelectorViews that we are currently
* displaying. * displaying.
*/ */
get matchedSelectorViews() get matchedSelectorViews() {
{
if (!this._matchedSelectorViews) { if (!this._matchedSelectorViews) {
this._matchedSelectorViews = []; this._matchedSelectorViews = [];
this._matchedSelectorResponse.forEach( this._matchedSelectorResponse.forEach(
function matchedSelectorViews_convert(aSelectorInfo) { function(aSelectorInfo) {
this._matchedSelectorViews.push(new SelectorView(this.tree, aSelectorInfo)); let selectorView = new SelectorView(this.tree, aSelectorInfo);
this._matchedSelectorViews.push(selectorView);
}, this); }, this);
} }
return this._matchedSelectorViews; return this._matchedSelectorViews;
@ -1146,8 +1124,7 @@ PropertyView.prototype = {
* Update all the selector source links to reflect whether we're linking to * Update all the selector source links to reflect whether we're linking to
* original sources (e.g. Sass files). * original sources (e.g. Sass files).
*/ */
updateSourceLinks: function PropertyView_updateSourceLinks() updateSourceLinks: function() {
{
if (!this._matchedSelectorViews) { if (!this._matchedSelectorViews) {
return; return;
} }
@ -1162,8 +1139,7 @@ PropertyView.prototype = {
* @param {Event} aEvent Used to determine the class name of the targets click * @param {Event} aEvent Used to determine the class name of the targets click
* event. * event.
*/ */
onMatchedToggle: function PropertyView_onMatchedToggle(aEvent) onMatchedToggle: function(aEvent) {
{
if (aEvent.shiftKey) { if (aEvent.shiftKey) {
return; return;
} }
@ -1175,8 +1151,7 @@ PropertyView.prototype = {
/** /**
* The action when a user clicks on the MDN help link for a property. * The action when a user clicks on the MDN help link for a property.
*/ */
mdnLinkClick: function PropertyView_mdnLinkClick(aEvent) mdnLinkClick: function(aEvent) {
{
let inspector = this.tree.inspector; let inspector = this.tree.inspector;
if (inspector.target.tab) { if (inspector.target.tab) {
@ -1189,7 +1164,7 @@ PropertyView.prototype = {
/** /**
* Destroy this property view, removing event listeners * Destroy this property view, removing event listeners
*/ */
destroy: function PropertyView_destroy() { destroy: function() {
this.element.removeEventListener("dblclick", this.onMatchedToggle, false); this.element.removeEventListener("dblclick", this.onMatchedToggle, false);
this.element.removeEventListener("keydown", this.onKeyDown, false); this.element.removeEventListener("keydown", this.onKeyDown, false);
this.element = null; this.element = null;
@ -1210,8 +1185,7 @@ PropertyView.prototype = {
* @param CssComputedView aTree, the owning CssComputedView * @param CssComputedView aTree, the owning CssComputedView
* @param aSelectorInfo * @param aSelectorInfo
*/ */
function SelectorView(aTree, aSelectorInfo) function SelectorView(aTree, aSelectorInfo) {
{
this.tree = aTree; this.tree = aTree;
this.selectorInfo = aSelectorInfo; this.selectorInfo = aSelectorInfo;
this._cacheStatusNames(); this._cacheStatusNames();
@ -1245,8 +1219,7 @@ SelectorView.prototype = {
* *
* @return {void} * @return {void}
*/ */
_cacheStatusNames: function SelectorView_cacheStatusNames() _cacheStatusNames: function() {
{
if (SelectorView.STATUS_NAMES.length) { if (SelectorView.STATUS_NAMES.length) {
return; return;
} }
@ -1256,7 +1229,7 @@ SelectorView.prototype = {
if (i > CssLogic.STATUS.UNMATCHED) { if (i > CssLogic.STATUS.UNMATCHED) {
let value = CssComputedView.l10n("rule.status." + status); let value = CssComputedView.l10n("rule.status." + status);
// Replace normal spaces with non-breaking spaces // Replace normal spaces with non-breaking spaces
SelectorView.STATUS_NAMES[i] = value.replace(/ /g, '\u00A0'); SelectorView.STATUS_NAMES[i] = value.replace(/ /g, "\u00A0");
} }
} }
}, },
@ -1264,21 +1237,18 @@ SelectorView.prototype = {
/** /**
* A localized version of cssRule.status * A localized version of cssRule.status
*/ */
get statusText() get statusText() {
{
return SelectorView.STATUS_NAMES[this.selectorInfo.status]; return SelectorView.STATUS_NAMES[this.selectorInfo.status];
}, },
/** /**
* Get class name for selector depending on status * Get class name for selector depending on status
*/ */
get statusClass() get statusClass() {
{
return SelectorView.CLASS_NAMES[this.selectorInfo.status - 1]; return SelectorView.CLASS_NAMES[this.selectorInfo.status - 1];
}, },
get href() get href() {
{
if (this._href) { if (this._href) {
return this._href; return this._href;
} }
@ -1287,19 +1257,15 @@ SelectorView.prototype = {
return this._href; return this._href;
}, },
get sourceText() get sourceText() {
{
return this.selectorInfo.sourceText; return this.selectorInfo.sourceText;
}, },
get value() {
get value()
{
return this.selectorInfo.value; return this.selectorInfo.value;
}, },
get outputFragment() get outputFragment() {
{
// Sadly, because this fragment is added to the template by DOM Templater // Sadly, because this fragment is added to the template by DOM Templater
// we lose any events that are attached. This means that URLs will open in a // we lose any events that are attached. This means that URLs will open in a
// new window. At some point we should fix this by stopping using the // new window. At some point we should fix this by stopping using the
@ -1320,8 +1286,7 @@ SelectorView.prototype = {
* Update the text of the source link to reflect whether we're showing * Update the text of the source link to reflect whether we're showing
* original sources or not. * original sources or not.
*/ */
updateSourceLink: function() updateSourceLink: function() {
{
return this.updateSource().then((oldSource) => { return this.updateSource().then((oldSource) => {
if (oldSource != this.source && this.tree.element) { if (oldSource != this.source && this.tree.element) {
let selector = '[sourcelocation="' + oldSource + '"]'; let selector = '[sourcelocation="' + oldSource + '"]';
@ -1337,8 +1302,7 @@ SelectorView.prototype = {
/** /**
* Update the 'source' store based on our original sources preference. * Update the 'source' store based on our original sources preference.
*/ */
updateSource: function() updateSource: function() {
{
let rule = this.selectorInfo.rule; let rule = this.selectorInfo.rule;
this.sheet = rule.parentStyleSheet; this.sheet = rule.parentStyleSheet;
@ -1373,8 +1337,7 @@ SelectorView.prototype = {
/** /**
* Open the style editor if the RETURN key was pressed. * Open the style editor if the RETURN key was pressed.
*/ */
maybeOpenStyleEditor: function(aEvent) maybeOpenStyleEditor: function(aEvent) {
{
let keyEvent = Ci.nsIDOMKeyEvent; let keyEvent = Ci.nsIDOMKeyEvent;
if (aEvent.keyCode == keyEvent.DOM_VK_RETURN) { if (aEvent.keyCode == keyEvent.DOM_VK_RETURN) {
this.openStyleEditor(); this.openStyleEditor();
@ -1391,8 +1354,7 @@ SelectorView.prototype = {
* *
* @param aEvent The click event * @param aEvent The click event
*/ */
openStyleEditor: function(aEvent) openStyleEditor: function(aEvent) {
{
let inspector = this.tree.inspector; let inspector = this.tree.inspector;
let rule = this.selectorInfo.rule; let rule = this.selectorInfo.rule;
@ -1401,15 +1363,8 @@ SelectorView.prototype = {
// //
// If the stylesheet is a content stylesheet we send it to the style // If the stylesheet is a content stylesheet we send it to the style
// editor else we display it in the view source window. // editor else we display it in the view source window.
let sheet = rule.parentStyleSheet; let parentStyleSheet = rule.parentStyleSheet;
if (!sheet || sheet.isSystem) { if (!parentStyleSheet || parentStyleSheet.isSystem) {
let contentDoc = null;
if (this.tree.viewedElement.isLocal_toBeDeprecated()) {
let rawNode = this.tree.viewedElement.rawNode();
if (rawNode) {
contentDoc = rawNode.ownerDocument;
}
}
let toolbox = gDevTools.getToolbox(inspector.target); let toolbox = gDevTools.getToolbox(inspector.target);
toolbox.viewSource(rule.href, rule.line); toolbox.viewSource(rule.href, rule.line);
return; return;
@ -1447,7 +1402,7 @@ function createChild(aParent, aTag, aAttributes={}) {
if (aAttributes.hasOwnProperty(attr)) { if (aAttributes.hasOwnProperty(attr)) {
if (attr === "textContent") { if (attr === "textContent") {
elt.textContent = aAttributes[attr]; elt.textContent = aAttributes[attr];
} else if(attr === "child") { } else if (attr === "child") {
elt.appendChild(aAttributes[attr]); elt.appendChild(aAttributes[attr]);
} else { } else {
elt.setAttribute(attr, aAttributes[attr]); elt.setAttribute(attr, aAttributes[attr]);

Просмотреть файл

@ -5,7 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals overlays, Services, EventEmitter, StyleInspectorMenu, /* globals overlays, Services, EventEmitter, StyleInspectorMenu,
clipboardHelper, _strings, domUtils, AutocompletePopup */ clipboardHelper, _strings, domUtils, AutocompletePopup, loader,
osString */
"use strict"; "use strict";
@ -209,7 +210,7 @@ ElementStyle.prototype = {
filter: this.showUserAgentStyles ? "ua" : undefined, filter: this.showUserAgentStyles ? "ua" : undefined,
}).then(entries => { }).then(entries => {
if (this.destroyed) { if (this.destroyed) {
return; return promise.resolve(undefined);
} }
// Make sure the dummy element has been created before continuing... // Make sure the dummy element has been created before continuing...
@ -236,14 +237,12 @@ ElementStyle.prototype = {
// We're done with the previous list of rules. // We're done with the previous list of rules.
delete this._refreshRules; delete this._refreshRules;
return null;
}); });
}).then(null, e => { }).then(null, e => {
// populate is often called after a setTimeout, // populate is often called after a setTimeout,
// the connection may already be closed. // the connection may already be closed.
if (this.destroyed) { if (this.destroyed) {
return; return promise.resolve(undefined);
} }
return promiseWarn(e); return promiseWarn(e);
}); });
@ -636,7 +635,7 @@ Rule.prototype = {
disabled.delete(this.style); disabled.delete(this.style);
} }
let promise = aModifications.apply().then(() => { let modificationsPromise = aModifications.apply().then(() => {
let cssProps = {}; let cssProps = {};
for (let cssProp of parseDeclarations(this.style.cssText)) { for (let cssProp of parseDeclarations(this.style.cssText)) {
cssProps[cssProp.name] = cssProp; cssProps[cssProp.name] = cssProp;
@ -668,8 +667,8 @@ Rule.prototype = {
this.elementStyle._changed(); this.elementStyle._changed();
}).then(null, promiseWarn); }).then(null, promiseWarn);
this._applyingModifications = promise; this._applyingModifications = modificationsPromise;
return promise; return modificationsPromise;
}, },
/** /**
@ -1741,7 +1740,7 @@ CssRuleView.prototype = {
refreshPanel: function() { refreshPanel: function() {
// Ignore refreshes during editing or when no element is selected. // Ignore refreshes during editing or when no element is selected.
if (this.isEditing || !this._elementStyle) { if (this.isEditing || !this._elementStyle) {
return; return promise.resolve(undefined);
} }
// Repopulate the element style once the current modifications are done. // Repopulate the element style once the current modifications are done.
@ -1893,9 +1892,10 @@ CssRuleView.prototype = {
/** /**
* Creates an expandable container in the rule view * Creates an expandable container in the rule view
* @param {String} aLabel The label for the container header * @param {String} aLabel
* @param {Boolean} isPseudo Whether or not the container will hold * The label for the container header
* pseudo element rules * @param {Boolean} isPseudo
* Whether or not the container will hold pseudo element rules
* @return {DOMNode} The container element * @return {DOMNode} The container element
*/ */
createExpandableContainer: function(aLabel, isPseudo = false) { createExpandableContainer: function(aLabel, isPseudo = false) {
@ -1915,44 +1915,59 @@ CssRuleView.prototype = {
container.classList.add("ruleview-expandable-container"); container.classList.add("ruleview-expandable-container");
this.element.appendChild(container); this.element.appendChild(container);
let toggleContainerVisibility = (isPseudo, showPseudo) => {
let isOpen = twisty.getAttribute("open");
if (isPseudo) {
this._showPseudoElements = !!showPseudo;
Services.prefs.setBoolPref("devtools.inspector.show_pseudo_elements",
this.showPseudoElements);
header.classList.toggle("show-expandable-container",
this.showPseudoElements);
isOpen = !this.showPseudoElements;
} else {
header.classList.toggle("show-expandable-container");
}
if (isOpen) {
twisty.removeAttribute("open");
} else {
twisty.setAttribute("open", "true");
}
};
header.addEventListener("dblclick", () => { header.addEventListener("dblclick", () => {
toggleContainerVisibility(isPseudo, !this.showPseudoElements); this._toggleContainerVisibility(twisty, header, isPseudo,
!this.showPseudoElements);
}, false); }, false);
twisty.addEventListener("click", () => { twisty.addEventListener("click", () => {
toggleContainerVisibility(isPseudo, !this.showPseudoElements); this._toggleContainerVisibility(twisty, header, isPseudo,
!this.showPseudoElements);
}, false); }, false);
if (isPseudo) { if (isPseudo) {
toggleContainerVisibility(isPseudo, this.showPseudoElements); this._toggleContainerVisibility(twisty, header, isPseudo,
this.showPseudoElements);
} }
return container; return container;
}, },
/**
* Toggle the visibility of an expandable container
* @param {DOMNode} twisty
* clickable toggle DOM Node
* @param {DOMNode} header
* expandable container header DOM Node
* @param {Boolean} isPseudo
* whether or not the container will hold pseudo element rules
* @param {Boolean} showPseudo
* whether or not pseudo element rules should be displayed
*/
_toggleContainerVisibility: function(twisty, header, isPseudo, showPseudo) {
let isOpen = twisty.getAttribute("open");
if (isPseudo) {
this._showPseudoElements = !!showPseudo;
Services.prefs.setBoolPref("devtools.inspector.show_pseudo_elements",
this.showPseudoElements);
header.classList.toggle("show-expandable-container",
this.showPseudoElements);
isOpen = !this.showPseudoElements;
} else {
header.classList.toggle("show-expandable-container");
}
if (isOpen) {
twisty.removeAttribute("open");
} else {
twisty.setAttribute("open", "true");
}
},
_getRuleViewHeaderClassName: function(isPseudo) { _getRuleViewHeaderClassName: function(isPseudo) {
let baseClassName = "theme-gutter ruleview-header"; let baseClassName = "theme-gutter ruleview-header";
return isPseudo ? baseClassName + " ruleview-expandable-header" : return isPseudo ? baseClassName + " ruleview-expandable-header" :