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_HTMLAnchorElement_h
8 #define mozilla_dom_HTMLAnchorElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/AnchorAreaFormRelValues.h"
12 #include "mozilla/dom/Link.h"
13 #include "mozilla/dom/HTMLDNSPrefetch.h"
14 #include "nsGenericHTMLElement.h"
15 #include "nsDOMTokenList.h"
18 class EventChainPostVisitor
;
19 class EventChainPreVisitor
;
22 class HTMLAnchorElement final
: public nsGenericHTMLElement
,
24 public SupportsDNSPrefetch
,
25 public AnchorAreaFormRelValues
{
27 using Element::GetText
;
29 explicit HTMLAnchorElement(
30 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
31 : nsGenericHTMLElement(std::move(aNodeInfo
)), Link(this) {}
34 NS_DECL_ISUPPORTS_INHERITED
37 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAnchorElement
,
40 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLAnchorElement
, a
);
42 int32_t TabIndexDefault() override
;
43 bool Draggable() const override
;
46 bool IsInteractiveHTMLContent() const override
;
48 // DOM memory reporter participant
49 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
51 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
52 void UnbindFromTree(bool aNullParent
= true) override
;
53 bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
54 int32_t* aTabIndex
) override
;
56 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
58 nsresult
PostHandleEvent(EventChainPostVisitor
& aVisitor
) override
;
60 void GetLinkTarget(nsAString
& aTarget
) override
;
61 already_AddRefed
<nsIURI
> GetHrefURI() const override
;
63 void BeforeSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
64 const nsAttrValue
* aValue
, bool aNotify
) override
;
65 void AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
66 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
67 nsIPrincipal
* aSubjectPrincipal
, bool aNotify
) override
;
69 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
73 void GetHref(nsAString
& aValue
) const {
74 GetURIAttr(nsGkAtoms::href
, nullptr, aValue
);
76 void SetHref(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
77 SetHTMLAttr(nsGkAtoms::href
, aValue
, rv
);
79 void GetTarget(nsAString
& aValue
) const;
80 void SetTarget(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
81 SetHTMLAttr(nsGkAtoms::target
, aValue
, rv
);
83 void GetDownload(DOMString
& aValue
) const {
84 GetHTMLAttr(nsGkAtoms::download
, aValue
);
86 void SetDownload(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
87 SetHTMLAttr(nsGkAtoms::download
, aValue
, rv
);
89 void GetPing(DOMString
& aValue
) const {
90 GetHTMLAttr(nsGkAtoms::ping
, aValue
);
92 void SetPing(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
93 SetHTMLAttr(nsGkAtoms::ping
, aValue
, rv
);
95 void GetRel(DOMString
& aValue
) const { GetHTMLAttr(nsGkAtoms::rel
, aValue
); }
96 void SetRel(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
97 SetHTMLAttr(nsGkAtoms::rel
, aValue
, rv
);
99 void SetReferrerPolicy(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
100 SetHTMLAttr(nsGkAtoms::referrerpolicy
, aValue
, rv
);
102 void GetReferrerPolicy(DOMString
& aPolicy
) const {
103 GetEnumAttr(nsGkAtoms::referrerpolicy
, "", aPolicy
);
105 nsDOMTokenList
* RelList();
106 void GetHreflang(DOMString
& aValue
) const {
107 GetHTMLAttr(nsGkAtoms::hreflang
, aValue
);
109 void SetHreflang(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
110 SetHTMLAttr(nsGkAtoms::hreflang
, aValue
, rv
);
112 // Needed for docshell
113 void GetType(nsAString
& aValue
) const {
114 GetHTMLAttr(nsGkAtoms::type
, aValue
);
116 void GetType(DOMString
& aValue
) const {
117 GetHTMLAttr(nsGkAtoms::type
, aValue
);
119 void SetType(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
120 SetHTMLAttr(nsGkAtoms::type
, aValue
, rv
);
122 void GetText(nsAString
& aText
, mozilla::ErrorResult
& aRv
) const;
123 void SetText(const nsAString
& aText
, mozilla::ErrorResult
& aRv
);
125 // Link::GetOrigin is OK for us
127 // Link::GetProtocol is OK for us
128 // Link::SetProtocol is OK for us
130 // Link::GetUsername is OK for us
131 // Link::SetUsername is OK for us
133 // Link::GetPassword is OK for us
134 // Link::SetPassword is OK for us
136 // Link::Link::GetHost is OK for us
137 // Link::Link::SetHost is OK for us
139 // Link::Link::GetHostname is OK for us
140 // Link::Link::SetHostname is OK for us
142 // Link::Link::GetPort is OK for us
143 // Link::Link::SetPort is OK for us
145 // Link::Link::GetPathname is OK for us
146 // Link::Link::SetPathname is OK for us
148 // Link::Link::GetSearch is OK for us
149 // Link::Link::SetSearch is OK for us
151 // Link::Link::GetHash is OK for us
152 // Link::Link::SetHash is OK for us
154 void GetCoords(DOMString
& aValue
) const {
155 GetHTMLAttr(nsGkAtoms::coords
, aValue
);
157 void SetCoords(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
158 SetHTMLAttr(nsGkAtoms::coords
, aValue
, rv
);
160 void GetCharset(DOMString
& aValue
) const {
161 GetHTMLAttr(nsGkAtoms::charset
, aValue
);
163 void SetCharset(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
164 SetHTMLAttr(nsGkAtoms::charset
, aValue
, rv
);
166 void GetName(DOMString
& aValue
) const {
167 GetHTMLAttr(nsGkAtoms::name
, aValue
);
169 void GetName(nsAString
& aValue
) const {
170 GetHTMLAttr(nsGkAtoms::name
, aValue
);
172 void SetName(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
173 SetHTMLAttr(nsGkAtoms::name
, aValue
, rv
);
175 void GetRev(DOMString
& aValue
) const { GetHTMLAttr(nsGkAtoms::rev
, aValue
); }
176 void SetRev(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
177 SetHTMLAttr(nsGkAtoms::rev
, aValue
, rv
);
179 void GetShape(DOMString
& aValue
) const {
180 GetHTMLAttr(nsGkAtoms::shape
, aValue
);
182 void SetShape(const nsAString
& aValue
, mozilla::ErrorResult
& rv
) {
183 SetHTMLAttr(nsGkAtoms::shape
, aValue
, rv
);
185 void Stringify(nsAString
& aResult
) const { GetHref(aResult
); }
186 void ToString(nsAString
& aSource
) const { GetHref(aSource
); }
188 void NodeInfoChanged(Document
* aOldDoc
) final
{
189 ClearHasPendingLinkUpdate();
190 nsGenericHTMLElement::NodeInfoChanged(aOldDoc
);
194 virtual ~HTMLAnchorElement();
196 JSObject
* WrapNode(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
197 RefPtr
<nsDOMTokenList
> mRelList
;
201 } // namespace mozilla
203 #endif // mozilla_dom_HTMLAnchorElement_h