2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-07-18 07:07:55 +00:00
|
|
|
|
|
|
|
#include "nsMenuBarFrame.h"
|
2002-09-07 05:38:16 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-07-18 07:07:55 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1999-07-18 07:07:55 +00:00
|
|
|
#include "nsCSSRendering.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-07-19 02:26:39 +00:00
|
|
|
#include "nsIDocument.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1999-07-22 09:01:55 +00:00
|
|
|
#include "nsMenuFrame.h"
|
1999-09-25 03:39:35 +00:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2001-10-13 00:16:32 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2002-09-06 00:19:58 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2004-01-21 23:05:10 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2002-02-15 03:53:26 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsISound.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#endif
|
2008-04-15 04:16:24 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUTF8Utils.h"
|
2013-09-25 11:21:19 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2016-01-12 04:19:08 +00:00
|
|
|
#include "mozilla/dom/Event.h"
|
1999-07-19 09:09:36 +00:00
|
|
|
|
2013-10-01 07:22:58 +00:00
|
|
|
using namespace mozilla;
|
1999-09-21 01:03:00 +00:00
|
|
|
|
1999-07-18 07:07:55 +00:00
|
|
|
//
|
|
|
|
// NS_NewMenuBarFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu Bar container
|
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-07-18 07:07:55 +00:00
|
|
|
{
|
2015-01-06 09:27:56 +00:00
|
|
|
return new (aPresShell) nsMenuBarFrame(aContext);
|
1999-07-18 07:07:55 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMenuBarFrame)
|
|
|
|
|
2011-09-28 01:46:11 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsMenuBarFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsMenuBarFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
1999-07-18 07:07:55 +00:00
|
|
|
//
|
|
|
|
// nsMenuBarFrame cntr
|
|
|
|
//
|
2016-12-26 07:19:02 +00:00
|
|
|
nsMenuBarFrame::nsMenuBarFrame(nsStyleContext* aContext)
|
2017-05-26 10:11:11 +00:00
|
|
|
: nsBoxFrame(aContext, kClassID)
|
2016-12-26 07:19:02 +00:00
|
|
|
, mStayActive(false)
|
|
|
|
, mIsActive(false)
|
|
|
|
, mActiveByKeyboard(false)
|
|
|
|
, mCurrentMenu(nullptr)
|
1999-07-18 07:07:55 +00:00
|
|
|
{
|
|
|
|
} // cntr
|
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsMenuBarFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-07-19 02:02:38 +00:00
|
|
|
{
|
2013-03-20 01:47:48 +00:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
1999-07-19 02:02:38 +00:00
|
|
|
|
|
|
|
// Create the menu bar listener.
|
2016-12-26 07:19:02 +00:00
|
|
|
mMenuBarListener = new nsMenuBarListener(this, aContent);
|
1999-07-19 02:02:38 +00:00
|
|
|
}
|
1999-07-19 08:09:30 +00:00
|
|
|
|
1999-07-22 09:49:35 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsMenuBarFrame::SetActive(bool aActiveFlag)
|
1999-07-22 09:49:35 +00:00
|
|
|
{
|
2003-02-04 04:26:38 +00:00
|
|
|
// If the activity is not changed, there is nothing to do.
|
|
|
|
if (mIsActive == aActiveFlag)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!aActiveFlag) {
|
2007-10-03 22:00:41 +00:00
|
|
|
// Don't deactivate when switching between menus on the menubar.
|
|
|
|
if (mStayActive)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 15:49:38 +00: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;
|
|
|
|
}
|
|
|
|
|
1999-07-23 08:36:39 +00:00
|
|
|
mIsActive = aActiveFlag;
|
2000-02-09 09:34:35 +00:00
|
|
|
if (mIsActive) {
|
|
|
|
InstallKeyboardNavigator();
|
|
|
|
}
|
2002-09-06 02:52:24 +00:00
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mActiveByKeyboard = false;
|
2002-09-06 02:52:24 +00:00
|
|
|
RemoveKeyboardNavigator();
|
2000-02-18 08:57:28 +00:00
|
|
|
}
|
2002-07-10 22:20:36 +00:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(active, "DOMMenuBarActive");
|
|
|
|
NS_NAMED_LITERAL_STRING(inactive, "DOMMenuBarInactive");
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
FireDOMEvent(mIsActive ? active : inactive, mContent);
|
2000-02-09 09:34:35 +00:00
|
|
|
|
1999-07-22 09:49:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame*
|
1999-07-19 08:09:30 +00:00
|
|
|
nsMenuBarFrame::ToggleMenuActiveState()
|
|
|
|
{
|
1999-07-21 07:42:16 +00:00
|
|
|
if (mIsActive) {
|
1999-07-19 08:09:30 +00:00
|
|
|
// Deactivate the menu bar
|
2011-10-17 14:59:28 +00:00
|
|
|
SetActive(false);
|
1999-07-19 08:09:30 +00:00
|
|
|
if (mCurrentMenu) {
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame* closeframe = mCurrentMenu;
|
2011-10-17 14:59:28 +00:00
|
|
|
closeframe->SelectMenu(false);
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentMenu = nullptr;
|
2007-07-04 15:49:38 +00:00
|
|
|
return closeframe;
|
1999-07-19 08:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-09-04 21:19:36 +00:00
|
|
|
// if the menu bar is already selected (eg. mouseover), deselect it
|
|
|
|
if (mCurrentMenu)
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
1999-07-19 08:09:30 +00:00
|
|
|
|
|
|
|
// Set the active menu to be the top left item (e.g., the File menu).
|
2017-07-06 12:00:35 +00:00
|
|
|
// We use an attribute called "menuactive" to track the current
|
2002-03-27 07:01:26 +00:00
|
|
|
// active menu.
|
2016-11-17 14:56:43 +00:00
|
|
|
nsMenuFrame* firstFrame = nsXULPopupManager::GetNextMenuItem(this, nullptr, false, false);
|
1999-07-22 01:59:09 +00:00
|
|
|
if (firstFrame) {
|
2012-05-30 07:33:20 +00:00
|
|
|
// Activate the menu bar
|
|
|
|
SetActive(true);
|
2011-10-17 14:59:28 +00:00
|
|
|
firstFrame->SelectMenu(true);
|
2017-07-06 12:00:35 +00:00
|
|
|
|
1999-07-19 08:09:30 +00:00
|
|
|
// Track this item for keyboard navigation.
|
1999-07-22 01:59:09 +00:00
|
|
|
mCurrentMenu = firstFrame;
|
1999-07-19 08:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
1999-07-19 08:09:30 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame*
|
2002-04-24 07:15:35 +00:00
|
|
|
nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
|
1999-07-23 07:39:16 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t charCode;
|
2002-04-24 07:15:35 +00:00
|
|
|
aKeyEvent->GetCharCode(&charCode);
|
2008-04-15 04:16:24 +00:00
|
|
|
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<uint32_t, 10> accessKeys;
|
2013-10-01 07:22:58 +00:00
|
|
|
WidgetKeyboardEvent* nativeKeyEvent =
|
2016-02-12 15:40:07 +00:00
|
|
|
aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
|
2016-03-18 02:22:37 +00:00
|
|
|
if (nativeKeyEvent) {
|
|
|
|
nativeKeyEvent->GetAccessKeyCandidates(accessKeys);
|
|
|
|
}
|
2008-04-15 04:16:24 +00:00
|
|
|
if (accessKeys.IsEmpty() && charCode)
|
|
|
|
accessKeys.AppendElement(charCode);
|
|
|
|
|
|
|
|
if (accessKeys.IsEmpty())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr; // no character was pressed so just return
|
2002-04-24 07:15:35 +00:00
|
|
|
|
1999-07-23 07:39:16 +00:00
|
|
|
// Enumerate over our list of frames.
|
2014-11-20 18:24:09 +00:00
|
|
|
auto insertion = PresContext()->PresShell()->FrameConstructor()->
|
2014-05-24 22:20:39 +00:00
|
|
|
GetInsertionPoint(GetContent(), nullptr);
|
2014-11-20 18:24:09 +00:00
|
|
|
nsContainerFrame* immediateParent = insertion.mParentFrame;
|
2000-04-06 22:32:39 +00:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = this;
|
|
|
|
|
2008-04-15 04:16:24 +00:00
|
|
|
// Find a most preferred accesskey which should be returned.
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIFrame* foundMenu = nullptr;
|
2014-05-09 01:03:35 +00:00
|
|
|
size_t foundIndex = accessKeys.NoIndex;
|
2016-01-29 14:42:14 +00:00
|
|
|
nsIFrame* currFrame = immediateParent->PrincipalChildList().FirstChild();
|
2000-04-06 22:32:39 +00:00
|
|
|
|
1999-07-23 07:39:16 +00:00
|
|
|
while (currFrame) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* current = currFrame->GetContent();
|
2008-04-15 04:16:24 +00:00
|
|
|
|
1999-07-23 07:39:16 +00:00
|
|
|
// See if it's a menu item.
|
2015-12-07 01:15:53 +00:00
|
|
|
if (nsXULPopupManager::IsValidMenuItem(current, false)) {
|
1999-07-23 07:39:16 +00:00
|
|
|
// Get the shortcut attribute.
|
2001-06-06 00:37:15 +00:00
|
|
|
nsAutoString shortcutKey;
|
2006-12-26 17:47:52 +00:00
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, shortcutKey);
|
2001-06-06 00:37:15 +00:00
|
|
|
if (!shortcutKey.IsEmpty()) {
|
2008-04-15 04:16:24 +00:00
|
|
|
ToLowerCase(shortcutKey);
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* start = shortcutKey.BeginReading();
|
|
|
|
const char16_t* end = shortcutKey.EndReading();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t ch = UTF16CharEnumerator::NextChar(&start, end);
|
2014-05-09 01:03:35 +00:00
|
|
|
size_t index = accessKeys.IndexOf(ch);
|
2008-04-15 04:16:24 +00:00
|
|
|
if (index != accessKeys.NoIndex &&
|
2009-06-20 01:36:33 +00:00
|
|
|
(foundIndex == accessKeys.NoIndex || index < foundIndex)) {
|
2008-04-15 04:16:24 +00:00
|
|
|
foundMenu = currFrame;
|
|
|
|
foundIndex = index;
|
1999-07-23 07:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetNextSibling();
|
1999-07-23 07:39:16 +00:00
|
|
|
}
|
2008-04-15 04:16:24 +00:00
|
|
|
if (foundMenu) {
|
2012-07-31 00:43:28 +00:00
|
|
|
return do_QueryFrame(foundMenu);
|
2008-04-15 04:16:24 +00:00
|
|
|
}
|
2002-02-15 03:53:26 +00: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
|
2002-03-05 06:28:49 +00:00
|
|
|
if (mIsActive) {
|
|
|
|
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
|
|
|
if (soundInterface)
|
|
|
|
soundInterface->Beep();
|
|
|
|
}
|
2002-02-15 03:53:26 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2007-09-18 15:00:43 +00:00
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popup = pm->GetTopPopup(ePopupTypeAny);
|
|
|
|
if (popup)
|
2014-04-08 12:45:52 +00:00
|
|
|
pm->HidePopup(popup->GetContent(), true, true, true, false);
|
2007-09-18 15:00:43 +00:00
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
SetCurrentMenuItem(nullptr);
|
2011-10-17 14:59:28 +00:00
|
|
|
SetActive(false);
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2002-02-15 03:53:26 +00:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
1999-07-23 07:39:16 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
/* virtual */ nsMenuFrame*
|
|
|
|
nsMenuBarFrame::GetCurrentMenuItem()
|
1999-07-23 05:47:43 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
return mCurrentMenu;
|
1999-07-23 05:47:43 +00:00
|
|
|
}
|
|
|
|
|
2000-02-09 09:34:35 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuBarFrame::SetCurrentMenuItem(nsMenuFrame* aMenuItem)
|
1999-07-19 08:47:02 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
2000-02-09 09:34:35 +00:00
|
|
|
return NS_OK;
|
2006-09-03 20:25:58 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mCurrentMenu)
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-06-29 22:39:50 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (aMenuItem)
|
2011-10-17 14:59:28 +00:00
|
|
|
aMenuItem->SelectMenu(true);
|
2007-06-29 22:39:50 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
mCurrentMenu = aMenuItem;
|
2000-02-09 09:34:35 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-19 08:47:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
|
|
|
nsMenuBarFrame::CurrentMenuIsBeingDestroyed()
|
2007-06-29 22:39:50 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentMenu = nullptr;
|
2007-06-29 22:39:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class nsMenuBarSwitchMenu : public Runnable
|
2007-09-04 17:42:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-10-03 22:00:41 +00:00
|
|
|
nsMenuBarSwitchMenu(nsIContent* aMenuBar,
|
2017-06-12 19:34:10 +00:00
|
|
|
nsIContent* aOldMenu,
|
|
|
|
nsIContent* aNewMenu,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aSelectFirstItem)
|
2017-06-12 19:34:10 +00:00
|
|
|
: mozilla::Runnable("nsMenuBarSwitchMenu")
|
|
|
|
, mMenuBar(aMenuBar)
|
|
|
|
, mOldMenu(aOldMenu)
|
|
|
|
, mNewMenu(aNewMenu)
|
|
|
|
, mSelectFirstItem(aSelectFirstItem)
|
2007-09-04 17:42:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override
|
2007-09-04 17:42:38 +00:00
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!pm)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2007-10-03 22:00:41 +00: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 14:20:58 +00:00
|
|
|
nsMenuBarFrame* menubar = nullptr;
|
2007-10-03 22:00:41 +00:00
|
|
|
if (mOldMenu && mNewMenu) {
|
2012-07-31 00:43:28 +00:00
|
|
|
menubar = do_QueryFrame(mMenuBar->GetPrimaryFrame());
|
2009-06-20 01:36:33 +00:00
|
|
|
if (menubar)
|
2011-10-17 14:59:28 +00:00
|
|
|
menubar->SetStayActive(true);
|
2007-10-03 22:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mOldMenu) {
|
2017-03-01 17:03:14 +00:00
|
|
|
AutoWeakFrame weakMenuBar(menubar);
|
2014-04-08 12:45:52 +00:00
|
|
|
pm->HidePopup(mOldMenu, false, false, false, false);
|
2007-10-03 22:00:41 +00:00
|
|
|
// clear the flag again
|
|
|
|
if (mNewMenu && weakMenuBar.IsAlive())
|
2011-10-17 14:59:28 +00:00
|
|
|
menubar->SetStayActive(false);
|
2007-10-03 22:00:41 +00:00
|
|
|
}
|
|
|
|
|
2007-09-04 17:42:38 +00:00
|
|
|
if (mNewMenu)
|
2011-10-17 14:59:28 +00:00
|
|
|
pm->ShowMenu(mNewMenu, mSelectFirstItem, false);
|
2007-09-04 17:42:38 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-10-03 22:00:41 +00:00
|
|
|
nsCOMPtr<nsIContent> mMenuBar;
|
2007-09-04 17:42:38 +00:00
|
|
|
nsCOMPtr<nsIContent> mOldMenu;
|
|
|
|
nsCOMPtr<nsIContent> mNewMenu;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mSelectFirstItem;
|
2007-09-04 17:42:38 +00:00
|
|
|
};
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuBarFrame::ChangeMenuItem(nsMenuFrame* aMenuItem,
|
2015-06-26 16:32:25 +00:00
|
|
|
bool aSelectFirstItem,
|
|
|
|
bool aFromKey)
|
1999-07-19 09:09:36 +00:00
|
|
|
{
|
|
|
|
if (mCurrentMenu == aMenuItem)
|
1999-07-21 07:42:16 +00:00
|
|
|
return NS_OK;
|
1999-07-19 09:09:36 +00:00
|
|
|
|
2005-09-28 18:48:27 +00:00
|
|
|
// check if there's an open context menu, we ignore this
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2012-07-30 14:20:58 +00:00
|
|
|
if (pm && pm->HasContextMenu(nullptr))
|
2005-09-28 18:48:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2014-08-08 14:04:45 +00:00
|
|
|
nsIContent* aOldMenu = nullptr;
|
|
|
|
nsIContent* aNewMenu = nullptr;
|
2017-07-06 12:00:35 +00:00
|
|
|
|
1999-07-22 09:01:55 +00:00
|
|
|
// Unset the current child.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool wasOpen = false;
|
1999-07-22 01:59:09 +00:00
|
|
|
if (mCurrentMenu) {
|
2007-07-04 15:49:38 +00:00
|
|
|
wasOpen = mCurrentMenu->IsOpen();
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (wasOpen) {
|
|
|
|
nsMenuPopupFrame* popupFrame = mCurrentMenu->GetPopup();
|
|
|
|
if (popupFrame)
|
2007-09-04 17:42:38 +00:00
|
|
|
aOldMenu = popupFrame->GetContent();
|
2006-09-03 20:25:58 +00:00
|
|
|
}
|
1999-07-22 01:59:09 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// set to null first in case the IsAlive check below returns false
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentMenu = nullptr;
|
2006-09-03 20:25:58 +00:00
|
|
|
|
1999-07-19 09:09:36 +00:00
|
|
|
// Set the new child.
|
1999-07-22 01:59:09 +00:00
|
|
|
if (aMenuItem) {
|
2007-07-04 15:49:38 +00:00
|
|
|
nsCOMPtr<nsIContent> content = aMenuItem->GetContent();
|
2011-10-17 14:59:28 +00:00
|
|
|
aMenuItem->SelectMenu(true);
|
2007-07-04 15:49:38 +00:00
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
if (wasOpen && !aMenuItem->IsDisabled())
|
2007-09-04 17:42:38 +00:00
|
|
|
aNewMenu = content;
|
1999-07-22 01:59:09 +00:00
|
|
|
}
|
1999-07-22 09:01:55 +00:00
|
|
|
|
2007-09-04 17:42:38 +00:00
|
|
|
// use an event so that hiding and showing can be done synchronously, which
|
|
|
|
// avoids flickering
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2007-10-03 22:00:41 +00:00
|
|
|
new nsMenuBarSwitchMenu(GetContent(), aOldMenu, aNewMenu, aSelectFirstItem);
|
2017-07-26 08:13:35 +00:00
|
|
|
return mContent->OwnerDoc()->Dispatch(TaskCategory::Other,
|
2017-03-16 10:09:13 +00:00
|
|
|
event.forget());
|
1999-07-23 07:49:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame*
|
2013-10-02 03:46:03 +00:00
|
|
|
nsMenuBarFrame::Enter(WidgetGUIEvent* aEvent)
|
1999-07-24 01:59:32 +00:00
|
|
|
{
|
|
|
|
if (!mCurrentMenu)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-01-20 11:58:30 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mCurrentMenu->IsOpen())
|
2011-04-13 17:53:24 +00:00
|
|
|
return mCurrentMenu->Enter(aEvent);
|
2007-06-29 22:39:50 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return mCurrentMenu;
|
2007-06-29 22:39:50 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuBarFrame::MenuClosed()
|
2007-06-29 22:39:50 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
SetActive(false);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!mIsActive && mCurrentMenu) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2012-07-30 14:20:58 +00:00
|
|
|
mCurrentMenu = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-06-29 22:39:50 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-06-29 22:39:50 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
2000-02-09 09:34:35 +00:00
|
|
|
nsMenuBarFrame::InstallKeyboardNavigator()
|
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
2011-10-17 14:59:28 +00:00
|
|
|
pm->SetActiveMenuBar(this, true);
|
2000-02-09 09:34:35 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
2000-02-09 09:34:35 +00:00
|
|
|
nsMenuBarFrame::RemoveKeyboardNavigator()
|
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!mIsActive) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
2011-10-17 14:59:28 +00:00
|
|
|
pm->SetActiveMenuBar(this, false);
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
1999-07-26 01:35:39 +00:00
|
|
|
}
|
1999-08-22 07:44:00 +00:00
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
2009-12-24 05:21:15 +00:00
|
|
|
nsMenuBarFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
1999-08-22 07:44:00 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
2011-10-17 14:59:28 +00:00
|
|
|
pm->SetActiveMenuBar(this, false);
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2015-05-15 11:42:14 +00:00
|
|
|
mMenuBarListener->OnDestroyMenuBarFrame();
|
2015-04-19 18:48:49 +00:00
|
|
|
mMenuBarListener = nullptr;
|
1999-08-22 07:44:00 +00:00
|
|
|
|
2009-12-24 05:21:15 +00:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
1999-08-24 00:32:35 +00:00
|
|
|
}
|