2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
|
|
|
#include "nsIContent.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-07-18 11:07:55 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.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 "nsUTF8Utils.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
|
|
|
#include "mozilla/PresShell.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-01-12 07:19:08 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
1999-07-19 13:09:36 +04:00
|
|
|
|
2013-10-01 11:22:58 +04:00
|
|
|
using namespace mozilla;
|
2018-02-09 19:17:09 +03:00
|
|
|
using mozilla::dom::KeyboardEvent;
|
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
|
|
|
|
//
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewMenuBarFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) nsMenuBarFrame(aStyle, aPresShell->GetPresContext());
|
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)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsMenuBarFrame)
|
2011-09-28 05:46:11 +04:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
1999-07-18 11:07:55 +04:00
|
|
|
//
|
|
|
|
// nsMenuBarFrame cntr
|
|
|
|
//
|
2019-02-05 19:45:54 +03:00
|
|
|
nsMenuBarFrame::nsMenuBarFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
: nsBoxFrame(aStyle, aPresContext, kClassID),
|
2016-12-26 10:19:02 +03:00
|
|
|
mStayActive(false),
|
|
|
|
mIsActive(false),
|
|
|
|
mActiveByKeyboard(false),
|
|
|
|
mCurrentMenu(nullptr) {} // cntr
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsMenuBarFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
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.
|
2016-12-26 10:19:02 +03:00
|
|
|
mMenuBarListener = new nsMenuBarListener(this, aContent);
|
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) {
|
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");
|
2017-07-06 15:00:35 +03: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;
|
|
|
|
}
|
|
|
|
|
1999-07-19 12:09:30 +04:00
|
|
|
nsMenuFrame* 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
|
2011-10-17 18:59:28 +04:00
|
|
|
if (mCurrentMenu) 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).
|
2017-07-06 15:00:35 +03:00
|
|
|
// We use an attribute called "menuactive" to track the current
|
2002-03-27 10:01:26 +03:00
|
|
|
// active menu.
|
2016-11-17 17:56:43 +03:00
|
|
|
nsMenuFrame* firstFrame =
|
|
|
|
nsXULPopupManager::GetNextMenuItem(this, nullptr, false, 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);
|
2017-07-06 15:00:35 +03: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
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:09 +03:00
|
|
|
nsMenuFrame* nsMenuBarFrame::FindMenuWithShortcut(KeyboardEvent* aKeyEvent,
|
|
|
|
bool aPeek) {
|
|
|
|
uint32_t charCode = aKeyEvent->CharCode();
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<uint32_t, 10> accessKeys;
|
2013-10-01 11:22:58 +04:00
|
|
|
WidgetKeyboardEvent* nativeKeyEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2016-03-18 05:22:37 +03:00
|
|
|
if (nativeKeyEvent) {
|
|
|
|
nativeKeyEvent->GetAccessKeyCandidates(accessKeys);
|
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
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.
|
Bug 1427677: Get rid of nsContentUtils::HasDistributedChildren. r=bz
The whole function doesn't have much sense.
I killed its only DOM use in bug 1427511.
Now it only has two callers in nsCSSFrameConstructor, which basically only want
to know whether the children of the same node can have different flattened tree
parents.
So let's check that directly instead (checking whether the element has a binding
or a shadow root), and simplify a bit other surrounding code while at it.
Leave the XUL popup / menubar code doing the broken thing they were doing
beforehand, because it doesn't look to me like it's trivial to fix... They're
effectively assuming that the children of the menupopup end up in a single
insertion point, which is true, but doesn't need to be. Maybe they should walk
the DOM tree? Don't want to dig into that right now, since XUL insertion points
can be filtered and all that... Not fun.
Also, this removes the broken optimization that used to check
mParentFrame->GetContent()->HasChildren(), because it's pretty broken. It used
to be relevant before bug 653881, because <children> element used to not exist,
but now the insertion point at least needs to contain the <children> element all
the time.
There even used to be a XXX comment saying that the optimization didn't work,
which was removed in:
https://hg.mozilla.org/mozilla-central/rev/2d8585ec74b3
We could still check for "no insertion points", and optimize that, but it
doesn't seem worth it.
MozReview-Commit-ID: L4lspkxKENr
2018-01-02 17:04:38 +03:00
|
|
|
nsContainerFrame* immediateParent =
|
|
|
|
nsXULPopupManager::ImmediateParentFrame(this);
|
2000-04-07 02:32:39 +04:00
|
|
|
|
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;
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* currFrame = immediateParent->PrincipalChildList().FirstChild();
|
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.
|
2015-12-07 04:15:53 +03:00
|
|
|
if (nsXULPopupManager::IsValidMenuItem(current, false)) {
|
1999-07-23 11:39:16 +04:00
|
|
|
// Get the shortcut attribute.
|
2001-06-06 04:37:15 +04:00
|
|
|
nsAutoString shortcutKey;
|
2017-12-07 21:13:50 +03:00
|
|
|
if (current->IsElement()) {
|
|
|
|
current->AsElement()->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
|
2018-01-15 23:16:56 +03:00
|
|
|
if (!aPeek) {
|
|
|
|
// 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();
|
|
|
|
}
|
2002-02-15 06:53:26 +03:00
|
|
|
|
2018-01-15 23:16:56 +03:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popup = pm->GetTopPopup(ePopupTypeMenu);
|
|
|
|
if (popup) pm->HidePopup(popup->GetContent(), true, true, true, false);
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2018-01-15 23:16:56 +03:00
|
|
|
SetCurrentMenuItem(nullptr);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
nsMenuFrame* nsMenuBarFrame::GetCurrentMenuItem() { 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) {
|
|
|
|
if (mCurrentMenu == aMenuItem) return NS_OK;
|
2006-09-04 00:25:58 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (mCurrentMenu) mCurrentMenu->SelectMenu(false);
|
2007-06-30 02:39:50 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (aMenuItem) 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() {
|
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
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsMenuBarSwitchMenu : public Runnable {
|
2007-09-04 21:42:38 +04:00
|
|
|
public:
|
2007-10-04 02:00:41 +04:00
|
|
|
nsMenuBarSwitchMenu(nsIContent* aMenuBar, nsIContent* aOldMenu,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIContent* aNewMenu, bool aSelectFirstItem)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("nsMenuBarSwitchMenu"),
|
|
|
|
mMenuBar(aMenuBar),
|
|
|
|
mOldMenu(aOldMenu),
|
|
|
|
mNewMenu(aNewMenu),
|
|
|
|
mSelectFirstItem(aSelectFirstItem) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() 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());
|
2011-10-17 18:59:28 +04:00
|
|
|
if (menubar) menubar->SetStayActive(true);
|
2007-10-04 02:00:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mOldMenu) {
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame 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()) menubar->SetStayActive(false);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (mNewMenu) 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, bool aSelectFirstItem,
|
2015-06-26 19:32:25 +03:00
|
|
|
bool aFromKey) {
|
1999-07-19 13:09:36 +04:00
|
|
|
if (mCurrentMenu == aMenuItem) return NS_OK;
|
|
|
|
|
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)) return NS_OK;
|
2005-09-28 22:48:27 +04:00
|
|
|
|
2014-08-08 18:04:45 +04:00
|
|
|
nsIContent* aOldMenu = nullptr;
|
|
|
|
nsIContent* aNewMenu = nullptr;
|
2017-07-06 15:00:35 +03: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();
|
2007-09-04 21:42:38 +04:00
|
|
|
if (popupFrame) 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()) 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 = new nsMenuBarSwitchMenu(
|
2007-10-04 02:00:41 +04:00
|
|
|
GetContent(), aOldMenu, aNewMenu, aSelectFirstItem);
|
2017-07-26 11:13:35 +03:00
|
|
|
return mContent->OwnerDoc()->Dispatch(TaskCategory::Other, event.forget());
|
1999-07-23 11:49:43 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
nsMenuFrame* nsMenuBarFrame::Enter(WidgetGUIEvent* aEvent) {
|
1999-07-24 05:59:32 +04:00
|
|
|
if (!mCurrentMenu) return nullptr;
|
2003-01-20 14:58:30 +03:00
|
|
|
|
2011-04-13 21:53:24 +04:00
|
|
|
if (mCurrentMenu->IsOpen()) 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
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
bool nsMenuBarFrame::MenuClosed() {
|
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
|
|
|
}
|
|
|
|
|
2000-02-09 12:34:35 +03:00
|
|
|
void nsMenuBarFrame::InstallKeyboardNavigator() {
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2011-10-17 18:59:28 +04:00
|
|
|
if (pm) pm->SetActiveMenuBar(this, true);
|
2000-02-09 12:34:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsMenuBarFrame::RemoveKeyboardNavigator() {
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!mIsActive) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2011-10-17 18:59:28 +04:00
|
|
|
if (pm) 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
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsMenuBarFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2011-10-17 18:59:28 +04:00
|
|
|
if (pm) pm->SetActiveMenuBar(this, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2015-05-15 14:42:14 +03:00
|
|
|
mMenuBarListener->OnDestroyMenuBarFrame();
|
2015-04-19 21:48:49 +03:00
|
|
|
mMenuBarListener = nullptr;
|
1999-08-22 11:44:00 +04:00
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
1999-08-24 04:32:35 +04:00
|
|
|
}
|