Bug 1180584 - Support multiple badges on the Hamburger menu button. r=markh

This commit is contained in:
Edouard Oger 2015-08-06 14:47:32 +10:00
Родитель 28ed82509d
Коммит be5abed620
10 изменённых файлов: 112 добавлений и 19 удалений

Просмотреть файл

@ -277,6 +277,7 @@ let gFxAccounts = {
this.panelUIFooter.removeAttribute("fxastatus");
this.panelUIFooter.removeAttribute("fxaprofileimage");
this.panelUIAvatar.style.removeProperty("list-style-image");
let showErrorBadge = false;
if (!this._inCustomizationMode && userData) {
// At this point we consider the user as logged-in (but still can be in an error state)
@ -285,6 +286,7 @@ let gFxAccounts = {
this.panelUIFooter.setAttribute("fxastatus", "error");
this.panelUILabel.setAttribute("label", errorLabel);
this.panelUIStatus.setAttribute("tooltiptext", tooltipDescription);
showErrorBadge = true;
} else {
this.panelUIFooter.setAttribute("fxastatus", "signedin");
this.panelUILabel.setAttribute("label", userData.email);
@ -294,6 +296,11 @@ let gFxAccounts = {
this.panelUIFooter.setAttribute("fxaprofileimage", "enabled");
}
}
if (showErrorBadge) {
gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_FXA, "fxa-needs-authentication");
} else {
gMenuButtonBadgeManager.removeBadge(gMenuButtonBadgeManager.BADGEID_FXA);
}
}
let updateWithProfile = (profile) => {

Просмотреть файл

@ -2569,6 +2569,47 @@ function PageProxyClickHandler(aEvent)
middleMousePaste(aEvent);
}
let gMenuButtonBadgeManager = {
BADGEID_APPUPDATE: "update",
BADGEID_FXA: "fxa",
fxaBadge: null,
appUpdateBadge: null,
_showBadge: function () {
let badgeToShow = this.appUpdateBadge || this.fxaBadge;
if (badgeToShow) {
PanelUI.menuButton.setAttribute("badge-status", badgeToShow);
} else {
PanelUI.menuButton.removeAttribute("badge-status");
}
},
_changeBadge: function (badgeId, badgeStatus = null) {
if (badgeId == this.BADGEID_APPUPDATE) {
this.appUpdateBadge = badgeStatus;
} else if (badgeId == this.BADGEID_FXA) {
this.fxaBadge = badgeStatus;
} else {
Cu.reportError("This badge ID is unknown!");
}
this._showBadge();
},
addBadge: function (badgeId, badgeStatus) {
if (!badgeStatus) {
Cu.reportError("badgeStatus must be defined");
return;
}
this._changeBadge(badgeId, badgeStatus);
},
removeBadge: function (badgeId) {
this._changeBadge(badgeId);
}
};
// Setup the hamburger button badges for updates, if enabled.
let gMenuButtonUpdateBadge = {
enabled: false,
@ -2585,7 +2626,6 @@ let gMenuButtonUpdateBadge = {
} catch (e) {
this.badgeWaitTime = 345600; // 4 days
}
PanelUI.menuButton.classList.add("badged-button");
Services.obs.addObserver(this, "update-staged", false);
Services.obs.addObserver(this, "update-downloaded", false);
}
@ -2597,7 +2637,6 @@ let gMenuButtonUpdateBadge = {
if (this.enabled) {
Services.obs.removeObserver(this, "update-staged");
Services.obs.removeObserver(this, "update-downloaded");
PanelUI.panel.removeEventListener("popupshowing", this, true);
this.enabled = false;
}
},
@ -2645,10 +2684,8 @@ let gMenuButtonUpdateBadge = {
displayBadge: function (succeeded) {
let status = succeeded ? "succeeded" : "failed";
PanelUI.menuButton.setAttribute("update-status", status);
if (!succeeded) {
PanelUI.menuButton.setAttribute("badge", "!");
}
let badgeStatus = "update-" + status;
gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_APPUPDATE, badgeStatus);
let stringId;
let updateButtonText;
@ -2667,15 +2704,6 @@ let gMenuButtonUpdateBadge = {
updateButton.setAttribute("label", updateButtonText);
updateButton.setAttribute("update-status", status);
updateButton.hidden = false;
PanelUI.panel.addEventListener("popupshowing", this, true);
},
handleEvent: function(e) {
if (e.type === "popupshowing") {
PanelUI.menuButton.removeAttribute("badge");
PanelUI.panel.removeEventListener("popupshowing", this, true);
}
}
};

Просмотреть файл

@ -960,7 +960,7 @@
class="chromeclass-toolbar-additional"
removable="false">
<toolbarbutton id="PanelUI-menu-button"
class="toolbarbutton-1"
class="toolbarbutton-1 badged-button"
consumeanchor="PanelUI-button"
label="&brandShortName;"
tooltiptext="&appmenu.tooltip;"/>

Просмотреть файл

@ -509,3 +509,4 @@ support-files =
support-files =
readerModeArticle.html
[browser_domFullscreen_fullscreenMode.js]
[browser_menuButtonBadgeManager.js]

Просмотреть файл

@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let menuButton = document.getElementById("PanelUI-menu-button");
add_task(function* testButtonActivities() {
is(menuButton.hasAttribute("badge-status"), false, "Should not have a badge status");
is(menuButton.hasAttribute("badge"), false, "Should not have the badge attribute set");
gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_FXA, "fxa-needs-authentication");
is(menuButton.getAttribute("badge-status"), "fxa-needs-authentication", "Should have fxa-needs-authentication badge status");
gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_APPUPDATE, "update-succeeded");
is(menuButton.getAttribute("badge-status"), "update-succeeded", "Should have update-succeeded badge status (update > fxa)");
gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_APPUPDATE, "update-failed");
is(menuButton.getAttribute("badge-status"), "update-failed", "Should have update-failed badge status");
gMenuButtonBadgeManager.addBadge("unknownbadge", "attr");
is(menuButton.getAttribute("badge-status"), "update-failed", "Should not have changed badge status");
gMenuButtonBadgeManager.removeBadge(gMenuButtonBadgeManager.BADGEID_APPUPDATE);
is(menuButton.getAttribute("badge-status"), "fxa-needs-authentication", "Should have fxa-needs-authentication badge status");
gMenuButtonBadgeManager.removeBadge(gMenuButtonBadgeManager.BADGEID_FXA);
is(menuButton.hasAttribute("badge-status"), false, "Should not have a badge status");
});

Просмотреть файл

@ -105,6 +105,7 @@ browser.jar:
skin/classic/browser/Toolbar-small.png
skin/classic/browser/undoCloseTab.png (../shared/undoCloseTab.png)
skin/classic/browser/update-badge.svg (../shared/update-badge.svg)
skin/classic/browser/update-badge-failed.svg (../shared/update-badge-failed.svg)
skin/classic/browser/urlbar-arrow.png (../shared/urlbar-arrow.png)
skin/classic/browser/urlbar-arrow@2x.png (../shared/urlbar-arrow@2x.png)
skin/classic/browser/session-restore.svg (../shared/incontent-icons/session-restore.svg)

Просмотреть файл

@ -138,6 +138,7 @@ browser.jar:
skin/classic/browser/undoCloseTab.png (../shared/undoCloseTab.png)
skin/classic/browser/undoCloseTab@2x.png (../shared/undoCloseTab@2x.png)
skin/classic/browser/update-badge.svg (../shared/update-badge.svg)
skin/classic/browser/update-badge-failed.svg (../shared/update-badge-failed.svg)
skin/classic/browser/urlbar-history-dropmarker.png
skin/classic/browser/urlbar-history-dropmarker@2x.png
skin/classic/browser/urlbar-arrow.png (../shared/urlbar-arrow.png)

Просмотреть файл

@ -101,15 +101,35 @@
border-image-source: linear-gradient(transparent, rgba(100%,100%,100%,.2) 20%, rgba(100%,100%,100%,.2) 80%, transparent);
}
#PanelUI-menu-button[update-status="succeeded"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
#PanelUI-menu-button[badge-status] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
display: -moz-box;
background-image: url(chrome://browser/skin/update-badge.svg);
background-color: #74BF43;
height: 10px;
width: 10px;
background-size: contain;
border: none;
}
#PanelUI-menu-button[badge-status="update-succeeded"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
background-image: url(chrome://browser/skin/update-badge.svg);
background-color: #74BF43;
}
#PanelUI-menu-button[badge-status="update-failed"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
background-image: url(chrome://browser/skin/update-badge-failed.svg);
background-color: #D90000;
}
#PanelUI-menu-button[badge-status="fxa-needs-authentication"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
background-color: transparent;
background-image: url(chrome://browser/skin/warning.svg);
box-shadow: none;
filter: drop-shadow(0 1px 0 hsla(206, 50%, 10%, .15));
}
#PanelUI-menu-button[badge-status="fxa-needs-authentication"] > .toolbarbutton-badge-stack > .toolbarbutton-badge:-moz-window-inactive {
filter: none;
}
.panel-subviews {
padding: 4px;
background-clip: padding-box;

Просмотреть файл

@ -0,0 +1,6 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<svg xmlns="http://www.w3.org/2000/svg" width="10px" height="10px">
<path d="M5,6C4.2,6,3.5,6.7,3.5,7.5S4.2,9,5,9s1.5-0.7,1.5-1.5S5.8,6,5,6z M5,5L5,5c0.6,0,1-0.4,1-1l0.2-2.8 C6.2,0.5,5.7,0,5,0S3.8,0.5,3.8,1.2L4,4C4,4.6,4.4,5,5,5z" fill="#fff"/>
</svg>

После

Ширина:  |  Высота:  |  Размер: 466 B

Просмотреть файл

@ -143,6 +143,7 @@ browser.jar:
skin/classic/browser/undoCloseTab.png (../shared/undoCloseTab.png)
skin/classic/browser/undoCloseTab@2x.png (../shared/undoCloseTab@2x.png)
skin/classic/browser/update-badge.svg (../shared/update-badge.svg)
skin/classic/browser/update-badge-failed.svg (../shared/update-badge-failed.svg)
skin/classic/browser/urlbar-arrow.png (../shared/urlbar-arrow.png)
skin/classic/browser/urlbar-arrow@2x.png (../shared/urlbar-arrow@2x.png)
skin/classic/browser/urlbar-popup-blocked.png