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"
|
2007-05-14 09:11:38 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
1998-09-02 23:53:16 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2000-07-27 23:17:53 +00:00
|
|
|
#include "nsILink.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
#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"
|
2008-02-21 12:47:26 +00:00
|
|
|
#include "nsPLDOMEvent.h"
|
1998-09-01 01:27:08 +00:00
|
|
|
|
2009-10-13 22:13:41 +00:00
|
|
|
#include "Link.h"
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
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,
|
2009-10-13 22:13:41 +00:00
|
|
|
public nsStyleLinkElement,
|
|
|
|
public Link
|
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
|
2006-09-05 10:22:54 +00:00
|
|
|
NS_FORWARD_NSIDOMNODE(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
|
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);
|
|
|
|
|
2007-04-23 07:31:21 +00:00
|
|
|
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
|
2006-03-07 17:08:51 +00:00
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
|
2007-01-04 10:53:59 +00:00
|
|
|
virtual PRBool IsLink(nsIURI** aURI) const;
|
|
|
|
virtual void GetLinkTarget(nsAString& aTarget);
|
2009-07-13 11:48:06 +00:00
|
|
|
virtual nsLinkState GetLinkState() const;
|
|
|
|
virtual void SetLinkState(nsLinkState aState);
|
|
|
|
virtual already_AddRefed<nsIURI> GetHrefURI() const;
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
|
|
|
|
1998-09-01 01:27:08 +00:00
|
|
|
protected:
|
2009-07-28 16:07:31 +00:00
|
|
|
virtual already_AddRefed<nsIURI> GetStyleSheetURL(PRBool* aIsInline);
|
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);
|
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)
|
2009-10-13 22:13:41 +00:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
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
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsHTMLLinkElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE4(nsHTMLLinkElement,
|
|
|
|
nsIDOMHTMLLinkElement,
|
|
|
|
nsIDOMLinkStyle,
|
|
|
|
nsILink,
|
|
|
|
nsIStyleSheetLinkingElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLLinkElement,
|
|
|
|
nsGenericHTMLElement)
|
2007-08-20 22:55:06 +00:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLLinkElement)
|
1998-09-01 01:27:08 +00:00
|
|
|
|
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(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)
|
|
|
|
{
|
2009-01-29 20:39:21 +00:00
|
|
|
nsCOMPtr<nsIDOMStyleSheet> ss(do_QueryInterface(GetStyleSheet()));
|
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)
|
|
|
|
{
|
2009-01-29 20:39:21 +00:00
|
|
|
nsCOMPtr<nsIDOMStyleSheet> ss(do_QueryInterface(GetStyleSheet()));
|
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);
|
|
|
|
|
2009-05-20 08:00:04 +00:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsRunnableMethod<nsHTMLLinkElement>(this,
|
|
|
|
&nsHTMLLinkElement::UpdateStyleSheetInternal));
|
2005-04-05 23:54:35 +00:00
|
|
|
|
|
|
|
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
|
|
|
|
|
2010-02-18 18:07:01 +00:00
|
|
|
return rv;
|
2005-04-05 23:54:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-10-13 22:13:41 +00:00
|
|
|
Link::ResetLinkState();
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2008-04-11 17:29:06 +00:00
|
|
|
// Once we have XPCOMGC we shouldn't need to call UnbindFromTree during Unlink
|
|
|
|
// and so this messy event dispatch can go away.
|
2009-10-13 22:13:41 +00:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
|
2005-04-05 23:54:35 +00:00
|
|
|
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2007-04-20 22:59:18 +00:00
|
|
|
UpdateStyleSheetInternal(oldDoc);
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
// 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
|
2009-01-23 09:02:09 +00:00
|
|
|
// page really does want to specify that its author is a stylesheet. Since
|
2004-01-09 23:54:21 +00:00
|
|
|
// 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.
|
2006-04-24 05:40:11 +00:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2006-12-26 17:47:52 +00:00
|
|
|
{&nsGkAtoms::_empty, &nsGkAtoms::stylesheet, nsnull};
|
2006-04-24 05:40:11 +00:00
|
|
|
|
|
|
|
if (!nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
|
2006-12-26 17:47:52 +00:00
|
|
|
nsGkAtoms::rev) &&
|
|
|
|
FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::rel,
|
2006-04-24 05:40:11 +00:00
|
|
|
strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH)
|
2004-01-09 23:54:21 +00:00
|
|
|
return;
|
|
|
|
|
2009-03-06 18:12:20 +00:00
|
|
|
nsRefPtr<nsPLDOMEvent> event = new nsPLDOMEvent(this, aEventName, PR_TRUE);
|
2008-02-21 12:47:26 +00:00
|
|
|
if (event) {
|
2009-11-06 23:30:24 +00:00
|
|
|
// Always run async in order to avoid running script when the content
|
|
|
|
// sink isn't expecting it.
|
|
|
|
event->PostDOMEvent();
|
2008-02-21 12:47:26 +00:00
|
|
|
}
|
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
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aName == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2009-10-13 22:13:41 +00:00
|
|
|
Link::ResetLinkState();
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2007-04-25 18:48:18 +00:00
|
|
|
PRBool dropSheet = PR_FALSE;
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::rel &&
|
2009-01-29 20:39:21 +00:00
|
|
|
GetStyleSheet()) {
|
2009-01-18 20:14:14 +00:00
|
|
|
nsAutoTArray<nsString, 4> linkTypes;
|
2007-04-25 18:48:18 +00:00
|
|
|
nsStyleLinkElement::ParseLinkTypes(aValue, linkTypes);
|
2009-01-18 20:14:14 +00:00
|
|
|
dropSheet = !linkTypes.Contains(NS_LITERAL_STRING("stylesheet"));
|
2007-04-25 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-20 22:59:18 +00:00
|
|
|
UpdateStyleSheetInternal(nsnull,
|
2007-04-25 18:48:18 +00:00
|
|
|
dropSheet ||
|
|
|
|
(aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type)));
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLLinkElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2008-09-10 22:12:43 +00:00
|
|
|
if (aAttribute == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
|
2009-10-13 22:13:41 +00:00
|
|
|
Link::ResetLinkState();
|
2008-09-10 22:12:43 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
2007-04-20 22:59:18 +00:00
|
|
|
UpdateStyleSheetInternal(nsnull,
|
|
|
|
aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::rel ||
|
|
|
|
aAttribute == nsGkAtoms::title ||
|
|
|
|
aAttribute == nsGkAtoms::media ||
|
|
|
|
aAttribute == nsGkAtoms::type));
|
2004-01-09 23:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-04-23 07:31:21 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLLinkElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
return PreHandleEventForAnchors(aVisitor);
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
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
|
|
|
|
2007-01-04 10:53:59 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLLinkElement::IsLink(nsIURI** aURI) const
|
|
|
|
{
|
|
|
|
return IsHTMLLink(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLLinkElement::GetLinkTarget(nsAString& aTarget)
|
|
|
|
{
|
2007-03-26 13:19:33 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
|
|
|
|
if (aTarget.IsEmpty()) {
|
2007-01-04 10:53:59 +00:00
|
|
|
GetBaseTarget(aTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
nsLinkState
|
|
|
|
nsHTMLLinkElement::GetLinkState() const
|
2000-07-27 23:17:53 +00:00
|
|
|
{
|
2009-10-13 22:13:41 +00:00
|
|
|
return Link::GetLinkState();
|
2000-07-27 23:17:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
void
|
2000-07-27 23:17:53 +00:00
|
|
|
nsHTMLLinkElement::SetLinkState(nsLinkState aState)
|
|
|
|
{
|
2009-10-13 22:13:41 +00:00
|
|
|
Link::SetLinkState(aState);
|
2000-07-27 23:17:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLLinkElement::GetHrefURI() const
|
2000-07-27 23:17:53 +00:00
|
|
|
{
|
2009-07-13 11:48:06 +00:00
|
|
|
return GetHrefURIForAnchors();
|
2000-07-27 23:17:53 +00:00
|
|
|
}
|
2000-08-22 04:14:53 +00:00
|
|
|
|
2009-07-28 16:07:31 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLLinkElement::GetStyleSheetURL(PRBool* aIsInline)
|
2002-04-05 11:29:40 +00:00
|
|
|
{
|
|
|
|
*aIsInline = PR_FALSE;
|
2009-07-28 16:07:31 +00:00
|
|
|
return GetHrefURIForAnchors();
|
2002-04-05 11:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2009-01-18 20:14:14 +00:00
|
|
|
nsAutoTArray<nsString, 4> linkTypes;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::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?
|
2009-01-18 20:14:14 +00:00
|
|
|
if (!linkTypes.Contains(NS_LITERAL_STRING("stylesheet"))) {
|
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;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::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?
|
2009-01-18 20:14:14 +00:00
|
|
|
if (linkTypes.Contains(NS_LITERAL_STRING("alternate"))) {
|
2001-05-19 02:59:15 +00:00
|
|
|
if (aTitle.IsEmpty()) { // alternates must have title
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
*aIsAlternate = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::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;
|
2006-12-26 17:47:52 +00:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
2002-04-05 11:29:40 +00:00
|
|
|
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
|
|
|
}
|