From 1c1e53ed43b37ab6a5b044e9664123f8af98144a Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Fri, 27 Jun 2014 08:58:13 -0700 Subject: [PATCH] Bug 1011598 fix marks and status buttons for toolbar overflow menu, r=Gijs --- browser/base/content/browser-social.js | 15 ++-- browser/base/content/socialmarks.xml | 101 ++++++++++++------------- browser/modules/PanelFrame.jsm | 14 +++- 3 files changed, 67 insertions(+), 63 deletions(-) diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js index d00d19dc6111..0ce93ebad889 100644 --- a/browser/base/content/browser-social.js +++ b/browser/base/content/browser-social.js @@ -1182,7 +1182,6 @@ SocialStatus = { let button = widget.forWindow(window).node; if (button) { // we only grab the first notification, ignore all others - let place = CustomizableUI.getPlaceForItem(button); let provider = Social._getProviderFromOrigin(origin); let icons = provider.ambientNotificationIcons; let iconNames = Object.keys(icons); @@ -1192,7 +1191,7 @@ SocialStatus = { // ambient notification and profile changes. let iconURL = provider.icon32URL || provider.iconURL; let tooltiptext; - if (!notif || place == "palette") { + if (!notif || !widget.areaType) { button.style.listStyleImage = "url(" + iconURL + ")"; button.setAttribute("badge", ""); button.setAttribute("aria-label", ""); @@ -1249,8 +1248,12 @@ SocialMarks = { update: function() { // signal each button to update itself let currentButtons = document.querySelectorAll('toolbarbutton[type="socialmark"]'); - for (let elt of currentButtons) - elt.update(); + for (let elt of currentButtons) { + // make sure we can call update since the xbl is not completely bound if + // the button is in overflow, until the button becomes visible. + if (elt.update) + elt.update(); + } }, updatePanelButtons: function() { @@ -1263,7 +1266,9 @@ SocialMarks = { if (!widget) continue; let node = widget.forWindow(window).node; - if (node) + // xbl binding is not complete on startup when buttons are not in toolbar, + // verify update is available + if (node && node.update) node.update(); } }, diff --git a/browser/base/content/socialmarks.xml b/browser/base/content/socialmarks.xml index dddf6e86a526..a2095266a85b 100644 --- a/browser/base/content/socialmarks.xml +++ b/browser/base/content/socialmarks.xml @@ -17,18 +17,27 @@ xbl:inherits="xbl:text=label,accesskey,wrap"/> - false - false + + // if we overflow, we have to reset the button. unfortunately we cannot + // use a widget listener because we need to do this *after* the node is + // moved, and the event happens before the node is moved. + this.update(); + + + + let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id")); + return widgetGroup.forWindow(window).anchor; + + + + + let provider = Social._getProviderFromOrigin(this.getAttribute("origin")); + return !provider.getPageSize("marks"); + + - let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id")); - let widget = widgetGroup.forWindow(window); - this.inMenuPanel = widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL; - if (this.inMenuPanel) { - widget.node.setAttribute("closemenu", "none"); - return document.getElementById("PanelUI-socialapi"); - } return document.getAnonymousElementByAttribute(this, "anonid", "panel"); @@ -41,7 +50,6 @@ let provider = Social._getProviderFromOrigin(this.getAttribute("origin")); let size = provider.getPageSize("marks"); let {width, height} = size ? size : {width: 330, height: 100}; - this._useDynamicResizer = !size; this._frame = SharedFrame.createFrame( notificationFrameId, /* frame name */ @@ -89,8 +97,8 @@ let provider = this.provider; // we cannot size the image when we apply it via listStyleImage, so // use the toolbar image - let place = CustomizableUI.getPlaceForItem(this); - val = val && place != "palette"; + let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id")); + val = val && !!widgetGroup.areaType; let icon = val ? provider.markedIcon : provider.unmarkedIcon; let iconURL = icon || provider.icon32URL || provider.iconURL; this.setAttribute("image", iconURL); @@ -112,24 +120,26 @@ // do we have a savable page loaded? let aURI = gBrowser.currentURI; - this.disabled = !aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https')); - if (this.disabled) { + let disabled = !aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https')); + // when overflowed in toolbar, we must have the attribute set + if (disabled) { + this.setAttribute("disabled", "true"); this.isMarked = false; } else { + this.removeAttribute("disabled"); Social.isURIMarked(provider.origin, aURI, (isMarked) => { this.isMarked = isMarked; }); } this.content.setAttribute("origin", provider.origin); - if (!this.inMenuPanel) { - let panel = this.panel; - // if customization is currently happening, we may not have a panel - // that we can hide - if (panel.hidePopup) { - panel.hidePopup(); - panel.hidden = true; - } + + let panel = this.panel; + // if customization is currently happening, we may not have a panel + // that we can hide + if (panel.hidePopup) { + panel.hidePopup(); + panel.hidden = true; } this.pageData = null; ]]> @@ -157,7 +167,7 @@ this._loading = false; this.content.removeEventListener("DOMContentLoaded", DOMContentLoaded, true); // add our resizer after the dom is ready - if (!this.inMenuPanel && this._useDynamicResizer) { + if (this._useDynamicResizer) { let DynamicResizeWatcher = Cu.import("resource:///modules/Social.jsm", {}).DynamicResizeWatcher; this._dynamicResizer = new DynamicResizeWatcher(); this._dynamicResizer.start(this.panel, this.content); @@ -213,27 +223,13 @@ frameIter = frameIter.nextElementSibling; } - // if we're a slice in the hambuger, use that panel instead - let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id")); - let widget = widgetGroup.forWindow(window); - let inMenuPanel = widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL; - if (inMenuPanel) { - PanelUI.showSubView("PanelUI-socialapi", widget.node, - CustomizableUI.AREA_PANEL); - } else { - let anchor = document.getAnonymousElementByAttribute(this, "class", "toolbarbutton-icon"); + let anchor = document.getAnonymousElementByAttribute(this._anchor, "class", "toolbarbutton-icon"); + // Bug 849216 - open the popup in a setTimeout so we avoid the auto-rollup + // handling from preventing it being opened in some cases. + setTimeout(() => { panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false); - this.setAttribute("open", "true"); - } - if (aResetOnClose) { - let evName = inMenuPanel ? "ViewHiding": "popuphidden"; - let _hidden = () => { - panel.removeEventListener(evName, _hidden); - this.update(); - }; - panel.addEventListener(evName, _hidden, false); - } - ]]> + }, 0); + ]]> @@ -241,8 +237,7 @@ { this.content.removeEventListener("load", panelBrowserOnload, true); this.dispatchPanelEvent("socialFrameShow"); - if (!this.inMenuPanel && this._useDynamicResizer) + if (this._useDynamicResizer) sizeSocialPanelToContent(this.panel, this.content); }; this.content.addEventListener("load", panelBrowserOnload, true); @@ -328,24 +323,22 @@ this.setAttribute("image", uri.spec); } break; - case "ViewShowing": - this.onShown(); - break; - case "ViewHiding": - this.dispatchPanelEvent("socialFrameHide"); - break; } ]]> +