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_HTMLObjectElement_h
8 #define mozilla_dom_HTMLObjectElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/ConstraintValidation.h"
12 #include "nsGenericHTMLElement.h"
13 #include "nsObjectLoadingContent.h"
15 namespace mozilla::dom
{
20 class WindowProxyHolder
;
22 class HTMLObjectElement final
: public nsGenericHTMLFormControlElement
,
23 public nsObjectLoadingContent
,
24 public ConstraintValidation
{
26 explicit HTMLObjectElement(
27 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
28 FromParser aFromParser
= NOT_FROM_PARSER
);
31 NS_DECL_ISUPPORTS_INHERITED
33 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLObjectElement
, object
)
34 int32_t TabIndexDefault() override
;
36 // nsObjectLoadingContent
37 const Element
* AsElement() const final
{ return this; }
40 bool IsInteractiveHTMLContent() const override
;
42 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
43 void UnbindFromTree(UnbindContext
&) override
;
45 bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
46 int32_t* aTabIndex
) override
;
48 // Overriden nsIFormControl methods
49 NS_IMETHOD
Reset() override
{ return NS_OK
; }
51 NS_IMETHOD
SubmitNamesValues(FormData
* aFormData
) override
{ return NS_OK
; }
53 void DoneAddingChildren(bool aHaveNotified
) override
;
55 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
56 const nsAString
& aValue
,
57 nsIPrincipal
* aMaybeScriptedPrincipal
,
58 nsAttrValue
& aResult
) override
;
59 nsMapRuleToAttributesFunc
GetAttributeMappingFunction() const override
;
60 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
61 void DestroyContent() override
;
63 // nsObjectLoadingContent
64 uint32_t GetCapabilities() const override
;
65 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
67 nsresult
CopyInnerTo(Element
* aDest
);
69 void StartObjectLoad() { StartObjectLoad(true, false); }
71 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLObjectElement
,
72 nsGenericHTMLFormControlElement
)
74 // Web IDL binding methods
75 void GetData(DOMString
& aValue
) {
76 GetURIAttr(nsGkAtoms::data
, nsGkAtoms::codebase
, aValue
);
78 void SetData(const nsAString
& aValue
, ErrorResult
& aRv
) {
79 SetHTMLAttr(nsGkAtoms::data
, aValue
, aRv
);
81 void GetType(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::type
, aValue
); }
82 void SetType(const nsAString
& aValue
, ErrorResult
& aRv
) {
83 SetHTMLAttr(nsGkAtoms::type
, aValue
, aRv
);
85 void GetName(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::name
, aValue
); }
86 void SetName(const nsAString
& aValue
, ErrorResult
& aRv
) {
87 SetHTMLAttr(nsGkAtoms::name
, aValue
, aRv
);
89 void GetUseMap(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::usemap
, aValue
); }
90 void SetUseMap(const nsAString
& aValue
, ErrorResult
& aRv
) {
91 SetHTMLAttr(nsGkAtoms::usemap
, aValue
, aRv
);
93 void GetWidth(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::width
, aValue
); }
94 void SetWidth(const nsAString
& aValue
, ErrorResult
& aRv
) {
95 SetHTMLAttr(nsGkAtoms::width
, aValue
, aRv
);
97 void GetHeight(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::height
, aValue
); }
98 void SetHeight(const nsAString
& aValue
, ErrorResult
& aRv
) {
99 SetHTMLAttr(nsGkAtoms::height
, aValue
, aRv
);
101 using nsObjectLoadingContent::GetContentDocument
;
103 Nullable
<WindowProxyHolder
> GetContentWindow(nsIPrincipal
& aSubjectPrincipal
);
105 using ConstraintValidation::GetValidationMessage
;
106 using ConstraintValidation::SetCustomValidity
;
107 void GetAlign(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::align
, aValue
); }
108 void SetAlign(const nsAString
& aValue
, ErrorResult
& aRv
) {
109 SetHTMLAttr(nsGkAtoms::align
, aValue
, aRv
);
111 void GetArchive(DOMString
& aValue
) {
112 GetHTMLAttr(nsGkAtoms::archive
, aValue
);
114 void SetArchive(const nsAString
& aValue
, ErrorResult
& aRv
) {
115 SetHTMLAttr(nsGkAtoms::archive
, aValue
, aRv
);
117 void GetCode(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::code
, aValue
); }
118 void SetCode(const nsAString
& aValue
, ErrorResult
& aRv
) {
119 SetHTMLAttr(nsGkAtoms::code
, aValue
, aRv
);
121 bool Declare() { return GetBoolAttr(nsGkAtoms::declare
); }
122 void SetDeclare(bool aValue
, ErrorResult
& aRv
) {
123 SetHTMLBoolAttr(nsGkAtoms::declare
, aValue
, aRv
);
126 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::hspace
, 0);
128 void SetHspace(uint32_t aValue
, ErrorResult
& aRv
) {
129 SetUnsignedIntAttr(nsGkAtoms::hspace
, aValue
, 0, aRv
);
131 void GetStandby(DOMString
& aValue
) {
132 GetHTMLAttr(nsGkAtoms::standby
, aValue
);
134 void SetStandby(const nsAString
& aValue
, ErrorResult
& aRv
) {
135 SetHTMLAttr(nsGkAtoms::standby
, aValue
, aRv
);
138 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::vspace
, 0);
140 void SetVspace(uint32_t aValue
, ErrorResult
& aRv
) {
141 SetUnsignedIntAttr(nsGkAtoms::vspace
, aValue
, 0, aRv
);
143 void GetCodeBase(DOMString
& aValue
) {
144 GetURIAttr(nsGkAtoms::codebase
, nullptr, aValue
);
146 void SetCodeBase(const nsAString
& aValue
, ErrorResult
& aRv
) {
147 SetHTMLAttr(nsGkAtoms::codebase
, aValue
, aRv
);
149 void GetCodeType(DOMString
& aValue
) {
150 GetHTMLAttr(nsGkAtoms::codetype
, aValue
);
152 void SetCodeType(const nsAString
& aValue
, ErrorResult
& aRv
) {
153 SetHTMLAttr(nsGkAtoms::codetype
, aValue
, aRv
);
155 void GetBorder(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::border
, aValue
); }
156 void SetBorder(const nsAString
& aValue
, ErrorResult
& aRv
) {
157 SetHTMLAttr(nsGkAtoms::border
, aValue
, aRv
);
160 Document
* GetSVGDocument(nsIPrincipal
& aSubjectPrincipal
) {
161 return GetContentDocument(aSubjectPrincipal
);
165 * Calls LoadObject with the correct arguments to start the plugin load.
167 void StartObjectLoad(bool aNotify
, bool aForceLoad
);
170 void AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
171 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
172 nsIPrincipal
* aSubjectPrincipal
, bool aNotify
) override
;
173 void OnAttrSetButNotChanged(int32_t aNamespaceID
, nsAtom
* aName
,
174 const nsAttrValueOrString
& aValue
,
175 bool aNotify
) override
;
178 nsContentPolicyType
GetContentPolicyType() const override
{
179 return nsIContentPolicy::TYPE_INTERNAL_OBJECT
;
182 virtual ~HTMLObjectElement();
184 JSObject
* WrapNode(JSContext
* aCx
,
185 JS::Handle
<JSObject
*> aGivenProto
) override
;
187 static void MapAttributesIntoRule(MappedDeclarationsBuilder
&);
190 * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
191 * This function will be called by AfterSetAttr whether the attribute is being
194 * @param aNamespaceID the namespace of the attr being set
195 * @param aName the localname of the attribute being set
196 * @param aNotify Whether we plan to notify document observers.
198 void AfterMaybeChangeAttr(int32_t aNamespaceID
, nsAtom
* aName
, bool aNotify
);
200 bool mIsDoneAddingChildren
;
203 } // namespace mozilla::dom
205 #endif // mozilla_dom_HTMLObjectElement_h