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 ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -38,9 +39,13 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cr = Components.results;
const Cc = Components.classes;
// parameters to gCommonDialogParam.Get() are defined in nsPIPromptService.idl // parameters to gCommonDialogParam.Get() are defined in nsPIPromptService.idl
var gCommonDialogParam = var gCommonDialogParam =
window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock); window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
function showControls() function showControls()
{ {
@ -101,6 +106,27 @@ function setLabelForNode(aNode, aLabel, aIsLabelFlag)
aNode.accessKey = accessKey; 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() function commonDialogOnLoad()
{ {
// limit the dialog to the screen width // limit the dialog to the screen width
@ -113,6 +139,10 @@ function commonDialogOnLoad()
document.title = gCommonDialogParam.GetString(12); document.title = gCommonDialogParam.GetString(12);
#endif #endif
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.addObserver(softkbObserver, "softkb-change", false);
// set the number of command buttons // set the number of command buttons
var nButtons = gCommonDialogParam.GetInt(2); var nButtons = gCommonDialogParam.GetInt(2);
var dialog = document.documentElement; var dialog = document.documentElement;
@ -182,8 +212,8 @@ function commonDialogOnLoad()
{ {
var delayInterval = 2000; var delayInterval = 2000;
try { try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"] var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch); .getService(Ci.nsIPrefBranch);
delayInterval = prefs.getIntPref("security.dialog_enable_delay"); delayInterval = prefs.getIntPref("security.dialog_enable_delay");
} catch (e) {} } catch (e) {}
@ -203,13 +233,19 @@ function commonDialogOnLoad()
try { try {
var sound = gCommonDialogParam.GetString(13); var sound = gCommonDialogParam.GetString(13);
if (sound) { if (sound) {
Components.classes["@mozilla.org/sound;1"] Cc["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound) .createInstance(Ci.nsISound)
.playSystemSound(sound); .playSystemSound(sound);
} }
} catch (e) { } } catch (e) { }
} }
function commonDialogOnUnload(){
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.removeObserver(softkbObserver, "softkb-change");
}
var gDelayExpired = false; var gDelayExpired = false;
var gBlurred = false; var gBlurred = false;

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

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