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
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuBarFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef nsMenuBarFrame_h__
|
|
|
|
#define nsMenuBarFrame_h__
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsBoxFrame.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsMenuFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMenuBarListener.h"
|
2008-12-05 08:37:31 -08:00
|
|
|
#include "nsMenuParent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
|
|
|
|
|
|
|
nsIFrame* NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class nsMenuBarFrame MOZ_FINAL : public nsBoxFrame, public nsMenuParent
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-09-27 18:46:11 -07:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsMenuBarFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarFrame(nsIPresShell* aShell, nsStyleContext* aContext);
|
|
|
|
|
2008-12-05 08:37:31 -08:00
|
|
|
// nsMenuParent interface
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nsMenuFrame* GetCurrentMenuItem() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) MOZ_OVERRIDE;
|
|
|
|
virtual void CurrentMenuIsBeingDestroyed() MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD SetActive(bool aActiveFlag) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsMenuBar() MOZ_OVERRIDE { return true; }
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual bool IsContextMenu() MOZ_OVERRIDE { return false; }
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsActive() MOZ_OVERRIDE { return mIsActive; }
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual bool IsMenu() MOZ_OVERRIDE { return false; }
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsOpen() MOZ_OVERRIDE { return true; } // menubars are considered always open
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsMenuOpen() { return mCurrentMenu && mCurrentMenu->IsOpen(); }
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void InstallKeyboardNavigator();
|
|
|
|
void RemoveKeyboardNavigator();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void LockMenuUntilClosed(bool aLock) MOZ_OVERRIDE {}
|
|
|
|
virtual bool IsMenuLocked() MOZ_OVERRIDE { return false; }
|
2010-04-19 07:12:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Non-interface helpers
|
|
|
|
|
2013-01-11 12:21:48 -08:00
|
|
|
// The 'stay active' flag is set when navigating from one top-level menu
|
|
|
|
// to another, to prevent the menubar from deactivating and submenus from
|
|
|
|
// firing extra DOMMenuItemActive events.
|
|
|
|
bool GetStayActive() { return mStayActive; }
|
|
|
|
void SetStayActive(bool aStayActive) { mStayActive = aStayActive; }
|
2007-10-03 15:00:41 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// Called when a menu on the menu bar is clicked on. Returns a menu if one
|
|
|
|
// needs to be closed.
|
|
|
|
nsMenuFrame* ToggleMenuActiveState();
|
2007-06-29 12:04:45 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsActiveByKeyboard() { return mActiveByKeyboard; }
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetActiveByKeyboard() { mActiveByKeyboard = true; }
|
2011-01-04 09:24:51 -08:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// indicate that a menu on the menubar was closed. Returns true if the caller
|
|
|
|
// may deselect the menuitem.
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool MenuClosed() MOZ_OVERRIDE;
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// Called when Enter is pressed while the menubar is focused. If the current
|
|
|
|
// menu is open, let the child handle the key.
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// Used to handle ALT+key combos
|
|
|
|
nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Override bogus IsFrameOfType in nsBoxFrame.
|
|
|
|
if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsBoxFrame::IsFrameOfType(aFlags);
|
|
|
|
}
|
|
|
|
|
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("MenuBar"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
|
|
|
|
|
2007-10-03 15:00:41 -07:00
|
|
|
// flag that is temporarily set when switching from one menu on the menubar to another
|
|
|
|
// to indicate that the menubar should not be deactivated.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mStayActive;
|
2007-10-03 15:00:41 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).
|
2011-01-04 09:24:51 -08:00
|
|
|
|
|
|
|
// whether the menubar was made active via the keyboard.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mActiveByKeyboard;
|
2011-01-04 09:24:51 -08:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// The current menu that is active (highlighted), which may not be open. This will
|
|
|
|
// be null if no menu is active.
|
|
|
|
nsMenuFrame* mCurrentMenu;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
mozilla::dom::EventTarget* mTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
}; // class nsMenuBarFrame
|
|
|
|
|
|
|
|
#endif
|