2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuPopupFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuPopupFrame_h__
|
|
|
|
#define nsMenuPopupFrame_h__
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAtom.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsMenuFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsBoxFrame.h"
|
2008-12-05 08:37:31 -08:00
|
|
|
#include "nsMenuParent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
2009-04-01 14:59:02 -07:00
|
|
|
class nsIWidget;
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
// 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
|
2014-07-14 10:39:04 -07:00
|
|
|
// 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.
|
2007-08-03 07:05:07 -07:00
|
|
|
// 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 open but the widget is not yet visible
|
2014-07-14 10:39:04 -07:00
|
|
|
ePopupOpening,
|
|
|
|
// state while a popup is visible and waiting for the popupshown event
|
|
|
|
ePopupVisible,
|
2007-08-03 07:05:07 -07:00
|
|
|
// state while a popup is open and visible on screen
|
2014-07-14 10:39:04 -07:00
|
|
|
ePopupShown,
|
2007-08-03 07:05:07 -07:00
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2010-10-13 12:41:37 -07:00
|
|
|
// How a popup may be flipped. Flipping to the outside edge is like how
|
|
|
|
// a submenu would work. The entire popup is flipped to the opposite side
|
|
|
|
// of the anchor.
|
|
|
|
enum FlipStyle {
|
|
|
|
FlipStyle_None = 0,
|
|
|
|
FlipStyle_Outside = 1,
|
|
|
|
FlipStyle_Inside = 2
|
|
|
|
};
|
|
|
|
|
2014-01-22 12:09:03 -08:00
|
|
|
// Values for the flip attribute
|
|
|
|
enum FlipType {
|
|
|
|
FlipType_Default = 0,
|
|
|
|
FlipType_None = 1, // don't try to flip or translate to stay onscreen
|
|
|
|
FlipType_Both = 2, // flip in both directions
|
|
|
|
FlipType_Slide = 3 // allow the arrow to "slide" instead of resizing
|
|
|
|
};
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// values are selected so that the direction can be flipped just by
|
|
|
|
// changing the sign
|
|
|
|
#define POPUPALIGNMENT_NONE 0
|
|
|
|
#define POPUPALIGNMENT_TOPLEFT 1
|
|
|
|
#define POPUPALIGNMENT_TOPRIGHT -1
|
|
|
|
#define POPUPALIGNMENT_BOTTOMLEFT 2
|
|
|
|
#define POPUPALIGNMENT_BOTTOMRIGHT -2
|
|
|
|
|
2010-12-05 14:09:36 -08:00
|
|
|
#define POPUPALIGNMENT_LEFTCENTER 16
|
2012-12-18 09:08:08 -08:00
|
|
|
#define POPUPALIGNMENT_RIGHTCENTER -16
|
|
|
|
#define POPUPALIGNMENT_TOPCENTER 17
|
|
|
|
#define POPUPALIGNMENT_BOTTOMCENTER 18
|
2010-12-05 14:09:36 -08:00
|
|
|
|
2013-04-18 17:47:27 -07:00
|
|
|
// The constants here are selected so that horizontally and vertically flipping
|
|
|
|
// can be easily handled using the two flip macros below.
|
|
|
|
#define POPUPPOSITION_UNKNOWN -1
|
|
|
|
#define POPUPPOSITION_BEFORESTART 0
|
|
|
|
#define POPUPPOSITION_BEFOREEND 1
|
|
|
|
#define POPUPPOSITION_AFTERSTART 2
|
|
|
|
#define POPUPPOSITION_AFTEREND 3
|
|
|
|
#define POPUPPOSITION_STARTBEFORE 4
|
|
|
|
#define POPUPPOSITION_ENDBEFORE 5
|
|
|
|
#define POPUPPOSITION_STARTAFTER 6
|
|
|
|
#define POPUPPOSITION_ENDAFTER 7
|
|
|
|
#define POPUPPOSITION_OVERLAP 8
|
|
|
|
#define POPUPPOSITION_AFTERPOINTER 9
|
|
|
|
|
|
|
|
#define POPUPPOSITION_HFLIP(v) (v ^ 1)
|
|
|
|
#define POPUPPOSITION_VFLIP(v) (v ^ 2)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define INC_TYP_INTERVAL 1000 // 1s. If the interval between two keypresses is shorter than this,
|
|
|
|
// treat as a continue typing
|
|
|
|
// XXX, kyle.yuan@sun.com, there are 4 definitions for the same purpose:
|
|
|
|
// nsMenuPopupFrame.h, nsListControlFrame.cpp, listbox.xml, tree.xml
|
|
|
|
// need to find a good place to put them together.
|
|
|
|
// if someone changes one, please also change the other.
|
|
|
|
|
2012-09-14 14:17:08 -07:00
|
|
|
#define CONTEXT_MENU_OFFSET_PIXELS 2
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* NS_NewMenuPopupFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
2013-01-04 19:12:24 -08:00
|
|
|
class nsViewManager;
|
2013-01-03 05:23:11 -08:00
|
|
|
class nsView;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsMenuPopupFrame;
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
// this class is used for dispatching popupshown events asynchronously.
|
|
|
|
class nsXULPopupShownEvent : public nsRunnable, public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXULPopupShownEvent(nsIContent *aPopup, nsPresContext* aPresContext)
|
|
|
|
: mPopup(aPopup), mPresContext(aPresContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
void CancelListener();
|
|
|
|
|
2014-07-08 14:23:18 -07:00
|
|
|
protected:
|
|
|
|
virtual ~nsXULPopupShownEvent() { }
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mPopup;
|
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
|
|
|
};
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class nsMenuPopupFrame MOZ_FINAL : public nsBoxFrame, public nsMenuParent
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-09-27 18:46:11 -07:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsMenuPopupFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuPopupFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
|
|
|
|
2008-12-05 08:37:31 -08:00
|
|
|
// nsMenuParent interface
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual nsMenuFrame* GetCurrentMenuItem() MOZ_OVERRIDE;
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) MOZ_OVERRIDE;
|
|
|
|
virtual void CurrentMenuIsBeingDestroyed() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem) MOZ_OVERRIDE;
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// as popups are opened asynchronously, the popup pending state is used to
|
|
|
|
// prevent multiple requests from attempting to open the same popup twice
|
2007-08-03 07:05:07 -07:00
|
|
|
nsPopupState PopupState() { return mPopupState; }
|
|
|
|
void SetPopupState(nsPopupState aPopupState) { mPopupState = aPopupState; }
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
NS_IMETHOD SetActive(bool aActiveFlag) MOZ_OVERRIDE { return NS_OK; } // We don't care.
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsActive() MOZ_OVERRIDE { return false; }
|
|
|
|
virtual bool IsMenuBar() MOZ_OVERRIDE { return false; }
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When this popup is open, should clicks outside of it be consumed?
|
2011-10-17 07:59:28 -07:00
|
|
|
* Return true if the popup should rollup on an outside click,
|
2007-07-04 08:49:38 -07:00
|
|
|
* but consume that click so it can't be used for anything else.
|
2011-10-17 07:59:28 -07:00
|
|
|
* Return false to allow clicks outside the popup to activate content
|
2007-07-04 08:49:38 -07:00
|
|
|
* even when the popup is open.
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Should clicks outside of a popup be eaten?
|
|
|
|
*
|
|
|
|
* Menus Autocomplete Comboboxes
|
|
|
|
* Mac Eat No Eat
|
|
|
|
* Win No No Eat
|
|
|
|
* Unix Eat No Eat
|
|
|
|
*
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ConsumeOutsideClicks();
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsContextMenu() MOZ_OVERRIDE { return mIsContextMenu; }
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool MenuClosed() MOZ_OVERRIDE { return true; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void LockMenuUntilClosed(bool aLock) MOZ_OVERRIDE;
|
|
|
|
virtual bool IsMenuLocked() MOZ_OVERRIDE { return mIsMenuLocked; }
|
2010-04-19 07:12:58 -07:00
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
nsIWidget* GetWidget();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The dismissal listener gets created and attached to the window.
|
2007-07-04 08:49:38 -07:00
|
|
|
void AttachedDismissalListener();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Overridden methods
|
2014-05-24 15:20:40 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-28 12:18:11 -08:00
|
|
|
// returns true if the popup is a panel with the noautohide attribute set to
|
|
|
|
// true. These panels do not roll up automatically.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsNoAutoHide() const;
|
2007-11-28 12:18:11 -08:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsPopupLevel PopupLevel() const
|
|
|
|
{
|
|
|
|
return PopupLevel(IsNoAutoHide());
|
|
|
|
}
|
2008-09-08 05:58:07 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void EnsureWidget();
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsresult CreateWidgetForView(nsView* aView);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t GetShadowStyle();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2014-05-28 12:36:58 -07:00
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual bool IsLeaf() const MOZ_OVERRIDE;
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2010-05-13 06:42:57 -07:00
|
|
|
// layout, position and display the popup as needed
|
2014-01-28 08:28:45 -08:00
|
|
|
void LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu,
|
|
|
|
nsIFrame* aAnchor, bool aSizedToPopup);
|
2010-05-13 06:42:57 -07:00
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* GetRootViewForPopup(nsIFrame* aStartFrame);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// set the position of the popup either relative to the anchor aAnchorFrame
|
|
|
|
// (or the frame for mAnchorContent if aAnchorFrame is null) or at a specific
|
|
|
|
// point if a screen position (mScreenXPos and mScreenYPos) are set. The popup
|
2010-02-01 07:11:08 -08:00
|
|
|
// will be adjusted so that it is on screen. If aIsMove is true, then the popup
|
|
|
|
// is being moved, and should not be flipped.
|
2014-01-28 08:28:45 -08:00
|
|
|
nsresult SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove, bool aSizedToPopup);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasGeneratedChildren() { return mGeneratedChildren; }
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetGeneratedChildren() { mGeneratedChildren = true; }
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// called when the Enter key is pressed while the popup is open. This will
|
2007-11-17 07:47:38 -08:00
|
|
|
// just pass the call down to the current menu, if any. If a current menu
|
|
|
|
// should be opened as a result, this method should return the frame for
|
|
|
|
// that menu, or null if no menu should be opened. Also, calling Enter will
|
|
|
|
// reset the current incremental search string, calculated in
|
|
|
|
// FindMenuWithShortcut.
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-08-15 18:09:58 -07:00
|
|
|
nsPopupType PopupType() const { return mPopupType; }
|
2013-05-14 09:33:23 -07:00
|
|
|
bool IsMenu() MOZ_OVERRIDE { return mPopupType == ePopupTypeMenu; }
|
2014-07-14 10:39:04 -07:00
|
|
|
bool IsOpen() MOZ_OVERRIDE { return mPopupState == ePopupOpening ||
|
|
|
|
mPopupState == ePopupVisible ||
|
|
|
|
mPopupState == ePopupShown; }
|
|
|
|
bool IsVisible() { return mPopupState == ePopupVisible ||
|
|
|
|
mPopupState == ePopupShown; }
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2014-01-31 05:27:43 -08:00
|
|
|
bool IsMouseTransparent() { return mMouseTransparent; }
|
2011-04-25 18:37:20 -07:00
|
|
|
|
2010-09-10 13:24:25 -07:00
|
|
|
static nsIContent* GetTriggerContent(nsMenuPopupFrame* aMenuPopupFrame);
|
2012-07-30 07:20:58 -07:00
|
|
|
void ClearTriggerContent() { mTriggerContent = nullptr; }
|
2010-08-09 09:17:19 -07:00
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
// returns true if the popup is in a content shell, or false for a popup in
|
|
|
|
// a chrome shell
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsInContentShell() { return mInContentShell; }
|
2007-08-03 07:05:07 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// the Initialize methods are used to set the anchor position for
|
|
|
|
// each way of opening a popup.
|
|
|
|
void InitializePopup(nsIContent* aAnchorContent,
|
2010-08-09 09:17:19 -07:00
|
|
|
nsIContent* aTriggerContent,
|
2007-07-04 08:49:38 -07:00
|
|
|
const nsAString& aPosition,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAttributesOverride);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2008-04-23 14:25:34 -07:00
|
|
|
/**
|
|
|
|
* @param aIsContextMenu if true, then the popup is
|
|
|
|
* positioned at a slight offset from aXPos/aYPos to ensure the
|
|
|
|
* (presumed) mouse position is not over the menu.
|
|
|
|
*/
|
2010-08-09 09:17:19 -07:00
|
|
|
void InitializePopupAtScreen(nsIContent* aTriggerContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsContextMenu);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
void InitializePopupWithAnchorAlign(nsIContent* aAnchorContent,
|
|
|
|
nsAString& aAnchor,
|
|
|
|
nsAString& aAlign,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// indicate that the popup should be opened
|
2011-09-28 23:19:26 -07:00
|
|
|
void ShowPopup(bool aIsContextMenu, bool aSelectFirstItem);
|
2007-08-03 07:05:07 -07:00
|
|
|
// indicate that the popup should be hidden. The new state should either be
|
|
|
|
// ePopupClosed or ePopupInvisible.
|
2011-09-28 23:19:26 -07:00
|
|
|
void HidePopup(bool aDeselectMenu, nsPopupState aNewState);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// locate and return the menu frame that should be activated for the
|
|
|
|
// supplied key event. If doAction is set to true by this method,
|
|
|
|
// then the menu's action should be carried out, as if the user had pressed
|
|
|
|
// the Enter key. If doAction is false, the menu should just be highlighted.
|
|
|
|
// This method also handles incremental searching in menus so the user can
|
|
|
|
// type the first few letters of an item/s name to select it.
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool& doAction);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
void ClearIncrementalString() { mIncrementalString.Truncate(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE { return nsGkAtoms::menuPopupFrame; }
|
2007-04-20 03:56:49 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("MenuPopup"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void EnsureMenuItemIsVisible(nsMenuFrame* aMenuFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
// Move the popup to the screen coordinate (aLeft, aTop) in CSS pixels.
|
|
|
|
// If aUpdateAttrs is true, and the popup already has left or top attributes,
|
|
|
|
// then those attributes are updated to the new location.
|
2009-02-17 07:51:11 -08:00
|
|
|
// The frame may be destroyed by this method.
|
2012-08-22 08:56:38 -07:00
|
|
|
void MoveTo(int32_t aLeft, int32_t aTop, bool aUpdateAttrs);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-23 05:11:13 -07:00
|
|
|
void MoveToAnchor(nsIContent* aAnchorContent,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
bool aAttributesOverride);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetAutoPosition();
|
|
|
|
void SetAutoPosition(bool aShouldAutoPosition);
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetConsumeRollupEvent(uint32_t aConsumeMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-01 04:22:31 -07:00
|
|
|
nsIScrollableFrame* GetScrollFrame(nsIFrame* aStart);
|
2007-12-19 08:37:32 -08:00
|
|
|
|
2010-08-02 08:06:04 -07:00
|
|
|
// For a popup that should appear anchored at the given rect, determine
|
2009-12-23 10:45:44 -08:00
|
|
|
// the screen area that it is constrained by. This will be the available
|
|
|
|
// area of the screen the popup should be displayed on. Content popups,
|
|
|
|
// however, will also be constrained by the content area, given by
|
|
|
|
// aRootScreenRect. All coordinates are in app units.
|
2014-02-07 09:35:09 -08:00
|
|
|
// For non-toplevel popups (which will always be panels), we will also
|
|
|
|
// constrain them to the available screen rect, ie they will not fall
|
|
|
|
// underneath the taskbar, dock or other fixed OS elements.
|
|
|
|
nsRect GetConstraintRect(const nsRect& aAnchorRect, const nsRect& aRootScreenRect,
|
|
|
|
nsPopupLevel aPopupLevel);
|
2009-12-23 10:45:44 -08:00
|
|
|
|
|
|
|
// Determines whether the given edges of the popup may be moved, where
|
|
|
|
// aHorizontalSide and aVerticalSide are one of the NS_SIDE_* constants, or
|
|
|
|
// 0 for no movement in that direction. aChange is the distance to move on
|
|
|
|
// those sides. If will be reset to 0 if the side cannot be adjusted at all
|
|
|
|
// in that direction. For example, a popup cannot be moved if it is anchored
|
|
|
|
// on a particular side.
|
|
|
|
//
|
|
|
|
// Later, when bug 357725 is implemented, we can make this adjust aChange by
|
|
|
|
// the amount that the side can be resized, so that minimums and maximums
|
|
|
|
// can be taken into account.
|
2012-08-22 08:56:38 -07:00
|
|
|
void CanAdjustEdges(int8_t aHorizontalSide, int8_t aVerticalSide, nsIntPoint& aChange);
|
2009-12-23 10:45:44 -08:00
|
|
|
|
2010-07-27 06:38:02 -07:00
|
|
|
// Return true if the popup is positioned relative to an anchor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsAnchored() const { return mScreenXPos == -1 && mScreenYPos == -1; }
|
2010-07-27 06:38:02 -07:00
|
|
|
|
2010-09-21 10:53:01 -07:00
|
|
|
// Return the anchor if there is one.
|
|
|
|
nsIContent* GetAnchor() const { return mAnchorContent; }
|
|
|
|
|
2010-07-27 06:38:02 -07:00
|
|
|
// Return the screen coordinates of the popup, or (-1, -1) if anchored.
|
2012-09-29 04:36:09 -07:00
|
|
|
// This position is in CSS pixels.
|
2010-07-27 06:38:02 -07:00
|
|
|
nsIntPoint ScreenPosition() const { return nsIntPoint(mScreenXPos, mScreenYPos); }
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
nsIntPoint GetLastClientOffset() const { return mLastClientOffset; }
|
|
|
|
|
2013-04-18 17:47:27 -07:00
|
|
|
// Return the alignment of the popup
|
|
|
|
int8_t GetAlignmentPosition() const;
|
|
|
|
|
2013-05-08 15:59:03 -07:00
|
|
|
// Return the offset applied to the alignment of the popup
|
|
|
|
nscoord GetAlignmentOffset() const { return mAlignmentOffset; }
|
2014-06-16 11:43:07 -07:00
|
|
|
|
|
|
|
// Clear the mPopupShownDispatcher, remove the listener and return true if
|
|
|
|
// mPopupShownDispatcher was non-null.
|
|
|
|
bool ClearPopupShownDispatcher()
|
|
|
|
{
|
|
|
|
if (mPopupShownDispatcher) {
|
|
|
|
mPopupShownDispatcher->CancelListener();
|
|
|
|
mPopupShownDispatcher = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// returns the popup's level.
|
2011-09-28 23:19:26 -07:00
|
|
|
nsPopupLevel PopupLevel(bool aIsNoAutoHide) const;
|
2010-07-27 06:38:03 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// redefine to tell the box system not to move the views.
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual void GetLayoutFlags(uint32_t& aFlags) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void InitPositionFromAnchorAlign(const nsAString& aAnchor,
|
|
|
|
const nsAString& aAlign);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// return the position where the popup should be, when it should be
|
|
|
|
// anchored at anchorRect. aHFlip and aVFlip will be set if the popup may be
|
|
|
|
// flipped in that direction if there is not enough space available.
|
2010-12-05 14:09:36 -08:00
|
|
|
nsPoint AdjustPositionForAnchorAlign(nsRect& anchorRect,
|
2010-10-13 12:41:37 -07:00
|
|
|
FlipStyle& aHFlip, FlipStyle& aVFlip);
|
2008-12-10 07:19:16 -08:00
|
|
|
|
|
|
|
// check if the popup will fit into the available space and resize it. This
|
|
|
|
// method handles only one axis at a time so is called twice, once for
|
|
|
|
// horizontal and once for vertical. All arguments are specified for this
|
|
|
|
// one axis. All coordinates are in app units relative to the screen.
|
|
|
|
// aScreenPoint - the point where the popup should appear
|
|
|
|
// aSize - the size of the popup
|
|
|
|
// aScreenBegin - the left or top edge of the screen
|
|
|
|
// aScreenEnd - the right or bottom edge of the screen
|
|
|
|
// aAnchorBegin - the left or top edge of the anchor rectangle
|
|
|
|
// aAnchorEnd - the right or bottom edge of the anchor rectangle
|
|
|
|
// aMarginBegin - the left or top margin of the popup
|
|
|
|
// aMarginEnd - the right or bottom margin of the popup
|
|
|
|
// aOffsetForContextMenu - the additional offset to add for context menus
|
2010-10-13 12:41:37 -07:00
|
|
|
// aFlip - how to flip or resize the popup when there isn't space
|
2009-12-23 10:45:44 -08:00
|
|
|
// aFlipSide - pointer to where current flip mode is stored
|
2008-12-10 07:19:16 -08:00
|
|
|
nscoord FlipOrResize(nscoord& aScreenPoint, nscoord aSize,
|
|
|
|
nscoord aScreenBegin, nscoord aScreenEnd,
|
|
|
|
nscoord aAnchorBegin, nscoord aAnchorEnd,
|
|
|
|
nscoord aMarginBegin, nscoord aMarginEnd,
|
2010-10-13 12:41:37 -07:00
|
|
|
nscoord aOffsetForContextMenu, FlipStyle aFlip,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aFlipSide);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-08 15:59:03 -07:00
|
|
|
// check if the popup can fit into the available space by "sliding" (i.e.,
|
|
|
|
// by having the anchor arrow slide along one axis and only resizing if that
|
|
|
|
// can't provide the requested size). Only one axis can be slid - the other
|
|
|
|
// axis is "flipped" as normal. This method can handle either axis, but is
|
|
|
|
// only called for the sliding axis. All coordinates are in app units
|
|
|
|
// relative to the screen.
|
|
|
|
// aScreenPoint - the point where the popup should appear
|
|
|
|
// aSize - the size of the popup
|
|
|
|
// aScreenBegin - the left or top edge of the screen
|
|
|
|
// aScreenEnd - the right or bottom edge of the screen
|
|
|
|
// aOffset - the amount by which the arrow must be slid such that it is
|
|
|
|
// still aligned with the anchor.
|
|
|
|
// Result is the new size of the popup, which will typically be the same
|
|
|
|
// as aSize, unless aSize is greater than the screen width/height.
|
|
|
|
nscoord SlideOrResize(nscoord& aScreenPoint, nscoord aSize,
|
|
|
|
nscoord aScreenBegin, nscoord aScreenEnd,
|
|
|
|
nscoord *aOffset);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Move the popup to the position specified in its |left| and |top| attributes.
|
|
|
|
void MoveToAttributePosition();
|
|
|
|
|
2011-01-13 06:02:20 -08:00
|
|
|
/**
|
|
|
|
* Return whether the popup direction should be RTL.
|
|
|
|
* If the popup has an anchor, its direction is the anchor direction.
|
|
|
|
* Otherwise, its the general direction of the UI.
|
|
|
|
*
|
|
|
|
* Return whether the popup direction should be RTL.
|
|
|
|
*/
|
|
|
|
bool IsDirectionRTL() const {
|
|
|
|
return mAnchorContent && mAnchorContent->GetPrimaryFrame()
|
2013-02-16 13:51:02 -08:00
|
|
|
? mAnchorContent->GetPrimaryFrame()->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL
|
|
|
|
: StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
|
2011-01-13 06:02:20 -08:00
|
|
|
}
|
|
|
|
|
2011-04-29 06:51:05 -07:00
|
|
|
// Create a popup view for this frame. The view is added a child of the root
|
|
|
|
// view, and is initially hidden.
|
2013-03-19 18:47:48 -07:00
|
|
|
void CreatePopupView();
|
2011-04-29 06:51:05 -07:00
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
nsString mIncrementalString; // for incremental typing navigation
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// the content that the popup is anchored to, if any, which may be in a
|
|
|
|
// different document than the popup.
|
|
|
|
nsCOMPtr<nsIContent> mAnchorContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-09 09:17:19 -07:00
|
|
|
// the content that triggered the popup, typically the node where the mouse
|
|
|
|
// was clicked. It will be cleared when the popup is hidden.
|
|
|
|
nsCOMPtr<nsIContent> mTriggerContent;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame* mCurrentMenu; // The current menu that is active.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
nsRefPtr<nsXULPopupShownEvent> mPopupShownDispatcher;
|
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// A popup's preferred size may be different than its actual size stored in
|
|
|
|
// mRect in the case where the popup was resized because it was too large
|
|
|
|
// for the screen. The preferred size mPrefSize holds the full size the popup
|
|
|
|
// would be before resizing. Computations are performed using this size.
|
|
|
|
nsSize mPrefSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
// The position of the popup, in CSS pixels.
|
|
|
|
// The screen coordinates, if set to values other than -1,
|
|
|
|
// override mXPos and mYPos.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mXPos;
|
|
|
|
int32_t mYPos;
|
|
|
|
int32_t mScreenXPos;
|
|
|
|
int32_t mScreenYPos;
|
2013-05-08 15:59:03 -07:00
|
|
|
|
|
|
|
// If the panel prefers to "slide" rather than resize, then the arrow gets
|
|
|
|
// positioned at this offset (along either the x or y axis, depending on
|
|
|
|
// mPosition)
|
|
|
|
nscoord mAlignmentOffset;
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
// The value of the client offset of our widget the last time we positioned
|
|
|
|
// ourselves. We store this so that we can detect when it changes but the
|
|
|
|
// position of our widget didn't change.
|
|
|
|
nsIntPoint mLastClientOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsPopupType mPopupType; // type of popup
|
2007-08-03 07:05:07 -07:00
|
|
|
nsPopupState mPopupState; // open state of the popup
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// popup alignment relative to the anchor node
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t mPopupAlignment;
|
|
|
|
int8_t mPopupAnchor;
|
2013-04-18 17:47:27 -07:00
|
|
|
int8_t mPosition;
|
|
|
|
|
2011-07-26 23:43:37 -07:00
|
|
|
// One of nsIPopupBoxObject::ROLLUP_DEFAULT/ROLLUP_CONSUME/ROLLUP_NO_CONSUME
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t mConsumeRollupEvent;
|
2014-01-22 12:09:03 -08:00
|
|
|
FlipType mFlip; // Whether to flip
|
2009-05-12 03:13:09 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsOpenChanged; // true if the open state changed since the last layout
|
|
|
|
bool mIsContextMenu; // true for context menus
|
2008-04-23 14:25:34 -07:00
|
|
|
// true if we need to offset the popup to ensure it's not under the mouse
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAdjustOffsetForContextMenu;
|
|
|
|
bool mGeneratedChildren; // true if the contents have been created
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mMenuCanOverlapOSBar; // can we appear over the taskbar/menubar?
|
|
|
|
bool mShouldAutoPosition; // Should SetPopupPosition be allowed to auto position popup?
|
|
|
|
bool mInContentShell; // True if the popup is in a content shell
|
|
|
|
bool mIsMenuLocked; // Should events inside this menu be ignored?
|
2014-01-31 05:27:43 -08:00
|
|
|
bool mMouseTransparent; // True if this is a popup is transparent to mouse events
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-23 10:45:44 -08:00
|
|
|
// the flip modes that were used when the popup was opened
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHFlip;
|
|
|
|
bool mVFlip;
|
2009-12-23 10:45:44 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int8_t sDefaultLevelIsTop;
|
2007-03-22 10:30:00 -07:00
|
|
|
}; // class nsMenuPopupFrame
|
|
|
|
|
|
|
|
#endif
|