Teaching the menus about the ESC key (which will close up each level of menu

until you hit the menu bar).
This commit is contained in:
hyatt%netscape.com 1999-07-23 07:49:43 +00:00
parent 7a62bb78f1
commit b636708367
7 changed files with 82 additions and 1 deletions

View File

@ -372,4 +372,21 @@ NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIFrame* aMenuItem)
mCurrentMenu = aMenuItem;
return NS_OK;
}
void
nsMenuBarFrame::Escape()
{
if (!mCurrentMenu)
return;
// See if our menu is open.
nsMenuFrame* menuFrame = (nsMenuFrame*)mCurrentMenu;
if (menuFrame->IsOpen()) {
// Let the child menu handle this.
menuFrame->Escape();
}
// It's us. Just set our active flag to false.
mIsActive = PR_FALSE;
}

View File

@ -56,11 +56,20 @@ public:
nsIFrame* aPrevInFlow);
// Non-interface helpers
// Called when a menu on the menu bar is clicked on.
void ToggleMenuActiveState();
// Used to move up, down, left, and right in menus.
void KeyboardNavigation(PRUint32 aDirection);
// Used to handle ALT+key combos
void ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
nsIFrame* FindMenuWithShortcut(PRUint32 aLetter);
// Called when the ESC key is held down to close levels of menus.
void Escape();
protected:
nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
PRBool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).

View File

@ -248,6 +248,11 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
if (active)
mMenuBarFrame->KeyboardNavigation(theChar);
}
else if (theChar == NS_VK_ESCAPE) {
// Close one level.
if (active)
mMenuBarFrame->Escape();
}
else {
// Get the character code.
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aKeyEvent);

View File

@ -347,6 +347,13 @@ nsMenuFrame::KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag)
}
}
void
nsMenuFrame::Escape()
{
}
void
nsMenuFrame::SelectFirstItem()
{

View File

@ -79,6 +79,7 @@ public:
void KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag);
void ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
void Escape();
void ToggleMenuState();
void SelectMenu(PRBool aActivateFlag);

View File

@ -370,10 +370,48 @@ nsMenuPopupFrame::CaptureMouseEvents(PRBool aGrabMouseEvents)
return NS_OK;
}
void
nsMenuPopupFrame::Escape()
{
}
nsIFrame*
nsMenuPopupFrame::FindMenuWithShortcut(PRUint32 aLetter)
{
// Enumerate over our list of frames.
nsIFrame* currFrame = mFrames.FirstChild();
while (currFrame) {
nsCOMPtr<nsIContent> current;
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
// Get the shortcut attribute.
nsString shortcutKey = "";
current->GetAttribute(kNameSpaceID_None, nsXULAtoms::shortcut, shortcutKey);
shortcutKey.ToUpperCase();
if (shortcutKey.Length() > 0) {
// We've got something.
PRUnichar shortcutChar = shortcutKey.CharAt(0);
if (shortcutChar == aLetter) {
// We match!
return currFrame;
}
}
}
currFrame->GetNextSibling(&currFrame);
}
return nsnull;
}
void
nsMenuPopupFrame::ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag)
{
}
void

View File

@ -64,7 +64,11 @@ public:
NS_IMETHOD CaptureMouseEvents(PRBool aGrabMouseEvents);
void KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag);
void ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag);
nsIFrame* FindMenuWithShortcut(PRUint32 aLetter);
void Escape();
protected:
nsIFrame* mCurrentMenu; // The current menu that is active.