2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dan Rosen <dr@netscape.com>
|
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsICaret.h"
|
|
|
|
#include "nsIFocusController.h"
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsISound.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewMenuBarFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu Bar container
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMenuBarFrame (aPresShell, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuBarFrame cntr
|
|
|
|
//
|
|
|
|
nsMenuBarFrame::nsMenuBarFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext),
|
|
|
|
mMenuBarListener(nsnull),
|
2007-10-03 15:00:41 -07:00
|
|
|
mStayActive(PR_FALSE),
|
2007-03-22 10:30:00 -07:00
|
|
|
mIsActive(PR_FALSE),
|
2007-10-09 10:21:36 -07:00
|
|
|
mCurrentMenu(nsnull),
|
2007-03-22 10:30:00 -07:00
|
|
|
mTarget(nsnull),
|
|
|
|
mCaretWasVisible(PR_FALSE)
|
|
|
|
{
|
|
|
|
} // cntr
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuBarFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
|
|
|
// Create the menu bar listener.
|
|
|
|
mMenuBarListener = new nsMenuBarListener(this);
|
|
|
|
NS_IF_ADDREF(mMenuBarListener);
|
|
|
|
if (! mMenuBarListener)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Hook up the menu bar as a key listener on the whole document. It will see every
|
|
|
|
// key press that occurs, but after everyone else does.
|
2007-05-14 02:11:38 -07:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aContent->GetDocument());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mTarget = target;
|
|
|
|
|
|
|
|
// Also hook up the listener to the window listening for focus events. This is so we can keep proper
|
|
|
|
// state as the user alt-tabs through processes.
|
|
|
|
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("keypress"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("keydown"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("keyup"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("mousedown"), (nsIDOMMouseListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
target->AddEventListener(NS_LITERAL_STRING("blur"), (nsIDOMFocusListener*)mMenuBarListener, PR_TRUE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuBarFrame::SetActive(PRBool aActiveFlag)
|
|
|
|
{
|
|
|
|
// If the activity is not changed, there is nothing to do.
|
|
|
|
if (mIsActive == aActiveFlag)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!aActiveFlag) {
|
2007-10-03 15:00:41 -07:00
|
|
|
// Don't deactivate when switching between menus on the menubar.
|
|
|
|
if (mStayActive)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// if there is a request to deactivate the menu bar, check to see whether
|
|
|
|
// there is a menu popup open for the menu bar. In this case, don't
|
|
|
|
// deactivate the menu bar.
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && pm->IsPopupOpenForMenuParent(this))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mIsActive = aActiveFlag;
|
|
|
|
if (mIsActive) {
|
|
|
|
InstallKeyboardNavigator();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RemoveKeyboardNavigator();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want the caret to blink while the menus are active
|
|
|
|
// The caret distracts screen readers and other assistive technologies from the menu selection
|
|
|
|
// There is 1 caret per document, we need to find the focused document and toggle its caret
|
|
|
|
do {
|
2007-03-30 14:11:41 -07:00
|
|
|
nsIPresShell *presShell = PresContext()->GetPresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!presShell)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsIDocument *document = presShell->GetDocument();
|
|
|
|
if (!document)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = document->GetContainer();
|
|
|
|
nsCOMPtr<nsPIDOMWindow> windowPrivate = do_GetInterface(container);
|
|
|
|
if (!windowPrivate)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsIFocusController *focusController =
|
|
|
|
windowPrivate->GetRootFocusController();
|
|
|
|
if (!focusController)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> windowInternal;
|
|
|
|
focusController->GetFocusedWindow(getter_AddRefs(windowInternal));
|
|
|
|
if (!windowInternal)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
nsCOMPtr<nsIDocument> focusedDoc;
|
|
|
|
windowInternal->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
focusedDoc = do_QueryInterface(domDoc);
|
|
|
|
if (!focusedDoc)
|
|
|
|
break;
|
|
|
|
|
2007-05-01 15:24:20 -07:00
|
|
|
presShell = focusedDoc->GetPrimaryShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(presShell));
|
|
|
|
// there is no selection controller for full page plugins
|
|
|
|
if (!selCon)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (mIsActive) {// store whether caret was visible so that we can restore that state when menu is closed
|
|
|
|
PRBool isCaretVisible;
|
|
|
|
selCon->GetCaretEnabled(&isCaretVisible);
|
|
|
|
mCaretWasVisible |= isCaretVisible;
|
|
|
|
}
|
|
|
|
selCon->SetCaretEnabled(!mIsActive && mCaretWasVisible);
|
|
|
|
if (!mIsActive) {
|
|
|
|
mCaretWasVisible = PR_FALSE;
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(active, "DOMMenuBarActive");
|
|
|
|
NS_NAMED_LITERAL_STRING(inactive, "DOMMenuBarInactive");
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
FireDOMEvent(mIsActive ? active : inactive, mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame::ToggleMenuActiveState()
|
|
|
|
{
|
|
|
|
if (mIsActive) {
|
|
|
|
// Deactivate the menu bar
|
|
|
|
SetActive(PR_FALSE);
|
|
|
|
if (mCurrentMenu) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame* closeframe = mCurrentMenu;
|
|
|
|
closeframe->SelectMenu(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentMenu = nsnull;
|
2007-07-04 08:49:38 -07:00
|
|
|
return closeframe;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if the menu bar is already selected (eg. mouseover), deselect it
|
|
|
|
if (mCurrentMenu)
|
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
|
|
|
|
|
|
|
// Activate the menu bar
|
|
|
|
SetActive(PR_TRUE);
|
|
|
|
|
|
|
|
// Set the active menu to be the top left item (e.g., the File menu).
|
|
|
|
// We use an attribute called "menuactive" to track the current
|
|
|
|
// active menu.
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame* firstFrame = nsXULPopupManager::GetNextMenuItem(this, nsnull, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (firstFrame) {
|
|
|
|
firstFrame->SelectMenu(PR_TRUE);
|
|
|
|
|
|
|
|
// Track this item for keyboard navigation.
|
|
|
|
mCurrentMenu = firstFrame;
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
static void
|
|
|
|
GetInsertionPoint(nsIPresShell* aShell, nsIFrame* aFrame, nsIFrame* aChild,
|
|
|
|
nsIFrame** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIContent* child = nsnull;
|
|
|
|
if (aChild)
|
|
|
|
child = aChild->GetContent();
|
|
|
|
aShell->FrameConstructor()->GetInsertionPoint(aFrame, child, aResult);
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
PRUint32 charCode;
|
|
|
|
aKeyEvent->GetCharCode(&charCode);
|
2007-08-23 14:21:27 -07:00
|
|
|
if (!charCode) // no character was pressed so just return
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Enumerate over our list of frames.
|
|
|
|
nsIFrame* immediateParent = nsnull;
|
2007-03-30 14:11:41 -07:00
|
|
|
GetInsertionPoint(PresContext()->PresShell(), this, nsnull, &immediateParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = this;
|
|
|
|
|
|
|
|
nsIFrame* currFrame = immediateParent->GetFirstChild(nsnull);
|
|
|
|
|
|
|
|
while (currFrame) {
|
|
|
|
nsIContent* current = currFrame->GetContent();
|
|
|
|
|
|
|
|
// See if it's a menu item.
|
2007-07-04 08:49:38 -07:00
|
|
|
if (nsXULPopupManager::IsValidMenuItem(PresContext(), current, PR_FALSE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the shortcut attribute.
|
|
|
|
nsAutoString shortcutKey;
|
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, shortcutKey);
|
|
|
|
if (!shortcutKey.IsEmpty()) {
|
|
|
|
// We've got something.
|
|
|
|
PRUnichar letter = PRUnichar(charCode); // throw away the high-zero-fill
|
|
|
|
if ( shortcutKey.Equals(Substring(&letter, &letter+1),
|
|
|
|
nsCaseInsensitiveStringComparator()) ) {
|
|
|
|
// We match!
|
2007-07-04 08:49:38 -07:00
|
|
|
return (currFrame->GetType() == nsGkAtoms::menuFrame) ?
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMenuFrame *>(currFrame) : nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't find a matching menu item
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// behavior on Windows - this item is on the menu bar, beep and deactivate the menu bar
|
|
|
|
if (mIsActive) {
|
|
|
|
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
|
|
|
if (soundInterface)
|
|
|
|
soundInterface->Beep();
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2007-09-18 08:00:43 -07:00
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popup = pm->GetTopPopup(ePopupTypeAny);
|
|
|
|
if (popup)
|
|
|
|
pm->HidePopup(popup->GetContent(), PR_TRUE, PR_TRUE, PR_TRUE);
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
SetCurrentMenuItem(nsnull);
|
|
|
|
SetActive(PR_FALSE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
/* virtual */ nsMenuFrame*
|
|
|
|
nsMenuBarFrame::GetCurrentMenuItem()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
return mCurrentMenu;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuBarFrame::SetCurrentMenuItem(nsMenuFrame* aMenuItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mCurrentMenu)
|
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
2007-06-29 15:39:50 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (aMenuItem)
|
|
|
|
aMenuItem->SelectMenu(PR_TRUE);
|
2007-06-29 15:39:50 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
mCurrentMenu = aMenuItem;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuBarFrame::CurrentMenuIsBeingDestroyed()
|
2007-06-29 15:39:50 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
|
|
|
mCurrentMenu = nsnull;
|
2007-06-29 15:39:50 -07:00
|
|
|
}
|
|
|
|
|
2007-09-04 10:42:38 -07:00
|
|
|
class nsMenuBarSwitchMenu : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2007-10-03 15:00:41 -07:00
|
|
|
nsMenuBarSwitchMenu(nsIContent* aMenuBar,
|
|
|
|
nsIContent *aOldMenu,
|
2007-09-04 10:42:38 -07:00
|
|
|
nsIContent *aNewMenu,
|
|
|
|
PRBool aSelectFirstItem)
|
2007-10-03 15:00:41 -07:00
|
|
|
: mMenuBar(aMenuBar), mOldMenu(aOldMenu), mNewMenu(aNewMenu),
|
|
|
|
mSelectFirstItem(aSelectFirstItem)
|
2007-09-04 10:42:38 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!pm)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2007-10-03 15:00:41 -07:00
|
|
|
// if switching from one menu to another, set a flag so that the call to
|
|
|
|
// HidePopup doesn't deactivate the menubar when the first menu closes.
|
|
|
|
nsMenuBarFrame* menubar = nsnull;
|
|
|
|
if (mOldMenu && mNewMenu) {
|
|
|
|
menubar = static_cast<nsMenuBarFrame *>
|
2007-10-09 05:43:15 -07:00
|
|
|
(pm->GetFrameOfTypeForContent(mMenuBar, nsGkAtoms::menuBarFrame, PR_FALSE));
|
2007-10-03 15:00:41 -07:00
|
|
|
menubar->SetStayActive(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOldMenu) {
|
|
|
|
nsWeakFrame weakMenuBar(menubar);
|
2007-09-04 10:42:38 -07:00
|
|
|
pm->HidePopup(mOldMenu, PR_FALSE, PR_FALSE, PR_FALSE);
|
2007-10-03 15:00:41 -07:00
|
|
|
// clear the flag again
|
|
|
|
if (mNewMenu && weakMenuBar.IsAlive())
|
|
|
|
menubar->SetStayActive(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2007-09-04 10:42:38 -07:00
|
|
|
if (mNewMenu)
|
|
|
|
pm->ShowMenu(mNewMenu, mSelectFirstItem, PR_FALSE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-10-03 15:00:41 -07:00
|
|
|
nsCOMPtr<nsIContent> mMenuBar;
|
2007-09-04 10:42:38 -07:00
|
|
|
nsCOMPtr<nsIContent> mOldMenu;
|
|
|
|
nsCOMPtr<nsIContent> mNewMenu;
|
|
|
|
PRBool mSelectFirstItem;
|
|
|
|
};
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuBarFrame::ChangeMenuItem(nsMenuFrame* aMenuItem,
|
|
|
|
PRBool aSelectFirstItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mCurrentMenu == aMenuItem)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// check if there's an open context menu, we ignore this
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && pm->HasContextMenu(nsnull))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-09-04 10:42:38 -07:00
|
|
|
nsIContent* aOldMenu = nsnull, *aNewMenu = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Unset the current child.
|
2007-07-04 08:49:38 -07:00
|
|
|
PRBool wasOpen = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurrentMenu) {
|
2007-07-04 08:49:38 -07:00
|
|
|
wasOpen = mCurrentMenu->IsOpen();
|
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
|
|
|
if (wasOpen) {
|
|
|
|
nsMenuPopupFrame* popupFrame = mCurrentMenu->GetPopup();
|
|
|
|
if (popupFrame)
|
2007-09-04 10:42:38 -07:00
|
|
|
aOldMenu = popupFrame->GetContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// set to null first in case the IsAlive check below returns false
|
|
|
|
mCurrentMenu = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set the new child.
|
|
|
|
if (aMenuItem) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsCOMPtr<nsIContent> content = aMenuItem->GetContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
aMenuItem->SelectMenu(PR_TRUE);
|
2007-07-04 08:49:38 -07:00
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
if (wasOpen && !aMenuItem->IsDisabled())
|
2007-09-04 10:42:38 -07:00
|
|
|
aNewMenu = content;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-04 10:42:38 -07:00
|
|
|
// use an event so that hiding and showing can be done synchronously, which
|
|
|
|
// avoids flickering
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2007-10-03 15:00:41 -07:00
|
|
|
new nsMenuBarSwitchMenu(GetContent(), aOldMenu, aNewMenu, aSelectFirstItem);
|
2007-09-04 10:42:38 -07:00
|
|
|
return NS_DispatchToCurrentThread(event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame::Enter()
|
|
|
|
{
|
|
|
|
if (!mCurrentMenu)
|
2007-07-04 08:49:38 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mCurrentMenu->IsOpen())
|
|
|
|
return mCurrentMenu->Enter();
|
2007-06-29 15:39:50 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
return mCurrentMenu;
|
2007-06-29 15:39:50 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
PRBool
|
|
|
|
nsMenuBarFrame::MenuClosed()
|
2007-06-29 15:39:50 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
SetActive(PR_FALSE);
|
|
|
|
if (!mIsActive && mCurrentMenu) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
2007-07-04 08:49:38 -07:00
|
|
|
mCurrentMenu = nsnull;
|
|
|
|
return PR_TRUE;
|
2007-06-29 15:39:50 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
return PR_FALSE;
|
2007-06-29 15:39:50 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame::InstallKeyboardNavigator()
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->SetActiveMenuBar(this, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame::RemoveKeyboardNavigator()
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!mIsActive) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->SetActiveMenuBar(this, PR_FALSE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuBarFrame::Destroy()
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->SetActiveMenuBar(this, PR_FALSE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("keypress"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("keydown"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("keyup"), (nsIDOMKeyListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), (nsIDOMMouseListener*)mMenuBarListener, PR_FALSE);
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("blur"), (nsIDOMFocusListener*)mMenuBarListener, PR_TRUE);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mMenuBarListener);
|
|
|
|
|
|
|
|
nsBoxFrame::Destroy();
|
|
|
|
}
|