Bug 1213421 - Truncate long body and title text in notifications. r=MattN

--HG--
extra : rebase_source : bb92c1846bbc15347cd6e5fe1b43919b11b2b467
This commit is contained in:
Jared Wein 2015-11-13 15:56:47 -05:00
Родитель 9a7610609b
Коммит fd3e052054
3 изменённых файлов: 27 добавлений и 3 удалений

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

@ -1779,6 +1779,7 @@ nsContextMenu.prototype = {
// Store searchTerms in context menu item so we know what to search onclick
menuItem.searchTerms = selectedText;
// Copied to alert.js' prefillAlertInfo().
// If the JS character after our truncation point is a trail surrogate,
// include it in the truncated string to avoid splitting a surrogate pair.
if (selectedText.length > 15) {

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

@ -10,6 +10,7 @@ const NS_ALERT_LEFT = 2;
const NS_ALERT_TOP = 4;
const WINDOW_MARGIN = 10;
const BODY_TEXT_LIMIT = 200;
Cu.import("resource://gre/modules/Services.jsm");
@ -93,10 +94,32 @@ function prefillAlertInfo() {
case 3:
if (window.arguments[2]) {
document.getElementById("alertBox").setAttribute("hasBodyText", true);
document.getElementById("alertTextLabel").textContent = window.arguments[2];
let bodyText = window.arguments[2];
let bodyTextLabel = document.getElementById("alertTextLabel");
if (bodyText.length > BODY_TEXT_LIMIT) {
let ellipsis = "\u2026";
try {
ellipsis = Services.prefs.getComplexValue("intl.ellipsis",
Ci.nsIPrefLocalizedString).data;
} catch (e) { }
// Copied from nsContextMenu.js' formatSearchContextItem().
// If the JS character after our truncation point is a trail surrogate,
// include it in the truncated string to avoid splitting a surrogate pair.
let truncLength = BODY_TEXT_LIMIT;
let truncChar = bodyText[BODY_TEXT_LIMIT].charCodeAt(0);
if (truncChar >= 0xDC00 && truncChar <= 0xDFFF) {
truncLength++;
}
bodyTextLabel.textContent = bodyText.substring(0, truncLength) +
ellipsis;
bodyTextLabel.setAttribute("tooltiptext", bodyText);
}
}
case 2:
document.getElementById("alertTitleLabel").textContent = window.arguments[1];
document.getElementById("alertTitleLabel").setAttribute("value", window.arguments[1]);
case 1:
if (window.arguments[0]) {
document.getElementById("alertBox").setAttribute("hasImage", true);

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

@ -25,7 +25,7 @@
<vbox id="alertBox" class="alertBox">
<box id="alertTitleBox">
<label id="alertTitleLabel" class="alertTitle plain"/>
<label id="alertTitleLabel" class="alertTitle plain" crop="end"/>
<vbox class="alertCloseBox">
<toolbarbutton class="alertCloseButton close-icon"
tooltiptext="&closeAlert.tooltip;"