2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsISound.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#endif
|
2008-04-14 21:16:24 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUTF8Utils.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 00:22:58 -07:00
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewMenuBarFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu Bar container
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
2015-01-06 01:27:56 -08:00
|
|
|
return new (aPresShell) nsMenuBarFrame(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMenuBarFrame)
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
NS_QUERYFRAME_HEAD(nsMenuBarFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsMenuBarFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// nsMenuBarFrame cntr
|
|
|
|
//
|
2015-01-06 01:27:56 -08:00
|
|
|
nsMenuBarFrame::nsMenuBarFrame(nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aContext),
|
2012-07-30 07:20:58 -07:00
|
|
|
mMenuBarListener(nullptr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mStayActive(false),
|
|
|
|
mIsActive(false),
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu(nullptr),
|
|
|
|
mTarget(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
} // cntr
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsMenuBarFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create the menu bar listener.
|
|
|
|
mMenuBarListener = new nsMenuBarListener(this);
|
2013-03-19 18:47:48 -07:00
|
|
|
NS_ADDREF(mMenuBarListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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.
|
2014-08-22 13:11:27 -07:00
|
|
|
mTarget = aContent->GetComposedDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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.
|
2013-04-19 15:18:32 -07:00
|
|
|
|
2014-10-06 06:56:00 -07:00
|
|
|
mTarget->AddSystemEventListener(NS_LITERAL_STRING("keypress"), mMenuBarListener, false);
|
|
|
|
mTarget->AddSystemEventListener(NS_LITERAL_STRING("keydown"), mMenuBarListener, false);
|
|
|
|
mTarget->AddSystemEventListener(NS_LITERAL_STRING("keyup"), mMenuBarListener, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-03 17:55:15 -08:00
|
|
|
// mousedown event should be handled in all phase
|
2014-11-27 01:23:51 -08:00
|
|
|
mTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, true);
|
|
|
|
mTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, false);
|
|
|
|
mTarget->AddEventListener(NS_LITERAL_STRING("blur"), mMenuBarListener, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuBarFrame::SetActive(bool aActiveFlag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// 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 {
|
2011-10-17 07:59:28 -07:00
|
|
|
mActiveByKeyboard = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
RemoveKeyboardNavigator();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2011-10-17 07:59:28 -07:00
|
|
|
SetActive(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurrentMenu) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame* closeframe = mCurrentMenu;
|
2011-10-17 07:59:28 -07:00
|
|
|
closeframe->SelectMenu(false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr;
|
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)
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsMenuFrame* firstFrame = nsXULPopupManager::GetNextMenuItem(this, nullptr, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (firstFrame) {
|
2012-05-30 00:33:20 -07:00
|
|
|
// Activate the menu bar
|
|
|
|
SetActive(true);
|
2011-10-17 07:59:28 -07:00
|
|
|
firstFrame->SelectMenu(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Track this item for keyboard navigation.
|
|
|
|
mCurrentMenu = firstFrame;
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
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::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t charCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyEvent->GetCharCode(&charCode);
|
2008-04-14 21:16:24 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAutoTArray<uint32_t, 10> accessKeys;
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent* nativeKeyEvent =
|
2013-10-17 23:10:24 -07:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
2008-04-14 21:16:24 -07:00
|
|
|
if (nativeKeyEvent)
|
|
|
|
nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, accessKeys);
|
|
|
|
if (accessKeys.IsEmpty() && charCode)
|
|
|
|
accessKeys.AppendElement(charCode);
|
|
|
|
|
|
|
|
if (accessKeys.IsEmpty())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // no character was pressed so just return
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Enumerate over our list of frames.
|
2014-11-20 10:24:09 -08:00
|
|
|
auto insertion = PresContext()->PresShell()->FrameConstructor()->
|
2014-05-24 15:20:39 -07:00
|
|
|
GetInsertionPoint(GetContent(), nullptr);
|
2014-11-20 10:24:09 -08:00
|
|
|
nsContainerFrame* immediateParent = insertion.mParentFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = this;
|
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
// Find a most preferred accesskey which should be returned.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* foundMenu = nullptr;
|
2014-05-08 18:03:35 -07:00
|
|
|
size_t foundIndex = accessKeys.NoIndex;
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* currFrame = immediateParent->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
while (currFrame) {
|
|
|
|
nsIContent* current = currFrame->GetContent();
|
2008-04-14 21:16:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if it's a menu item.
|
2011-10-17 07:59:28 -07:00
|
|
|
if (nsXULPopupManager::IsValidMenuItem(PresContext(), current, 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()) {
|
2008-04-14 21:16:24 -07:00
|
|
|
ToLowerCase(shortcutKey);
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* start = shortcutKey.BeginReading();
|
|
|
|
const char16_t* end = shortcutKey.EndReading();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t ch = UTF16CharEnumerator::NextChar(&start, end);
|
2014-05-08 18:03:35 -07:00
|
|
|
size_t index = accessKeys.IndexOf(ch);
|
2008-04-14 21:16:24 -07:00
|
|
|
if (index != accessKeys.NoIndex &&
|
2009-06-19 18:36:33 -07:00
|
|
|
(foundIndex == accessKeys.NoIndex || index < foundIndex)) {
|
2008-04-14 21:16:24 -07:00
|
|
|
foundMenu = currFrame;
|
|
|
|
foundIndex = index;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
|
|
|
}
|
2008-04-14 21:16:24 -07:00
|
|
|
if (foundMenu) {
|
2012-07-30 17:43:28 -07:00
|
|
|
return do_QueryFrame(foundMenu);
|
2008-04-14 21:16:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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)
|
2014-04-08 05:45:52 -07:00
|
|
|
pm->HidePopup(popup->GetContent(), true, true, true, false);
|
2007-09-18 08:00:43 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
SetCurrentMenuItem(nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
SetActive(false);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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)
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-06-29 15:39:50 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (aMenuItem)
|
2011-10-17 07:59:28 -07:00
|
|
|
aMenuItem->SelectMenu(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
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr;
|
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,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Run() override
|
2007-09-04 10:42:38 -07:00
|
|
|
{
|
|
|
|
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.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsMenuBarFrame* menubar = nullptr;
|
2007-10-03 15:00:41 -07:00
|
|
|
if (mOldMenu && mNewMenu) {
|
2012-07-30 17:43:28 -07:00
|
|
|
menubar = do_QueryFrame(mMenuBar->GetPrimaryFrame());
|
2009-06-19 18:36:33 -07:00
|
|
|
if (menubar)
|
2011-10-17 07:59:28 -07:00
|
|
|
menubar->SetStayActive(true);
|
2007-10-03 15:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mOldMenu) {
|
|
|
|
nsWeakFrame weakMenuBar(menubar);
|
2014-04-08 05:45:52 -07:00
|
|
|
pm->HidePopup(mOldMenu, false, false, false, false);
|
2007-10-03 15:00:41 -07:00
|
|
|
// clear the flag again
|
|
|
|
if (mNewMenu && weakMenuBar.IsAlive())
|
2011-10-17 07:59:28 -07:00
|
|
|
menubar->SetStayActive(false);
|
2007-10-03 15:00:41 -07:00
|
|
|
}
|
|
|
|
|
2007-09-04 10:42:38 -07:00
|
|
|
if (mNewMenu)
|
2011-10-17 07:59:28 -07:00
|
|
|
pm->ShowMenu(mNewMenu, mSelectFirstItem, false);
|
2007-09-04 10:42:38 -07:00
|
|
|
|
|
|
|
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;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSelectFirstItem;
|
2007-09-04 10:42:38 -07:00
|
|
|
};
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuBarFrame::ChangeMenuItem(nsMenuFrame* aMenuItem,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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();
|
2012-07-30 07:20:58 -07:00
|
|
|
if (pm && pm->HasContextMenu(nullptr))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2014-08-08 07:04:45 -07:00
|
|
|
nsIContent* aOldMenu = nullptr;
|
|
|
|
nsIContent* aNewMenu = nullptr;
|
2007-09-04 10:42:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Unset the current child.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasOpen = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurrentMenu) {
|
2007-07-04 08:49:38 -07:00
|
|
|
wasOpen = mCurrentMenu->IsOpen();
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-07-04 08:49:38 -07:00
|
|
|
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
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr;
|
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();
|
2011-10-17 07:59:28 -07:00
|
|
|
aMenuItem->SelectMenu(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*
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuBarFrame::Enter(WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mCurrentMenu)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mCurrentMenu->IsOpen())
|
2011-04-13 10:53:24 -07:00
|
|
|
return mCurrentMenu->Enter(aEvent);
|
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
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuBarFrame::MenuClosed()
|
2007-06-29 15:39:50 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
SetActive(false);
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!mIsActive && mCurrentMenu) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-06-29 15:39:50 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return 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)
|
2011-10-17 07:59:28 -07:00
|
|
|
pm->SetActiveMenuBar(this, 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)
|
2011-10-17 07:59:28 -07:00
|
|
|
pm->SetActiveMenuBar(this, false);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsMenuBarFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
2011-10-17 07:59:28 -07:00
|
|
|
pm->SetActiveMenuBar(this, false);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2014-10-06 06:56:00 -07:00
|
|
|
mTarget->RemoveSystemEventListener(NS_LITERAL_STRING("keypress"), mMenuBarListener, false);
|
|
|
|
mTarget->RemoveSystemEventListener(NS_LITERAL_STRING("keydown"), mMenuBarListener, false);
|
|
|
|
mTarget->RemoveSystemEventListener(NS_LITERAL_STRING("keyup"), mMenuBarListener, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-27 01:23:51 -08:00
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, true);
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"), mMenuBarListener, false);
|
|
|
|
mTarget->RemoveEventListener(NS_LITERAL_STRING("blur"), mMenuBarListener, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mMenuBarListener);
|
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|