diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 8bfb31fed831..4528cb72b5a6 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1330,9 +1330,11 @@ pref("devtools.tilt.outro_transition", true); // 'Open Recent'-menu. // - showTrailingSpace: Whether to highlight trailing space or not. // - enableCodeFolding: Whether to enable code folding or not. +// - enableAutocompletion: Whether to enable JavaScript autocompletion. pref("devtools.scratchpad.recentFilesMax", 10); pref("devtools.scratchpad.showTrailingSpace", false); pref("devtools.scratchpad.enableCodeFolding", true); +pref("devtools.scratchpad.enableAutocompletion", true); // Enable the Style Editor. pref("devtools.styleeditor.enabled", true); diff --git a/browser/base/content/browser-fullScreen.js b/browser/base/content/browser-fullScreen.js index 4e416ef0437e..15bfbf7f9158 100644 --- a/browser/base/content/browser-fullScreen.js +++ b/browser/base/content/browser-fullScreen.js @@ -566,6 +566,8 @@ var FullScreen = { navbar.appendChild(fullscreenctls); } fullscreenctls.hidden = aShow; + + ToolbarIconColor.inferFromText(); } }; XPCOMUtils.defineLazyGetter(FullScreen, "useLionFullScreen", function() { diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js index 47e4a4219d0f..e3ec47491e5d 100644 --- a/browser/base/content/browser-social.js +++ b/browser/base/content/browser-social.js @@ -69,7 +69,7 @@ SocialUI = { Services.prefs.addObserver("social.toast-notifications.enabled", this, false); gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true); - document.getElementById("PanelUI-popup").addEventListener("popupshown", SocialMarks.updatePanelButtons, true); + PanelUI.panel.addEventListener("popupshown", SocialUI.updateState, true); // menupopups that list social providers. we only populate them when shown, // and if it has not been done already. @@ -102,7 +102,7 @@ SocialUI = { Services.prefs.removeObserver("social.toast-notifications.enabled", this); - document.getElementById("PanelUI-popup").removeEventListener("popupshown", SocialMarks.updatePanelButtons, true); + PanelUI.panel.removeEventListener("popupshown", SocialUI.updateState, true); document.getElementById("viewSidebarMenu").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true); document.getElementById("social-statusarea-popup").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true); @@ -288,7 +288,7 @@ SocialUI = { // called on tab/urlbar/location changes and after customization. Update // anything that is tab specific. updateState: function() { - if (!this.enabled) + if (!SocialUI.enabled) return; SocialMarks.update(); SocialShare.update(); @@ -432,6 +432,12 @@ SocialFlyout = { } SocialShare = { + // Share panel may be attached to the overflow or menu button depending on + // customization, we need to manage open state of the anchor. + get anchor() { + let widget = CustomizableUI.getWidget("social-share-button"); + return widget.forWindow(window).anchor; + }, get panel() { return document.getElementById("social-share-panel"); }, @@ -523,7 +529,15 @@ SocialShare = { }, get shareButton() { - return document.getElementById("social-share-button"); + // web-panels (bookmark/sidebar) don't include customizableui, so + // nsContextMenu fails when accessing shareButton, breaking + // browser_bug409481.js. + if (!window.CustomizableUI) + return null; + let widget = CustomizableUI.getWidget("social-share-button"); + if (!widget || !widget.areaType) + return null; + return widget.forWindow(window).node; }, canSharePage: function(aURI) { @@ -540,23 +554,29 @@ SocialShare = { let shareButton = this.shareButton; shareButton.hidden = !SocialUI.enabled || [p for (p of Social.providers) if (p.shareURL)].length == 0; - shareButton.disabled = shareButton.hidden || !this.canSharePage(gBrowser.currentURI); + let disabled = shareButton.hidden || !this.canSharePage(gBrowser.currentURI); - // also update the relevent command's disabled state so the keyboard + // 1. update the relevent command's disabled state so the keyboard // shortcut only works when available. + // 2. If the button has been relocated to a place that is not visible by + // default (e.g. menu panel) then the disabled attribute will not update + // correctly based on the command, so we update the attribute directly as. let cmd = document.getElementById("Social:SharePage"); - if (shareButton.disabled) + if (disabled) { cmd.setAttribute("disabled", "true"); - else + shareButton.setAttribute("disabled", "true"); + } else { cmd.removeAttribute("disabled"); + shareButton.removeAttribute("disabled"); + } }, onShowing: function() { - this.shareButton.setAttribute("open", "true"); + this.anchor.setAttribute("open", "true"); }, onHidden: function() { - this.shareButton.removeAttribute("open"); + this.anchor.removeAttribute("open"); this.iframe.setAttribute("src", "data:text/plain;charset=utf8,"); this.currentShare = null; }, @@ -670,8 +690,7 @@ SocialShare = { iframe.setAttribute("origin", provider.origin); iframe.setAttribute("src", shareEndpoint); - let navBar = document.getElementById("nav-bar"); - let anchor = document.getAnonymousElementByAttribute(this.shareButton, "class", "toolbarbutton-icon"); + let anchor = document.getAnonymousElementByAttribute(this.anchor, "class", "toolbarbutton-icon"); this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false); Social.setErrorListener(iframe, this.setErrorMessage.bind(this)); } @@ -1357,7 +1376,6 @@ SocialMarks = { // querySelectorAll does not work on the menu panel the panel, so we have to // do this the hard way. let providers = SocialMarks.getProviders(); - let panel = document.getElementById("PanelUI-popup"); for (let p of providers) { let widgetId = SocialMarks._toolbarHelper.idFromOrigin(p.origin); let widget = CustomizableUI.getWidget(widgetId); diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 743995d28b1b..7a39a302ae2c 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -947,6 +947,8 @@ var gBrowserInit = { } #endif + ToolbarIconColor.init(); + // Wait until chrome is painted before executing code not critical to making the window visible this._boundDelayedStartup = this._delayedStartup.bind(this, mustLoadSidebar); window.addEventListener("MozAfterPaint", this._boundDelayedStartup); @@ -1283,6 +1285,8 @@ var gBrowserInit = { TabsInTitlebar.uninit(); + ToolbarIconColor.uninit(); + var enumerator = Services.wm.getEnumerator(null); enumerator.getNext(); if (!enumerator.hasMoreElements()) { @@ -4296,6 +4300,8 @@ function setToolbarVisibility(toolbar, isVisible, persist=true) { PlacesToolbarHelper.init(); BookmarkingUI.onToolbarVisibilityChange(); gBrowser.updateWindowResizers(); + if (isVisible) + ToolbarIconColor.inferFromText(); } var TabsInTitlebar = { @@ -4540,6 +4546,8 @@ var TabsInTitlebar = { titlebar.style.marginBottom = ""; menubar.style.paddingBottom = ""; } + + ToolbarIconColor.inferFromText(); }, _sizePlaceholder: function (type, width) { @@ -7192,3 +7200,71 @@ function BrowserOpenNewTabOrWindow(event) { BrowserOpenTab(); } } + +let ToolbarIconColor = { + init: function () { + this._initialized = true; + + window.addEventListener("activate", this); + window.addEventListener("deactivate", this); + Services.obs.addObserver(this, "lightweight-theme-styling-update", false); + + // If the window isn't active now, we assume that it has never been active + // before and will soon become active such that inferFromText will be + // called from the initial activate event. + if (Services.focus.activeWindow == window) + this.inferFromText(); + }, + + uninit: function () { + this._initialized = false; + + window.removeEventListener("activate", this); + window.removeEventListener("deactivate", this); + Services.obs.removeObserver(this, "lightweight-theme-styling-update"); + }, + + handleEvent: function (event) { + switch (event.type) { + case "activate": + case "deactivate": + this.inferFromText(); + break; + } + }, + + observe: function (aSubject, aTopic, aData) { + switch (aTopic) { + case "lightweight-theme-styling-update": + // inferFromText needs to run after LightweightThemeConsumer.jsm's + // lightweight-theme-styling-update observer. + setTimeout(() => { this.inferFromText(); }, 0); + break; + } + }, + + inferFromText: function () { + if (!this._initialized) + return; + + function parseRGB(aColorString) { + let rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/); + rgb.shift(); + return rgb.map(x => parseInt(x)); + } + + let toolbarSelector = "#navigator-toolbox > toolbar:not([collapsed=true]):not(#addon-bar)"; +#ifdef XP_MACOSX + toolbarSelector += ":not([type=menubar])"; +#endif + + for (let toolbar of document.querySelectorAll(toolbarSelector)) { + let [r, g, b] = parseRGB(getComputedStyle(toolbar).color); + let luminance = 0.2125 * r + 0.7154 * g + 0.0721 * b; + if (luminance <= 110) + toolbar.removeAttribute("brighttext"); + else + toolbar.setAttribute("brighttext", "true"); + } + } +} diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 1a9bf7fadc65..2d48525e27f0 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -899,10 +899,10 @@