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_HTMLSharedObjectElement_h
8 : #define mozilla_dom_HTMLSharedObjectElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "nsGenericHTMLElement.h"
12 : #include "nsObjectLoadingContent.h"
13 : #include "nsGkAtoms.h"
14 : #include "nsError.h"
15 : #include "nsIDOMHTMLAppletElement.h"
16 : #include "nsIDOMHTMLEmbedElement.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : class HTMLSharedObjectElement final : public nsGenericHTMLElement
22 : , public nsObjectLoadingContent
23 : , public nsIDOMHTMLAppletElement
24 : , public nsIDOMHTMLEmbedElement
25 : {
26 : public:
27 : explicit HTMLSharedObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
28 : mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
29 :
30 : // nsISupports
31 : NS_DECL_ISUPPORTS_INHERITED
32 :
33 : virtual int32_t TabIndexDefault() override;
34 :
35 : #ifdef XP_MACOSX
36 : // nsIDOMEventTarget
37 : NS_IMETHOD PostHandleEvent(EventChainPostVisitor& aVisitor) override;
38 : #endif
39 :
40 : // nsIDOMHTMLAppletElement
41 : NS_DECL_NSIDOMHTMLAPPLETELEMENT
42 :
43 : // Can't use macro for nsIDOMHTMLEmbedElement because it has conflicts with
44 : // NS_DECL_NSIDOMHTMLAPPLETELEMENT.
45 :
46 : // EventTarget
47 : virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
48 :
49 : // nsIDOMHTMLEmbedElement
50 : NS_IMETHOD GetSrc(nsAString &aSrc) override;
51 : NS_IMETHOD SetSrc(const nsAString &aSrc) override;
52 : NS_IMETHOD GetType(nsAString &aType) override;
53 : NS_IMETHOD SetType(const nsAString &aType) override;
54 :
55 : virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
56 : nsIContent *aBindingParent,
57 : bool aCompileEventHandlers) override;
58 : virtual void UnbindFromTree(bool aDeep = true,
59 : bool aNullParent = true) override;
60 :
61 : virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override;
62 : virtual IMEState GetDesiredIMEState() override;
63 :
64 : virtual void DoneAddingChildren(bool aHaveNotified) override;
65 : virtual bool IsDoneAddingChildren() override;
66 :
67 : virtual bool ParseAttribute(int32_t aNamespaceID,
68 : nsIAtom *aAttribute,
69 : const nsAString &aValue,
70 : nsAttrValue &aResult) override;
71 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
72 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom *aAttribute) const override;
73 : virtual EventStates IntrinsicState() const override;
74 : virtual void DestroyContent() override;
75 :
76 : // nsObjectLoadingContent
77 : virtual uint32_t GetCapabilities() const override;
78 :
79 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
80 : bool aPreallocateChildren) const override;
81 :
82 : nsresult CopyInnerTo(Element* aDest, bool aPreallocateChildren);
83 :
84 0 : void StartObjectLoad() { StartObjectLoad(true, false); }
85 :
86 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(HTMLSharedObjectElement,
87 : nsGenericHTMLElement)
88 :
89 : // WebIDL API for <applet>
90 0 : void GetAlign(DOMString& aValue)
91 : {
92 0 : GetHTMLAttr(nsGkAtoms::align, aValue);
93 0 : }
94 0 : void SetAlign(const nsAString& aValue, ErrorResult& aRv)
95 : {
96 0 : SetHTMLAttr(nsGkAtoms::align, aValue, aRv);
97 0 : }
98 0 : void GetAlt(DOMString& aValue)
99 : {
100 0 : GetHTMLAttr(nsGkAtoms::alt, aValue);
101 0 : }
102 0 : void SetAlt(const nsAString& aValue, ErrorResult& aRv)
103 : {
104 0 : SetHTMLAttr(nsGkAtoms::alt, aValue, aRv);
105 0 : }
106 0 : void GetArchive(DOMString& aValue)
107 : {
108 0 : GetHTMLAttr(nsGkAtoms::archive, aValue);
109 0 : }
110 0 : void SetArchive(const nsAString& aValue, ErrorResult& aRv)
111 : {
112 0 : SetHTMLAttr(nsGkAtoms::archive, aValue, aRv);
113 0 : }
114 0 : void GetCode(DOMString& aValue)
115 : {
116 0 : GetHTMLAttr(nsGkAtoms::code, aValue);
117 0 : }
118 0 : void SetCode(const nsAString& aValue, ErrorResult& aRv)
119 : {
120 0 : SetHTMLAttr(nsGkAtoms::code, aValue, aRv);
121 0 : }
122 : // XPCOM GetCodebase is ok; note that it's a URI attribute
123 0 : void SetCodeBase(const nsAString& aValue, ErrorResult& aRv)
124 : {
125 0 : SetHTMLAttr(nsGkAtoms::codebase, aValue, aRv);
126 0 : }
127 0 : void GetHeight(DOMString& aValue)
128 : {
129 0 : GetHTMLAttr(nsGkAtoms::height, aValue);
130 0 : }
131 0 : void SetHeight(const nsAString& aValue, ErrorResult& aRv)
132 : {
133 0 : SetHTMLAttr(nsGkAtoms::height, aValue, aRv);
134 0 : }
135 0 : uint32_t Hspace()
136 : {
137 0 : return GetUnsignedIntAttr(nsGkAtoms::hspace, 0);
138 : }
139 0 : void SetHspace(uint32_t aValue, ErrorResult& aRv)
140 : {
141 0 : SetUnsignedIntAttr(nsGkAtoms::hspace, aValue, 0, aRv);
142 0 : }
143 0 : void GetName(DOMString& aValue)
144 : {
145 0 : GetHTMLAttr(nsGkAtoms::name, aValue);
146 0 : }
147 0 : void SetName(const nsAString& aValue, ErrorResult& aRv)
148 : {
149 0 : SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
150 0 : }
151 : // XPCOM GetObject is ok; note that it's a URI attribute with a weird base URI
152 0 : void SetObject(const nsAString& aValue, ErrorResult& aRv)
153 : {
154 0 : SetHTMLAttr(nsGkAtoms::object, aValue, aRv);
155 0 : }
156 0 : uint32_t Vspace()
157 : {
158 0 : return GetUnsignedIntAttr(nsGkAtoms::vspace, 0);
159 : }
160 0 : void SetVspace(uint32_t aValue, ErrorResult& aRv)
161 : {
162 0 : SetUnsignedIntAttr(nsGkAtoms::vspace, aValue, 0, aRv);
163 0 : }
164 0 : void GetWidth(DOMString& aValue)
165 : {
166 0 : GetHTMLAttr(nsGkAtoms::width, aValue);
167 0 : }
168 0 : void SetWidth(const nsAString& aValue, ErrorResult& aRv)
169 : {
170 0 : SetHTMLAttr(nsGkAtoms::width, aValue, aRv);
171 0 : }
172 :
173 : // WebIDL <embed> api
174 : // XPCOM GetSrc is ok; note that it's a URI attribute
175 0 : void SetSrc(const nsAString& aValue, ErrorResult& aRv)
176 : {
177 0 : SetHTMLAttr(nsGkAtoms::src, aValue, aRv);
178 0 : }
179 0 : void GetType(DOMString& aValue)
180 : {
181 0 : GetHTMLAttr(nsGkAtoms::type, aValue);
182 0 : }
183 0 : void SetType(const nsAString& aValue, ErrorResult& aRv)
184 : {
185 0 : SetHTMLAttr(nsGkAtoms::type, aValue, aRv);
186 0 : }
187 : // width covered by <applet>
188 : // height covered by <applet>
189 : // align covered by <applet>
190 : // name covered by <applet>
191 : nsIDocument*
192 0 : GetSVGDocument(nsIPrincipal& aSubjectPrincipal)
193 : {
194 0 : return GetContentDocument(aSubjectPrincipal);
195 : }
196 :
197 : /**
198 : * Calls LoadObject with the correct arguments to start the plugin load.
199 : */
200 : void StartObjectLoad(bool aNotify, bool aForceLoad);
201 :
202 : protected:
203 : // Override for nsImageLoadingContent.
204 0 : nsIContent* AsContent() override { return this; }
205 :
206 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
207 : const nsAttrValue* aValue,
208 : const nsAttrValue* aOldValue,
209 : bool aNotify) override;
210 : virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsIAtom* aName,
211 : const nsAttrValueOrString& aValue,
212 : bool aNotify) override;
213 :
214 : private:
215 : virtual ~HTMLSharedObjectElement();
216 :
217 0 : nsIAtom *URIAttrName() const
218 : {
219 0 : return mNodeInfo->Equals(nsGkAtoms::applet) ?
220 : nsGkAtoms::code :
221 0 : nsGkAtoms::src;
222 : }
223 :
224 : nsContentPolicyType GetContentPolicyType() const override;
225 :
226 : // mIsDoneAddingChildren is only really used for <applet>. This boolean is
227 : // always true for <embed>, per the documentation in nsIContent.h.
228 : bool mIsDoneAddingChildren;
229 :
230 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
231 :
232 : static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
233 : GenericSpecifiedValues* aGenericData);
234 :
235 : /**
236 : * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
237 : * It will not be called if the value is being unset.
238 : *
239 : * @param aNamespaceID the namespace of the attr being set
240 : * @param aName the localname of the attribute being set
241 : * @param aNotify Whether we plan to notify document observers.
242 : */
243 : nsresult AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
244 : bool aNotify);
245 : };
246 :
247 : } // namespace dom
248 : } // namespace mozilla
249 :
250 : #endif // mozilla_dom_HTMLSharedObjectElement_h
|