diff --git a/browser/devtools/shared/test/browser_css_color.js b/browser/devtools/shared/test/browser_css_color.js index 4f4f29be5f0e..f1dd1d537448 100644 --- a/browser/devtools/shared/test/browser_css_color.js +++ b/browser/devtools/shared/test/browser_css_color.js @@ -1,7 +1,6 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -const COLOR_UNIT_PREF = "devtools.defaultColorUnit"; const TEST_URI = "data:text/html;charset=utf-8,browser_css_color.js"; let {colorUtils} = devtools.require("devtools/css-color"); let origColorUnit; @@ -9,7 +8,6 @@ let origColorUnit; add_task(function*() { yield promiseTab("about:blank"); let [host, win, doc] = yield createHost("bottom", TEST_URI); - origColorUnit = Services.prefs.getCharPref(COLOR_UNIT_PREF); info("Creating a test canvas element to test colors"); let canvas = createTestCanvas(doc); @@ -49,23 +47,19 @@ function testColorUtils(canvas) { } function testToString(color, name, hex, hsl, rgb) { - switchColorUnit(colorUtils.CssColor.COLORUNIT.name); + color.colorUnit = colorUtils.CssColor.COLORUNIT.name; is(color.toString(), name, "toString() with authored type"); - switchColorUnit(colorUtils.CssColor.COLORUNIT.hex); + color.colorUnit = colorUtils.CssColor.COLORUNIT.hex; is(color.toString(), hex, "toString() with hex type"); - switchColorUnit(colorUtils.CssColor.COLORUNIT.hsl); + color.colorUnit = colorUtils.CssColor.COLORUNIT.hsl; is(color.toString(), hsl, "toString() with hsl type"); - switchColorUnit(colorUtils.CssColor.COLORUNIT.rgb); + color.colorUnit = colorUtils.CssColor.COLORUNIT.rgb; is(color.toString(), rgb, "toString() with rgb type"); } -function switchColorUnit(unit) { - Services.prefs.setCharPref(COLOR_UNIT_PREF, unit); -} - function testColorMatch(name, hex, hsl, rgb, rgba, canvas) { let target; let ctx = canvas.getContext("2d"); @@ -110,7 +104,6 @@ function testColorMatch(name, hex, hsl, rgb, rgba, canvas) { test(hex, "hex"); test(hsl, "hsl"); test(rgb, "rgb"); - switchColorUnit(origColorUnit); } function testProcessCSSString() { diff --git a/browser/devtools/shared/widgets/Tooltip.js b/browser/devtools/shared/widgets/Tooltip.js index bc58325e73c1..abe8a818c856 100644 --- a/browser/devtools/shared/widgets/Tooltip.js +++ b/browser/devtools/shared/widgets/Tooltip.js @@ -1020,6 +1020,11 @@ SwatchBasedEditorTooltip.prototype = { _onSwatchClick: function(event) { let swatch = this.swatches.get(event.target); + + if (event.shiftKey) { + event.stopPropagation(); + return; + } if (swatch) { this.activeSwatch = event.target; this.show(); diff --git a/browser/devtools/styleinspector/computed-view.js b/browser/devtools/styleinspector/computed-view.js index 2cc5a7747bce..07eb0cad1598 100644 --- a/browser/devtools/styleinspector/computed-view.js +++ b/browser/devtools/styleinspector/computed-view.js @@ -980,7 +980,6 @@ function PropertyView(aTree, aName) this.link = "https://developer.mozilla.org/CSS/" + aName; - this.templateMatchedSelectors = aTree.styleDocument.getElementById("templateMatchedSelectors"); this._propertyInfo = new PropertyInfo(aTree, aName); } @@ -1192,6 +1191,7 @@ PropertyView.prototype = { this.propertyInfo.value, { colorSwatchClass: "computedview-colorswatch", + colorClass: "computedview-color", urlClass: "theme-link" // No need to use baseURI here as computed URIs are never relative. }); @@ -1222,9 +1222,10 @@ PropertyView.prototype = { } this._matchedSelectorResponse = matched; - CssHtmlTree.processTemplate(this.templateMatchedSelectors, - this.matchedSelectorsContainer, this); + + this._buildMatchedSelectors(); this.matchedExpander.setAttribute("open", ""); + this.tree.inspector.emit("computed-view-property-expanded"); }).then(null, console.error); } else { @@ -1240,6 +1241,40 @@ PropertyView.prototype = { return this._matchedSelectorResponse; }, + _buildMatchedSelectors: function() { + let frag = this.element.ownerDocument.createDocumentFragment(); + + for (let selector of this.matchedSelectorViews) { + let p = createChild(frag, "p"); + let span = createChild(p, "span", { + class: "rule-link" + }); + let link = createChild(span, "a", { + target: "_blank", + class: "link theme-link", + title: selector.href, + sourcelocation: selector.source, + tabindex: "0", + textContent: selector.source + }); + link.addEventListener("click", selector.openStyleEditor, false); + link.addEventListener("keydown", selector.maybeOpenStyleEditor, false); + + let status = createChild(p, "span", { + dir: "ltr", + class: "rule-text theme-fg-color3 " + selector.statusClass, + title: selector.statusText, + textContent: selector.sourceText + }); + let valueSpan = createChild(status, "span", { + class: "other-property-value theme-fg-color1" + }); + valueSpan.appendChild(selector.outputFragment); + } + + this.matchedSelectorsContainer.appendChild(frag); + }, + /** * Provide access to the matched SelectorViews that we are currently * displaying. @@ -1279,6 +1314,9 @@ PropertyView.prototype = { */ onMatchedToggle: function PropertyView_onMatchedToggle(aEvent) { + if (aEvent.shiftKey) { + return; + } this.matchedExpanded = !this.matchedExpanded; this.refreshMatchedSelectors(); aEvent.preventDefault(); @@ -1328,6 +1366,9 @@ function SelectorView(aTree, aSelectorInfo) this.selectorInfo = aSelectorInfo; this._cacheStatusNames(); + this.openStyleEditor = this.openStyleEditor.bind(this); + this.maybeOpenStyleEditor = this.maybeOpenStyleEditor.bind(this); + this.updateSourceLink(); } @@ -1418,6 +1459,7 @@ SelectorView.prototype = { this.selectorInfo.name, this.selectorInfo.value, { colorSwatchClass: "computedview-colorswatch", + colorClass: "computedview-color", urlClass: "theme-link", baseURI: this.selectorInfo.rule.href }); @@ -1540,5 +1582,32 @@ SelectorView.prototype = { } }; +/** + * Create a child element with a set of attributes. + * + * @param {Element} aParent + * The parent node. + * @param {string} aTag + * The tag name. + * @param {object} aAttributes + * A set of attributes to set on the node. + */ +function createChild(aParent, aTag, aAttributes={}) { + let elt = aParent.ownerDocument.createElementNS(HTML_NS, aTag); + for (let attr in aAttributes) { + if (aAttributes.hasOwnProperty(attr)) { + if (attr === "textContent") { + elt.textContent = aAttributes[attr]; + } else if(attr === "child") { + elt.appendChild(aAttributes[attr]); + } else { + elt.setAttribute(attr, aAttributes[attr]); + } + } + } + aParent.appendChild(elt); + return elt; +} + exports.CssHtmlTree = CssHtmlTree; exports.PropertyView = PropertyView; diff --git a/browser/devtools/styleinspector/computedview.xhtml b/browser/devtools/styleinspector/computedview.xhtml index c922f3979a7f..121475537c57 100644 --- a/browser/devtools/styleinspector/computedview.xhtml +++ b/browser/devtools/styleinspector/computedview.xhtml @@ -72,38 +72,5 @@ &noPropertiesFound; - -
-