diff --git a/layout/xul/base/src/nsMenuBarFrame.cpp b/layout/xul/base/src/nsMenuBarFrame.cpp index c3b34abc3f7c..88c0023a65d4 100644 --- a/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/layout/xul/base/src/nsMenuBarFrame.cpp @@ -257,10 +257,11 @@ void nsMenuBarFrame::SetCurrentMenuItem(nsIContent* aMenuItem) return; // Unset the current child. - mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE); + if (mCurrentMenu) + mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE); // Set the new child. - aMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE); + if (aMenuItem) + aMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE); mCurrentMenu = aMenuItem; } - diff --git a/layout/xul/base/src/nsMenuBarListener.cpp b/layout/xul/base/src/nsMenuBarListener.cpp index 11617ba63d03..f47ee71167e5 100644 --- a/layout/xul/base/src/nsMenuBarListener.cpp +++ b/layout/xul/base/src/nsMenuBarListener.cpp @@ -133,31 +133,34 @@ 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 target; - aMouseEvent->GetTarget(getter_AddRefs(target)); + // Make sure the active menu gets set properly. + // If we're over something then switch to it. + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); - nsCOMPtr current = do_QueryInterface(target); - nsCOMPtr menuBar; - mMenuBarFrame->GetContent(getter_AddRefs(menuBar)); + nsCOMPtr current = do_QueryInterface(target); + nsCOMPtr menuBar; + mMenuBarFrame->GetContent(getter_AddRefs(menuBar)); - while (current && (current.get() != menuBar)) { - // See if we're a menu item. - nsCOMPtr tag; - current->GetTag(*getter_AddRefs(tag)); - if (tag && (tag.get() == nsXULAtoms::xpmenu)) { - // We found a menu. - mMenuBarFrame->SetCurrentMenuItem(current); - break; - } - - // Get our parent. - nsCOMPtr parent; - current->GetParent(*getter_AddRefs(parent)); - current = parent.get(); + while (current && (current.get() != menuBar)) { + // See if we're a menu item. + nsCOMPtr tag; + current->GetTag(*getter_AddRefs(tag)); + if (tag && (tag.get() == nsXULAtoms::xpmenu)) { + // We found a menu. + mMenuBarFrame->SetCurrentMenuItem(current); + break; } + + // Get our parent. + nsCOMPtr parent; + current->GetParent(*getter_AddRefs(parent)); + current = parent.get(); + } + + if (!mMenuBarFrame->IsActive()) { + // Clear the selected item if there is one. + mMenuBarFrame->SetCurrentMenuItem(nsnull); } return NS_OK; // means I am NOT consuming event