Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends

nsXULPopupManager Class Reference

#include <nsXULPopupManager.h>

Inheritance diagram for nsXULPopupManager:
Collaboration diagram for nsXULPopupManager:

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS virtual
NS_DECL_NSITIMERCALLBACK
nsresult 
Rollup (PRUint32 aCount, nsIContent **aContent)
virtual nsresult ShouldRollupOnMouseWheelEvent (PRBool *aShould)
virtual nsresult ShouldRollupOnMouseActivate (PRBool *aShould)
virtual PRUint32 GetSubmenuWidgetChain (nsTArray< nsIWidget * > *aWidgetChain)
virtual void AdjustPopupsOnWindowChange (nsPIDOMWindow *aWindow)
nsIFrame * GetFrameOfTypeForContent (nsIContent *aContent, nsIAtom *aFrameType, PRBool aShouldFlush)
void SetActiveMenuBar (nsMenuBarFrame *aMenuBar, PRBool aActivate)
void GetMouseLocation (nsIDOMNode **aNode, PRInt32 *aOffset)
void ShowMenu (nsIContent *aMenu, PRBool aSelectFirstItem, PRBool aAsynchronous)
 Open a <menu> given its content node.
void ShowPopup (nsIContent *aPopup, nsIContent *aAnchorContent, const nsAString &aPosition, PRInt32 aXPos, PRInt32 aYPos, PRBool aIsContextMenu, PRBool aAttributesOverride, PRBool aSelectFirstItem, nsIDOMEvent *aTriggerEvent)
 Open a popup, either anchored or unanchored.
void ShowPopupAtScreen (nsIContent *aPopup, PRInt32 aXPos, PRInt32 aYPos, PRBool aIsContextMenu, nsIDOMEvent *aTriggerEvent)
 Open a popup at a specific screen position specified by aXPos and aYPos, measured in CSS pixels.
void ShowTooltipAtScreen (nsIContent *aPopup, nsIContent *aTriggerContent, PRInt32 aXPos, PRInt32 aYPos)
 Open a tooltip at a specific screen position specified by aXPos and aYPos, measured in CSS pixels.
void ShowPopupWithAnchorAlign (nsIContent *aPopup, nsIContent *aAnchorContent, nsAString &aAnchor, nsAString &aAlign, PRInt32 aXPos, PRInt32 aYPos, PRBool aIsContextMenu)
 This method is provided only for compatibility with an older popup API.
void HidePopup (nsIContent *aPopup, PRBool aHideChain, PRBool aDeselectMenu, PRBool aAsynchronous, nsIContent *aLastPopup=0L)
void HidePopup (nsIView *aView)
 Hide the popup associated the view aView.
void HidePopupAfterDelay (nsMenuPopupFrame *aPopup)
 Hide a popup after a short delay.
void HidePopupsInDocShell (nsIDocShellTreeItem *aDocShellToHide)
 Hide all of the popups from a given docshell.
void ExecuteMenu (nsIContent *aMenu, nsXULMenuCommandEvent *aEvent)
 Execute a menu command from the triggering event aEvent.
PRBool IsPopupOpen (nsIContent *aPopup)
 Return true if the popup for the supplied content node is open.
PRBool IsPopupOpenForMenuParent (nsMenuParent *aMenuParent)
 Return true if the popup for the supplied menu parent is open.
nsIFrame * GetTopPopup (nsPopupType aType)
 Return the frame for the topmost open popup of a given type, or null if no popup of that type is open.
nsTArray< nsIFrame * > GetVisiblePopups ()
 Return an array of all the open and visible popup frames for menus, in order from top to bottom.
already_AddRefed< nsIDOMNodeGetLastTriggerPopupNode (nsIDocument *aDocument)
 Get the node that last triggered a popup or tooltip in the document aDocument.
already_AddRefed< nsIDOMNodeGetLastTriggerTooltipNode (nsIDocument *aDocument)
PRBool MayShowPopup (nsMenuPopupFrame *aFrame)
 Return false if a popup may not be opened.
void PopupMoved (nsIView *aView, nsIntPoint aPoint)
 Indicate that the popup associated with aView has been moved to the specified screen coordiates.
void PopupResized (nsIView *aView, nsIntSize ASize)
 Indicate that the popup associated with aView has been resized to the specified screen width and height.
void PopupDestroyed (nsMenuPopupFrame *aFrame)
 Called when a popup frame is destroyed.
PRBool HasContextMenu (nsMenuPopupFrame *aPopup)
 Returns true if there is a context menu open.
void UpdateMenuItems (nsIContent *aPopup)
 Update the commands for the menus within the menu popup for a given content node.
void KillMenuTimer ()
 Stop the timer which hides a popup after a delay, started by a previous call to HidePopupAfterDelay.
void CancelMenuTimer (nsMenuParent *aMenuParent)
 Cancel the timer which closes menus after delay, but only if the menu to close is aMenuParent.
PRBool HandleShortcutNavigation (nsIDOMKeyEvent *aKeyEvent, nsMenuPopupFrame *aFrame)
 Handles navigation for menu accelkeys.
PRBool HandleKeyboardNavigation (PRUint32 aKeyCode)
 Handles cursor navigation within a menu.
PRBool HandleKeyboardNavigationInPopup (nsMenuPopupFrame *aFrame, nsNavigationDirection aDir)
 Handle keyboard navigation within a menu popup specified by aFrame.
nsresult HandleEvent (nsIDOMEvent *aEvent)
virtual nsresult KeyUp (nsIDOMEvent *aKeyEvent)
virtual nsresult KeyDown (nsIDOMEvent *aKeyEvent)
virtual nsresult KeyPress (nsIDOMEvent *aKeyEvent)

Static Public Member Functions

static nsresult Init ()
static void Shutdown ()
static nsXULPopupManagerGetInstance ()
static nsMenuFrame * GetPreviousMenuItem (nsIFrame *aParent, nsMenuFrame *aStart, PRBool aIsPopup)
static nsMenuFrame * GetNextMenuItem (nsIFrame *aParent, nsMenuFrame *aStart, PRBool aIsPopup)
static PRBool IsValidMenuItem (nsPresContext *aPresContext, nsIContent *aContent, PRBool aOnPopup)

Static Public Attributes

static nsXULPopupManagersInstance

Protected Member Functions

 nsXULPopupManager ()
 ~nsXULPopupManager ()
nsMenuFrame * GetMenuFrameForContent (nsIContent *aContent)
nsMenuPopupFrame * GetPopupFrameForContent (nsIContent *aContent, PRBool aShouldFlush)
nsMenuChainItemGetTopVisibleMenu ()
void HidePopupsInList (const nsTArray< nsMenuPopupFrame * > &aFrames, PRBool aDeselectMenu)
void InitTriggerEvent (nsIDOMEvent *aEvent, nsIContent *aPopup, nsIContent **aTriggerContent)
void ShowPopupCallback (nsIContent *aPopup, nsMenuPopupFrame *aPopupFrame, PRBool aIsContextMenu, PRBool aSelectFirstItem)
void HidePopupCallback (nsIContent *aPopup, nsMenuPopupFrame *aPopupFrame, nsIContent *aNextPopup, nsIContent *aLastPopup, nsPopupType aPopupType, PRBool aDeselectMenu)
void FirePopupShowingEvent (nsIContent *aPopup, PRBool aIsContextMenu, PRBool aSelectFirstItem)
 Fire a popupshowing event on the popup and then open the popup.
void FirePopupHidingEvent (nsIContent *aPopup, nsIContent *aNextPopup, nsIContent *aLastPopup, nsPresContext *aPresContext, nsPopupType aPopupType, PRBool aDeselectMenu)
 Fire a popuphiding event and then hide the popup.
PRBool HandleKeyboardNavigationInPopup (nsMenuChainItem *aItem, nsNavigationDirection aDir)
 Handle keyboard navigation within a menu popup specified by aItem.
already_AddRefed< nsIDOMNodeGetLastTriggerNode (nsIDocument *aDocument, PRBool aIsTooltip)
void SetCaptureState (nsIContent *aOldPopup)
 Set mouse capturing for the current popup.
void UpdateKeyboardListeners ()
 Key event listeners are attached to the document containing the current menu for menu and shortcut navigation.
PRBool IsChildOfDocShell (nsIDocument *aDoc, nsIDocShellTreeItem *aExpected)

Protected Attributes

nsCOMPtr< nsIDOMEventTargetmKeyListener
nsCOMPtr< nsIWidget > mWidget
nsCOMPtr< nsIDOMNodemRangeParent
PRInt32 mRangeOffset
nsIntPoint mCachedMousePoint
nsMenuBarFrame * mActiveMenuBar
nsMenuChainItemmPopups
nsMenuChainItemmNoHidePanels
nsCOMPtr< nsITimermCloseTimer
nsMenuPopupFrame * mTimerMenu
nsCOMPtr< nsIContent > mOpeningPopup

Friends

class nsXULPopupShowingEvent
class nsXULPopupHidingEvent
class nsXULMenuCommandEvent

Constructor & Destructor Documentation

nsXULPopupManager::nsXULPopupManager (  )  [protected]
nsXULPopupManager::~nsXULPopupManager (  )  [protected]

Member Function Documentation

virtual void nsXULPopupManager::AdjustPopupsOnWindowChange ( nsPIDOMWindow aWindow  )  [virtual]
void nsXULPopupManager::CancelMenuTimer ( nsMenuParent *  aMenuParent  ) 

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.

void nsXULPopupManager::ExecuteMenu ( nsIContent *  aMenu,
nsXULMenuCommandEvent aEvent 
)

Execute a menu command from the triggering event aEvent.

aMenu - a menuitem to execute aEvent - an nsXULMenuCommandEvent that contains all the info from the mouse event which triggered the menu to be executed, may not be null

void nsXULPopupManager::FirePopupHidingEvent ( nsIContent *  aPopup,
nsIContent *  aNextPopup,
nsIContent *  aLastPopup,
nsPresContext aPresContext,
nsPopupType  aPopupType,
PRBool  aDeselectMenu 
) [protected]

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, 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.

The caller must keep a strong reference to aPopup, aNextPopup and aLastPopup.

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 aPopupType - the PopupType of the frame. aDeselectMenu - true to unhighlight the menu when hiding it

void nsXULPopupManager::FirePopupShowingEvent ( nsIContent *  aPopup,
PRBool  aIsContextMenu,
PRBool  aSelectFirstItem 
) [protected]

Fire a popupshowing event on the popup and then open the popup.

aPopup - the popup to open aIsContextMenu - true for context menus aSelectFirstItem - true to select the first item in the menu

nsIFrame* nsXULPopupManager::GetFrameOfTypeForContent ( nsIContent *  aContent,
nsIAtom aFrameType,
PRBool  aShouldFlush 
)
static nsXULPopupManager* nsXULPopupManager::GetInstance (  )  [static]
already_AddRefed<nsIDOMNode> nsXULPopupManager::GetLastTriggerNode ( nsIDocument *  aDocument,
PRBool  aIsTooltip 
) [protected]
already_AddRefed<nsIDOMNode> nsXULPopupManager::GetLastTriggerPopupNode ( nsIDocument *  aDocument  )  [inline]

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> nsXULPopupManager::GetLastTriggerTooltipNode ( nsIDocument *  aDocument  )  [inline]
nsMenuFrame* nsXULPopupManager::GetMenuFrameForContent ( nsIContent *  aContent  )  [protected]
void nsXULPopupManager::GetMouseLocation ( nsIDOMNode **  aNode,
PRInt32 *  aOffset 
)
static nsMenuFrame* nsXULPopupManager::GetNextMenuItem ( nsIFrame *  aParent,
nsMenuFrame *  aStart,
PRBool  aIsPopup 
) [static]
nsMenuPopupFrame* nsXULPopupManager::GetPopupFrameForContent ( nsIContent *  aContent,
PRBool  aShouldFlush 
) [protected]
static nsMenuFrame* nsXULPopupManager::GetPreviousMenuItem ( nsIFrame *  aParent,
nsMenuFrame *  aStart,
PRBool  aIsPopup 
) [static]
virtual PRUint32 nsXULPopupManager::GetSubmenuWidgetChain ( nsTArray< nsIWidget * > *  aWidgetChain  )  [virtual]
nsIFrame* nsXULPopupManager::GetTopPopup ( nsPopupType  aType  ) 

Return the frame for the topmost open popup of a given type, or null if no popup of that type is open.

If aType is ePopupTypeAny, a menu of any type is returned, except for popups in the mNoHidePanels list.

nsMenuChainItem* nsXULPopupManager::GetTopVisibleMenu (  )  [protected]
nsTArray<nsIFrame *> nsXULPopupManager::GetVisiblePopups (  ) 

Return an array of all the open and visible popup frames for menus, in order from top to bottom.

nsresult nsXULPopupManager::HandleEvent ( nsIDOMEvent aEvent  )  [inline]
PRBool nsXULPopupManager::HandleKeyboardNavigation ( PRUint32  aKeyCode  ) 

Handles cursor navigation within a menu.

Returns true if the key has been handled.

PRBool nsXULPopupManager::HandleKeyboardNavigationInPopup ( nsMenuPopupFrame *  aFrame,
nsNavigationDirection  aDir 
) [inline]

Handle keyboard navigation within a menu popup specified by aFrame.

Returns true if the key was handled and other default handling should not occur.

PRBool nsXULPopupManager::HandleKeyboardNavigationInPopup ( nsMenuChainItem aItem,
nsNavigationDirection  aDir 
) [inline, protected]

Handle keyboard navigation within a menu popup specified by aItem.

PRBool nsXULPopupManager::HandleShortcutNavigation ( nsIDOMKeyEvent aKeyEvent,
nsMenuPopupFrame *  aFrame 
)

Handles navigation for menu accelkeys.

Returns true if the key has been handled. 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.

PRBool nsXULPopupManager::HasContextMenu ( nsMenuPopupFrame *  aPopup  ) 

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.

void nsXULPopupManager::HidePopup ( nsIContent *  aPopup,
PRBool  aHideChain,
PRBool  aDeselectMenu,
PRBool  aAsynchronous,
nsIContent *  aLastPopup = 0L 
)
void nsXULPopupManager::HidePopup ( nsIView *  aView  ) 

Hide the popup associated the view aView.

void nsXULPopupManager::HidePopupAfterDelay ( nsMenuPopupFrame *  aPopup  ) 

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 nsXULPopupManager::HidePopupCallback ( nsIContent *  aPopup,
nsMenuPopupFrame *  aPopupFrame,
nsIContent *  aNextPopup,
nsIContent *  aLastPopup,
nsPopupType  aPopupType,
PRBool  aDeselectMenu 
) [protected]
void nsXULPopupManager::HidePopupsInDocShell ( nsIDocShellTreeItem aDocShellToHide  ) 

Hide all of the popups from a given docshell.

This should be called when the document is hidden.

void nsXULPopupManager::HidePopupsInList ( const nsTArray< nsMenuPopupFrame * > &  aFrames,
PRBool  aDeselectMenu 
) [protected]
static nsresult nsXULPopupManager::Init (  )  [static]
void nsXULPopupManager::InitTriggerEvent ( nsIDOMEvent aEvent,
nsIContent *  aPopup,
nsIContent **  aTriggerContent 
) [protected]
PRBool nsXULPopupManager::IsChildOfDocShell ( nsIDocument *  aDoc,
nsIDocShellTreeItem aExpected 
) [protected]
PRBool nsXULPopupManager::IsPopupOpen ( nsIContent *  aPopup  ) 

Return true if the popup for the supplied content node is open.

PRBool nsXULPopupManager::IsPopupOpenForMenuParent ( nsMenuParent *  aMenuParent  ) 

Return true if the popup for the supplied menu parent is open.

static PRBool nsXULPopupManager::IsValidMenuItem ( nsPresContext aPresContext,
nsIContent *  aContent,
PRBool  aOnPopup 
) [static]
virtual nsresult nsXULPopupManager::KeyDown ( nsIDOMEvent aKeyEvent  )  [virtual]
virtual nsresult nsXULPopupManager::KeyPress ( nsIDOMEvent aKeyEvent  )  [virtual]
virtual nsresult nsXULPopupManager::KeyUp ( nsIDOMEvent aKeyEvent  )  [virtual]
void nsXULPopupManager::KillMenuTimer (  ) 

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.

PRBool nsXULPopupManager::MayShowPopup ( nsMenuPopupFrame *  aFrame  ) 

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.

void nsXULPopupManager::PopupDestroyed ( nsMenuPopupFrame *  aFrame  ) 

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 nsXULPopupManager::PopupMoved ( nsIView *  aView,
nsIntPoint  aPoint 
)

Indicate that the popup associated with aView has been moved to the specified screen coordiates.

void nsXULPopupManager::PopupResized ( nsIView *  aView,
nsIntSize  ASize 
)

Indicate that the popup associated with aView has been resized to the specified screen width and height.

NS_DECL_ISUPPORTS virtual NS_DECL_NSITIMERCALLBACK nsresult nsXULPopupManager::Rollup ( PRUint32  aCount,
nsIContent **  aContent 
) [virtual]
void nsXULPopupManager::SetActiveMenuBar ( nsMenuBarFrame *  aMenuBar,
PRBool  aActivate 
)
void nsXULPopupManager::SetCaptureState ( nsIContent *  aOldPopup  )  [protected]

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.

virtual nsresult nsXULPopupManager::ShouldRollupOnMouseActivate ( PRBool aShould  )  [virtual]
virtual nsresult nsXULPopupManager::ShouldRollupOnMouseWheelEvent ( PRBool aShould  )  [virtual]
void nsXULPopupManager::ShowMenu ( nsIContent *  aMenu,
PRBool  aSelectFirstItem,
PRBool  aAsynchronous 
)

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.

void nsXULPopupManager::ShowPopup ( nsIContent *  aPopup,
nsIContent *  aAnchorContent,
const nsAString aPosition,
PRInt32  aXPos,
PRInt32  aYPos,
PRBool  aIsContextMenu,
PRBool  aAttributesOverride,
PRBool  aSelectFirstItem,
nsIDOMEvent aTriggerEvent 
)

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.

aTriggerEvent should be the event that triggered the event. This is used to determine the coordinates and trigger node for the popup. This may be null if the popup was not triggered by an event.

This fires the popupshowing event synchronously.

void nsXULPopupManager::ShowPopupAtScreen ( nsIContent *  aPopup,
PRInt32  aXPos,
PRInt32  aYPos,
PRBool  aIsContextMenu,
nsIDOMEvent aTriggerEvent 
)

Open a popup at a specific screen position specified by aXPos and aYPos, measured in CSS pixels.

This fires the popupshowing event synchronously.

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.

void nsXULPopupManager::ShowPopupCallback ( nsIContent *  aPopup,
nsMenuPopupFrame *  aPopupFrame,
PRBool  aIsContextMenu,
PRBool  aSelectFirstItem 
) [protected]
void nsXULPopupManager::ShowPopupWithAnchorAlign ( nsIContent *  aPopup,
nsIContent *  aAnchorContent,
nsAString aAnchor,
nsAString aAlign,
PRInt32  aXPos,
PRInt32  aYPos,
PRBool  aIsContextMenu 
)

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 nsXULPopupManager::ShowTooltipAtScreen ( nsIContent *  aPopup,
nsIContent *  aTriggerContent,
PRInt32  aXPos,
PRInt32  aYPos 
)

Open a tooltip at a specific screen position specified by aXPos and aYPos, measured in CSS pixels.

This fires the popupshowing event synchronously.

static void nsXULPopupManager::Shutdown (  )  [static]
void nsXULPopupManager::UpdateKeyboardListeners (  )  [protected]

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 nsXULPopupManager::UpdateMenuItems ( nsIContent *  aPopup  ) 

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.


Friends And Related Function Documentation

friend class nsXULMenuCommandEvent [friend]
friend class nsXULPopupHidingEvent [friend]
friend class nsXULPopupShowingEvent [friend]

Member Data Documentation

nsMenuBarFrame* nsXULPopupManager::mActiveMenuBar [protected]
nsCOMPtr<nsIContent> nsXULPopupManager::mOpeningPopup [protected]
PRInt32 nsXULPopupManager::mRangeOffset [protected]
nsMenuPopupFrame* nsXULPopupManager::mTimerMenu [protected]
nsCOMPtr<nsIWidget> nsXULPopupManager::mWidget [protected]

The documentation for this class was generated from the following file: