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 dom_xul_XULButtonElement_h__
8 #define dom_xul_XULButtonElement_h__
10 #include "mozilla/Attributes.h"
12 #include "nsXULElement.h"
15 class nsMenuPopupFrame
;
16 class nsXULMenuCommandEvent
;
18 namespace mozilla::dom
{
21 class XULPopupElement
;
22 class XULMenuBarElement
;
23 class XULMenuParentElement
;
25 class XULButtonElement
: public nsXULElement
{
27 explicit XULButtonElement(
28 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
30 ~XULButtonElement() override
;
32 MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool MouseClicked(WidgetGUIEvent
&);
33 MOZ_CAN_RUN_SCRIPT nsresult
PostHandleEvent(EventChainPostVisitor
&) override
;
34 MOZ_CAN_RUN_SCRIPT
void PostHandleEventForMenus(EventChainPostVisitor
&);
35 MOZ_CAN_RUN_SCRIPT
void HandleEnterKeyPress(WidgetEvent
&);
38 MOZ_CAN_RUN_SCRIPT
void PopupClosed(bool aDeselectMenu
);
40 XULPopupElement
* GetContainingPopupElement() const;
41 nsMenuPopupFrame
* GetContainingPopupWithoutFlushing() const;
42 MOZ_CAN_RUN_SCRIPT
void ToggleMenuState();
43 bool IsMenuPopupOpen();
45 bool IsMenuItem() const { return NodeInfo()->Equals(nsGkAtoms::menuitem
); }
46 bool IsMenuList() const { return NodeInfo()->Equals(nsGkAtoms::menulist
); }
47 bool IsMenuActive() const;
48 MOZ_CAN_RUN_SCRIPT
void OpenMenuPopup(bool aSelectFirstItem
);
49 void CloseMenuPopup(bool aDeselectMenu
);
51 bool IsOnMenu() const;
52 bool IsOnMenuList() const;
53 bool IsOnMenuBar() const;
54 bool IsOnContextMenu() const;
56 XULMenuParentElement
* GetMenuParent() const;
58 void UnbindFromTree(bool aNullParent
) override
;
60 MOZ_CAN_RUN_SCRIPT
bool HandleKeyPress(KeyboardEvent
& keyEvent
);
61 bool OpenedWithKey() const;
62 // Called to execute our command handler.
63 MOZ_CAN_RUN_SCRIPT
void ExecuteMenu(WidgetEvent
&);
64 MOZ_CAN_RUN_SCRIPT
void ExecuteMenu(Modifiers
, int16_t aButton
,
67 // Whether we are a menu/menulist/menuitem element.
68 bool IsAlwaysMenu() const { return mIsAlwaysMenu
; }
69 // Whether we should behave like a menu. This is the above plus buttons with
70 // type=menu attribute.
73 nsChangeHint
GetAttributeChangeHint(const nsAtom
* aAttribute
,
74 int32_t aModType
) const override
;
75 nsresult
AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
76 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
77 nsIPrincipal
* aSubjectPrincipal
, bool aNotify
) override
;
79 NS_IMPL_FROMNODE_HELPER(XULButtonElement
,
80 IsAnyOfXULElements(nsGkAtoms::checkbox
,
81 nsGkAtoms::radio
, nsGkAtoms::thumb
,
82 nsGkAtoms::button
, nsGkAtoms::menu
,
85 nsGkAtoms::toolbarbutton
,
86 nsGkAtoms::toolbarpaletteitem
,
87 nsGkAtoms::scrollbarbutton
))
89 nsMenuPopupFrame
* GetMenuPopup(FlushType aFlushType
);
90 nsMenuPopupFrame
* GetMenuPopupWithoutFlushing() const;
91 XULPopupElement
* GetMenuPopupContent() const;
92 int32_t MenuOpenCloseDelay() const;
94 bool IsDisabled() const { return GetXULBoolAttr(nsGkAtoms::disabled
); }
97 XULMenuBarElement
* GetMenuBar() const;
104 Maybe
<MenuType
> GetMenuType() const;
106 void UncheckRadioSiblings();
108 MOZ_CAN_RUN_SCRIPT
void StartBlinking();
109 void KillMenuOpenTimer();
110 MOZ_CAN_RUN_SCRIPT
void PassMenuCommandEventToPopupManager();
112 bool mIsHandlingKeyEvent
= false;
114 // Whether this is a XULMenuElement.
115 const bool mIsAlwaysMenu
;
116 RefPtr
<nsXULMenuCommandEvent
> mDelayedMenuCommandEvent
;
117 nsCOMPtr
<nsITimer
> mMenuOpenTimer
;
118 nsCOMPtr
<nsITimer
> mMenuBlinkTimer
;
121 } // namespace mozilla::dom