2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
1999-07-18 10:35:03 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuPopupFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuPopupFrame_h__
|
|
|
|
#define nsMenuPopupFrame_h__
|
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-01-24 13:41:56 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
2020-05-19 23:56:06 +03:00
|
|
|
#include "mozilla/StaticPrefs_ui.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsGkAtoms.h"
|
1999-07-18 10:35:03 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsMenuFrame.h"
|
1999-07-18 10:35:03 +04:00
|
|
|
|
1999-07-21 06:56:23 +04:00
|
|
|
#include "nsBoxFrame.h"
|
2008-12-05 19:37:31 +03:00
|
|
|
#include "nsMenuParent.h"
|
1999-07-18 10:35:03 +04:00
|
|
|
|
2015-09-29 03:17:34 +03:00
|
|
|
#include "Units.h"
|
|
|
|
|
2009-04-02 01:59:02 +04:00
|
|
|
class nsIWidget;
|
|
|
|
|
2018-02-09 19:17:09 +03:00
|
|
|
namespace mozilla {
|
2019-04-16 10:24:49 +03:00
|
|
|
class PresShell;
|
2018-02-09 19:17:09 +03:00
|
|
|
namespace dom {
|
|
|
|
class KeyboardEvent;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-01-10 05:12:10 +03:00
|
|
|
enum ConsumeOutsideClicksResult {
|
|
|
|
ConsumeOutsideClicks_ParentOnly =
|
|
|
|
0, // Only consume clicks on the parent anchor
|
|
|
|
ConsumeOutsideClicks_True = 1, // Always consume clicks
|
|
|
|
ConsumeOutsideClicks_Never = 2 // Never consume clicks
|
|
|
|
};
|
|
|
|
|
2010-10-13 23:41:37 +04: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-23 00:09:03 +04: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
|
|
|
|
};
|
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
enum MenuPopupAnchorType {
|
|
|
|
MenuPopupAnchorType_Node = 0, // anchored to a node
|
|
|
|
MenuPopupAnchorType_Point = 1, // unanchored and positioned at a screen point
|
|
|
|
MenuPopupAnchorType_Rect = 2, // anchored at a screen rectangle
|
|
|
|
};
|
|
|
|
|
2007-07-04 19:49:38 +04: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-06 01:09:36 +03:00
|
|
|
#define POPUPALIGNMENT_LEFTCENTER 16
|
2012-12-18 21:08:08 +04:00
|
|
|
#define POPUPALIGNMENT_RIGHTCENTER -16
|
|
|
|
#define POPUPALIGNMENT_TOPCENTER 17
|
|
|
|
#define POPUPALIGNMENT_BOTTOMCENTER 18
|
2010-12-06 01:09:36 +03:00
|
|
|
|
2013-04-19 04:47:27 +04: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
|
2016-08-11 17:37:25 +03:00
|
|
|
#define POPUPPOSITION_SELECTION 10
|
2013-04-19 04:47:27 +04:00
|
|
|
|
|
|
|
#define POPUPPOSITION_HFLIP(v) (v ^ 1)
|
|
|
|
#define POPUPPOSITION_VFLIP(v) (v ^ 2)
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewMenuPopupFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
mozilla::ComputedStyle* aStyle);
|
1999-07-18 10:35:03 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
class nsView;
|
2006-03-15 01:48:09 +03:00
|
|
|
class nsMenuPopupFrame;
|
|
|
|
|
2014-06-16 22:43:07 +04:00
|
|
|
// this class is used for dispatching popupshown events asynchronously.
|
2018-09-06 04:23:14 +03:00
|
|
|
class nsXULPopupShownEvent final : public mozilla::Runnable,
|
|
|
|
public nsIDOMEventListener {
|
2014-06-16 22:43:07 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsXULPopupShownEvent(nsIContent* aPopup, nsPresContext* aPresContext)
|
|
|
|
: mozilla::Runnable("nsXULPopupShownEvent"),
|
|
|
|
mPopup(aPopup),
|
|
|
|
mPresContext(aPresContext) {}
|
2014-06-16 22:43:07 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
void CancelListener();
|
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
protected:
|
2020-03-17 12:38:32 +03:00
|
|
|
virtual ~nsXULPopupShownEvent() = default;
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2014-06-16 22:43:07 +04:00
|
|
|
private:
|
2021-12-23 19:27:23 +03:00
|
|
|
const nsCOMPtr<nsIContent> mPopup;
|
|
|
|
const RefPtr<nsPresContext> mPresContext;
|
2014-06-16 22:43:07 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsMenuPopupFrame final : public nsBoxFrame,
|
|
|
|
public nsMenuParent,
|
2021-03-31 20:41:55 +03:00
|
|
|
public nsIReflowCallback {
|
1999-07-18 10:35:03 +04:00
|
|
|
public:
|
2011-09-28 05:46:11 +04:00
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsMenuPopupFrame)
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsMenuPopupFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
|
Bug 1698997 - Make nsXULPopupManager::ShowPopupAtScreen open a native context menu, if preffed on. r=tnikkel
This is macOS only and behind the prefs widget.macos.native-context-menus and
browser.proton.contextmenus.enabled .
The big design question here is: Where do we put the fork in the road? How much
should the existing non-native popup management machinery know about the state
of the native menu? Which parts of the non-native state should a) reflect the
true native state, b) enter a special "handled natively" state, or c) lie?
This patch picks the following approach:
- The nsMenuPopupFrame of the root menupopup knows about the native menu; it
keeps it alive in its new mNativeMenu field.
- If the context menu has submenus, i.e. nested <menupopup> elements, the
nsMenuPopupFrames for those nested menupopups do not know anything about the
native menu.
- The mPopupState of natively-handled nsMenuPopupFrames is ePopupClosed.
- XULPopupElement::GetState, which queries the frame's mPopupState, also
returns "closed". This might cause problems in the future.
- The XUL popup manager's mPopups "menu chain" does not know about any open
native menus.
- The rollup widget also does not know about the native popup.
I've chosen to use ePopupClosed for native menus for the following reasons:
1. While mirroring / updating the state for the root menu would be doable
without too much trouble, it would be much more annoying to do the same for
nested menupopups of submenus. So if submenus will be ePopupClosed, it's
consistent for the root menu to also be ePopupClosed.
2. nsXULPopupManager has assertions (for example in MayShowPopup) that make
sure that the menu popup frame's mPopupState is consistent with the XUL
popup manager's mPopups menu chain. Keeping the two both "closed" is the
easiest way to achieve consistency.
Unless there are grave concerns with this approach, I suggest we go with it for
now and see what trouble arises.
Differential Revision: https://phabricator.services.mozilla.com/D109183
2021-03-23 17:38:29 +03:00
|
|
|
~nsMenuPopupFrame();
|
1999-07-18 10:35:03 +04:00
|
|
|
|
2008-12-05 19:37:31 +03:00
|
|
|
// nsMenuParent interface
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsMenuFrame* GetCurrentMenuItem() override;
|
2019-05-06 16:57:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) override;
|
|
|
|
virtual void CurrentMenuIsBeingDestroyed() override;
|
2019-04-30 04:35:30 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2015-06-26 19:32:25 +03:00
|
|
|
NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem,
|
|
|
|
bool aFromKey) override;
|
2007-06-30 02:15:59 +04:00
|
|
|
|
2007-07-04 19:49:38 +04: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 18:05:07 +04:00
|
|
|
nsPopupState PopupState() { return mPopupState; }
|
2021-08-23 15:10:43 +03:00
|
|
|
void SetPopupState(nsPopupState);
|
2007-06-30 02:15:59 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetActive(bool aActiveFlag) override {
|
|
|
|
// We don't care.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
virtual bool IsActive() override { return false; }
|
|
|
|
virtual bool IsMenuBar() override { return false; }
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When this popup is open, should clicks outside of it be consumed?
|
2011-10-17 18:59:28 +04:00
|
|
|
* Return true if the popup should rollup on an outside click,
|
2007-07-04 19:49:38 +04:00
|
|
|
* but consume that click so it can't be used for anything else.
|
2011-10-17 18:59:28 +04:00
|
|
|
* Return false to allow clicks outside the popup to activate content
|
2007-07-04 19:49:38 +04: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
|
|
|
|
*
|
|
|
|
*/
|
2015-01-10 05:12:10 +03:00
|
|
|
ConsumeOutsideClicksResult ConsumeOutsideClicks();
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2022-03-04 14:45:41 +03:00
|
|
|
bool IsContextMenu() override { return mIsContextMenu; }
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2022-03-04 14:45:41 +03:00
|
|
|
bool MenuClosed() override { return true; }
|
2000-02-09 12:34:35 +03:00
|
|
|
|
2022-03-04 14:45:41 +03:00
|
|
|
void LockMenuUntilClosed(bool aLock) override;
|
|
|
|
bool IsMenuLocked() override { return mIsMenuLocked; }
|
2010-04-19 18:12:58 +04:00
|
|
|
|
2011-12-02 01:35:42 +04:00
|
|
|
nsIWidget* GetWidget();
|
1999-09-25 07:39:35 +04:00
|
|
|
|
1999-07-21 11:42:16 +04:00
|
|
|
// Overridden methods
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2001-09-10 11:34:54 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) override;
|
1999-07-20 11:28:39 +04:00
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) override;
|
1999-09-10 12:47:12 +04:00
|
|
|
|
2017-05-17 20:16:25 +03:00
|
|
|
bool HasRemoteContent() const;
|
|
|
|
|
2021-12-23 15:55:34 +03:00
|
|
|
// Whether we should create a widget on Init().
|
|
|
|
bool ShouldCreateWidgetUpfront() const;
|
|
|
|
|
|
|
|
// Returns true if the popup is a panel with the noautohide attribute set to
|
2007-11-28 23:18:11 +03:00
|
|
|
// true. These panels do not roll up automatically.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsNoAutoHide() const;
|
2007-11-28 23:18:11 +03:00
|
|
|
|
2010-07-27 17:38:03 +04:00
|
|
|
nsPopupLevel PopupLevel() const { return PopupLevel(IsNoAutoHide()); }
|
2008-09-08 16:58:07 +04:00
|
|
|
|
2017-05-17 20:16:25 +03:00
|
|
|
// Ensure that a widget has already been created for this view, and create
|
|
|
|
// one if it hasn't. If aRecreate is true, destroys any existing widget and
|
|
|
|
// creates a new one, regardless of whether one has already been created.
|
|
|
|
void EnsureWidget(bool aRecreate = false);
|
2007-06-30 02:15:59 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult CreateWidgetForView(nsView* aView);
|
2019-11-25 19:00:23 +03:00
|
|
|
mozilla::StyleWindowShadow GetShadowStyle();
|
1999-07-26 05:35:39 +04:00
|
|
|
|
2019-11-20 05:37:06 +03:00
|
|
|
void DidSetComputedStyle(ComputedStyle* aOldStyle) override;
|
2017-06-16 22:08:30 +03:00
|
|
|
|
2010-05-13 17:42:57 +04:00
|
|
|
// layout, position and display the popup as needed
|
2019-05-06 16:57:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2014-01-28 20:28:45 +04:00
|
|
|
void LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu,
|
2019-05-14 23:08:53 +03:00
|
|
|
bool aSizedToPopup);
|
2010-05-13 17:42:57 +04:00
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
// Set the position of the popup either relative to the anchor aAnchorFrame
|
|
|
|
// (or the frame for mAnchorContent if aAnchorFrame is null), anchored at a
|
|
|
|
// rectangle, or at a specific point if a screen position is set. The popup
|
|
|
|
// will be adjusted so that it is on screen. If aIsMove is true, then the
|
2020-10-06 19:28:33 +03:00
|
|
|
// popup is being moved, and should not be flipped.
|
2016-08-17 01:33:05 +03:00
|
|
|
nsresult SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove,
|
2020-10-06 19:28:33 +03:00
|
|
|
bool aSizedToPopup);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// called when the Enter key is pressed while the popup is open. This will
|
2007-11-17 18:47:38 +03: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-02 07:46:03 +04:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2007-08-16 05:09:58 +04:00
|
|
|
nsPopupType PopupType() const { return mPopupType; }
|
2015-03-21 19:28:04 +03:00
|
|
|
bool IsMenu() override { return mPopupType == ePopupTypeMenu; }
|
|
|
|
bool IsOpen() override {
|
|
|
|
return mPopupState == ePopupOpening || mPopupState == ePopupVisible ||
|
2014-07-14 21:39:04 +04:00
|
|
|
mPopupState == ePopupShown;
|
|
|
|
}
|
|
|
|
bool IsVisible() {
|
|
|
|
return mPopupState == ePopupVisible || mPopupState == ePopupShown;
|
|
|
|
}
|
2021-05-31 16:07:35 +03:00
|
|
|
bool IsVisibleOrShowing() {
|
|
|
|
return IsOpen() || mPopupState == ePopupPositioning ||
|
|
|
|
mPopupState == ePopupShowing;
|
|
|
|
}
|
2022-03-04 14:45:41 +03:00
|
|
|
bool IsNativeMenu() const { return mIsNativeMenu; }
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2016-08-11 17:36:20 +03:00
|
|
|
// Return true if the popup is for a menulist.
|
|
|
|
bool IsMenuList();
|
|
|
|
|
2021-09-01 22:24:39 +03:00
|
|
|
bool IsMouseTransparent(const ComputedStyle&) const;
|
|
|
|
bool IsMouseTransparent() const { return IsMouseTransparent(*Style()); }
|
2011-04-26 05:37:20 +04:00
|
|
|
|
2010-09-11 00:24:25 +04:00
|
|
|
static nsIContent* GetTriggerContent(nsMenuPopupFrame* aMenuPopupFrame);
|
2012-07-30 18:20:58 +04:00
|
|
|
void ClearTriggerContent() { mTriggerContent = nullptr; }
|
2021-03-31 20:41:56 +03:00
|
|
|
void ClearTriggerContentIncludingDocument();
|
2010-08-09 20:17:19 +04:00
|
|
|
|
2007-08-03 18:05:07 +04:00
|
|
|
// returns true if the popup is in a content shell, or false for a popup in
|
|
|
|
// a chrome shell
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInContentShell() { return mInContentShell; }
|
2007-08-03 18:05:07 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// the Initialize methods are used to set the anchor position for
|
|
|
|
// each way of opening a popup.
|
|
|
|
void InitializePopup(nsIContent* aAnchorContent, nsIContent* aTriggerContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
const nsAString& aPosition, int32_t aXPos, int32_t aYPos,
|
2015-05-08 21:49:54 +03:00
|
|
|
MenuPopupAnchorType aAnchorType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAttributesOverride);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
void InitializePopupAtRect(nsIContent* aTriggerContent,
|
|
|
|
const nsAString& aPosition, const nsIntRect& aRect,
|
|
|
|
bool aAttributesOverride);
|
|
|
|
|
2008-04-24 01:25:34 +04: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 20:17:19 +04:00
|
|
|
void InitializePopupAtScreen(nsIContent* aTriggerContent, int32_t aXPos,
|
2011-09-29 10:19:26 +04:00
|
|
|
int32_t aYPos, bool aIsContextMenu);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
Bug 1698997 - Make nsXULPopupManager::ShowPopupAtScreen open a native context menu, if preffed on. r=tnikkel
This is macOS only and behind the prefs widget.macos.native-context-menus and
browser.proton.contextmenus.enabled .
The big design question here is: Where do we put the fork in the road? How much
should the existing non-native popup management machinery know about the state
of the native menu? Which parts of the non-native state should a) reflect the
true native state, b) enter a special "handled natively" state, or c) lie?
This patch picks the following approach:
- The nsMenuPopupFrame of the root menupopup knows about the native menu; it
keeps it alive in its new mNativeMenu field.
- If the context menu has submenus, i.e. nested <menupopup> elements, the
nsMenuPopupFrames for those nested menupopups do not know anything about the
native menu.
- The mPopupState of natively-handled nsMenuPopupFrames is ePopupClosed.
- XULPopupElement::GetState, which queries the frame's mPopupState, also
returns "closed". This might cause problems in the future.
- The XUL popup manager's mPopups "menu chain" does not know about any open
native menus.
- The rollup widget also does not know about the native popup.
I've chosen to use ePopupClosed for native menus for the following reasons:
1. While mirroring / updating the state for the root menu would be doable
without too much trouble, it would be much more annoying to do the same for
nested menupopups of submenus. So if submenus will be ePopupClosed, it's
consistent for the root menu to also be ePopupClosed.
2. nsXULPopupManager has assertions (for example in MayShowPopup) that make
sure that the menu popup frame's mPopupState is consistent with the XUL
popup manager's mPopups menu chain. Keeping the two both "closed" is the
easiest way to achieve consistency.
Unless there are grave concerns with this approach, I suggest we go with it for
now and see what trouble arises.
Differential Revision: https://phabricator.services.mozilla.com/D109183
2021-03-23 17:38:29 +03:00
|
|
|
// Called if this popup should be displayed as an OS-native context menu.
|
2021-03-31 20:41:55 +03:00
|
|
|
void InitializePopupAsNativeContextMenu(nsIContent* aTriggerContent,
|
Bug 1698997 - Make nsXULPopupManager::ShowPopupAtScreen open a native context menu, if preffed on. r=tnikkel
This is macOS only and behind the prefs widget.macos.native-context-menus and
browser.proton.contextmenus.enabled .
The big design question here is: Where do we put the fork in the road? How much
should the existing non-native popup management machinery know about the state
of the native menu? Which parts of the non-native state should a) reflect the
true native state, b) enter a special "handled natively" state, or c) lie?
This patch picks the following approach:
- The nsMenuPopupFrame of the root menupopup knows about the native menu; it
keeps it alive in its new mNativeMenu field.
- If the context menu has submenus, i.e. nested <menupopup> elements, the
nsMenuPopupFrames for those nested menupopups do not know anything about the
native menu.
- The mPopupState of natively-handled nsMenuPopupFrames is ePopupClosed.
- XULPopupElement::GetState, which queries the frame's mPopupState, also
returns "closed". This might cause problems in the future.
- The XUL popup manager's mPopups "menu chain" does not know about any open
native menus.
- The rollup widget also does not know about the native popup.
I've chosen to use ePopupClosed for native menus for the following reasons:
1. While mirroring / updating the state for the root menu would be doable
without too much trouble, it would be much more annoying to do the same for
nested menupopups of submenus. So if submenus will be ePopupClosed, it's
consistent for the root menu to also be ePopupClosed.
2. nsXULPopupManager has assertions (for example in MayShowPopup) that make
sure that the menu popup frame's mPopupState is consistent with the XUL
popup manager's mPopups menu chain. Keeping the two both "closed" is the
easiest way to achieve consistency.
Unless there are grave concerns with this approach, I suggest we go with it for
now and see what trouble arises.
Differential Revision: https://phabricator.services.mozilla.com/D109183
2021-03-23 17:38:29 +03:00
|
|
|
int32_t aXPos, int32_t aYPos);
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// indicate that the popup should be opened
|
2015-12-09 07:04:37 +03:00
|
|
|
void ShowPopup(bool aIsContextMenu);
|
2007-08-03 18:05:07 +04:00
|
|
|
// indicate that the popup should be hidden. The new state should either be
|
|
|
|
// ePopupClosed or ePopupInvisible.
|
2011-09-29 10:19:26 +04:00
|
|
|
void HidePopup(bool aDeselectMenu, nsPopupState aNewState);
|
2007-07-04 19:49:38 +04: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.
|
2018-02-09 19:17:09 +03:00
|
|
|
nsMenuFrame* FindMenuWithShortcut(mozilla::dom::KeyboardEvent* aKeyEvent,
|
|
|
|
bool& doAction);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
void ClearIncrementalString() { mIncrementalString.Truncate(); }
|
2016-10-12 16:18:08 +03:00
|
|
|
static bool IsWithinIncrementalTime(DOMTimeStamp time) {
|
2020-05-19 23:56:06 +03:00
|
|
|
return time - sLastKeyTime <=
|
|
|
|
mozilla::StaticPrefs::ui_menu_incremental_search_timeout();
|
2016-10-12 16:18:08 +03:00
|
|
|
}
|
2000-02-13 11:33:39 +03:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(u"MenuPopup"_ns, aResult);
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
}
|
2001-09-15 04:45:54 +04:00
|
|
|
#endif
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
|
2019-05-06 16:57:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void EnsureMenuItemIsVisible(nsMenuFrame* aMenuFrame);
|
2001-06-05 03:03:24 +04:00
|
|
|
|
2015-05-20 20:11:06 +03:00
|
|
|
void ChangeByPage(bool aIsUp);
|
|
|
|
|
2015-09-29 03:17:34 +03:00
|
|
|
// Move the popup to the screen coordinate |aPos| in CSS pixels.
|
2012-09-29 15:36:09 +04:00
|
|
|
// 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 18:51:11 +03:00
|
|
|
// The frame may be destroyed by this method.
|
2021-09-01 16:02:51 +03:00
|
|
|
void MoveTo(const mozilla::CSSPoint& aPos, bool aUpdateAttrs);
|
2001-09-10 11:34:54 +04:00
|
|
|
|
2012-10-23 16:11:13 +04:00
|
|
|
void MoveToAnchor(nsIContent* aAnchorContent, const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos, bool aAttributesOverride);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetAutoPosition();
|
|
|
|
void SetAutoPosition(bool aShouldAutoPosition);
|
2001-09-10 11:34:54 +04:00
|
|
|
|
2009-09-01 15:22:31 +04:00
|
|
|
nsIScrollableFrame* GetScrollFrame(nsIFrame* aStart);
|
2007-12-19 19:37:32 +03:00
|
|
|
|
2016-06-09 18:34:12 +03:00
|
|
|
void SetOverrideConstraintRect(mozilla::LayoutDeviceIntRect aRect) {
|
2018-08-11 07:46:23 +03:00
|
|
|
mOverrideConstraintRect = ToAppUnits(aRect, mozilla::AppUnitsPerCSSPixel());
|
2016-06-09 18:34:12 +03:00
|
|
|
}
|
|
|
|
|
2010-08-02 19:06:04 +04:00
|
|
|
// For a popup that should appear anchored at the given rect, determine
|
2009-12-23 21:45:44 +03: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 21:35:09 +04: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.
|
2015-12-03 16:19:50 +03:00
|
|
|
// This operates in device pixels.
|
|
|
|
mozilla::LayoutDeviceIntRect GetConstraintRect(
|
|
|
|
const mozilla::LayoutDeviceIntRect& aAnchorRect,
|
|
|
|
const mozilla::LayoutDeviceIntRect& aRootScreenRect,
|
|
|
|
nsPopupLevel aPopupLevel);
|
2009-12-23 21:45:44 +03:00
|
|
|
|
|
|
|
// Determines whether the given edges of the popup may be moved, where
|
2017-01-24 13:41:56 +03:00
|
|
|
// aHorizontalSide and aVerticalSide are one of the enum Side constants.
|
|
|
|
// 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.
|
2009-12-23 21:45:44 +03:00
|
|
|
//
|
|
|
|
// 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.
|
2017-01-24 13:41:56 +03:00
|
|
|
void CanAdjustEdges(mozilla::Side aHorizontalSide,
|
|
|
|
mozilla::Side aVerticalSide,
|
2015-02-02 01:27:41 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint& aChange);
|
2009-12-23 21:45:44 +03:00
|
|
|
|
2010-07-27 17:38:02 +04:00
|
|
|
// Return true if the popup is positioned relative to an anchor.
|
2015-05-08 21:49:54 +03:00
|
|
|
bool IsAnchored() const { return mAnchorType != MenuPopupAnchorType_Point; }
|
2010-07-27 17:38:02 +04:00
|
|
|
|
2010-09-21 21:53:01 +04:00
|
|
|
// Return the anchor if there is one.
|
|
|
|
nsIContent* GetAnchor() const { return mAnchorContent; }
|
|
|
|
|
2015-07-20 15:59:50 +03:00
|
|
|
// Return the screen coordinates in CSS pixels of the popup,
|
|
|
|
// or (-1, -1, 0, 0) if anchored.
|
2021-09-01 16:02:51 +03:00
|
|
|
mozilla::CSSIntRect GetScreenAnchorRect() const {
|
|
|
|
return mozilla::CSSRect::FromAppUnitsRounded(mScreenRect);
|
|
|
|
}
|
2010-07-27 17:38:02 +04:00
|
|
|
|
2015-11-13 12:37:02 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint GetLastClientOffset() const {
|
|
|
|
return mLastClientOffset;
|
|
|
|
}
|
2011-12-02 01:35:42 +04:00
|
|
|
|
2013-04-19 04:47:27 +04:00
|
|
|
// Return the alignment of the popup
|
|
|
|
int8_t GetAlignmentPosition() const;
|
|
|
|
|
2013-05-09 02:59:03 +04:00
|
|
|
// Return the offset applied to the alignment of the popup
|
|
|
|
nscoord GetAlignmentOffset() const { return mAlignmentOffset; }
|
2014-06-16 22:43:07 +04: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;
|
|
|
|
}
|
|
|
|
|
2016-08-17 01:33:05 +03:00
|
|
|
void ShowWithPositionedEvent() {
|
|
|
|
mPopupState = ePopupPositioning;
|
|
|
|
mShouldAutoPosition = true;
|
|
|
|
}
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
// Checks for the anchor to change and either moves or hides the popup
|
|
|
|
// accordingly. The original position of the anchor should be supplied as
|
|
|
|
// the argument. If the popup needs to be hidden, HidePopup will be called by
|
|
|
|
// CheckForAnchorChange. If the popup needs to be moved, aRect will be updated
|
|
|
|
// with the new rectangle.
|
|
|
|
void CheckForAnchorChange(nsRect& aRect);
|
|
|
|
|
2020-10-06 19:28:33 +03:00
|
|
|
void WillDispatchPopupPositioned() { mPendingPositionedEvent = false; }
|
|
|
|
|
2015-03-20 07:55:33 +03:00
|
|
|
// nsIReflowCallback
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool ReflowFinished() override;
|
|
|
|
virtual void ReflowCallbackCanceled() override;
|
2015-03-20 07:55:33 +03:00
|
|
|
|
1999-07-18 10:35:03 +04:00
|
|
|
protected:
|
2010-07-27 17:38:03 +04:00
|
|
|
// returns the popup's level.
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPopupLevel PopupLevel(bool aIsNoAutoHide) const;
|
2010-07-27 17:38:03 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// redefine to tell the box system not to move the views.
|
2019-08-08 22:48:19 +03:00
|
|
|
ReflowChildFlags GetXULLayoutFlags() override;
|
2000-04-25 11:10:48 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void InitPositionFromAnchorAlign(const nsAString& aAnchor,
|
|
|
|
const nsAString& aAlign);
|
2000-02-08 12:30:15 +03:00
|
|
|
|
2008-12-10 18:19:16 +03: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-06 01:09:36 +03:00
|
|
|
nsPoint AdjustPositionForAnchorAlign(nsRect& anchorRect, FlipStyle& aHFlip,
|
2010-10-13 23:41:37 +04:00
|
|
|
FlipStyle& aVFlip);
|
2008-12-10 18:19:16 +03:00
|
|
|
|
2016-08-11 17:37:25 +03:00
|
|
|
// For popups that are going to align to their selected item, get the frame of
|
|
|
|
// the selected item.
|
|
|
|
nsIFrame* GetSelectedItemForAlignment();
|
|
|
|
|
2008-12-10 18:19:16 +03: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
|
2010-10-13 23:41:37 +04:00
|
|
|
// aFlip - how to flip or resize the popup when there isn't space
|
2009-12-23 21:45:44 +03:00
|
|
|
// aFlipSide - pointer to where current flip mode is stored
|
2008-12-10 18:19:16 +03:00
|
|
|
nscoord FlipOrResize(nscoord& aScreenPoint, nscoord aSize,
|
|
|
|
nscoord aScreenBegin, nscoord aScreenEnd,
|
|
|
|
nscoord aAnchorBegin, nscoord aAnchorEnd,
|
|
|
|
nscoord aMarginBegin, nscoord aMarginEnd,
|
2022-03-04 14:45:41 +03:00
|
|
|
FlipStyle aFlip, bool aIsOnEnd, bool* aFlipSide);
|
2000-03-02 07:08:04 +03:00
|
|
|
|
2013-05-09 02:59:03 +04: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);
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
// Given an anchor frame, compute the anchor rectangle relative to the screen,
|
|
|
|
// using the popup frame's app units, and taking into account transforms.
|
|
|
|
nsRect ComputeAnchorRect(nsPresContext* aRootPresContext,
|
|
|
|
nsIFrame* aAnchorFrame);
|
|
|
|
|
2001-09-10 11:34:54 +04:00
|
|
|
// Move the popup to the position specified in its |left| and |top|
|
|
|
|
// attributes.
|
|
|
|
void MoveToAttributePosition();
|
|
|
|
|
2011-04-29 17:51:05 +04:00
|
|
|
// Create a popup view for this frame. The view is added a child of the root
|
|
|
|
// view, and is initially hidden.
|
2013-03-20 05:47:48 +04:00
|
|
|
void CreatePopupView();
|
2011-04-29 17:51:05 +04:00
|
|
|
|
2017-03-21 03:22:13 +03:00
|
|
|
nsView* GetViewInternal() const override { return mView; }
|
|
|
|
void SetViewInternal(nsView* aView) override { mView = aView; }
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
// Returns true if the popup should try to remain at the same relative
|
|
|
|
// location as the anchor while it is open. If the anchor becomes hidden
|
|
|
|
// either directly or indirectly because a parent popup or other element
|
|
|
|
// is no longer visible, or a parent deck page is changed, the popup hides
|
|
|
|
// as well. The second variation also sets the anchor rectangle, relative to
|
|
|
|
// the popup frame.
|
|
|
|
bool ShouldFollowAnchor();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
public:
|
2021-08-12 17:07:30 +03: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()
|
|
|
|
? mAnchorContent->GetPrimaryFrame()
|
|
|
|
->StyleVisibility()
|
|
|
|
->mDirection == mozilla::StyleDirection::Rtl
|
|
|
|
: StyleVisibility()->mDirection == mozilla::StyleDirection::Rtl;
|
|
|
|
}
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
bool ShouldFollowAnchor(nsRect& aRect);
|
|
|
|
|
2019-04-17 17:19:57 +03:00
|
|
|
// Returns parent menu widget for submenus that are in the same
|
|
|
|
// frame hierarchy, it's needed for Linux/Wayland which demands
|
|
|
|
// strict popup windows hierarchy.
|
|
|
|
nsIWidget* GetParentMenuWidget();
|
2021-08-11 09:37:07 +03:00
|
|
|
|
2022-03-04 14:45:41 +03:00
|
|
|
// Returns the effective margin for this popup. This is the CSS margin plus
|
|
|
|
// the context-menu shift, if needed.
|
|
|
|
nsMargin GetMargin() const;
|
|
|
|
|
2021-08-11 09:37:07 +03:00
|
|
|
// These are used by Wayland backend.
|
2022-03-04 14:45:41 +03:00
|
|
|
const nsRect& GetUntransformedAnchorRect() const {
|
|
|
|
return mUntransformedAnchorRect;
|
|
|
|
}
|
|
|
|
int GetPopupAlignment() const { return mPopupAlignment; }
|
|
|
|
int GetPopupAnchor() const { return mPopupAnchor; }
|
|
|
|
FlipType GetFlipType() const { return mFlip; }
|
2019-04-17 17:19:57 +03:00
|
|
|
|
2021-10-10 21:53:07 +03:00
|
|
|
void WidgetPositionOrSizeDidChange();
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
protected:
|
2009-05-12 14:13:09 +04:00
|
|
|
nsString mIncrementalString; // for incremental typing navigation
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// the content that the popup is anchored to, if any, which may be in a
|
|
|
|
// different document than the popup.
|
|
|
|
nsCOMPtr<nsIContent> mAnchorContent;
|
2000-02-09 12:34:35 +03:00
|
|
|
|
2010-08-09 20:17:19 +04: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 19:49:38 +04:00
|
|
|
nsMenuFrame* mCurrentMenu; // The current menu that is active.
|
2017-03-21 03:22:13 +03:00
|
|
|
nsView* mView;
|
2000-02-09 12:34:35 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXULPopupShownEvent> mPopupShownDispatcher;
|
2014-06-16 22:43:07 +04:00
|
|
|
|
2016-08-17 01:33:05 +03:00
|
|
|
// The popup's screen rectangle in app units.
|
|
|
|
nsIntRect mUsedScreenRect;
|
|
|
|
|
2009-05-12 14:13:09 +04: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;
|
2000-02-13 11:33:39 +03:00
|
|
|
|
2012-09-29 15:36:09 +04: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 19:56:38 +04:00
|
|
|
int32_t mXPos;
|
|
|
|
int32_t mYPos;
|
2021-09-01 16:02:51 +03:00
|
|
|
nsRect mScreenRect;
|
2022-03-04 14:45:41 +03:00
|
|
|
// Used for store rectangle which the popup is going to be anchored to, we
|
|
|
|
// need that for Wayland. It's important that this rect is unflipped, and
|
|
|
|
// without margins applied, as GTK is what takes care of determining how to
|
|
|
|
// flip etc. on Wayland.
|
|
|
|
nsRect mUntransformedAnchorRect;
|
2022-03-02 13:27:54 +03:00
|
|
|
// Store SizedToPopup attribute for MoveTo call to avoid
|
|
|
|
// unwanted popup resize there.
|
|
|
|
bool mSizedToPopup = false;
|
2021-08-11 09:37:07 +03:00
|
|
|
|
2013-05-09 02:59:03 +04: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-02 01:35:42 +04: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.
|
2015-11-13 12:37:02 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint mLastClientOffset;
|
2006-03-15 01:48:09 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
nsPopupType mPopupType; // type of popup
|
2007-08-03 18:05:07 +04:00
|
|
|
nsPopupState mPopupState; // open state of the popup
|
2000-03-01 06:12:51 +03:00
|
|
|
|
2009-05-12 14:13:09 +04:00
|
|
|
// popup alignment relative to the anchor node
|
2012-08-22 19:56:38 +04:00
|
|
|
int8_t mPopupAlignment;
|
|
|
|
int8_t mPopupAnchor;
|
2013-04-19 04:47:27 +04:00
|
|
|
int8_t mPosition;
|
|
|
|
|
2014-01-23 00:09:03 +04:00
|
|
|
FlipType mFlip; // Whether to flip
|
2009-05-12 14:13:09 +04:00
|
|
|
|
2015-03-20 07:55:33 +03:00
|
|
|
struct ReflowCallbackData {
|
2018-04-13 16:01:28 +03:00
|
|
|
ReflowCallbackData()
|
2022-03-02 13:27:54 +03:00
|
|
|
: mPosted(false), mAnchor(nullptr), mIsOpenChanged(false) {}
|
|
|
|
void MarkPosted(nsIFrame* aAnchor, bool aIsOpenChanged) {
|
2015-03-20 07:55:33 +03:00
|
|
|
mPosted = true;
|
|
|
|
mAnchor = aAnchor;
|
2017-12-07 16:39:50 +03:00
|
|
|
mIsOpenChanged = aIsOpenChanged;
|
2015-03-20 07:55:33 +03:00
|
|
|
}
|
|
|
|
void Clear() {
|
|
|
|
mPosted = false;
|
|
|
|
mAnchor = nullptr;
|
2017-12-07 16:39:50 +03:00
|
|
|
mIsOpenChanged = false;
|
2015-03-20 07:55:33 +03:00
|
|
|
}
|
|
|
|
bool mPosted;
|
|
|
|
nsIFrame* mAnchor;
|
2017-12-07 16:39:50 +03:00
|
|
|
bool mIsOpenChanged;
|
2015-03-20 07:55:33 +03:00
|
|
|
};
|
|
|
|
ReflowCallbackData mReflowCallbackData;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsOpenChanged; // true if the open state changed since the last layout
|
2022-03-04 14:45:41 +03:00
|
|
|
bool mIsContextMenu = false; // true for context menus and their submenus.
|
|
|
|
bool mIsTopLevelContextMenu = false; // true for the topmost context menu.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04: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?
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 1368094 - Correct panel sliding on window resize r=bytesized
This is in response to an issue that's affecting the new app
update doorhangers on OSX, where the problem is more obvious.
On OSX, the panel styling makes it so that the doorhanger
overflows the window a little bit. This is fine until you enter
fullscreen with ctrl+command+F. At this point, the doorhanger
should come back onto the screen and the arrow should be rooted
to its anchor element (in our case the hamburger menu icon), but
instead it lags and the panel is not adjusted right away. This
is because right after the window is resized, which ends up
calling SetPopupPosition with aIsMove == false, SetPopupPosition
is called again from CheckForAnchorChange with aIsMove set to
true. There could be other solutions to this particular problem,
but since the aIsMove boolean is intended to limit the visual
noise when moving a window between screens, it seemed appropriate
for it to only prevent sliding or flipping if the panel isn't
already slid or flipped.
There was another issue affecting specifically the arrow, where
the logic for notifying observers of a positioning change in the
panel doesn't account for changes only to the position of the
anchor rect. This change adds tracking of that and sets aNotify
to true when called from ReflowFinished, since this is where
the position of the anchor element relative to the window can
need to change, even when the screen position of the panel rect
doesn't change.
MozReview-Commit-ID: Lpfokwkgl33
--HG--
extra : rebase_source : b05adc0b3f876196ff45499f0d70533f78cafb0e
2017-06-09 20:49:53 +03:00
|
|
|
// True if this popup has been offset due to moving off / near the edge of the
|
|
|
|
// screen. (This is useful for ensuring that a move, which can't offset the
|
|
|
|
// popup, doesn't undo a previously set offset.)
|
|
|
|
bool mIsOffset;
|
|
|
|
|
2009-12-23 21:45:44 +03:00
|
|
|
// the flip modes that were used when the popup was opened
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHFlip;
|
|
|
|
bool mVFlip;
|
2009-12-23 21:45:44 +03:00
|
|
|
|
2021-04-08 05:50:48 +03:00
|
|
|
// Whether the most recent initialization of this menupopup happened via
|
|
|
|
// InitializePopupAsNativeContextMenu.
|
|
|
|
bool mIsNativeMenu = false;
|
|
|
|
|
2020-10-06 19:28:33 +03:00
|
|
|
// Whether we have a pending `popuppositioned` event.
|
|
|
|
bool mPendingPositionedEvent = false;
|
|
|
|
|
2017-12-07 16:39:50 +03:00
|
|
|
// When POPUPPOSITION_SELECTION is used, this indicates the vertical offset
|
|
|
|
// that the original selected item was. This needs to be used in case the
|
|
|
|
// popup gets changed so that we can keep the popup at the same vertical
|
|
|
|
// offset.
|
|
|
|
nscoord mPositionedOffset;
|
|
|
|
|
2015-05-08 21:49:54 +03:00
|
|
|
// How the popup is anchored.
|
|
|
|
MenuPopupAnchorType mAnchorType;
|
|
|
|
|
2016-06-09 18:34:12 +03:00
|
|
|
nsRect mOverrideConstraintRect;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int8_t sDefaultLevelIsTop;
|
2015-02-19 09:50:20 +03:00
|
|
|
|
2016-10-12 16:18:08 +03:00
|
|
|
static DOMTimeStamp sLastKeyTime;
|
|
|
|
|
1999-07-18 10:35:03 +04:00
|
|
|
}; // class nsMenuPopupFrame
|
|
|
|
|
|
|
|
#endif
|