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 mozilla_dom_HTMLMenuItemElement_h
8 #define mozilla_dom_HTMLMenuItemElement_h
10 #include "mozilla/Attributes.h"
11 #include "nsGenericHTMLElement.h"
15 class EventChainPreVisitor
;
21 class HTMLMenuItemElement final
: public nsGenericHTMLElement
{
23 using mozilla::dom::Element::GetText
;
25 HTMLMenuItemElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
26 mozilla::dom::FromParser aFromParser
);
28 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLMenuItemElement
, menuitem
)
31 NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLMenuItemElement
,
34 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
35 virtual nsresult
PostHandleEvent(EventChainPostVisitor
& aVisitor
) override
;
37 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
39 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
40 const nsAString
& aValue
,
41 nsIPrincipal
* aMaybeScriptedPrincipal
,
42 nsAttrValue
& aResult
) override
;
44 virtual void DoneCreatingElement() override
;
46 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
48 uint8_t GetType() const { return mType
; }
51 * Syntax sugar to make it easier to check for checked and checked dirty
53 bool IsChecked() const { return mChecked
; }
54 bool IsCheckedDirty() const { return mCheckedDirty
; }
56 void GetText(nsAString
& aText
);
60 void GetType(DOMString
& aValue
);
61 void SetType(const nsAString
& aType
, ErrorResult
& aError
) {
62 SetHTMLAttr(nsGkAtoms::type
, aType
, aError
);
65 // nsAString needed for HTMLMenuElement
66 void GetLabel(nsAString
& aValue
) {
67 if (!GetAttr(kNameSpaceID_None
, nsGkAtoms::label
, aValue
)) {
71 void SetLabel(const nsAString
& aLabel
, ErrorResult
& aError
) {
72 SetHTMLAttr(nsGkAtoms::label
, aLabel
, aError
);
75 // nsAString needed for HTMLMenuElement
76 void GetIcon(nsAString
& aValue
) {
77 GetURIAttr(nsGkAtoms::icon
, nullptr, aValue
);
79 void SetIcon(const nsAString
& aIcon
, ErrorResult
& aError
) {
80 SetHTMLAttr(nsGkAtoms::icon
, aIcon
, aError
);
83 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled
); }
84 void SetDisabled(bool aDisabled
, ErrorResult
& aError
) {
85 SetHTMLBoolAttr(nsGkAtoms::disabled
, aDisabled
, aError
);
88 bool Checked() const { return mChecked
; }
89 void SetChecked(bool aChecked
);
91 void GetRadiogroup(DOMString
& aValue
) {
92 GetHTMLAttr(nsGkAtoms::radiogroup
, aValue
);
94 void SetRadiogroup(const nsAString
& aRadiogroup
, ErrorResult
& aError
) {
95 SetHTMLAttr(nsGkAtoms::radiogroup
, aRadiogroup
, aError
);
98 bool DefaultChecked() const { return GetBoolAttr(nsGkAtoms::checked
); }
99 void SetDefaultChecked(bool aDefault
, ErrorResult
& aError
) {
100 SetHTMLBoolAttr(nsGkAtoms::checked
, aDefault
, aError
);
104 virtual ~HTMLMenuItemElement();
106 virtual JSObject
* WrapNode(JSContext
* aCx
,
107 JS::Handle
<JSObject
*> aGivenProto
) override
;
110 virtual nsresult
AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
111 const nsAttrValue
* aValue
,
112 const nsAttrValue
* aOldValue
,
113 nsIPrincipal
* aSubjectPrincipal
,
114 bool aNotify
) override
;
116 void WalkRadioGroup(Visitor
* aVisitor
);
118 HTMLMenuItemElement
* GetSelectedRadio();
120 void AddedToRadioGroup();
124 friend class ClearCheckedVisitor
;
125 friend class SetCheckedDirtyVisitor
;
127 void ClearChecked() { mChecked
= false; }
128 void SetCheckedDirty() { mCheckedDirty
= true; }
132 bool mParserCreating
: 1;
133 bool mShouldInitChecked
: 1;
134 bool mCheckedDirty
: 1;
139 } // namespace mozilla
141 #endif // mozilla_dom_HTMLMenuItemElement_h