HTMLSharedElement.h 5.6 KB

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