2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 06:36:37 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuFrame_h__
|
|
|
|
#define nsMenuFrame_h__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
1999-07-21 02:56:23 +00:00
|
|
|
#include "nsBoxFrame.h"
|
1999-07-18 06:41:41 +00:00
|
|
|
#include "nsFrameList.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2008-12-05 16:37:31 +00:00
|
|
|
#include "nsMenuParent.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsXULPopupManager.h"
|
1999-07-25 00:16:11 +00:00
|
|
|
#include "nsITimer.h"
|
2012-06-19 03:26:34 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
1999-07-18 06:36:37 +00:00
|
|
|
|
2009-01-19 18:31:33 +00:00
|
|
|
nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
nsIFrame* NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
1999-07-18 06:36:37 +00:00
|
|
|
|
2013-03-22 00:05:20 +00:00
|
|
|
class nsIContent;
|
1999-07-21 07:42:16 +00:00
|
|
|
class nsMenuBarFrame;
|
1999-07-18 06:36:37 +00:00
|
|
|
|
2001-10-11 03:03:42 +00:00
|
|
|
#define NS_STATE_ACCELTEXT_IS_DERIVED NS_STATE_BOX_CHILD_RESERVED
|
|
|
|
|
2007-07-04 15:49:38 +00: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 14:05:07 +00:00
|
|
|
enum nsMenuListType {
|
|
|
|
eNotMenuList, // not a menulist
|
|
|
|
eReadonlyMenuList, // <menulist/>
|
|
|
|
eEditableMenuList // <menulist editable="true"/>
|
|
|
|
};
|
|
|
|
|
2006-01-12 16:40:47 +00: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.
|
|
|
|
*/
|
2012-06-19 03:26:34 +00:00
|
|
|
class nsMenuTimerMediator MOZ_FINAL : public nsITimerCallback
|
2006-01-12 16:40:47 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMenuTimerMediator(nsMenuFrame* aFrame);
|
|
|
|
~nsMenuTimerMediator();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
|
|
|
void ClearFrame();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Pointer to the wrapped frame.
|
|
|
|
nsMenuFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2011-07-11 14:05:07 +00:00
|
|
|
class nsMenuFrame : public nsBoxFrame
|
1999-07-18 06:36:37 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-03-26 21:30:36 +00:00
|
|
|
nsMenuFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
1999-07-18 06:36:37 +00:00
|
|
|
|
2011-07-11 14:05:07 +00:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsMenuFrame)
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2012-09-14 16:10:08 +00:00
|
|
|
NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
|
|
|
virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
|
|
|
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
1999-07-21 07:42:16 +00:00
|
|
|
|
2004-06-19 09:07:47 +00:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) MOZ_OVERRIDE;
|
2004-06-19 09:07:47 +00:00
|
|
|
#endif
|
2000-03-02 03:01:30 +00:00
|
|
|
|
2007-07-04 15:49:38 +00: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.
|
2012-09-14 16:10:08 +00:00
|
|
|
virtual const nsFrameList& GetChildList(ChildListID aList) const MOZ_OVERRIDE;
|
|
|
|
virtual void GetChildLists(nsTArray<ChildList>* aLists) const MOZ_OVERRIDE;
|
2013-05-14 16:33:23 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
1999-07-18 06:48:03 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// Overridden to prevent events from going to children of the menu.
|
2013-02-14 11:12:27 +00:00
|
|
|
virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2007-11-17 15:47:38 +00:00
|
|
|
// this method can destroy the frame
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 08:36:33 +00:00
|
|
|
mozilla::WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
1999-07-20 09:35:35 +00:00
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
1999-07-31 11:29:03 +00:00
|
|
|
|
2012-09-14 16:10:08 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE { return nsGkAtoms::menuFrame; }
|
1999-07-22 09:01:55 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD SelectMenu(bool aActivateFlag);
|
1999-07-20 09:35:35 +00:00
|
|
|
|
2013-05-14 16:33:23 +00:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE;
|
2009-09-01 11:22:31 +00:00
|
|
|
|
2014-01-28 16:28:45 +00: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 15:49:38 +00:00
|
|
|
/**
|
2007-11-17 15:47:38 +00:00
|
|
|
* NOTE: OpenMenu will open the menu asynchronously.
|
2007-07-04 15:49:38 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
void OpenMenu(bool aSelectFirstItem);
|
2007-07-04 15:49:38 +00:00
|
|
|
// CloseMenu closes the menu asynchronously
|
2011-09-29 06:19:26 +00:00
|
|
|
void CloseMenu(bool aDeselectMenu);
|
2000-08-17 09:15:51 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsChecked() { return mChecked; }
|
2001-12-17 22:51:39 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
NS_IMETHOD GetActiveChild(nsIDOMElement** aResult);
|
2007-11-17 15:47:38 +00:00
|
|
|
NS_IMETHOD SetActiveChild(nsIDOMElement* aChild);
|
1999-07-22 09:01:55 +00:00
|
|
|
|
2007-07-04 15:49:38 +00: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 15:47:38 +00:00
|
|
|
// the menuitem. If the menu should be opened, this frame will be returned,
|
|
|
|
// otherwise null will be returned.
|
2013-10-02 03:46:03 +00:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
1999-10-17 21:37:37 +00:00
|
|
|
|
2014-05-24 22:20:41 +00:00
|
|
|
// Return the nearest menu bar or menupopup ancestor frame.
|
|
|
|
nsMenuParent* GetMenuParent() const;
|
2000-05-26 22:45:26 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
const nsAString& GetRadioGroupName() { return mGroupName; }
|
|
|
|
nsMenuType GetMenuType() { return mType; }
|
2012-03-08 01:57:37 +00: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-17 21:37:37 +00:00
|
|
|
|
|
|
|
// nsMenuFrame methods
|
|
|
|
|
2014-05-24 22:20:41 +00: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 06:19:26 +00:00
|
|
|
virtual bool IsOpen();
|
|
|
|
virtual bool IsMenu();
|
2011-07-11 14:05:07 +00:00
|
|
|
nsMenuListType GetParentMenuListType();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsDisabled();
|
2007-07-04 15:49:38 +00: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 15:47:38 +00:00
|
|
|
// the menu, so the frames could be gone after this call.
|
2007-07-04 15:49:38 +00: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 15:47:38 +00: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 06:19:26 +00:00
|
|
|
void PopupClosed(bool aDeselectMenu);
|
2007-07-04 15:49:38 +00: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-24 22:20:41 +00:00
|
|
|
bool IsOnMenu() const
|
|
|
|
{
|
|
|
|
nsMenuParent* menuParent = GetMenuParent();
|
|
|
|
return menuParent && menuParent->IsMenu();
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetIsMenu(bool aIsMenu) { mIsMenu = aIsMenu; }
|
1999-08-02 08:15:30 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_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-09 22:02:40 +00:00
|
|
|
{
|
2001-11-14 01:33:42 +00: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-09 22:02:40 +00:00
|
|
|
}
|
2001-09-15 00:45:54 +00: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-09 22:02:40 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool IsSizedToPopup(nsIContent* aContent, bool aRequireAlways);
|
2002-03-17 23:41:22 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
protected:
|
2006-01-12 16:40:47 +00:00
|
|
|
friend class nsMenuTimerMediator;
|
2007-06-29 22:15:59 +00:00
|
|
|
friend class nsASyncMenuInitialization;
|
2010-08-12 11:59:03 +00:00
|
|
|
friend class nsMenuAttributeChangedEvent;
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2012-03-08 01:57:37 +00:00
|
|
|
/**
|
|
|
|
* Initialize the popup list to the first popup frame within
|
|
|
|
* aChildList. Removes the popup, if any, from aChildList.
|
|
|
|
*/
|
2009-07-28 12:53:20 +00:00
|
|
|
void SetPopupFrame(nsFrameList& aChildList);
|
|
|
|
|
2012-03-08 01:57:37 +00:00
|
|
|
/**
|
|
|
|
* Get the popup frame list from the frame property.
|
2012-07-30 14:20:58 +00:00
|
|
|
* @return the property value if it exists, nullptr otherwise.
|
2012-03-08 01:57:37 +00:00
|
|
|
*/
|
|
|
|
nsFrameList* GetPopupList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the popup list property. The list must exist and be empty.
|
|
|
|
*/
|
|
|
|
void DestroyPopupList();
|
|
|
|
|
2007-11-17 15:47:38 +00:00
|
|
|
// Update the menu's type (normal, checkbox, radio).
|
|
|
|
// This method can destroy the frame.
|
|
|
|
void UpdateMenuType(nsPresContext* aPresContext);
|
|
|
|
// Update the checked state of the menu, and for radios, clear any other
|
|
|
|
// checked items. This method can destroy the frame.
|
|
|
|
void UpdateMenuSpecialState(nsPresContext* aPresContext);
|
1999-07-20 09:35:35 +00:00
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
// Examines the key node and builds the accelerator.
|
2011-09-29 06:19:26 +00:00
|
|
|
void BuildAcceleratorText(bool aNotify);
|
1999-07-31 01:43:33 +00:00
|
|
|
|
2007-11-17 15:47:38 +00:00
|
|
|
// Called to execute our command handler. This method can destroy the frame.
|
2013-10-02 03:46:03 +00:00
|
|
|
void Execute(mozilla::WidgetGUIEvent *aEvent);
|
2001-08-06 21:49:35 +00:00
|
|
|
|
2007-11-17 15:47:38 +00:00
|
|
|
// This method can destroy the frame
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2012-12-09 17:23:19 +00:00
|
|
|
virtual ~nsMenuFrame() { }
|
1999-09-08 03:51:41 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize);
|
2005-06-25 09:35:05 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ShouldBlink();
|
2013-10-02 03:46:03 +00:00
|
|
|
void StartBlinking(mozilla::WidgetGUIEvent* aEvent, bool aFlipChecked);
|
2010-04-19 14:12:58 +00:00
|
|
|
void StopBlinking();
|
2013-10-02 03:46:03 +00:00
|
|
|
void CreateMenuCommandEvent(mozilla::WidgetGUIEvent* aEvent,
|
|
|
|
bool aFlipChecked);
|
2010-04-19 14:12:58 +00:00
|
|
|
void PassMenuCommandEventToPopupManager();
|
|
|
|
|
1999-07-18 06:41:41 +00:00
|
|
|
protected:
|
2004-06-19 09:07:47 +00:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug);
|
2004-06-19 09:07:47 +00:00
|
|
|
#endif
|
2014-06-02 12:08:21 +00:00
|
|
|
nsresult Notify(nsITimer* aTimer);
|
2000-03-02 03:01:30 +00:00
|
|
|
|
2011-09-29 06:19:26 +00: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
|
1999-10-17 21:37:37 +00:00
|
|
|
nsMenuType mType;
|
|
|
|
|
2006-01-12 16:40:47 +00:00
|
|
|
// Reference to the mediator which wraps this frame.
|
|
|
|
nsRefPtr<nsMenuTimerMediator> mTimerMediator;
|
|
|
|
|
1999-07-25 00:16:11 +00:00
|
|
|
nsCOMPtr<nsITimer> mOpenTimer;
|
2010-04-19 14:12:58 +00:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mBlinkState; // 0: not blinking, 1: off, 2: on
|
2010-04-19 14:12:58 +00:00
|
|
|
nsRefPtr<nsXULMenuCommandEvent> mDelayedMenuCommandEvent;
|
2006-01-12 16:40:47 +00:00
|
|
|
|
1999-10-17 21:37:37 +00:00
|
|
|
nsString mGroupName;
|
2001-07-03 00:26:41 +00:00
|
|
|
|
1999-07-18 06:36:37 +00:00
|
|
|
}; // class nsMenuFrame
|
|
|
|
|
|
|
|
#endif
|