XULButtonElement.h (4385B)
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 #ifndef dom_xul_XULButtonElement_h__ 8 #define dom_xul_XULButtonElement_h__ 9 10 #include "mozilla/Attributes.h" 11 #include "nsINode.h" 12 #include "nsXULElement.h" 13 14 class nsMenuBarFrame; 15 class nsMenuPopupFrame; 16 class nsXULMenuCommandEvent; 17 18 namespace mozilla::dom { 19 20 class KeyboardEvent; 21 class XULPopupElement; 22 class XULMenuBarElement; 23 class XULMenuParentElement; 24 25 class XULButtonElement : public nsXULElement { 26 public: 27 explicit XULButtonElement( 28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 29 30 ~XULButtonElement() override; 31 32 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool OnPointerClicked(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&); 36 37 void PopupOpened(); 38 MOZ_CAN_RUN_SCRIPT void PopupClosed(bool aDeselectMenu); 39 40 XULPopupElement* GetContainingPopupElement() const; 41 nsMenuPopupFrame* GetContainingPopupWithoutFlushing() const; 42 MOZ_CAN_RUN_SCRIPT void ToggleMenuState(); 43 bool IsMenuPopupOpen(); 44 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); 50 51 bool IsOnMenu() const; 52 bool IsOnMenuList() const; 53 bool IsOnMenuBar() const; 54 bool IsOnContextMenu() const; 55 56 XULMenuParentElement* GetMenuParent() const; 57 58 void UnbindFromTree(UnbindContext&) override; 59 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, 65 bool aIsTrusted); 66 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. 71 bool IsMenu() const; 72 73 nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute, 74 AttrModType aModType) const override; 75 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, 76 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 77 nsIPrincipal* aSubjectPrincipal, bool aNotify) override; 78 79 NS_IMPL_FROMNODE_HELPER(XULButtonElement, 80 IsAnyOfXULElements(nsGkAtoms::checkbox, 81 nsGkAtoms::radio, nsGkAtoms::thumb, 82 nsGkAtoms::button, nsGkAtoms::menu, 83 nsGkAtoms::menulist, 84 nsGkAtoms::menuitem, 85 nsGkAtoms::toolbarbutton, 86 nsGkAtoms::toolbarpaletteitem, 87 nsGkAtoms::scrollbarbutton)) 88 89 nsMenuPopupFrame* GetMenuPopup(FlushType aFlushType); 90 nsMenuPopupFrame* GetMenuPopupWithoutFlushing() const; 91 XULPopupElement* GetMenuPopupContent() const; 92 int32_t MenuOpenCloseDelay() const; 93 94 private: 95 XULMenuBarElement* GetMenuBar() const; 96 void Blurred(); 97 enum class MenuType { 98 Checkbox, 99 Radio, 100 Normal, 101 }; 102 Maybe<MenuType> GetMenuType() const; 103 104 void UncheckRadioSiblings(); 105 void StopBlinking(); 106 MOZ_CAN_RUN_SCRIPT void StartBlinking(); 107 void KillMenuOpenTimer(); 108 MOZ_CAN_RUN_SCRIPT void PassMenuCommandEventToPopupManager(); 109 110 bool mIsHandlingKeyEvent = false; 111 112 // Whether this is a XULMenuElement. 113 const bool mIsAlwaysMenu : 1; 114 // Whether this supports the `checked` attribute. 115 const bool mCheckable : 1; 116 RefPtr<nsXULMenuCommandEvent> mDelayedMenuCommandEvent; 117 nsCOMPtr<nsITimer> mMenuOpenTimer; 118 nsCOMPtr<nsITimer> mMenuBlinkTimer; 119 }; 120 121 } // namespace mozilla::dom 122 123 #endif