зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1017248 - Show @media sidebar for original sources in style editor; r=bgrins
This commit is contained in:
Родитель
2ef8b4324a
Коммит
15bd529d3e
|
@ -454,26 +454,23 @@ StyleEditorUI.prototype = {
|
|||
}
|
||||
}, false);
|
||||
|
||||
Task.spawn(function* () {
|
||||
// autofocus if it's a new user-created stylesheet
|
||||
if (editor.isNew) {
|
||||
yield this._selectEditor(editor);
|
||||
}
|
||||
// autofocus if it's a new user-created stylesheet
|
||||
if (editor.isNew) {
|
||||
this._selectEditor(editor);
|
||||
}
|
||||
|
||||
if (this._styleSheetToSelect
|
||||
&& this._styleSheetToSelect.stylesheet == editor.styleSheet.href) {
|
||||
yield this.switchToSelectedSheet();
|
||||
}
|
||||
if (this._styleSheetToSelect
|
||||
&& this._styleSheetToSelect.stylesheet == editor.styleSheet.href) {
|
||||
this.switchToSelectedSheet();
|
||||
}
|
||||
|
||||
// If this is the first stylesheet and there is no pending request to
|
||||
// select a particular style sheet, select this sheet.
|
||||
if (!this.selectedEditor && !this._styleSheetBoundToSelect
|
||||
&& editor.styleSheet.styleSheetIndex == 0) {
|
||||
yield this._selectEditor(editor);
|
||||
}
|
||||
|
||||
this.emit("editor-added", editor);
|
||||
}.bind(this)).then(null, Cu.reportError);
|
||||
// If this is the first stylesheet and there is no pending request to
|
||||
// select a particular style sheet, select this sheet.
|
||||
if (!this.selectedEditor && !this._styleSheetBoundToSelect
|
||||
&& editor.styleSheet.styleSheetIndex == 0) {
|
||||
this._selectEditor(editor);
|
||||
}
|
||||
this.emit("editor-added", editor);
|
||||
}.bind(this),
|
||||
|
||||
onShow: function(summary, details, data) {
|
||||
|
@ -712,7 +709,8 @@ StyleEditorUI.prototype = {
|
|||
* Editor to update @media sidebar of
|
||||
*/
|
||||
_updateMediaList: function(editor) {
|
||||
this.getEditorDetails(editor).then((details) => {
|
||||
Task.spawn(function* () {
|
||||
let details = yield this.getEditorDetails(editor);
|
||||
let list = details.querySelector(".stylesheet-media-list");
|
||||
|
||||
while (list.firstChild) {
|
||||
|
@ -722,12 +720,31 @@ StyleEditorUI.prototype = {
|
|||
let rules = editor.mediaRules;
|
||||
let showSidebar = Services.prefs.getBoolPref(PREF_MEDIA_SIDEBAR);
|
||||
let sidebar = details.querySelector(".stylesheet-sidebar");
|
||||
sidebar.hidden = !showSidebar || !rules.length;
|
||||
|
||||
let inSource = false;
|
||||
|
||||
for (let rule of rules) {
|
||||
let {line, column, parentStyleSheet} = rule;
|
||||
|
||||
let location = {
|
||||
line: line,
|
||||
column: column,
|
||||
source: editor.styleSheet.href,
|
||||
styleSheet: parentStyleSheet
|
||||
};
|
||||
if (editor.styleSheet.isOriginalSource) {
|
||||
location = yield editor.cssSheet.getOriginalLocation(line, column);
|
||||
}
|
||||
|
||||
// this @media rule is from a different original source
|
||||
if (location.source != editor.styleSheet.href) {
|
||||
continue;
|
||||
}
|
||||
inSource = true;
|
||||
|
||||
let div = this._panelDoc.createElement("div");
|
||||
div.className = "media-rule-label";
|
||||
div.addEventListener("click", this._jumpToMediaRule.bind(this, rule));
|
||||
div.addEventListener("click", this._jumpToLocation.bind(this, location));
|
||||
|
||||
let cond = this._panelDoc.createElement("div");
|
||||
cond.textContent = rule.conditionText;
|
||||
|
@ -737,25 +754,29 @@ StyleEditorUI.prototype = {
|
|||
}
|
||||
div.appendChild(cond);
|
||||
|
||||
let line = this._panelDoc.createElement("div");
|
||||
line.className = "media-rule-line theme-link";
|
||||
line.textContent = ":" + rule.line;
|
||||
div.appendChild(line);
|
||||
let link = this._panelDoc.createElement("div");
|
||||
link.className = "media-rule-line theme-link";
|
||||
link.textContent = ":" + location.line;
|
||||
div.appendChild(link);
|
||||
|
||||
list.appendChild(div);
|
||||
}
|
||||
|
||||
sidebar.hidden = !showSidebar || !inSource;
|
||||
|
||||
this.emit("media-list-changed", editor);
|
||||
});
|
||||
}.bind(this)).then(null, Cu.reportError);
|
||||
},
|
||||
|
||||
/**
|
||||
* Jump cursor to the editor for a stylesheet and line number for a rule.
|
||||
*
|
||||
* @param {MediaRuleFront} rule
|
||||
* Rule to jump to.
|
||||
* @param {object} location
|
||||
* Location object with 'line', 'column', and 'source' properties.
|
||||
*/
|
||||
_jumpToMediaRule: function(rule) {
|
||||
this.selectStyleSheet(rule.parentStyleSheet, rule.line - 1, rule.column - 1);
|
||||
_jumpToLocation: function(location) {
|
||||
let source = location.styleSheet || location.source;
|
||||
this.selectStyleSheet(source, location.line - 1, location.column - 1);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
|
|
|
@ -96,21 +96,14 @@ function StyleSheetEditor(styleSheet, win, file, isNew, walker) {
|
|||
this.checkLinkedFileForChanges = this.checkLinkedFileForChanges.bind(this);
|
||||
this.markLinkedFileBroken = this.markLinkedFileBroken.bind(this);
|
||||
|
||||
this.mediaRules = [];
|
||||
if (this.styleSheet.getMediaRules) {
|
||||
this.styleSheet.getMediaRules().then(this._onMediaRulesChanged);
|
||||
}
|
||||
this.styleSheet.on("media-rules-changed", this._onMediaRulesChanged);
|
||||
|
||||
this._focusOnSourceEditorReady = false;
|
||||
|
||||
let relatedSheet = this.styleSheet.relatedStyleSheet;
|
||||
if (relatedSheet) {
|
||||
relatedSheet.on("property-change", this._onPropertyChange);
|
||||
}
|
||||
this.styleSheet.on("property-change", this._onPropertyChange);
|
||||
this.cssSheet.on("property-change", this._onPropertyChange);
|
||||
this.styleSheet.on("error", this._onError);
|
||||
|
||||
this.mediaRules = [];
|
||||
if (this.cssSheet.getMediaRules) {
|
||||
this.cssSheet.getMediaRules().then(this._onMediaRulesChanged);
|
||||
}
|
||||
this.cssSheet.on("media-rules-changed", this._onMediaRulesChanged);
|
||||
this.savedFile = file;
|
||||
this.linkCSSFile();
|
||||
}
|
||||
|
@ -131,6 +124,17 @@ StyleSheetEditor.prototype = {
|
|||
return this._isNew;
|
||||
},
|
||||
|
||||
/**
|
||||
* The style sheet or the generated style sheet for this source if it's an
|
||||
* original source.
|
||||
*/
|
||||
get cssSheet() {
|
||||
if (this.styleSheet.isOriginalSource) {
|
||||
return this.styleSheet.relatedStyleSheet;
|
||||
}
|
||||
return this.styleSheet;
|
||||
},
|
||||
|
||||
get savedFile() {
|
||||
return this._savedFile;
|
||||
},
|
||||
|
@ -530,7 +534,9 @@ StyleSheetEditor.prototype = {
|
|||
this._friendlyName = null;
|
||||
this.savedFile = returnFile;
|
||||
|
||||
this.sourceEditor.setClean();
|
||||
if (this.sourceEditor) {
|
||||
this.sourceEditor.setClean();
|
||||
}
|
||||
|
||||
this.emit("property-change");
|
||||
|
||||
|
@ -628,8 +634,8 @@ StyleSheetEditor.prototype = {
|
|||
if (this.sourceEditor) {
|
||||
this.sourceEditor.destroy();
|
||||
}
|
||||
this.styleSheet.off("media-rules-changed", this._onMediaRulesChanged);
|
||||
this.styleSheet.off("property-change", this._onPropertyChange);
|
||||
this.cssSheet.off("property-change", this._onPropertyChange);
|
||||
this.cssSheet.off("media-rules-changed", this._onMediaRulesChanged);
|
||||
this.styleSheet.off("error", this._onError);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ support-files =
|
|||
media.html
|
||||
media-rules.html
|
||||
media-rules.css
|
||||
media-rules-sourcemaps.html
|
||||
minified.html
|
||||
nostyle.html
|
||||
pretty.css
|
||||
|
@ -30,7 +31,10 @@ support-files =
|
|||
sourcemap-css/contained.css
|
||||
sourcemap-css/sourcemaps.css
|
||||
sourcemap-css/sourcemaps.css.map
|
||||
sourcemap-css/media-rules.css
|
||||
sourcemap-css/media-rules.css.map
|
||||
sourcemap-sass/sourcemaps.scss
|
||||
sourcemap-sass/media-rules.scss
|
||||
sourcemaps.html
|
||||
test_private.css
|
||||
test_private.html
|
||||
|
@ -49,6 +53,7 @@ skip-if = os == "linux" || "mac" # bug 949355
|
|||
[browser_styleeditor_inline_friendly_names.js]
|
||||
[browser_styleeditor_loading.js]
|
||||
[browser_styleeditor_media_sidebar.js]
|
||||
[browser_styleeditor_media_sidebar_sourcemaps.js]
|
||||
[browser_styleeditor_new.js]
|
||||
[browser_styleeditor_nostyle.js]
|
||||
[browser_styleeditor_pretty.js]
|
||||
|
|
|
@ -20,7 +20,7 @@ function testEditorAdded(aEditor)
|
|||
{
|
||||
if (aEditor.styleSheet.styleSheetIndex == 0) {
|
||||
gEditorAddedCount++;
|
||||
testFirstStyleSheetEditor(aEditor);
|
||||
gUI.editors[0].getSourceEditor().then(testFirstStyleSheetEditor);
|
||||
}
|
||||
if (aEditor.styleSheet.styleSheetIndex == 1) {
|
||||
gEditorAddedCount++;
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// https rather than chrome to improve coverage
|
||||
const TESTCASE_URI = TEST_BASE_HTTPS + "media-rules-sourcemaps.html";
|
||||
const MEDIA_PREF = "devtools.styleeditor.showMediaSidebar";
|
||||
const MAP_PREF = "devtools.styleeditor.source-maps-enabled";
|
||||
|
||||
const LABELS = ["screen and (max-width: 320px)",
|
||||
"screen and (min-width: 1200px)"];
|
||||
const LINE_NOS = [4, 4];
|
||||
|
||||
waitForExplicitFinish();
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
Services.prefs.setBoolPref(MEDIA_PREF, true);
|
||||
Services.prefs.setBoolPref(MAP_PREF, true);
|
||||
|
||||
let {UI} = yield addTabAndOpenStyleEditors(2, null, TESTCASE_URI);
|
||||
|
||||
yield listenForMediaChange(UI);
|
||||
|
||||
is(UI.editors.length, 1, "correct number of editors");
|
||||
|
||||
// Test editor with @media rules
|
||||
let mediaEditor = UI.editors[0];
|
||||
yield openEditor(mediaEditor);
|
||||
testMediaEditor(mediaEditor);
|
||||
|
||||
Services.prefs.clearUserPref(MEDIA_PREF);
|
||||
Services.prefs.clearUserPref(MAP_PREF);
|
||||
});
|
||||
|
||||
function testMediaEditor(editor) {
|
||||
let sidebar = editor.details.querySelector(".stylesheet-sidebar");
|
||||
is(sidebar.hidden, false, "sidebar is showing on editor with @media");
|
||||
|
||||
let entries = [...sidebar.querySelectorAll(".media-rule-label")];
|
||||
is(entries.length, 2, "two @media rules displayed in sidebar");
|
||||
|
||||
testRule(entries[0], LABELS[0], LINE_NOS[0]);
|
||||
testRule(entries[1], LABELS[1], LINE_NOS[1]);
|
||||
}
|
||||
|
||||
function testRule(rule, text, lineno) {
|
||||
let cond = rule.querySelector(".media-rule-condition");
|
||||
is(cond.textContent, text, "media label is correct for " + text);
|
||||
|
||||
let line = rule.querySelector(".media-rule-line");
|
||||
is(line.textContent, ":" + lineno, "correct line number shown");
|
||||
}
|
||||
|
||||
/* Helpers */
|
||||
|
||||
function openEditor(editor) {
|
||||
getLinkFor(editor).click();
|
||||
|
||||
return editor.getSourceEditor();
|
||||
}
|
||||
|
||||
function listenForMediaChange(UI) {
|
||||
let deferred = promise.defer();
|
||||
UI.once("media-list-changed", () => {
|
||||
deferred.resolve();
|
||||
})
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function getLinkFor(editor) {
|
||||
return editor.summary.querySelector(".stylesheet-name");
|
||||
}
|
|
@ -27,7 +27,11 @@ function test()
|
|||
function runTests()
|
||||
{
|
||||
let count = 0;
|
||||
gUI.once("editor-selected", (event, editor) => {
|
||||
gUI.on("editor-selected", function editorSelected(event, editor) {
|
||||
if (editor.styleSheet != gUI.editors[1].styleSheet) {
|
||||
return;
|
||||
}
|
||||
gUI.off("editor-selected", editorSelected);
|
||||
editor.getSourceEditor().then(() => {
|
||||
info("selected second editor, about to reload page");
|
||||
reloadPage();
|
||||
|
@ -41,7 +45,7 @@ function runTests()
|
|||
})
|
||||
});
|
||||
});
|
||||
gUI.selectStyleSheet(gUI.editors[1].styleSheet.href, LINE_NO, COL_NO);
|
||||
gUI.selectStyleSheet(gUI.editors[1].styleSheet, LINE_NO, COL_NO);
|
||||
}
|
||||
|
||||
function testRemembered()
|
||||
|
|
|
@ -30,7 +30,12 @@ function runTests()
|
|||
|
||||
// Make sure Editor doesn't go into an infinite loop when
|
||||
// column isn't passed. See bug 941018.
|
||||
gUI.once("editor-selected", (event, editor) => {
|
||||
gUI.on("editor-selected", function editorSelected(event, editor) {
|
||||
if (editor.styleSheet != gUI.editors[1].styleSheet) {
|
||||
return;
|
||||
}
|
||||
gUI.off("editor-selected", editorSelected);
|
||||
|
||||
editor.getSourceEditor().then(() => {
|
||||
is(gUI.selectedEditor, gUI.editors[1], "second editor is selected");
|
||||
let {line, ch} = gUI.selectedEditor.sourceEditor.getCursor();
|
||||
|
|
|
@ -104,9 +104,13 @@ function togglePref(UI) {
|
|||
deferred.resolve();
|
||||
}
|
||||
})
|
||||
let editorsPromise = deferred.promise;
|
||||
|
||||
let selectedPromise = UI.once("editor-selected");
|
||||
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
return deferred.promise;
|
||||
|
||||
return promise.all([editorsPromise, selectedPromise]);
|
||||
}
|
||||
|
||||
function openEditor(editor) {
|
||||
|
|
|
@ -45,9 +45,10 @@ function addTabAndOpenStyleEditors(count, callback, uri) {
|
|||
let deferred = promise.defer();
|
||||
let currentCount = 0;
|
||||
let panel;
|
||||
addTabAndCheckOnStyleEditorAdded(p => panel = p, function () {
|
||||
addTabAndCheckOnStyleEditorAdded(p => panel = p, function (editor) {
|
||||
currentCount++;
|
||||
info(currentCount + " of " + count + " editors opened");
|
||||
info(currentCount + " of " + count + " editors opened: "
|
||||
+ editor.styleSheet.href);
|
||||
if (currentCount == count) {
|
||||
if (callback) {
|
||||
callback(panel);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" type="text/css" href="sourcemap-css/media-rules.css"
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Testing style editor media sidebar with source maps
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
@media screen and (max-width: 320px) {
|
||||
div {
|
||||
width: 100px; } }
|
||||
@media screen and (min-width: 1200px) {
|
||||
div {
|
||||
width: 400px; } }
|
||||
|
||||
/*# sourceMappingURL=media-rules.css.map */
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version": 3,
|
||||
"mappings": "AAIE,oCAA4C;EAD9C,GAAI;IAEA,KAAK,EAAE,KAAK;AAEd,qCAA4C;EAJ9C,GAAI;IAKA,KAAK,EAAE,KAAK",
|
||||
"sources": ["../sourcemap-sass/media-rules.scss"],
|
||||
"file": "media-rules.css"
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
$break-small: 320px;
|
||||
$break-large: 1200px;
|
||||
|
||||
div {
|
||||
@media screen and (max-width: $break-small) {
|
||||
width: 100px;
|
||||
}
|
||||
@media screen and (min-width: $break-large) {
|
||||
width: 400px;
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче