mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-09 04:25:38 +00:00
Bug 479279: Fennec should have a system for browser-level notifications, r=gavin
This commit is contained in:
parent
9199d6ef76
commit
d47adc4868
@ -1014,6 +1014,54 @@ function getNotificationBox(aWindow) {
|
||||
return Browser.getNotificationBox();
|
||||
}
|
||||
|
||||
var AlertsHelper = {
|
||||
_timeoutID: -1,
|
||||
_listener: null,
|
||||
_cookie: "",
|
||||
_clickable: false,
|
||||
|
||||
showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) {
|
||||
this._clickable = aTextClickable || false;
|
||||
this._listener = aListener || null;
|
||||
this._cookie = aCookie || "";
|
||||
|
||||
document.getElementById("alerts-image").setAttribute("src", aImageURL);
|
||||
document.getElementById("alerts-title").value = aTitle;
|
||||
document.getElementById("alerts-text").textContent = aText;
|
||||
|
||||
let container = document.getElementById("alerts-container");
|
||||
container.hidden = false;
|
||||
|
||||
let rect = container.getBoundingClientRect();
|
||||
container.top = window.innerHeight - (rect.height + 20);
|
||||
container.left = window.innerWidth - (rect.width + 20);
|
||||
|
||||
let timeout = gPrefService.getIntPref("alerts.totalOpenTime");
|
||||
let self = this;
|
||||
this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
|
||||
},
|
||||
|
||||
_timeoutAlert: function ah__timeoutAlert() {
|
||||
this._timeoutID = -1;
|
||||
let container = document.getElementById("alerts-container");
|
||||
container.hidden = true;
|
||||
|
||||
if (this._listener)
|
||||
this._listener.observe(null, "alertfinished", this._cookie);
|
||||
|
||||
// TODO: add slide to UI
|
||||
},
|
||||
|
||||
click: function ah_click(aEvent) {
|
||||
if (this._clickable && this._listener)
|
||||
this._listener.observe(null, "alertclickcallback", this._cookie);
|
||||
|
||||
if (this._timeoutID != -1) {
|
||||
clearTimeout(this._timeoutID);
|
||||
this._timeoutAlert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ProgressController(tab) {
|
||||
this._tab = tab;
|
||||
|
@ -367,6 +367,14 @@
|
||||
<placetree id="folder-items" type="bookmarks" mode="folders" flex="1" onselect="FolderPicker.moveItem();"/>
|
||||
</vbox>
|
||||
|
||||
<hbox id="alerts-container" hidden="true" style="-moz-stack-sizing: ignore;" align="start" top="0" left="0" width="200"
|
||||
onclick="AlertsHelper.click(event);">
|
||||
<image id="alerts-image"/>
|
||||
<vbox>
|
||||
<label id="alerts-title" value=""/>
|
||||
<description id="alerts-text"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</stack>
|
||||
|
||||
</box>
|
||||
|
@ -52,13 +52,14 @@ XPIDL_MODULE = browsercompsbase
|
||||
EXTRA_COMPONENTS = \
|
||||
aboutFirstrun.js \
|
||||
geolocationPrompt.js \
|
||||
alertsService.js \
|
||||
$(NULL)
|
||||
|
||||
DIRS = protocols \
|
||||
$(NULL)
|
||||
|
||||
|
||||
ifdef WINCE
|
||||
DIRS += phone
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
63
mobile/components/alertsService.js
Normal file
63
mobile/components/alertsService.js
Normal file
@ -0,0 +1,63 @@
|
||||
/* ***** 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 Alerts Service.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mark Finkle <mfinkle@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either 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 ***** */
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Alerts Service
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
function AlertsService() { }
|
||||
|
||||
AlertsService.prototype = {
|
||||
classDescription: "Alerts Service",
|
||||
contractID: "@mozilla.org/alerts-service;1",
|
||||
classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
|
||||
|
||||
showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener, aName) {
|
||||
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
let browser = wm.getMostRecentWindow("navigator:browser");
|
||||
browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener);
|
||||
}
|
||||
};
|
||||
|
||||
function NSGetModule(aCompMgr, aFileSpec) {
|
||||
return XPCOMUtils.generateModule([AlertsService]);
|
||||
}
|
@ -723,3 +723,18 @@ richpref > button {
|
||||
border: 0;
|
||||
padding: .2em;
|
||||
}
|
||||
|
||||
/* alerts popup ----------------------------------------------------------- */
|
||||
#alerts-container {
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
border: 4px solid gray;
|
||||
-moz-border-radius: 8px;
|
||||
padding: 8px;
|
||||
-moz-box-shadow: black 4px 4px 10px;
|
||||
}
|
||||
|
||||
#alerts-text {
|
||||
font-size: 85% !important;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
@ -716,3 +716,18 @@ richpref > button {
|
||||
border: 0;
|
||||
padding: .2em;
|
||||
}
|
||||
|
||||
/* alerts popup ----------------------------------------------------------- */
|
||||
#alerts-container {
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
border: 4px solid gray;
|
||||
-moz-border-radius: 8px;
|
||||
padding: 8px;
|
||||
-moz-box-shadow: black 4px 4px 10px;
|
||||
}
|
||||
|
||||
#alerts-text {
|
||||
font-size: 85% !important;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user