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_HTMLSharedElement_h
8 : #define mozilla_dom_HTMLSharedElement_h
9 :
10 : #include "nsIDOMHTMLBaseElement.h"
11 : #include "nsIDOMHTMLDirectoryElement.h"
12 : #include "nsIDOMHTMLQuoteElement.h"
13 : #include "nsIDOMHTMLHeadElement.h"
14 : #include "nsIDOMHTMLHtmlElement.h"
15 : #include "nsGenericHTMLElement.h"
16 :
17 : #include "nsGkAtoms.h"
18 :
19 : #include "mozilla/Attributes.h"
20 : #include "mozilla/Assertions.h"
21 :
22 : namespace mozilla {
23 : namespace dom {
24 :
25 : class HTMLSharedElement final : public nsGenericHTMLElement,
26 : public nsIDOMHTMLBaseElement,
27 : public nsIDOMHTMLDirectoryElement,
28 : public nsIDOMHTMLQuoteElement,
29 : public nsIDOMHTMLHeadElement,
30 : public nsIDOMHTMLHtmlElement
31 : {
32 : public:
33 14 : explicit HTMLSharedElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
34 14 : : nsGenericHTMLElement(aNodeInfo)
35 : {
36 21 : if (mNodeInfo->Equals(nsGkAtoms::head) ||
37 7 : mNodeInfo->Equals(nsGkAtoms::html)) {
38 14 : SetHasWeirdParserInsertionMode();
39 : }
40 14 : }
41 :
42 : // nsISupports
43 : NS_DECL_ISUPPORTS_INHERITED
44 :
45 : // nsIDOMHTMLBaseElement
46 : NS_DECL_NSIDOMHTMLBASEELEMENT
47 :
48 : // nsIDOMHTMLQuoteElement
49 : NS_DECL_NSIDOMHTMLQUOTEELEMENT
50 :
51 : // nsIDOMHTMLHeadElement
52 : NS_DECL_NSIDOMHTMLHEADELEMENT
53 :
54 : // nsIDOMHTMLHtmlElement
55 : NS_DECL_NSIDOMHTMLHTMLELEMENT
56 :
57 : // nsIContent
58 : virtual bool ParseAttribute(int32_t aNamespaceID,
59 : nsIAtom* aAttribute,
60 : const nsAString& aValue,
61 : nsAttrValue& aResult) override;
62 :
63 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
64 : nsIContent* aBindingParent,
65 : bool aCompileEventHandlers) override;
66 :
67 : virtual void UnbindFromTree(bool aDeep = true,
68 : bool aNullParent = true) override;
69 :
70 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
71 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
72 :
73 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
74 : bool aPreallocateChildren) const override;
75 :
76 : // WebIDL API
77 : // HTMLParamElement
78 0 : void GetName(DOMString& aValue)
79 : {
80 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
81 0 : GetHTMLAttr(nsGkAtoms::name, aValue);
82 0 : }
83 0 : void SetName(const nsAString& aValue, ErrorResult& aResult)
84 : {
85 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
86 0 : SetHTMLAttr(nsGkAtoms::name, aValue, aResult);
87 0 : }
88 0 : void GetValue(DOMString& aValue)
89 : {
90 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
91 0 : GetHTMLAttr(nsGkAtoms::value, aValue);
92 0 : }
93 0 : void SetValue(const nsAString& aValue, ErrorResult& aResult)
94 : {
95 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
96 0 : SetHTMLAttr(nsGkAtoms::value, aValue, aResult);
97 0 : }
98 0 : void GetType(DOMString& aValue)
99 : {
100 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
101 0 : GetHTMLAttr(nsGkAtoms::type, aValue);
102 0 : }
103 0 : void SetType(const nsAString& aValue, ErrorResult& aResult)
104 : {
105 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
106 0 : SetHTMLAttr(nsGkAtoms::type, aValue, aResult);
107 0 : }
108 0 : void GetValueType(DOMString& aValue)
109 : {
110 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
111 0 : GetHTMLAttr(nsGkAtoms::valuetype, aValue);
112 0 : }
113 0 : void SetValueType(const nsAString& aValue, ErrorResult& aResult)
114 : {
115 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::param));
116 0 : SetHTMLAttr(nsGkAtoms::valuetype, aValue, aResult);
117 0 : }
118 :
119 : // HTMLBaseElement
120 0 : void GetTarget(DOMString& aValue)
121 : {
122 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::base));
123 0 : GetHTMLAttr(nsGkAtoms::target, aValue);
124 0 : }
125 0 : void SetTarget(const nsAString& aValue, ErrorResult& aResult)
126 : {
127 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::base));
128 0 : SetHTMLAttr(nsGkAtoms::target, aValue, aResult);
129 0 : }
130 : // The XPCOM GetHref is fine for us
131 0 : void SetHref(const nsAString& aValue, ErrorResult& aResult)
132 : {
133 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::base));
134 0 : SetHTMLAttr(nsGkAtoms::href, aValue, aResult);
135 0 : }
136 :
137 : // HTMLDirectoryElement
138 0 : bool Compact() const
139 : {
140 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::dir));
141 0 : return GetBoolAttr(nsGkAtoms::compact);
142 : }
143 0 : void SetCompact(bool aCompact, ErrorResult& aResult)
144 : {
145 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::dir));
146 0 : SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aResult);
147 0 : }
148 :
149 : // HTMLQuoteElement
150 : // The XPCOM GetCite works fine for us
151 0 : void SetCite(const nsAString& aValue, ErrorResult& aResult)
152 : {
153 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::q) ||
154 : mNodeInfo->Equals(nsGkAtoms::blockquote));
155 0 : SetHTMLAttr(nsGkAtoms::cite, aValue, aResult);
156 0 : }
157 :
158 : // HTMLHtmlElement
159 0 : void GetVersion(DOMString& aValue)
160 : {
161 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::html));
162 0 : GetHTMLAttr(nsGkAtoms::version, aValue);
163 0 : }
164 0 : void SetVersion(const nsAString& aValue, ErrorResult& aResult)
165 : {
166 0 : MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::html));
167 0 : SetHTMLAttr(nsGkAtoms::version, aValue, aResult);
168 0 : }
169 :
170 : protected:
171 : virtual ~HTMLSharedElement();
172 :
173 : virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
174 :
175 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
176 : const nsAttrValue* aValue,
177 : const nsAttrValue* aOldValue,
178 : bool aNotify) override;
179 : };
180 :
181 : } // namespace dom
182 : } // namespace mozilla
183 :
184 : #endif // mozilla_dom_HTMLSharedElement_h
|