Bug 64157 Should be able to navigate <menulist> when it's not dropped down r=aaronl sr=roc

This commit is contained in:
neil%parkwaycc.co.uk 2004-07-03 21:00:07 +00:00
parent bac92025e4
commit bb69790fdb
5 changed files with 62 additions and 15 deletions

View File

@ -39,7 +39,7 @@
#include "nsIBoxObject.idl"
interface nsIDOMElement;
interface nsIDOMKeyEvent;
[scriptable, uuid(F5099746-5049-4e81-A03E-945D5110FEE2)]
interface nsIMenuBoxObject : nsISupports
@ -47,6 +47,8 @@ interface nsIMenuBoxObject : nsISupports
void openMenu(in boolean openFlag);
attribute nsIDOMElement activeChild;
boolean handleKeyPress(in nsIDOMKeyEvent keyEvent);
};
%{C++

View File

@ -35,12 +35,13 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsISupportsUtils.h"
#include "nsIMenuBoxObject.h"
#include "nsBoxObject.h"
#include "nsIPresShell.h"
#include "nsIMenuFrame.h"
#include "nsIFrame.h"
#include "nsGUIEvent.h"
class nsMenuBoxObject : public nsIMenuBoxObject, public nsBoxObject
{
@ -89,7 +90,8 @@ NS_IMETHODIMP nsMenuBoxObject::OpenMenu(PRBool aOpenFlag)
if (!frame)
return NS_OK;
nsCOMPtr<nsIMenuFrame> menuFrame(do_QueryInterface(frame));
nsIMenuFrame* menuFrame;
CallQueryInterface(frame, &menuFrame);
if (!menuFrame)
return NS_OK;
@ -102,7 +104,8 @@ NS_IMETHODIMP nsMenuBoxObject::GetActiveChild(nsIDOMElement** aResult)
if (!frame)
return NS_OK;
nsCOMPtr<nsIMenuFrame> menuFrame(do_QueryInterface(frame));
nsIMenuFrame* menuFrame;
CallQueryInterface(frame, &menuFrame);
if (!menuFrame)
return NS_OK;
@ -115,13 +118,46 @@ NS_IMETHODIMP nsMenuBoxObject::SetActiveChild(nsIDOMElement* aResult)
if (!frame)
return NS_OK;
nsCOMPtr<nsIMenuFrame> menuFrame(do_QueryInterface(frame));
nsIMenuFrame* menuFrame;
CallQueryInterface(frame, &menuFrame);
if (!menuFrame)
return NS_OK;
return menuFrame->SetActiveChild(aResult);
}
/* boolean handleKeyPress (in nsIDOMKeyEvent keyEvent); */
NS_IMETHODIMP nsMenuBoxObject::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent, PRBool* aHandledFlag)
{
*aHandledFlag = PR_FALSE;
NS_ENSURE_ARG(aKeyEvent);
nsIFrame* frame = GetFrame();
if (!frame)
return NS_OK;
nsIMenuFrame* menuFrame;
CallQueryInterface(frame, &menuFrame);
if (!menuFrame)
return NS_OK;
PRUint32 keyCode;
aKeyEvent->GetKeyCode(&keyCode);
switch (keyCode) {
case NS_VK_UP:
case NS_VK_DOWN:
case NS_VK_HOME:
case NS_VK_END:
PRBool altKey;
aKeyEvent->GetAltKey(&altKey);
if (altKey)
return NS_OK;
return menuFrame->KeyboardNavigation(keyCode, *aHandledFlag);
default:
return menuFrame->ShortcutNavigation(aKeyEvent, *aHandledFlag);
}
}
// Creation Routine ///////////////////////////////////////////////////////////////////////
nsresult

View File

@ -376,16 +376,9 @@ nsMenuFrame::HandleEvent(nsIPresContext* aPresContext,
if (aEvent->message == NS_KEY_PRESS && !IsDisabled()) {
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
PRUint32 keyCode = keyEvent->keyCode;
if ((keyCode == NS_VK_F4 && !mMenuParent) && IsOpen() &&
!keyEvent->isAlt && !keyEvent->isShift && !keyEvent->isControl)
OpenMenu(PR_FALSE); // Close menu on unmodified F4
else if (keyCode == NS_VK_UP || keyCode == NS_VK_DOWN ||
(keyCode == NS_VK_F4 && !keyEvent->isAlt && !keyEvent->isShift &&
!keyEvent->isControl && !mMenuParent))
// Plain or modified down or up arrow will open any menu
// Unmodified F4 will open <menulist> as well
if (!IsOpen())
OpenMenu(PR_TRUE);
if ((keyCode == NS_VK_F4 && !keyEvent->isAlt) ||
((keyCode == NS_VK_UP || keyCode == NS_VK_DOWN) && keyEvent->isAlt))
OpenMenu(!IsOpen()); // Toggle menulist on unmodified F4 or Alt arrow
}
else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && !IsDisabled() && IsMenu() ) {
PRBool isMenuBar = PR_FALSE;

View File

@ -43,6 +43,14 @@
this.menuBoxObject.activeChild = this.selectedInternal;
]]>
</handler>
<handler event="keypress" phase="target">
<![CDATA[
this.menuBoxObject.activeChild = this.selectedInternal;
if (this.menuBoxObject.handleKeyPress(event))
this.menuBoxObject.activeChild.doCommand();
]]>
</handler>
</handlers>
<implementation implements="nsIDOMXULMenuListElement, nsIAccessibleProvider">

View File

@ -35,6 +35,14 @@
this.menuBoxObject.activeChild = this.selectedInternal;
]]>
</handler>
<handler event="keypress" phase="target">
<![CDATA[
this.menuBoxObject.activeChild = this.selectedInternal;
if (this.menuBoxObject.handleKeyPress(event))
this.menuBoxObject.activeChild.doCommand();
]]>
</handler>
</handlers>
<implementation implements="nsIDOMXULMenuListElement, nsIAccessibleProvider">