|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 // |
|
7 // nsMenuBarFrame |
|
8 // |
|
9 |
|
10 #ifndef nsMenuBarFrame_h__ |
|
11 #define nsMenuBarFrame_h__ |
|
12 |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "nsIAtom.h" |
|
15 #include "nsCOMPtr.h" |
|
16 #include "nsBoxFrame.h" |
|
17 #include "nsMenuFrame.h" |
|
18 #include "nsMenuBarListener.h" |
|
19 #include "nsMenuParent.h" |
|
20 |
|
21 class nsIContent; |
|
22 |
|
23 nsIFrame* NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
24 |
|
25 class nsMenuBarFrame : public nsBoxFrame, public nsMenuParent |
|
26 { |
|
27 public: |
|
28 NS_DECL_QUERYFRAME_TARGET(nsMenuBarFrame) |
|
29 NS_DECL_QUERYFRAME |
|
30 NS_DECL_FRAMEARENA_HELPERS |
|
31 |
|
32 nsMenuBarFrame(nsIPresShell* aShell, nsStyleContext* aContext); |
|
33 |
|
34 // nsMenuParent interface |
|
35 virtual nsMenuFrame* GetCurrentMenuItem() MOZ_OVERRIDE; |
|
36 NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) MOZ_OVERRIDE; |
|
37 virtual void CurrentMenuIsBeingDestroyed() MOZ_OVERRIDE; |
|
38 NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem) MOZ_OVERRIDE; |
|
39 |
|
40 NS_IMETHOD SetActive(bool aActiveFlag) MOZ_OVERRIDE; |
|
41 |
|
42 virtual bool IsMenuBar() MOZ_OVERRIDE { return true; } |
|
43 virtual bool IsContextMenu() MOZ_OVERRIDE { return false; } |
|
44 virtual bool IsActive() MOZ_OVERRIDE { return mIsActive; } |
|
45 virtual bool IsMenu() MOZ_OVERRIDE { return false; } |
|
46 virtual bool IsOpen() MOZ_OVERRIDE { return true; } // menubars are considered always open |
|
47 |
|
48 bool IsMenuOpen() { return mCurrentMenu && mCurrentMenu->IsOpen(); } |
|
49 |
|
50 void InstallKeyboardNavigator(); |
|
51 void RemoveKeyboardNavigator(); |
|
52 |
|
53 virtual void Init(nsIContent* aContent, |
|
54 nsIFrame* aParent, |
|
55 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
56 |
|
57 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
58 |
|
59 virtual void LockMenuUntilClosed(bool aLock) MOZ_OVERRIDE {} |
|
60 virtual bool IsMenuLocked() MOZ_OVERRIDE { return false; } |
|
61 |
|
62 // Non-interface helpers |
|
63 |
|
64 // The 'stay active' flag is set when navigating from one top-level menu |
|
65 // to another, to prevent the menubar from deactivating and submenus from |
|
66 // firing extra DOMMenuItemActive events. |
|
67 bool GetStayActive() { return mStayActive; } |
|
68 void SetStayActive(bool aStayActive) { mStayActive = aStayActive; } |
|
69 |
|
70 // Called when a menu on the menu bar is clicked on. Returns a menu if one |
|
71 // needs to be closed. |
|
72 nsMenuFrame* ToggleMenuActiveState(); |
|
73 |
|
74 bool IsActiveByKeyboard() { return mActiveByKeyboard; } |
|
75 void SetActiveByKeyboard() { mActiveByKeyboard = true; } |
|
76 |
|
77 // indicate that a menu on the menubar was closed. Returns true if the caller |
|
78 // may deselect the menuitem. |
|
79 virtual bool MenuClosed() MOZ_OVERRIDE; |
|
80 |
|
81 // Called when Enter is pressed while the menubar is focused. If the current |
|
82 // menu is open, let the child handle the key. |
|
83 nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent); |
|
84 |
|
85 // Used to handle ALT+key combos |
|
86 nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent); |
|
87 |
|
88 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
89 { |
|
90 // Override bogus IsFrameOfType in nsBoxFrame. |
|
91 if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced)) |
|
92 return false; |
|
93 return nsBoxFrame::IsFrameOfType(aFlags); |
|
94 } |
|
95 |
|
96 #ifdef DEBUG_FRAME_DUMP |
|
97 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
|
98 { |
|
99 return MakeFrameName(NS_LITERAL_STRING("MenuBar"), aResult); |
|
100 } |
|
101 #endif |
|
102 |
|
103 protected: |
|
104 nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events. |
|
105 |
|
106 // flag that is temporarily set when switching from one menu on the menubar to another |
|
107 // to indicate that the menubar should not be deactivated. |
|
108 bool mStayActive; |
|
109 |
|
110 bool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown). |
|
111 |
|
112 // whether the menubar was made active via the keyboard. |
|
113 bool mActiveByKeyboard; |
|
114 |
|
115 // The current menu that is active (highlighted), which may not be open. This will |
|
116 // be null if no menu is active. |
|
117 nsMenuFrame* mCurrentMenu; |
|
118 |
|
119 mozilla::dom::EventTarget* mTarget; |
|
120 |
|
121 }; // class nsMenuBarFrame |
|
122 |
|
123 #endif |