Bug 563261 - Make lightweight themes / personas work with SeaMonkey trunk in browser windows, r=IanN sr=Neil

This commit is contained in:
Robert Kaiser 2010-07-20 15:53:55 +02:00
Родитель 03fe26041d
Коммит 80f5603305
6 изменённых файлов: 213 добавлений и 3 удалений

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

@ -488,10 +488,10 @@ pref("extensions.dss.switchPending", false); // Non-dynamic switch pending af
// restart.
pref("xpinstall.enabled", true);
pref("xpinstall.whitelist.add.103", "addons.mozilla.org");
pref("xpinstall.whitelist.add", "addons.mozilla.org");
pref("xpinstall.whitelist.add.36", "getpersonas.com");
pref("xpinstall.whitelist.add", "update.mozilla.org");
pref("xpinstall.blacklist.add", "");
pref("lightweightThemes.update.enabled", true);
// Customizable toolbar stuff
pref("custtoolbar.personal_toolbar_folder", "");

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

@ -640,6 +640,10 @@ function Startup()
// now load bookmarks after a delay
setTimeout(LoadBookmarksCallback, 0);
gBrowser.mPanelContainer.addEventListener("InstallBrowserTheme", LightWeightThemeWebInstaller, false, true);
gBrowser.mPanelContainer.addEventListener("PreviewBrowserTheme", LightWeightThemeWebInstaller, false, true);
gBrowser.mPanelContainer.addEventListener("ResetBrowserThemePreview", LightWeightThemeWebInstaller, false, true);
// initialize the session-restore service
setTimeout(InitSessionStoreCallback, 0);
}
@ -2599,3 +2603,170 @@ function BrowserToolboxCustomizeChange(event)
{
toolboxCustomizeChange(getNavToolbox(), event);
}
var LightWeightThemeWebInstaller = {
handleEvent: function (event) {
switch (event.type) {
case "InstallBrowserTheme":
case "PreviewBrowserTheme":
case "ResetBrowserThemePreview":
// ignore requests from background tabs
if (event.target.ownerDocument.defaultView.top != content)
return;
}
switch (event.type) {
case "InstallBrowserTheme":
this._installRequest(event);
break;
case "PreviewBrowserTheme":
this._preview(event);
break;
case "ResetBrowserThemePreview":
this._resetPreview(event);
break;
case "pagehide":
case "TabSelect":
this._resetPreview();
break;
}
},
get _manager () {
var temp = {};
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", temp);
delete this._manager;
return this._manager = temp.LightweightThemeManager;
},
_installRequest: function (event) {
var node = event.target;
var data = this._getThemeFromNode(node);
if (!data)
return;
if (this._isAllowed(node)) {
this._install(data);
return;
}
var allowButtonText =
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
var allowButtonAccesskey =
gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
var message =
gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
[node.ownerDocument.location.host]);
var buttons = [{
label: allowButtonText,
accessKey: allowButtonAccesskey,
callback: function () {
return LightWeightThemeWebInstaller._install(data);
}
}];
this._removePreviousNotifications();
var notificationBox = gBrowser.getNotificationBox();
var notificationBar =
notificationBox.appendNotification(message, "lwtheme-install-request", "",
notificationBox.PRIORITY_INFO_MEDIUM,
buttons);
notificationBar.persistence = 1;
},
_install: function (newTheme) {
var previousTheme = this._manager.currentTheme;
this._manager.currentTheme = newTheme;
if (this._manager.currentTheme &&
this._manager.currentTheme.id == newTheme.id) {
this._postInstallNotification(newTheme, previousTheme);
// Posting the install notification destroys the permission notification,
// so tell the former that it's closed already.
return true;
}
return false;
},
_postInstallNotification: function (newTheme, previousTheme) {
function text(id) {
return gNavigatorBundle.getString("lwthemePostInstallNotification." + id);
}
var buttons = [{
label: text("undoButton"),
accessKey: text("undoButton.accesskey"),
callback: function () {
LightWeightThemeWebInstaller._manager.forgetUsedTheme(newTheme.id);
LightWeightThemeWebInstaller._manager.currentTheme = previousTheme;
}
}, {
label: text("manageButton"),
accessKey: text("manageButton.accesskey"),
callback: function () {
toEM("addons://list/theme");
}
}];
this._removePreviousNotifications();
var notificationBox = gBrowser.getNotificationBox();
var notificationBar =
notificationBox.appendNotification(text("message"),
"lwtheme-install-notification", "",
notificationBox.PRIORITY_INFO_MEDIUM,
buttons);
notificationBar.persistence = 1;
notificationBar.timeout = Date.now() + 20000; // 20 seconds
},
_removePreviousNotifications: function () {
var box = gBrowser.getNotificationBox();
["lwtheme-install-request",
"lwtheme-install-notification"].forEach(function (value) {
var notification = box.getNotificationWithValue(value);
if (notification)
box.removeNotification(notification);
});
},
_previewWindow: null,
_preview: function (event) {
if (!this._isAllowed(event.target))
return;
var data = this._getThemeFromNode(event.target);
if (!data)
return;
this._resetPreview();
this._previewWindow = event.target.ownerDocument.defaultView;
this._previewWindow.addEventListener("pagehide", this, true);
gBrowser.tabContainer.addEventListener("TabSelect", this, false);
this._manager.previewTheme(data);
},
_resetPreview: function (event) {
if (!this._previewWindow ||
event && !this._isAllowed(event.target))
return;
this._previewWindow.removeEventListener("pagehide", this, true);
this._previewWindow = null;
gBrowser.tabContainer.removeEventListener("TabSelect", this, false);
this._manager.resetPreview();
},
_isAllowed: function (node) {
var uri = node.ownerDocument.documentURIObject;
return Services.perms.testPermission(uri, "install") == Services.perms.ALLOW_ACTION;
},
_getThemeFromNode: function (node) {
return this._manager.parseTheme(node.getAttribute("data-browsertheme"),
node.baseURI);
}
}

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

@ -65,6 +65,8 @@
title="&mainWindow.title;"
titlemodifier="&mainWindow.titlemodifier;"
titlemenuseparator="&mainWindow.titlemodifiermenuseparator;"
lightweightthemes="true"
lightweightthemesfooter="status-bar"
windowtype="navigator:browser"
persist="screenX screenY width height sizemode">

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

@ -126,3 +126,14 @@ prefwindow {
prefpane {
-moz-binding: url("chrome://communicator/content/bindings/prefwindow.xml#prefpane");
}
/******* lightweight themes *******/
window[lwtheme="true"] {
background-repeat: no-repeat;
background-position: top right;
}
statusbar[lwthemefooter="true"] {
background-repeat: no-repeat;
background-position: bottom left;
}

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

@ -41,6 +41,18 @@ tabs.closeButton=Close all tabs
tabs.closeWarningPromptMe=Warn me when closing multiple tabs
tabs.historyItem=Group of Tabs
# LOCALIZATION NOTE (lwthemeInstallRequest.message): %S will be replaced with
# the host name of the site.
lwthemeInstallRequest.message=This site (%S) attempted to install a theme. Click Allow to proceed.
lwthemeInstallRequest.allowButton=Allow
lwthemeInstallRequest.allowButton.accesskey=a
lwthemePostInstallNotification.message=A new theme has been installed.
lwthemePostInstallNotification.undoButton=Undo
lwthemePostInstallNotification.undoButton.accesskey=n
lwthemePostInstallNotification.manageButton=Manage Themes…
lwthemePostInstallNotification.manageButton.accesskey=M
# urlbarBindings.xml
# LOCALIZATION NOTE: This is for the location bar drop-down string:
# "Search " + search_engine_name + " for " + user_input

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

@ -291,6 +291,15 @@ toolbar[mode="text"] > #window-controls > toolbarbutton > .toolbarbutton-icon {
min-width: 0px;
}
#urlbar:-moz-lwtheme:not([focused="true"]),
.tabbrowser-tab:-moz-lwtheme:not([selected="true"]) {
opacity: .8;
}
.tabbrowser-tab:-moz-lwtheme {
text-shadow: none;
}
#urlbar {
border: 3px solid;
-moz-border-top-colors: transparent ThreeDShadow ThreeDDarkShadow;
@ -397,6 +406,11 @@ panel[nomatch="true"] > .autocomplete-search-box {
font-weight: bold;
}
#search-button:-moz-lwtheme,
#go-button:-moz-lwtheme {
opacity: .8;
}
#search-button {
list-style-image: url("chrome://communicator/skin/icons/search.png");
-moz-image-region: rect(0 17px 17px 0);