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_HTMLAnchorElement_h
8 : #define mozilla_dom_HTMLAnchorElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/dom/Link.h"
12 : #include "nsGenericHTMLElement.h"
13 : #include "nsIDOMHTMLAnchorElement.h"
14 : #include "nsDOMTokenList.h"
15 :
16 : namespace mozilla {
17 : class EventChainPostVisitor;
18 : class EventChainPreVisitor;
19 : namespace dom {
20 :
21 : class HTMLAnchorElement final : public nsGenericHTMLElement,
22 : public nsIDOMHTMLAnchorElement,
23 : public Link
24 : {
25 : public:
26 : using Element::GetText;
27 : using Element::SetText;
28 :
29 0 : explicit HTMLAnchorElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
30 0 : : nsGenericHTMLElement(aNodeInfo)
31 0 : , Link(this)
32 : {
33 0 : }
34 :
35 : // nsISupports
36 : NS_DECL_ISUPPORTS_INHERITED
37 :
38 : // CC
39 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAnchorElement,
40 : nsGenericHTMLElement)
41 :
42 : virtual int32_t TabIndexDefault() override;
43 : virtual bool Draggable() const override;
44 :
45 : // Element
46 : virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
47 :
48 : // nsIDOMHTMLAnchorElement
49 : NS_DECL_NSIDOMHTMLANCHORELEMENT
50 :
51 : // DOM memory reporter participant
52 : NS_DECL_SIZEOF_EXCLUDING_THIS
53 :
54 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
55 : nsIContent* aBindingParent,
56 : bool aCompileEventHandlers) override;
57 : virtual void UnbindFromTree(bool aDeep = true,
58 : bool aNullParent = true) override;
59 : virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override;
60 :
61 : virtual nsresult GetEventTargetParent(
62 : EventChainPreVisitor& aVisitor) override;
63 : virtual nsresult PostHandleEvent(
64 : EventChainPostVisitor& aVisitor) override;
65 : virtual bool IsLink(nsIURI** aURI) const override;
66 : virtual void GetLinkTarget(nsAString& aTarget) override;
67 : virtual already_AddRefed<nsIURI> GetHrefURI() const override;
68 :
69 : virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
70 : const nsAttrValueOrString* aValue,
71 : bool aNotify) override;
72 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
73 : const nsAttrValue* aValue,
74 : const nsAttrValue* aOldValue,
75 : bool aNotify) override;
76 :
77 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
78 : bool aPreallocateChildren) const override;
79 :
80 : virtual EventStates IntrinsicState() const override;
81 :
82 : virtual void OnDNSPrefetchDeferred() override;
83 : virtual void OnDNSPrefetchRequested() override;
84 : virtual bool HasDeferredDNSPrefetchRequest() override;
85 :
86 : // WebIDL API
87 :
88 : // The XPCOM GetHref is OK for us
89 0 : void SetHref(const nsAString& aValue, mozilla::ErrorResult& rv)
90 : {
91 0 : SetHTMLAttr(nsGkAtoms::href, aValue, rv);
92 0 : }
93 : // The XPCOM GetTarget is OK for us
94 0 : void SetTarget(const nsAString& aValue, mozilla::ErrorResult& rv)
95 : {
96 0 : SetHTMLAttr(nsGkAtoms::target, aValue, rv);
97 0 : }
98 0 : void GetDownload(DOMString& aValue)
99 : {
100 0 : GetHTMLAttr(nsGkAtoms::download, aValue);
101 0 : }
102 0 : void SetDownload(const nsAString& aValue, mozilla::ErrorResult& rv)
103 : {
104 0 : SetHTMLAttr(nsGkAtoms::download, aValue, rv);
105 0 : }
106 : // The XPCOM GetPing is OK for us
107 0 : void SetPing(const nsAString& aValue, mozilla::ErrorResult& rv)
108 : {
109 0 : SetHTMLAttr(nsGkAtoms::ping, aValue, rv);
110 0 : }
111 0 : void GetRel(DOMString& aValue)
112 : {
113 0 : GetHTMLAttr(nsGkAtoms::rel, aValue);
114 0 : }
115 0 : void SetRel(const nsAString& aValue, mozilla::ErrorResult& rv)
116 : {
117 0 : SetHTMLAttr(nsGkAtoms::rel, aValue, rv);
118 0 : }
119 0 : void SetReferrerPolicy(const nsAString& aValue, mozilla::ErrorResult& rv)
120 : {
121 0 : SetHTMLAttr(nsGkAtoms::referrerpolicy, aValue, rv);
122 0 : }
123 0 : void GetReferrerPolicy(nsAString& aReferrer)
124 : {
125 0 : GetEnumAttr(nsGkAtoms::referrerpolicy, EmptyCString().get(), aReferrer);
126 0 : }
127 : nsDOMTokenList* RelList();
128 0 : void GetHreflang(DOMString& aValue)
129 : {
130 0 : GetHTMLAttr(nsGkAtoms::hreflang, aValue);
131 0 : }
132 0 : void SetHreflang(const nsAString& aValue, mozilla::ErrorResult& rv)
133 : {
134 0 : SetHTMLAttr(nsGkAtoms::hreflang, aValue, rv);
135 0 : }
136 0 : void GetType(DOMString& aValue)
137 : {
138 0 : GetHTMLAttr(nsGkAtoms::type, aValue);
139 0 : }
140 0 : void SetType(const nsAString& aValue, mozilla::ErrorResult& rv)
141 : {
142 0 : SetHTMLAttr(nsGkAtoms::type, aValue, rv);
143 0 : }
144 : // The XPCOM GetText is OK for us
145 0 : void SetText(const nsAString& aValue, mozilla::ErrorResult& rv)
146 : {
147 0 : rv = SetText(aValue);
148 0 : }
149 :
150 : // Link::GetOrigin is OK for us
151 :
152 : // Link::GetProtocol is OK for us
153 : // Link::SetProtocol is OK for us
154 :
155 : // Link::GetUsername is OK for us
156 : // Link::SetUsername is OK for us
157 :
158 : // Link::GetPassword is OK for us
159 : // Link::SetPassword is OK for us
160 :
161 : // Link::Link::GetHost is OK for us
162 : // Link::Link::SetHost is OK for us
163 :
164 : // Link::Link::GetHostname is OK for us
165 : // Link::Link::SetHostname is OK for us
166 :
167 : // Link::Link::GetPort is OK for us
168 : // Link::Link::SetPort is OK for us
169 :
170 : // Link::Link::GetPathname is OK for us
171 : // Link::Link::SetPathname is OK for us
172 :
173 : // Link::Link::GetSearch is OK for us
174 : // Link::Link::SetSearch is OK for us
175 :
176 : // Link::Link::GetHash is OK for us
177 : // Link::Link::SetHash is OK for us
178 :
179 : // The XPCOM URI decomposition attributes are fine for us
180 0 : void GetCoords(DOMString& aValue)
181 : {
182 0 : GetHTMLAttr(nsGkAtoms::coords, aValue);
183 0 : }
184 0 : void SetCoords(const nsAString& aValue, mozilla::ErrorResult& rv)
185 : {
186 0 : SetHTMLAttr(nsGkAtoms::coords, aValue, rv);
187 0 : }
188 0 : void GetCharset(DOMString& aValue)
189 : {
190 0 : GetHTMLAttr(nsGkAtoms::charset, aValue);
191 0 : }
192 0 : void SetCharset(const nsAString& aValue, mozilla::ErrorResult& rv)
193 : {
194 0 : SetHTMLAttr(nsGkAtoms::charset, aValue, rv);
195 0 : }
196 0 : void GetName(DOMString& aValue)
197 : {
198 0 : GetHTMLAttr(nsGkAtoms::name, aValue);
199 0 : }
200 0 : void SetName(const nsAString& aValue, mozilla::ErrorResult& rv)
201 : {
202 0 : SetHTMLAttr(nsGkAtoms::name, aValue, rv);
203 0 : }
204 0 : void GetRev(DOMString& aValue)
205 : {
206 0 : GetHTMLAttr(nsGkAtoms::rev, aValue);
207 0 : }
208 0 : void SetRev(const nsAString& aValue, mozilla::ErrorResult& rv)
209 : {
210 0 : SetHTMLAttr(nsGkAtoms::rev, aValue, rv);
211 0 : }
212 0 : void GetShape(DOMString& aValue)
213 : {
214 0 : GetHTMLAttr(nsGkAtoms::shape, aValue);
215 0 : }
216 0 : void SetShape(const nsAString& aValue, mozilla::ErrorResult& rv)
217 : {
218 0 : SetHTMLAttr(nsGkAtoms::shape, aValue, rv);
219 0 : }
220 0 : void Stringify(nsAString& aResult)
221 : {
222 0 : GetHref(aResult);
223 0 : }
224 :
225 0 : virtual void NodeInfoChanged(nsIDocument* aOldDoc) final override
226 : {
227 0 : ClearHasPendingLinkUpdate();
228 0 : nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
229 0 : }
230 :
231 : static DOMTokenListSupportedToken sSupportedRelValues[];
232 :
233 : protected:
234 : virtual ~HTMLAnchorElement();
235 :
236 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
237 : RefPtr<nsDOMTokenList > mRelList;
238 : };
239 :
240 : } // namespace dom
241 : } // namespace mozilla
242 :
243 : #endif // mozilla_dom_HTMLAnchorElement_h
|