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