bug 481914 - dialogs shouldn't be larger than available screen space. Listen to soft keyboad notifications r=neil

This commit is contained in:
Brad Lassey 2009-04-20 02:17:48 -04:00
Родитель 9901470cb2
Коммит 7f55d79e57
2 изменённых файлов: 43 добавлений и 6 удалений

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

@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -38,9 +39,13 @@
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cr = Components.results;
const Cc = Components.classes;
// parameters to gCommonDialogParam.Get() are defined in nsPIPromptService.idl
var gCommonDialogParam =
window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
function showControls()
{
@ -101,6 +106,27 @@ function setLabelForNode(aNode, aLabel, aIsLabelFlag)
aNode.accessKey = accessKey;
}
var softkbObserver = {
QueryInterface: function (aIID) {
if (aIID.equals(Ci.nsISupports) ||
aIID.equals(Ci.nsIObserver))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
observe: function(subject, topic, data) {
if (topic === "softkb-change") {
var rect = JSON.parse(data);
if (rect) {
var height = rect.bottom - rect.top;
var width = rect.right - rect.left;
var top = (rect.top + (height - window.innerHeight) / 2);
var left = (rect.left + width - window.innerWidth) / 2);
window.moveTo(left, top);
}
}
}
};
function commonDialogOnLoad()
{
// limit the dialog to the screen width
@ -113,6 +139,10 @@ function commonDialogOnLoad()
document.title = gCommonDialogParam.GetString(12);
#endif
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.addObserver(softkbObserver, "softkb-change", false);
// set the number of command buttons
var nButtons = gCommonDialogParam.GetInt(2);
var dialog = document.documentElement;
@ -182,8 +212,8 @@ function commonDialogOnLoad()
{
var delayInterval = 2000;
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
delayInterval = prefs.getIntPref("security.dialog_enable_delay");
} catch (e) {}
@ -203,13 +233,19 @@ function commonDialogOnLoad()
try {
var sound = gCommonDialogParam.GetString(13);
if (sound) {
Components.classes["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound)
.playSystemSound(sound);
Cc["@mozilla.org/sound;1"]
.createInstance(Ci.nsISound)
.playSystemSound(sound);
}
} catch (e) { }
}
function commonDialogOnUnload(){
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.removeObserver(softkbObserver, "softkb-change");
}
var gDelayExpired = false;
var gBlurred = false;

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

@ -10,6 +10,7 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
aria-describedby="info.body"
onload="commonDialogOnLoad();"
onunload="commonDialogOnUnload();"
ondialogaccept="return commonDialogOnAccept();"
ondialogextra1="return commonDialogOnExtra1();"
ondialogextra2="return commonDialogOnExtra2();"