diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp
index c8348a36039..c8685c60361 100644
--- a/accessible/src/html/nsHTMLImageAccessible.cpp
+++ b/accessible/src/html/nsHTMLImageAccessible.cpp
@@ -284,9 +284,9 @@ nsHTMLImageAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
if (!domNode)
return NS_ERROR_INVALID_ARG;
- nsCOMPtr link(do_QueryInterface(domNode));
+ nsCOMPtr link(do_QueryInterface(domNode));
if (link)
- link->GetHrefURI(aURI);
+ *aURI = link->GetHrefURI();
return NS_OK;
}
diff --git a/accessible/src/html/nsHTMLLinkAccessible.cpp b/accessible/src/html/nsHTMLLinkAccessible.cpp
index d90ef2625d5..38a571e8abf 100644
--- a/accessible/src/html/nsHTMLLinkAccessible.cpp
+++ b/accessible/src/html/nsHTMLLinkAccessible.cpp
@@ -82,11 +82,7 @@ nsHTMLLinkAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
*aState |= nsIAccessibleStates::STATE_SELECTABLE;
}
- nsCOMPtr link = do_QueryInterface(mDOMNode);
- NS_ENSURE_STATE(link);
-
- nsLinkState linkState;
- link->GetLinkState(linkState);
+ nsLinkState linkState = content->GetLinkState();
if (linkState == eLinkState_NotLink || linkState == eLinkState_Unknown) {
// This is a either named anchor (a link with also a name attribute) or
// it doesn't have any attributes. Check if 'click' event handler is
@@ -180,10 +176,11 @@ nsHTMLLinkAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
if (aIndex != 0)
return NS_ERROR_INVALID_ARG;
- nsCOMPtr link(do_QueryInterface(mDOMNode));
+ nsCOMPtr link(do_QueryInterface(mDOMNode));
NS_ENSURE_STATE(link);
- return link->GetHrefURI(aURI);
+ *aURI = link->GetHrefURI();
+ return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@@ -192,13 +189,11 @@ nsHTMLLinkAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
PRBool
nsHTMLLinkAccessible::IsLinked()
{
- nsCOMPtr link(do_QueryInterface(mDOMNode));
+ nsCOMPtr link(do_QueryInterface(mDOMNode));
if (!link)
return PR_FALSE;
- nsLinkState linkState;
- nsresult rv = link->GetLinkState(linkState);
+ nsLinkState linkState = link->GetLinkState();
- return NS_SUCCEEDED(rv) && linkState != eLinkState_NotLink &&
- linkState != eLinkState_Unknown;
+ return linkState != eLinkState_NotLink && linkState != eLinkState_Unknown;
}
diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h
index f592c7fcfbf..44ec61d3680 100644
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -61,10 +61,17 @@ class nsIDocShell;
class nsISMILAttr;
#endif // MOZ_SMIL
+enum nsLinkState {
+ eLinkState_Unknown = 0,
+ eLinkState_Unvisited = 1,
+ eLinkState_Visited = 2,
+ eLinkState_NotLink = 3
+};
+
// IID for the nsIContent interface
#define NS_ICONTENT_IID \
-{ 0x08dadcc4, 0x057a, 0x4b8d, \
- { 0x89, 0x43, 0x30, 0x0e, 0x61, 0xc6, 0x9d, 0x36 } }
+{ 0x4aaa38b8, 0x6bc1, 0x4d01, \
+ { 0xb6, 0x3d, 0xcd, 0x11, 0xc0, 0x84, 0x56, 0x9e } }
/**
* A node of content in a document's content model. This interface
@@ -598,6 +605,40 @@ public:
*/
virtual PRBool IsLink(nsIURI** aURI) const = 0;
+ /**
+ * Get the cached state of the link. If the state is unknown,
+ * return eLinkState_Unknown.
+ *
+ * @return The cached link state of the link.
+ */
+ virtual nsLinkState GetLinkState() const
+ {
+ return eLinkState_NotLink;
+ }
+
+ /**
+ * Set the cached state of the link.
+ *
+ * @param aState The cached link state of the link.
+ */
+ virtual void SetLinkState(nsLinkState aState)
+ {
+ NS_ASSERTION(aState == eLinkState_NotLink,
+ "Need to override SetLinkState?");
+ }
+
+ /**
+ * Get a pointer to the full href URI (fully resolved and canonicalized,
+ * since it's an nsIURI object) for link elements.
+ *
+ * @return A pointer to the URI or null if the element is not a link or it
+ * has no HREF attribute.
+ */
+ virtual already_AddRefed GetHrefURI() const
+ {
+ return nsnull;
+ }
+
/**
* Give this element a chance to fire links that should be fired
* automatically when loaded. If the element was an autoloading link
diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp
index 6ff87df4e87..cc8fe7b608d 100644
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -7305,10 +7305,7 @@ public:
// Throw away the cached link state so it gets refetched by the style
// system
- nsCOMPtr link = do_QueryInterface(aContent);
- if (link) {
- link->SetLinkState(eLinkState_Unknown);
- }
+ aContent->SetLinkState(eLinkState_Unknown);
contentVisited.AppendObject(aContent);
}
};
diff --git a/content/html/content/public/nsILink.h b/content/html/content/public/nsILink.h
index 842b5fbccb5..e53e0e8506d 100644
--- a/content/html/content/public/nsILink.h
+++ b/content/html/content/public/nsILink.h
@@ -45,8 +45,8 @@ class nsIURI;
// IID for the nsILink interface
#define NS_ILINK_IID \
-{ 0x0c212bc4, 0xfcd7, 0x479d, \
- { 0x8c, 0x3f, 0x3b, 0xe8, 0xe6, 0x78, 0x74, 0x50 } }
+{ 0x6f374a11, 0x212d, 0x47d6, \
+ { 0x94, 0xd1, 0xe6, 0x7c, 0x23, 0x4d, 0x34, 0x99 } }
/**
* This interface allows SelectorMatches to get the canonical
@@ -60,31 +60,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINK_IID)
/**
- * Get the cached state of the link. If the state is unknown,
- * return eLinkState_Unknown.
- *
- * @param aState [out] The cached link state of the link.
- * @return NS_OK
+ * GetLinkState/SetLinkState/GetHrefURI were moved to nsIContent.
+ * @see nsIContent
*/
- NS_IMETHOD GetLinkState(nsLinkState &aState) = 0;
-
- /**
- * Set the cached state of the link.
- *
- * @param aState The cached link state of the link.
- * @return NS_OK
- */
- NS_IMETHOD SetLinkState(nsLinkState aState) = 0;
-
- /**
- * Get a pointer to the fully href URI (fully resolved and canonicalized,
- * since it's an nsIURI object).
- *
- * @param aURI [out] A pointer to be filled in with a pointer to the URI
- * If the element has no HREF attribute, it is set to nsnull.
- * @return NS_OK if the out pointer is filled in (possibly with nsnull)
- */
- NS_IMETHOD GetHrefURI(nsIURI** aURI) = 0;
/**
* Dispatch a LinkAdded event to the chrome event handler for this document.
diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp
index 665f16b33eb..1ceacbbe41e 100644
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1013,13 +1013,13 @@ nsGenericHTMLElement::IsHTMLLink(nsIURI** aURI) const
{
NS_PRECONDITION(aURI, "Must provide aURI out param");
- GetHrefURIForAnchors(aURI);
+ *aURI = GetHrefURIForAnchors().get();
// We promise out param is non-null if we return true, so base rv on it
return *aURI != nsnull;
}
-nsresult
-nsGenericHTMLElement::GetHrefURIForAnchors(nsIURI** aURI) const
+already_AddRefed
+nsGenericHTMLElement::GetHrefURIForAnchors() const
{
// This is used by the three nsILink implementations and
// nsHTMLStyleElement.
@@ -1027,9 +1027,10 @@ nsGenericHTMLElement::GetHrefURIForAnchors(nsIURI** aURI) const
// Get href= attribute (relative URI).
// We use the nsAttrValue's copy of the URI string to avoid copying.
- GetURIAttr(nsGkAtoms::href, nsnull, PR_FALSE, aURI);
+ nsCOMPtr uri;
+ GetURIAttr(nsGkAtoms::href, nsnull, PR_FALSE, getter_AddRefs(uri));
- return NS_OK;
+ return uri.forget();
}
void
@@ -3194,8 +3195,7 @@ nsGenericHTMLElement::SetPortInHrefURI(const nsAString &aPort)
nsresult
nsGenericHTMLElement::GetProtocolFromHrefURI(nsAString& aProtocol)
{
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
if (!uri) {
aProtocol.AssignLiteral("http");
@@ -3213,8 +3213,7 @@ nsGenericHTMLElement::GetHostFromHrefURI(nsAString& aHost)
{
aHost.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
@@ -3238,8 +3237,7 @@ nsresult
nsGenericHTMLElement::GetHostnameFromHrefURI(nsAString& aHostname)
{
aHostname.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
@@ -3264,8 +3262,7 @@ nsGenericHTMLElement::GetPathnameFromHrefURI(nsAString& aPathname)
{
aPathname.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
@@ -3294,8 +3291,7 @@ nsresult
nsGenericHTMLElement::GetSearchFromHrefURI(nsAString& aSearch)
{
aSearch.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
nsCOMPtr url(do_QueryInterface(uri));
if (!url) {
// Don't throw from these methods! Not a valid URI means return
@@ -3319,8 +3315,7 @@ nsresult
nsGenericHTMLElement::GetPortFromHrefURI(nsAString& aPort)
{
aPort.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
@@ -3350,8 +3345,7 @@ nsresult
nsGenericHTMLElement::GetHashFromHrefURI(nsAString& aHash)
{
aHash.Truncate();
- nsCOMPtr uri;
- GetHrefURIForAnchors(getter_AddRefs(uri));
+ nsCOMPtr uri = GetHrefURIForAnchors();
nsCOMPtr url(do_QueryInterface(uri));
if (!url) {
// Don't throw from these methods! Not a valid URI means return
diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h
index 612b2921eaa..66925509a7c 100644
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -196,7 +196,7 @@ public:
PRBool IsHTMLLink(nsIURI** aURI) const;
// Used by A, AREA, LINK, and STYLE.
- nsresult GetHrefURIForAnchors(nsIURI** aURI) const;
+ already_AddRefed GetHrefURIForAnchors() const;
// As above, but makes sure to return a URI object that we can mutate with
// impunity without changing our current URI. That is, if the URI is cached
diff --git a/content/html/content/src/nsHTMLAnchorElement.cpp b/content/html/content/src/nsHTMLAnchorElement.cpp
index 7c619cfba76..f69b67b2445 100644
--- a/content/html/content/src/nsHTMLAnchorElement.cpp
+++ b/content/html/content/src/nsHTMLAnchorElement.cpp
@@ -99,9 +99,6 @@ public:
NS_DECL_NSIDOMNSHTMLANCHORELEMENT2
// nsILink
- NS_IMETHOD GetLinkState(nsLinkState &aState);
- NS_IMETHOD SetLinkState(nsLinkState aState);
- NS_IMETHOD GetHrefURI(nsIURI** aURI);
NS_IMETHOD LinkAdded() { return NS_OK; }
NS_IMETHOD LinkRemoved() { return NS_OK; }
@@ -119,6 +116,9 @@ public:
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
+ virtual nsLinkState GetLinkState() const;
+ virtual void SetLinkState(nsLinkState aState);
+ virtual already_AddRefed GetHrefURI() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue, PRBool aNotify)
@@ -422,24 +422,22 @@ nsHTMLAnchorElement::SetPing(const nsAString& aValue)
return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, PR_TRUE);
}
-NS_IMETHODIMP
-nsHTMLAnchorElement::GetLinkState(nsLinkState &aState)
+nsLinkState
+nsHTMLAnchorElement::GetLinkState() const
{
- aState = mLinkState;
- return NS_OK;
+ return mLinkState;
}
-NS_IMETHODIMP
+void
nsHTMLAnchorElement::SetLinkState(nsLinkState aState)
{
mLinkState = aState;
- return NS_OK;
}
-NS_IMETHODIMP
-nsHTMLAnchorElement::GetHrefURI(nsIURI** aURI)
+already_AddRefed
+nsHTMLAnchorElement::GetHrefURI() const
{
- return GetHrefURIForAnchors(aURI);
+ return GetHrefURIForAnchors();
}
nsresult
diff --git a/content/html/content/src/nsHTMLAreaElement.cpp b/content/html/content/src/nsHTMLAreaElement.cpp
index fe9ade6ba93..33eaa22ad06 100644
--- a/content/html/content/src/nsHTMLAreaElement.cpp
+++ b/content/html/content/src/nsHTMLAreaElement.cpp
@@ -81,9 +81,6 @@ public:
NS_DECL_NSIDOMNSHTMLAREAELEMENT2
// nsILink
- NS_IMETHOD GetLinkState(nsLinkState &aState);
- NS_IMETHOD SetLinkState(nsLinkState aState);
- NS_IMETHOD GetHrefURI(nsIURI** aURI);
NS_IMETHOD LinkAdded() { return NS_OK; }
NS_IMETHOD LinkRemoved() { return NS_OK; }
@@ -91,6 +88,9 @@ public:
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
+ virtual nsLinkState GetLinkState() const;
+ virtual void SetLinkState(nsLinkState aState);
+ virtual already_AddRefed GetHrefURI() const;
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
@@ -320,22 +320,20 @@ nsHTMLAreaElement::SetPing(const nsAString& aValue)
return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, PR_TRUE);
}
-NS_IMETHODIMP
-nsHTMLAreaElement::GetLinkState(nsLinkState &aState)
+nsLinkState
+nsHTMLAreaElement::GetLinkState() const
{
- aState = mLinkState;
- return NS_OK;
+ return mLinkState;
}
-NS_IMETHODIMP
+void
nsHTMLAreaElement::SetLinkState(nsLinkState aState)
{
mLinkState = aState;
- return NS_OK;
}
-NS_IMETHODIMP
-nsHTMLAreaElement::GetHrefURI(nsIURI** aURI)
+already_AddRefed
+nsHTMLAreaElement::GetHrefURI() const
{
- return GetHrefURIForAnchors(aURI);
+ return GetHrefURIForAnchors();
}
diff --git a/content/html/content/src/nsHTMLDNSPrefetch.cpp b/content/html/content/src/nsHTMLDNSPrefetch.cpp
index 96054d09444..f82b63e157d 100644
--- a/content/html/content/src/nsHTMLDNSPrefetch.cpp
+++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp
@@ -260,7 +260,7 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
if (mEntries[mTail].mElement->GetOwnerDoc()) {
nsCOMPtr hrefURI;
- mEntries[mTail].mElement->GetHrefURIForAnchors(getter_AddRefs(hrefURI));
+ hrefURI = mEntries[mTail].mElement->GetHrefURIForAnchors();
if (hrefURI)
hrefURI->GetAsciiHost(hostName);
diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp
index 03c7d91ae8a..bf68000fe7d 100644
--- a/content/html/content/src/nsHTMLLinkElement.cpp
+++ b/content/html/content/src/nsHTMLLinkElement.cpp
@@ -85,9 +85,6 @@ public:
NS_DECL_NSIDOMHTMLLINKELEMENT
// nsILink
- NS_IMETHOD GetLinkState(nsLinkState &aState);
- NS_IMETHOD SetLinkState(nsLinkState aState);
- NS_IMETHOD GetHrefURI(nsIURI** aURI);
NS_IMETHOD LinkAdded();
NS_IMETHOD LinkRemoved();
@@ -112,6 +109,9 @@ public:
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
+ virtual nsLinkState GetLinkState() const;
+ virtual void SetLinkState(nsLinkState aState);
+ virtual already_AddRefed GetHrefURI() const;
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
@@ -377,24 +377,22 @@ nsHTMLLinkElement::GetLinkTarget(nsAString& aTarget)
}
}
-NS_IMETHODIMP
-nsHTMLLinkElement::GetLinkState(nsLinkState &aState)
+nsLinkState
+nsHTMLLinkElement::GetLinkState() const
{
- aState = mLinkState;
- return NS_OK;
+ return mLinkState;
}
-NS_IMETHODIMP
+void
nsHTMLLinkElement::SetLinkState(nsLinkState aState)
{
mLinkState = aState;
- return NS_OK;
}
-NS_IMETHODIMP
-nsHTMLLinkElement::GetHrefURI(nsIURI** aURI)
+already_AddRefed
+nsHTMLLinkElement::GetHrefURI() const
{
- return GetHrefURIForAnchors(aURI);
+ return GetHrefURIForAnchors();
}
void
@@ -402,7 +400,7 @@ nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline,
nsIURI** aURI)
{
*aIsInline = PR_FALSE;
- GetHrefURIForAnchors(aURI);
+ *aURI = GetHrefURIForAnchors().get();
return;
}
diff --git a/content/html/content/src/nsHTMLStyleElement.cpp b/content/html/content/src/nsHTMLStyleElement.cpp
index 0e0a4d9f7a5..2a606cb13e4 100644
--- a/content/html/content/src/nsHTMLStyleElement.cpp
+++ b/content/html/content/src/nsHTMLStyleElement.cpp
@@ -328,7 +328,7 @@ nsHTMLStyleElement::GetStyleSheetURL(PRBool* aIsInline,
return;
}
- GetHrefURIForAnchors(aURI);
+ *aURI = GetHrefURIForAnchors().get();
return;
}
diff --git a/content/svg/content/src/nsSVGAElement.cpp b/content/svg/content/src/nsSVGAElement.cpp
index a3403d039a2..408846d8c0c 100644
--- a/content/svg/content/src/nsSVGAElement.cpp
+++ b/content/svg/content/src/nsSVGAElement.cpp
@@ -120,33 +120,27 @@ nsSVGAElement::GetTarget(nsIDOMSVGAnimatedString * *aTarget)
//----------------------------------------------------------------------
-// nsILink methods
+// nsIContent methods
-NS_IMETHODIMP
-nsSVGAElement::GetLinkState(nsLinkState &aState)
+nsLinkState
+nsSVGAElement::GetLinkState() const
{
- aState = mLinkState;
- return NS_OK;
+ return mLinkState;
}
-NS_IMETHODIMP
+void
nsSVGAElement::SetLinkState(nsLinkState aState)
{
mLinkState = aState;
- return NS_OK;
}
-NS_IMETHODIMP
-nsSVGAElement::GetHrefURI(nsIURI** aURI)
+already_AddRefed
+nsSVGAElement::GetHrefURI() const
{
- *aURI = nsnull;
- return NS_OK; // XXX GetHrefURIForAnchors(aURI);
+ return nsnull; // XXX GetHrefURIForAnchors();
}
-//----------------------------------------------------------------------
-// nsIContent methods
-
PRBool
nsSVGAElement::IsFocusable(PRInt32 *aTabIndex)
{
diff --git a/content/svg/content/src/nsSVGAElement.h b/content/svg/content/src/nsSVGAElement.h
index 5dc24cd5b17..5a9b607d3e8 100644
--- a/content/svg/content/src/nsSVGAElement.h
+++ b/content/svg/content/src/nsSVGAElement.h
@@ -71,9 +71,6 @@ public:
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
// nsILink
- NS_IMETHOD GetLinkState(nsLinkState &aState);
- NS_IMETHOD SetLinkState(nsLinkState aState);
- NS_IMETHOD GetHrefURI(nsIURI** aURI);
NS_IMETHOD LinkAdded() { return NS_OK; }
NS_IMETHOD LinkRemoved() { return NS_OK; }
@@ -81,6 +78,9 @@ public:
virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull);
virtual PRBool IsLink(nsIURI** aURI) const;
virtual void GetLinkTarget(nsAString& aTarget);
+ virtual nsLinkState GetLinkState() const;
+ virtual void SetLinkState(nsLinkState aState);
+ virtual already_AddRefed GetHrefURI() const;
protected:
diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp
index 0980710e983..246e6da3f6d 100644
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1380,7 +1380,7 @@ nsImageFrame::GetAnchorHREFTargetAndNode(nsIURI** aHref, nsString& aTarget,
content; content = content->GetParent()) {
nsCOMPtr link(do_QueryInterface(content));
if (link) {
- link->GetHrefURI(aHref);
+ *aHref = content->GetHrefURI().get();
status = (*aHref != nsnull);
nsCOMPtr anchor(do_QueryInterface(content));
diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp
index 80c1a470740..30323316a7f 100644
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -909,8 +909,7 @@ RuleProcessorData::RuleProcessorData(nsPresContext* aPresContext,
mPresContext ? mPresContext->GetLinkHandler() : nsnull;
if (mIsHTMLContent && mHasAttributes) {
// check if it is an HTML Link
- if(nsStyleUtil::IsHTMLLink(aContent, mContentTag, linkHandler,
- &mLinkState)) {
+ if(nsStyleUtil::IsHTMLLink(aContent, linkHandler, &mLinkState)) {
mIsLink = PR_TRUE;
}
}
diff --git a/layout/style/nsIStyleRuleProcessor.h b/layout/style/nsIStyleRuleProcessor.h
index e5b7b82fd91..4588b949948 100644
--- a/layout/style/nsIStyleRuleProcessor.h
+++ b/layout/style/nsIStyleRuleProcessor.h
@@ -49,13 +49,12 @@
#include "nsISupports.h"
#include "nsPresContext.h" // for nsCompatability
-#include "nsILinkHandler.h"
#include "nsString.h"
#include "nsChangeHint.h"
+#include "nsIContent.h"
class nsIStyleSheet;
class nsPresContext;
-class nsIContent;
class nsIAtom;
class nsICSSPseudoComparator;
class nsRuleWalker;
diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp
index caeb357b9fb..4a967c50074 100644
--- a/layout/style/nsStyleUtil.cpp
+++ b/layout/style/nsStyleUtil.cpp
@@ -42,7 +42,6 @@
#include "nsGkAtoms.h"
#include "nsILinkHandler.h"
-#include "nsILink.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
@@ -429,55 +428,40 @@ GetLinkStateFromURI(nsIURI* aURI, nsIContent* aContent,
}
/*static*/
-PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag,
+PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent,
nsILinkHandler *aLinkHandler,
nsLinkState *aState)
{
- NS_ASSERTION(aContent && aState, "null arg in IsHTMLLink");
+ NS_ASSERTION(aContent->IsNodeOfType(nsINode::eHTML),
+ "Only use this function with HTML elements");
+ NS_ASSERTION(aState, "null arg in IsHTMLLink");
- // check for:
- // - HTML ANCHOR with valid HREF
- // - HTML LINK with valid HREF
- // - HTML AREA with valid HREF
+ nsLinkState linkState = aContent->GetLinkState();
+ if (linkState == eLinkState_Unknown) {
+ // if it is an anchor, area or link then check the href attribute
+ // make sure this anchor has a link even if we are not testing state
+ // if there is no link, then this anchor is not really a linkpseudo.
+ // bug=23209
- PRBool result = PR_FALSE;
+ nsCOMPtr hrefURI = aContent->GetHrefURI();
- if ((aTag == nsGkAtoms::a) ||
- (aTag == nsGkAtoms::link) ||
- (aTag == nsGkAtoms::area)) {
-
- nsCOMPtr link( do_QueryInterface(aContent) );
- // In XML documents, this can be null.
- if (link) {
- nsLinkState linkState;
- link->GetLinkState(linkState);
- if (linkState == eLinkState_Unknown) {
- // if it is an anchor, area or link then check the href attribute
- // make sure this anchor has a link even if we are not testing state
- // if there is no link, then this anchor is not really a linkpseudo.
- // bug=23209
-
- nsCOMPtr hrefURI;
- link->GetHrefURI(getter_AddRefs(hrefURI));
-
- if (hrefURI) {
- linkState = GetLinkStateFromURI(hrefURI, aContent, aLinkHandler);
- } else {
- linkState = eLinkState_NotLink;
- }
- if (linkState != eLinkState_NotLink && aContent->IsInDoc()) {
- aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, hrefURI);
- }
- link->SetLinkState(linkState);
- }
- if (linkState != eLinkState_NotLink) {
- *aState = linkState;
- result = PR_TRUE;
- }
+ if (hrefURI) {
+ linkState = GetLinkStateFromURI(hrefURI, aContent, aLinkHandler);
+ } else {
+ linkState = eLinkState_NotLink;
}
+ if (linkState != eLinkState_NotLink && aContent->IsInDoc()) {
+ aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, hrefURI);
+ }
+ aContent->SetLinkState(linkState);
+ }
+ if (linkState == eLinkState_NotLink) {
+ return PR_FALSE;
}
- return result;
+ *aState = linkState;
+
+ return PR_TRUE;
}
/*static*/
diff --git a/layout/style/nsStyleUtil.h b/layout/style/nsStyleUtil.h
index 5f7d76179c1..62f474148fb 100644
--- a/layout/style/nsStyleUtil.h
+++ b/layout/style/nsStyleUtil.h
@@ -69,8 +69,7 @@ public:
static PRInt32 ConstrainFontWeight(PRInt32 aWeight);
- static PRBool IsHTMLLink(nsIContent *aContent, nsIAtom *aTag,
- nsILinkHandler *aLinkHandler,
+ static PRBool IsHTMLLink(nsIContent *aContent, nsILinkHandler *aLinkHandler,
nsLinkState *aState);
static PRBool IsLink(nsIContent *aContent, nsILinkHandler *aLinkHandler,
nsLinkState *aState);
diff --git a/webshell/public/nsILinkHandler.h b/webshell/public/nsILinkHandler.h
index 913da51b18d..b860cd34b4c 100644
--- a/webshell/public/nsILinkHandler.h
+++ b/webshell/public/nsILinkHandler.h
@@ -38,11 +38,11 @@
#define nsILinkHandler_h___
#include "nsISupports.h"
+#include "nsIContent.h"
class nsIInputStream;
class nsIDocShell;
class nsIRequest;
-class nsIContent;
class nsString;
class nsGUIEvent;
@@ -50,13 +50,6 @@ class nsGUIEvent;
#define NS_ILINKHANDLER_IID \
{ 0x514bc565, 0x8d38, 0x4dde,{0xb4, 0xeb, 0xe7, 0xb5, 0x01, 0x2b, 0xf4, 0x64}}
-enum nsLinkState {
- eLinkState_Unknown = 0,
- eLinkState_Unvisited = 1,
- eLinkState_Visited = 2,
- eLinkState_NotLink = 3
-};
-
/**
* Interface used for handling clicks on links
*/