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 #include "mozilla/dom/HTMLAreaElement.h"
9 #include "mozilla/Attributes.h"
10 #include "mozilla/dom/BindContext.h"
11 #include "mozilla/dom/Document.h"
12 #include "mozilla/dom/HTMLAnchorElement.h"
13 #include "mozilla/dom/HTMLAreaElementBinding.h"
14 #include "mozilla/EventDispatcher.h"
15 #include "mozilla/MemoryReporting.h"
16 #include "nsWindowSizes.h"
18 NS_IMPL_NS_NEW_HTML_ELEMENT(Area
)
20 namespace mozilla::dom
{
22 HTMLAreaElement::HTMLAreaElement(
23 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
24 : nsGenericHTMLElement(std::move(aNodeInfo
)), Link(this) {}
26 HTMLAreaElement::~HTMLAreaElement() = default;
28 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLAreaElement
,
29 nsGenericHTMLElement
, Link
)
31 NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLAreaElement
, nsGenericHTMLElement
,
34 NS_IMPL_ELEMENT_CLONE(HTMLAreaElement
)
36 int32_t HTMLAreaElement::TabIndexDefault() { return 0; }
38 void HTMLAreaElement::GetTarget(DOMString
& aValue
) {
39 if (!GetAttr(nsGkAtoms::target
, aValue
)) {
40 GetBaseTarget(aValue
);
44 void HTMLAreaElement::GetEventTargetParent(EventChainPreVisitor
& aVisitor
) {
45 GetEventTargetParentForAnchors(aVisitor
);
48 nsresult
HTMLAreaElement::PostHandleEvent(EventChainPostVisitor
& aVisitor
) {
49 return PostHandleEventForAnchors(aVisitor
);
52 void HTMLAreaElement::GetLinkTargetImpl(nsAString
& aTarget
) {
53 GetAttr(nsGkAtoms::target
, aTarget
);
54 if (aTarget
.IsEmpty()) {
55 GetBaseTarget(aTarget
);
59 nsDOMTokenList
* HTMLAreaElement::RelList() {
62 new nsDOMTokenList(this, nsGkAtoms::rel
, sAnchorAndFormRelValues
);
67 nsresult
HTMLAreaElement::BindToTree(BindContext
& aContext
, nsINode
& aParent
) {
68 nsresult rv
= nsGenericHTMLElement::BindToTree(aContext
, aParent
);
69 NS_ENSURE_SUCCESS(rv
, rv
);
71 Link::BindToTree(aContext
);
75 void HTMLAreaElement::UnbindFromTree(UnbindContext
& aContext
) {
76 nsGenericHTMLElement::UnbindFromTree(aContext
);
77 // Without removing the link state we risk a dangling pointer in the
78 // mStyledLinks hashtable
79 Link::UnbindFromTree();
82 void HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
83 const nsAttrValue
* aValue
,
84 const nsAttrValue
* aOldValue
,
85 nsIPrincipal
* aSubjectPrincipal
,
87 if (aNamespaceID
== kNameSpaceID_None
&& aName
== nsGkAtoms::href
) {
88 Link::ResetLinkState(aNotify
, !!aValue
);
91 return nsGenericHTMLElement::AfterSetAttr(
92 aNamespaceID
, aName
, aValue
, aOldValue
, aSubjectPrincipal
, aNotify
);
95 already_AddRefed
<nsIURI
> HTMLAreaElement::GetHrefURI() const {
96 if (nsCOMPtr
<nsIURI
> uri
= GetCachedURI()) {
99 return GetHrefURIForAnchors();
102 void HTMLAreaElement::AddSizeOfExcludingThis(nsWindowSizes
& aSizes
,
103 size_t* aNodeSize
) const {
104 nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes
, aNodeSize
);
105 *aNodeSize
+= Link::SizeOfExcludingThis(aSizes
.mState
);
108 JSObject
* HTMLAreaElement::WrapNode(JSContext
* aCx
,
109 JS::Handle
<JSObject
*> aGivenProto
) {
110 return HTMLAreaElement_Binding::Wrap(aCx
, this, aGivenProto
);
113 } // namespace mozilla::dom