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:36:37 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuFrame_h__
|
|
|
|
#define nsMenuFrame_h__
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
1999-07-18 10:36:37 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
1999-07-21 06:56:23 +04:00
|
|
|
#include "nsBoxFrame.h"
|
1999-07-18 10:41:41 +04:00
|
|
|
#include "nsFrameList.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2008-12-05 19:37:31 +03:00
|
|
|
#include "nsMenuParent.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsXULPopupManager.h"
|
2017-03-20 10:07:31 +03:00
|
|
|
#include "nsINamed.h"
|
2017-02-18 11:13:40 +03:00
|
|
|
#include "nsIReflowCallback.h"
|
1999-07-25 04:16:11 +04:00
|
|
|
#include "nsITimer.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class PresShell;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
nsIFrame* NS_NewMenuFrame(mozilla::PresShell* aPresShell,
|
|
|
|
mozilla::ComputedStyle*);
|
|
|
|
nsIFrame* NS_NewMenuItemFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
mozilla::ComputedStyle*);
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsIContent;
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2018-04-27 06:37:33 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// the type of menuitem
|
|
|
|
enum nsMenuType {
|
|
|
|
// a normal menuitem where a command is carried out when activated
|
|
|
|
eMenuType_Normal = 0,
|
|
|
|
// a menuitem with a checkmark that toggles when activated
|
|
|
|
eMenuType_Checkbox = 1,
|
|
|
|
// a radio menuitem where only one of it and its siblings with the same
|
|
|
|
// name attribute can be checked at a time
|
|
|
|
eMenuType_Radio = 2
|
|
|
|
};
|
|
|
|
|
2006-01-12 19:40:47 +03:00
|
|
|
class nsMenuFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsMenuTimerMediator is a wrapper around an nsMenuFrame which can be safely
|
|
|
|
* passed to timers. The class is reference counted unlike the underlying
|
|
|
|
* nsMenuFrame, so that it will exist as long as the timer holds a reference
|
|
|
|
* to it. The callback is delegated to the contained nsMenuFrame as long as
|
|
|
|
* the contained nsMenuFrame has not been destroyed.
|
|
|
|
*/
|
2017-03-20 10:07:31 +03:00
|
|
|
class nsMenuTimerMediator final : public nsITimerCallback, public nsINamed {
|
2006-01-12 19:40:47 +03:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsMenuTimerMediator(nsMenuFrame* aFrame);
|
2006-01-12 19:40:47 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2017-03-20 10:07:31 +03:00
|
|
|
NS_DECL_NSINAMED
|
2006-01-12 19:40:47 +03:00
|
|
|
|
|
|
|
void ClearFrame();
|
|
|
|
|
|
|
|
private:
|
2014-06-24 02:40:01 +04:00
|
|
|
~nsMenuTimerMediator();
|
2006-01-12 19:40:47 +03:00
|
|
|
|
|
|
|
// Pointer to the wrapped frame.
|
|
|
|
nsMenuFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsMenuFrame final : public nsBoxFrame, public nsIReflowCallback {
|
1999-07-18 10:36:37 +04:00
|
|
|
public:
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsMenuFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsMenuFrame)
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:35 +03:00
|
|
|
NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
|
2016-04-21 07:28:31 +03:00
|
|
|
virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
|
2016-04-21 07:28:31 +03:00
|
|
|
virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
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;
|
1999-07-21 11:42:16 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// The following methods are all overridden so that the menupopup
|
|
|
|
// can be stored in a separate list, so that it doesn't impact reflow of the
|
|
|
|
// actual menu item at all.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual const nsFrameList& GetChildList(ChildListID aList) const override;
|
|
|
|
virtual void GetChildLists(nsTArray<ChildList>* aLists) const override;
|
2017-11-07 03:20:33 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) override;
|
1999-07-18 10:48:03 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Overridden to prevent events from going to children of the menu.
|
2013-02-14 15:12:27 +04:00
|
|
|
virtual void BuildDisplayListForChildren(
|
2015-03-21 19:28:04 +03:00
|
|
|
nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) override;
|
2017-04-30 18:30:08 +03:00
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// this method can destroy the frame
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 12:36:33 +04:00
|
|
|
mozilla::WidgetGUIEvent* aEvent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsEventStatus* aEventStatus) override;
|
1999-07-20 13:35:35 +04:00
|
|
|
|
2022-11-02 00:15:54 +03:00
|
|
|
void SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList&& aChildList) override;
|
2022-11-02 00:15:54 +03:00
|
|
|
void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
|
2022-11-02 00:15:55 +03:00
|
|
|
void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
|
|
|
nsFrameList&& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
1999-07-31 15:29:03 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHOD SelectMenu(bool aActivateFlag);
|
1999-07-20 13:35:35 +04:00
|
|
|
|
2020-11-20 01:46:33 +03:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() const override;
|
2009-09-01 15:22:31 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
/**
|
2007-11-17 18:47:38 +03:00
|
|
|
* NOTE: OpenMenu will open the menu asynchronously.
|
2007-07-04 19:49:38 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void OpenMenu(bool aSelectFirstItem);
|
2007-07-04 19:49:38 +04:00
|
|
|
// CloseMenu closes the menu asynchronously
|
2011-09-29 10:19:26 +04:00
|
|
|
void CloseMenu(bool aDeselectMenu);
|
2000-08-17 13:15:51 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsChecked() { return mChecked; }
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2018-04-27 06:37:33 +03:00
|
|
|
NS_IMETHOD GetActiveChild(mozilla::dom::Element** aResult);
|
|
|
|
NS_IMETHOD SetActiveChild(mozilla::dom::Element* aChild);
|
1999-07-22 13:01:55 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// called when the Enter key is pressed while the menuitem is the current
|
|
|
|
// one in its parent popup. This will carry out the command attached to
|
2007-11-17 18:47:38 +03:00
|
|
|
// the menuitem. If the menu should be opened, this frame will be returned,
|
|
|
|
// otherwise null will be returned.
|
2013-10-02 07:46:03 +04:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
1999-10-18 01:37:37 +04:00
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
// Return the nearest menu bar or menupopup ancestor frame.
|
|
|
|
nsMenuParent* GetMenuParent() const;
|
2000-05-27 02:45:26 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
const nsAString& GetRadioGroupName() { return mGroupName; }
|
|
|
|
nsMenuType GetMenuType() { return mType; }
|
2020-11-20 01:46:33 +03:00
|
|
|
nsMenuPopupFrame* GetPopup() const;
|
2012-03-08 05:57:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if this frame has a popup child frame.
|
|
|
|
*/
|
|
|
|
bool HasPopup() const {
|
2020-06-28 04:00:19 +03:00
|
|
|
return HasAnyStateBits(NS_STATE_MENU_HAS_POPUP_LIST);
|
2012-03-08 05:57:37 +04:00
|
|
|
}
|
|
|
|
|
1999-10-18 01:37:37 +04:00
|
|
|
// nsMenuFrame methods
|
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
bool IsOnMenuBar() const {
|
|
|
|
nsMenuParent* menuParent = GetMenuParent();
|
|
|
|
return menuParent && menuParent->IsMenuBar();
|
|
|
|
}
|
|
|
|
bool IsOnActiveMenuBar() const {
|
|
|
|
nsMenuParent* menuParent = GetMenuParent();
|
|
|
|
return menuParent && menuParent->IsMenuBar() && menuParent->IsActive();
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsOpen();
|
|
|
|
virtual bool IsMenu();
|
2018-11-07 22:22:29 +03:00
|
|
|
bool IsParentMenuList();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDisabled();
|
2007-07-04 19:49:38 +04:00
|
|
|
void ToggleMenuState();
|
|
|
|
|
2021-04-12 03:32:19 +03:00
|
|
|
// Activate this menu item.
|
2021-04-21 01:13:24 +03:00
|
|
|
void ActivateItem(mozilla::Modifiers aModifiers, int16_t aButton);
|
2021-04-12 03:32:19 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// indiciate that the menu's popup has just been opened, so that the menu
|
|
|
|
// can update its open state. This method modifies the open attribute on
|
2007-11-17 18:47:38 +03:00
|
|
|
// the menu, so the frames could be gone after this call.
|
2007-07-04 19:49:38 +04:00
|
|
|
void PopupOpened();
|
|
|
|
// indiciate that the menu's popup has just been closed, so that the menu
|
|
|
|
// can update its open state. The menu should be unhighlighted if
|
2007-11-17 18:47:38 +03:00
|
|
|
// aDeselectedMenu is true. This method modifies the open attribute on
|
|
|
|
// the menu, so the frames could be gone after this call.
|
2011-09-29 10:19:26 +04:00
|
|
|
void PopupClosed(bool aDeselectMenu);
|
2007-07-04 19:49:38 +04:00
|
|
|
|
|
|
|
// returns true if this is a menu on another menu popup. A menu is a submenu
|
|
|
|
// if it has a parent popup or menupopup.
|
2014-05-25 02:20:41 +04:00
|
|
|
bool IsOnMenu() const {
|
|
|
|
nsMenuParent* menuParent = GetMenuParent();
|
|
|
|
return menuParent && menuParent->IsMenu();
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetIsMenu(bool aIsMenu) { mIsMenu = aIsMenu; }
|
1999-08-02 12:15:30 +04: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"Menu"_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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSizedToPopup(nsIContent* aContent, bool aRequireAlways);
|
2002-03-18 02:41:22 +03:00
|
|
|
|
2017-02-18 11:13:40 +03:00
|
|
|
// nsIReflowCallback
|
|
|
|
virtual bool ReflowFinished() override;
|
|
|
|
virtual void ReflowCallbackCanceled() override;
|
|
|
|
|
1999-07-20 13:35:35 +04:00
|
|
|
protected:
|
2006-01-12 19:40:47 +03:00
|
|
|
friend class nsMenuTimerMediator;
|
2007-06-30 02:15:59 +04:00
|
|
|
friend class nsASyncMenuInitialization;
|
2010-08-12 15:59:03 +04:00
|
|
|
friend class nsMenuAttributeChangedEvent;
|
2007-06-30 02:15:59 +04:00
|
|
|
|
2012-03-08 05:57:37 +04:00
|
|
|
/**
|
|
|
|
* Initialize the popup list to the first popup frame within
|
|
|
|
* aChildList. Removes the popup, if any, from aChildList.
|
|
|
|
*/
|
2009-07-28 16:53:20 +04:00
|
|
|
void SetPopupFrame(nsFrameList& aChildList);
|
|
|
|
|
2012-03-08 05:57:37 +04:00
|
|
|
/**
|
|
|
|
* Get the popup frame list from the frame property.
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return the property value if it exists, nullptr otherwise.
|
2012-03-08 05:57:37 +04:00
|
|
|
*/
|
|
|
|
nsFrameList* GetPopupList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the popup list property. The list must exist and be empty.
|
|
|
|
*/
|
|
|
|
void DestroyPopupList();
|
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// Update the menu's type (normal, checkbox, radio).
|
|
|
|
// This method can destroy the frame.
|
2015-12-07 04:15:53 +03:00
|
|
|
void UpdateMenuType();
|
2007-11-17 18:47:38 +03:00
|
|
|
// Update the checked state of the menu, and for radios, clear any other
|
|
|
|
// checked items. This method can destroy the frame.
|
2015-12-07 04:15:53 +03:00
|
|
|
void UpdateMenuSpecialState();
|
1999-07-20 13:35:35 +04:00
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// Called to execute our command handler. This method can destroy the frame.
|
2013-10-02 07:46:03 +04:00
|
|
|
void Execute(mozilla::WidgetGUIEvent* aEvent);
|
2001-08-07 01:49:35 +04:00
|
|
|
|
2007-11-17 18:47:38 +03:00
|
|
|
// This method can destroy the frame
|
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;
|
2020-03-17 12:38:32 +03:00
|
|
|
virtual ~nsMenuFrame() = default;
|
1999-09-08 07:51:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize);
|
2005-06-25 13:35:05 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldBlink();
|
2021-04-12 03:32:18 +03:00
|
|
|
void StartBlinking();
|
2010-04-19 18:12:58 +04:00
|
|
|
void StopBlinking();
|
2021-04-20 20:44:16 +03:00
|
|
|
void CreateMenuCommandEvent(bool aIsTrusted, mozilla::Modifiers aModifiers,
|
|
|
|
int16_t aButton);
|
2010-04-19 18:12:58 +04:00
|
|
|
void PassMenuCommandEventToPopupManager();
|
|
|
|
|
1999-07-18 10:41:41 +04:00
|
|
|
protected:
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult Notify(nsITimer* aTimer);
|
2000-03-02 06:01:30 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsMenu; // Whether or not we can even have children or not.
|
|
|
|
bool mChecked; // are we checked?
|
2017-02-18 11:13:40 +03:00
|
|
|
bool mReflowCallbackPosted;
|
1999-10-18 01:37:37 +04:00
|
|
|
nsMenuType mType;
|
|
|
|
|
2006-01-12 19:40:47 +03:00
|
|
|
// Reference to the mediator which wraps this frame.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMenuTimerMediator> mTimerMediator;
|
2006-01-12 19:40:47 +03:00
|
|
|
|
1999-07-25 04:16:11 +04:00
|
|
|
nsCOMPtr<nsITimer> mOpenTimer;
|
2010-04-19 18:12:58 +04:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mBlinkState; // 0: not blinking, 1: off, 2: on
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXULMenuCommandEvent> mDelayedMenuCommandEvent;
|
2006-01-12 19:40:47 +03:00
|
|
|
|
1999-10-18 01:37:37 +04:00
|
|
|
nsString mGroupName;
|
2001-07-03 04:26:41 +04:00
|
|
|
|
1999-07-18 10:36:37 +04:00
|
|
|
}; // class nsMenuFrame
|
|
|
|
|
|
|
|
#endif
|