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
)
20 HTMLAreaElement::HTMLAreaElement(already_AddRefed
<mozilla::dom::NodeInfo
>& aNodeInfo
)
21 : nsGenericHTMLElement(aNodeInfo
)
26 HTMLAreaElement::~HTMLAreaElement()
30 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLAreaElement
)
31 NS_INTERFACE_TABLE_INHERITED(HTMLAreaElement
,
32 nsIDOMHTMLAreaElement
,
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
,
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
,
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
)
64 HTMLAreaElement::TabIndexDefault()
70 HTMLAreaElement::GetItemValueText(nsAString
& aValue
)
76 HTMLAreaElement::SetItemValueText(const nsAString
& aValue
)
82 HTMLAreaElement::GetTarget(nsAString
& aValue
)
84 if (!GetAttr(kNameSpaceID_None
, nsGkAtoms::target
, aValue
)) {
85 GetBaseTarget(aValue
);
91 HTMLAreaElement::SetTarget(const nsAString
& aValue
)
93 return SetAttr(kNameSpaceID_None
, nsGkAtoms::target
, aValue
, true);
97 HTMLAreaElement::PreHandleEvent(EventChainPreVisitor
& aVisitor
)
99 return PreHandleEventForAnchors(aVisitor
);
103 HTMLAreaElement::PostHandleEvent(EventChainPostVisitor
& aVisitor
)
105 return PostHandleEventForAnchors(aVisitor
);
109 HTMLAreaElement::IsLink(nsIURI
** aURI
) const
111 return IsHTMLLink(aURI
);
115 HTMLAreaElement::GetLinkTarget(nsAString
& aTarget
)
117 GetAttr(kNameSpaceID_None
, nsGkAtoms::target
, aTarget
);
118 if (aTarget
.IsEmpty()) {
119 GetBaseTarget(aTarget
);
124 HTMLAreaElement::RelList()
127 mRelList
= new nsDOMTokenList(this, nsGkAtoms::rel
);
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
,
140 aCompileEventHandlers
);
141 NS_ENSURE_SUCCESS(rv
, rv
);
143 nsIDocument
* doc
= GetComposedDoc();
145 doc
->RegisterPendingLinkUpdate(this);
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
159 nsIDocument
* doc
= OwnerDoc();
161 doc
->UnregisterPendingLinkUpdate(this);
164 nsGenericHTMLElement::UnbindFromTree(aDeep
, aNullParent
);
168 HTMLAreaElement::SetAttr(int32_t aNameSpaceID
, nsIAtom
* aName
,
169 nsIAtom
* aPrefix
, const nsAString
& aValue
,
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);
188 HTMLAreaElement::UnsetAttr(int32_t aNameSpaceID
, nsIAtom
* aAttribute
,
191 nsresult rv
= nsGenericHTMLElement::UnsetAttr(aNameSpaceID
, aAttribute
,
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);
206 #define IMPL_URI_PART(_part) \
208 HTMLAreaElement::Get##_part(nsAString& a##_part) \
211 Link::Get##_part(a##_part, rv); \
212 MOZ_ASSERT(!rv.Failed()); \
216 HTMLAreaElement::Set##_part(const nsAString& a##_part) \
219 Link::Set##_part(a##_part, rv); \
220 MOZ_ASSERT(!rv.Failed()); \
224 IMPL_URI_PART(Protocol
)
226 IMPL_URI_PART(Hostname
)
227 IMPL_URI_PART(Pathname
)
228 IMPL_URI_PART(Search
)
235 HTMLAreaElement::ToString(nsAString
& aSource
)
237 return GetHref(aSource
);
241 HTMLAreaElement::GetPing(nsAString
& aValue
)
243 return GetURIListAttr(nsGkAtoms::ping
, aValue
);
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();
259 HTMLAreaElement::IntrinsicState() const
261 return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
265 HTMLAreaElement::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const
267 return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf
) +
268 Link::SizeOfExcludingThis(aMallocSizeOf
);
272 HTMLAreaElement::WrapNode(JSContext
* aCx
)
274 return HTMLAreaElementBinding::Wrap(aCx
, this);
278 } // namespace mozilla