2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-01 01:27:08 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-09-01 01:27:08 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-09-01 01:27:08 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-01 01:27:08 +00:00
|
|
|
#include "nsIDOMHTMLLinkElement.h"
|
2000-08-22 04:14:53 +00:00
|
|
|
#include "nsIDOMLinkStyle.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
#include "nsIDOMEventReceiver.h"
|
1998-09-02 23:53:16 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2000-07-27 23:17:53 +00:00
|
|
|
#include "nsILink.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1999-02-23 19:18:12 +00:00
|
|
|
#include "nsIDOMStyleSheet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsStyleLinkElement.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-10-19 21:00:02 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2000-07-27 23:17:53 +00:00
|
|
|
#include "nsIURL.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIDocument.h"
|
2001-11-06 09:02:55 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
2005-02-02 03:17:49 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2001-11-06 09:02:55 +00:00
|
|
|
#include "nsIDOMDocumentEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
2002-04-05 11:29:40 +00:00
|
|
|
#include "nsParserUtils.h"
|
2005-10-10 18:38:57 +00:00
|
|
|
#include "nsContentUtils.h"
|
2005-06-15 23:52:46 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2004-02-10 19:36:43 +00:00
|
|
|
class nsHTMLLinkElement : public nsGenericHTMLElement,
|
2000-12-23 10:56:31 +00:00
|
|
|
public nsIDOMHTMLLinkElement,
|
2000-07-27 23:17:53 +00:00
|
|
|
public nsILink,
|
2001-05-19 02:59:15 +00:00
|
|
|
public nsStyleLinkElement
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-05-18 20:58:12 +00:00
|
|
|
nsHTMLLinkElement(nsINodeInfo *aNodeInfo);
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~nsHTMLLinkElement();
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
// nsISupports
|
2000-12-23 10:56:31 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
// nsIDOMNode
|
2004-02-10 19:36:43 +00:00
|
|
|
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
// nsIDOMElement
|
2004-02-10 19:36:43 +00:00
|
|
|
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
// nsIDOMHTMLElement
|
2004-02-10 19:36:43 +00:00
|
|
|
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
// nsIDOMHTMLLinkElement
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_DECL_NSIDOMHTMLLINKELEMENT
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2000-07-27 23:17:53 +00:00
|
|
|
// nsILink
|
|
|
|
NS_IMETHOD GetLinkState(nsLinkState &aState);
|
|
|
|
NS_IMETHOD SetLinkState(nsLinkState aState);
|
2003-07-01 02:59:54 +00:00
|
|
|
NS_IMETHOD GetHrefURI(nsIURI** aURI);
|
2005-06-15 23:52:46 +00:00
|
|
|
NS_IMETHOD LinkAdded();
|
|
|
|
NS_IMETHOD LinkRemoved();
|
2000-07-27 23:17:53 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
PRBool aCompileEventHandlers);
|
|
|
|
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
|
|
|
|
PRBool aNullParent = PR_TRUE);
|
|
|
|
void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName);
|
2004-01-15 17:07:27 +00:00
|
|
|
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAString& aValue, PRBool aNotify)
|
|
|
|
{
|
|
|
|
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
2004-01-15 17:07:27 +00:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2004-01-09 23:54:21 +00:00
|
|
|
PRBool aNotify);
|
|
|
|
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
PRBool aNotify);
|
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-09-01 01:27:08 +00:00
|
|
|
protected:
|
2002-04-05 11:29:40 +00:00
|
|
|
virtual void GetStyleSheetURL(PRBool* aIsInline,
|
2003-07-01 02:59:54 +00:00
|
|
|
nsIURI** aURI);
|
2002-04-05 11:29:40 +00:00
|
|
|
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
2002-03-23 23:04:39 +00:00
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
2002-04-05 11:29:40 +00:00
|
|
|
PRBool* aIsAlternate);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2000-07-27 23:17:53 +00:00
|
|
|
// The cached visited state
|
|
|
|
nsLinkState mLinkState;
|
1998-09-01 01:27:08 +00:00
|
|
|
};
|
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2004-05-18 20:58:12 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Link)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
|
2004-05-18 20:58:12 +00:00
|
|
|
nsHTMLLinkElement::nsHTMLLinkElement(nsINodeInfo *aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mLinkState(eLinkState_Unknown)
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-02 23:53:16 +00:00
|
|
|
nsHTMLLinkElement::~nsHTMLLinkElement()
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLLinkElement, nsGenericElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLLinkElement, nsGenericElement)
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
// QueryInterface implementation for nsHTMLLinkElement
|
2004-02-10 19:36:43 +00:00
|
|
|
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLinkElement, nsGenericHTMLElement)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLLinkElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMLinkStyle)
|
2003-06-08 19:53:55 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsILink)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleSheetLinkingElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLLinkElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_MAP_END
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
|
2004-10-15 14:42:14 +00:00
|
|
|
NS_IMPL_DOM_CLONENODE(nsHTMLLinkElement)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::GetDisabled(PRBool* aDisabled)
|
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
nsCOMPtr<nsIDOMStyleSheet> ss(do_QueryInterface(mStyleSheet));
|
1999-02-23 19:18:12 +00:00
|
|
|
nsresult result = NS_OK;
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
if (ss) {
|
|
|
|
result = ss->GetDisabled(aDisabled);
|
|
|
|
} else {
|
1999-02-23 19:18:12 +00:00
|
|
|
*aDisabled = PR_FALSE;
|
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::SetDisabled(PRBool aDisabled)
|
|
|
|
{
|
2000-12-23 10:56:31 +00:00
|
|
|
nsCOMPtr<nsIDOMStyleSheet> ss(do_QueryInterface(mStyleSheet));
|
1999-02-23 19:18:12 +00:00
|
|
|
nsresult result = NS_OK;
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
if (ss) {
|
|
|
|
result = ss->SetDisabled(aDisabled);
|
1999-02-23 19:18:12 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
1998-11-03 01:08:02 +00:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Charset, charset)
|
2003-07-08 05:35:04 +00:00
|
|
|
NS_IMPL_URI_ATTR(nsHTMLLinkElement, Href, href)
|
1998-11-03 01:08:02 +00:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Hreflang, hreflang)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Media, media)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Rel, rel)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Rev, rev)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Target, target)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLLinkElement, Type, type)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
PRBool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
UpdateStyleSheet(nsnull);
|
|
|
|
|
|
|
|
// XXXbz we really shouldn't fire the event until after we've finished with
|
|
|
|
// the outermost BindToTree... In particular, this can effectively cause us
|
|
|
|
// to reenter this code, or for some part of the document to become unbound
|
|
|
|
// inside the event!
|
|
|
|
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-06-15 23:52:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::LinkAdded()
|
|
|
|
{
|
|
|
|
CreateAndDispatchEvent(GetOwnerDoc(), NS_LITERAL_STRING("DOMLinkAdded"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::LinkRemoved()
|
|
|
|
{
|
|
|
|
CreateAndDispatchEvent(GetOwnerDoc(), NS_LITERAL_STRING("DOMLinkRemoved"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2005-04-05 23:54:35 +00:00
|
|
|
nsHTMLLinkElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
2004-08-10 10:22:36 +00:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
|
2005-08-10 20:21:44 +00:00
|
|
|
if (oldDoc) {
|
|
|
|
GetCurrentDoc()->ForgetLink(this);
|
|
|
|
// If this link is ever reinserted into a document, it might
|
|
|
|
// be under a different xml:base, so forget the cached state now
|
|
|
|
mLinkState = eLinkState_Unknown;
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
// XXXbz we really shouldn't fire the event until after we've finished with
|
|
|
|
// the outermost UnbindFromTree... In particular, this can effectively cause
|
|
|
|
// us to reenter this code, or to be bound to a different tree inside the
|
|
|
|
// event!
|
|
|
|
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2004-01-09 23:54:21 +00:00
|
|
|
UpdateStyleSheet(oldDoc);
|
|
|
|
}
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
|
|
|
nsHTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc,
|
|
|
|
const nsAString& aEventName)
|
|
|
|
{
|
|
|
|
if (!aDoc)
|
|
|
|
return;
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString rev;
|
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::rel, rel);
|
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::rev, rev);
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
// In the unlikely case that both rev is specified *and* rel=stylesheet,
|
|
|
|
// this code will cause the event to fire, on the principle that maybe the
|
|
|
|
// page really does want to specify that it's author is a stylesheet. Since
|
|
|
|
// this should never actually happen and the performance hit is minimal,
|
|
|
|
// doing the "right" thing costs virtually nothing here, even if it doesn't
|
|
|
|
// make much sense.
|
2005-04-05 23:54:35 +00:00
|
|
|
if (rev.IsEmpty() &&
|
|
|
|
(rel.IsEmpty() || rel.LowerCaseEqualsLiteral("stylesheet")))
|
2004-01-09 23:54:21 +00:00
|
|
|
return;
|
|
|
|
|
2005-10-10 18:38:57 +00:00
|
|
|
nsContentUtils::DispatchTrustedEvent(aDoc,
|
|
|
|
NS_STATIC_CAST(nsIContent*, this),
|
|
|
|
aEventName, PR_TRUE, PR_TRUE);
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLLinkElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
2004-01-15 17:07:27 +00:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
PRBool aNotify)
|
2004-01-09 23:54:21 +00:00
|
|
|
{
|
|
|
|
if (aName == nsHTMLAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2005-08-10 20:21:44 +00:00
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->ForgetLink(this);
|
|
|
|
// The change to 'href' will cause style reresolution which will
|
|
|
|
// eventually recompute the link state and re-add this element
|
|
|
|
// to the link map if necessary.
|
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
SetLinkState(eLinkState_Unknown);
|
|
|
|
}
|
|
|
|
|
2004-02-10 19:36:43 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
2004-01-09 23:54:21 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-12-09 19:20:42 +00:00
|
|
|
UpdateStyleSheet(nsnull, nsnull,
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsHTMLAtoms::rel ||
|
|
|
|
aName == nsHTMLAtoms::title ||
|
|
|
|
aName == nsHTMLAtoms::media ||
|
|
|
|
aName == nsHTMLAtoms::type));
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLLinkElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2004-02-10 19:36:43 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
2004-01-09 23:54:21 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-12-09 19:20:42 +00:00
|
|
|
UpdateStyleSheet(nsnull, nsnull,
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsHTMLAtoms::rel ||
|
|
|
|
aAttribute == nsHTMLAtoms::title ||
|
|
|
|
aAttribute == nsHTMLAtoms::media ||
|
|
|
|
aAttribute == nsHTMLAtoms::type));
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-03-07 17:08:51 +00:00
|
|
|
nsHTMLLinkElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
1998-09-01 01:27:08 +00:00
|
|
|
{
|
2006-03-07 17:08:51 +00:00
|
|
|
return PostHandleEventForAnchors(aVisitor);
|
1998-09-01 01:27:08 +00:00
|
|
|
}
|
1998-12-10 23:52:46 +00:00
|
|
|
|
2000-07-27 23:17:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::GetLinkState(nsLinkState &aState)
|
|
|
|
{
|
|
|
|
aState = mLinkState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkElement::SetLinkState(nsLinkState aState)
|
|
|
|
{
|
|
|
|
mLinkState = aState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-07-01 02:59:54 +00:00
|
|
|
nsHTMLLinkElement::GetHrefURI(nsIURI** aURI)
|
2000-07-27 23:17:53 +00:00
|
|
|
{
|
2003-07-01 02:59:54 +00:00
|
|
|
return GetHrefURIForAnchors(aURI);
|
2000-07-27 23:17:53 +00:00
|
|
|
}
|
2000-08-22 04:14:53 +00:00
|
|
|
|
2001-05-19 02:59:15 +00:00
|
|
|
void
|
2002-04-05 11:29:40 +00:00
|
|
|
nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline,
|
2003-07-01 02:59:54 +00:00
|
|
|
nsIURI** aURI)
|
2002-04-05 11:29:40 +00:00
|
|
|
{
|
|
|
|
*aIsInline = PR_FALSE;
|
2003-07-01 02:59:54 +00:00
|
|
|
GetHrefURIForAnchors(aURI);
|
2002-04-05 11:29:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
|
2002-03-23 23:04:39 +00:00
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
2001-05-19 02:59:15 +00:00
|
|
|
PRBool* aIsAlternate)
|
2000-08-22 04:14:53 +00:00
|
|
|
{
|
2001-05-19 02:59:15 +00:00
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
|
|
|
*aIsAlternate = PR_FALSE;
|
2000-08-22 04:14:53 +00:00
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
nsAutoString rel;
|
2001-09-06 19:16:03 +00:00
|
|
|
nsStringArray linkTypes(4);
|
2002-04-05 11:29:40 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::rel, rel);
|
2001-05-19 02:59:15 +00:00
|
|
|
nsStyleLinkElement::ParseLinkTypes(rel, linkTypes);
|
2002-04-05 11:29:40 +00:00
|
|
|
// Is it a stylesheet link?
|
|
|
|
if (linkTypes.IndexOf(NS_LITERAL_STRING("stylesheet")) < 0) {
|
2001-05-19 02:59:15 +00:00
|
|
|
return;
|
2002-04-05 11:29:40 +00:00
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
nsAutoString title;
|
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::title, title);
|
2001-05-19 02:59:15 +00:00
|
|
|
title.CompressWhitespace();
|
|
|
|
aTitle.Assign(title);
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
// If alternate, does it have title?
|
2001-05-19 02:59:15 +00:00
|
|
|
if (-1 != linkTypes.IndexOf(NS_LITERAL_STRING("alternate"))) {
|
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
*aIsAlternate = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::media, aMedia);
|
2001-05-19 02:59:15 +00:00
|
|
|
ToLowerCase(aMedia); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString notUsed;
|
2002-04-05 11:29:40 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, aType);
|
|
|
|
nsParserUtils::SplitMimeType(aType, mimeType, notUsed);
|
2004-06-17 00:13:25 +00:00
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
2001-05-19 02:59:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
2004-06-17 00:13:25 +00:00
|
|
|
aType.AssignLiteral("text/css");
|
2001-05-19 02:59:15 +00:00
|
|
|
|
|
|
|
return;
|
2000-08-22 04:14:53 +00:00
|
|
|
}
|