Bug 831737 Re-write and simplify newmailalert.{js|xul|css} (Backport changes from SeaMonkey Bug 404580) ui-r=paenglab r=mkmelin.

--HG--
rename : suite/mailnews/newmailalert.css => mailnews/base/content/newmailalert.css
rename : suite/mailnews/newmailalert.js => mailnews/base/content/newmailalert.js
rename : suite/mailnews/newmailalert.xul => mailnews/base/content/newmailalert.xul
This commit is contained in:
Philip Chee 2013-02-01 21:37:17 +08:00
Родитель fdeb4e8429
Коммит f14240ea43
13 изменённых файлов: 75 добавлений и 321 удалений

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

@ -214,11 +214,6 @@ pref("general.autoScroll", true);
pref("mail.shell.checkDefaultClient", true);
pref("mail.spellcheck.inline", true);
pref("mail.biff.alert.show_preview", true);
pref("mail.biff.alert.show_subject", true);
pref("mail.biff.alert.show_sender", true);
pref("mail.biff.alert.preview_length", 40);
pref("mail.folder.views.version", 0);
// target folder URI used for the last move or copy
@ -400,7 +395,7 @@ pref("profile.force.migration", "");
// prefs to control the mail alert notification
pref("alerts.slideIncrementTime", 50);
pref("alerts.totalOpenTime", 3000);
pref("alerts.totalOpenTime", 10000);
// analyze urls in mail messages for scams
pref("mail.phishing.detection.enabled", true);

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

@ -1,190 +0,0 @@
/* 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/. */
Components.utils.import("resource://gre/modules/Services.jsm");
const HORIZONTAL = 1;
const LEFT = 2;
const TOP = 4;
var gSlideTime = 50;
var gNumNewMsgsToShowInAlert = 4; // the more messages we show in the alert, the larger it will be
var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
var gAlertListener = null;
var gPendingPreviewFetchRequests = 0;
var gUserInitiated = false;
var gFadeIncrement = .05;
var gOrigin = 0;
function prefillAlertInfo()
{
// unwrap all the args....
// arguments[0] --> array of folders with new mail
// arguments[1] --> the observer to call back with notifications about the alert
// arguments[2] --> user initiated boolean. true if the user initiated opening the alert
// (which means skip the fade effect and don't auto close the alert)
// arguments[3] --> the alert origin returned by the look and feel
var foldersWithNewMail = window.arguments[0];
gAlertListener = window.arguments[1];
gUserInitiated = window.arguments[2];
gOrigin = window.arguments[3];
// For now just grab the first folder which should be a root folder
// for the account that has new mail. If we can't find a folder, just
// return to avoid the exception and empty dialog in upper left-hand corner.
let rootFolder;
if (foldersWithNewMail && foldersWithNewMail.Count() > 0)
rootFolder = foldersWithNewMail.GetElementAt(0)
.QueryInterface(Components.interfaces.nsIWeakReference)
.QueryReferent(Components.interfaces.nsIMsgFolder);
else
return;
// generate an account label string based on the root folder
var label = document.getElementById('alertTitle');
var totalNumNewMessages = rootFolder.getNumNewMessages(true);
label.value = document.getElementById('bundle_messenger').getFormattedString(totalNumNewMessages == 1 ? "newMailNotification_message" : "newMailNotification_messages",
[rootFolder.prettiestName, totalNumNewMessages]);
// this is really the root folder and we have to walk through the list to find the real folder that has new mail in it...:(
var allFolders = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
rootFolder.ListDescendents(allFolders);
var numFolders = allFolders.Count();
var folderSummaryInfoEl = document.getElementById('folderSummaryInfo');
folderSummaryInfoEl.mMaxMsgHdrsInPopup = gNumNewMsgsToShowInAlert;
for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
{
var folder = allFolders.GetElementAt(folderIndex).QueryInterface(Components.interfaces.nsIMsgFolder);
const nsMsgFolderFlags = Components.interfaces.nsMsgFolderFlags;
if (folder.hasNewMessages && !(folder.flags & nsMsgFolderFlags.Virtual))
{
var asyncFetch = {};
folderSummaryInfoEl.parseFolder(folder, new urlListener(folder), asyncFetch);
if (asyncFetch.value)
gPendingPreviewFetchRequests++;
}
}
}
function urlListener(aFolder)
{
this.mFolder = aFolder;
}
urlListener.prototype = {
OnStartRunningUrl: function(aUrl)
{
},
OnStopRunningUrl: function(aUrl, aExitCode)
{
var folderSummaryInfoEl = document.getElementById('folderSummaryInfo');
var asyncFetch = {};
folderSummaryInfoEl.parseFolder(this.mFolder, null, asyncFetch);
gPendingPreviewFetchRequests--;
// when we are done running all of our urls for fetching the preview text,
// start the alert.
if (!gPendingPreviewFetchRequests)
showAlert();
}
}
function onAlertLoad()
{
prefillAlertInfo();
// read out our initial settings from prefs.
try
{
gSlideTime = Services.prefs.getIntPref("alerts.slideIncrementTime");
gOpenTime = Services.prefs.getIntPref("alerts.totalOpenTime");
} catch (ex) {}
// bogus call to make sure the window is moved offscreen until we are ready for it.
resizeAlert(true);
// if we aren't waiting to fetch preview text, then go ahead and
// start showing the alert.
if (!gPendingPreviewFetchRequests)
setTimeout(showAlert, 0); // let the JS thread unwind, to give layout
// a chance to recompute the styles and widths for our alert text.
}
// If the user initiated the alert, show it right away, otherwise start opening the alert with
// the fade effect.
function showAlert()
{
if (!gUserInitiated) // set the initial opacity before we resize the window
document.getElementById('alertContainer').style.opacity = 0;
// resize the alert based on our current content
resizeAlert(false);
if (document.getElementById('folderSummaryInfo').hasMessages)
{
if (!gUserInitiated) // don't fade in if the user opened the alert
setTimeout(fadeOpen, gSlideTime);
}
else
closeAlert(); // no mail, so don't bother showing the alert...
}
function resizeAlert(aMoveOffScreen)
{
// sizeToContent is not working. It isn't honoring the max widths we are attaching to our inner
// objects like the folder summary element. While the folder summary element is cropping,
// sizeToContent ends up thinking the window needs to be much wider than it should be.
// use resizeTo and make up our measurements...
//sizeToContent();
// Use the wider of the alert groove and the folderSummaryInfo box, then
// add on the width of alertImageBox + some small amount of fudge. For the height,
// just use the size of the alertBox, that appears to be pretty accurate.
var windowWidth = Math.max (document.getBoxObjectFor(document.getElementById('alertGroove')).width,
document.getBoxObjectFor(document.getElementById('folderSummaryInfo')).width);
resizeTo(windowWidth + document.getBoxObjectFor(document.getElementById('alertImageBox')).width + 30,
document.getBoxObjectFor(document.getElementById('alertBox')).height + 10);
// leftover hack to get the window properly hidden when we first open it
if (aMoveOffScreen)
window.outerHeight = 1;
// Determine position and move window
var x = gOrigin & LEFT ? screen.availLeft :
(screen.availLeft + screen.availWidth - window.outerWidth);
var y = gOrigin & TOP ? screen.availTop :
(screen.availTop + screen.availHeight - window.outerHeight);
window.moveTo(x, y);
}
function fadeOpen()
{
var alertContainer = document.getElementById('alertContainer');
var newOpacity = parseFloat(window.getComputedStyle(alertContainer, "").opacity) + gFadeIncrement;
alertContainer.style.opacity = newOpacity;
if (newOpacity < 1.0)
setTimeout(fadeOpen, gSlideTime);
else // switch gears and start closing the alert
setTimeout(fadeClose, gOpenTime);
}
function fadeClose()
{
var alertContainer = document.getElementById('alertContainer');
var newOpacity = parseFloat(window.getComputedStyle(alertContainer, "").opacity) - gFadeIncrement;
alertContainer.style.opacity = newOpacity;
if (newOpacity <= 0)
closeAlert();
else
setTimeout(fadeClose, gSlideTime);
}
function closeAlert()
{
if (gAlertListener)
gAlertListener.observe(null, "alertfinished", "");
window.close();
}

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

@ -1,37 +0,0 @@
<?xml version="1.0"?>
<!-- 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/. -->
<?xml-stylesheet href="chrome://messenger/skin/newmailalert.css" type="text/css"?>
<window id="newMailAlertNotification"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
windowtype="alert:alert"
role="alert"
align="start"
onload="onAlertLoad()">
<stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
<script type="application/javascript" src="chrome://messenger/content/newmailalert.js"/>
<stack id="alertContainer" mousethrough="always">
<hbox id="alertBox">
<hbox id ="alertImageBox" align="center" valign="center">
<image id="alertImage"/>
</hbox>
<vbox id="alertTextBox">
<label id="alertTitle"/>
<separator id="alertGroove" class="groove"/>
<folderSummary id="folderSummaryInfo" mousethrough="never"/>
</vbox>
</hbox>
<hbox align="top">
<spacer flex="1"/>
<toolbarbutton id="closeButton" onclick="closeAlert();"/>
</hbox>
</stack>
</window>

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

@ -70,8 +70,6 @@ messenger.jar:
content/messenger/search.xml (content/search.xml)
content/messenger/tabmail.xml (content/tabmail.xml)
content/messenger/tabmail.css (content/tabmail.css)
content/messenger/newmailalert.xul (content/newmailalert.xul)
content/messenger/newmailalert.js (content/newmailalert.js)
content/messenger/newTagDialog.xul (content/newTagDialog.xul)
content/messenger/newTagDialog.js (content/newTagDialog.js)
* content/messenger/viewSourceOverlay.xul (content/viewSourceOverlay.xul)

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

@ -11,19 +11,10 @@
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/*
* See bug 332160. Apply these rules on #alertContainer instead of on
* #newMailAlertNotification like on windows.
*/
#alertContainer {
#newMailAlertNotification {
-moz-appearance: none;
min-height: 60px;
border: ridge #5486DA 4px;
background-color: -moz-Dialog;
color: -moz-DialogText;
}
#newMailAlertNotification {
border: none; /* See bug 332160. */
}
#alertImage {
@ -31,24 +22,16 @@
}
#alertImageBox {
-moz-margin-start: 4px;
-moz-margin-end: 6px;
min-height: 46px;
padding: 4px;
}
#alertTitle {
font-weight: bold;
text-align: center;
/* this right margin keeps us from overlapping with the
close button. It's value should be related to the width
of the closeButtonImage
*/
-moz-margin-end: 16px;
}
#alertTextBox {
-moz-padding-end: 10px;
padding-top: 5px;
padding: 4px;
-moz-padding-end: 20px;
}
.folderSummary-message-row
@ -82,11 +65,7 @@
-moz-image-region: rect(0px, 16px, 16px, 0px);
-moz-appearance: none;
border: none !important;
padding: 2px 0px 0px;
}
#closeButton > .toolbarbutton-icon {
-moz-margin-end: 0px; /* override toolkit's default value */
padding: 2px;
}
#closeButton:hover {

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

@ -14,8 +14,6 @@
#newMailAlertNotification {
min-height: 60px;
border: ridge #5486DA 4px;
background-color: -moz-Dialog;
color: -moz-DialogText;
}
#alertImage {
@ -23,24 +21,16 @@
}
#alertImageBox {
-moz-margin-start: 4px;
-moz-margin-end: 6px;
min-height: 46px;
padding: 4px;
}
#alertTitle {
font-weight: bold;
text-align: center;
/* this right margin keeps us from overlapping with the
close button. It's value should be related to the width
of the closeButtonImage
*/
-moz-margin-end: 16px;
}
#alertTextBox {
-moz-padding-end: 10px;
padding-top: 5px;
padding: 4px;
-moz-padding-end: 20px;
}
.folderSummary-message-row
@ -74,11 +64,7 @@
-moz-image-region: rect(0px, 16px, 16px, 0px);
-moz-appearance: none;
border: none !important;
padding: 2px 0px 0px;
}
#closeButton > .toolbarbutton-icon {
-moz-margin-end: 0px; /* override toolkit's default value */
padding: 2px;
}
#closeButton:hover {

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

@ -10,14 +10,26 @@
opacity: 1;
}
#alertContainer[animate] {
#alertContainer[fade-in] {
animation-timing-function: ease-out;
animation-duration: 4s;
animation-duration: 2s;
animation-fill-mode: both;
animation-name: alert-animation;
animation-name: fade-in;
}
@keyframes alert-animation {
@keyframes fade-in {
from {opacity: 0;}
to {opacity: 1;}
}
#alertContainer[fade-out] {
animation-timing-function: ease-in;
animation-duration: 2s;
animation-fill-mode: both;
animation-name: fade-out;
}
@keyframes fade-out {
from {opacity: 1;}
to {opacity: 0;}
}

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

@ -22,10 +22,10 @@ function prefillAlertInfo()
// unwrap all the args....
// arguments[0] --> array of folders with new mail
// arguments[1] --> the observer to call back with notifications about the alert
// arguments[2] --> user initiated boolean. true if the user initiated opening the alert
// arguments[2] --> user initiated boolean. true if the user initiated opening the alert
// (which means skip the fade effect and don't auto close the alert)
// arguments[3] --> the alert origin returned by the look and feel
var foldersWithNewMail = window.arguments[0];
var foldersWithNewMail = window.arguments[0];
gAlertListener = window.arguments[1];
gUserInitiated = window.arguments[2];
gOrigin = window.arguments[3];
@ -46,7 +46,7 @@ function prefillAlertInfo()
var message = totalNumNewMessages == 1 ? "newMailNotification_message"
: "newMailNotification_messages";
label.value = document.getElementById('bundle_messenger')
.getFormattedString(message,
.getFormattedString(message,
[rootFolder.prettiestName, totalNumNewMessages]);
// This is really the root folder and we have to walk through the list to
@ -100,28 +100,33 @@ function onAlertLoad()
{
prefillAlertInfo();
// read out our initial settings from prefs.
try
try
{
gOpenTime = Services.prefs.getIntPref("alerts.totalOpenTime");
} catch (ex) {}
// bogus call to make sure the window is moved offscreen until we are ready for it.
resizeAlert(true);
// if we aren't waiting to fetch preview text, then go ahead and
// if we aren't waiting to fetch preview text, then go ahead and
// start showing the alert.
if (!gPendingPreviewFetchRequests)
setTimeout(showAlert, 0); // let the JS thread unwind, to give layout
setTimeout(showAlert, 0); // let the JS thread unwind, to give layout
// a chance to recompute the styles and widths for our alert text.
}
// If the user initiated the alert, show it right away, otherwise start opening the alert with
// the fade effect.
// the fade effect.
function showAlert()
{
// resize the alert based on our current content
if (!document.getElementById("folderSummaryInfo").hasMessages) {
closeAlert(); // no mail, so don't bother showing the alert...
return;
}
// resize the alert based on our current content
resizeAlert(false);
var alertContainer = document.getElementById("alertContainer");
// Don't fade in if the user opened the alert or the pref is true.
if (gUserInitiated ||
@ -130,22 +135,15 @@ function showAlert()
setTimeout(closeAlert, gOpenTime);
return;
}
if (document.getElementById('folderSummaryInfo').hasMessages)
{
alertContainer.addEventListener("animationend", function hideAlert(event) {
if (event.animationName == "alert-animation") {
alertContainer.removeEventListener("animationend", hideAlert, false);
let remaining = Math.max(Math.round(gOpenTime - event.elapsedTime * 1000), 0);
setTimeout(closeAlert, remaining);
}
}, false);
alertContainer.setAttribute("animate", true);
}
else
{
closeAlert(); // no mail, so don't bother showing the alert...
}
alertContainer.addEventListener("animationend", function hideAlert(event) {
if (event.animationName == "fade-in") {
alertContainer.removeEventListener("animationend", hideAlert, false);
let remaining = Math.max(Math.round(gOpenTime - event.elapsedTime * 1000), 0);
setTimeout(fadeOutAlert, remaining);
}
}, false);
alertContainer.setAttribute("fade-in", true);
}
function resizeAlert(aMoveOffScreen)
@ -155,7 +153,7 @@ function resizeAlert(aMoveOffScreen)
alertImageBox.style.minHeight = alertTextBox.scrollHeight + "px";
sizeToContent();
// leftover hack to get the window properly hidden when we first open it
if (aMoveOffScreen)
window.outerHeight = 1;
@ -173,9 +171,21 @@ function resizeAlert(aMoveOffScreen)
window.moveTo(x, y);
}
function fadeOutAlert()
{
var alertContainer = document.getElementById("alertContainer");
alertContainer.addEventListener("animationend", function fadeOut(event) {
if (event.animationName == "fade-out") {
alertContainer.removeEventListener("animationend", fadeOut, false);
closeAlert();
}
}, false);
alertContainer.setAttribute("fade-out", true);
}
function closeAlert()
{
if (gAlertListener)
gAlertListener.observe(null, "alertfinished", "");
window.close();
gAlertListener.observe(null, "alertfinished", "");
window.close();
}

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

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

@ -126,3 +126,6 @@ messenger.jar:
content/messenger/dateFormat.js (base/content/dateFormat.js)
content/messenger/shutdownWindow.xul (base/content/shutdownWindow.xul)
content/messenger/shutdownWindow.js (base/content/shutdownWindow.js)
content/messenger/newmailalert.css (base/content/newmailalert.css)
content/messenger/newmailalert.js (base/content/newmailalert.js)
content/messenger/newmailalert.xul (base/content/newmailalert.xul)

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

@ -608,6 +608,11 @@ pref("mailnews.append_preconfig_accounts.version", 1);
// pref mail.smtpservers.appendsmtpservers
pref("mail.append_preconfig_smtpservers.version", 1);
pref("mail.biff.alert.show_preview", true);
pref("mail.biff.alert.show_subject", true);
pref("mail.biff.alert.show_sender", true);
pref("mail.biff.alert.preview_length", 40);
pref("mail.biff.play_sound", true);
// 0 == default system sound, 1 == user specified wav
pref("mail.biff.play_sound.type", 0);

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

@ -325,10 +325,6 @@ pref("browser.offline-apps.notify", true);
pref("browser.formfill.expire_days", 180);
pref("mail.biff.alert.show_preview", true);
pref("mail.biff.alert.show_subject", true);
pref("mail.biff.alert.show_sender", true);
pref("mail.biff.alert.preview_length", 40);
pref("mail.biff.show_new_alert", true);
pref("mailnews.ui.deleteMarksRead", true);
@ -669,7 +665,7 @@ pref("browser.throbber.url","chrome://navigator-region/locale/region.properties"
// pref to control the alert notification
pref("alerts.slideIncrement", 1);
pref("alerts.slideIncrementTime", 10);
pref("alerts.totalOpenTime", 4000);
pref("alerts.totalOpenTime", 10000);
// 0 opens the download manager
// 1 opens a progress dialog

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

@ -58,9 +58,6 @@ messenger.jar:
content/messenger/mail-offline.js
content/messenger/mailContextMenus.js
content/messenger/msgFolderPickerOverlay.xul
content/messenger/newmailalert.css
content/messenger/newmailalert.js
content/messenger/newmailalert.xul
content/messenger/start.xhtml
content/messenger/messengerdnd.js
content/messenger/mailPrefsOverlay.xul (prefs/mailPrefsOverlay.xul)