/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
/**
* The XUL Popup Manager keeps track of all open popups.
*/
#ifndef nsXULPopupManager_h__
#define nsXULPopupManager_h__
#include "mozilla/Logging.h"
#include "nsHashtablesFwd.h"
#include "nsIContent.h"
#include "nsIRollupListener.h"
#include "nsIDOMEventListener.h"
#include "Units.h"
#include "nsPoint.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIObserver.h"
#include "nsThreadUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/FunctionRef.h"
#include "mozilla/widget/InitData.h"
#include "mozilla/widget/NativeMenu.h"
// XXX Avoid including this here by moving function bodies to the cpp file.
#include "mozilla/dom/Element.h"
// X.h defines KeyPress
#ifdef KeyPress
# undef KeyPress
#endif
/**
* 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
* linked list in mPopups.
* 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.
*/
class nsContainerFrame;
class nsITimer;
class nsIDocShellTreeItem;
class nsMenuPopupFrame;
class nsPIDOMWindowOuter;
class nsRefreshDriver;
namespace mozilla {
class PresShell;
namespace dom {
class Event;
class KeyboardEvent;
class UIEvent;
class XULButtonElement;
class XULMenuBarElement;
class XULPopupElement;
} // namespace dom
} // namespace mozilla
// XUL popups can be in several different states. When opening a popup, the
// state changes as follows:
// ePopupClosed - initial state
// ePopupShowing - during the period when the popupshowing event fires
// ePopupOpening - between the popupshowing event and being visible. Creation
// of the child frames, layout and reflow occurs in this
// state. The popup is stored in the popup manager's list of
// open popups during this state.
// ePopupVisible - layout is done and the popup's view and widget are made
// visible. The popup is visible on screen but may be
// transitioning. The popupshown event has not yet fired.
// ePopupShown - the popup has been shown and is fully ready. This state is
// assigned just before the popupshown event fires.
// When closing a popup:
// ePopupHidden - during the period when the popuphiding event fires and
// the popup is removed.
// ePopupClosed - the popup's widget is made invisible.
enum nsPopupState {
// state when a popup is not open
ePopupClosed,
// state from when a popup is requested to be shown to after the
// popupshowing event has been fired.
ePopupShowing,
// state while a popup is waiting to be laid out and positioned
ePopupPositioning,
// state while a popup is open but the widget is not yet visible
ePopupOpening,
// state while a popup is visible and waiting for the popupshown event
ePopupVisible,
// state while a popup is open and visible on screen
ePopupShown,
// state from when a popup is requested to be hidden to when it is closed.
ePopupHiding,
// state which indicates that the popup was hidden without firing the
// popuphiding or popuphidden events. It is used when executing a menu
// command because the menu needs to be hidden before the command event
// fires, yet the popuphiding and popuphidden events are fired after. This
// state can also occur when the popup is removed because the document is
// unloaded.
ePopupInvisible
};
// 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
};
/**
* 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
};
enum nsIgnoreKeys {
eIgnoreKeys_False,
eIgnoreKeys_True,
eIgnoreKeys_Shortcuts,
};
enum class HidePopupOption : uint8_t {
// If the entire chain of menus should be closed.
HideChain,
// If the parent