2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuFrame_h__
|
|
|
|
#define nsMenuFrame_h__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsFrameList.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2008-12-05 08:37:31 -08:00
|
|
|
#include "nsMenuParent.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITimer.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
nsIFrame* NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsIContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsMenuBarFrame;
|
|
|
|
|
|
|
|
#define NS_STATE_ACCELTEXT_IS_DERIVED NS_STATE_BOX_CHILD_RESERVED
|
|
|
|
|
2007-07-04 08:49:38 -07: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 07:05:07 -07:00
|
|
|
enum nsMenuListType {
|
|
|
|
eNotMenuList, // not a menulist
|
|
|
|
eReadonlyMenuList, // <menulist/>
|
|
|
|
eEditableMenuList // <menulist editable="true"/>
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07: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-18 20:26:34 -07:00
|
|
|
class nsMenuTimerMediator MOZ_FINAL : public nsITimerCallback
|
2007-03-22 10:30:00 -07: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 07:05:07 -07:00
|
|
|
class nsMenuFrame : public nsBoxFrame
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMenuFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
|
|
|
|
2011-07-11 07:05:07 -07:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsMenuFrame)
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
|
|
|
virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
|
|
|
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-07-04 08:49:38 -07: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 09:10:08 -07:00
|
|
|
virtual const nsFrameList& GetChildList(ChildListID aList) const MOZ_OVERRIDE;
|
|
|
|
virtual void GetChildLists(nsTArray<ChildList>* aLists) const MOZ_OVERRIDE;
|
2014-02-18 00:36:33 -08:00
|
|
|
virtual nsresult SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Overridden to prevent events from going to children of the menu.
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-17 07:47:38 -08:00
|
|
|
// this method can destroy the frame
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
mozilla::WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AppendFrames(ChildListID aListID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult InsertFrames(ChildListID aListID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult RemoveFrame(ChildListID aListID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE { return nsGkAtoms::menuFrame; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SelectMenu(bool aActivateFlag);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE;
|
2009-09-01 04:22:31 -07:00
|
|
|
|
2014-01-28 08:28:45 -08: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 08:49:38 -07:00
|
|
|
/**
|
2007-11-17 07:47:38 -08:00
|
|
|
* NOTE: OpenMenu will open the menu asynchronously.
|
2007-07-04 08:49:38 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void OpenMenu(bool aSelectFirstItem);
|
2007-07-04 08:49:38 -07:00
|
|
|
// CloseMenu closes the menu asynchronously
|
2011-09-28 23:19:26 -07:00
|
|
|
void CloseMenu(bool aDeselectMenu);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsChecked() { return mChecked; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
NS_IMETHOD GetActiveChild(nsIDOMElement** aResult);
|
2007-11-17 07:47:38 -08:00
|
|
|
NS_IMETHOD SetActiveChild(nsIDOMElement* aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07: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 07:47:38 -08:00
|
|
|
// the menuitem. If the menu should be opened, this frame will be returned,
|
|
|
|
// otherwise null will be returned.
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-24 15:20:39 -07:00
|
|
|
virtual void SetParent(nsContainerFrame* aParent) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-05 08:37:31 -08:00
|
|
|
virtual nsMenuParent *GetMenuParent() { return mMenuParent; }
|
2007-07-04 08:49:38 -07:00
|
|
|
const nsAString& GetRadioGroupName() { return mGroupName; }
|
|
|
|
nsMenuType GetMenuType() { return mType; }
|
2012-03-07 17:57:37 -08: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsMenuFrame methods
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsOnMenuBar() { return mMenuParent && mMenuParent->IsMenuBar(); }
|
|
|
|
bool IsOnActiveMenuBar() { return IsOnMenuBar() && mMenuParent->IsActive(); }
|
|
|
|
virtual bool IsOpen();
|
|
|
|
virtual bool IsMenu();
|
2011-07-11 07:05:07 -07:00
|
|
|
nsMenuListType GetParentMenuListType();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsDisabled();
|
2007-07-04 08:49:38 -07: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 07:47:38 -08:00
|
|
|
// the menu, so the frames could be gone after this call.
|
2007-07-04 08:49:38 -07: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 07:47:38 -08:00
|
|
|
// aDeselectedMenu is true. This method modifies the open attribute on
|
|
|
|
// the menu, so the frames could be gone after this call.
|
2011-09-28 23:19:26 -07:00
|
|
|
void PopupClosed(bool aDeselectMenu);
|
2007-07-04 08:49:38 -07: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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsOnMenu() { return mMenuParent && mMenuParent->IsMenu(); }
|
|
|
|
void SetIsMenu(bool aIsMenu) { mIsMenu = aIsMenu; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Menu"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsSizedToPopup(nsIContent* aContent, bool aRequireAlways);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class nsMenuTimerMediator;
|
2007-06-29 15:15:59 -07:00
|
|
|
friend class nsASyncMenuInitialization;
|
2010-08-12 04:59:03 -07:00
|
|
|
friend class nsMenuAttributeChangedEvent;
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
/**
|
|
|
|
* Initialize the popup list to the first popup frame within
|
|
|
|
* aChildList. Removes the popup, if any, from aChildList.
|
|
|
|
*/
|
2009-07-28 05:53:20 -07:00
|
|
|
void SetPopupFrame(nsFrameList& aChildList);
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
/**
|
|
|
|
* Get the popup frame list from the frame property.
|
2012-07-30 07:20:58 -07:00
|
|
|
* @return the property value if it exists, nullptr otherwise.
|
2012-03-07 17:57:37 -08:00
|
|
|
*/
|
|
|
|
nsFrameList* GetPopupList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the popup list property. The list must exist and be empty.
|
|
|
|
*/
|
|
|
|
void DestroyPopupList();
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// set mMenuParent to the nearest enclosing menu bar or menupopup frame of
|
|
|
|
// aParent (or aParent itself). This is called when initializing the frame,
|
|
|
|
// so aParent should be the expected parent of this frame.
|
|
|
|
void InitMenuParent(nsIFrame* aParent);
|
|
|
|
|
2007-11-17 07:47:38 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Examines the key node and builds the accelerator.
|
2011-09-28 23:19:26 -07:00
|
|
|
void BuildAcceleratorText(bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-17 07:47:38 -08:00
|
|
|
// Called to execute our command handler. This method can destroy the frame.
|
2013-10-01 20:46:03 -07:00
|
|
|
void Execute(mozilla::WidgetGUIEvent *aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-17 07:47:38 -08:00
|
|
|
// This method can destroy the frame
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2012-12-09 09:23:19 -08:00
|
|
|
virtual ~nsMenuFrame() { }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ShouldBlink();
|
2013-10-01 20:46:03 -07:00
|
|
|
void StartBlinking(mozilla::WidgetGUIEvent* aEvent, bool aFlipChecked);
|
2010-04-19 07:12:58 -07:00
|
|
|
void StopBlinking();
|
2013-10-01 20:46:03 -07:00
|
|
|
void CreateMenuCommandEvent(mozilla::WidgetGUIEvent* aEvent,
|
|
|
|
bool aFlipChecked);
|
2010-04-19 07:12:58 -07:00
|
|
|
void PassMenuCommandEventToPopupManager();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
#ifdef DEBUG_LAYOUT
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
NS_HIDDEN_(nsresult) Notify(nsITimer* aTimer);
|
|
|
|
|
2011-09-28 23:19:26 -07: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
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuType mType;
|
|
|
|
|
2008-12-05 08:37:31 -08:00
|
|
|
nsMenuParent* mMenuParent; // Our parent menu.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Reference to the mediator which wraps this frame.
|
|
|
|
nsRefPtr<nsMenuTimerMediator> mTimerMediator;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mOpenTimer;
|
2010-04-19 07:12:58 -07:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mBlinkState; // 0: not blinking, 1: off, 2: on
|
2010-04-19 07:12:58 -07:00
|
|
|
nsRefPtr<nsXULMenuCommandEvent> mDelayedMenuCommandEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsString mGroupName;
|
|
|
|
|
|
|
|
}; // class nsMenuFrame
|
|
|
|
|
|
|
|
#endif
|