diff --git a/browser/devtools/styleinspector/CssHtmlTree.jsm b/browser/devtools/styleinspector/CssHtmlTree.jsm index f5f27e929b2..480cb54afc5 100644 --- a/browser/devtools/styleinspector/CssHtmlTree.jsm +++ b/browser/devtools/styleinspector/CssHtmlTree.jsm @@ -81,6 +81,9 @@ function CssHtmlTree(aStyleInspector) this.templateProperty = this.styleDocument.getElementById("templateProperty"); this.panel = aStyleInspector.panel; + // No results text. + this.noResults = this.styleDocument.getElementById("noResults"); + // The element that we're inspecting, and the document that it comes from. this.viewedElement = null; this.createStyleViews(); @@ -154,6 +157,9 @@ CssHtmlTree.prototype = { // Toggle for zebra striping _darkStripe: true, + // Number of visible properties + numVisibleProperties: 0, + get showOnlyUserStyles() { return this.onlyUserStylesCheckbox.checked; @@ -198,6 +204,9 @@ CssHtmlTree.prototype = { let propView = new PropertyView(this, name); CssHtmlTree.processTemplate(this.templateProperty, this.propertyContainer, propView, true); + if (propView.visible) { + this.numVisibleProperties++; + } propView.refreshAllSelectors(); this.propertyViews.push(propView); } @@ -209,6 +218,7 @@ CssHtmlTree.prototype = { } else { this.htmlComplete = true; this._panelRefreshTimeout = null; + this.noResults.hidden = this.numVisibleProperties > 0; Services.obs.notifyObservers(null, "StyleInspector-populated", null); } } @@ -227,6 +237,11 @@ CssHtmlTree.prototype = { this.win.clearTimeout(this._panelRefreshTimeout); } + this.noResults.hidden = true; + + // Reset visible property count + this.numVisibleProperties = 0; + // Reset zebra striping. this._darkStripe = true; @@ -246,6 +261,7 @@ CssHtmlTree.prototype = { this._panelRefreshTimeout = this.win.setTimeout(refreshView.bind(this), 15); } else { this._panelRefreshTimeout = null; + this.noResults.hidden = this.numVisibleProperties > 0; Services.obs.notifyObservers(null, "StyleInspector-populated", null); } } @@ -579,6 +595,7 @@ PropertyView.prototype = { return; } + this.tree.numVisibleProperties++; this.valueNode.innerHTML = this.propertyInfo.value; this.refreshAllSelectors(); }, diff --git a/browser/devtools/styleinspector/csshtmltree.xul b/browser/devtools/styleinspector/csshtmltree.xul index 45e66b44aa9..3ce7c9db6dd 100644 --- a/browser/devtools/styleinspector/csshtmltree.xul +++ b/browser/devtools/styleinspector/csshtmltree.xul @@ -63,6 +63,11 @@
+ + +
diff --git a/browser/devtools/styleinspector/test/browser/Makefile.in b/browser/devtools/styleinspector/test/browser/Makefile.in index f6c48b59dae..26728730c0a 100644 --- a/browser/devtools/styleinspector/test/browser/Makefile.in +++ b/browser/devtools/styleinspector/test/browser/Makefile.in @@ -51,6 +51,7 @@ _BROWSER_TEST_FILES = \ browser_bug683672.js \ browser_styleinspector_bug_672746_default_styles.js \ browser_styleinspector_bug_672744_search_filter.js \ + browser_styleinspector_bug_689759_no_results_placeholder.js \ browser_bug_692400_element_style.js \ browser_ruleview_editor.js \ browser_ruleview_inherit.js \ diff --git a/browser/devtools/styleinspector/test/browser/browser_styleinspector_bug_689759_no_results_placeholder.js b/browser/devtools/styleinspector/test/browser/browser_styleinspector_bug_689759_no_results_placeholder.js new file mode 100644 index 00000000000..0a7ae442d51 --- /dev/null +++ b/browser/devtools/styleinspector/test/browser/browser_styleinspector_bug_689759_no_results_placeholder.js @@ -0,0 +1,118 @@ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that the no results placeholder works properly. + +let doc; +let stylePanel; + +function createDocument() +{ + doc.body.innerHTML = '' + + 'Some styled text'; + doc.title = "Tests that the no results placeholder works properly"; + ok(window.StyleInspector, "StyleInspector exists"); + stylePanel = new StyleInspector(window); + Services.obs.addObserver(runStyleInspectorTests, "StyleInspector-opened", false); + stylePanel.createPanel(false, function() { + stylePanel.open(doc.body); + }); +} + +function runStyleInspectorTests() +{ + Services.obs.removeObserver(runStyleInspectorTests, "StyleInspector-opened", false); + + ok(stylePanel.isOpen(), "style inspector is open"); + + Services.obs.addObserver(SI_AddFilterText, "StyleInspector-populated", false); + + let span = doc.querySelector("#matches"); + ok(span, "captain, we have the matches span"); + + let htmlTree = stylePanel.cssHtmlTree; + stylePanel.selectNode(span); + + is(span, htmlTree.viewedElement, + "style inspector node matches the selected node"); + is(htmlTree.viewedElement, stylePanel.cssLogic.viewedElement, + "cssLogic node matches the cssHtmlTree node"); +} + +function SI_AddFilterText() +{ + Services.obs.removeObserver(SI_AddFilterText, "StyleInspector-populated", false); + + let iframe = stylePanel.iframe; + let searchbar = stylePanel.cssHtmlTree.searchField; + let searchTerm = "xxxxx"; + + Services.obs.addObserver(SI_checkPlaceholderVisible, "StyleInspector-populated", false); + info("setting filter text to \"" + searchTerm + "\""); + searchbar.focus(); + for each (let c in searchTerm) { + EventUtils.synthesizeKey(c, {}, iframe.contentWindow); + } +} + +function SI_checkPlaceholderVisible() +{ + Services.obs.removeObserver(SI_checkPlaceholderVisible, "StyleInspector-populated", false); + info("SI_checkPlaceholderVisible called"); + let placeholder = stylePanel.cssHtmlTree.noResults; + let iframe = stylePanel.iframe; + let display = iframe.contentWindow.getComputedStyle(placeholder).display; + + is(display, "block", "placeholder is visible"); + + SI_ClearFilterText(); +} + +function SI_ClearFilterText() +{ + let iframe = stylePanel.iframe; + let searchbar = stylePanel.cssHtmlTree.searchField; + + Services.obs.addObserver(SI_checkPlaceholderHidden, "StyleInspector-populated", false); + info("clearing filter text"); + searchbar.focus(); + searchbar.value = ""; + EventUtils.synthesizeKey("c", {}, iframe.contentWindow); +} + +function SI_checkPlaceholderHidden() +{ + Services.obs.removeObserver(SI_checkPlaceholderHidden, "StyleInspector-populated", false); + let placeholder = stylePanel.cssHtmlTree.noResults; + let iframe = stylePanel.iframe; + let display = iframe.contentWindow.getComputedStyle(placeholder).display; + + is(display, "none", "placeholder is hidden"); + + Services.obs.addObserver(finishUp, "StyleInspector-closed", false); + stylePanel.close(); +} + +function finishUp() +{ + Services.obs.removeObserver(finishUp, "StyleInspector-closed", false); + ok(!stylePanel.isOpen(), "style inspector is closed"); + doc = stylePanel = null; + gBrowser.removeCurrentTab(); + finish(); +} + +function test() +{ + waitForExplicitFinish(); + gBrowser.selectedTab = gBrowser.addTab(); + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); + doc = content.document; + waitForFocus(createDocument, content); + }, true); + + content.location = "data:text/html,no results placeholder test"; +} diff --git a/browser/locales/en-US/chrome/browser/devtools/styleinspector.dtd b/browser/locales/en-US/chrome/browser/devtools/styleinspector.dtd index 07bc28aad96..56427f2b788 100644 --- a/browser/locales/en-US/chrome/browser/devtools/styleinspector.dtd +++ b/browser/locales/en-US/chrome/browser/devtools/styleinspector.dtd @@ -18,6 +18,11 @@ - This is the link title shown in the hover tooltip. --> + + + diff --git a/browser/themes/gnomestripe/browser/devtools/csshtmltree.css b/browser/themes/gnomestripe/browser/devtools/csshtmltree.css index dd1df3f6102..0f6fa69edfa 100644 --- a/browser/themes/gnomestripe/browser/devtools/csshtmltree.css +++ b/browser/themes/gnomestripe/browser/devtools/csshtmltree.css @@ -224,6 +224,12 @@ background-color: rgba(0,0,0,.022); } +#noResults { + font-size: 18px; + margin-top: 5px; + text-align: center; +} + .header { color: -moz-dialogtext; background-color: -moz-dialog; diff --git a/browser/themes/pinstripe/browser/devtools/csshtmltree.css b/browser/themes/pinstripe/browser/devtools/csshtmltree.css index 626f146b733..043739ab2b6 100644 --- a/browser/themes/pinstripe/browser/devtools/csshtmltree.css +++ b/browser/themes/pinstripe/browser/devtools/csshtmltree.css @@ -222,6 +222,12 @@ background-color: rgba(0,0,0,.022); } +#noResults { + font-size: 18px; + margin-top: 5px; + text-align: center; +} + .header { color: -moz-dialogtext; background-color: -moz-dialog; diff --git a/browser/themes/winstripe/browser/devtools/csshtmltree.css b/browser/themes/winstripe/browser/devtools/csshtmltree.css index 7969e2ad7a0..0fa362039d0 100644 --- a/browser/themes/winstripe/browser/devtools/csshtmltree.css +++ b/browser/themes/winstripe/browser/devtools/csshtmltree.css @@ -223,6 +223,12 @@ background-color: rgba(0,0,0,.022); } +#noResults { + font-size: 18px; + margin-top: 5px; + text-align: center; +} + .header { color: -moz-dialogtext; background-color: -moz-dialog;