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/. */
7 #ifndef XULMenuParentElement_h__
8 #define XULMenuParentElement_h__
10 #include "mozilla/Attributes.h"
11 #include "nsISupports.h"
12 #include "nsXULElement.h"
14 namespace mozilla::dom
{
17 class XULButtonElement
;
19 nsXULElement
* NS_NewXULMenuParentElement(
20 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
22 class XULMenuParentElement
: public nsXULElement
{
24 NS_DECL_ISUPPORTS_INHERITED
25 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULMenuParentElement
, nsXULElement
)
27 explicit XULMenuParentElement(
28 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
30 bool IsMenuBar() const { return NodeInfo()->Equals(nsGkAtoms::menubar
); }
31 bool IsMenu() const { return !IsMenuBar(); }
33 bool IsLocked() const { return mLocked
; }
35 void LockMenuUntilClosed(bool aLock
);
37 bool IsInMenuList() const {
38 return GetParent() && GetParent()->IsXULElement(nsGkAtoms::menulist
);
41 XULButtonElement
* FindMenuWithShortcut(KeyboardEvent
&) const;
42 XULButtonElement
* FindMenuWithShortcut(const nsAString
& aString
,
43 bool& aDoAction
) const;
44 MOZ_CAN_RUN_SCRIPT
void HandleEnterKeyPress(WidgetEvent
&);
46 NS_IMPL_FROMNODE_HELPER(XULMenuParentElement
,
47 IsAnyOfXULElements(nsGkAtoms::menupopup
,
48 nsGkAtoms::popup
, nsGkAtoms::panel
,
52 XULButtonElement
* GetActiveMenuChild() const { return mActiveItem
.get(); }
53 enum class ByKey
: bool { No
, Yes
};
54 MOZ_CAN_RUN_SCRIPT
void SetActiveMenuChild(XULButtonElement
*,
57 XULButtonElement
* GetFirstMenuItem() const;
58 XULButtonElement
* GetLastMenuItem() const;
60 XULButtonElement
* GetNextMenuItemFrom(const XULButtonElement
&) const;
61 XULButtonElement
* GetPrevMenuItemFrom(const XULButtonElement
&) const;
63 enum class Wrap
: bool { No
, Yes
};
64 XULButtonElement
* GetNextMenuItem(Wrap
= Wrap::Yes
) const;
65 XULButtonElement
* GetPrevMenuItem(Wrap
= Wrap::Yes
) const;
67 XULButtonElement
* GetContainingMenu() const;
69 MOZ_CAN_RUN_SCRIPT
void SelectFirstItem();
72 RefPtr
<XULButtonElement
> mActiveItem
;
75 ~XULMenuParentElement() override
;
78 } // namespace mozilla::dom
80 #endif // XULMenuParentElement_h