Bug 345238: Make XPFE alerts service use alert origin reported by look and feel. Ported from the toolkit patch by Jens Bannmann <jens.b@web.de>, r=neil, sr=biesi

This commit is contained in:
smontagu%smontagu.org 2006-12-13 16:06:20 +00:00
Родитель 286a9ad511
Коммит 2eda3dd40e
6 изменённых файлов: 27 добавлений и 437 удалений

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

@ -1,84 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* ===== alert.css =====================================================
== Styles specific to the alerts dialog.
======================================================================= */
@import url("chrome://global/skin/");
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
.alertBox {
border-right: 2px solid #7B969C;
border-bottom: 2px solid #7B969C;
border-top: 2px solid #7B969C;
border-left: 2px solid #7B969C;
background-color: -moz-Dialog;
min-height: 50px;
}
.alertImageBox {
margin-left: 4px;
margin-right: 6px;
min-height: 46px;
}
.alertTitle {
font-weight: bold;
}
.alertText {
margin-right: 6px;
}
.alertText[clickable="true"] {
cursor: pointer;
color: #1455D6;
text-decoration: underline;
}
.alertText[clickable="true"]:hover:active {
color: #424F63;
}
.alertTextBox
{
padding-right: 10px;
padding-top: 5px;
}

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

@ -1,82 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* ===== alert.css =====================================================
== Styles specific to the alerts dialog.
======================================================================= */
@import url("chrome://global/skin/");
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
.alertBox {
border-right: 2px solid #7B969C;
border-bottom: 2px solid #7B969C;
border-top: 2px solid #7B969C;
border-left: 2px solid #7B969C;
background-color: #C7D0D9;
min-height: 50px;
}
.alertImageBox {
margin-left: 4px;
min-height: 46px;
}
.alertTitle {
font-weight: bold;
}
.alertTextBox {
margin-top: 4px;
margin-right: 6px;
margin-left: 6px;
}
.alertText {
margin-right: 6px;
}
.alertText[clickable="true"] {
cursor: pointer;
color: #1455D6;
text-decoration: underline;
}
.alertText[clickable="true"]:hover:active {
color: #424F63;
}

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

@ -1,134 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
* Jens Bannmann <jens.b@web.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var gFinalHeight = 50;
var gSlideIncrement = 1;
var gSlideTime = 10;
var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
var gAlertListener = null;
var gAlertTextClickable = false;
var gAlertCookie = "";
function prefillAlertInfo()
{
// unwrap all the args....
// arguments[0] --> the image src url
// arguments[1] --> the alert title
// arguments[2] --> the alert text
// arguments[3] --> is the text clickable?
// arguments[4] --> the alert cookie to be passed back to the listener
// arguments[5] --> an optional callback listener (nsIObserver)
document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]);
document.getElementById('alertTextLabel').setAttribute('value', window.arguments[2]);
gAlertTextClickable = window.arguments[3];
gAlertCookie = window.arguments[4];
if (gAlertTextClickable)
document.getElementById('alertTextLabel').setAttribute('clickable', true);
// the 5th argument is optional
gAlertListener = window.arguments[5];
}
function onAlertLoad()
{
// read out our initial settings from prefs.
try
{
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch(null);
gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
} catch (ex) {}
sizeToContent();
// work around a bug where sizeToContent() leaves a border outside of the content
var contentDim = document.getElementById("alertBox").boxObject;
if (window.innerWidth == contentDim.width + 1)
--window.innerWidth;
gFinalHeight = window.outerHeight;
// start with a 1px height, because 0 causes trouble with gtk1/2
window.outerHeight = 1;
// be sure to offset the alert by 10 pixels from the far right edge of the screen
window.moveTo( (screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availTop + screen.availHeight - window.outerHeight);
setTimeout(animateAlert, gSlideTime);
}
function animateAlert()
{
if (window.outerHeight < gFinalHeight)
{
window.screenY -= gSlideIncrement;
window.outerHeight += gSlideIncrement;
setTimeout(animateAlert, gSlideTime);
}
else
setTimeout(closeAlert, gOpenTime);
}
function closeAlert()
{
if (window.outerHeight > 1)
{
window.screenY += gSlideIncrement;
window.outerHeight -= gSlideIncrement;
setTimeout(closeAlert, gSlideTime);
}
else
{
if (gAlertListener)
gAlertListener.observe(null, "alertfinished", gAlertCookie);
window.close();
}
}
function onAlertClick()
{
if (gAlertListener && gAlertTextClickable)
gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
}

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

@ -1,66 +0,0 @@
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is
Netscape Communications Corporation.
Portions created by the Initial Developer are Copyright (C) 1998-1999
the Initial Developer. All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the terms of
either of the GNU General Public License Version 2 or later (the "GPL"),
or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://communicator/skin/alerts/alert.css" type="text/css"?>
<window id="alertNotification"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
windowtype="alert:alert"
align="start"
onload="onAlertLoad()">
<script type="application/x-javascript" src="chrome://communicator/content/alerts/alert.js"/>
<hbox id="alertBox" class="alertBox">
<hbox class="alertImageBox" align="center" valign="center">
<image id="alertImage"/>
</hbox>
<vbox id="alertTextBox" class="alertTextBox">
<label id="alertTitleLabel" class="alertTitle plain"/>
<label id="alertTextLabel" class="alertText plain" onclick="onAlertClick();"/>
</vbox>
</hbox>
<!-- This method is called inline because we want to make sure we establish the width
and height of the alert before we fire the onload handler. -->
<script type="application/x-javascript">prefillAlertInfo();</script>
</window>

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

@ -1,66 +0,0 @@
#! gmake
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = appcomps
LIBRARY_NAME = alerts_s
MOZILLA_INTERNAL_API = 1
REQUIRES = xpcom \
string \
windowwatcher \
dom \
$(NULL)
CPPSRCS = \
nsAlertsService.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)

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

@ -21,6 +21,8 @@
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
* Jens Bannmann <jens.b@web.de>
* Simon Montagu <smontagu@smontagu.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -44,6 +46,8 @@
#include "nsIDOMWindowInternal.h"
#include "nsIWindowWatcher.h"
#include "nsDependentString.h"
#include "nsWidgetsCID.h"
#include "nsILookAndFeel.h"
#define ALERT_CHROME_URL "chrome://communicator/content/alerts/alert.xul"
@ -80,31 +84,49 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
NS_ENSURE_TRUE(scriptableImageUrl, NS_ERROR_FAILURE);
scriptableImageUrl->SetData(aImageUrl);
argsArray->AppendElement(scriptableImageUrl);
rv = argsArray->AppendElement(scriptableImageUrl);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsString> scriptableAlertTitle (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
NS_ENSURE_TRUE(scriptableAlertTitle, NS_ERROR_FAILURE);
scriptableAlertTitle->SetData(aAlertTitle);
argsArray->AppendElement(scriptableAlertTitle);
rv = argsArray->AppendElement(scriptableAlertTitle);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsString> scriptableAlertText (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
NS_ENSURE_TRUE(scriptableAlertText, NS_ERROR_FAILURE);
scriptableAlertText->SetData(aAlertText);
argsArray->AppendElement(scriptableAlertText);
rv = argsArray->AppendElement(scriptableAlertText);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsPRBool> scriptableIsClickable (do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID));
NS_ENSURE_TRUE(scriptableIsClickable, NS_ERROR_FAILURE);
scriptableIsClickable->SetData(aAlertTextClickable);
argsArray->AppendElement(scriptableIsClickable);
rv = argsArray->AppendElement(scriptableIsClickable);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsString> scriptableAlertCookie (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
NS_ENSURE_TRUE(scriptableAlertCookie, NS_ERROR_FAILURE);
scriptableAlertCookie->SetData(aAlertCookie);
argsArray->AppendElement(scriptableAlertCookie);
rv = argsArray->AppendElement(scriptableAlertCookie);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsPRInt32> scriptableOrigin (do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID));
NS_ENSURE_TRUE(scriptableOrigin, NS_ERROR_FAILURE);
nsCOMPtr<nsILookAndFeel> lookAndFeel = do_GetService("@mozilla.org/widget/lookandfeel;1");
if (lookAndFeel)
{
PRInt32 origin;
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_AlertNotificationOrigin,
origin);
scriptableOrigin->SetData(origin);
}
rv = argsArray->AppendElement(scriptableOrigin);
NS_ENSURE_SUCCESS(rv, rv);
if (aAlertListener)
{