Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / html / HTMLAreaElement.cpp
blobc3cff228409d3cb03aaaeb4b09f7f157018452c0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
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 #include "mozilla/dom/HTMLAreaElement.h"
9 #include "mozilla/Attributes.h"
10 #include "mozilla/dom/HTMLAreaElementBinding.h"
11 #include "mozilla/EventDispatcher.h"
12 #include "mozilla/EventStates.h"
13 #include "mozilla/MemoryReporting.h"
15 NS_IMPL_NS_NEW_HTML_ELEMENT(Area)
17 namespace mozilla {
18 namespace dom {
20 HTMLAreaElement::HTMLAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
21 : nsGenericHTMLElement(aNodeInfo)
22 , Link(this)
26 HTMLAreaElement::~HTMLAreaElement()
30 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLAreaElement)
31 NS_INTERFACE_TABLE_INHERITED(HTMLAreaElement,
32 nsIDOMHTMLAreaElement,
33 Link)
34 NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
36 NS_IMPL_ADDREF_INHERITED(HTMLAreaElement, Element)
37 NS_IMPL_RELEASE_INHERITED(HTMLAreaElement, Element)
39 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLAreaElement)
41 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLAreaElement,
42 nsGenericHTMLElement)
43 tmp->Link::Traverse(cb);
44 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList)
45 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
47 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLAreaElement,
48 nsGenericHTMLElement)
49 tmp->Link::Unlink();
50 NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList)
51 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
53 NS_IMPL_ELEMENT_CLONE(HTMLAreaElement)
56 NS_IMPL_STRING_ATTR(HTMLAreaElement, Alt, alt)
57 NS_IMPL_STRING_ATTR(HTMLAreaElement, Coords, coords)
58 NS_IMPL_URI_ATTR(HTMLAreaElement, Href, href)
59 NS_IMPL_BOOL_ATTR(HTMLAreaElement, NoHref, nohref)
60 NS_IMPL_STRING_ATTR(HTMLAreaElement, Shape, shape)
61 NS_IMPL_STRING_ATTR(HTMLAreaElement, Download, download)
63 int32_t
64 HTMLAreaElement::TabIndexDefault()
66 return 0;
69 void
70 HTMLAreaElement::GetItemValueText(nsAString& aValue)
72 GetHref(aValue);
75 void
76 HTMLAreaElement::SetItemValueText(const nsAString& aValue)
78 SetHref(aValue);
81 NS_IMETHODIMP
82 HTMLAreaElement::GetTarget(nsAString& aValue)
84 if (!GetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue)) {
85 GetBaseTarget(aValue);
87 return NS_OK;
90 NS_IMETHODIMP
91 HTMLAreaElement::SetTarget(const nsAString& aValue)
93 return SetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue, true);
96 nsresult
97 HTMLAreaElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
99 return PreHandleEventForAnchors(aVisitor);
102 nsresult
103 HTMLAreaElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
105 return PostHandleEventForAnchors(aVisitor);
108 bool
109 HTMLAreaElement::IsLink(nsIURI** aURI) const
111 return IsHTMLLink(aURI);
114 void
115 HTMLAreaElement::GetLinkTarget(nsAString& aTarget)
117 GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
118 if (aTarget.IsEmpty()) {
119 GetBaseTarget(aTarget);
123 nsDOMTokenList*
124 HTMLAreaElement::RelList()
126 if (!mRelList) {
127 mRelList = new nsDOMTokenList(this, nsGkAtoms::rel);
129 return mRelList;
132 nsresult
133 HTMLAreaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
134 nsIContent* aBindingParent,
135 bool aCompileEventHandlers)
137 Link::ResetLinkState(false, Link::ElementHasHref());
138 nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
139 aBindingParent,
140 aCompileEventHandlers);
141 NS_ENSURE_SUCCESS(rv, rv);
143 nsIDocument* doc = GetComposedDoc();
144 if (doc) {
145 doc->RegisterPendingLinkUpdate(this);
147 return rv;
150 void
151 HTMLAreaElement::UnbindFromTree(bool aDeep, bool aNullParent)
153 // If this link is ever reinserted into a document, it might
154 // be under a different xml:base, so forget the cached state now.
155 Link::ResetLinkState(false, Link::ElementHasHref());
157 // Note, we need to use OwnerDoc() here, since GetComposedDoc() might
158 // return null.
159 nsIDocument* doc = OwnerDoc();
160 if (doc) {
161 doc->UnregisterPendingLinkUpdate(this);
164 nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
167 nsresult
168 HTMLAreaElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
169 nsIAtom* aPrefix, const nsAString& aValue,
170 bool aNotify)
172 nsresult rv =
173 nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue, aNotify);
175 // The ordering of the parent class's SetAttr call and Link::ResetLinkState
176 // is important here! The attribute is not set until SetAttr returns, and
177 // we will need the updated attribute value because notifying the document
178 // that content states have changed will call IntrinsicState, which will try
179 // to get updated information about the visitedness from Link.
180 if (aName == nsGkAtoms::href && aNameSpaceID == kNameSpaceID_None) {
181 Link::ResetLinkState(!!aNotify, true);
184 return rv;
187 nsresult
188 HTMLAreaElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
189 bool aNotify)
191 nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
192 aNotify);
194 // The ordering of the parent class's UnsetAttr call and Link::ResetLinkState
195 // is important here! The attribute is not unset until UnsetAttr returns, and
196 // we will need the updated attribute value because notifying the document
197 // that content states have changed will call IntrinsicState, which will try
198 // to get updated information about the visitedness from Link.
199 if (aAttribute == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
200 Link::ResetLinkState(!!aNotify, false);
203 return rv;
206 #define IMPL_URI_PART(_part) \
207 NS_IMETHODIMP \
208 HTMLAreaElement::Get##_part(nsAString& a##_part) \
210 ErrorResult rv; \
211 Link::Get##_part(a##_part, rv); \
212 MOZ_ASSERT(!rv.Failed()); \
213 return NS_OK; \
215 NS_IMETHODIMP \
216 HTMLAreaElement::Set##_part(const nsAString& a##_part) \
218 ErrorResult rv; \
219 Link::Set##_part(a##_part, rv); \
220 MOZ_ASSERT(!rv.Failed()); \
221 return NS_OK; \
224 IMPL_URI_PART(Protocol)
225 IMPL_URI_PART(Host)
226 IMPL_URI_PART(Hostname)
227 IMPL_URI_PART(Pathname)
228 IMPL_URI_PART(Search)
229 IMPL_URI_PART(Port)
230 IMPL_URI_PART(Hash)
232 #undef IMPL_URI_PART
234 NS_IMETHODIMP
235 HTMLAreaElement::ToString(nsAString& aSource)
237 return GetHref(aSource);
240 NS_IMETHODIMP
241 HTMLAreaElement::GetPing(nsAString& aValue)
243 return GetURIListAttr(nsGkAtoms::ping, aValue);
246 NS_IMETHODIMP
247 HTMLAreaElement::SetPing(const nsAString& aValue)
249 return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, true);
252 already_AddRefed<nsIURI>
253 HTMLAreaElement::GetHrefURI() const
255 return GetHrefURIForAnchors();
258 EventStates
259 HTMLAreaElement::IntrinsicState() const
261 return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
264 size_t
265 HTMLAreaElement::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
267 return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf) +
268 Link::SizeOfExcludingThis(aMallocSizeOf);
271 JSObject*
272 HTMLAreaElement::WrapNode(JSContext* aCx)
274 return HTMLAreaElementBinding::Wrap(aCx, this);
277 } // namespace dom
278 } // namespace mozilla