2007-07-04 19:49:38 +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/. */
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsMenuBarListener.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2012-08-04 11:44:00 +04:00
|
|
|
#include "nsIDOMEvent.h"
|
2008-02-21 20:40:12 +03:00
|
|
|
#include "nsIDOMXULElement.h"
|
2010-08-09 20:17:19 +04:00
|
|
|
#include "nsIXULDocument.h"
|
2008-02-21 20:40:12 +03:00
|
|
|
#include "nsIXULTemplateBuilder.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2014-11-12 20:05:29 +03:00
|
|
|
#include "nsGlobalWindow.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsITimer.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2008-02-20 23:16:55 +03:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2008-07-16 14:52:01 +04:00
|
|
|
#include "nsCaret.h"
|
2008-04-01 12:35:11 +04:00
|
|
|
#include "nsIDocument.h"
|
2010-08-09 20:17:19 +04:00
|
|
|
#include "nsPIWindowRoot.h"
|
2009-07-22 04:45:06 +04:00
|
|
|
#include "nsFrameManager.h"
|
2011-06-18 13:11:36 +04:00
|
|
|
#include "nsIObserverService.h"
|
2012-11-04 12:05:25 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2011-09-09 06:27:13 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-11-04 12:05:25 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-09-09 06:27:13 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-04-20 02:18:32 +04:00
|
|
|
using namespace mozilla::dom;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2013-09-25 15:21:19 +04:00
|
|
|
static_assert(nsIDOMKeyEvent::DOM_VK_HOME == nsIDOMKeyEvent::DOM_VK_END + 1 &&
|
|
|
|
nsIDOMKeyEvent::DOM_VK_LEFT == nsIDOMKeyEvent::DOM_VK_END + 2 &&
|
|
|
|
nsIDOMKeyEvent::DOM_VK_UP == nsIDOMKeyEvent::DOM_VK_END + 3 &&
|
|
|
|
nsIDOMKeyEvent::DOM_VK_RIGHT == nsIDOMKeyEvent::DOM_VK_END + 4 &&
|
|
|
|
nsIDOMKeyEvent::DOM_VK_DOWN == nsIDOMKeyEvent::DOM_VK_END + 5,
|
|
|
|
"nsXULPopupManager assumes some keyCode values are consecutive");
|
|
|
|
|
2008-12-30 16:30:51 +03:00
|
|
|
const nsNavigationDirection DirectionFromKeyCodeTable[2][6] = {
|
|
|
|
{
|
2013-09-25 15:21:19 +04:00
|
|
|
eNavigationDirection_Last, // nsIDOMKeyEvent::DOM_VK_END
|
|
|
|
eNavigationDirection_First, // nsIDOMKeyEvent::DOM_VK_HOME
|
|
|
|
eNavigationDirection_Start, // nsIDOMKeyEvent::DOM_VK_LEFT
|
|
|
|
eNavigationDirection_Before, // nsIDOMKeyEvent::DOM_VK_UP
|
|
|
|
eNavigationDirection_End, // nsIDOMKeyEvent::DOM_VK_RIGHT
|
|
|
|
eNavigationDirection_After // nsIDOMKeyEvent::DOM_VK_DOWN
|
2008-12-30 16:30:51 +03:00
|
|
|
},
|
|
|
|
{
|
2013-09-25 15:21:19 +04:00
|
|
|
eNavigationDirection_Last, // nsIDOMKeyEvent::DOM_VK_END
|
|
|
|
eNavigationDirection_First, // nsIDOMKeyEvent::DOM_VK_HOME
|
|
|
|
eNavigationDirection_End, // nsIDOMKeyEvent::DOM_VK_LEFT
|
|
|
|
eNavigationDirection_Before, // nsIDOMKeyEvent::DOM_VK_UP
|
|
|
|
eNavigationDirection_Start, // nsIDOMKeyEvent::DOM_VK_RIGHT
|
|
|
|
eNavigationDirection_After // nsIDOMKeyEvent::DOM_VK_DOWN
|
2008-12-30 16:30:51 +03:00
|
|
|
}
|
2007-07-17 02:25:29 +04:00
|
|
|
};
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsXULPopupManager* nsXULPopupManager::sInstance = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
nsIContent* nsMenuChainItem::Content()
|
|
|
|
{
|
|
|
|
return mFrame->GetContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsMenuChainItem::SetParent(nsMenuChainItem* aParent)
|
|
|
|
{
|
|
|
|
if (mParent) {
|
|
|
|
NS_ASSERTION(mParent->mChild == this, "Unexpected - parent's child not set to this");
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent->mChild = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
mParent = aParent;
|
|
|
|
if (mParent) {
|
|
|
|
if (mParent->mChild)
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent->mChild->mParent = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
mParent->mChild = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsMenuChainItem::Detach(nsMenuChainItem** aRoot)
|
|
|
|
{
|
|
|
|
// If the item has a child, set the child's parent to this item's parent,
|
|
|
|
// effectively removing the item from the chain. If the item has no child,
|
|
|
|
// just set the parent to null.
|
|
|
|
if (mChild) {
|
|
|
|
NS_ASSERTION(this != *aRoot, "Unexpected - popup with child at end of chain");
|
|
|
|
mChild->SetParent(mParent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// An item without a child should be the first item in the chain, so set
|
|
|
|
// the first item pointer, pointed to by aRoot, to the parent.
|
|
|
|
NS_ASSERTION(this == *aRoot, "Unexpected - popup with no child not at end of chain");
|
|
|
|
*aRoot = mParent;
|
2012-07-30 18:20:58 +04:00
|
|
|
SetParent(nullptr);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsXULPopupManager,
|
|
|
|
nsIDOMEventListener,
|
|
|
|
nsITimerCallback,
|
|
|
|
nsIObserver)
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
nsXULPopupManager::nsXULPopupManager() :
|
|
|
|
mRangeOffset(0),
|
2009-07-22 04:45:06 +04:00
|
|
|
mCachedMousePoint(0, 0),
|
2011-07-09 11:41:32 +04:00
|
|
|
mCachedModifiers(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveMenuBar(nullptr),
|
|
|
|
mPopups(nullptr),
|
|
|
|
mNoHidePanels(nullptr),
|
|
|
|
mTimerMenu(nullptr)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2011-06-18 13:11:36 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
2011-10-17 18:59:28 +04:00
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
2011-06-18 13:11:36 +04:00
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULPopupManager::~nsXULPopupManager()
|
|
|
|
{
|
2008-12-05 19:37:30 +03:00
|
|
|
NS_ASSERTION(!mPopups && !mNoHidePanels, "XUL popups still open");
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPopupManager::Init()
|
|
|
|
{
|
|
|
|
sInstance = new nsXULPopupManager();
|
|
|
|
NS_ENSURE_TRUE(sInstance, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(sInstance);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::Shutdown()
|
|
|
|
{
|
2007-07-12 17:57:01 +04:00
|
|
|
NS_IF_RELEASE(sInstance);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-06-18 13:11:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPopupManager::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aData)
|
2011-06-18 13:11:36 +04:00
|
|
|
{
|
|
|
|
if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
if (mKeyListener) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
|
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, true);
|
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keyup"), this, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mKeyListener = nullptr;
|
2011-06-18 13:11:36 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mRangeParent = nullptr;
|
2011-06-18 13:11:36 +04:00
|
|
|
// mOpeningPopup is cleared explicitly soon after using it.
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "xpcom-shutdown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager*
|
|
|
|
nsXULPopupManager::GetInstance()
|
|
|
|
{
|
2012-10-26 17:15:22 +04:00
|
|
|
MOZ_ASSERT(sInstance);
|
2007-07-04 19:49:38 +04:00
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
2012-10-26 17:15:22 +04:00
|
|
|
bool
|
2015-01-08 04:52:20 +03:00
|
|
|
nsXULPopupManager::Rollup(uint32_t aCount, bool aFlush,
|
|
|
|
const nsIntPoint* pos, nsIContent** aLastRolledUp)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2012-10-26 17:15:22 +04:00
|
|
|
bool consume = false;
|
2007-12-03 19:33:42 +03:00
|
|
|
|
2007-09-18 19:00:43 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2007-12-03 19:33:42 +03:00
|
|
|
if (item) {
|
2012-10-26 17:15:22 +04:00
|
|
|
if (aLastRolledUp) {
|
2015-07-13 13:07:49 +03:00
|
|
|
// We need to get the popup that will be closed last, so that widget can
|
|
|
|
// keep track of it so it doesn't reopen if a mousedown event is going to
|
|
|
|
// processed. Keep going up the menu chain to get the first level menu of
|
|
|
|
// the same type. If a different type is encountered it means we have,
|
|
|
|
// for example, a menulist or context menu inside a panel, and we want to
|
|
|
|
// treat these as distinct. It's possible that this menu doesn't end up
|
|
|
|
// closing because the popuphiding event was cancelled, but in that case
|
|
|
|
// we don't need to deal with the menu reopening as it will already still
|
|
|
|
// be open.
|
2007-12-03 19:33:42 +03:00
|
|
|
nsMenuChainItem* first = item;
|
2015-07-13 13:07:49 +03:00
|
|
|
while (first->GetParent()) {
|
|
|
|
nsMenuChainItem* parent = first->GetParent();
|
|
|
|
if (first->Frame()->PopupType() != parent->Frame()->PopupType() ||
|
|
|
|
first->IsContextMenu() != parent->IsContextMenu()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
first = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-26 17:15:22 +04:00
|
|
|
*aLastRolledUp = first->Content();
|
2007-12-03 19:33:42 +03:00
|
|
|
}
|
2009-06-12 22:23:16 +04:00
|
|
|
|
2015-01-10 05:12:10 +03:00
|
|
|
ConsumeOutsideClicksResult consumeResult = item->Frame()->ConsumeOutsideClicks();
|
|
|
|
consume = (consumeResult == ConsumeOutsideClicks_True);
|
|
|
|
|
2015-02-02 23:53:53 +03:00
|
|
|
bool rollup = true;
|
|
|
|
|
|
|
|
// If norolluponanchor is true, then don't rollup when clicking the anchor.
|
|
|
|
// This would be used to allow adjusting the caret position in an
|
|
|
|
// autocomplete field without hiding the popup for example.
|
|
|
|
bool noRollupOnAnchor = (!consume && pos &&
|
|
|
|
item->Frame()->GetContent()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::norolluponanchor, nsGkAtoms::_true, eCaseMatters));
|
|
|
|
|
|
|
|
// When ConsumeOutsideClicks_ParentOnly is used, always consume the click
|
|
|
|
// when the click was over the anchor. This way, clicking on a menu doesn't
|
2015-01-10 05:12:10 +03:00
|
|
|
// reopen the menu.
|
2015-02-02 23:53:53 +03:00
|
|
|
if ((consumeResult == ConsumeOutsideClicks_ParentOnly || noRollupOnAnchor) && pos) {
|
2015-07-20 15:59:50 +03:00
|
|
|
nsMenuPopupFrame* popupFrame = item->Frame();
|
|
|
|
nsIntRect anchorRect;
|
|
|
|
if (popupFrame->IsAnchored()) {
|
|
|
|
// Check if the popup has a screen anchor rectangle. If not, get the rectangle
|
|
|
|
// from the anchor element.
|
|
|
|
anchorRect = popupFrame->GetScreenAnchorRect();
|
|
|
|
if (anchorRect.x == -1 || anchorRect.y == -1) {
|
|
|
|
nsCOMPtr<nsIContent> anchor = popupFrame->GetAnchor();
|
2014-07-01 04:09:43 +04:00
|
|
|
|
2015-07-20 15:59:50 +03:00
|
|
|
// Check if the anchor has indicated another node to use for checking
|
|
|
|
// for roll-up. That way, we can anchor a popup on anonymous content or
|
|
|
|
// an individual icon, while clicking elsewhere within a button or other
|
|
|
|
// container doesn't result in us re-opening the popup.
|
|
|
|
if (anchor) {
|
|
|
|
nsAutoString consumeAnchor;
|
|
|
|
anchor->GetAttr(kNameSpaceID_None, nsGkAtoms::consumeanchor,
|
|
|
|
consumeAnchor);
|
|
|
|
if (!consumeAnchor.IsEmpty()) {
|
|
|
|
nsIDocument* doc = anchor->GetOwnerDocument();
|
|
|
|
nsIContent* newAnchor = doc->GetElementById(consumeAnchor);
|
|
|
|
if (newAnchor) {
|
|
|
|
anchor = newAnchor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anchor && anchor->GetPrimaryFrame()) {
|
|
|
|
anchorRect = anchor->GetPrimaryFrame()->GetScreenRect();
|
2014-07-01 04:09:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:59:50 +03:00
|
|
|
// It's possible that some other element is above the anchor at the same
|
|
|
|
// position, but the only thing that would happen is that the mouse
|
|
|
|
// event will get consumed, so here only a quick coordinates check is
|
|
|
|
// done rather than a slower complete check of what is at that location.
|
2015-08-10 15:31:37 +03:00
|
|
|
nsPresContext* presContext = item->Frame()->PresContext();
|
|
|
|
nsIntPoint posCSSPixels(presContext->DevPixelsToIntCSSPixels(pos->x),
|
|
|
|
presContext->DevPixelsToIntCSSPixels(pos->y));
|
|
|
|
if (anchorRect.Contains(posCSSPixels)) {
|
2015-07-20 15:59:50 +03:00
|
|
|
if (consumeResult == ConsumeOutsideClicks_ParentOnly) {
|
|
|
|
consume = true;
|
|
|
|
}
|
2015-02-02 23:53:53 +03:00
|
|
|
|
2015-07-20 15:59:50 +03:00
|
|
|
if (noRollupOnAnchor) {
|
|
|
|
rollup = false;
|
2013-11-04 20:22:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-26 17:15:22 +04:00
|
|
|
|
2015-02-02 23:53:53 +03:00
|
|
|
if (rollup) {
|
|
|
|
// if a number of popups to close has been specified, determine the last
|
|
|
|
// popup to close
|
|
|
|
nsIContent* lastPopup = nullptr;
|
|
|
|
if (aCount != UINT32_MAX) {
|
|
|
|
nsMenuChainItem* last = item;
|
|
|
|
while (--aCount && last->GetParent()) {
|
|
|
|
last = last->GetParent();
|
|
|
|
}
|
|
|
|
if (last) {
|
|
|
|
lastPopup = last->Content();
|
|
|
|
}
|
2009-06-12 22:23:16 +04:00
|
|
|
}
|
|
|
|
|
2015-02-02 23:53:53 +03:00
|
|
|
nsPresContext* presContext = item->Frame()->PresContext();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> viewManager = presContext->PresShell()->GetViewManager();
|
2015-01-08 04:52:20 +03:00
|
|
|
|
2015-02-02 23:53:53 +03:00
|
|
|
HidePopup(item->Content(), true, true, false, true, lastPopup);
|
2015-01-08 04:52:20 +03:00
|
|
|
|
2015-02-02 23:53:53 +03:00
|
|
|
if (aFlush) {
|
|
|
|
// The popup's visibility doesn't update until the minimize animation has
|
|
|
|
// finished, so call UpdateWidgetGeometry to update it right away.
|
|
|
|
viewManager->UpdateWidgetGeometry();
|
|
|
|
}
|
2015-01-08 04:52:20 +03:00
|
|
|
}
|
2007-12-03 19:33:42 +03:00
|
|
|
}
|
2011-11-08 23:59:07 +04:00
|
|
|
|
2012-10-26 17:15:22 +04:00
|
|
|
return consume;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2011-11-08 23:59:07 +04:00
|
|
|
bool nsXULPopupManager::ShouldRollupOnMouseWheelEvent()
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
// should rollup only for autocomplete widgets
|
|
|
|
// XXXndeakin this should really be something the popup has more control over
|
2011-01-20 06:21:38 +03:00
|
|
|
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2011-01-20 06:21:38 +03:00
|
|
|
if (!item)
|
2011-11-08 23:59:07 +04:00
|
|
|
return false;
|
2011-01-20 06:21:38 +03:00
|
|
|
|
|
|
|
nsIContent* content = item->Frame()->GetContent();
|
2011-11-08 23:59:07 +04:00
|
|
|
if (!content)
|
|
|
|
return false;
|
2011-01-20 06:21:38 +03:00
|
|
|
|
2013-01-26 02:30:50 +04:00
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::rolluponmousewheel,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::rolluponmousewheel,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
|
|
|
return false;
|
|
|
|
|
2011-11-08 23:59:07 +04:00
|
|
|
nsAutoString value;
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::type, value);
|
|
|
|
return StringBeginsWith(value, NS_LITERAL_STRING("autocomplete"));
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:48:48 +04:00
|
|
|
bool nsXULPopupManager::ShouldConsumeOnMouseWheelEvent()
|
|
|
|
{
|
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (!item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsMenuPopupFrame* frame = item->Frame();
|
|
|
|
if (frame->PopupType() != ePopupTypePanel)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
return !(content && content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::arrow, eCaseMatters));
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// a menu should not roll up if activated by a mouse activate message (eg. X-mouse)
|
2011-11-08 23:59:07 +04:00
|
|
|
bool nsXULPopupManager::ShouldRollupOnMouseActivate()
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2011-11-08 23:59:07 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2009-06-12 22:23:16 +04:00
|
|
|
nsXULPopupManager::GetSubmenuWidgetChain(nsTArray<nsIWidget*> *aWidgetChain)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-08-09 12:53:19 +04:00
|
|
|
// this method is used by the widget code to determine the list of popups
|
|
|
|
// that are open. If a mouse click occurs outside one of these popups, the
|
|
|
|
// panels will roll up. If the click is inside a popup, they will not roll up
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0, sameTypeCount = 0;
|
2009-06-12 22:23:16 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(aWidgetChain, "null parameter");
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
2011-12-02 01:35:42 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget = item->Frame()->GetWidget();
|
2007-09-18 18:32:22 +04:00
|
|
|
NS_ASSERTION(widget, "open popup has no widget");
|
2009-06-12 22:23:16 +04:00
|
|
|
aWidgetChain->AppendElement(widget.get());
|
2007-08-09 12:53:19 +04:00
|
|
|
// In the case when a menulist inside a panel is open, clicking in the
|
|
|
|
// panel should still roll up the menu, so if a different type is found,
|
|
|
|
// stop scanning.
|
2007-11-09 11:00:23 +03:00
|
|
|
nsMenuChainItem* parent = item->GetParent();
|
2009-06-12 22:23:16 +04:00
|
|
|
if (!sameTypeCount) {
|
|
|
|
count++;
|
|
|
|
if (!parent || item->Frame()->PopupType() != parent->Frame()->PopupType() ||
|
|
|
|
item->IsContextMenu() != parent->IsContextMenu()) {
|
|
|
|
sameTypeCount = count;
|
|
|
|
}
|
|
|
|
}
|
2007-08-09 12:53:19 +04:00
|
|
|
item = parent;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2009-06-12 22:23:16 +04:00
|
|
|
|
|
|
|
return sameTypeCount;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2012-10-26 17:15:22 +04:00
|
|
|
nsIWidget*
|
|
|
|
nsXULPopupManager::GetRollupWidget()
|
|
|
|
{
|
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
return item ? item->Frame()->GetWidget() : nullptr;
|
|
|
|
}
|
|
|
|
|
2008-01-17 10:00:31 +03:00
|
|
|
void
|
2010-07-27 17:38:02 +04:00
|
|
|
nsXULPopupManager::AdjustPopupsOnWindowChange(nsPIDOMWindow* aWindow)
|
2007-11-28 23:18:11 +03:00
|
|
|
{
|
2010-07-27 17:38:02 +04:00
|
|
|
// When the parent window is moved, adjust any child popups. Dismissable
|
|
|
|
// menus and panels are expected to roll up when a window is moved, so there
|
|
|
|
// is no need to check these popups, only the noautohide popups.
|
2014-03-19 20:48:08 +04:00
|
|
|
|
|
|
|
// The items are added to a list so that they can be adjusted bottom to top.
|
|
|
|
nsTArray<nsMenuPopupFrame *> list;
|
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mNoHidePanels;
|
2007-11-28 23:18:11 +03:00
|
|
|
while (item) {
|
2010-07-27 17:38:02 +04:00
|
|
|
// only move popups that are within the same window and where auto
|
|
|
|
// positioning has not been disabled
|
2014-03-19 20:48:08 +04:00
|
|
|
nsMenuPopupFrame* frame = item->Frame();
|
2010-07-27 17:38:02 +04:00
|
|
|
if (frame->GetAutoPosition()) {
|
|
|
|
nsIContent* popup = frame->GetContent();
|
|
|
|
if (popup) {
|
|
|
|
nsIDocument* document = popup->GetCurrentDoc();
|
|
|
|
if (document) {
|
|
|
|
nsPIDOMWindow* window = document->GetWindow();
|
|
|
|
if (window) {
|
|
|
|
window = window->GetPrivateRoot();
|
|
|
|
if (window == aWindow) {
|
2014-03-19 20:48:08 +04:00
|
|
|
list.AppendElement(frame);
|
2010-07-27 17:38:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 23:18:11 +03:00
|
|
|
item = item->GetParent();
|
|
|
|
}
|
2014-03-19 20:48:08 +04:00
|
|
|
|
|
|
|
for (int32_t l = list.Length() - 1; l >= 0; l--) {
|
|
|
|
list[l]->SetPopupPosition(nullptr, true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXULPopupManager::AdjustPopupsOnWindowChange(nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
if (aPresShell->GetDocument()) {
|
|
|
|
AdjustPopupsOnWindowChange(aPresShell->GetDocument()->GetWindow());
|
|
|
|
}
|
2007-11-28 23:18:11 +03:00
|
|
|
}
|
|
|
|
|
2010-07-27 17:38:02 +04:00
|
|
|
static
|
2011-11-21 21:53:20 +04:00
|
|
|
nsMenuPopupFrame* GetPopupToMoveOrResize(nsIFrame* aFrame)
|
2010-07-27 17:38:02 +04:00
|
|
|
{
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(aFrame);
|
|
|
|
if (!menuPopupFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-27 17:38:02 +04:00
|
|
|
|
|
|
|
// no point moving or resizing hidden popups
|
2014-07-14 21:39:04 +04:00
|
|
|
if (!menuPopupFrame->IsVisible())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-27 17:38:02 +04:00
|
|
|
|
2013-04-29 00:27:25 +04:00
|
|
|
nsIWidget* widget = menuPopupFrame->GetWidget();
|
|
|
|
if (widget && !widget->IsVisible())
|
|
|
|
return nullptr;
|
|
|
|
|
2010-07-27 17:38:02 +04:00
|
|
|
return menuPopupFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-21 21:53:20 +04:00
|
|
|
nsXULPopupManager::PopupMoved(nsIFrame* aFrame, nsIntPoint aPnt)
|
2010-07-27 17:38:02 +04:00
|
|
|
{
|
2011-11-21 21:53:20 +04:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aFrame);
|
2010-07-27 17:38:02 +04:00
|
|
|
if (!menuPopupFrame)
|
|
|
|
return;
|
|
|
|
|
2014-04-05 03:59:03 +04:00
|
|
|
nsView* view = menuPopupFrame->GetView();
|
|
|
|
if (!view)
|
|
|
|
return;
|
2012-09-29 15:36:09 +04:00
|
|
|
|
2010-07-27 17:38:02 +04:00
|
|
|
// Don't do anything if the popup is already at the specified location. This
|
|
|
|
// prevents recursive calls when a popup is positioned.
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect curDevSize = view->CalcWidgetBounds(eWindowType_popup);
|
2011-12-02 01:35:42 +04:00
|
|
|
nsIWidget* widget = menuPopupFrame->GetWidget();
|
2014-04-05 03:59:03 +04:00
|
|
|
if (curDevSize.x == aPnt.x && curDevSize.y == aPnt.y &&
|
2015-11-13 12:37:02 +03:00
|
|
|
(!widget || widget->GetClientOffset() ==
|
|
|
|
menuPopupFrame->GetLastClientOffset())) {
|
2014-04-05 03:59:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the popup's position using SetPopupPosition if the popup is
|
|
|
|
// anchored and at the parent level as these maintain their position
|
|
|
|
// relative to the parent window. Otherwise, just update the popup to
|
|
|
|
// the specified screen coordinates.
|
|
|
|
if (menuPopupFrame->IsAnchored() &&
|
|
|
|
menuPopupFrame->PopupLevel() == ePopupLevelParent) {
|
|
|
|
menuPopupFrame->SetPopupPosition(nullptr, true, false);
|
|
|
|
}
|
|
|
|
else {
|
2015-11-10 02:22:25 +03:00
|
|
|
CSSPoint cssPos = LayoutDeviceIntPoint::FromUnknownPoint(aPnt)
|
2015-09-29 03:17:34 +03:00
|
|
|
/ menuPopupFrame->PresContext()->CSSToDevPixelScale();
|
|
|
|
menuPopupFrame->MoveTo(RoundedToInt(cssPos), false);
|
2010-07-27 17:38:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-30 18:36:01 +03:00
|
|
|
nsXULPopupManager::PopupResized(nsIFrame* aFrame, LayoutDeviceIntSize aSize)
|
2010-07-27 17:38:02 +04:00
|
|
|
{
|
2011-11-21 21:53:20 +04:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aFrame);
|
2010-07-27 17:38:02 +04:00
|
|
|
if (!menuPopupFrame)
|
|
|
|
return;
|
|
|
|
|
2013-03-27 04:02:57 +04:00
|
|
|
nsView* view = menuPopupFrame->GetView();
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect curDevSize = view->CalcWidgetBounds(eWindowType_popup);
|
2013-03-27 04:02:57 +04:00
|
|
|
// If the size is what we think it is, we have nothing to do.
|
|
|
|
if (curDevSize.width == aSize.width && curDevSize.height == aSize.height)
|
|
|
|
return;
|
2010-07-27 17:38:02 +04:00
|
|
|
|
2013-03-27 04:02:57 +04:00
|
|
|
// The size is different. Convert the actual size to css pixels and store it
|
|
|
|
// as 'width' and 'height' attributes on the popup.
|
|
|
|
nsPresContext* presContext = menuPopupFrame->PresContext();
|
2012-09-29 15:36:09 +04:00
|
|
|
|
2015-03-30 18:36:01 +03:00
|
|
|
CSSIntSize newCSS(presContext->DevPixelsToIntCSSPixels(aSize.width),
|
|
|
|
presContext->DevPixelsToIntCSSPixels(aSize.height));
|
2012-09-29 15:36:09 +04:00
|
|
|
|
2013-03-27 04:02:57 +04:00
|
|
|
nsIContent* popup = menuPopupFrame->GetContent();
|
|
|
|
nsAutoString width, height;
|
|
|
|
width.AppendInt(newCSS.width);
|
|
|
|
height.AppendInt(newCSS.height);
|
|
|
|
popup->SetAttr(kNameSpaceID_None, nsGkAtoms::width, width, false);
|
|
|
|
popup->SetAttr(kNameSpaceID_None, nsGkAtoms::height, height, true);
|
2010-07-27 17:38:02 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame*
|
|
|
|
nsXULPopupManager::GetPopupFrameForContent(nsIContent* aContent, bool aShouldFlush)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2010-05-13 17:42:57 +04:00
|
|
|
if (aShouldFlush) {
|
|
|
|
nsIDocument *document = aContent->GetCurrentDoc();
|
|
|
|
if (document) {
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = document->GetShell();
|
2010-05-13 17:42:57 +04:00
|
|
|
if (presShell)
|
2010-09-06 07:30:17 +04:00
|
|
|
presShell->FlushPendingNotifications(Flush_Layout);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
return do_QueryFrame(aContent->GetPrimaryFrame());
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem*
|
|
|
|
nsXULPopupManager::GetTopVisibleMenu()
|
|
|
|
{
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mPopups;
|
2007-08-15 18:03:21 +04:00
|
|
|
while (item && item->Frame()->PopupState() == ePopupInvisible)
|
|
|
|
item = item->GetParent();
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULPopupManager::GetMouseLocation(nsIDOMNode** aNode, int32_t* aOffset)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
*aNode = mRangeParent;
|
|
|
|
NS_IF_ADDREF(*aNode);
|
|
|
|
*aOffset = mRangeOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-09 20:17:19 +04:00
|
|
|
nsXULPopupManager::InitTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup,
|
|
|
|
nsIContent** aTriggerContent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2015-02-04 23:21:03 +03:00
|
|
|
mCachedMousePoint = LayoutDeviceIntPoint(0, 0);
|
2007-07-17 16:21:53 +04:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
if (aTriggerContent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aTriggerContent = nullptr;
|
2010-08-09 20:17:19 +04:00
|
|
|
if (aEvent) {
|
|
|
|
// get the trigger content from the event
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<nsIContent> target = do_QueryInterface(
|
|
|
|
aEvent->InternalDOMEvent()->GetTarget());
|
|
|
|
target.forget(aTriggerContent);
|
2010-08-09 20:17:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-09 11:41:32 +04:00
|
|
|
mCachedModifiers = 0;
|
|
|
|
|
2011-08-26 11:43:49 +04:00
|
|
|
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aEvent);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (uiEvent) {
|
|
|
|
uiEvent->GetRangeParent(getter_AddRefs(mRangeParent));
|
|
|
|
uiEvent->GetRangeOffset(&mRangeOffset);
|
2007-07-17 16:21:53 +04:00
|
|
|
|
|
|
|
// get the event coordinates relative to the root frame of the document
|
|
|
|
// containing the popup.
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_ASSERTION(aPopup, "Expected a popup node");
|
2013-10-02 07:46:04 +04:00
|
|
|
WidgetEvent* event = aEvent->GetInternalNSEvent();
|
2012-06-11 03:44:50 +04:00
|
|
|
if (event) {
|
2013-10-18 10:10:26 +04:00
|
|
|
WidgetInputEvent* inputEvent = event->AsInputEvent();
|
|
|
|
if (inputEvent) {
|
|
|
|
mCachedModifiers = inputEvent->modifiers;
|
2012-06-11 03:44:50 +04:00
|
|
|
}
|
|
|
|
nsIDocument* doc = aPopup->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsIPresShell* presShell = doc->GetShell();
|
|
|
|
nsPresContext* presContext;
|
|
|
|
if (presShell && (presContext = presShell->GetPresContext())) {
|
|
|
|
nsPresContext* rootDocPresContext =
|
|
|
|
presContext->GetRootPresContext();
|
|
|
|
if (!rootDocPresContext)
|
|
|
|
return;
|
|
|
|
nsIFrame* rootDocumentRootFrame = rootDocPresContext->
|
|
|
|
PresShell()->FrameManager()->GetRootFrame();
|
2014-08-04 09:28:50 +04:00
|
|
|
if ((event->mClass == eMouseEventClass ||
|
2014-08-04 09:28:51 +04:00
|
|
|
event->mClass == eMouseScrollEventClass ||
|
2014-08-04 09:28:51 +04:00
|
|
|
event->mClass == eWheelEventClass) &&
|
2013-10-22 12:55:20 +04:00
|
|
|
!event->AsGUIEvent()->widget) {
|
2012-06-11 03:44:50 +04:00
|
|
|
// no widget, so just use the client point if available
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
|
|
|
|
nsIntPoint clientPt;
|
|
|
|
mouseEvent->GetClientX(&clientPt.x);
|
|
|
|
mouseEvent->GetClientY(&clientPt.y);
|
|
|
|
|
|
|
|
// XXX this doesn't handle IFRAMEs in transforms
|
|
|
|
nsPoint thisDocToRootDocOffset = presShell->FrameManager()->
|
|
|
|
GetRootFrame()->GetOffsetToCrossDoc(rootDocumentRootFrame);
|
|
|
|
// convert to device pixels
|
|
|
|
mCachedMousePoint.x = presContext->AppUnitsToDevPixels(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(clientPt.x) + thisDocToRootDocOffset.x);
|
|
|
|
mCachedMousePoint.y = presContext->AppUnitsToDevPixels(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(clientPt.y) + thisDocToRootDocOffset.y);
|
|
|
|
}
|
|
|
|
else if (rootDocumentRootFrame) {
|
|
|
|
nsPoint pnt =
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(event, rootDocumentRootFrame);
|
2015-02-04 23:21:03 +03:00
|
|
|
mCachedMousePoint = LayoutDeviceIntPoint(rootDocPresContext->AppUnitsToDevPixels(pnt.x),
|
|
|
|
rootDocPresContext->AppUnitsToDevPixels(pnt.y));
|
2007-07-17 16:21:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mRangeParent = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
mRangeOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULPopupManager::SetActiveMenuBar(nsMenuBarFrame* aMenuBar, bool aActivate)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
if (aActivate)
|
|
|
|
mActiveMenuBar = aMenuBar;
|
|
|
|
else if (mActiveMenuBar == aMenuBar)
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveMenuBar = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
UpdateKeyboardListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowMenu(nsIContent *aMenu,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSelectFirstItem,
|
|
|
|
bool aAsynchronous)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2008-02-21 20:40:12 +03:00
|
|
|
// generate any template content first. Otherwise, the menupopup may not
|
|
|
|
// have been created yet.
|
|
|
|
if (aMenu) {
|
|
|
|
nsIContent* element = aMenu;
|
|
|
|
do {
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulelem = do_QueryInterface(element);
|
|
|
|
if (xulelem) {
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder;
|
|
|
|
xulelem->GetBuilder(getter_AddRefs(builder));
|
|
|
|
if (builder) {
|
2011-10-17 18:59:28 +04:00
|
|
|
builder->CreateContents(aMenu, true);
|
2008-02-21 20:40:12 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
element = element->GetParent();
|
|
|
|
} while (element);
|
|
|
|
}
|
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(aMenu->GetPrimaryFrame());
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!menuFrame || !menuFrame->IsMenu())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsMenuPopupFrame* popupFrame = menuFrame->GetPopup();
|
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// inherit whether or not we're a context menu from the parent
|
2011-09-29 10:19:26 +04:00
|
|
|
bool parentIsContextMenu = false;
|
|
|
|
bool onMenuBar = false;
|
|
|
|
bool onmenu = menuFrame->IsOnMenu();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2008-12-05 19:37:31 +03:00
|
|
|
nsMenuParent* parent = menuFrame->GetMenuParent();
|
2007-07-04 19:49:38 +04:00
|
|
|
if (parent && onmenu) {
|
|
|
|
parentIsContextMenu = parent->IsContextMenu();
|
|
|
|
onMenuBar = parent->IsMenuBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString position;
|
|
|
|
if (onMenuBar || !onmenu)
|
|
|
|
position.AssignLiteral("after_start");
|
|
|
|
else
|
|
|
|
position.AssignLiteral("end_before");
|
2010-08-09 20:17:19 +04:00
|
|
|
|
2010-09-06 07:30:17 +04:00
|
|
|
// there is no trigger event for menus
|
2012-07-30 18:20:58 +04:00
|
|
|
InitTriggerEvent(nullptr, nullptr, nullptr);
|
2015-05-08 21:49:54 +03:00
|
|
|
popupFrame->InitializePopup(menuFrame->GetAnchor(), nullptr, position, 0, 0,
|
|
|
|
MenuPopupAnchorType_Node, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
if (aAsynchronous) {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2010-09-06 07:30:17 +04:00
|
|
|
new nsXULPopupShowingEvent(popupFrame->GetContent(),
|
2007-07-04 19:49:38 +04:00
|
|
|
parentIsContextMenu, aSelectFirstItem);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
|
|
|
else {
|
2007-08-03 18:05:07 +04:00
|
|
|
nsCOMPtr<nsIContent> popupContent = popupFrame->GetContent();
|
2010-09-06 07:30:17 +04:00
|
|
|
FirePopupShowingEvent(popupContent, parentIsContextMenu, aSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowPopup(nsIContent* aPopup,
|
|
|
|
nsIContent* aAnchorContent,
|
|
|
|
const nsAString& aPosition,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aAttributesOverride,
|
|
|
|
bool aSelectFirstItem,
|
2007-11-17 18:47:38 +03:00
|
|
|
nsIDOMEvent* aTriggerEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopupFrameForContent(aPopup, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
nsCOMPtr<nsIContent> triggerContent;
|
|
|
|
InitTriggerEvent(aTriggerEvent, aPopup, getter_AddRefs(triggerContent));
|
2007-11-17 18:47:38 +03:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
popupFrame->InitializePopup(aAnchorContent, triggerContent, aPosition,
|
2015-05-08 21:49:54 +03:00
|
|
|
aXPos, aYPos, MenuPopupAnchorType_Node, aAttributesOverride);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2010-09-06 07:30:17 +04:00
|
|
|
FirePopupShowingEvent(aPopup, aIsContextMenu, aSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowPopupAtScreen(nsIContent* aPopup,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
2007-11-17 18:47:38 +03:00
|
|
|
nsIDOMEvent* aTriggerEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopupFrameForContent(aPopup, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
nsCOMPtr<nsIContent> triggerContent;
|
|
|
|
InitTriggerEvent(aTriggerEvent, aPopup, getter_AddRefs(triggerContent));
|
2007-11-17 18:47:38 +03:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
popupFrame->InitializePopupAtScreen(triggerContent, aXPos, aYPos, aIsContextMenu);
|
2011-10-17 18:59:28 +04:00
|
|
|
FirePopupShowingEvent(aPopup, aIsContextMenu, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowPopupAtScreenRect(nsIContent* aPopup,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aAttributesOverride,
|
|
|
|
nsIDOMEvent* aTriggerEvent)
|
|
|
|
{
|
|
|
|
nsMenuPopupFrame* popupFrame = GetPopupFrameForContent(aPopup, true);
|
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> triggerContent;
|
|
|
|
InitTriggerEvent(aTriggerEvent, aPopup, getter_AddRefs(triggerContent));
|
|
|
|
|
|
|
|
popupFrame->InitializePopupAtRect(triggerContent, aPosition,
|
|
|
|
aRect, aAttributesOverride);
|
|
|
|
|
|
|
|
FirePopupShowingEvent(aPopup, aIsContextMenu, false);
|
|
|
|
}
|
|
|
|
|
2010-09-11 00:22:17 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowTooltipAtScreen(nsIContent* aPopup,
|
|
|
|
nsIContent* aTriggerContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aXPos, int32_t aYPos)
|
2010-09-11 00:22:17 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopupFrameForContent(aPopup, true);
|
2010-09-11 00:22:17 +04:00
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
InitTriggerEvent(nullptr, nullptr, nullptr);
|
2010-09-11 00:22:17 +04:00
|
|
|
|
2013-07-16 18:12:48 +04:00
|
|
|
nsPresContext* pc = popupFrame->PresContext();
|
2015-02-04 23:21:03 +03:00
|
|
|
mCachedMousePoint = LayoutDeviceIntPoint(pc->CSSPixelsToDevPixels(aXPos),
|
|
|
|
pc->CSSPixelsToDevPixels(aYPos));
|
2013-07-16 18:12:48 +04:00
|
|
|
|
2010-10-08 00:38:13 +04:00
|
|
|
// coordinates are relative to the root widget
|
2013-07-16 18:12:48 +04:00
|
|
|
nsPresContext* rootPresContext = pc->GetRootPresContext();
|
2010-10-08 00:38:13 +04:00
|
|
|
if (rootPresContext) {
|
2013-07-16 18:12:48 +04:00
|
|
|
nsIWidget *rootWidget = rootPresContext->GetRootWidget();
|
|
|
|
if (rootWidget) {
|
2015-02-04 23:21:03 +03:00
|
|
|
mCachedMousePoint -= rootWidget->WidgetToScreenOffset();
|
2013-07-16 18:12:48 +04:00
|
|
|
}
|
2010-10-08 00:38:13 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
popupFrame->InitializePopupAtScreen(aTriggerContent, aXPos, aYPos, false);
|
2010-09-11 00:22:17 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
FirePopupShowingEvent(aPopup, false, false);
|
2010-09-11 00:22:17 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowPopupWithAnchorAlign(nsIContent* aPopup,
|
|
|
|
nsIContent* aAnchorContent,
|
|
|
|
nsAString& aAnchor,
|
|
|
|
nsAString& aAlign,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopupFrameForContent(aPopup, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!popupFrame || !MayShowPopup(popupFrame))
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
InitTriggerEvent(nullptr, nullptr, nullptr);
|
2007-11-17 18:47:38 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
popupFrame->InitializePopupWithAnchorAlign(aAnchorContent, aAnchor,
|
|
|
|
aAlign, aXPos, aYPos);
|
2011-10-17 18:59:28 +04:00
|
|
|
FirePopupShowingEvent(aPopup, aIsContextMenu, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
static void
|
2014-08-06 09:19:29 +04:00
|
|
|
CheckCaretDrawingState()
|
|
|
|
{
|
2008-04-01 12:35:11 +04:00
|
|
|
// There is 1 caret per document, we need to find the focused
|
|
|
|
// document and erase its caret.
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
fm->GetFocusedWindow(getter_AddRefs(window));
|
|
|
|
if (!window)
|
|
|
|
return;
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
|
|
|
|
MOZ_ASSERT(piWindow);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> focusedDoc = piWindow->GetDoc();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!focusedDoc)
|
|
|
|
return;
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell* presShell = focusedDoc->GetShell();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!presShell)
|
|
|
|
return;
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsCaret> caret = presShell->GetCaret();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (!caret)
|
|
|
|
return;
|
2014-08-06 09:19:29 +04:00
|
|
|
caret->SchedulePaint();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
2008-04-01 12:35:11 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::ShowPopupCallback(nsIContent* aPopup,
|
|
|
|
nsMenuPopupFrame* aPopupFrame,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aSelectFirstItem)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType popupType = aPopupFrame->PopupType();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ismenu = (popupType == ePopupTypeMenu);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
nsMenuChainItem* item =
|
2007-08-16 05:09:58 +04:00
|
|
|
new nsMenuChainItem(aPopupFrame, aIsContextMenu, popupType);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2007-11-13 00:52:13 +03:00
|
|
|
// install keyboard event listeners for navigating menus. For panels, the
|
|
|
|
// escape key may be used to close the panel. However, the ignorekeys
|
|
|
|
// attribute may be used to disable adding these event listeners for popups
|
|
|
|
// that want to handle their own keyboard events.
|
2015-09-17 18:20:33 +03:00
|
|
|
nsAutoString ignorekeys;
|
|
|
|
aPopup->GetAttr(kNameSpaceID_None, nsGkAtoms::ignorekeys, ignorekeys);
|
|
|
|
if (ignorekeys.EqualsLiteral("true")) {
|
|
|
|
item->SetIgnoreKeys(eIgnoreKeys_True);
|
|
|
|
} else if (ignorekeys.EqualsLiteral("handled")) {
|
|
|
|
item->SetIgnoreKeys(eIgnoreKeys_Handled);
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-11-13 00:52:13 +03:00
|
|
|
if (ismenu) {
|
2007-07-04 19:49:38 +04:00
|
|
|
// if the menu is on a menubar, use the menubar's listener instead
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(aPopupFrame->GetParent());
|
2010-08-09 20:17:19 +04:00
|
|
|
if (menuFrame) {
|
2007-07-04 19:49:38 +04:00
|
|
|
item->SetOnMenuBar(menuFrame->IsOnMenuBar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// use a weak frame as the popup will set an open attribute if it is a menu
|
|
|
|
nsWeakFrame weakFrame(aPopupFrame);
|
2010-09-06 07:30:17 +04:00
|
|
|
aPopupFrame->ShowPopup(aIsContextMenu, aSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
|
|
|
|
|
|
|
// popups normally hide when an outside click occurs. Panels may use
|
|
|
|
// the noautohide attribute to disable this behaviour. It is expected
|
|
|
|
// that the application will hide these popups manually. The tooltip
|
|
|
|
// listener will handle closing the tooltip also.
|
2007-11-28 23:18:11 +03:00
|
|
|
if (aPopupFrame->IsNoAutoHide() || popupType == ePopupTypeTooltip) {
|
2008-12-05 19:37:30 +03:00
|
|
|
item->SetParent(mNoHidePanels);
|
|
|
|
mNoHidePanels = item;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* oldmenu = nullptr;
|
2008-12-05 19:37:30 +03:00
|
|
|
if (mPopups)
|
|
|
|
oldmenu = mPopups->Content();
|
|
|
|
item->SetParent(mPopups);
|
|
|
|
mPopups = item;
|
2007-07-04 19:49:38 +04:00
|
|
|
SetCaptureState(oldmenu);
|
|
|
|
}
|
|
|
|
|
2010-09-06 07:30:17 +04:00
|
|
|
if (aSelectFirstItem) {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuFrame* next = GetNextMenuItem(aPopupFrame, nullptr, true);
|
2010-09-06 07:30:17 +04:00
|
|
|
aPopupFrame->SetCurrentMenuItem(next);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2010-09-06 07:30:17 +04:00
|
|
|
if (ismenu)
|
|
|
|
UpdateMenuItems(aPopup);
|
|
|
|
|
2008-04-01 12:35:11 +04:00
|
|
|
// Caret visibility may have been affected, ensure that
|
|
|
|
// the caret isn't now drawn when it shouldn't be.
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
CheckCaretDrawingState();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::HidePopup(nsIContent* aPopup,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHideChain,
|
|
|
|
bool aDeselectMenu,
|
|
|
|
bool aAsynchronous,
|
2014-09-24 20:15:49 +04:00
|
|
|
bool aIsCancel,
|
2009-06-12 22:23:16 +04:00
|
|
|
nsIContent* aLastPopup)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2008-12-05 19:37:30 +03:00
|
|
|
// if the popup is on the nohide panels list, remove it but don't close any
|
|
|
|
// other panels
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool foundPanel = false;
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mNoHidePanels;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Content() == aPopup) {
|
2011-10-17 18:59:28 +04:00
|
|
|
foundPanel = true;
|
2007-07-04 19:49:38 +04:00
|
|
|
popupFrame = item->Frame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// when removing a menu, all of the child popups must be closed
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuChainItem* foundMenu = nullptr;
|
2008-12-05 19:37:30 +03:00
|
|
|
item = mPopups;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Content() == aPopup) {
|
|
|
|
foundMenu = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType type = ePopupTypePanel;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool deselectMenu = false;
|
2007-07-04 19:49:38 +04:00
|
|
|
nsCOMPtr<nsIContent> popupToHide, nextPopup, lastPopup;
|
|
|
|
if (foundMenu) {
|
2007-08-24 02:13:42 +04:00
|
|
|
// at this point, foundMenu will be set to the found item in the list. If
|
|
|
|
// foundMenu is the topmost menu, the one to remove, then there are no other
|
|
|
|
// popups to hide. If foundMenu is not the topmost menu, then there may be
|
2007-07-04 19:49:38 +04:00
|
|
|
// open submenus below it. In this case, we need to make sure that those
|
2007-08-24 02:13:42 +04:00
|
|
|
// submenus are closed up first. To do this, we scan up the menu list to
|
|
|
|
// find the topmost popup with only menus between it and foundMenu and
|
|
|
|
// close that menu first. In synchronous mode, the FirePopupHidingEvent
|
|
|
|
// method will be called which in turn calls HidePopupCallback to close up
|
|
|
|
// the next popup in the chain. These two methods will be called in
|
|
|
|
// sequence recursively to close up all the necessary popups. In
|
|
|
|
// asynchronous mode, a similar process occurs except that the
|
2007-11-17 18:47:38 +03:00
|
|
|
// FirePopupHidingEvent method is called asynchronously. In either case,
|
2007-08-24 02:13:42 +04:00
|
|
|
// nextPopup is set to the content node of the next popup to close, and
|
|
|
|
// lastPopup is set to the last popup in the chain to close, which will be
|
|
|
|
// aPopup, or null to close up all menus.
|
|
|
|
|
|
|
|
nsMenuChainItem* topMenu = foundMenu;
|
|
|
|
// Use IsMenu to ensure that foundMenu is a menu and scan down the child
|
|
|
|
// list until a non-menu is found. If foundMenu isn't a menu at all, don't
|
|
|
|
// scan and just close up this menu.
|
|
|
|
if (foundMenu->IsMenu()) {
|
|
|
|
item = topMenu->GetChild();
|
|
|
|
while (item && item->IsMenu()) {
|
|
|
|
topMenu = item;
|
|
|
|
item = item->GetChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
deselectMenu = aDeselectMenu;
|
2007-08-24 02:13:42 +04:00
|
|
|
popupToHide = topMenu->Content();
|
|
|
|
popupFrame = topMenu->Frame();
|
2007-08-16 05:09:58 +04:00
|
|
|
type = popupFrame->PopupType();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-24 02:13:42 +04:00
|
|
|
nsMenuChainItem* parent = topMenu->GetParent();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-03 18:05:07 +04:00
|
|
|
// close up another popup if there is one, and we are either hiding the
|
|
|
|
// entire chain or the item to hide isn't the topmost popup.
|
2007-08-24 02:13:42 +04:00
|
|
|
if (parent && (aHideChain || topMenu != foundMenu))
|
2007-08-03 18:05:07 +04:00
|
|
|
nextPopup = parent->Content();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
lastPopup = aLastPopup ? aLastPopup : (aHideChain ? nullptr : aPopup);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
else if (foundPanel) {
|
|
|
|
popupToHide = aPopup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (popupFrame) {
|
2007-08-03 18:05:07 +04:00
|
|
|
nsPopupState state = popupFrame->PopupState();
|
|
|
|
// if the popup is already being hidden, don't attempt to hide it again
|
|
|
|
if (state == ePopupHiding)
|
|
|
|
return;
|
|
|
|
// change the popup state to hiding. Don't set the hiding state if the
|
|
|
|
// popup is invisible, otherwise nsMenuPopupFrame::HidePopup will
|
|
|
|
// run again. In the invisible state, we just want the events to fire.
|
|
|
|
if (state != ePopupInvisible)
|
|
|
|
popupFrame->SetPopupState(ePopupHiding);
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
// for menus, popupToHide is always the frontmost item in the list to hide.
|
2007-07-04 19:49:38 +04:00
|
|
|
if (aAsynchronous) {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new nsXULPopupHidingEvent(popupToHide, nextPopup, lastPopup,
|
2014-09-24 20:15:49 +04:00
|
|
|
type, deselectMenu, aIsCancel);
|
2007-07-04 19:49:38 +04:00
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FirePopupHidingEvent(popupToHide, nextPopup, lastPopup,
|
2014-09-24 20:15:49 +04:00
|
|
|
popupFrame->PresContext(), type, deselectMenu, aIsCancel);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
// This is used to hide the popup after a transition finishes.
|
|
|
|
class TransitionEnder : public nsIDOMEventListener
|
|
|
|
{
|
2014-06-24 02:40:01 +04:00
|
|
|
protected:
|
|
|
|
virtual ~TransitionEnder() { }
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
public:
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
|
|
|
bool mDeselectMenu;
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(TransitionEnder)
|
2014-04-08 16:45:52 +04:00
|
|
|
|
|
|
|
TransitionEnder(nsIContent* aContent, bool aDeselectMenu)
|
|
|
|
: mContent(aContent), mDeselectMenu(aDeselectMenu)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override
|
2014-04-08 16:45:52 +04:00
|
|
|
{
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("transitionend"), this, false);
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
// Now hide the popup. There could be other properties transitioning, but
|
|
|
|
// we'll assume they all end at the same time and just hide the popup upon
|
|
|
|
// the first one ending.
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2014-04-08 16:45:52 +04:00
|
|
|
if (pm && popupFrame) {
|
|
|
|
pm->HidePopupCallback(mContent, popupFrame, nullptr, nullptr,
|
|
|
|
popupFrame->PopupType(), mDeselectMenu);
|
2014-04-08 16:45:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TransitionEnder)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TransitionEnder)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TransitionEnder)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(TransitionEnder, mContent);
|
2014-04-08 16:45:52 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::HidePopupCallback(nsIContent* aPopup,
|
|
|
|
nsMenuPopupFrame* aPopupFrame,
|
|
|
|
nsIContent* aNextPopup,
|
|
|
|
nsIContent* aLastPopup,
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType aPopupType,
|
2014-04-08 16:45:52 +04:00
|
|
|
bool aDeselectMenu)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-10-29 20:26:19 +03:00
|
|
|
if (mCloseTimer && mTimerMenu == aPopupFrame) {
|
2007-07-04 19:49:38 +04:00
|
|
|
mCloseTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mCloseTimer = nullptr;
|
|
|
|
mTimerMenu = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-03 18:05:07 +04:00
|
|
|
// The popup to hide is aPopup. Search the list again to find the item that
|
|
|
|
// corresponds to the popup to hide aPopup. This is done because it's
|
|
|
|
// possible someone added another item (attempted to open another popup)
|
|
|
|
// or removed a popup frame during the event processing so the item isn't at
|
|
|
|
// the front anymore.
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mNoHidePanels;
|
2007-08-03 18:05:07 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Content() == aPopup) {
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mNoHidePanels);
|
2007-08-03 18:05:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item) {
|
2008-12-05 19:37:30 +03:00
|
|
|
item = mPopups;
|
2007-08-03 18:05:07 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Content() == aPopup) {
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mPopups);
|
2007-08-03 18:05:07 +04:00
|
|
|
SetCaptureState(aPopup);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
nsWeakFrame weakFrame(aPopupFrame);
|
|
|
|
aPopupFrame->HidePopup(aDeselectMenu, ePopupClosed);
|
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
// send the popuphidden event synchronously. This event has no default
|
|
|
|
// behaviour.
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-04 13:54:11 +03:00
|
|
|
WidgetMouseEvent event(true, eXULPopupHidden, nullptr,
|
2014-04-08 16:45:52 +04:00
|
|
|
WidgetMouseEvent::eReal);
|
|
|
|
EventDispatcher::Dispatch(aPopup, aPopupFrame->PresContext(),
|
|
|
|
&event, nullptr, &status);
|
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// if there are more popups to close, look for the next one
|
|
|
|
if (aNextPopup && aPopup != aLastPopup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuChainItem* foundMenu = nullptr;
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mPopups;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Content() == aNextPopup) {
|
|
|
|
foundMenu = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// continue hiding the chain of popups until the last popup aLastPopup
|
|
|
|
// is reached, or until a popup of a different type is reached. This
|
|
|
|
// last check is needed so that a menulist inside a non-menu panel only
|
|
|
|
// closes the menu and not the panel as well.
|
2007-08-16 05:09:58 +04:00
|
|
|
if (foundMenu &&
|
|
|
|
(aLastPopup || aPopupType == foundMenu->PopupType())) {
|
2009-06-12 22:23:16 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsCOMPtr<nsIContent> popupToHide = item->Content();
|
2007-07-10 21:03:32 +04:00
|
|
|
nsMenuChainItem* parent = item->GetParent();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> nextPopup;
|
2007-07-10 21:03:32 +04:00
|
|
|
if (parent && popupToHide != aLastPopup)
|
|
|
|
nextPopup = parent->Content();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-03 18:05:07 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = item->Frame();
|
|
|
|
nsPopupState state = popupFrame->PopupState();
|
|
|
|
if (state == ePopupHiding)
|
|
|
|
return;
|
|
|
|
if (state != ePopupInvisible)
|
|
|
|
popupFrame->SetPopupState(ePopupHiding);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
FirePopupHidingEvent(popupToHide, nextPopup, aLastPopup,
|
2007-08-16 05:09:58 +04:00
|
|
|
popupFrame->PresContext(),
|
2014-04-08 16:45:52 +04:00
|
|
|
foundMenu->PopupType(), aDeselectMenu, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 17:38:04 +04:00
|
|
|
void
|
2011-11-21 21:53:20 +04:00
|
|
|
nsXULPopupManager::HidePopup(nsIFrame* aFrame)
|
2010-07-27 17:38:04 +04:00
|
|
|
{
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* popup = do_QueryFrame(aFrame);
|
|
|
|
if (popup)
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(aFrame->GetContent(), false, true, false, false);
|
2010-07-27 17:38:04 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::HidePopupAfterDelay(nsMenuPopupFrame* aPopup)
|
|
|
|
{
|
|
|
|
// Don't close up immediately.
|
|
|
|
// Kick off a close timer.
|
|
|
|
KillMenuTimer();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t menuDelay =
|
2011-09-09 06:27:13 +04:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_SubmenuDelay, 300); // ms
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// Kick off the timer.
|
|
|
|
mCloseTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
mCloseTimer->InitWithCallback(this, menuDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
|
|
|
|
// the popup will call PopupDestroyed if it is destroyed, which checks if it
|
|
|
|
// is set to mTimerMenu, so it should be safe to keep a reference to it
|
|
|
|
mTimerMenu = aPopup;
|
|
|
|
}
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
void
|
|
|
|
nsXULPopupManager::HidePopupsInList(const nsTArray<nsMenuPopupFrame *> &aFrames,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDeselectMenu)
|
2007-11-17 18:47:38 +03:00
|
|
|
{
|
|
|
|
// Create a weak frame list. This is done in a separate array with the
|
|
|
|
// right capacity predetermined, otherwise the array would get resized and
|
|
|
|
// move the weak frame pointers around.
|
|
|
|
nsTArray<nsWeakFrame> weakPopups(aFrames.Length());
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t f;
|
2007-11-17 18:47:38 +03:00
|
|
|
for (f = 0; f < aFrames.Length(); f++) {
|
|
|
|
nsWeakFrame* wframe = weakPopups.AppendElement();
|
|
|
|
if (wframe)
|
|
|
|
*wframe = aFrames[f];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (f = 0; f < weakPopups.Length(); f++) {
|
|
|
|
// check to ensure that the frame is still alive before hiding it.
|
|
|
|
if (weakPopups[f].IsAlive()) {
|
|
|
|
nsMenuPopupFrame* frame =
|
|
|
|
static_cast<nsMenuPopupFrame *>(weakPopups[f].GetFrame());
|
2011-10-17 18:59:28 +04:00
|
|
|
frame->HidePopup(true, ePopupInvisible);
|
2007-11-17 18:47:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
SetCaptureState(nullptr);
|
2007-11-17 18:47:38 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-02-08 23:23:05 +03:00
|
|
|
nsXULPopupManager::IsChildOfDocShell(nsIDocument* aDoc, nsIDocShellTreeItem* aExpected)
|
|
|
|
{
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem(aDoc->GetDocShell());
|
2008-02-08 23:23:05 +03:00
|
|
|
while(docShellItem) {
|
|
|
|
if (docShellItem == aExpected)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-02-08 23:23:05 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
docShellItem->GetParent(getter_AddRefs(parent));
|
|
|
|
docShellItem = parent;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-02-08 23:23:05 +03:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
2008-02-08 23:23:05 +03:00
|
|
|
nsXULPopupManager::HidePopupsInDocShell(nsIDocShellTreeItem* aDocShellToHide)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-11-17 18:47:38 +03:00
|
|
|
nsTArray<nsMenuPopupFrame *> popupsToHide;
|
|
|
|
|
|
|
|
// iterate to get the set of popup frames to hide
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mPopups;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
2007-08-03 18:05:07 +04:00
|
|
|
nsMenuChainItem* parent = item->GetParent();
|
2007-11-17 18:47:38 +03:00
|
|
|
if (item->Frame()->PopupState() != ePopupInvisible &&
|
2011-10-18 14:53:36 +04:00
|
|
|
IsChildOfDocShell(item->Content()->OwnerDoc(), aDocShellToHide)) {
|
2007-11-17 18:47:38 +03:00
|
|
|
nsMenuPopupFrame* frame = item->Frame();
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mPopups);
|
2007-08-03 18:05:07 +04:00
|
|
|
delete item;
|
2007-11-17 18:47:38 +03:00
|
|
|
popupsToHide.AppendElement(frame);
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
|
|
|
item = parent;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// now look for panels to hide
|
2008-12-05 19:37:30 +03:00
|
|
|
item = mNoHidePanels;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
2007-08-03 18:05:07 +04:00
|
|
|
nsMenuChainItem* parent = item->GetParent();
|
2007-11-17 18:47:38 +03:00
|
|
|
if (item->Frame()->PopupState() != ePopupInvisible &&
|
2011-10-18 14:53:36 +04:00
|
|
|
IsChildOfDocShell(item->Content()->OwnerDoc(), aDocShellToHide)) {
|
2007-11-17 18:47:38 +03:00
|
|
|
nsMenuPopupFrame* frame = item->Frame();
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mNoHidePanels);
|
2007-08-03 18:05:07 +04:00
|
|
|
delete item;
|
2007-11-17 18:47:38 +03:00
|
|
|
popupsToHide.AppendElement(frame);
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
|
|
|
item = parent;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2007-08-15 18:03:21 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
HidePopupsInList(popupsToHide, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-19 18:12:58 +04:00
|
|
|
nsXULPopupManager::ExecuteMenu(nsIContent* aMenu, nsXULMenuCommandEvent* aEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-08-30 19:43:10 +04:00
|
|
|
CloseMenuMode cmm = CloseMenuMode_Auto;
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 18:20:58 +04:00
|
|
|
{&nsGkAtoms::none, &nsGkAtoms::single, nullptr};
|
2007-08-30 19:43:10 +04:00
|
|
|
|
|
|
|
switch (aMenu->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::closemenu,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
cmm = CloseMenuMode_None;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
cmm = CloseMenuMode_Single;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// When a menuitem is selected to be executed, first hide all the open
|
|
|
|
// popups, but don't remove them yet. This is needed when a menu command
|
|
|
|
// opens a modal dialog. The views associated with the popups needed to be
|
|
|
|
// hidden and the accesibility events fired before the command executes, but
|
|
|
|
// the popuphiding/popuphidden events are fired afterwards.
|
2007-11-17 18:47:38 +03:00
|
|
|
nsTArray<nsMenuPopupFrame *> popupsToHide;
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2007-08-30 19:43:10 +04:00
|
|
|
if (cmm != CloseMenuMode_None) {
|
|
|
|
while (item) {
|
|
|
|
// if it isn't a <menupopup>, don't close it automatically
|
|
|
|
if (!item->IsMenu())
|
|
|
|
break;
|
|
|
|
nsMenuChainItem* next = item->GetParent();
|
2007-11-17 18:47:38 +03:00
|
|
|
popupsToHide.AppendElement(item->Frame());
|
2007-08-30 19:43:10 +04:00
|
|
|
if (cmm == CloseMenuMode_Single) // only close one level of menu
|
|
|
|
break;
|
|
|
|
item = next;
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// Now hide the popups. If the closemenu mode is auto, deselect the menu,
|
|
|
|
// otherwise only one popup is closing, so keep the parent menu selected.
|
|
|
|
HidePopupsInList(popupsToHide, cmm == CloseMenuMode_Auto);
|
|
|
|
}
|
2007-08-15 18:03:21 +04:00
|
|
|
|
2010-04-19 18:12:58 +04:00
|
|
|
aEvent->SetCloseMenuMode(cmm);
|
|
|
|
nsCOMPtr<nsIRunnable> event = aEvent;
|
2007-07-04 19:49:38 +04:00
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::FirePopupShowingEvent(nsIContent* aPopup,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aSelectFirstItem)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2010-09-06 07:30:17 +04:00
|
|
|
nsCOMPtr<nsIContent> popup = aPopup; // keep a strong reference to the popup
|
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(aPopup->GetPrimaryFrame());
|
|
|
|
if (!popupFrame)
|
2010-09-06 07:30:17 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsPresContext *presContext = popupFrame->PresContext();
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
|
|
|
|
nsPopupType popupType = popupFrame->PopupType();
|
|
|
|
|
|
|
|
// generate the child frames if they have not already been generated
|
|
|
|
if (!popupFrame->HasGeneratedChildren()) {
|
|
|
|
popupFrame->SetGeneratedChildren();
|
|
|
|
presShell->FrameConstructor()->GenerateChildFrames(popupFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the frame again
|
2012-07-31 04:43:28 +04:00
|
|
|
nsIFrame* frame = aPopup->GetPrimaryFrame();
|
2010-09-06 07:30:17 +04:00
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
presShell->FrameNeedsReflow(frame, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
// cache the popup so that document.popupNode can retrieve the trigger node
|
|
|
|
// during the popupshowing event. It will be cleared below after the event
|
|
|
|
// has fired.
|
|
|
|
mOpeningPopup = aPopup;
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-04 13:54:11 +03:00
|
|
|
WidgetMouseEvent event(true, eXULPopupShowing, nullptr,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal);
|
2009-09-03 23:30:07 +04:00
|
|
|
|
|
|
|
// coordinates are relative to the root widget
|
|
|
|
nsPresContext* rootPresContext =
|
2010-01-26 16:10:12 +03:00
|
|
|
presShell->GetPresContext()->GetRootPresContext();
|
|
|
|
if (rootPresContext) {
|
|
|
|
rootPresContext->PresShell()->GetViewManager()->
|
|
|
|
GetRootWidget(getter_AddRefs(event.widget));
|
|
|
|
}
|
|
|
|
else {
|
2012-07-30 18:20:58 +04:00
|
|
|
event.widget = nullptr;
|
2010-01-26 16:10:12 +03:00
|
|
|
}
|
2009-09-03 23:30:07 +04:00
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
event.refPoint = mCachedMousePoint;
|
2012-04-25 07:00:02 +04:00
|
|
|
event.modifiers = mCachedModifiers;
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(popup, presContext, &event, nullptr, &status);
|
2011-07-09 11:41:32 +04:00
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
mCachedMousePoint = LayoutDeviceIntPoint(0, 0);
|
2012-07-30 18:20:58 +04:00
|
|
|
mOpeningPopup = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2011-07-09 11:41:32 +04:00
|
|
|
mCachedModifiers = 0;
|
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
// if a panel, blur whatever has focus so that the panel can take the focus.
|
|
|
|
// This is done after the popupshowing event in case that event is cancelled.
|
|
|
|
// Using noautofocus="true" will disable this behaviour, which is needed for
|
|
|
|
// the autocomplete widget as it manages focus itself.
|
2010-09-06 07:30:17 +04:00
|
|
|
if (popupType == ePopupTypePanel &&
|
|
|
|
!popup->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
|
2007-08-16 05:09:58 +04:00
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
2010-09-06 07:30:17 +04:00
|
|
|
nsIDocument* doc = popup->GetCurrentDoc();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
|
|
|
|
// Only remove the focus if the currently focused item is ouside the
|
|
|
|
// popup. It isn't a big deal if the current focus is in a child popup
|
|
|
|
// inside the popup as that shouldn't be visible. This check ensures that
|
|
|
|
// a node inside the popup that is focused during a popupshowing event
|
|
|
|
// remains focused.
|
|
|
|
nsCOMPtr<nsIDOMElement> currentFocusElement;
|
|
|
|
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
|
|
|
|
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
|
|
|
|
if (doc && currentFocus &&
|
2010-09-06 07:30:17 +04:00
|
|
|
!nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, popup)) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
fm->ClearFocus(doc->GetWindow());
|
|
|
|
}
|
2007-08-16 05:09:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
// clear these as they are no longer valid
|
2012-07-30 18:20:58 +04:00
|
|
|
mRangeParent = nullptr;
|
2010-08-09 20:17:19 +04:00
|
|
|
mRangeOffset = 0;
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// get the frame again in case it went away
|
2012-07-31 04:43:28 +04:00
|
|
|
popupFrame = do_QueryFrame(aPopup->GetPrimaryFrame());
|
|
|
|
if (popupFrame) {
|
2010-08-09 20:17:19 +04:00
|
|
|
// if the event was cancelled, don't open the popup, reset its state back
|
|
|
|
// to closed and clear its trigger content.
|
2007-08-03 18:05:07 +04:00
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
popupFrame->SetPopupState(ePopupClosed);
|
2010-09-11 00:24:25 +04:00
|
|
|
popupFrame->ClearTriggerContent();
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-07-04 19:49:38 +04:00
|
|
|
ShowPopupCallback(aPopup, popupFrame, aIsContextMenu, aSelectFirstItem);
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::FirePopupHidingEvent(nsIContent* aPopup,
|
|
|
|
nsIContent* aNextPopup,
|
|
|
|
nsIContent* aLastPopup,
|
|
|
|
nsPresContext *aPresContext,
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType aPopupType,
|
2014-04-08 16:45:52 +04:00
|
|
|
bool aDeselectMenu,
|
2014-09-24 20:15:49 +04:00
|
|
|
bool aIsCancel)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = aPresContext->PresShell();
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-04 13:54:11 +03:00
|
|
|
WidgetMouseEvent event(true, eXULPopupHiding, nullptr,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal);
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(aPopup, aPresContext, &event, nullptr, &status);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
// when a panel is closed, blur whatever has focus inside the popup
|
|
|
|
if (aPopupType == ePopupTypePanel &&
|
|
|
|
!aPopup->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautofocus,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
nsIDocument* doc = aPopup->GetCurrentDoc();
|
|
|
|
|
|
|
|
// Remove the focus from the focused node only if it is inside the popup.
|
|
|
|
nsCOMPtr<nsIDOMElement> currentFocusElement;
|
|
|
|
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
|
|
|
|
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
|
|
|
|
if (doc && currentFocus &&
|
2009-08-27 19:51:41 +04:00
|
|
|
nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, aPopup)) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
fm->ClearFocus(doc->GetWindow());
|
|
|
|
}
|
2007-08-16 05:09:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// get frame again in case it went away
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(aPopup->GetPrimaryFrame());
|
|
|
|
if (popupFrame) {
|
2010-08-09 20:17:19 +04:00
|
|
|
// if the event was cancelled, don't hide the popup, and reset its
|
2007-08-03 18:05:07 +04:00
|
|
|
// state back to open. Only popups in chrome shells can prevent a popup
|
|
|
|
// from hiding.
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault &&
|
|
|
|
!popupFrame->IsInContentShell()) {
|
2014-07-14 21:39:04 +04:00
|
|
|
// XXXndeakin
|
|
|
|
// If an attempt was made to hide this popup before the popupshown event
|
|
|
|
// fired, then ePopupShown is set here even though it should be
|
|
|
|
// ePopupVisible. This probably isn't worth the hassle of handling.
|
|
|
|
popupFrame->SetPopupState(ePopupShown);
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-07-18 20:58:26 +04:00
|
|
|
// If the popup has an animate attribute and it is not set to false, check
|
|
|
|
// if it has a closing transition and wait for it to finish. The transition
|
2014-04-08 16:45:52 +04:00
|
|
|
// may still occur either way, but the view will be hidden and you won't be
|
|
|
|
// able to see it. If there is a next popup, indicating that mutliple popups
|
|
|
|
// are rolling up, don't wait and hide the popup right away since the effect
|
2014-07-18 20:58:26 +04:00
|
|
|
// would likely be undesirable. Transitions are currently disabled on Linux
|
|
|
|
// due to rendering issues on certain configurations.
|
2014-05-06 16:33:12 +04:00
|
|
|
#ifndef MOZ_WIDGET_GTK
|
2014-07-14 21:39:04 +04:00
|
|
|
if (!aNextPopup && aPopup->HasAttr(kNameSpaceID_None, nsGkAtoms::animate)) {
|
2014-04-08 16:45:52 +04:00
|
|
|
// If animate="false" then don't transition at all. If animate="cancel",
|
|
|
|
// only show the transition if cancelling the popup or rolling up.
|
|
|
|
// Otherwise, always show the transition.
|
2014-07-14 21:39:04 +04:00
|
|
|
nsAutoString animate;
|
|
|
|
aPopup->GetAttr(kNameSpaceID_None, nsGkAtoms::animate, animate);
|
|
|
|
|
2014-04-08 16:45:52 +04:00
|
|
|
if (!animate.EqualsLiteral("false") &&
|
2014-09-24 20:15:49 +04:00
|
|
|
(!animate.EqualsLiteral("cancel") || aIsCancel)) {
|
2014-07-14 21:39:04 +04:00
|
|
|
presShell->FlushPendingNotifications(Flush_Layout);
|
|
|
|
|
|
|
|
// Get the frame again in case the flush caused it to go away
|
|
|
|
popupFrame = do_QueryFrame(aPopup->GetPrimaryFrame());
|
|
|
|
if (!popupFrame)
|
|
|
|
return;
|
|
|
|
|
2015-07-01 21:43:13 +03:00
|
|
|
if (nsLayoutUtils::HasCurrentTransitions(popupFrame)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TransitionEnder> ender = new TransitionEnder(aPopup, aDeselectMenu);
|
2014-07-14 21:39:04 +04:00
|
|
|
aPopup->AddSystemEventListener(NS_LITERAL_STRING("transitionend"),
|
|
|
|
ender, false, false);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-08 16:45:52 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 16:33:12 +04:00
|
|
|
#endif
|
2014-04-08 16:45:52 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
HidePopupCallback(aPopup, popupFrame, aNextPopup, aLastPopup,
|
2014-04-08 16:45:52 +04:00
|
|
|
aPopupType, aDeselectMenu);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-11 21:23:30 +04:00
|
|
|
nsXULPopupManager::IsPopupOpen(nsIContent* aPopup)
|
|
|
|
{
|
2007-08-03 18:05:07 +04:00
|
|
|
// a popup is open if it is in the open list. The assertions ensure that the
|
|
|
|
// frame is in the correct state. If the popup is in the hiding or invisible
|
|
|
|
// state, it will still be in the open popup list until it is closed.
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mPopups;
|
2007-07-11 21:23:30 +04:00
|
|
|
while (item) {
|
2007-08-03 18:05:07 +04:00
|
|
|
if (item->Content() == aPopup) {
|
|
|
|
NS_ASSERTION(item->Frame()->IsOpen() ||
|
|
|
|
item->Frame()->PopupState() == ePopupHiding ||
|
|
|
|
item->Frame()->PopupState() == ePopupInvisible,
|
2007-08-30 19:43:10 +04:00
|
|
|
"popup in open list not actually open");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
2007-07-11 21:23:30 +04:00
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
item = mNoHidePanels;
|
2007-07-11 21:23:30 +04:00
|
|
|
while (item) {
|
2007-08-03 18:05:07 +04:00
|
|
|
if (item->Content() == aPopup) {
|
|
|
|
NS_ASSERTION(item->Frame()->IsOpen() ||
|
|
|
|
item->Frame()->PopupState() == ePopupHiding ||
|
|
|
|
item->Frame()->PopupState() == ePopupInvisible,
|
2007-08-30 19:43:10 +04:00
|
|
|
"popup in open list not actually open");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
2007-07-11 21:23:30 +04:00
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-11 21:23:30 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-12-05 19:37:31 +03:00
|
|
|
nsXULPopupManager::IsPopupOpenForMenuParent(nsMenuParent* aMenuParent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
2007-08-03 18:05:07 +04:00
|
|
|
nsMenuPopupFrame* popup = item->Frame();
|
|
|
|
if (popup && popup->IsOpen()) {
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(popup->GetParent());
|
2010-08-09 20:17:19 +04:00
|
|
|
if (menuFrame && menuFrame->GetMenuParent() == aMenuParent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-03 18:05:07 +04:00
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsXULPopupManager::GetTopPopup(nsPopupType aType)
|
|
|
|
{
|
2010-08-09 20:17:19 +04:00
|
|
|
if ((aType == ePopupTypePanel || aType == ePopupTypeTooltip) && mNoHidePanels)
|
2008-12-05 19:37:30 +03:00
|
|
|
return mNoHidePanels->Frame();
|
2007-08-16 05:09:58 +04:00
|
|
|
|
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
while (item) {
|
2007-09-18 19:00:43 +04:00
|
|
|
if (item->PopupType() == aType || aType == ePopupTypeAny)
|
2007-08-16 05:09:58 +04:00
|
|
|
return item->Frame();
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-08-16 05:09:58 +04:00
|
|
|
}
|
|
|
|
|
2012-11-29 20:14:13 +04:00
|
|
|
void
|
|
|
|
nsXULPopupManager::GetVisiblePopups(nsTArray<nsIFrame *>& aPopups)
|
2007-07-16 18:53:32 +04:00
|
|
|
{
|
2012-11-29 20:14:13 +04:00
|
|
|
aPopups.Clear();
|
2007-07-16 18:53:32 +04:00
|
|
|
|
2014-01-31 17:27:43 +04:00
|
|
|
// Iterate over both lists of popups
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mPopups;
|
2014-01-31 17:27:43 +04:00
|
|
|
for (int32_t list = 0; list < 2; list++) {
|
|
|
|
while (item) {
|
2014-07-14 21:39:04 +04:00
|
|
|
// Skip panels which are not visible as well as popups that
|
2014-01-31 17:27:43 +04:00
|
|
|
// are transparent to mouse events.
|
2014-07-14 21:39:04 +04:00
|
|
|
if (item->Frame()->IsVisible() && !item->Frame()->IsMouseTransparent()) {
|
2014-01-31 17:27:43 +04:00
|
|
|
aPopups.AppendElement(item->Frame());
|
|
|
|
}
|
2010-07-27 17:38:03 +04:00
|
|
|
|
2014-01-31 17:27:43 +04:00
|
|
|
item = item->GetParent();
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
2014-01-31 17:27:43 +04:00
|
|
|
|
|
|
|
item = mNoHidePanels;
|
2007-07-16 18:53:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
already_AddRefed<nsIDOMNode>
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXULPopupManager::GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip)
|
2010-08-09 20:17:19 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-09 20:17:19 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
|
|
|
|
// if mOpeningPopup is set, it means that a popupshowing event is being
|
|
|
|
// fired. In this case, just use the cached node, as the popup is not yet in
|
|
|
|
// the list of open popups.
|
|
|
|
if (mOpeningPopup && mOpeningPopup->GetCurrentDoc() == aDocument &&
|
2015-03-03 14:09:00 +03:00
|
|
|
aIsTooltip == mOpeningPopup->IsXULElement(nsGkAtoms::tooltip)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
node = do_QueryInterface(nsMenuPopupFrame::GetTriggerContent(GetPopupFrameForContent(mOpeningPopup, false)));
|
2010-08-09 20:17:19 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsMenuChainItem* item = aIsTooltip ? mNoHidePanels : mPopups;
|
|
|
|
while (item) {
|
|
|
|
// look for a popup of the same type and document.
|
|
|
|
if ((item->PopupType() == ePopupTypeTooltip) == aIsTooltip &&
|
|
|
|
item->Content()->GetCurrentDoc() == aDocument) {
|
2010-09-11 00:24:25 +04:00
|
|
|
node = do_QueryInterface(nsMenuPopupFrame::GetTriggerContent(item->Frame()));
|
|
|
|
if (node)
|
|
|
|
break;
|
2010-08-09 20:17:19 +04:00
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node.forget();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager::MayShowPopup(nsMenuPopupFrame* aPopup)
|
|
|
|
{
|
2007-08-03 18:05:07 +04:00
|
|
|
// if a popup's IsOpen method returns true, then the popup must always be in
|
|
|
|
// the popup chain scanned in IsPopupOpen.
|
|
|
|
NS_ASSERTION(!aPopup->IsOpen() || IsPopupOpen(aPopup->GetContent()),
|
|
|
|
"popup frame state doesn't match XULPopupManager open state");
|
|
|
|
|
|
|
|
nsPopupState state = aPopup->PopupState();
|
|
|
|
|
|
|
|
// if the popup is not in the open popup chain, then it must have a state that
|
|
|
|
// is either closed, in the process of being shown, or invisible.
|
|
|
|
NS_ASSERTION(IsPopupOpen(aPopup->GetContent()) || state == ePopupClosed ||
|
|
|
|
state == ePopupShowing || state == ePopupInvisible,
|
|
|
|
"popup not in XULPopupManager open list is open");
|
|
|
|
|
|
|
|
// don't show popups unless they are closed or invisible
|
|
|
|
if (state != ePopupClosed && state != ePopupInvisible)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2009-12-04 07:01:39 +03:00
|
|
|
// Don't show popups that we already have in our popup chain
|
|
|
|
if (IsPopupOpen(aPopup->GetContent())) {
|
|
|
|
NS_WARNING("Refusing to show duplicate popup");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-12-04 07:01:39 +03:00
|
|
|
}
|
|
|
|
|
2007-12-03 19:33:42 +03:00
|
|
|
// if the popup was just rolled up, don't reopen it
|
2011-12-02 01:35:42 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget = aPopup->GetWidget();
|
2007-12-03 19:33:42 +03:00
|
|
|
if (widget && widget->GetLastRollup() == aPopup->GetContent())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-12-03 19:33:42 +03:00
|
|
|
|
2013-11-20 23:18:25 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = aPopup->PresContext()->GetDocShell();
|
2008-09-10 20:57:57 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(dsti);
|
|
|
|
if (!baseWin)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2014-11-12 20:05:29 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
dsti->GetRootTreeItem(getter_AddRefs(root));
|
|
|
|
if (!root) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> rootWin = root->GetWindow();
|
|
|
|
|
2008-09-10 20:57:57 +04:00
|
|
|
// chrome shells can always open popups, but other types of shells can only
|
|
|
|
// open popups when they are focused and visible
|
2014-02-09 12:04:39 +04:00
|
|
|
if (dsti->ItemType() != nsIDocShellTreeItem::typeChrome) {
|
2008-09-10 20:57:57 +04:00
|
|
|
// only allow popups in active windows
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm || !rootWin)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> activeWindow;
|
|
|
|
fm->GetActiveWindow(getter_AddRefs(activeWindow));
|
|
|
|
if (activeWindow != rootWin)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// only allow popups in visible frames
|
2011-09-29 10:19:26 +04:00
|
|
|
bool visible;
|
2007-07-04 19:49:38 +04:00
|
|
|
baseWin->GetVisibility(&visible);
|
|
|
|
if (!visible)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2008-09-10 20:57:57 +04:00
|
|
|
// platforms respond differently when an popup is opened in a minimized
|
|
|
|
// window, so this is always disabled.
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
baseWin->GetMainWidget(getter_AddRefs(mainWidget));
|
2013-04-26 10:49:47 +04:00
|
|
|
if (mainWidget && mainWidget->SizeMode() == nsSizeMode_Minimized) {
|
|
|
|
return false;
|
2008-09-10 20:57:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:05:29 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (rootWin) {
|
|
|
|
nsGlobalWindow *globalWin = static_cast<nsGlobalWindow *>(rootWin.get());
|
|
|
|
if (globalWin->IsInModalState()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// cannot open a popup that is a submenu of a menupopup that isn't open.
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(aPopup->GetParent());
|
2010-08-09 20:17:19 +04:00
|
|
|
if (menuFrame) {
|
2008-12-05 19:37:31 +03:00
|
|
|
nsMenuParent* parentPopup = menuFrame->GetMenuParent();
|
2007-07-04 19:49:38 +04:00
|
|
|
if (parentPopup && !parentPopup->IsOpen())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::PopupDestroyed(nsMenuPopupFrame* aPopup)
|
|
|
|
{
|
|
|
|
// when a popup frame is destroyed, just unhook it from the list of popups
|
|
|
|
if (mTimerMenu == aPopup) {
|
|
|
|
if (mCloseTimer) {
|
|
|
|
mCloseTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mCloseTimer = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimerMenu = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
nsMenuChainItem* item = mNoHidePanels;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
|
|
|
if (item->Frame() == aPopup) {
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mNoHidePanels);
|
2007-07-04 19:49:38 +04:00
|
|
|
delete item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
nsTArray<nsMenuPopupFrame *> popupsToHide;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
item = mPopups;
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item) {
|
2007-11-17 18:47:38 +03:00
|
|
|
nsMenuPopupFrame* frame = item->Frame();
|
|
|
|
if (frame == aPopup) {
|
|
|
|
if (frame->PopupState() != ePopupInvisible) {
|
|
|
|
// Iterate through any child menus and hide them as well, since the
|
|
|
|
// parent is going away. We won't remove them from the list yet, just
|
|
|
|
// hide them, as they will be removed from the list when this function
|
|
|
|
// gets called for that child frame.
|
|
|
|
nsMenuChainItem* child = item->GetChild();
|
|
|
|
while (child) {
|
|
|
|
// if the popup is a child frame of the menu that was destroyed, add
|
|
|
|
// it to the list of popups to hide. Don't bother with the events
|
|
|
|
// since the frames are going away. If the child menu is not a child
|
|
|
|
// frame, for example, a context menu, use HidePopup instead, but call
|
|
|
|
// it asynchronously since we are in the middle of frame destruction.
|
|
|
|
nsMenuPopupFrame* childframe = child->Frame();
|
|
|
|
if (nsLayoutUtils::IsProperAncestorFrame(frame, childframe)) {
|
|
|
|
popupsToHide.AppendElement(childframe);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// HidePopup will take care of hiding any of its children, so
|
|
|
|
// break out afterwards
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(child->Content(), false, false, true, false);
|
2007-11-17 18:47:38 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
child = child->GetChild();
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
item->Detach(&mPopups);
|
2007-07-04 19:49:38 +04:00
|
|
|
delete item;
|
2007-11-17 18:47:38 +03:00
|
|
|
break;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
item = item->GetParent();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
HidePopupsInList(popupsToHide, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager::HasContextMenu(nsMenuPopupFrame* aPopup)
|
|
|
|
{
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2007-07-04 19:49:38 +04:00
|
|
|
while (item && item->Frame() != aPopup) {
|
|
|
|
if (item->IsContextMenu())
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
item = item->GetParent();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::SetCaptureState(nsIContent* aOldPopup)
|
|
|
|
{
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (item && aOldPopup == item->Content())
|
2007-07-04 19:49:38 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mWidget) {
|
2012-10-26 17:15:22 +04:00
|
|
|
mWidget->CaptureRollupEvents(nullptr, false);
|
2012-07-30 18:20:58 +04:00
|
|
|
mWidget = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-15 18:03:21 +04:00
|
|
|
if (item) {
|
|
|
|
nsMenuPopupFrame* popup = item->Frame();
|
2012-02-14 00:19:50 +04:00
|
|
|
mWidget = popup->GetWidget();
|
|
|
|
if (mWidget) {
|
2012-10-26 17:15:22 +04:00
|
|
|
mWidget->CaptureRollupEvents(nullptr, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
popup->AttachedDismissalListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateKeyboardListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::UpdateKeyboardListeners()
|
|
|
|
{
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<EventTarget> newTarget;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isForMenu = false;
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (item) {
|
2015-09-17 18:20:33 +03:00
|
|
|
if (item->IgnoreKeys() != eIgnoreKeys_True) {
|
2014-08-23 00:11:27 +04:00
|
|
|
newTarget = item->Content()->GetComposedDoc();
|
2015-09-17 18:20:33 +03:00
|
|
|
}
|
2007-12-04 07:07:12 +03:00
|
|
|
isForMenu = item->PopupType() == ePopupTypeMenu;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
else if (mActiveMenuBar) {
|
2014-08-23 00:11:27 +04:00
|
|
|
newTarget = mActiveMenuBar->GetContent()->GetComposedDoc();
|
2011-10-17 18:59:28 +04:00
|
|
|
isForMenu = true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mKeyListener != newTarget) {
|
|
|
|
if (mKeyListener) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
|
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, true);
|
|
|
|
mKeyListener->RemoveEventListener(NS_LITERAL_STRING("keyup"), this, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
mKeyListener = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsContentUtils::NotifyInstalledMenuKeyboardListener(false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newTarget) {
|
2011-10-17 18:59:28 +04:00
|
|
|
newTarget->AddEventListener(NS_LITERAL_STRING("keypress"), this, true);
|
|
|
|
newTarget->AddEventListener(NS_LITERAL_STRING("keydown"), this, true);
|
|
|
|
newTarget->AddEventListener(NS_LITERAL_STRING("keyup"), this, true);
|
2007-12-04 07:07:12 +03:00
|
|
|
nsContentUtils::NotifyInstalledMenuKeyboardListener(isForMenu);
|
2007-07-04 19:49:38 +04:00
|
|
|
mKeyListener = newTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
|
|
|
|
{
|
|
|
|
// Walk all of the menu's children, checking to see if any of them has a
|
|
|
|
// command attribute. If so, then several attributes must potentially be updated.
|
2013-04-20 02:18:32 +04:00
|
|
|
|
2012-11-04 12:05:25 +04:00
|
|
|
nsCOMPtr<nsIDocument> document = aPopup->GetCurrentDoc();
|
|
|
|
if (!document) {
|
2012-10-30 23:55:03 +04:00
|
|
|
return;
|
2012-11-04 12:05:25 +04:00
|
|
|
}
|
2012-10-30 23:55:03 +04:00
|
|
|
|
2012-01-25 11:50:07 +04:00
|
|
|
for (nsCOMPtr<nsIContent> grandChild = aPopup->GetFirstChild();
|
|
|
|
grandChild;
|
|
|
|
grandChild = grandChild->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (grandChild->IsXULElement(nsGkAtoms::menugroup)) {
|
2014-05-27 20:16:00 +04:00
|
|
|
if (grandChild->GetChildCount() == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-13 00:23:12 +04:00
|
|
|
grandChild = grandChild->GetFirstChild();
|
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (grandChild->IsXULElement(nsGkAtoms::menuitem)) {
|
2007-07-04 19:49:38 +04:00
|
|
|
// See if we have a command attribute.
|
|
|
|
nsAutoString command;
|
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
|
|
|
|
if (!command.IsEmpty()) {
|
|
|
|
// We do! Look it up in our document
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<dom::Element> commandElement =
|
2012-11-04 12:05:25 +04:00
|
|
|
document->GetElementById(command);
|
|
|
|
if (commandElement) {
|
2007-07-04 19:49:38 +04:00
|
|
|
nsAutoString commandValue;
|
|
|
|
// The menu's disabled state needs to be updated to match the command.
|
2012-11-04 12:05:25 +04:00
|
|
|
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandValue))
|
2011-10-17 18:59:28 +04:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandValue, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
grandChild->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-10-20 00:04:07 +04:00
|
|
|
// The menu's label, accesskey checked and hidden states need to be updated
|
2007-07-04 19:49:38 +04:00
|
|
|
// to match the command. Note that unlike the disabled state if the
|
|
|
|
// command has *no* value, we assume the menu is supplying its own.
|
2012-11-04 12:05:25 +04:00
|
|
|
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::label, commandValue))
|
2011-10-17 18:59:28 +04:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::label, commandValue, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-11-04 12:05:25 +04:00
|
|
|
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, commandValue))
|
2011-10-17 18:59:28 +04:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, commandValue, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-11-04 12:05:25 +04:00
|
|
|
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::checked, commandValue))
|
2011-10-17 18:59:28 +04:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::checked, commandValue, true);
|
2012-10-20 00:04:07 +04:00
|
|
|
|
2012-11-04 12:05:25 +04:00
|
|
|
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::hidden, commandValue))
|
2012-10-20 00:04:07 +04:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::hidden, commandValue, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-13 00:23:12 +04:00
|
|
|
if (!grandChild->GetNextSibling() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
grandChild->GetParent()->IsXULElement(nsGkAtoms::menugroup)) {
|
2014-05-13 00:23:12 +04:00
|
|
|
grandChild = grandChild->GetParent();
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify
|
|
|
|
//
|
|
|
|
// The item selection timer has fired, we might have to readjust the
|
|
|
|
// selected item. There are two cases here that we are trying to deal with:
|
|
|
|
// (1) diagonal movement from a parent menu to a submenu passing briefly over
|
|
|
|
// other items, and
|
|
|
|
// (2) moving out from a submenu to a parent or grandparent menu.
|
|
|
|
// In both cases, |mTimerMenu| is the menu item that might have an open submenu and
|
2008-12-05 19:37:30 +03:00
|
|
|
// the first item in |mPopups| is the item the mouse is currently over, which could be
|
|
|
|
// none of them.
|
2007-07-04 19:49:38 +04:00
|
|
|
//
|
|
|
|
// case (1):
|
|
|
|
// As the mouse moves from the parent item of a submenu (we'll call 'A') diagonally into the
|
|
|
|
// submenu, it probably passes through one or more sibilings (B). As the mouse passes
|
|
|
|
// through B, it becomes the current menu item and the timer is set and mTimerMenu is
|
|
|
|
// set to A. Before the timer fires, the mouse leaves the menu containing A and B and
|
2008-12-05 19:37:30 +03:00
|
|
|
// enters the submenus. Now when the timer fires, |mPopups| is null (!= |mTimerMenu|)
|
2007-07-04 19:49:38 +04:00
|
|
|
// so we have to see if anything in A's children is selected (recall that even disabled
|
|
|
|
// items are selected, the style just doesn't show it). If that is the case, we need to
|
|
|
|
// set the selected item back to A.
|
|
|
|
//
|
|
|
|
// case (2);
|
|
|
|
// Item A has an open submenu, and in it there is an item (B) which also has an open
|
|
|
|
// submenu (so there are 3 menus displayed right now). The mouse then leaves B's child
|
|
|
|
// submenu and selects an item that is a sibling of A, call it C. When the mouse enters C,
|
2008-12-05 19:37:30 +03:00
|
|
|
// the timer is set and |mTimerMenu| is A and |mPopups| is C. As the timer fires,
|
2007-07-04 19:49:38 +04:00
|
|
|
// the mouse is still within C. The correct behavior is to set the current item to C
|
|
|
|
// and close up the chain parented at A.
|
|
|
|
//
|
|
|
|
// This brings up the question of is the logic of case (1) enough? The answer is no,
|
|
|
|
// and is discussed in bugzilla bug 29400. Case (1) asks if A's submenu has a selected
|
|
|
|
// child, and if it does, set the selected item to A. Because B has a submenu open, it
|
|
|
|
// is selected and as a result, A is set to be the selected item even though the mouse
|
|
|
|
// rests in C -- very wrong.
|
|
|
|
//
|
|
|
|
// The solution is to use the same idea, but instead of only checking one level,
|
|
|
|
// drill all the way down to the deepest open submenu and check if it has something
|
|
|
|
// selected. Since the mouse is in a grandparent, it won't, and we know that we can
|
|
|
|
// safely close up A and all its children.
|
|
|
|
//
|
|
|
|
// The code below melds the two cases together.
|
|
|
|
//
|
|
|
|
nsresult
|
|
|
|
nsXULPopupManager::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
if (aTimer == mCloseTimer)
|
|
|
|
KillMenuTimer();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULPopupManager::KillMenuTimer()
|
|
|
|
{
|
|
|
|
if (mCloseTimer && mTimerMenu) {
|
|
|
|
mCloseTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mCloseTimer = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
if (mTimerMenu->IsOpen())
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(mTimerMenu->GetContent(), false, false, true, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimerMenu = nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-07-11 16:05:40 +04:00
|
|
|
void
|
2008-12-05 19:37:31 +03:00
|
|
|
nsXULPopupManager::CancelMenuTimer(nsMenuParent* aMenuParent)
|
2007-07-11 16:05:40 +04:00
|
|
|
{
|
|
|
|
if (mCloseTimer && mTimerMenu == aMenuParent) {
|
|
|
|
mCloseTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mCloseTimer = nullptr;
|
|
|
|
mTimerMenu = nullptr;
|
2007-07-11 16:05:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-23 21:08:10 +04:00
|
|
|
nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
nsMenuPopupFrame* aFrame)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2015-09-17 18:20:33 +03:00
|
|
|
// On Windows, don't check shortcuts when the accelerator key is down.
|
|
|
|
#ifdef XP_WIN
|
|
|
|
WidgetInputEvent* evt = aKeyEvent->GetInternalNSEvent()->AsInputEvent();
|
|
|
|
if (evt && evt->IsAccel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (!aFrame && item)
|
|
|
|
aFrame = item->Frame();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-07-23 21:08:10 +04:00
|
|
|
if (aFrame) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool action;
|
2007-07-23 21:08:10 +04:00
|
|
|
nsMenuFrame* result = aFrame->FindMenuWithShortcut(aKeyEvent, action);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (result) {
|
2015-06-26 19:32:25 +03:00
|
|
|
aFrame->ChangeMenuItem(result, false, true);
|
2007-07-07 12:40:54 +04:00
|
|
|
if (action) {
|
2013-10-22 12:55:20 +04:00
|
|
|
WidgetGUIEvent* evt = aKeyEvent->GetInternalNSEvent()->AsGUIEvent();
|
2011-04-13 21:53:24 +04:00
|
|
|
nsMenuFrame* menuToOpen = result->Enter(evt);
|
2007-07-07 12:40:54 +04:00
|
|
|
if (menuToOpen) {
|
|
|
|
nsCOMPtr<nsIContent> content = menuToOpen->GetContent();
|
2011-10-17 18:59:28 +04:00
|
|
|
ShowMenu(content, true, false);
|
2007-07-07 12:40:54 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mActiveMenuBar) {
|
|
|
|
nsMenuFrame* result = mActiveMenuBar->FindMenuWithShortcut(aKeyEvent);
|
|
|
|
if (result) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mActiveMenuBar->SetActive(true);
|
|
|
|
result->OpenMenu(true);
|
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXULPopupManager::HandleKeyboardNavigation(uint32_t aKeyCode)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
// navigate up through the open menus, looking for the topmost one
|
|
|
|
// in the same hierarchy
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuChainItem* item = nullptr;
|
2007-08-15 18:03:21 +04:00
|
|
|
nsMenuChainItem* nextitem = GetTopVisibleMenu();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
while (nextitem) {
|
|
|
|
item = nextitem;
|
|
|
|
nextitem = item->GetParent();
|
|
|
|
|
|
|
|
if (nextitem) {
|
|
|
|
// stop if the parent isn't a menu
|
|
|
|
if (!nextitem->IsMenu())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// check to make sure that the parent is actually the parent menu. It won't
|
|
|
|
// be if the parent is in a different frame hierarchy, for example, for a
|
|
|
|
// context menu opened on another menu.
|
2008-12-05 19:37:31 +03:00
|
|
|
nsMenuParent* expectedParent = static_cast<nsMenuParent *>(nextitem->Frame());
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(item->Frame()->GetParent());
|
2010-08-09 20:17:19 +04:00
|
|
|
if (!menuFrame || menuFrame->GetMenuParent() != expectedParent) {
|
2007-07-04 19:49:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* itemFrame;
|
|
|
|
if (item)
|
|
|
|
itemFrame = item->Frame();
|
|
|
|
else if (mActiveMenuBar)
|
|
|
|
itemFrame = mActiveMenuBar;
|
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
nsNavigationDirection theDirection;
|
2013-10-22 17:27:36 +04:00
|
|
|
NS_ASSERTION(aKeyCode >= nsIDOMKeyEvent::DOM_VK_END &&
|
|
|
|
aKeyCode <= nsIDOMKeyEvent::DOM_VK_DOWN, "Illegal key code");
|
2008-12-30 16:30:51 +03:00
|
|
|
theDirection = NS_DIRECTION_FROM_KEY_CODE(itemFrame, aKeyCode);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// if a popup is open, first check for navigation within the popup
|
|
|
|
if (item && HandleKeyboardNavigationInPopup(item, theDirection))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// no popup handled the key, so check the active menubar, if any
|
|
|
|
if (mActiveMenuBar) {
|
|
|
|
nsMenuFrame* currentMenu = mActiveMenuBar->GetCurrentMenuItem();
|
|
|
|
|
|
|
|
if (NS_DIRECTION_IS_INLINE(theDirection)) {
|
|
|
|
nsMenuFrame* nextItem = (theDirection == eNavigationDirection_End) ?
|
2011-10-17 18:59:28 +04:00
|
|
|
GetNextMenuItem(mActiveMenuBar, currentMenu, false) :
|
|
|
|
GetPreviousMenuItem(mActiveMenuBar, currentMenu, false);
|
2015-06-26 19:32:25 +03:00
|
|
|
mActiveMenuBar->ChangeMenuItem(nextItem, true, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2008-03-13 00:47:11 +03:00
|
|
|
else if (NS_DIRECTION_IS_BLOCK(theDirection)) {
|
2007-07-04 19:49:38 +04:00
|
|
|
// Open the menu and select its first item.
|
2007-12-17 21:17:03 +03:00
|
|
|
if (currentMenu) {
|
|
|
|
nsCOMPtr<nsIContent> content = currentMenu->GetContent();
|
2011-10-17 18:59:28 +04:00
|
|
|
ShowMenu(content, true, false);
|
2007-12-17 21:17:03 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager::HandleKeyboardNavigationInPopup(nsMenuChainItem* item,
|
2007-07-23 21:08:10 +04:00
|
|
|
nsMenuPopupFrame* aFrame,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsNavigationDirection aDir)
|
|
|
|
{
|
2007-07-23 21:08:10 +04:00
|
|
|
NS_ASSERTION(aFrame, "aFrame is null");
|
|
|
|
NS_ASSERTION(!item || item->Frame() == aFrame,
|
|
|
|
"aFrame is expected to be equal to item->Frame()");
|
|
|
|
|
|
|
|
nsMenuFrame* currentMenu = aFrame->GetCurrentMenuItem();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-07-23 21:08:10 +04:00
|
|
|
aFrame->ClearIncrementalString();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// This method only gets called if we're open.
|
|
|
|
if (!currentMenu && NS_DIRECTION_IS_INLINE(aDir)) {
|
|
|
|
// We've been opened, but we haven't had anything selected.
|
|
|
|
// We can handle End, but our parent handles Start.
|
|
|
|
if (aDir == eNavigationDirection_End) {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuFrame* nextItem = GetNextMenuItem(aFrame, nullptr, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (nextItem) {
|
2015-06-26 19:32:25 +03:00
|
|
|
aFrame->ChangeMenuItem(nextItem, false, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isContainer = false;
|
|
|
|
bool isOpen = false;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (currentMenu) {
|
|
|
|
isOpen = currentMenu->IsOpen();
|
|
|
|
isContainer = currentMenu->IsMenu();
|
|
|
|
if (isOpen) {
|
|
|
|
// for an open popup, have the child process the event
|
2012-07-30 18:20:58 +04:00
|
|
|
nsMenuChainItem* child = item ? item->GetChild() : nullptr;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (child && HandleKeyboardNavigationInPopup(child, aDir))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
else if (aDir == eNavigationDirection_End &&
|
|
|
|
isContainer && !currentMenu->IsDisabled()) {
|
|
|
|
// The menu is not yet open. Open it and select the first item.
|
|
|
|
nsCOMPtr<nsIContent> content = currentMenu->GetContent();
|
2011-10-17 18:59:28 +04:00
|
|
|
ShowMenu(content, true, false);
|
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For block progression, we can move in either direction
|
|
|
|
if (NS_DIRECTION_IS_BLOCK(aDir) ||
|
|
|
|
NS_DIRECTION_IS_BLOCK_TO_EDGE(aDir)) {
|
|
|
|
nsMenuFrame* nextItem;
|
|
|
|
|
|
|
|
if (aDir == eNavigationDirection_Before)
|
2011-10-17 18:59:28 +04:00
|
|
|
nextItem = GetPreviousMenuItem(aFrame, currentMenu, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
else if (aDir == eNavigationDirection_After)
|
2011-10-17 18:59:28 +04:00
|
|
|
nextItem = GetNextMenuItem(aFrame, currentMenu, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
else if (aDir == eNavigationDirection_First)
|
2012-07-30 18:20:58 +04:00
|
|
|
nextItem = GetNextMenuItem(aFrame, nullptr, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
nextItem = GetPreviousMenuItem(aFrame, nullptr, true);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
if (nextItem) {
|
2015-06-26 19:32:25 +03:00
|
|
|
aFrame->ChangeMenuItem(nextItem, false, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (currentMenu && isContainer && isOpen) {
|
|
|
|
if (aDir == eNavigationDirection_Start) {
|
|
|
|
// close a submenu when Left is pressed
|
|
|
|
nsMenuPopupFrame* popupFrame = currentMenu->GetPopup();
|
|
|
|
if (popupFrame)
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(popupFrame->GetContent(), false, false, false, false);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
bool
|
|
|
|
nsXULPopupManager::HandleKeyboardEventWithKeyCode(
|
|
|
|
nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
nsMenuChainItem* aTopVisibleMenuItem)
|
|
|
|
{
|
|
|
|
uint32_t keyCode;
|
|
|
|
aKeyEvent->GetKeyCode(&keyCode);
|
|
|
|
|
|
|
|
// Escape should close panels, but the other keys should have no effect.
|
|
|
|
if (aTopVisibleMenuItem &&
|
|
|
|
aTopVisibleMenuItem->PopupType() != ePopupTypeMenu) {
|
|
|
|
if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE) {
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(aTopVisibleMenuItem->Content(), false, false, false, true);
|
2013-07-25 10:09:29 +04:00
|
|
|
aKeyEvent->StopPropagation();
|
2015-05-25 23:54:13 +03:00
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
2013-07-25 10:09:29 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool consume = (mPopups || mActiveMenuBar);
|
|
|
|
switch (keyCode) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END:
|
|
|
|
HandleKeyboardNavigation(keyCode);
|
|
|
|
break;
|
|
|
|
|
2015-05-20 20:11:06 +03:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
|
|
|
|
if (aTopVisibleMenuItem) {
|
|
|
|
aTopVisibleMenuItem->Frame()->ChangeByPage(keyCode == nsIDOMKeyEvent::DOM_VK_PAGE_UP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_ESCAPE:
|
|
|
|
// Pressing Escape hides one level of menus only. If no menu is open,
|
|
|
|
// check if a menubar is active and inform it that a menu closed. Even
|
|
|
|
// though in this latter case, a menu didn't actually close, the effect
|
|
|
|
// ends up being the same. Similar for the tab key below.
|
|
|
|
if (aTopVisibleMenuItem) {
|
2014-04-08 16:45:52 +04:00
|
|
|
HidePopup(aTopVisibleMenuItem->Content(), false, false, false, true);
|
2013-07-25 10:09:29 +04:00
|
|
|
} else if (mActiveMenuBar) {
|
|
|
|
mActiveMenuBar->MenuClosed();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_TAB:
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_F10:
|
|
|
|
#endif
|
2015-10-14 20:59:29 +03:00
|
|
|
if (aTopVisibleMenuItem &&
|
|
|
|
!aTopVisibleMenuItem->Frame()->GetContent()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::activateontab, nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
// close popups or deactivate menubar when Tab or F10 are pressed
|
2015-01-08 04:52:20 +03:00
|
|
|
Rollup(0, false, nullptr, nullptr);
|
2015-10-14 20:59:29 +03:00
|
|
|
break;
|
2013-07-25 10:09:29 +04:00
|
|
|
} else if (mActiveMenuBar) {
|
|
|
|
mActiveMenuBar->MenuClosed();
|
2015-10-14 20:59:29 +03:00
|
|
|
break;
|
2013-07-25 10:09:29 +04:00
|
|
|
}
|
2015-10-14 20:59:29 +03:00
|
|
|
// Intentional fall-through to RETURN case
|
2013-07-25 10:09:29 +04:00
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RETURN: {
|
|
|
|
// If there is a popup open, check if the current item needs to be opened.
|
|
|
|
// Otherwise, tell the active menubar, if any, to activate the menu. The
|
|
|
|
// Enter method will return a menu if one needs to be opened as a result.
|
|
|
|
nsMenuFrame* menuToOpen = nullptr;
|
2013-10-22 12:55:20 +04:00
|
|
|
WidgetGUIEvent* GUIEvent = aKeyEvent->GetInternalNSEvent()->AsGUIEvent();
|
2013-07-25 10:09:29 +04:00
|
|
|
if (aTopVisibleMenuItem) {
|
|
|
|
menuToOpen = aTopVisibleMenuItem->Frame()->Enter(GUIEvent);
|
|
|
|
} else if (mActiveMenuBar) {
|
|
|
|
menuToOpen = mActiveMenuBar->Enter(GUIEvent);
|
|
|
|
}
|
|
|
|
if (menuToOpen) {
|
|
|
|
nsCOMPtr<nsIContent> content = menuToOpen->GetContent();
|
|
|
|
ShowMenu(content, true, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (consume) {
|
|
|
|
aKeyEvent->StopPropagation();
|
2015-05-25 23:54:13 +03:00
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
2013-07-25 10:09:29 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuFrame*
|
2014-05-25 02:20:39 +04:00
|
|
|
nsXULPopupManager::GetNextMenuItem(nsContainerFrame* aParent,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuFrame* aStart,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsPopup)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = aParent->PresContext();
|
2014-11-20 21:24:09 +03:00
|
|
|
auto insertion = presContext->PresShell()->
|
2013-05-02 02:50:08 +04:00
|
|
|
FrameConstructor()->GetInsertionPoint(aParent->GetContent(), nullptr);
|
2014-11-20 21:24:09 +03:00
|
|
|
nsContainerFrame* immediateParent = insertion.mParentFrame;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = aParent;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* currFrame = nullptr;
|
2014-05-13 00:23:12 +04:00
|
|
|
if (aStart) {
|
|
|
|
if (aStart->GetNextSibling())
|
|
|
|
currFrame = aStart->GetNextSibling();
|
2015-03-03 14:08:59 +03:00
|
|
|
else if (aStart->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = aStart->GetParent()->GetNextSibling();
|
|
|
|
}
|
|
|
|
else
|
2011-08-25 00:54:30 +04:00
|
|
|
currFrame = immediateParent->GetFirstPrincipalChild();
|
2014-05-13 00:23:12 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
while (currFrame) {
|
|
|
|
// See if it's a menu item.
|
2014-05-13 00:23:12 +04:00
|
|
|
nsIContent* currFrameContent = currFrame->GetContent();
|
|
|
|
if (IsValidMenuItem(presContext, currFrameContent, aIsPopup)) {
|
2012-07-31 04:43:28 +04:00
|
|
|
return do_QueryFrame(currFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (currFrameContent->IsXULElement(nsGkAtoms::menugroup) &&
|
2014-05-27 20:16:00 +04:00
|
|
|
currFrameContent->GetChildCount() > 0)
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetFirstPrincipalChild();
|
|
|
|
else if (!currFrame->GetNextSibling() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
currFrame->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetParent()->GetNextSibling();
|
|
|
|
else
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
currFrame = immediateParent->GetFirstPrincipalChild();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// Still don't have anything. Try cycling from the beginning.
|
|
|
|
while (currFrame && currFrame != aStart) {
|
|
|
|
// See if it's a menu item.
|
2014-05-13 00:23:12 +04:00
|
|
|
nsIContent* currFrameContent = currFrame->GetContent();
|
|
|
|
if (IsValidMenuItem(presContext, currFrameContent, aIsPopup)) {
|
2012-07-31 04:43:28 +04:00
|
|
|
return do_QueryFrame(currFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (currFrameContent->IsXULElement(nsGkAtoms::menugroup) &&
|
2014-05-27 20:16:00 +04:00
|
|
|
currFrameContent->GetChildCount() > 0)
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetFirstPrincipalChild();
|
|
|
|
else if (!currFrame->GetNextSibling() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
currFrame->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetParent()->GetNextSibling();
|
|
|
|
else
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// No luck. Just return our start value.
|
|
|
|
return aStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuFrame*
|
2014-05-25 02:20:39 +04:00
|
|
|
nsXULPopupManager::GetPreviousMenuItem(nsContainerFrame* aParent,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuFrame* aStart,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsPopup)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = aParent->PresContext();
|
2014-11-20 21:24:09 +03:00
|
|
|
auto insertion = presContext->PresShell()->
|
2013-05-02 02:50:08 +04:00
|
|
|
FrameConstructor()->GetInsertionPoint(aParent->GetContent(), nullptr);
|
2014-11-20 21:24:09 +03:00
|
|
|
nsContainerFrame* immediateParent = insertion.mParentFrame;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = aParent;
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
const nsFrameList& frames(immediateParent->PrincipalChildList());
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* currFrame = nullptr;
|
2014-05-13 00:23:12 +04:00
|
|
|
if (aStart) {
|
|
|
|
if (aStart->GetPrevSibling())
|
|
|
|
currFrame = aStart->GetPrevSibling();
|
2015-03-03 14:08:59 +03:00
|
|
|
else if (aStart->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = aStart->GetParent()->GetPrevSibling();
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
else
|
|
|
|
currFrame = frames.LastChild();
|
|
|
|
|
|
|
|
while (currFrame) {
|
|
|
|
// See if it's a menu item.
|
2014-05-13 00:23:12 +04:00
|
|
|
nsIContent* currFrameContent = currFrame->GetContent();
|
|
|
|
if (IsValidMenuItem(presContext, currFrameContent, aIsPopup)) {
|
2012-07-31 04:43:28 +04:00
|
|
|
return do_QueryFrame(currFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (currFrameContent->IsXULElement(nsGkAtoms::menugroup) &&
|
2014-05-27 20:16:00 +04:00
|
|
|
currFrameContent->GetChildCount() > 0) {
|
2014-05-13 00:23:12 +04:00
|
|
|
const nsFrameList& menugroupFrames(currFrame->PrincipalChildList());
|
|
|
|
currFrame = menugroupFrames.LastChild();
|
|
|
|
}
|
|
|
|
else if (!currFrame->GetPrevSibling() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
currFrame->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetParent()->GetPrevSibling();
|
|
|
|
else
|
|
|
|
currFrame = currFrame->GetPrevSibling();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
currFrame = frames.LastChild();
|
|
|
|
|
|
|
|
// Still don't have anything. Try cycling from the end.
|
|
|
|
while (currFrame && currFrame != aStart) {
|
|
|
|
// See if it's a menu item.
|
2014-05-13 00:23:12 +04:00
|
|
|
nsIContent* currFrameContent = currFrame->GetContent();
|
|
|
|
if (IsValidMenuItem(presContext, currFrameContent, aIsPopup)) {
|
2012-07-31 04:43:28 +04:00
|
|
|
return do_QueryFrame(currFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (currFrameContent->IsXULElement(nsGkAtoms::menugroup) &&
|
2014-05-27 20:16:00 +04:00
|
|
|
currFrameContent->GetChildCount() > 0) {
|
2014-05-13 00:23:12 +04:00
|
|
|
const nsFrameList& menugroupFrames(currFrame->PrincipalChildList());
|
|
|
|
currFrame = menugroupFrames.LastChild();
|
|
|
|
}
|
|
|
|
else if (!currFrame->GetPrevSibling() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
currFrame->GetParent()->GetContent()->IsXULElement(nsGkAtoms::menugroup))
|
2014-05-13 00:23:12 +04:00
|
|
|
currFrame = currFrame->GetParent()->GetPrevSibling();
|
|
|
|
else
|
|
|
|
currFrame = currFrame->GetPrevSibling();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// No luck. Just return our start value.
|
|
|
|
return aStart;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-07-04 19:49:38 +04:00
|
|
|
nsXULPopupManager::IsValidMenuItem(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aOnPopup)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2015-03-03 14:09:00 +03:00
|
|
|
if (aContent->IsXULElement()) {
|
|
|
|
if (!aContent->IsAnyOfXULElements(nsGkAtoms::menu, nsGkAtoms::menuitem)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-03-03 14:09:00 +03:00
|
|
|
}
|
2007-11-17 18:47:38 +03:00
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
else if (!aOnPopup || !aContent->IsHTMLElement(nsGkAtoms::option)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-11-17 18:47:38 +03:00
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool skipNavigatingDisabledMenuItem = true;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (aOnPopup) {
|
2011-09-09 06:27:13 +04:00
|
|
|
skipNavigatingDisabledMenuItem =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_SkipNavigatingDisabledMenuItem,
|
|
|
|
0) != 0;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return !(skipNavigatingDisabledMenuItem &&
|
|
|
|
aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-06-29 22:07:48 +04:00
|
|
|
nsXULPopupManager::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2011-06-29 22:54:46 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
2011-06-29 22:07:48 +04:00
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
|
|
|
bool trustedEvent = false;
|
|
|
|
aEvent->GetIsTrusted(&trustedEvent);
|
|
|
|
if (!trustedEvent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-29 22:07:48 +04:00
|
|
|
nsAutoString eventType;
|
|
|
|
keyEvent->GetType(eventType);
|
|
|
|
if (eventType.EqualsLiteral("keyup")) {
|
|
|
|
return KeyUp(keyEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("keydown")) {
|
|
|
|
return KeyDown(keyEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("keypress")) {
|
|
|
|
return KeyPress(keyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPopupManager::KeyUp(nsIDOMKeyEvent* aKeyEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2007-11-21 23:47:11 +03:00
|
|
|
// don't do anything if a menu isn't open or a menubar isn't active
|
|
|
|
if (!mActiveMenuBar) {
|
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (!item || item->PopupType() != ePopupTypeMenu)
|
|
|
|
return NS_OK;
|
2015-09-17 18:20:33 +03:00
|
|
|
|
|
|
|
if (item->IgnoreKeys() == eIgnoreKeys_Handled) {
|
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-24 01:21:27 +04:00
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-11-21 23:47:11 +03:00
|
|
|
aKeyEvent->StopPropagation();
|
2015-05-25 23:54:13 +03:00
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
2007-11-21 23:47:11 +03:00
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
return NS_OK; // I am consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-06-29 22:07:48 +04:00
|
|
|
nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
2010-04-19 18:12:58 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
|
|
|
if (item && item->Frame()->IsMenuLocked())
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
if (HandleKeyboardEventWithKeyCode(aKeyEvent, item)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-21 23:47:11 +03:00
|
|
|
// don't do anything if a menu isn't open or a menubar isn't active
|
2010-04-19 18:12:58 +04:00
|
|
|
if (!mActiveMenuBar && (!item || item->PopupType() != ePopupTypeMenu))
|
|
|
|
return NS_OK;
|
2007-08-24 01:21:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t menuAccessKey = -1;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// If the key just pressed is the access key (usually Alt),
|
|
|
|
// dismiss and unfocus the menu.
|
|
|
|
|
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
if (menuAccessKey) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t theChar;
|
2011-06-29 22:07:48 +04:00
|
|
|
aKeyEvent->GetKeyCode(&theChar);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
if (theChar == (uint32_t)menuAccessKey) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ctrl = false;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_CONTROL)
|
2011-06-29 22:54:46 +04:00
|
|
|
aKeyEvent->GetCtrlKey(&ctrl);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool alt=false;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_ALT)
|
2011-06-29 22:54:46 +04:00
|
|
|
aKeyEvent->GetAltKey(&alt);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shift=false;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_SHIFT)
|
2011-06-29 22:54:46 +04:00
|
|
|
aKeyEvent->GetShiftKey(&shift);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool meta=false;
|
2007-07-04 19:49:38 +04:00
|
|
|
if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_META)
|
2011-06-29 22:54:46 +04:00
|
|
|
aKeyEvent->GetMetaKey(&meta);
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!(ctrl || alt || shift || meta)) {
|
|
|
|
// The access key just went down and no other
|
|
|
|
// modifiers are already down.
|
2008-12-05 19:37:30 +03:00
|
|
|
if (mPopups)
|
2015-01-08 04:52:20 +03:00
|
|
|
Rollup(0, false, nullptr, nullptr);
|
2007-11-21 23:47:11 +03:00
|
|
|
else if (mActiveMenuBar)
|
|
|
|
mActiveMenuBar->MenuClosed();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
2015-09-17 18:20:33 +03:00
|
|
|
aKeyEvent->StopPropagation();
|
2013-07-25 10:09:29 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
// Since a menu was open, stop propagation of the event to keep other event
|
2007-07-04 19:49:38 +04:00
|
|
|
// listeners from becoming confused.
|
2015-09-17 18:20:33 +03:00
|
|
|
|
|
|
|
if (!item || item->IgnoreKeys() != eIgnoreKeys_Handled) {
|
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
}
|
|
|
|
|
2015-05-25 23:54:13 +03:00
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
2013-07-25 10:09:29 +04:00
|
|
|
return NS_OK;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-06-29 22:07:48 +04:00
|
|
|
nsXULPopupManager::KeyPress(nsIDOMKeyEvent* aKeyEvent)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
// Don't check prevent default flag -- menus always get first shot at key events.
|
|
|
|
|
2010-04-19 18:12:58 +04:00
|
|
|
nsMenuChainItem* item = GetTopVisibleMenu();
|
2013-07-25 10:09:29 +04:00
|
|
|
if (item &&
|
|
|
|
(item->Frame()->IsMenuLocked() || item->PopupType() != ePopupTypeMenu)) {
|
2010-04-19 18:12:58 +04:00
|
|
|
return NS_OK;
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
2011-06-29 22:07:48 +04:00
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_UNEXPECTED);
|
2007-11-21 23:47:11 +03:00
|
|
|
// if a menu is open or a menubar is active, it consumes the key event
|
2011-09-29 10:19:26 +04:00
|
|
|
bool consume = (mPopups || mActiveMenuBar);
|
2015-09-17 18:20:33 +03:00
|
|
|
|
|
|
|
// When ignorekeys="handled" is used, we don't call preventDefault on the key
|
|
|
|
// event, which allows another listener to handle keys that the popup hasn't
|
|
|
|
// already handled. For instance, this allows global shortcuts to still apply
|
|
|
|
// while a menu is open.
|
|
|
|
bool onlyHandled = item && item->IgnoreKeys() == eIgnoreKeys_Handled;
|
|
|
|
bool handled = HandleShortcutNavigation(keyEvent, nullptr);
|
|
|
|
|
|
|
|
aKeyEvent->StopCrossProcessForwarding();
|
|
|
|
if (handled || (consume && !onlyHandled)) {
|
2007-08-24 01:21:27 +04:00
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
return NS_OK; // I am consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPopupShowingEvent::Run()
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2010-09-06 07:30:17 +04:00
|
|
|
if (pm) {
|
|
|
|
pm->FirePopupShowingEvent(mPopup, mIsContextMenu, mSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULPopupHidingEvent::Run()
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2010-09-06 07:30:17 +04:00
|
|
|
|
|
|
|
nsIDocument *document = mPopup->GetCurrentDoc();
|
|
|
|
if (pm && document) {
|
|
|
|
nsIPresShell* presShell = document->GetShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsPresContext* context = presShell->GetPresContext();
|
|
|
|
if (context) {
|
|
|
|
pm->FirePopupHidingEvent(mPopup, mNextPopup, mLastPopup,
|
2014-04-08 16:45:52 +04:00
|
|
|
context, mPopupType, mDeselectMenu, mIsRollup);
|
2010-09-06 07:30:17 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULMenuCommandEvent::Run()
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!pm)
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-01-05 07:12:24 +04:00
|
|
|
// The order of the nsViewManager and nsIPresShell COM pointers is
|
2007-07-04 19:49:38 +04:00
|
|
|
// important below. We want the pres shell to get released before the
|
|
|
|
// associated view manager on exit from this function.
|
|
|
|
// See bug 54233.
|
|
|
|
// XXXndeakin is this still needed?
|
2007-08-24 02:13:42 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> popup;
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(mMenu->GetPrimaryFrame());
|
2010-04-19 18:12:58 +04:00
|
|
|
nsWeakFrame weakFrame(menuFrame);
|
|
|
|
if (menuFrame && mFlipChecked) {
|
|
|
|
if (menuFrame->IsChecked()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mMenu->UnsetAttr(kNameSpaceID_None, nsGkAtoms::checked, true);
|
2010-04-19 18:12:58 +04:00
|
|
|
} else {
|
|
|
|
mMenu->SetAttr(kNameSpaceID_None, nsGkAtoms::checked,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2010-04-19 18:12:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menuFrame && weakFrame.IsAlive()) {
|
2007-08-24 02:13:42 +04:00
|
|
|
// Find the popup that the menu is inside. Below, this popup will
|
|
|
|
// need to be hidden.
|
2012-07-31 04:43:28 +04:00
|
|
|
nsIFrame* frame = menuFrame->GetParent();
|
|
|
|
while (frame) {
|
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(frame);
|
|
|
|
if (popupFrame) {
|
2007-10-26 21:24:35 +04:00
|
|
|
popup = popupFrame->GetContent();
|
2007-12-03 19:33:42 +03:00
|
|
|
break;
|
2007-10-26 21:24:35 +04:00
|
|
|
}
|
2012-07-31 04:43:28 +04:00
|
|
|
frame = frame->GetParent();
|
2007-08-24 02:13:42 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsPresContext* presContext = menuFrame->PresContext();
|
|
|
|
nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> kungFuDeathGrip = shell->GetViewManager();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// Deselect ourselves.
|
2007-08-30 19:43:10 +04:00
|
|
|
if (mCloseMenuMode != CloseMenuMode_None)
|
2011-10-17 18:59:28 +04:00
|
|
|
menuFrame->SelectMenu(false);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2013-10-22 17:27:35 +04:00
|
|
|
AutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr,
|
|
|
|
shell->GetDocument());
|
2012-07-30 18:20:58 +04:00
|
|
|
nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, shell,
|
2009-06-30 11:56:40 +04:00
|
|
|
mControl, mAlt, mShift, mMeta);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-30 19:43:10 +04:00
|
|
|
if (popup && mCloseMenuMode != CloseMenuMode_None)
|
2014-04-08 16:45:52 +04:00
|
|
|
pm->HidePopup(popup, mCloseMenuMode == CloseMenuMode_Auto, true, false, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|