tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLAreaElement.cpp (3634B)


      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 #include "mozilla/dom/HTMLAreaElement.h"
      8 
      9 #include "mozilla/EventDispatcher.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 "nsWindowSizes.h"
     15 
     16 NS_IMPL_NS_NEW_HTML_ELEMENT(Area)
     17 
     18 namespace mozilla::dom {
     19 
     20 HTMLAreaElement::HTMLAreaElement(
     21    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     22    : nsGenericHTMLElement(std::move(aNodeInfo)), Link(this) {}
     23 
     24 HTMLAreaElement::~HTMLAreaElement() = default;
     25 
     26 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLAreaElement,
     27                                             nsGenericHTMLElement, Link)
     28 
     29 NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLAreaElement, nsGenericHTMLElement,
     30                                   mRelList)
     31 
     32 NS_IMPL_ELEMENT_CLONE(HTMLAreaElement)
     33 
     34 int32_t HTMLAreaElement::TabIndexDefault() { return 0; }
     35 
     36 void HTMLAreaElement::GetTarget(DOMString& aValue) {
     37  if (!GetAttr(nsGkAtoms::target, aValue)) {
     38    GetBaseTarget(aValue);
     39  }
     40 }
     41 
     42 void HTMLAreaElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
     43  GetEventTargetParentForAnchors(aVisitor);
     44 }
     45 
     46 nsresult HTMLAreaElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
     47  return PostHandleEventForAnchors(aVisitor);
     48 }
     49 
     50 void HTMLAreaElement::GetLinkTargetImpl(nsAString& aTarget) {
     51  GetAttr(nsGkAtoms::target, aTarget);
     52  if (aTarget.IsEmpty()) {
     53    GetBaseTarget(aTarget);
     54  }
     55 }
     56 
     57 nsDOMTokenList* HTMLAreaElement::RelList() {
     58  if (!mRelList) {
     59    mRelList =
     60        new nsDOMTokenList(this, nsGkAtoms::rel, sAnchorAndFormRelValues);
     61  }
     62  return mRelList;
     63 }
     64 
     65 nsresult HTMLAreaElement::BindToTree(BindContext& aContext, nsINode& aParent) {
     66  nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
     67  NS_ENSURE_SUCCESS(rv, rv);
     68 
     69  Link::BindToTree(aContext);
     70  return rv;
     71 }
     72 
     73 void HTMLAreaElement::UnbindFromTree(UnbindContext& aContext) {
     74  nsGenericHTMLElement::UnbindFromTree(aContext);
     75  // Without removing the link state we risk a dangling pointer in the
     76  // mStyledLinks hashtable
     77  Link::UnbindFromTree();
     78 }
     79 
     80 void HTMLAreaElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
     81                                   const nsAttrValue* aValue,
     82                                   const nsAttrValue* aOldValue,
     83                                   nsIPrincipal* aSubjectPrincipal,
     84                                   bool aNotify) {
     85  if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::href) {
     86    Link::ResetLinkState(aNotify, !!aValue);
     87  }
     88 
     89  return nsGenericHTMLElement::AfterSetAttr(
     90      aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
     91 }
     92 
     93 already_AddRefed<nsIURI> HTMLAreaElement::GetHrefURI() const {
     94  if (nsCOMPtr<nsIURI> uri = GetCachedURI()) {
     95    return uri.forget();
     96  }
     97  return GetHrefURIForAnchors();
     98 }
     99 
    100 void HTMLAreaElement::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
    101                                             size_t* aNodeSize) const {
    102  nsGenericHTMLElement::AddSizeOfExcludingThis(aSizes, aNodeSize);
    103  *aNodeSize += Link::SizeOfExcludingThis(aSizes.mState);
    104 }
    105 
    106 JSObject* HTMLAreaElement::WrapNode(JSContext* aCx,
    107                                    JS::Handle<JSObject*> aGivenProto) {
    108  return HTMLAreaElement_Binding::Wrap(aCx, this, aGivenProto);
    109 }
    110 
    111 }  // namespace mozilla::dom