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
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, mozilla::ComputedStyle*);
|
|
|
|
nsIFrame* NS_NewMenuItemFrame(nsIPresShell* aPresShell, 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
|
|
|
|
|
2001-10-11 07:03:42 +04:00
|
|
|
#define NS_STATE_ACCELTEXT_IS_DERIVED NS_STATE_BOX_CHILD_RESERVED
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2011-07-11 18:05:07 +04:00
|
|
|
enum nsMenuListType {
|
|
|
|
eNotMenuList, // not a menulist
|
2018-08-24 17:44:38 +03:00
|
|
|
eReadonlyMenuList // <menulist/>
|
2011-07-11 18:05:07 +04:00
|
|
|
};
|
|
|
|
|
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
|
2017-02-18 11:13:40 +03:00
|
|
|
, public nsIReflowCallback
|
1999-07-18 10:36:37 +04:00
|
|
|
{
|
|
|
|
public:
|
2018-03-22 21:20:41 +03:00
|
|
|
explicit nsMenuFrame(ComputedStyle* aStyle);
|
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(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aChildList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() override;
|
2009-09-01 15:22:31 +04:00
|
|
|
|
2014-01-28 20:28:45 +04:00
|
|
|
// Retrieve the element that the menu should be anchored to. By default this is
|
|
|
|
// the menu itself. However, the anchor attribute may refer to the value of an
|
|
|
|
// anonid within the menu's binding, or, if not found, the id of an element in
|
|
|
|
// the document.
|
|
|
|
nsIContent* GetAnchor();
|
|
|
|
|
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; }
|
2012-03-08 05:57:37 +04:00
|
|
|
nsMenuPopupFrame* GetPopup();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if this frame has a popup child frame.
|
|
|
|
*/
|
|
|
|
bool HasPopup() const
|
|
|
|
{
|
|
|
|
return (GetStateBits() & NS_STATE_MENU_HAS_POPUP_LIST) != 0;
|
|
|
|
}
|
|
|
|
|
1999-10-18 01:37:37 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// nsMenuFrame methods
|
1999-10-18 01:37:37 +04:00
|
|
|
|
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();
|
2011-07-11 18:05:07 +04:00
|
|
|
nsMenuListType GetParentMenuListType();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDisabled();
|
2007-07-04 19:49:38 +04:00
|
|
|
void ToggleMenuState();
|
|
|
|
|
|
|
|
// 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
|
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-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Menu"), 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
|
|
|
|
1999-07-31 05:43:33 +04:00
|
|
|
// Examines the key node and builds the accelerator.
|
2011-09-29 10:19:26 +04:00
|
|
|
void BuildAcceleratorText(bool aNotify);
|
1999-07-31 05:43:33 +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,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) override;
|
2012-12-09 21:23:19 +04:00
|
|
|
virtual ~nsMenuFrame() { }
|
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();
|
2013-10-02 07:46:03 +04:00
|
|
|
void StartBlinking(mozilla::WidgetGUIEvent* aEvent, bool aFlipChecked);
|
2010-04-19 18:12:58 +04:00
|
|
|
void StopBlinking();
|
2013-10-02 07:46:03 +04:00
|
|
|
void CreateMenuCommandEvent(mozilla::WidgetGUIEvent* aEvent,
|
|
|
|
bool aFlipChecked);
|
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?
|
|
|
|
bool mIgnoreAccelTextChange; // temporarily set while determining the accelerator key
|
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
|