This commit is contained in:
hyatt%netscape.com 1999-07-19 09:09:36 +00:00
Родитель b66bc8ab1c
Коммит a736f44a5e
3 изменённых файлов: 51 добавлений и 9 удалений

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

@ -30,6 +30,14 @@
#include "nsIDOMEventReceiver.h"
#include "nsXULAtoms.h"
// XXX Notes to self
// 1. The menu bar should get its own view, and it should capture all events when the ALT key
// goes down.
//
// 2. Collapsing the menu bar will destroy the frame. The menu bar will need to unregister its
// listeners when this happens.
//
//
// NS_NewMenuBarFrame
//
@ -139,15 +147,7 @@ nsMenuBarFrame::KeyboardNavigation(PRUint32 aDirection)
GetNextMenuItem(mCurrentMenu, getter_AddRefs(nextItem));
else GetPreviousMenuItem(mCurrentMenu, getter_AddRefs(nextItem));
if (mCurrentMenu == nextItem.get())
return;
// Unset the current child.
mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
// Set the new child.
nextItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
mCurrentMenu = nextItem;
SetCurrentMenuItem(nextItem);
}
}
}
@ -251,3 +251,16 @@ nsMenuBarFrame::GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult)
NS_IF_ADDREF(aStart);
}
void nsMenuBarFrame::SetCurrentMenuItem(nsIContent* aMenuItem)
{
if (mCurrentMenu == aMenuItem)
return;
// Unset the current child.
mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
// Set the new child.
aMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
mCurrentMenu = aMenuItem;
}

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

@ -51,6 +51,8 @@ public:
void GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult);
void KeyboardNavigation(PRUint32 aDirection);
void SetCurrentMenuItem(nsIContent* aMenuItem);
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).

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

@ -133,6 +133,33 @@ nsMenuBarListener::HandleEvent(nsIDOMEvent* aEvent)
nsresult
nsMenuBarListener::MouseMove(nsIDOMEvent* aMouseEvent)
{
if (mMenuBarFrame->IsActive()) {
// Make sure the active menu gets set properly.
// If we're over something then switch to it.
nsCOMPtr<nsIDOMNode> target;
aMouseEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIContent> current = do_QueryInterface(target);
nsCOMPtr<nsIContent> menuBar;
mMenuBarFrame->GetContent(getter_AddRefs(menuBar));
while (current && (current.get() != menuBar)) {
// See if we're a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag && (tag.get() == nsXULAtoms::xpmenu)) {
// We found a menu.
mMenuBarFrame->SetCurrentMenuItem(current);
break;
}
// Get our parent.
nsCOMPtr<nsIContent> parent;
current->GetParent(*getter_AddRefs(parent));
current = parent.get();
}
}
return NS_OK; // means I am NOT consuming event
}