layout/xul/nsMenuBarFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsMenuBarFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//
    1.10 +// nsMenuBarFrame
    1.11 +//
    1.12 +
    1.13 +#ifndef nsMenuBarFrame_h__
    1.14 +#define nsMenuBarFrame_h__
    1.15 +
    1.16 +#include "mozilla/Attributes.h"
    1.17 +#include "nsIAtom.h"
    1.18 +#include "nsCOMPtr.h"
    1.19 +#include "nsBoxFrame.h"
    1.20 +#include "nsMenuFrame.h"
    1.21 +#include "nsMenuBarListener.h"
    1.22 +#include "nsMenuParent.h"
    1.23 +
    1.24 +class nsIContent;
    1.25 +
    1.26 +nsIFrame* NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.27 +
    1.28 +class nsMenuBarFrame : public nsBoxFrame, public nsMenuParent
    1.29 +{
    1.30 +public:
    1.31 +  NS_DECL_QUERYFRAME_TARGET(nsMenuBarFrame)
    1.32 +  NS_DECL_QUERYFRAME
    1.33 +  NS_DECL_FRAMEARENA_HELPERS
    1.34 +
    1.35 +  nsMenuBarFrame(nsIPresShell* aShell, nsStyleContext* aContext);
    1.36 +
    1.37 +  // nsMenuParent interface
    1.38 +  virtual nsMenuFrame* GetCurrentMenuItem() MOZ_OVERRIDE;
    1.39 +  NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) MOZ_OVERRIDE;
    1.40 +  virtual void CurrentMenuIsBeingDestroyed() MOZ_OVERRIDE;
    1.41 +  NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem) MOZ_OVERRIDE;
    1.42 +
    1.43 +  NS_IMETHOD SetActive(bool aActiveFlag) MOZ_OVERRIDE; 
    1.44 +
    1.45 +  virtual bool IsMenuBar() MOZ_OVERRIDE { return true; }
    1.46 +  virtual bool IsContextMenu() MOZ_OVERRIDE { return false; }
    1.47 +  virtual bool IsActive() MOZ_OVERRIDE { return mIsActive; }
    1.48 +  virtual bool IsMenu() MOZ_OVERRIDE { return false; }
    1.49 +  virtual bool IsOpen() MOZ_OVERRIDE { return true; } // menubars are considered always open
    1.50 +
    1.51 +  bool IsMenuOpen() { return mCurrentMenu && mCurrentMenu->IsOpen(); }
    1.52 +
    1.53 +  void InstallKeyboardNavigator();
    1.54 +  void RemoveKeyboardNavigator();
    1.55 +
    1.56 +  virtual void Init(nsIContent*      aContent,
    1.57 +                    nsIFrame*        aParent,
    1.58 +                    nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    1.59 +
    1.60 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.61 +
    1.62 +  virtual void LockMenuUntilClosed(bool aLock) MOZ_OVERRIDE {}
    1.63 +  virtual bool IsMenuLocked() MOZ_OVERRIDE { return false; }
    1.64 +
    1.65 +// Non-interface helpers
    1.66 +
    1.67 +  // The 'stay active' flag is set when navigating from one top-level menu
    1.68 +  // to another, to prevent the menubar from deactivating and submenus from
    1.69 +  // firing extra DOMMenuItemActive events.
    1.70 +  bool GetStayActive() { return mStayActive; }
    1.71 +  void SetStayActive(bool aStayActive) { mStayActive = aStayActive; }
    1.72 +
    1.73 +  // Called when a menu on the menu bar is clicked on. Returns a menu if one
    1.74 +  // needs to be closed.
    1.75 +  nsMenuFrame* ToggleMenuActiveState();
    1.76 +
    1.77 +  bool IsActiveByKeyboard() { return mActiveByKeyboard; }
    1.78 +  void SetActiveByKeyboard() { mActiveByKeyboard = true; }
    1.79 +
    1.80 +  // indicate that a menu on the menubar was closed. Returns true if the caller
    1.81 +  // may deselect the menuitem.
    1.82 +  virtual bool MenuClosed() MOZ_OVERRIDE;
    1.83 +
    1.84 +  // Called when Enter is pressed while the menubar is focused. If the current
    1.85 +  // menu is open, let the child handle the key.
    1.86 +  nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
    1.87 +
    1.88 +  // Used to handle ALT+key combos
    1.89 +  nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent);
    1.90 +
    1.91 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    1.92 +  {
    1.93 +    // Override bogus IsFrameOfType in nsBoxFrame.
    1.94 +    if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
    1.95 +      return false;
    1.96 +    return nsBoxFrame::IsFrameOfType(aFlags);
    1.97 +  }
    1.98 +
    1.99 +#ifdef DEBUG_FRAME_DUMP
   1.100 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
   1.101 +  {
   1.102 +      return MakeFrameName(NS_LITERAL_STRING("MenuBar"), aResult);
   1.103 +  }
   1.104 +#endif
   1.105 +
   1.106 +protected:
   1.107 +  nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
   1.108 +
   1.109 +  // flag that is temporarily set when switching from one menu on the menubar to another
   1.110 +  // to indicate that the menubar should not be deactivated.
   1.111 +  bool mStayActive;
   1.112 +
   1.113 +  bool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).
   1.114 +
   1.115 +  // whether the menubar was made active via the keyboard.
   1.116 +  bool mActiveByKeyboard;
   1.117 +
   1.118 +  // The current menu that is active (highlighted), which may not be open. This will
   1.119 +  // be null if no menu is active.
   1.120 +  nsMenuFrame* mCurrentMenu;
   1.121 +
   1.122 +  mozilla::dom::EventTarget* mTarget;
   1.123 +
   1.124 +}; // class nsMenuBarFrame
   1.125 +
   1.126 +#endif

mercurial