зеркало из https://github.com/mozilla/gecko-dev.git
114580 - dialog alignment issues, r=jag, sr=bryner, a=blizzard
This commit is contained in:
Родитель
85845b7611
Коммит
e91f00e308
|
@ -58,8 +58,7 @@
|
||||||
<parameter name="aDlgType"/>
|
<parameter name="aDlgType"/>
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var btns = this.getElementsByAttribute("dlgtype", aDlgType);
|
return this._buttons[aDlgType];
|
||||||
return btns.length > 0 ? btns[0] : document.getAnonymousElementByAttribute(this, "dlgtype", aDlgType);
|
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
|
@ -110,43 +109,26 @@
|
||||||
|
|
||||||
<constructor>
|
<constructor>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
this._useAnonButton = {};
|
this._configureButtons(this.getAttribute("buttons"));
|
||||||
|
|
||||||
// listen for when window is closed via native close buttons
|
// listen for when window is closed via native close buttons
|
||||||
window.addEventListener("close", this._closeHandler, false);
|
window.addEventListener("close", this._closeHandler, false);
|
||||||
|
|
||||||
window.addEventListener("load", this.initialize, false);
|
// for things that we need to initialize after onload fires
|
||||||
|
window.addEventListener("load", this.postLoadInit, false);
|
||||||
|
|
||||||
window.moveToAlertPosition = this.moveToAlertPosition;
|
window.moveToAlertPosition = this.moveToAlertPosition;
|
||||||
window.centerWindowOnScreen = this.centerWindowOnScreen;
|
window.centerWindowOnScreen = this.centerWindowOnScreen;
|
||||||
]]>
|
]]>
|
||||||
</constructor>
|
</constructor>
|
||||||
|
|
||||||
<method name="initialize">
|
<method name="postLoadInit">
|
||||||
<parameter name="event"/>
|
<parameter name="aEvent"/>
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var dialog = document.documentElement;
|
|
||||||
|
|
||||||
dialog._initDialogButton("accept");
|
|
||||||
dialog._initDialogButton("cancel");
|
|
||||||
dialog._initDialogButton("help");
|
|
||||||
dialog._initDialogButton("disclosure");
|
|
||||||
dialog._initDialogButton("extra1");
|
|
||||||
dialog._initDialogButton("extra2");
|
|
||||||
|
|
||||||
// hide/show the appropriate buttons
|
|
||||||
dialog._configureButtons(dialog.getAttribute("buttons"));
|
|
||||||
|
|
||||||
var position = dialog.getAttribute("position");
|
|
||||||
if (position == "alert")
|
|
||||||
dialog.moveToAlertPosition();
|
|
||||||
else if (position == "center")
|
|
||||||
dialog.centerWindowOnScreen();
|
|
||||||
|
|
||||||
// give focus to the first focusable element in the dialog
|
// give focus to the first focusable element in the dialog
|
||||||
if (!document.commandDispatcher.focusedElement)
|
if (!document.commandDispatcher.focusedElement)
|
||||||
document.commandDispatcher.advanceFocusIntoSubtree(dialog);
|
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
|
@ -168,63 +150,57 @@
|
||||||
]]></getter>
|
]]></getter>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
<method name="_initDialogButton">
|
|
||||||
<parameter name="aDlgType"/>
|
|
||||||
<body><![CDATA[
|
|
||||||
// determine if button is going to be anonymous or explicit
|
|
||||||
var btn;
|
|
||||||
var btns = this.getElementsByAttribute("dlgtype", aDlgType);
|
|
||||||
if (btns.length > 0) {
|
|
||||||
btn = btns[0];
|
|
||||||
this._useAnonButton[aDlgType] = false;
|
|
||||||
} else {
|
|
||||||
btn = document.getAnonymousElementByAttribute(this, "dlgtype", aDlgType);
|
|
||||||
this._useAnonButton[aDlgType] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (btn) {
|
|
||||||
btn.addEventListener("command", this._handleButtonCommand, true);
|
|
||||||
// don't override custom labels with pre-defined labels on explicit buttons
|
|
||||||
if (!btn.hasAttribute("label"))
|
|
||||||
btn.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+aDlgType));
|
|
||||||
}
|
|
||||||
return btn;
|
|
||||||
]]></body>
|
|
||||||
</method>
|
|
||||||
|
|
||||||
<method name="_configureButtons">
|
<method name="_configureButtons">
|
||||||
<parameter name="aButtons"/>
|
<parameter name="aButtons"/>
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var shown;
|
// by default, get all the anonymous button elements
|
||||||
if (!aButtons) {
|
var buttons = {};
|
||||||
shown = { accept: true, cancel: true, help: false,
|
this._buttons = buttons;
|
||||||
disclosure: false, extra1: false, extra2: false };
|
buttons.accept = document.getAnonymousElementByAttribute(this, "dlgtype", "accept");
|
||||||
} else {
|
buttons.cancel = document.getAnonymousElementByAttribute(this, "dlgtype", "cancel");
|
||||||
// expect a comma or space delimitd list of dlgtype values to be shown
|
buttons.extra1 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra1");
|
||||||
var list = aButtons.split(",");
|
buttons.extra2 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra2");
|
||||||
|
buttons.help = document.getAnonymousElementByAttribute(this, "dlgtype", "help");
|
||||||
|
buttons.disclosure = document.getAnonymousElementByAttribute(this, "dlgtype", "disclosure");
|
||||||
|
|
||||||
// mark shown dlgtypes as true
|
// look for any overriding explicit button elements
|
||||||
shown = { accept: false, cancel: false, help: false,
|
var exBtns = this.getElementsByAttribute("dlgtype", "*");
|
||||||
disclosure: false, extra1: false, extra2: false };
|
for (var i = 0; i < exBtns.length; ++i) {
|
||||||
for (var i = 0; i < list.length; ++i)
|
var dlgtype = exBtns[i].getAttribute("dlgtype");
|
||||||
shown[list[i].replace(/ /g, "")] = true;
|
buttons[dlgtype].hidden = true; // hide the anonymous button
|
||||||
|
buttons[dlgtype] = exBtns[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the label and oncommand handler to each button
|
||||||
|
for (var dlgtype in buttons) {
|
||||||
|
var button = buttons[dlgtype];
|
||||||
|
buttons[dlgtype].addEventListener("command", this._handleButtonCommand, true);
|
||||||
|
// don't override custom labels with pre-defined labels on explicit buttons
|
||||||
|
if (!button.hasAttribute("label"))
|
||||||
|
button.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+dlgtype));
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide anonymous buttons that aren't mentioned in the buttons attribute, and are not
|
// ensure that hitting enter triggers ondialogaccept
|
||||||
// supplied via explicit content
|
buttons["accept"].setAttribute("default", "true");
|
||||||
for (var dlgtype in shown) {
|
|
||||||
var anonBtn = document.getAnonymousElementByAttribute(this, "dlgtype", dlgtype);
|
// if there is a special button configuration, use it
|
||||||
if (anonBtn) {
|
if (aButtons) {
|
||||||
if (this._useAnonButton[dlgtype] && shown[dlgtype]) {
|
// expect a comma delimitd list of dlgtype values
|
||||||
anonBtn.removeAttribute("hidden");
|
var list = aButtons.split(",");
|
||||||
if (dlgtype == "accept")
|
|
||||||
anonBtn.setAttribute("default", "true");
|
// mark shown dlgtypes as true
|
||||||
} else {
|
var shown = { accept: false, cancel: false, help: false,
|
||||||
anonBtn.setAttribute("hidden", "true");
|
disclosure: false, extra1: false, extra2: false };
|
||||||
if (dlgtype == "accept")
|
for (var i = 0; i < list.length; ++i)
|
||||||
anonBtn.removeAttribute("default");
|
shown[list[i].replace(/ /g, "")] = true;
|
||||||
}
|
|
||||||
|
// hide/show the buttons we want
|
||||||
|
for (var dlgtype in shown) {
|
||||||
|
if (shown[dlgtype])
|
||||||
|
buttons[dlgtype].hidden = false;
|
||||||
|
else
|
||||||
|
buttons[dlgtype].hidden = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче