2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#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"
|
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
|
|
|
|
2009-01-19 21:31:33 +03:00
|
|
|
nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
nsIFrame* NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsIContent;
|
1999-07-21 11:42:16 +04:00
|
|
|
class nsMenuBarFrame;
|
1999-07-18 10:36:37 +04:00
|
|
|
|
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
|
|
|
|
eReadonlyMenuList, // <menulist/>
|
|
|
|
eEditableMenuList // <menulist editable="true"/>
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-06-19 07:26:34 +04:00
|
|
|
class nsMenuTimerMediator MOZ_FINAL : public nsITimerCallback
|
2006-01-12 19:40:47 +03: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 18:05:07 +04:00
|
|
|
class nsMenuFrame : public nsBoxFrame
|
1999-07-18 10:36:37 +04:00
|
|
|
{
|
|
|
|
public:
|
2006-03-27 01:30:36 +04:00
|
|
|
nsMenuFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
1999-07-18 10:36:37 +04:00
|
|
|
|
2011-07-11 18:05:07 +04:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsMenuFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2012-09-14 20:10:08 +04: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 11:02:06 +04:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
1999-07-21 11:42:16 +04:00
|
|
|
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult SetDebug(nsBoxLayoutState& aState, bool aDebug) MOZ_OVERRIDE;
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
2000-03-02 06:01:30 +03: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.
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual const nsFrameList& GetChildList(ChildListID aList) const MOZ_OVERRIDE;
|
|
|
|
virtual void GetChildLists(nsTArray<ChildList>* aLists) const MOZ_OVERRIDE;
|
2014-02-18 12:36:33 +04:00
|
|
|
virtual nsresult SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_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,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2006-01-26 05:29:17 +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,
|
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
1999-07-20 13:35:35 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AppendFrames(ChildListID aListID,
|
2014-02-18 12:36:33 +04:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
1999-07-31 15:29:03 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult InsertFrames(ChildListID aListID,
|
2014-02-18 12:36:33 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
1999-07-31 15:29:03 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult RemoveFrame(ChildListID aListID,
|
2014-02-18 12:36:33 +04:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
1999-07-31 15:29:03 +04:00
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE { return nsGkAtoms::menuFrame; }
|
1999-07-22 13:01:55 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHOD SelectMenu(bool aActivateFlag);
|
1999-07-20 13:35:35 +04:00
|
|
|
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_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
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
NS_IMETHOD GetActiveChild(nsIDOMElement** aResult);
|
2007-11-17 18:47:38 +03:00
|
|
|
NS_IMETHOD SetActiveChild(nsIDOMElement* 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
|
|
|
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual void SetParent(nsIFrame* aParent) MOZ_OVERRIDE;
|
2000-05-27 02:45:26 +04:00
|
|
|
|
2008-12-05 19:37:31 +03:00
|
|
|
virtual nsMenuParent *GetMenuParent() { return mMenuParent; }
|
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
|
|
|
|
|
|
|
// nsMenuFrame methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsOnMenuBar() { return mMenuParent && mMenuParent->IsMenuBar(); }
|
|
|
|
bool IsOnActiveMenuBar() { return IsOnMenuBar() && mMenuParent->IsActive(); }
|
|
|
|
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.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsOnMenu() { return mMenuParent && mMenuParent->IsMenu(); }
|
|
|
|
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
|
2014-02-18 11:47:48 +04: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-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
|
|
|
|
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-07-04 19:49:38 +04: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 18:47:38 +03: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 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,
|
2014-02-18 12:36:33 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_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:
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug);
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
2006-01-12 19:40:47 +03:00
|
|
|
NS_HIDDEN_(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
|
1999-10-18 01:37:37 +04:00
|
|
|
nsMenuType mType;
|
|
|
|
|
2008-12-05 19:37:31 +03:00
|
|
|
nsMenuParent* mMenuParent; // Our parent menu.
|
2006-01-12 19:40:47 +03:00
|
|
|
|
|
|
|
// Reference to the mediator which wraps this frame.
|
|
|
|
nsRefPtr<nsMenuTimerMediator> mTimerMediator;
|
|
|
|
|
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
|
2010-04-19 18:12:58 +04:00
|
|
|
nsRefPtr<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
|