Bug 1719855 - Take over preventDefaulted infomation for long-tap events to the origin...
[gecko.git] / dom / html / HTMLAreaElement.cpp
blobb3d83d4b41f2e5be2c957fc642953cf46b646ca2
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,
32 mRelList)
34 NS_IMPL_ELEMENT_CLONE(HTMLAreaElement)
36 int32_t HTMLAreaElement::TabIndexDefault() { return 0; }
38 void HTMLAreaElement::GetTarget(DOMString& aValue) {
39 if (!GetAttr(kNameSpaceID_None, 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::GetLinkTarget(nsAString& aTarget) {
53 GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
54 if (aTarget.IsEmpty()) {
55 GetBaseTarget(aTarget);
59 nsDOMTokenList* HTMLAreaElement::RelList() {
60 if (!mRelList) {
61 mRelList = new nsDOMTokenList(this, nsGkAtoms::rel, sSupportedRelValues);
63 return mRelList;
66 nsresult HTMLAreaElement::BindToTree(BindContext& aContext, nsINode& aParent) {
67 Link::ResetLinkState(false, Link::ElementHasHref());
68 nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
69 NS_ENSURE_SUCCESS(rv, rv);
71 if (IsInComposedDoc()) {
72 aContext.OwnerDoc().RegisterPendingLinkUpdate(this);
74 return rv;
77 void HTMLAreaElement::UnbindFromTree(bool aNullParent) {
78 // Without removing the link state we risk a dangling pointer
79 // in the mStyledLinks hashtable
80 Link::ResetLinkState(false, Link::ElementHasHref());
82 nsGenericHTMLElement::UnbindFromTree(aNullParent);
85 void HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
86 const nsAttrValue* aValue,
87 const nsAttrValue* aOldValue,
88 nsIPrincipal* aSubjectPrincipal,
89 bool aNotify) {
90 if (aNamespaceID == kNameSpaceID_None) {
91 // This must happen after the attribute is set. We will need the updated
92 // attribute value because notifying the document that content states have
93 // changed will call IntrinsicState, which will try to get updated
94 // information about the visitedness from Link.
95 if (aName == nsGkAtoms::href) {
96 Link::ResetLinkState(aNotify, !!aValue);
100 return nsGenericHTMLElement::AfterSetAttr(
101 aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
104 void HTMLAreaElement::ToString(nsAString& aSource) { GetHref(aSource); }
106 already_AddRefed<nsIURI> HTMLAreaElement::GetHrefURI() const {
107 if (nsCOMPtr<nsIURI> uri = GetCachedURI()) {
108 return uri.forget();
110 return GetHrefURIForAnchors();
113 ElementState HTMLAreaElement::IntrinsicState() const {
114 return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
117 void HTMLAreaElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
118 size_t* aNodeSize) const {
119 nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
120 *aNodeSize += Link::SizeOfExcludingThis(aSizes.mState);
123 JSObject* HTMLAreaElement::WrapNode(JSContext* aCx,
124 JS::Handle<JSObject*> aGivenProto) {
125 return HTMLAreaElement_Binding::Wrap(aCx, this, aGivenProto);
128 } // namespace mozilla::dom