Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLMenuItemElement.h
blob6e1d7aa55c87f9aed3ce796912f3e6578dd28d56
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"
13 namespace mozilla {
15 class EventChainPreVisitor;
17 namespace dom {
19 class Visitor;
21 class HTMLMenuItemElement final : public nsGenericHTMLElement {
22 public:
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)
30 // nsISupports
31 NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLMenuItemElement,
32 nsGenericHTMLElement)
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; }
50 /**
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);
58 // WebIDL
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)) {
68 GetText(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);
103 protected:
104 virtual ~HTMLMenuItemElement();
106 virtual JSObject* WrapNode(JSContext* aCx,
107 JS::Handle<JSObject*> aGivenProto) override;
109 protected:
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();
122 void InitChecked();
124 friend class ClearCheckedVisitor;
125 friend class SetCheckedDirtyVisitor;
127 void ClearChecked() { mChecked = false; }
128 void SetCheckedDirty() { mCheckedDirty = true; }
130 private:
131 uint8_t mType : 2;
132 bool mParserCreating : 1;
133 bool mShouldInitChecked : 1;
134 bool mCheckedDirty : 1;
135 bool mChecked : 1;
138 } // namespace dom
139 } // namespace mozilla
141 #endif // mozilla_dom_HTMLMenuItemElement_h