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