2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-27 11:05:23 -07:00
|
|
|
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
|
|
|
#include "nsILink.h"
|
|
|
|
#include "Link.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2009-08-27 11:05:23 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2008-11-07 15:00:26 -08:00
|
|
|
#include "nsHTMLDNSPrefetch.h"
|
|
|
|
|
2009-10-13 15:13:41 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2008-02-21 12:39:20 -08:00
|
|
|
class nsHTMLAnchorElement : public nsGenericHTMLElement,
|
|
|
|
public nsIDOMHTMLAnchorElement,
|
2009-10-13 15:13:41 -07:00
|
|
|
public nsILink,
|
|
|
|
public Link
|
2008-02-21 12:39:20 -08:00
|
|
|
{
|
|
|
|
public:
|
2012-11-14 14:10:08 -08:00
|
|
|
using Element::GetText;
|
|
|
|
using Element::SetText;
|
2010-07-30 16:48:57 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsHTMLAnchorElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
2008-02-21 12:39:20 -08:00
|
|
|
virtual ~nsHTMLAnchorElement();
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsIDOMNode
|
2012-10-09 05:31:24 -07:00
|
|
|
NS_FORWARD_NSIDOMNODE_TO_NSINODE
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
// nsIDOMElement
|
2012-10-16 04:51:00 -07:00
|
|
|
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
// nsIDOMHTMLElement
|
2012-11-10 15:30:15 -08:00
|
|
|
NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC
|
|
|
|
|
2012-10-06 00:19:51 -07:00
|
|
|
virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
|
2012-10-06 00:19:52 -07:00
|
|
|
virtual bool Draggable() const MOZ_OVERRIDE;
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
// nsIDOMHTMLAnchorElement
|
2012-12-02 12:55:52 -08:00
|
|
|
NS_DECL_NSIDOMHTMLANCHORELEMENT
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
// DOM memory reporter participant
|
|
|
|
NS_DECL_SIZEOF_EXCLUDING_THIS
|
2011-08-17 15:14:53 -07:00
|
|
|
|
2008-02-21 12:39:20 -08:00
|
|
|
// nsILink
|
|
|
|
NS_IMETHOD LinkAdded() { return NS_OK; }
|
|
|
|
NS_IMETHOD LinkRemoved() { return NS_OK; }
|
|
|
|
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers);
|
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
|
|
|
bool aNullParent = true);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex);
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
|
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsLink(nsIURI** aURI) const;
|
2008-02-21 12:39:20 -08:00
|
|
|
virtual void GetLinkTarget(nsAString& aTarget);
|
2009-07-13 04:48:06 -07:00
|
|
|
virtual nsLinkState GetLinkState() const;
|
|
|
|
virtual already_AddRefed<nsIURI> GetHrefURI() const;
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsAString& aValue, bool aNotify)
|
2008-02-21 12:39:20 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
|
2008-02-21 12:39:20 -08:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2008-02-21 12:39:20 -08:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID,
|
2009-03-10 06:51:34 -07:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult);
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
virtual nsEventStates IntrinsicState() const;
|
2010-07-23 02:49:57 -07:00
|
|
|
|
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
2012-04-25 06:47:30 -07:00
|
|
|
|
|
|
|
virtual nsIDOMNode* AsDOMNode() { return this; }
|
2012-12-02 12:55:52 -08:00
|
|
|
|
2012-01-20 15:14:46 -08:00
|
|
|
virtual void OnDNSPrefetchDeferred();
|
|
|
|
virtual void OnDNSPrefetchRequested();
|
|
|
|
virtual bool HasDeferredDNSPrefetchRequest();
|
2012-06-04 16:49:57 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void GetItemValueText(nsAString& text);
|
|
|
|
virtual void SetItemValueText(const nsAString& text);
|
2008-02-21 12:39:20 -08:00
|
|
|
};
|
|
|
|
|
2012-10-01 17:52:06 -07:00
|
|
|
#define ANCHOR_ELEMENT_FLAG_BIT(n_) NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
|
|
|
|
|
|
|
|
// Anchor element specific bits
|
|
|
|
enum {
|
|
|
|
// Indicates that a DNS Prefetch has been requested from this Anchor elem
|
|
|
|
HTML_ANCHOR_DNS_PREFETCH_REQUESTED = ANCHOR_ELEMENT_FLAG_BIT(0),
|
|
|
|
|
|
|
|
// Indicates that a DNS Prefetch was added to the deferral queue
|
|
|
|
HTML_ANCHOR_DNS_PREFETCH_DEFERRED = ANCHOR_ELEMENT_FLAG_BIT(1)
|
|
|
|
};
|
2012-01-20 15:14:46 -08:00
|
|
|
|
|
|
|
// Make sure we have enough space for those bits
|
2012-10-01 17:52:06 -07:00
|
|
|
PR_STATIC_ASSERT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 1 < 32);
|
|
|
|
|
|
|
|
#undef ANCHOR_ELEMENT_FLAG_BIT
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Anchor)
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsHTMLAnchorElement::nsHTMLAnchorElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2012-01-20 15:14:46 -08:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
, Link(this)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLAnchorElement::~nsHTMLAnchorElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 14:10:08 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLAnchorElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLAnchorElement, Element)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
DOMCI_NODE_DATA(HTMLAnchorElement, nsHTMLAnchorElement)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2008-02-21 12:39:20 -08:00
|
|
|
// QueryInterface implementation for nsHTMLAnchorElement
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsHTMLAnchorElement)
|
2010-08-04 19:40:17 -07:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLAnchorElement,
|
2008-11-03 02:31:47 -08:00
|
|
|
nsIDOMHTMLAnchorElement,
|
2010-02-24 08:37:03 -08:00
|
|
|
nsILink,
|
|
|
|
Link)
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAnchorElement,
|
|
|
|
nsGenericHTMLElement)
|
2008-02-21 12:39:20 -08:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAnchorElement)
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ELEMENT_CLONE(nsHTMLAnchorElement)
|
|
|
|
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Charset, charset)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Coords, coords)
|
|
|
|
NS_IMPL_URI_ATTR(nsHTMLAnchorElement, Href, href)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Hreflang, hreflang)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Name, name)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rel, rel)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rev, rev)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Shape, shape)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Type, type)
|
2012-12-02 12:55:52 -08:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Download, download)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-06 00:19:51 -07:00
|
|
|
int32_t
|
|
|
|
nsHTMLAnchorElement::TabIndexDefault()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
void
|
|
|
|
nsHTMLAnchorElement::GetItemValueText(nsAString& aValue)
|
|
|
|
{
|
|
|
|
GetHref(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLAnchorElement::SetItemValueText(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SetHref(aValue);
|
|
|
|
}
|
|
|
|
|
2012-10-06 00:19:52 -07:00
|
|
|
bool
|
|
|
|
nsHTMLAnchorElement::Draggable() const
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
// links can be dragged as long as there is an href and the
|
|
|
|
// draggable attribute isn't false
|
2012-10-06 00:19:52 -07:00
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
|
|
|
// no href, so just use the same behavior as other elements
|
|
|
|
return nsGenericHTMLElement::Draggable();
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
2012-10-06 00:19:52 -07:00
|
|
|
return !AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable,
|
|
|
|
nsGkAtoms::_false, eIgnoreCase);
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-20 15:14:46 -08:00
|
|
|
void
|
|
|
|
nsHTMLAnchorElement::OnDNSPrefetchRequested()
|
|
|
|
{
|
|
|
|
UnsetFlags(HTML_ANCHOR_DNS_PREFETCH_DEFERRED);
|
|
|
|
SetFlags(HTML_ANCHOR_DNS_PREFETCH_REQUESTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLAnchorElement::OnDNSPrefetchDeferred()
|
|
|
|
{
|
|
|
|
UnsetFlags(HTML_ANCHOR_DNS_PREFETCH_REQUESTED);
|
|
|
|
SetFlags(HTML_ANCHOR_DNS_PREFETCH_DEFERRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLAnchorElement::HasDeferredDNSPrefetchRequest()
|
|
|
|
{
|
|
|
|
return HasFlag(HTML_ANCHOR_DNS_PREFETCH_DEFERRED);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLAnchorElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2009-11-23 10:48:52 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-12-05 12:53:24 -08:00
|
|
|
// Prefetch links
|
2011-11-13 19:24:41 -08:00
|
|
|
if (aDocument) {
|
|
|
|
aDocument->RegisterPendingLinkUpdate(this);
|
|
|
|
if (nsHTMLDNSPrefetch::IsAllowed(OwnerDoc())) {
|
|
|
|
nsHTMLDNSPrefetch::PrefetchLow(this);
|
|
|
|
}
|
2008-12-05 12:53:24 -08:00
|
|
|
}
|
2011-11-13 19:24:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLAnchorElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-20 15:14:46 -08:00
|
|
|
// Cancel any DNS prefetches
|
|
|
|
// Note: Must come before ResetLinkState. If called after, it will recreate
|
|
|
|
// mCachedURI based on data that is invalid - due to a call to GetHostname.
|
|
|
|
|
|
|
|
// If prefetch was deferred, clear flag and move on
|
|
|
|
if (HasFlag(HTML_ANCHOR_DNS_PREFETCH_DEFERRED))
|
|
|
|
UnsetFlags(HTML_ANCHOR_DNS_PREFETCH_DEFERRED);
|
|
|
|
// Else if prefetch was requested, clear flag and send cancellation
|
|
|
|
else if (HasFlag(HTML_ANCHOR_DNS_PREFETCH_REQUESTED)) {
|
|
|
|
UnsetFlags(HTML_ANCHOR_DNS_PREFETCH_REQUESTED);
|
|
|
|
// Possible that hostname could have changed since binding, but since this
|
|
|
|
// covers common cases, most DNS prefetch requests will be canceled
|
|
|
|
nsHTMLDNSPrefetch::CancelPrefetchLow(this, NS_ERROR_ABORT);
|
|
|
|
}
|
|
|
|
|
2009-11-23 10:48:52 -08:00
|
|
|
// If this link is ever reinserted into a document, it might
|
|
|
|
// be under a different xml:base, so forget the cached state now.
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(false, Link::ElementHasHref());
|
2011-11-13 19:24:41 -08:00
|
|
|
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->UnregisterPendingLinkUpdate(this);
|
|
|
|
}
|
2009-11-23 10:48:52 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsHTMLAnchorElement::IsHTMLFocusable(bool aWithMouse,
|
2012-08-22 08:56:38 -07:00
|
|
|
bool *aIsFocusable, int32_t *aTabIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-21 05:37:34 -07:00
|
|
|
if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-04-15 11:40:38 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// cannot focus links if there is no link handler
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (doc) {
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell* presShell = doc->GetShell();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (presShell) {
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
if (presContext && !presContext->GetLinkHandler()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsFocusable = false;
|
|
|
|
return false;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-15 11:40:38 -07:00
|
|
|
if (IsEditable()) {
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsFocusable = false;
|
2008-04-15 11:40:38 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
|
|
|
|
// check whether we're actually a link
|
2012-05-22 20:03:32 -07:00
|
|
|
if (!Link::HasURI()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Not tabbable or focusable without href (bug 17605), unless
|
|
|
|
// forced to be via presence of nonnegative tabindex attribute
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
2008-04-15 11:40:38 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsFocusable = false;
|
2008-04-15 11:40:38 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex && (sTabFocusModel & eTabFocus_linksMask) == 0) {
|
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsFocusable = true;
|
2008-04-15 11:40:38 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-23 00:31:21 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLAnchorElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
return PreHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLAnchorElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
return PostHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLAnchorElement::IsLink(nsIURI** aURI) const
|
|
|
|
{
|
|
|
|
return IsHTMLLink(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLAnchorElement::GetLinkTarget(nsAString& aTarget)
|
|
|
|
{
|
2007-03-26 06:19:33 -07:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
|
|
|
|
if (aTarget.IsEmpty()) {
|
|
|
|
GetBaseTarget(aTarget);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::GetTarget(nsAString& aValue)
|
|
|
|
{
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue)) {
|
|
|
|
GetBaseTarget(aValue);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::SetTarget(const nsAString& aValue)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-09 19:32:09 -07:00
|
|
|
#define IMPL_URI_PART(_part) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsHTMLAnchorElement::Get##_part(nsAString& a##_part) \
|
|
|
|
{ \
|
2009-11-09 10:00:54 -08:00
|
|
|
return Link::Get##_part(a##_part); \
|
2009-03-09 19:32:09 -07:00
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsHTMLAnchorElement::Set##_part(const nsAString& a##_part) \
|
|
|
|
{ \
|
2009-11-09 10:00:54 -08:00
|
|
|
return Link::Set##_part(a##_part); \
|
2009-03-09 19:32:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-09 19:32:09 -07:00
|
|
|
IMPL_URI_PART(Protocol)
|
|
|
|
IMPL_URI_PART(Host)
|
|
|
|
IMPL_URI_PART(Hostname)
|
|
|
|
IMPL_URI_PART(Pathname)
|
|
|
|
IMPL_URI_PART(Search)
|
|
|
|
IMPL_URI_PART(Port)
|
|
|
|
IMPL_URI_PART(Hash)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-09 19:32:09 -07:00
|
|
|
#undef IMPL_URI_PART
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::GetText(nsAString& aText)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(this, true, aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-30 16:48:57 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::SetText(const nsAString& aText)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return nsContentUtils::SetNodeTextContent(this, aText, false);
|
2010-07-30 16:48:57 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::ToString(nsAString& aSource)
|
|
|
|
{
|
|
|
|
return GetHref(aSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::GetPing(nsAString& aValue)
|
|
|
|
{
|
|
|
|
return GetURIListAttr(nsGkAtoms::ping, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLAnchorElement::SetPing(const nsAString& aValue)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-13 04:48:06 -07:00
|
|
|
nsLinkState
|
|
|
|
nsHTMLAnchorElement::GetLinkState() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-13 15:13:41 -07:00
|
|
|
return Link::GetLinkState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-13 04:48:06 -07:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLAnchorElement::GetHrefURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-23 23:57:16 -07:00
|
|
|
nsIURI* uri = Link::GetCachedURI();
|
|
|
|
if (uri) {
|
|
|
|
NS_ADDREF(uri);
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2009-07-13 04:48:06 -07:00
|
|
|
return GetHrefURIForAnchors();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLAnchorElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-24 08:37:38 -08:00
|
|
|
bool reset = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2010-06-16 09:59:26 -07:00
|
|
|
// If we do not have a cached URI, we have some value here so we must reset
|
|
|
|
// our link state after calling the parent.
|
|
|
|
if (!Link::HasCachedURI()) {
|
2010-02-24 08:37:38 -08:00
|
|
|
reset = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-16 09:59:26 -07:00
|
|
|
// However, if we have a cached URI, we'll want to see if the value changed.
|
|
|
|
else {
|
|
|
|
nsAutoString val;
|
|
|
|
GetHref(val);
|
|
|
|
if (!val.Equals(aValue)) {
|
|
|
|
reset = true;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
|
|
|
|
2010-02-24 08:37:38 -08:00
|
|
|
// The ordering of the parent class's SetAttr call and Link::ResetLinkState
|
|
|
|
// is important here! The attribute is not set until SetAttr returns, and
|
|
|
|
// we will need the updated attribute value because notifying the document
|
|
|
|
// that content states have changed will call IntrinsicState, which will try
|
|
|
|
// to get updated information about the visitedness from Link.
|
|
|
|
if (reset) {
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(!!aNotify, true);
|
2010-02-24 08:37:38 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLAnchorElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-03 12:55:35 -08:00
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
|
|
|
|
|
|
|
// The ordering of the parent class's UnsetAttr call and Link::ResetLinkState
|
|
|
|
// is important here! The attribute is not unset until UnsetAttr returns, and
|
|
|
|
// we will need the updated attribute value because notifying the document
|
|
|
|
// that content states have changed will call IntrinsicState, which will try
|
|
|
|
// to get updated information about the visitedness from Link.
|
|
|
|
if (aAttribute == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2012-12-07 06:35:14 -08:00
|
|
|
Link::ResetLinkState(!!aNotify, false);
|
2010-03-03 12:55:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-03-10 06:51:34 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLAnchorElement::ParseAttribute(int32_t aNamespaceID,
|
2009-11-09 10:00:54 -08:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2009-03-10 06:51:34 -07:00
|
|
|
{
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2009-12-15 16:04:09 -08:00
|
|
|
nsHTMLAnchorElement::IntrinsicState() const
|
|
|
|
{
|
|
|
|
return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
|
|
|
|
}
|
2011-08-17 15:14:53 -07:00
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
size_t
|
|
|
|
nsHTMLAnchorElement::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf) +
|
|
|
|
Link::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|