Bug 467360, support buttons with child panels, r+sr=neil

This commit is contained in:
Neil Deakin 2009-01-20 12:46:55 -05:00
Родитель b9f13132ed
Коммит 9b4a7ab1d5
8 изменённых файлов: 148 добавлений и 36 удалений

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

@ -210,10 +210,12 @@ class nsXULPopupShowingEvent : public nsRunnable
public:
nsXULPopupShowingEvent(nsIContent *aPopup,
nsIContent *aMenu,
nsPopupType aPopupType,
PRBool aIsContextMenu,
PRBool aSelectFirstItem)
: mPopup(aPopup),
mMenu(aMenu),
mPopupType(aPopupType),
mIsContextMenu(aIsContextMenu),
mSelectFirstItem(aSelectFirstItem)
{
@ -226,6 +228,7 @@ public:
private:
nsCOMPtr<nsIContent> mPopup;
nsCOMPtr<nsIContent> mMenu;
nsPopupType mPopupType;
PRBool mIsContextMenu;
PRBool mSelectFirstItem;
};

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

@ -421,7 +421,7 @@ nsXULPopupManager::ShowMenu(nsIContent *aMenu,
if (aAsynchronous) {
SetTriggerEvent(nsnull, nsnull);
nsCOMPtr<nsIRunnable> event =
new nsXULPopupShowingEvent(popupFrame->GetContent(), aMenu,
new nsXULPopupShowingEvent(popupFrame->GetContent(), aMenu, popupFrame->PopupType(),
parentIsContextMenu, aSelectFirstItem);
NS_DispatchToCurrentThread(event);
}
@ -2010,9 +2010,7 @@ nsXULPopupShowingEvent::Run()
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
nsPresContext* context = GetPresContextFor(mPopup);
if (pm && context) {
// the popupshowing event should only be fired asynchronously
// for menus, so just use ePopupTypeMenu as the type
pm->FirePopupShowingEvent(mPopup, mMenu, context, ePopupTypeMenu,
pm->FirePopupShowingEvent(mPopup, mMenu, context, mPopupType,
mIsContextMenu, mSelectFirstItem);
}

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

@ -49,6 +49,7 @@ _TEST_FILES = test_bug360220.xul \
test_bug365773.xul \
test_bug382990.xul \
test_bug457632.xul \
test_button.xul \
test_closemenu_attribute.xul \
test_colorpicker_popup.xul \
test_deck.xul \

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

@ -0,0 +1,70 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
XUL Widget Test for button
-->
<window title="Button Test"
onload="setTimeout(test_button, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="/MochiKit/packed.js"></script>
<script type="application/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="/tests/SimpleTest/EventUtils.js"></script>
<button id="one" label="One"/>
<button id="two" label="Two"/>
<hbox>
<button id="three" label="Three" open="true"/>
</hbox>
<hbox>
<button id="four" type="menu" label="Four"/>
<button id="five" type="panel" label="Five"/>
<button id="six" label="Six"/>
</hbox>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
function test_button()
{
synthesizeMouseExpectEvent($("one"), 2, 2, {}, $("one"), "command", "button press");
$("one").focus();
synthesizeKeyExpectEvent("VK_SPACE", { }, $("one"), "command", "key press");
$("two").disabled = true;
synthesizeMouseExpectEvent($("two"), 2, 2, {}, $("two"), "!command", "button press command when disabled");
synthesizeMouseExpectEvent($("two"), 2, 2, {}, $("two"), "click", "button press click when disabled");
$("one").focus();
synthesizeKey("VK_DOWN", { });
is(document.activeElement, $("three"), "key cursor down on button");
synthesizeKey("VK_RIGHT", { });
is(document.activeElement, $("four"), "key cursor right on button");
synthesizeKey("VK_DOWN", { });
is(document.activeElement, $("four"), "key cursor down on menu button");
$("five").focus();
synthesizeKey("VK_DOWN", { });
is(document.activeElement, $("five"), "key cursor down on panel button");
$("three").focus();
synthesizeKey("VK_UP", { });
is(document.activeElement, $("one"), "key cursor up on button");
$("two").focus();
is(document.activeElement, $("one"), "focus disabled button");
SimpleTest.finish();
}
]]>
</script>
</window>

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

@ -19,7 +19,8 @@
4. As a menuitem was executed, the menu will roll up, hiding it.
5. The popuphidden event for the menu calls menuClosed which tests the popup states.
6. The panelOpened function tests the popup states again and hides the popup.
7. Once the panel's popuphidden event fires, the tests are complete.
7. Once the panel's popuphidden event fires, tests are performed to see if
panels inside buttons and toolbarbuttons work. Each is opened and the closed.
-->
<menu id="menu" onpopupshown="menuOpened()" onpopuphidden="menuClosed();">
@ -29,10 +30,25 @@
</menupopup>
</menu>
<panel id="panel" onpopupshown="panelOpened()" onpopuphidden="SimpleTest.finish()">
<panel id="panel" onpopupshown="panelOpened()"
onpopuphidden="$('button').focus(); $('button').open = true">
<textbox/>
</panel>
<button id="button" type="panel" label="Button">
<panel onpopupshown="panelOnButtonOpened(this)"
onpopuphidden="$('tbutton').open = true;">
<button label="OK" oncommand="this.parentNode.parentNode.open = false"/>
</panel>
</button>
<toolbarbutton id="tbutton" type="panel" label="Toolbarbutton">
<panel onpopupshown="panelOnToolbarbuttonOpened(this)"
onpopuphidden="SimpleTest.finish()">
<textbox/>
</panel>
</toolbarbutton>
<script class="testbody" type="application/javascript">
<![CDATA[
@ -65,6 +81,25 @@ function panelOpened()
$("panel").hidePopup();
}
function panelOnButtonOpened(panel)
{
is(panel.state, 'open', 'button panel is open');
is(document.activeElement, document.documentElement, "focus blurred on panel from button open");
synthesizeKey("VK_DOWN", { });
is(document.activeElement, document.documentElement, "focus not modified on cursor down from button");
panel.firstChild.doCommand()
}
function panelOnToolbarbuttonOpened(panel)
{
is(panel.state, 'open', 'toolbarbutton panel is open');
is(document.activeElement, document.documentElement, "focus blurred on panel from toolbarbutton open");
panel.firstChild.focus();
synthesizeKey("VK_DOWN", { });
is(document.activeElement, panel.firstChild.inputField, "focus not modified on cursor down from toolbarbutton");
panel.parentNode.open = false;
}
]]>
</script>

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

@ -142,28 +142,33 @@
<handler event="keypress">
<![CDATA[
if (event.keyCode == KeyEvent.DOM_VK_UP ||
(event.keyCode == KeyEvent.DOM_VK_LEFT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "ltr") ||
(event.keyCode == KeyEvent.DOM_VK_RIGHT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "rtl")) {
event.preventDefault();
window.document.commandDispatcher.rewindFocus();
return;
}
if (this.boxObject instanceof Components.interfaces.nsIMenuBoxObject) {
if (this.open)
return;
} else {
if (event.keyCode == KeyEvent.DOM_VK_UP ||
(event.keyCode == KeyEvent.DOM_VK_LEFT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "ltr") ||
(event.keyCode == KeyEvent.DOM_VK_RIGHT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "rtl")) {
event.preventDefault();
window.document.commandDispatcher.rewindFocus();
return;
}
if (event.keyCode == KeyEvent.DOM_VK_DOWN ||
(event.keyCode == KeyEvent.DOM_VK_RIGHT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "ltr") ||
(event.keyCode == KeyEvent.DOM_VK_LEFT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "rtl")) {
event.preventDefault();
window.document.commandDispatcher.advanceFocus();
return;
if (event.keyCode == KeyEvent.DOM_VK_DOWN ||
(event.keyCode == KeyEvent.DOM_VK_RIGHT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "ltr") ||
(event.keyCode == KeyEvent.DOM_VK_LEFT &&
document.defaultView.getComputedStyle(this.parentNode, "")
.direction == "rtl")) {
event.preventDefault();
window.document.commandDispatcher.advanceFocus();
return;
}
}
if (event.keyCode || event.charCode <= 32 || event.altKey ||
@ -206,7 +211,7 @@
</resources>
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
align="center" pack="center" flex="1" anonid="button-box">
<children>
@ -251,7 +256,7 @@
<binding id="menu" display="xul:menu"
extends="chrome://global/content/bindings/button.xml#button">
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:hbox class="box-inherit button-box" xbl:inherits="align,dir,pack,orient"
align="center" pack="center" flex="1">
<children>
@ -362,7 +367,7 @@
</resources>
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:button class="box-inherit button-menubutton-button"
anonid="button" flex="1" allowevents="true"
xbl:inherits="disabled,crop,image,label,accessKey,command,

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

@ -12,7 +12,7 @@
</resources>
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,toolbarmode,buttonstyle"/>
<xul:label class="toolbarbutton-text" crop="right" flex="1"
xbl:inherits="value=label,accesskey,crop,toolbarmode,buttonstyle"/>
@ -30,7 +30,7 @@
<binding id="menu" display="xul:menu"
extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,toolbarmode,buttonstyle"/>
<xul:label class="toolbarbutton-text" crop="right" flex="1"
xbl:inherits="value=label,accesskey,crop,dragover-top,toolbarmode,buttonstyle"/>
@ -41,7 +41,7 @@
<binding id="menu-vertical" display="xul:menu"
extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:hbox flex="1" align="center">
<xul:vbox flex="1" align="center">
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,toolbarmode,buttonstyle"/>
@ -60,7 +60,7 @@
</resources>
<content>
<children includes="observes|template|menupopup|tooltip"/>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:toolbarbutton class="box-inherit toolbarbutton-menubutton-button"
anonid="button" flex="1" allowevents="true"
xbl:inherits="disabled,crop,image,label,accesskey,command,

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

@ -122,7 +122,7 @@ button[type="repeat"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#button-repeat");
}
button[type="menu"] {
button[type="menu"], button[type="panel"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#menu");
}
@ -136,7 +136,7 @@ toolbarbutton {
-moz-binding: url("chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton");
}
toolbarbutton[type="menu"] {
toolbarbutton[type="menu"], toolbarbutton[type="panel"] {
-moz-binding: url("chrome://global/content/bindings/toolbarbutton.xml#menu");
}