Line data Source code
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 mozilla_dom_HTMLMenuItemElement_h
8 : #define mozilla_dom_HTMLMenuItemElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "nsIDOMHTMLMenuItemElement.h"
12 : #include "nsGenericHTMLElement.h"
13 :
14 : namespace mozilla {
15 :
16 : class EventChainPreVisitor;
17 :
18 : namespace dom {
19 :
20 : class Visitor;
21 :
22 : class HTMLMenuItemElement final : public nsGenericHTMLElement,
23 : public nsIDOMHTMLMenuItemElement
24 : {
25 : public:
26 : using mozilla::dom::Element::GetText;
27 :
28 : HTMLMenuItemElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
29 : mozilla::dom::FromParser aFromParser);
30 :
31 0 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuItemElement, menuitem)
32 :
33 : // nsISupports
34 : NS_DECL_ISUPPORTS_INHERITED
35 :
36 : // nsIDOMHTMLMenuItemElement
37 : NS_DECL_NSIDOMHTMLMENUITEMELEMENT
38 :
39 : virtual nsresult GetEventTargetParent(
40 : EventChainPreVisitor& aVisitor) override;
41 : virtual nsresult PostHandleEvent(
42 : EventChainPostVisitor& aVisitor) override;
43 :
44 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
45 : nsIContent* aBindingParent,
46 : bool aCompileEventHandlers) override;
47 :
48 : virtual bool ParseAttribute(int32_t aNamespaceID,
49 : nsIAtom* aAttribute,
50 : const nsAString& aValue,
51 : nsAttrValue& aResult) override;
52 :
53 : virtual void DoneCreatingElement() override;
54 :
55 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
56 : bool aPreallocateChildren) const override;
57 :
58 0 : uint8_t GetType() const { return mType; }
59 :
60 : /**
61 : * Syntax sugar to make it easier to check for checked and checked dirty
62 : */
63 0 : bool IsChecked() const { return mChecked; }
64 0 : bool IsCheckedDirty() const { return mCheckedDirty; }
65 :
66 : void GetText(nsAString& aText);
67 :
68 : // WebIDL
69 :
70 : // The XPCOM GetType is OK for us
71 0 : void SetType(const nsAString& aType, ErrorResult& aError)
72 : {
73 0 : SetHTMLAttr(nsGkAtoms::type, aType, aError);
74 0 : }
75 :
76 : // The XPCOM GetLabel is OK for us
77 0 : void SetLabel(const nsAString& aLabel, ErrorResult& aError)
78 : {
79 0 : SetAttrHelper(nsGkAtoms::label, aLabel);
80 0 : }
81 :
82 : // The XPCOM GetIcon is OK for us
83 0 : void SetIcon(const nsAString& aIcon, ErrorResult& aError)
84 : {
85 0 : SetAttrHelper(nsGkAtoms::icon, aIcon);
86 0 : }
87 :
88 0 : bool Disabled() const
89 : {
90 0 : return GetBoolAttr(nsGkAtoms::disabled);
91 : }
92 0 : void SetDisabled(bool aDisabled, ErrorResult& aError)
93 : {
94 0 : SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
95 0 : }
96 :
97 0 : bool Checked() const
98 : {
99 0 : return mChecked;
100 : }
101 0 : void SetChecked(bool aChecked, ErrorResult& aError)
102 : {
103 0 : aError = SetChecked(aChecked);
104 0 : }
105 :
106 : // The XPCOM GetRadiogroup is OK for us
107 0 : void SetRadiogroup(const nsAString& aRadiogroup, ErrorResult& aError)
108 : {
109 0 : SetHTMLAttr(nsGkAtoms::radiogroup, aRadiogroup, aError);
110 0 : }
111 :
112 0 : bool DefaultChecked() const
113 : {
114 0 : return GetBoolAttr(nsGkAtoms::checked);
115 : }
116 0 : void SetDefaultChecked(bool aDefault, ErrorResult& aError)
117 : {
118 0 : SetHTMLBoolAttr(nsGkAtoms::checked, aDefault, aError);
119 0 : }
120 :
121 : protected:
122 : virtual ~HTMLMenuItemElement();
123 :
124 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
125 :
126 :
127 : protected:
128 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
129 : const nsAttrValue* aValue,
130 : const nsAttrValue* aOldValue,
131 : bool aNotify) override;
132 :
133 : void WalkRadioGroup(Visitor* aVisitor);
134 :
135 : HTMLMenuItemElement* GetSelectedRadio();
136 :
137 : void AddedToRadioGroup();
138 :
139 : void InitChecked();
140 :
141 : friend class ClearCheckedVisitor;
142 : friend class SetCheckedDirtyVisitor;
143 :
144 0 : void ClearChecked() { mChecked = false; }
145 0 : void SetCheckedDirty() { mCheckedDirty = true; }
146 :
147 : private:
148 : uint8_t mType : 2;
149 : bool mParserCreating : 1;
150 : bool mShouldInitChecked : 1;
151 : bool mCheckedDirty : 1;
152 : bool mChecked : 1;
153 : };
154 :
155 : } // namespace dom
156 : } // namespace mozilla
157 :
158 : #endif // mozilla_dom_HTMLMenuItemElement_h
|