HTMLAnchorElement.h (6577B)
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/HTMLDNSPrefetch.h" 12 #include "mozilla/dom/Link.h" 13 #include "nsDOMTokenList.h" 14 #include "nsGenericHTMLElement.h" 15 16 namespace mozilla { 17 class EventChainPostVisitor; 18 class EventChainPreVisitor; 19 namespace dom { 20 21 class HTMLAnchorElement final : public nsGenericHTMLElement, 22 public Link, 23 public SupportsDNSPrefetch { 24 public: 25 using Element::GetCharacterDataBuffer; 26 27 explicit HTMLAnchorElement( 28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 29 : nsGenericHTMLElement(std::move(aNodeInfo)), Link(this) {} 30 31 // nsISupports 32 NS_DECL_ISUPPORTS_INHERITED 33 34 // CC 35 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAnchorElement, 36 nsGenericHTMLElement) 37 38 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLAnchorElement, a); 39 40 int32_t TabIndexDefault() override; 41 bool Draggable() const override; 42 43 // Element 44 bool IsInteractiveHTMLContent() const override; 45 46 // DOM memory reporter participant 47 NS_DECL_ADDSIZEOFEXCLUDINGTHIS 48 49 nsresult BindToTree(BindContext&, nsINode& aParent) override; 50 void UnbindFromTree(UnbindContext&) override; 51 bool IsHTMLFocusable(IsFocusableFlags, bool* aIsFocusable, 52 int32_t* aTabIndex) override; 53 54 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; 55 MOZ_CAN_RUN_SCRIPT 56 nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override; 57 58 void GetLinkTargetImpl(nsAString& aTarget) override; 59 already_AddRefed<nsIURI> GetHrefURI() const override; 60 61 void BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, 62 const nsAttrValue* aValue, bool aNotify) override; 63 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, 64 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 65 nsIPrincipal* aSubjectPrincipal, bool aNotify) override; 66 67 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 68 69 // WebIDL API 70 71 void GetHref(nsACString& aValue) const { 72 GetURIAttr(nsGkAtoms::href, nullptr, aValue); 73 } 74 void SetHref(const nsACString& aValue, ErrorResult& aRv) { 75 SetHTMLAttr(nsGkAtoms::href, NS_ConvertUTF8toUTF16(aValue), aRv); 76 } 77 void GetTarget(nsAString& aValue) const; 78 void SetTarget(const nsAString& aValue, mozilla::ErrorResult& rv) { 79 SetHTMLAttr(nsGkAtoms::target, aValue, rv); 80 } 81 void GetDownload(DOMString& aValue) const { 82 GetHTMLAttr(nsGkAtoms::download, aValue); 83 } 84 void SetDownload(const nsAString& aValue, mozilla::ErrorResult& rv) { 85 SetHTMLAttr(nsGkAtoms::download, aValue, rv); 86 } 87 void GetPing(DOMString& aValue) const { 88 GetHTMLAttr(nsGkAtoms::ping, aValue); 89 } 90 void SetPing(const nsAString& aValue, mozilla::ErrorResult& rv) { 91 SetHTMLAttr(nsGkAtoms::ping, aValue, rv); 92 } 93 void GetRel(DOMString& aValue) const { GetHTMLAttr(nsGkAtoms::rel, aValue); } 94 void SetRel(const nsAString& aValue, mozilla::ErrorResult& rv) { 95 SetHTMLAttr(nsGkAtoms::rel, aValue, rv); 96 } 97 void SetReferrerPolicy(const nsAString& aValue, mozilla::ErrorResult& rv) { 98 SetHTMLAttr(nsGkAtoms::referrerpolicy, aValue, rv); 99 } 100 void GetReferrerPolicy(DOMString& aPolicy) const { 101 GetEnumAttr(nsGkAtoms::referrerpolicy, "", aPolicy); 102 } 103 nsDOMTokenList* RelList(); 104 void GetHreflang(DOMString& aValue) const { 105 GetHTMLAttr(nsGkAtoms::hreflang, aValue); 106 } 107 void SetHreflang(const nsAString& aValue, mozilla::ErrorResult& rv) { 108 SetHTMLAttr(nsGkAtoms::hreflang, aValue, rv); 109 } 110 void GetType(DOMString& aValue) const { 111 GetHTMLAttr(nsGkAtoms::type, aValue); 112 } 113 void SetType(const nsAString& aValue, mozilla::ErrorResult& rv) { 114 SetHTMLAttr(nsGkAtoms::type, aValue, rv); 115 } 116 void GetText(nsAString& aText, mozilla::ErrorResult& aRv) const; 117 void SetText(const nsAString& aText, mozilla::ErrorResult& aRv); 118 119 // Link::GetOrigin is OK for us 120 121 // Link::GetProtocol is OK for us 122 // Link::SetProtocol is OK for us 123 124 // Link::GetUsername is OK for us 125 // Link::SetUsername is OK for us 126 127 // Link::GetPassword is OK for us 128 // Link::SetPassword is OK for us 129 130 // Link::Link::GetHost is OK for us 131 // Link::Link::SetHost is OK for us 132 133 // Link::Link::GetHostname is OK for us 134 // Link::Link::SetHostname is OK for us 135 136 // Link::Link::GetPort is OK for us 137 // Link::Link::SetPort is OK for us 138 139 // Link::Link::GetPathname is OK for us 140 // Link::Link::SetPathname is OK for us 141 142 // Link::Link::GetSearch is OK for us 143 // Link::Link::SetSearch is OK for us 144 145 // Link::Link::GetHash is OK for us 146 // Link::Link::SetHash is OK for us 147 148 void GetCoords(DOMString& aValue) const { 149 GetHTMLAttr(nsGkAtoms::coords, aValue); 150 } 151 void SetCoords(const nsAString& aValue, mozilla::ErrorResult& rv) { 152 SetHTMLAttr(nsGkAtoms::coords, aValue, rv); 153 } 154 void GetCharset(DOMString& aValue) const { 155 GetHTMLAttr(nsGkAtoms::charset, aValue); 156 } 157 void SetCharset(const nsAString& aValue, mozilla::ErrorResult& rv) { 158 SetHTMLAttr(nsGkAtoms::charset, aValue, rv); 159 } 160 void GetName(DOMString& aValue) const { 161 GetHTMLAttr(nsGkAtoms::name, aValue); 162 } 163 void GetName(nsAString& aValue) const { 164 GetHTMLAttr(nsGkAtoms::name, aValue); 165 } 166 void SetName(const nsAString& aValue, mozilla::ErrorResult& rv) { 167 SetHTMLAttr(nsGkAtoms::name, aValue, rv); 168 } 169 void GetRev(DOMString& aValue) const { GetHTMLAttr(nsGkAtoms::rev, aValue); } 170 void SetRev(const nsAString& aValue, mozilla::ErrorResult& rv) { 171 SetHTMLAttr(nsGkAtoms::rev, aValue, rv); 172 } 173 void GetShape(DOMString& aValue) const { 174 GetHTMLAttr(nsGkAtoms::shape, aValue); 175 } 176 void SetShape(const nsAString& aValue, mozilla::ErrorResult& rv) { 177 SetHTMLAttr(nsGkAtoms::shape, aValue, rv); 178 } 179 180 void NodeInfoChanged(Document* aOldDoc) final { 181 ClearHasPendingLinkUpdate(); 182 nsGenericHTMLElement::NodeInfoChanged(aOldDoc); 183 } 184 185 protected: 186 virtual ~HTMLAnchorElement(); 187 188 void MaybeTryDNSPrefetch(); 189 190 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 191 RefPtr<nsDOMTokenList> mRelList; 192 }; 193 194 } // namespace dom 195 } // namespace mozilla 196 197 #endif // mozilla_dom_HTMLAnchorElement_h