HTMLObjectElement.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_HTMLObjectElement_h
  6. #define mozilla_dom_HTMLObjectElement_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsGenericHTMLElement.h"
  9. #include "nsObjectLoadingContent.h"
  10. #include "nsIDOMHTMLObjectElement.h"
  11. #include "nsIConstraintValidation.h"
  12. namespace mozilla {
  13. namespace dom {
  14. class HTMLFormSubmission;
  15. class HTMLObjectElement final : public nsGenericHTMLFormElement
  16. , public nsObjectLoadingContent
  17. , public nsIDOMHTMLObjectElement
  18. , public nsIConstraintValidation
  19. {
  20. public:
  21. explicit HTMLObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
  22. FromParser aFromParser = NOT_FROM_PARSER);
  23. // nsISupports
  24. NS_DECL_ISUPPORTS_INHERITED
  25. NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLObjectElement, object)
  26. virtual int32_t TabIndexDefault() override;
  27. // Element
  28. virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
  29. // EventTarget
  30. virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
  31. // nsIDOMHTMLObjectElement
  32. NS_DECL_NSIDOMHTMLOBJECTELEMENT
  33. virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
  34. nsIContent *aBindingParent,
  35. bool aCompileEventHandlers) override;
  36. virtual void UnbindFromTree(bool aDeep = true,
  37. bool aNullParent = true) override;
  38. virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override;
  39. virtual IMEState GetDesiredIMEState() override;
  40. // Overriden nsIFormControl methods
  41. NS_IMETHOD_(uint32_t) GetType() const override
  42. {
  43. return NS_FORM_OBJECT;
  44. }
  45. NS_IMETHOD Reset() override;
  46. NS_IMETHOD SubmitNamesValues(HTMLFormSubmission *aFormSubmission) override;
  47. virtual bool IsDisabled() const override { return false; }
  48. virtual void DoneAddingChildren(bool aHaveNotified) override;
  49. virtual bool IsDoneAddingChildren() override;
  50. virtual bool ParseAttribute(int32_t aNamespaceID,
  51. nsIAtom *aAttribute,
  52. const nsAString &aValue,
  53. nsAttrValue &aResult) override;
  54. virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
  55. NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom *aAttribute) const override;
  56. virtual EventStates IntrinsicState() const override;
  57. virtual void DestroyContent() override;
  58. // nsObjectLoadingContent
  59. virtual uint32_t GetCapabilities() const override;
  60. virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
  61. nsresult CopyInnerTo(Element* aDest);
  62. void StartObjectLoad() { StartObjectLoad(true); }
  63. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLObjectElement,
  64. nsGenericHTMLFormElement)
  65. // Web IDL binding methods
  66. // XPCOM GetData is ok; note that it's a URI attribute with a weird base URI
  67. void SetData(const nsAString& aValue, ErrorResult& aRv)
  68. {
  69. SetHTMLAttr(nsGkAtoms::data, aValue, aRv);
  70. }
  71. void GetType(DOMString& aValue)
  72. {
  73. GetHTMLAttr(nsGkAtoms::type, aValue);
  74. }
  75. void SetType(const nsAString& aValue, ErrorResult& aRv)
  76. {
  77. SetHTMLAttr(nsGkAtoms::type, aValue, aRv);
  78. }
  79. bool TypeMustMatch()
  80. {
  81. return GetBoolAttr(nsGkAtoms::typemustmatch);
  82. }
  83. void SetTypeMustMatch(bool aValue, ErrorResult& aRv)
  84. {
  85. SetHTMLBoolAttr(nsGkAtoms::typemustmatch, aValue, aRv);
  86. }
  87. void GetName(DOMString& aValue)
  88. {
  89. GetHTMLAttr(nsGkAtoms::name, aValue);
  90. }
  91. void SetName(const nsAString& aValue, ErrorResult& aRv)
  92. {
  93. SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
  94. }
  95. void GetUseMap(DOMString& aValue)
  96. {
  97. GetHTMLAttr(nsGkAtoms::usemap, aValue);
  98. }
  99. void SetUseMap(const nsAString& aValue, ErrorResult& aRv)
  100. {
  101. SetHTMLAttr(nsGkAtoms::usemap, aValue, aRv);
  102. }
  103. using nsGenericHTMLFormElement::GetForm;
  104. void GetWidth(DOMString& aValue)
  105. {
  106. GetHTMLAttr(nsGkAtoms::width, aValue);
  107. }
  108. void SetWidth(const nsAString& aValue, ErrorResult& aRv)
  109. {
  110. SetHTMLAttr(nsGkAtoms::width, aValue, aRv);
  111. }
  112. void GetHeight(DOMString& aValue)
  113. {
  114. GetHTMLAttr(nsGkAtoms::height, aValue);
  115. }
  116. void SetHeight(const nsAString& aValue, ErrorResult& aRv)
  117. {
  118. SetHTMLAttr(nsGkAtoms::height, aValue, aRv);
  119. }
  120. using nsObjectLoadingContent::GetContentDocument;
  121. nsPIDOMWindowOuter*
  122. GetContentWindow(nsIPrincipal& aSubjectPrincipal);
  123. using nsIConstraintValidation::CheckValidity;
  124. using nsIConstraintValidation::ReportValidity;
  125. using nsIConstraintValidation::GetValidationMessage;
  126. void GetAlign(DOMString& aValue)
  127. {
  128. GetHTMLAttr(nsGkAtoms::align, aValue);
  129. }
  130. void SetAlign(const nsAString& aValue, ErrorResult& aRv)
  131. {
  132. SetHTMLAttr(nsGkAtoms::align, aValue, aRv);
  133. }
  134. void GetArchive(DOMString& aValue)
  135. {
  136. GetHTMLAttr(nsGkAtoms::archive, aValue);
  137. }
  138. void SetArchive(const nsAString& aValue, ErrorResult& aRv)
  139. {
  140. SetHTMLAttr(nsGkAtoms::archive, aValue, aRv);
  141. }
  142. // XPCOM GetCode is ok
  143. void SetCode(const nsAString& aValue, ErrorResult& aRv)
  144. {
  145. SetHTMLAttr(nsGkAtoms::code, aValue, aRv);
  146. }
  147. bool Declare()
  148. {
  149. return GetBoolAttr(nsGkAtoms::declare);
  150. }
  151. void SetDeclare(bool aValue, ErrorResult& aRv)
  152. {
  153. SetHTMLBoolAttr(nsGkAtoms::declare, aValue, aRv);
  154. }
  155. uint32_t Hspace()
  156. {
  157. return GetUnsignedIntAttr(nsGkAtoms::hspace, 0);
  158. }
  159. void SetHspace(uint32_t aValue, ErrorResult& aRv)
  160. {
  161. SetUnsignedIntAttr(nsGkAtoms::hspace, aValue, 0, aRv);
  162. }
  163. void GetStandby(DOMString& aValue)
  164. {
  165. GetHTMLAttr(nsGkAtoms::standby, aValue);
  166. }
  167. void SetStandby(const nsAString& aValue, ErrorResult& aRv)
  168. {
  169. SetHTMLAttr(nsGkAtoms::standby, aValue, aRv);
  170. }
  171. uint32_t Vspace()
  172. {
  173. return GetUnsignedIntAttr(nsGkAtoms::vspace, 0);
  174. }
  175. void SetVspace(uint32_t aValue, ErrorResult& aRv)
  176. {
  177. SetUnsignedIntAttr(nsGkAtoms::vspace, aValue, 0, aRv);
  178. }
  179. // XPCOM GetCodebase is ok; note that it's a URI attribute
  180. void SetCodeBase(const nsAString& aValue, ErrorResult& aRv)
  181. {
  182. SetHTMLAttr(nsGkAtoms::codebase, aValue, aRv);
  183. }
  184. void GetCodeType(DOMString& aValue)
  185. {
  186. GetHTMLAttr(nsGkAtoms::codetype, aValue);
  187. }
  188. void SetCodeType(const nsAString& aValue, ErrorResult& aRv)
  189. {
  190. SetHTMLAttr(nsGkAtoms::codetype, aValue, aRv);
  191. }
  192. void GetBorder(DOMString& aValue)
  193. {
  194. GetHTMLAttr(nsGkAtoms::border, aValue);
  195. }
  196. void SetBorder(const nsAString& aValue, ErrorResult& aRv)
  197. {
  198. SetHTMLAttr(nsGkAtoms::border, aValue, aRv);
  199. }
  200. nsIDocument*
  201. GetSVGDocument(nsIPrincipal& aSubjectPrincipal)
  202. {
  203. return GetContentDocument(aSubjectPrincipal);
  204. }
  205. protected:
  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. private:
  214. /**
  215. * Calls LoadObject with the correct arguments to start the plugin load.
  216. */
  217. void StartObjectLoad(bool aNotify);
  218. /**
  219. * Returns if the element is currently focusable regardless of it's tabindex
  220. * value. This is used to know the default tabindex value.
  221. */
  222. bool IsFocusableForTabIndex();
  223. nsContentPolicyType GetContentPolicyType() const override
  224. {
  225. return nsIContentPolicy::TYPE_INTERNAL_OBJECT;
  226. }
  227. virtual ~HTMLObjectElement();
  228. virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
  229. static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
  230. nsRuleData* aData);
  231. /**
  232. * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
  233. * This function will be called by AfterSetAttr whether the attribute is being
  234. * set or unset.
  235. *
  236. * @param aNamespaceID the namespace of the attr being set
  237. * @param aName the localname of the attribute being set
  238. * @param aNotify Whether we plan to notify document observers.
  239. */
  240. nsresult AfterMaybeChangeAttr(int32_t aNamespaceID, nsIAtom* aName,
  241. bool aNotify);
  242. bool mIsDoneAddingChildren;
  243. };
  244. } // namespace dom
  245. } // namespace mozilla
  246. #endif // mozilla_dom_HTMLObjectElement_h