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_HTMLLinkElement_h
8 #define mozilla_dom_HTMLLinkElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/Link.h"
12 #include "nsGenericHTMLElement.h"
13 #include "nsStyleLinkElement.h"
16 class EventChainPostVisitor
;
17 class EventChainPreVisitor
;
20 class HTMLLinkElement final
: public nsGenericHTMLElement
,
21 public nsStyleLinkElement
,
25 explicit HTMLLinkElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
28 NS_DECL_ISUPPORTS_INHERITED
31 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLLinkElement
,
34 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLLinkElement
, link
);
35 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
41 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
42 virtual nsresult
PostHandleEvent(
43 EventChainPostVisitor
& aVisitor
) override
;
46 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
47 virtual JSObject
* WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
50 virtual nsresult
BindToTree(nsIDocument
* aDocument
, nsIContent
* aParent
,
51 nsIContent
* aBindingParent
) override
;
52 virtual void UnbindFromTree(bool aDeep
= true,
53 bool aNullParent
= true) override
;
54 virtual nsresult
BeforeSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
55 const nsAttrValueOrString
* aValue
,
56 bool aNotify
) override
;
57 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
58 const nsAttrValue
* aValue
,
59 const nsAttrValue
* aOldValue
,
60 nsIPrincipal
* aSubjectPrincipal
,
61 bool aNotify
) override
;
62 virtual bool IsLink(nsIURI
** aURI
) const override
;
63 virtual already_AddRefed
<nsIURI
> GetHrefURI() const override
;
66 virtual bool ParseAttribute(int32_t aNamespaceID
,
68 const nsAString
& aValue
,
69 nsIPrincipal
* aMaybeScriptedPrincipal
,
70 nsAttrValue
& aResult
) override
;
71 virtual void GetLinkTarget(nsAString
& aTarget
) override
;
72 virtual EventStates
IntrinsicState() const override
;
74 void CreateAndDispatchEvent(nsIDocument
* aDoc
, const nsAString
& aEventName
);
76 virtual void OnDNSPrefetchDeferred() override
;
77 virtual void OnDNSPrefetchRequested() override
;
78 virtual bool HasDeferredDNSPrefetchRequest() override
;
82 void SetDisabled(bool aDisabled
);
84 void GetHref(nsAString
& aValue
)
86 GetURIAttr(nsGkAtoms::href
, nullptr, aValue
);
88 void SetHref(const nsAString
& aHref
, nsIPrincipal
* aTriggeringPrincipal
, ErrorResult
& aRv
)
90 SetHTMLAttr(nsGkAtoms::href
, aHref
, aTriggeringPrincipal
, aRv
);
92 void SetHref(const nsAString
& aHref
, ErrorResult
& aRv
)
94 SetHTMLAttr(nsGkAtoms::href
, aHref
, aRv
);
96 void GetCrossOrigin(nsAString
& aResult
)
98 // Null for both missing and invalid defaults is ok, since we
99 // always parse to an enum value, so we don't need an invalid
100 // default, and we _want_ the missing default to be null.
101 GetEnumAttr(nsGkAtoms::crossorigin
, nullptr, aResult
);
103 void SetCrossOrigin(const nsAString
& aCrossOrigin
, ErrorResult
& aError
)
105 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin
, aCrossOrigin
, aError
);
107 // nsAString for WebBrowserPersistLocalDocument
108 void GetRel(nsAString
& aValue
)
110 GetHTMLAttr(nsGkAtoms::rel
, aValue
);
112 void SetRel(const nsAString
& aRel
, ErrorResult
& aRv
)
114 SetHTMLAttr(nsGkAtoms::rel
, aRel
, aRv
);
116 nsDOMTokenList
* RelList();
117 void GetMedia(DOMString
& aValue
)
119 GetHTMLAttr(nsGkAtoms::media
, aValue
);
121 void SetMedia(const nsAString
& aMedia
, ErrorResult
& aRv
)
123 SetHTMLAttr(nsGkAtoms::media
, aMedia
, aRv
);
125 void GetHreflang(DOMString
& aValue
)
127 GetHTMLAttr(nsGkAtoms::hreflang
, aValue
);
129 void SetHreflang(const nsAString
& aHreflang
, ErrorResult
& aRv
)
131 SetHTMLAttr(nsGkAtoms::hreflang
, aHreflang
, aRv
);
133 void GetAs(nsAString
& aResult
);
134 void SetAs(const nsAString
& aAs
, ErrorResult
& aRv
)
136 SetAttr(nsGkAtoms::as
,aAs
, aRv
);
138 nsDOMTokenList
* Sizes()
140 return GetTokenList(nsGkAtoms::sizes
);
142 void GetType(DOMString
& aValue
)
144 GetHTMLAttr(nsGkAtoms::type
, aValue
);
146 void SetType(const nsAString
& aType
, ErrorResult
& aRv
)
148 SetHTMLAttr(nsGkAtoms::type
, aType
, aRv
);
150 void GetCharset(nsAString
& aValue
) override
152 GetHTMLAttr(nsGkAtoms::charset
, aValue
);
154 void SetCharset(const nsAString
& aCharset
, ErrorResult
& aRv
)
156 SetHTMLAttr(nsGkAtoms::charset
, aCharset
, aRv
);
158 void GetRev(DOMString
& aValue
)
160 GetHTMLAttr(nsGkAtoms::rev
, aValue
);
162 void SetRev(const nsAString
& aRev
, ErrorResult
& aRv
)
164 SetHTMLAttr(nsGkAtoms::rev
, aRev
, aRv
);
166 void GetTarget(DOMString
& aValue
)
168 GetHTMLAttr(nsGkAtoms::target
, aValue
);
170 void SetTarget(const nsAString
& aTarget
, ErrorResult
& aRv
)
172 SetHTMLAttr(nsGkAtoms::target
, aTarget
, aRv
);
174 void GetIntegrity(nsAString
& aIntegrity
) const
176 GetHTMLAttr(nsGkAtoms::integrity
, aIntegrity
);
178 void SetIntegrity(const nsAString
& aIntegrity
, ErrorResult
& aRv
)
180 SetHTMLAttr(nsGkAtoms::integrity
, aIntegrity
, aRv
);
182 void SetReferrerPolicy(const nsAString
& aReferrer
, ErrorResult
& aError
)
184 SetHTMLAttr(nsGkAtoms::referrerpolicy
, aReferrer
, aError
);
186 void GetReferrerPolicy(nsAString
& aReferrer
)
188 GetEnumAttr(nsGkAtoms::referrerpolicy
, EmptyCString().get(), aReferrer
);
191 CORSMode
GetCORSMode() const
193 return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin
));
196 void NodeInfoChanged(nsIDocument
* aOldDoc
) final
198 ClearHasPendingLinkUpdate();
199 nsGenericHTMLElement::NodeInfoChanged(aOldDoc
);
202 static bool CheckPreloadAttrs(const nsAttrValue
& aAs
, const nsAString
& aType
,
203 const nsAString
& aMedia
, nsIDocument
* aDocument
);
205 virtual ~HTMLLinkElement();
207 // nsStyleLinkElement
208 Maybe
<SheetInfo
> GetStyleSheetInfo() final
;
211 RefPtr
<nsDOMTokenList
> mRelList
;
215 } // namespace mozilla
217 #endif // mozilla_dom_HTMLLinkElement_h