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