michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // michael@0: // nsMenuBarFrame michael@0: // michael@0: michael@0: #ifndef nsMenuBarFrame_h__ michael@0: #define nsMenuBarFrame_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsBoxFrame.h" michael@0: #include "nsMenuFrame.h" michael@0: #include "nsMenuBarListener.h" michael@0: #include "nsMenuParent.h" michael@0: michael@0: class nsIContent; michael@0: michael@0: nsIFrame* NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: class nsMenuBarFrame : public nsBoxFrame, public nsMenuParent michael@0: { michael@0: public: michael@0: NS_DECL_QUERYFRAME_TARGET(nsMenuBarFrame) michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: nsMenuBarFrame(nsIPresShell* aShell, nsStyleContext* aContext); michael@0: michael@0: // nsMenuParent interface michael@0: virtual nsMenuFrame* GetCurrentMenuItem() MOZ_OVERRIDE; michael@0: NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) MOZ_OVERRIDE; michael@0: virtual void CurrentMenuIsBeingDestroyed() MOZ_OVERRIDE; michael@0: NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD SetActive(bool aActiveFlag) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsMenuBar() MOZ_OVERRIDE { return true; } michael@0: virtual bool IsContextMenu() MOZ_OVERRIDE { return false; } michael@0: virtual bool IsActive() MOZ_OVERRIDE { return mIsActive; } michael@0: virtual bool IsMenu() MOZ_OVERRIDE { return false; } michael@0: virtual bool IsOpen() MOZ_OVERRIDE { return true; } // menubars are considered always open michael@0: michael@0: bool IsMenuOpen() { return mCurrentMenu && mCurrentMenu->IsOpen(); } michael@0: michael@0: void InstallKeyboardNavigator(); michael@0: void RemoveKeyboardNavigator(); michael@0: michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual void LockMenuUntilClosed(bool aLock) MOZ_OVERRIDE {} michael@0: virtual bool IsMenuLocked() MOZ_OVERRIDE { return false; } michael@0: michael@0: // Non-interface helpers michael@0: michael@0: // The 'stay active' flag is set when navigating from one top-level menu michael@0: // to another, to prevent the menubar from deactivating and submenus from michael@0: // firing extra DOMMenuItemActive events. michael@0: bool GetStayActive() { return mStayActive; } michael@0: void SetStayActive(bool aStayActive) { mStayActive = aStayActive; } michael@0: michael@0: // Called when a menu on the menu bar is clicked on. Returns a menu if one michael@0: // needs to be closed. michael@0: nsMenuFrame* ToggleMenuActiveState(); michael@0: michael@0: bool IsActiveByKeyboard() { return mActiveByKeyboard; } michael@0: void SetActiveByKeyboard() { mActiveByKeyboard = true; } michael@0: michael@0: // indicate that a menu on the menubar was closed. Returns true if the caller michael@0: // may deselect the menuitem. michael@0: virtual bool MenuClosed() MOZ_OVERRIDE; michael@0: michael@0: // Called when Enter is pressed while the menubar is focused. If the current michael@0: // menu is open, let the child handle the key. michael@0: nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent); michael@0: michael@0: // Used to handle ALT+key combos michael@0: nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent); michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: // Override bogus IsFrameOfType in nsBoxFrame. michael@0: if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced)) michael@0: return false; michael@0: return nsBoxFrame::IsFrameOfType(aFlags); michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("MenuBar"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: protected: michael@0: nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events. michael@0: michael@0: // flag that is temporarily set when switching from one menu on the menubar to another michael@0: // to indicate that the menubar should not be deactivated. michael@0: bool mStayActive; michael@0: michael@0: bool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown). michael@0: michael@0: // whether the menubar was made active via the keyboard. michael@0: bool mActiveByKeyboard; michael@0: michael@0: // The current menu that is active (highlighted), which may not be open. This will michael@0: // be null if no menu is active. michael@0: nsMenuFrame* mCurrentMenu; michael@0: michael@0: mozilla::dom::EventTarget* mTarget; michael@0: michael@0: }; // class nsMenuBarFrame michael@0: michael@0: #endif