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
|
|
|
|
|
|
|
/**
|
|
|
|
* The XUL Popup Manager keeps track of all open popups.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsXULPopupManager_h__
|
|
|
|
#define nsXULPopupManager_h__
|
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIRollupListener.h"
|
2011-06-29 22:07:48 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-07-17 16:21:53 +04:00
|
|
|
#include "nsPoint.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2007-07-16 18:53:32 +04:00
|
|
|
#include "nsTArray.h"
|
2014-03-05 03:39:42 +04:00
|
|
|
#include "nsIObserver.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsITimer.h"
|
2010-09-06 07:30:17 +04:00
|
|
|
#include "nsIReflowCallback.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2008-12-30 16:30:51 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "nsWidgetInitData.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-03-30 18:36:01 +03:00
|
|
|
#include "Units.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2011-06-29 22:07:48 +04:00
|
|
|
// X.h defines KeyPress
|
|
|
|
#ifdef KeyPress
|
|
|
|
#undef KeyPress
|
|
|
|
#endif
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* There are two types that are used:
|
|
|
|
* - dismissable popups such as menus, which should close up when there is a
|
|
|
|
* click outside the popup. In this situation, the entire chain of menus
|
|
|
|
* above should also be closed.
|
|
|
|
* - panels, which stay open until a request is made to close them. This
|
|
|
|
* type is used by tooltips.
|
|
|
|
*
|
|
|
|
* When a new popup is opened, it is appended to the popup chain, stored in a
|
2017-03-13 16:44:02 +03:00
|
|
|
* linked list in mPopups.
|
2007-07-04 19:49:38 +04:00
|
|
|
* Popups are stored in this list linked from newest to oldest. When a click
|
|
|
|
* occurs outside one of the open dismissable popups, the chain is closed by
|
|
|
|
* calling Rollup.
|
|
|
|
*/
|
|
|
|
|
2014-05-25 02:20:39 +04:00
|
|
|
class nsContainerFrame;
|
2007-07-04 19:49:38 +04:00
|
|
|
class nsMenuFrame;
|
|
|
|
class nsMenuPopupFrame;
|
|
|
|
class nsMenuBarFrame;
|
2008-12-05 19:37:31 +03:00
|
|
|
class nsMenuParent;
|
2007-07-04 19:49:38 +04:00
|
|
|
class nsIDOMKeyEvent;
|
2008-02-08 23:23:05 +03:00
|
|
|
class nsIDocShellTreeItem;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowOuter;
|
2017-02-16 16:53:59 +03:00
|
|
|
class nsRefreshDriver;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-30 19:43:10 +04:00
|
|
|
// when a menu command is executed, the closemenu attribute may be used
|
|
|
|
// to define how the menu should be closed up
|
|
|
|
enum CloseMenuMode {
|
|
|
|
CloseMenuMode_Auto, // close up the chain of menus, default value
|
|
|
|
CloseMenuMode_None, // don't close up any menus
|
|
|
|
CloseMenuMode_Single // close up only the menu the command is inside
|
|
|
|
};
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* nsNavigationDirection: an enum expressing navigation through the menus in
|
|
|
|
* terms which are independent of the directionality of the chrome. The
|
|
|
|
* terminology, derived from XSL-FO and CSS3 (e.g.
|
|
|
|
* http://www.w3.org/TR/css3-text/#TextLayout), is BASE (Before, After, Start,
|
|
|
|
* End), with the addition of First and Last (mapped to Home and End
|
|
|
|
* respectively).
|
|
|
|
*
|
|
|
|
* In languages such as English where the inline progression is left-to-right
|
|
|
|
* and the block progression is top-to-bottom (lr-tb), these terms will map out
|
|
|
|
* as in the following diagram
|
|
|
|
*
|
|
|
|
* --- inline progression --->
|
|
|
|
*
|
|
|
|
* First |
|
|
|
|
* ... |
|
|
|
|
* Before |
|
|
|
|
* +--------+ block
|
|
|
|
* Start | | End progression
|
|
|
|
* +--------+ |
|
|
|
|
* After |
|
|
|
|
* ... |
|
|
|
|
* Last V
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum nsNavigationDirection {
|
|
|
|
eNavigationDirection_Last,
|
|
|
|
eNavigationDirection_First,
|
|
|
|
eNavigationDirection_Start,
|
|
|
|
eNavigationDirection_Before,
|
|
|
|
eNavigationDirection_End,
|
|
|
|
eNavigationDirection_After
|
|
|
|
};
|
|
|
|
|
2015-09-17 18:20:33 +03:00
|
|
|
enum nsIgnoreKeys {
|
|
|
|
eIgnoreKeys_False,
|
|
|
|
eIgnoreKeys_True,
|
2016-12-07 04:25:09 +03:00
|
|
|
eIgnoreKeys_Shortcuts,
|
2015-09-17 18:20:33 +03:00
|
|
|
};
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
#define NS_DIRECTION_IS_INLINE(dir) (dir == eNavigationDirection_Start || \
|
|
|
|
dir == eNavigationDirection_End)
|
|
|
|
#define NS_DIRECTION_IS_BLOCK(dir) (dir == eNavigationDirection_Before || \
|
|
|
|
dir == eNavigationDirection_After)
|
|
|
|
#define NS_DIRECTION_IS_BLOCK_TO_EDGE(dir) (dir == eNavigationDirection_First || \
|
|
|
|
dir == eNavigationDirection_Last)
|
|
|
|
|
2016-08-23 18:24:54 +03:00
|
|
|
static_assert(NS_STYLE_DIRECTION_LTR == 0 && NS_STYLE_DIRECTION_RTL == 1,
|
|
|
|
"Left to Right should be 0 and Right to Left should be 1");
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
2008-12-30 16:30:51 +03:00
|
|
|
* DirectionFromKeyCodeTable: two arrays, the first for left-to-right and the
|
|
|
|
* other for right-to-left, that map keycodes to values of
|
|
|
|
* nsNavigationDirection.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
2008-12-30 16:30:51 +03:00
|
|
|
extern const nsNavigationDirection DirectionFromKeyCodeTable[2][6];
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2008-12-30 16:30:51 +03:00
|
|
|
#define NS_DIRECTION_FROM_KEY_CODE(frame, keycode) \
|
2013-02-17 01:51:02 +04:00
|
|
|
(DirectionFromKeyCodeTable[frame->StyleVisibility()->mDirection] \
|
2013-09-25 15:21:19 +04:00
|
|
|
[keycode - nsIDOMKeyEvent::DOM_VK_END])
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// nsMenuChainItem holds info about an open popup. Items are stored in a
|
|
|
|
// doubly linked list. Note that the linked list is stored beginning from
|
|
|
|
// the lowest child in a chain of menus, as this is the active submenu.
|
|
|
|
class nsMenuChainItem
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsMenuPopupFrame* mFrame; // the popup frame
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType mPopupType; // the popup type of the frame
|
2017-03-13 16:44:02 +03:00
|
|
|
bool mNoAutoHide; // true for noautohide panels
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsContext; // true for context menus
|
|
|
|
bool mOnMenuBar; // true if the menu is on a menu bar
|
2015-09-17 18:20:33 +03:00
|
|
|
nsIgnoreKeys mIgnoreKeys; // indicates how keyboard listeners should be used
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
// True if the popup should maintain its position relative to the anchor when
|
|
|
|
// the anchor moves.
|
|
|
|
bool mFollowAnchor;
|
|
|
|
|
|
|
|
// The last seen position of the anchor, relative to the screen.
|
|
|
|
nsRect mCurrentRect;
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuChainItem* mParent;
|
|
|
|
nsMenuChainItem* mChild;
|
|
|
|
|
|
|
|
public:
|
2017-03-13 16:44:02 +03:00
|
|
|
nsMenuChainItem(nsMenuPopupFrame* aFrame, bool aNoAutoHide, bool aIsContext,
|
|
|
|
nsPopupType aPopupType)
|
2007-07-04 19:49:38 +04:00
|
|
|
: mFrame(aFrame),
|
2007-08-16 05:09:58 +04:00
|
|
|
mPopupType(aPopupType),
|
2017-03-13 16:44:02 +03:00
|
|
|
mNoAutoHide(aNoAutoHide),
|
2007-07-04 19:49:38 +04:00
|
|
|
mIsContext(aIsContext),
|
2011-10-17 18:59:28 +04:00
|
|
|
mOnMenuBar(false),
|
2015-09-17 18:20:33 +03:00
|
|
|
mIgnoreKeys(eIgnoreKeys_False),
|
2017-02-16 16:53:59 +03:00
|
|
|
mFollowAnchor(false),
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent(nullptr),
|
|
|
|
mChild(nullptr)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "null frame passed to nsMenuChainItem constructor");
|
|
|
|
MOZ_COUNT_CTOR(nsMenuChainItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsMenuChainItem()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsMenuChainItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* Content();
|
|
|
|
nsMenuPopupFrame* Frame() { return mFrame; }
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType PopupType() { return mPopupType; }
|
2017-03-13 16:44:02 +03:00
|
|
|
bool IsNoAutoHide() { return mNoAutoHide; }
|
|
|
|
void SetNoAutoHide(bool aNoAutoHide) { mNoAutoHide = aNoAutoHide; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsMenu() { return mPopupType == ePopupTypeMenu; }
|
|
|
|
bool IsContextMenu() { return mIsContext; }
|
2015-09-17 18:20:33 +03:00
|
|
|
nsIgnoreKeys IgnoreKeys() { return mIgnoreKeys; }
|
|
|
|
void SetIgnoreKeys(nsIgnoreKeys aIgnoreKeys) { mIgnoreKeys = aIgnoreKeys; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsOnMenuBar() { return mOnMenuBar; }
|
|
|
|
void SetOnMenuBar(bool aOnMenuBar) { mOnMenuBar = aOnMenuBar; }
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuChainItem* GetParent() { return mParent; }
|
|
|
|
nsMenuChainItem* GetChild() { return mChild; }
|
2017-02-16 16:53:59 +03:00
|
|
|
bool FollowsAnchor() { return mFollowAnchor; }
|
|
|
|
void UpdateFollowAnchor();
|
|
|
|
void CheckForAnchorChange();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// set the parent of this item to aParent, also changing the parent
|
|
|
|
// to have this as a child.
|
|
|
|
void SetParent(nsMenuChainItem* aParent);
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
// Removes an item from the chain. The root pointer must be supplied in case
|
2007-07-04 19:49:38 +04:00
|
|
|
// the item is the first item in the chain in which case the pointer will be
|
|
|
|
// set to the next item, or null if there isn't another item. After detaching,
|
|
|
|
// this item will not have a parent or a child.
|
|
|
|
void Detach(nsMenuChainItem** aRoot);
|
|
|
|
};
|
|
|
|
|
|
|
|
// this class is used for dispatching popupshowing events asynchronously.
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsXULPopupShowingEvent : public mozilla::Runnable
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsXULPopupShowingEvent(nsIContent* aPopup,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aSelectFirstItem)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("nsXULPopupShowingEvent")
|
|
|
|
, mPopup(aPopup)
|
|
|
|
, mIsContextMenu(aIsContextMenu)
|
|
|
|
, mSelectFirstItem(aSelectFirstItem)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPopup, "null popup supplied to nsXULPopupShowingEvent constructor");
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mPopup;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsContextMenu;
|
|
|
|
bool mSelectFirstItem;
|
2007-07-04 19:49:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// this class is used for dispatching popuphiding events asynchronously.
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsXULPopupHidingEvent : public mozilla::Runnable
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsXULPopupHidingEvent(nsIContent* aPopup,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsIContent* aNextPopup,
|
|
|
|
nsIContent* aLastPopup,
|
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)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("nsXULPopupHidingEvent")
|
|
|
|
, mPopup(aPopup)
|
|
|
|
, mNextPopup(aNextPopup)
|
|
|
|
, mLastPopup(aLastPopup)
|
|
|
|
, mPopupType(aPopupType)
|
|
|
|
, mDeselectMenu(aDeselectMenu)
|
|
|
|
, mIsRollup(aIsCancel)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPopup, "null popup supplied to nsXULPopupHidingEvent constructor");
|
|
|
|
// aNextPopup and aLastPopup may be null
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mPopup;
|
|
|
|
nsCOMPtr<nsIContent> mNextPopup;
|
|
|
|
nsCOMPtr<nsIContent> mLastPopup;
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType mPopupType;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDeselectMenu;
|
2014-04-08 16:45:52 +04:00
|
|
|
bool mIsRollup;
|
2007-07-04 19:49:38 +04:00
|
|
|
};
|
|
|
|
|
2016-08-17 01:33:05 +03:00
|
|
|
// this class is used for dispatching popuppositioned events asynchronously.
|
|
|
|
class nsXULPopupPositionedEvent : public mozilla::Runnable
|
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit nsXULPopupPositionedEvent(nsIContent* aPopup,
|
2016-08-17 01:33:05 +03:00
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aSelectFirstItem)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("nsXULPopupPositionedEvent")
|
|
|
|
, mPopup(aPopup)
|
2016-08-17 01:33:05 +03:00
|
|
|
, mIsContextMenu(aIsContextMenu)
|
|
|
|
, mSelectFirstItem(aSelectFirstItem)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPopup, "null popup supplied to nsXULPopupShowingEvent constructor");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override;
|
|
|
|
|
|
|
|
// Asynchronously dispatch a popuppositioned event at aPopup if this is a
|
|
|
|
// panel that should receieve such events. Return true if the event was sent.
|
|
|
|
static bool DispatchIfNeeded(nsIContent *aPopup,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aSelectFirstItem);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mPopup;
|
|
|
|
bool mIsContextMenu;
|
|
|
|
bool mSelectFirstItem;
|
|
|
|
};
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// this class is used for dispatching menu command events asynchronously.
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsXULMenuCommandEvent : public mozilla::Runnable
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsXULMenuCommandEvent(nsIContent* aMenu,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsTrusted,
|
|
|
|
bool aShift,
|
|
|
|
bool aControl,
|
|
|
|
bool aAlt,
|
|
|
|
bool aMeta,
|
|
|
|
bool aUserInput,
|
|
|
|
bool aFlipChecked)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("nsXULMenuCommandEvent")
|
|
|
|
, mMenu(aMenu)
|
|
|
|
, mIsTrusted(aIsTrusted)
|
|
|
|
, mShift(aShift)
|
|
|
|
, mControl(aControl)
|
|
|
|
, mAlt(aAlt)
|
|
|
|
, mMeta(aMeta)
|
|
|
|
, mUserInput(aUserInput)
|
|
|
|
, mFlipChecked(aFlipChecked)
|
|
|
|
, mCloseMenuMode(CloseMenuMode_Auto)
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aMenu, "null menu supplied to nsXULMenuCommandEvent constructor");
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2010-04-19 18:12:58 +04:00
|
|
|
void SetCloseMenuMode(CloseMenuMode aCloseMenuMode) { mCloseMenuMode = aCloseMenuMode; }
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mMenu;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsTrusted;
|
|
|
|
bool mShift;
|
|
|
|
bool mControl;
|
|
|
|
bool mAlt;
|
|
|
|
bool mMeta;
|
|
|
|
bool mUserInput;
|
|
|
|
bool mFlipChecked;
|
2007-08-30 19:43:10 +04:00
|
|
|
CloseMenuMode mCloseMenuMode;
|
2007-07-04 19:49:38 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsXULPopupManager final : public nsIDOMEventListener,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIRollupListener,
|
|
|
|
public nsIObserver
|
2007-07-04 19:49:38 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend class nsXULPopupShowingEvent;
|
|
|
|
friend class nsXULPopupHidingEvent;
|
2016-08-17 01:33:05 +03:00
|
|
|
friend class nsXULPopupPositionedEvent;
|
2007-07-04 19:49:38 +04:00
|
|
|
friend class nsXULMenuCommandEvent;
|
2014-04-08 16:45:52 +04:00
|
|
|
friend class TransitionEnder;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-06-18 13:11:36 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2011-06-29 22:07:48 +04:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2009-12-23 02:49:33 +03:00
|
|
|
// nsIRollupListener
|
2015-01-08 04:52:20 +03:00
|
|
|
virtual bool Rollup(uint32_t aCount, bool aFlush,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsIntPoint* pos, nsIContent** aLastRolledUp) override;
|
|
|
|
virtual bool ShouldRollupOnMouseWheelEvent() override;
|
|
|
|
virtual bool ShouldConsumeOnMouseWheelEvent() override;
|
|
|
|
virtual bool ShouldRollupOnMouseActivate() override;
|
|
|
|
virtual uint32_t GetSubmenuWidgetChain(nsTArray<nsIWidget*> *aWidgetChain) override;
|
|
|
|
virtual void NotifyGeometryChange() override {}
|
|
|
|
virtual nsIWidget* GetRollupWidget() override;
|
2008-01-17 09:57:13 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
static nsXULPopupManager* sInstance;
|
|
|
|
|
|
|
|
// initialize and shutdown methods called by nsLayoutStatics
|
|
|
|
static nsresult Init();
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
// returns a weak reference to the popup manager instance, could return null
|
|
|
|
// if a popup manager could not be allocated
|
|
|
|
static nsXULPopupManager* GetInstance();
|
|
|
|
|
2014-03-19 20:48:08 +04:00
|
|
|
// This should be called when a window is moved or resized to adjust the
|
|
|
|
// popups accordingly.
|
2016-01-30 20:05:36 +03:00
|
|
|
void AdjustPopupsOnWindowChange(nsPIDOMWindowOuter* aWindow);
|
2014-03-19 20:48:08 +04:00
|
|
|
void AdjustPopupsOnWindowChange(nsIPresShell* aPresShell);
|
2011-11-08 23:59:07 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// given a menu frame, find the prevous or next menu frame. If aPopup is
|
|
|
|
// true then navigate a menupopup, from one item on the menu to the previous
|
|
|
|
// or next one. This is used for cursor navigation between items in a popup
|
|
|
|
// menu. If aIsPopup is false, the navigation is on a menubar, so navigate
|
|
|
|
// between menus on the menubar. This is used for left/right cursor navigation.
|
|
|
|
//
|
2007-11-17 18:47:38 +03:00
|
|
|
// Items that are not valid, such as non-menu or non-menuitem elements are
|
|
|
|
// skipped, and the next or previous item after that is checked.
|
2007-07-04 19:49:38 +04:00
|
|
|
//
|
2007-11-17 18:47:38 +03:00
|
|
|
// If aStart is null, the first valid item is retrieved by GetNextMenuItem
|
|
|
|
// and the last valid item is retrieved by GetPreviousMenuItem.
|
|
|
|
//
|
|
|
|
// Both methods will loop around the beginning or end if needed.
|
2007-07-04 19:49:38 +04:00
|
|
|
//
|
|
|
|
// aParent - the parent menubar or menupopup
|
|
|
|
// aStart - the menu/menuitem to start navigation from. GetPreviousMenuItem
|
|
|
|
// returns the item before it, while GetNextMenuItem returns the
|
2007-11-17 18:47:38 +03:00
|
|
|
// item after it.
|
2007-07-04 19:49:38 +04:00
|
|
|
// aIsPopup - true for menupopups, false for menubars
|
2016-11-17 17:56:43 +03:00
|
|
|
// aWrap - true to wrap around to the beginning and continue searching if not
|
|
|
|
// found. False to end at the beginning or end of the menu.
|
2014-05-25 02:20:39 +04:00
|
|
|
static nsMenuFrame* GetPreviousMenuItem(nsContainerFrame* aParent,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuFrame* aStart,
|
2016-11-17 17:56:43 +03:00
|
|
|
bool aIsPopup,
|
|
|
|
bool aWrap);
|
2014-05-25 02:20:39 +04:00
|
|
|
static nsMenuFrame* GetNextMenuItem(nsContainerFrame* aParent,
|
2007-07-04 19:49:38 +04:00
|
|
|
nsMenuFrame* aStart,
|
2016-11-17 17:56:43 +03:00
|
|
|
bool aIsPopup,
|
|
|
|
bool aWrap);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// returns true if the menu item aContent is a valid menuitem which may
|
|
|
|
// be navigated to. aIsPopup should be true for items on a popup, or false
|
|
|
|
// for items on a menubar.
|
2015-12-07 04:15:53 +03:00
|
|
|
static bool IsValidMenuItem(nsIContent* aContent, bool aOnPopup);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// inform the popup manager that a menu bar has been activated or deactivated,
|
|
|
|
// either because one of its menus has opened or closed, or that the menubar
|
|
|
|
// has been focused such that its menus may be navigated with the keyboard.
|
|
|
|
// aActivate should be true when the menubar should be focused, and false
|
|
|
|
// when the active menu bar should be defocused. In the latter case, if
|
|
|
|
// aMenuBar isn't currently active, yet another menu bar is, that menu bar
|
|
|
|
// will remain active.
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetActiveMenuBar(nsMenuBarFrame* aMenuBar, bool aActivate);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// retrieve the node and offset of the last mouse event used to open a
|
|
|
|
// context menu. This information is determined from the rangeParent and
|
2007-11-17 18:47:38 +03:00
|
|
|
// the rangeOffset of the event supplied to ShowPopup or ShowPopupAtScreen.
|
2007-07-04 19:49:38 +04:00
|
|
|
// This is used by the implementation of nsIDOMXULDocument::GetPopupRangeParent
|
|
|
|
// and nsIDOMXULDocument::GetPopupRangeOffset.
|
2012-08-22 19:56:38 +04:00
|
|
|
void GetMouseLocation(nsIDOMNode** aNode, int32_t* aOffset);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a <menu> given its content node. If aSelectFirstItem is
|
|
|
|
* set to true, the first item on the menu will automatically be
|
|
|
|
* selected. If aAsynchronous is true, the event will be dispatched
|
|
|
|
* asynchronously. This should be true when called from frame code.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void ShowMenu(nsIContent *aMenu, bool aSelectFirstItem, bool aAsynchronous);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a popup, either anchored or unanchored. If aSelectFirstItem is
|
|
|
|
* true, then the first item in the menu is selected. The arguments are
|
|
|
|
* similar to those for nsIPopupBoxObject::OpenPopup.
|
|
|
|
*
|
2007-11-17 18:47:38 +03:00
|
|
|
* aTriggerEvent should be the event that triggered the event. This is used
|
2010-08-09 20:17:19 +04:00
|
|
|
* to determine the coordinates and trigger node for the popup. This may be
|
|
|
|
* null if the popup was not triggered by an event.
|
2007-11-17 18:47:38 +03:00
|
|
|
*
|
2007-07-04 19:49:38 +04:00
|
|
|
* This fires the popupshowing event synchronously.
|
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a popup at a specific screen position specified by aXPos and aYPos,
|
|
|
|
* measured in CSS pixels.
|
|
|
|
*
|
|
|
|
* This fires the popupshowing event synchronously.
|
2008-04-24 01:25:34 +04:00
|
|
|
*
|
|
|
|
* If aIsContextMenu is true, the popup is positioned at a slight
|
|
|
|
* offset from aXPos/aYPos to ensure that it is not under the mouse
|
|
|
|
* cursor.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
/* Open a popup anchored at a screen rectangle specified by aRect.
|
|
|
|
* The remaining arguments are similar to ShowPopup.
|
|
|
|
*/
|
|
|
|
void ShowPopupAtScreenRect(nsIContent* aPopup,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aAttributesOverride,
|
|
|
|
nsIDOMEvent* aTriggerEvent);
|
|
|
|
|
2010-09-11 00:22:17 +04:00
|
|
|
/**
|
|
|
|
* Open a tooltip at a specific screen position specified by aXPos and aYPos,
|
|
|
|
* measured in CSS pixels.
|
|
|
|
*
|
|
|
|
* This fires the popupshowing event synchronously.
|
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* This method is provided only for compatibility with an older popup API.
|
|
|
|
* New code should not call this function and should call ShowPopup instead.
|
|
|
|
*
|
|
|
|
* This fires the popupshowing event synchronously.
|
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
|
|
|
/*
|
|
|
|
* Hide a popup aPopup. If the popup is in a <menu>, then also inform the
|
|
|
|
* menu that the popup is being hidden.
|
|
|
|
*
|
|
|
|
* aHideChain - true if the entire chain of menus should be closed. If false,
|
|
|
|
* only this popup is closed.
|
|
|
|
* aDeselectMenu - true if the parent <menu> of the popup should be deselected.
|
|
|
|
* This will be false when the menu is closed by pressing the
|
|
|
|
* Escape key.
|
|
|
|
* aAsynchronous - true if the first popuphiding event should be sent
|
|
|
|
* asynchrously. This should be true if HidePopup is called
|
|
|
|
* from a frame.
|
2014-09-24 20:15:49 +04:00
|
|
|
* aIsCancel - true if this popup is hiding due to being cancelled.
|
2009-06-12 22:23:16 +04:00
|
|
|
* aLastPopup - optional popup to close last when hiding a chain of menus.
|
|
|
|
* If null, then all popups will be closed.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
|
|
|
void 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,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* aLastPopup = nullptr);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide a popup after a short delay. This is used when rolling over menu items.
|
|
|
|
* This timer is stored in mCloseTimer. The timer may be cancelled and the popup
|
|
|
|
* closed by calling KillMenuTimer.
|
|
|
|
*/
|
|
|
|
void HidePopupAfterDelay(nsMenuPopupFrame* aPopup);
|
|
|
|
|
|
|
|
/**
|
2008-02-08 23:23:05 +03:00
|
|
|
* Hide all of the popups from a given docshell. This should be called when the
|
2007-07-04 19:49:38 +04:00
|
|
|
* document is hidden.
|
|
|
|
*/
|
2008-02-08 23:23:05 +03:00
|
|
|
void HidePopupsInDocShell(nsIDocShellTreeItem* aDocShellToHide);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2016-01-31 16:00:44 +03:00
|
|
|
/**
|
|
|
|
* Enable or disable the dynamic noautohide state of a panel.
|
|
|
|
*
|
|
|
|
* aPanel - the panel whose state is to change
|
|
|
|
* aShouldRollup - whether the panel is no longer noautohide
|
|
|
|
*/
|
|
|
|
void EnableRollup(nsIContent* aPopup, bool aShouldRollup);
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
/**
|
|
|
|
* Check if any popups need to be repositioned or hidden after a style or
|
|
|
|
* layout change. This will update, for example, any arrow type panels when
|
|
|
|
* the anchor that is is pointing to has moved, resized or gone away.
|
|
|
|
* Only those popups that pertain to the supplied aRefreshDriver are updated.
|
|
|
|
*/
|
|
|
|
void UpdatePopupPositions(nsRefreshDriver* aRefreshDriver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable or disable anchor following on the popup if needed.
|
|
|
|
*/
|
|
|
|
void UpdateFollowAnchor(nsMenuPopupFrame* aPopup);
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* Execute a menu command from the triggering event aEvent.
|
|
|
|
*
|
|
|
|
* aMenu - a menuitem to execute
|
2010-04-19 18:12:58 +04:00
|
|
|
* aEvent - an nsXULMenuCommandEvent that contains all the info from the mouse
|
|
|
|
* event which triggered the menu to be executed, may not be null
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
2010-04-19 18:12:58 +04:00
|
|
|
void ExecuteMenu(nsIContent* aMenu, nsXULMenuCommandEvent* aEvent);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-07-11 21:23:30 +04:00
|
|
|
/**
|
|
|
|
* Return true if the popup for the supplied content node is open.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPopupOpen(nsIContent* aPopup);
|
2007-07-11 21:23:30 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* Return true if the popup for the supplied menu parent is open.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPopupOpenForMenuParent(nsMenuParent* aMenuParent);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
/**
|
|
|
|
* Return the frame for the topmost open popup of a given type, or null if
|
2007-09-18 19:00:43 +04:00
|
|
|
* no popup of that type is open. If aType is ePopupTypeAny, a menu of any
|
2017-03-13 16:44:02 +03:00
|
|
|
* type is returned.
|
2007-08-16 05:09:58 +04:00
|
|
|
*/
|
|
|
|
nsIFrame* GetTopPopup(nsPopupType aType);
|
|
|
|
|
2007-07-16 18:53:32 +04:00
|
|
|
/**
|
2009-02-24 11:25:25 +03:00
|
|
|
* Return an array of all the open and visible popup frames for
|
|
|
|
* menus, in order from top to bottom.
|
2007-07-16 18:53:32 +04:00
|
|
|
*/
|
2012-11-29 20:14:13 +04:00
|
|
|
void GetVisiblePopups(nsTArray<nsIFrame *>& aPopups);
|
2007-07-16 18:53:32 +04:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
/**
|
|
|
|
* Get the node that last triggered a popup or tooltip in the document
|
|
|
|
* aDocument. aDocument must be non-null and be a document contained within
|
|
|
|
* the same window hierarchy as the popup to retrieve.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIDOMNode> GetLastTriggerPopupNode(nsIDocument* aDocument)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetLastTriggerNode(aDocument, false);
|
2010-08-09 20:17:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIDOMNode> GetLastTriggerTooltipNode(nsIDocument* aDocument)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetLastTriggerNode(aDocument, true);
|
2010-08-09 20:17:19 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* Return false if a popup may not be opened. This will return false if the
|
|
|
|
* popup is already open, if the popup is in a content shell that is not
|
|
|
|
* focused, or if it is a submenu of another menu that isn't open.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool MayShowPopup(nsMenuPopupFrame* aFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2010-07-27 17:38:02 +04:00
|
|
|
/**
|
|
|
|
* Indicate that the popup associated with aView has been moved to the
|
|
|
|
* specified screen coordiates.
|
|
|
|
*/
|
2011-11-21 21:53:20 +04:00
|
|
|
void PopupMoved(nsIFrame* aFrame, nsIntPoint aPoint);
|
2010-07-27 17:38:02 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicate that the popup associated with aView has been resized to the
|
2015-03-30 18:36:01 +03:00
|
|
|
* given device pixel size aSize.
|
2010-07-27 17:38:02 +04:00
|
|
|
*/
|
2015-03-30 18:36:01 +03:00
|
|
|
void PopupResized(nsIFrame* aFrame, mozilla::LayoutDeviceIntSize aSize);
|
2010-07-27 17:38:02 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* Called when a popup frame is destroyed. In this case, just remove the
|
|
|
|
* item and later popups from the list. No point going through HidePopup as
|
|
|
|
* the frames have gone away.
|
|
|
|
*/
|
|
|
|
void PopupDestroyed(nsMenuPopupFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if there is a context menu open. If aPopup is specified,
|
|
|
|
* then the context menu must be later in the chain than aPopup. If aPopup
|
|
|
|
* is null, returns true if any context menu at all is open.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasContextMenu(nsMenuPopupFrame* aPopup);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the commands for the menus within the menu popup for a given
|
|
|
|
* content node. aPopup should be a XUL menupopup element. This method
|
|
|
|
* changes attributes on the children of aPopup, and deals only with the
|
|
|
|
* content of the popup, not the frames.
|
|
|
|
*/
|
|
|
|
void UpdateMenuItems(nsIContent* aPopup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the timer which hides a popup after a delay, started by a previous
|
|
|
|
* call to HidePopupAfterDelay. In addition, the popup awaiting to be hidden
|
|
|
|
* is closed asynchronously.
|
|
|
|
*/
|
|
|
|
void KillMenuTimer();
|
|
|
|
|
2007-07-11 16:05:40 +04:00
|
|
|
/**
|
|
|
|
* Cancel the timer which closes menus after delay, but only if the menu to
|
|
|
|
* close is aMenuParent. When a submenu is opened, the user might move the
|
|
|
|
* mouse over a sibling menuitem which would normally close the menu. This
|
|
|
|
* menu is closed via a timer. However, if the user moves the mouse over the
|
|
|
|
* submenu before the timer fires, we should instead cancel the timer. This
|
|
|
|
* ensures that the user can move the mouse diagonally over a menu.
|
|
|
|
*/
|
2008-12-05 19:37:31 +03:00
|
|
|
void CancelMenuTimer(nsMenuParent* aMenuParent);
|
2007-07-11 16:05:40 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
2016-12-07 04:25:09 +03:00
|
|
|
* Handles navigation for menu accelkeys. If aFrame is specified, then the
|
|
|
|
* key is handled by that popup, otherwise if aFrame is null, the key is
|
|
|
|
* handled by the active popup or menubar.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent,
|
2016-12-07 04:25:09 +03:00
|
|
|
nsMenuPopupFrame* aFrame);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles cursor navigation within a menu. Returns true if the key has
|
|
|
|
* been handled.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
bool HandleKeyboardNavigation(uint32_t aKeyCode);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-07-23 21:08:10 +04:00
|
|
|
/**
|
|
|
|
* Handle keyboard navigation within a menu popup specified by aFrame.
|
2007-11-17 18:47:38 +03:00
|
|
|
* Returns true if the key was handled and other default handling
|
2007-07-23 21:08:10 +04:00
|
|
|
* should not occur.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleKeyboardNavigationInPopup(nsMenuPopupFrame* aFrame,
|
2007-07-23 21:08:10 +04:00
|
|
|
nsNavigationDirection aDir)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return HandleKeyboardNavigationInPopup(nullptr, aFrame, aDir);
|
2007-07-23 21:08:10 +04:00
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:29 +04:00
|
|
|
/**
|
|
|
|
* Handles the keyboard event with keyCode value. Returns true if the event
|
|
|
|
* has been handled.
|
|
|
|
*/
|
|
|
|
bool HandleKeyboardEventWithKeyCode(nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
nsMenuChainItem* aTopVisibleMenuItem);
|
|
|
|
|
2017-01-17 23:40:15 +03:00
|
|
|
// Sets mIgnoreKeys of the Top Visible Menu Item
|
|
|
|
nsresult UpdateIgnoreKeys(bool aIgnoreKeys);
|
|
|
|
|
2011-06-29 22:07:48 +04:00
|
|
|
nsresult KeyUp(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
nsresult KeyDown(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
nsresult KeyPress(nsIDOMKeyEvent* aKeyEvent);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsXULPopupManager();
|
|
|
|
~nsXULPopupManager();
|
|
|
|
|
|
|
|
// get the nsMenuPopupFrame, if any, for the given content node
|
2011-09-29 10:19:26 +04:00
|
|
|
nsMenuPopupFrame* GetPopupFrameForContent(nsIContent* aContent, bool aShouldFlush);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-15 18:03:21 +04:00
|
|
|
// return the topmost menu, skipping over invisible popups
|
|
|
|
nsMenuChainItem* GetTopVisibleMenu();
|
|
|
|
|
2015-12-09 07:06:04 +03:00
|
|
|
// Hide all of the visible popups from the given list. This function can
|
|
|
|
// cause style changes and frame destruction.
|
|
|
|
void HidePopupsInList(const nsTArray<nsMenuPopupFrame *> &aFrames);
|
2007-11-17 18:47:38 +03:00
|
|
|
|
2010-08-09 20:17:19 +04:00
|
|
|
// set the event that was used to trigger the popup, or null to clear the
|
|
|
|
// event details. aTriggerContent will be set to the target of the event.
|
|
|
|
void InitTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup, nsIContent** aTriggerContent);
|
2007-11-17 18:47:38 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// callbacks for ShowPopup and HidePopup as events may be done asynchronously
|
|
|
|
void 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
|
|
|
void 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
|
|
|
|
|
|
|
/**
|
2010-09-06 07:30:17 +04:00
|
|
|
* Fire a popupshowing event on the popup and then open the popup.
|
2007-08-03 18:05:07 +04:00
|
|
|
*
|
2010-09-06 07:30:17 +04:00
|
|
|
* aPopup - the popup to open
|
2007-07-04 19:49:38 +04:00
|
|
|
* aIsContextMenu - true for context menus
|
|
|
|
* aSelectFirstItem - true to select the first item in the menu
|
|
|
|
*/
|
|
|
|
void FirePopupShowingEvent(nsIContent* aPopup,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsContextMenu,
|
2017-06-27 21:32:07 +03:00
|
|
|
bool aSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fire a popuphiding event and then hide the popup. This will be called
|
|
|
|
* recursively if aNextPopup and aLastPopup are set in order to hide a chain
|
|
|
|
* of open menus. If these are not set, only one popup is closed. However,
|
2007-08-16 05:09:58 +04:00
|
|
|
* if the popup type indicates a menu, yet the next popup is not a menu,
|
|
|
|
* then this ends the closing of popups. This allows a menulist inside a
|
|
|
|
* non-menu to close up the menu but not close up the panel it is contained
|
|
|
|
* within.
|
2007-07-04 19:49:38 +04:00
|
|
|
*
|
2007-08-03 18:05:07 +04:00
|
|
|
* The caller must keep a strong reference to aPopup, aNextPopup and aLastPopup.
|
|
|
|
*
|
2007-07-04 19:49:38 +04:00
|
|
|
* aPopup - the popup to hide
|
|
|
|
* aNextPopup - the next popup to hide
|
|
|
|
* aLastPopup - the last popup in the chain to hide
|
|
|
|
* aPresContext - nsPresContext for the popup's frame
|
2007-08-16 05:09:58 +04:00
|
|
|
* aPopupType - the PopupType of the frame.
|
2007-07-04 19:49:38 +04:00
|
|
|
* aDeselectMenu - true to unhighlight the menu when hiding it
|
2014-09-24 20:15:49 +04:00
|
|
|
* aIsCancel - true if this popup is hiding due to being cancelled.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
|
|
|
void 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
|
|
|
|
2007-07-23 21:08:10 +04:00
|
|
|
/**
|
|
|
|
* Handle keyboard navigation within a menu popup specified by aItem.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleKeyboardNavigationInPopup(nsMenuChainItem* aItem,
|
2007-07-23 21:08:10 +04:00
|
|
|
nsNavigationDirection aDir)
|
|
|
|
{
|
|
|
|
return HandleKeyboardNavigationInPopup(aItem, aItem->Frame(), aDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Handle keyboard navigation within a menu popup aFrame. If aItem is
|
|
|
|
* supplied, then it is expected to have a frame equal to aFrame.
|
|
|
|
* If aItem is non-null, then the navigation may be redirected to
|
|
|
|
* an open submenu if one exists. Returns true if the key was
|
2007-11-17 18:47:38 +03:00
|
|
|
* handled and other default handling should not occur.
|
2007-07-23 21:08:10 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleKeyboardNavigationInPopup(nsMenuChainItem* aItem,
|
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
|
|
|
protected:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
already_AddRefed<nsIDOMNode> GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip);
|
2010-08-09 20:17:19 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
|
|
|
* Set mouse capturing for the current popup. This traps mouse clicks that
|
|
|
|
* occur outside the popup so that it can be closed up. aOldPopup should be
|
|
|
|
* set to the popup that was previously the current popup.
|
|
|
|
*/
|
|
|
|
void SetCaptureState(nsIContent *aOldPopup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key event listeners are attached to the document containing the current
|
|
|
|
* menu for menu and shortcut navigation. Only one listener is needed at a
|
|
|
|
* time, stored in mKeyListener, so switch it only if the document changes.
|
|
|
|
* Having menus in different documents is very rare, so the listeners will
|
|
|
|
* usually only be attached when the first menu opens and removed when all
|
|
|
|
* menus have closed.
|
|
|
|
*
|
|
|
|
* This is also used when only a menubar is active without any open menus,
|
|
|
|
* so that keyboard navigation between menus on the menubar may be done.
|
|
|
|
*/
|
|
|
|
void UpdateKeyboardListeners();
|
|
|
|
|
2008-02-08 23:23:05 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the docshell for aDoc is aExpected or a child of aExpected.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsChildOfDocShell(nsIDocument* aDoc, nsIDocShellTreeItem* aExpected);
|
2008-02-08 23:23:05 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// the document the key event listener is attached to
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> mKeyListener;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// widget that is currently listening to rollup events
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// range parent and offset set in SetTriggerEvent
|
2007-07-04 19:49:38 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> mRangeParent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRangeOffset;
|
2009-07-22 04:45:06 +04:00
|
|
|
// Device pixels relative to the showing popup's presshell's
|
2010-07-19 06:23:48 +04:00
|
|
|
// root prescontext's root frame.
|
2015-02-04 23:21:03 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint mCachedMousePoint;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2011-07-09 11:41:32 +04:00
|
|
|
// cached modifiers
|
2013-09-14 06:39:41 +04:00
|
|
|
mozilla::Modifiers mCachedModifiers;
|
2011-07-09 11:41:32 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// set to the currently active menu bar, if any
|
|
|
|
nsMenuBarFrame* mActiveMenuBar;
|
|
|
|
|
2008-12-05 19:37:30 +03:00
|
|
|
// linked list of normal menus and panels.
|
|
|
|
nsMenuChainItem* mPopups;
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// timer used for HidePopupAfterDelay
|
|
|
|
nsCOMPtr<nsITimer> mCloseTimer;
|
|
|
|
|
|
|
|
// a popup that is waiting on the timer
|
|
|
|
nsMenuPopupFrame* mTimerMenu;
|
2010-08-09 20:17:19 +04:00
|
|
|
|
|
|
|
// the popup that is currently being opened, stored only during the
|
|
|
|
// popupshowing event
|
|
|
|
nsCOMPtr<nsIContent> mOpeningPopup;
|
2016-01-28 21:11:31 +03:00
|
|
|
|
|
|
|
// If true, all popups won't hide automatically on blur
|
|
|
|
static bool sDevtoolsDisableAutoHide;
|
2007-07-04 19:49:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|