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-04-13 20:24:54 +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-04-13 20:24:54 +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-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org 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):
|
2001-05-31 22:19:43 +00:00
|
|
|
* David Hyatt <hyatt@netscape.com>
|
2001-02-13 14:06:29 +00:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* 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 ***** */
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-06-10 05:28:32 +00:00
|
|
|
#include "nsCSSRule.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsICSSStyleRule.h"
|
2001-09-19 14:16:34 +00:00
|
|
|
#include "nsICSSGroupRule.h"
|
2002-01-15 22:43:37 +00:00
|
|
|
#include "nsCSSDeclaration.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-08-04 05:07:10 +00:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsICSSLoader.h"
|
|
|
|
#include "nsIURL.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIPresContext.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-08-07 02:16:38 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-05-18 21:09:43 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsUnitConversion.h"
|
1998-09-17 00:19:47 +00:00
|
|
|
#include "nsIFontMetrics.h"
|
1998-10-06 01:39:33 +00:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2003-06-24 05:40:37 +00:00
|
|
|
#include "nsICSSStyleRuleDOMWrapper.h"
|
1998-10-06 01:39:33 +00:00
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
|
|
|
#include "nsDOMCSSDeclaration.h"
|
1998-12-11 02:50:43 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2001-01-22 04:03:48 +00:00
|
|
|
#include "nsINameSpace.h"
|
1999-09-10 05:56:19 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsRuleNode.h"
|
2002-08-14 12:34:39 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2003-07-04 01:33:10 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
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
|
|
|
#include "nsContentUtils.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsContentErrors.h"
|
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
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// -- nsCSSSelector -------------------------------
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
#define NS_IF_COPY(dest,source,type) \
|
|
|
|
if (nsnull != source) dest = new type(*(source))
|
|
|
|
|
|
|
|
#define NS_IF_DELETE(ptr) \
|
|
|
|
if (nsnull != ptr) { delete ptr; ptr = nsnull; }
|
|
|
|
|
2001-03-20 11:49:20 +00:00
|
|
|
#define NS_IF_NEGATED_START(bool,str) \
|
2004-06-17 00:13:25 +00:00
|
|
|
if (bool) { str.AppendLiteral(":not("); }
|
2001-03-20 11:49:20 +00:00
|
|
|
|
|
|
|
#define NS_IF_NEGATED_END(bool,str) \
|
|
|
|
if (bool) { str.Append(PRUnichar(')')); }
|
|
|
|
|
2001-01-27 23:06:33 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsAtomList)
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
nsAtomList::nsAtomList(nsIAtom* aAtom)
|
|
|
|
: mAtom(aAtom),
|
1998-04-13 20:24:54 +00:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAtomList);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
nsAtomList::nsAtomList(const nsString& aAtomValue)
|
|
|
|
: mAtom(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAtomList);
|
2002-08-14 12:34:39 +00:00
|
|
|
mAtom = do_GetAtom(aAtomValue);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomList::nsAtomList(const nsAtomList& aCopy)
|
|
|
|
: mAtom(aCopy.mAtom),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAtomList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_COPY(mNext, aCopy.mNext, nsAtomList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomList::~nsAtomList(void)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsAtomList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_DELETE(mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsAtomList::Equals(const nsAtomList* aOther) const
|
|
|
|
{
|
|
|
|
if (this == aOther) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (nsnull != aOther) {
|
|
|
|
if (mAtom == aOther->mAtom) {
|
|
|
|
if (nsnull != mNext) {
|
|
|
|
return mNext->Equals(aOther->mNext);
|
|
|
|
}
|
|
|
|
return PRBool(nsnull == aOther->mNext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-14 12:34:39 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsAtomStringList)
|
|
|
|
|
|
|
|
nsAtomStringList::nsAtomStringList(nsIAtom* aAtom, const PRUnichar* aString)
|
|
|
|
: mAtom(aAtom),
|
|
|
|
mString(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAtomStringList);
|
|
|
|
if (aString)
|
|
|
|
mString = nsCRT::strdup(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomStringList::nsAtomStringList(const nsString& aAtomValue,
|
|
|
|
const PRUnichar* aString)
|
|
|
|
: mAtom(nsnull),
|
|
|
|
mString(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAtomStringList);
|
|
|
|
mAtom = do_GetAtom(aAtomValue);
|
|
|
|
if (aString)
|
|
|
|
mString = nsCRT::strdup(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomStringList::nsAtomStringList(const nsAtomStringList& aCopy)
|
|
|
|
: mAtom(aCopy.mAtom),
|
|
|
|
mString(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAtomStringList);
|
|
|
|
if (aCopy.mString)
|
|
|
|
mString = nsCRT::strdup(aCopy.mString);
|
|
|
|
NS_IF_COPY(mNext, aCopy.mNext, nsAtomStringList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomStringList::~nsAtomStringList(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAtomStringList);
|
|
|
|
if (mString)
|
|
|
|
nsCRT::free(mString);
|
|
|
|
NS_IF_DELETE(mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsAtomStringList::Equals(const nsAtomStringList* aOther) const
|
|
|
|
{
|
|
|
|
return (this == aOther) ||
|
|
|
|
(aOther &&
|
|
|
|
mAtom == aOther->mAtom &&
|
|
|
|
!mString == !aOther->mString &&
|
|
|
|
!mNext == !aOther->mNext &&
|
|
|
|
(!mNext || mNext->Equals(aOther->mNext)) &&
|
|
|
|
// Check strings last, since it's the slowest check.
|
|
|
|
(!mString || nsDependentString(mString).Equals(
|
|
|
|
nsDependentString(aOther->mString),
|
|
|
|
nsCaseInsensitiveStringComparator())));
|
|
|
|
}
|
|
|
|
|
2001-01-27 23:06:33 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsAttrSelector)
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr)
|
|
|
|
: mNameSpace(aNameSpace),
|
|
|
|
mAttr(nsnull),
|
1998-12-11 02:50:43 +00:00
|
|
|
mFunction(NS_ATTR_FUNC_SET),
|
1998-12-21 05:58:58 +00:00
|
|
|
mCaseSensitive(1),
|
1998-12-11 02:50:43 +00:00
|
|
|
mValue(),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
mAttr = NS_NewAtom(aAttr);
|
|
|
|
}
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunction,
|
|
|
|
const nsString& aValue, PRBool aCaseSensitive)
|
|
|
|
: mNameSpace(aNameSpace),
|
|
|
|
mAttr(nsnull),
|
1998-12-11 02:50:43 +00:00
|
|
|
mFunction(aFunction),
|
1998-12-21 05:58:58 +00:00
|
|
|
mCaseSensitive(aCaseSensitive),
|
1998-12-11 02:50:43 +00:00
|
|
|
mValue(aValue),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
mAttr = NS_NewAtom(aAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrSelector::nsAttrSelector(const nsAttrSelector& aCopy)
|
1999-06-10 05:28:32 +00:00
|
|
|
: mNameSpace(aCopy.mNameSpace),
|
|
|
|
mAttr(aCopy.mAttr),
|
1998-12-11 02:50:43 +00:00
|
|
|
mFunction(aCopy.mFunction),
|
1998-12-21 05:58:58 +00:00
|
|
|
mCaseSensitive(aCopy.mCaseSensitive),
|
1998-12-11 02:50:43 +00:00
|
|
|
mValue(aCopy.mValue),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_ADDREF(mAttr);
|
|
|
|
NS_IF_COPY(mNext, aCopy.mNext, nsAttrSelector);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrSelector::~nsAttrSelector(void)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsAttrSelector);
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_RELEASE(mAttr);
|
|
|
|
NS_IF_DELETE(mNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsAttrSelector::Equals(const nsAttrSelector* aOther) const
|
|
|
|
{
|
|
|
|
if (this == aOther) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (nsnull != aOther) {
|
1999-06-10 05:28:32 +00:00
|
|
|
if ((mNameSpace == aOther->mNameSpace) &&
|
|
|
|
(mAttr == aOther->mAttr) &&
|
1998-12-11 02:50:43 +00:00
|
|
|
(mFunction == aOther->mFunction) &&
|
1998-12-21 05:58:58 +00:00
|
|
|
(mCaseSensitive == aOther->mCaseSensitive) &&
|
1998-12-11 02:50:43 +00:00
|
|
|
mValue.Equals(aOther->mValue)) {
|
|
|
|
if (nsnull != mNext) {
|
|
|
|
return mNext->Equals(aOther->mNext);
|
|
|
|
}
|
|
|
|
return PRBool(nsnull == aOther->mNext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-27 23:06:33 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsCSSSelector)
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
nsCSSSelector::nsCSSSelector(void)
|
|
|
|
: mNameSpace(kNameSpaceID_Unknown), mTag(nsnull),
|
2001-02-13 14:06:29 +00:00
|
|
|
mIDList(nsnull),
|
1998-12-11 02:50:43 +00:00
|
|
|
mClassList(nsnull),
|
|
|
|
mPseudoClassList(nsnull),
|
|
|
|
mAttrList(nsnull),
|
|
|
|
mOperator(0),
|
2001-03-20 11:49:20 +00:00
|
|
|
mNegations(nsnull),
|
1998-04-13 20:24:54 +00:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCSSSelector);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelector::nsCSSSelector(const nsCSSSelector& aCopy)
|
1998-12-11 02:50:43 +00:00
|
|
|
: mNameSpace(aCopy.mNameSpace), mTag(aCopy.mTag),
|
2001-02-13 14:06:29 +00:00
|
|
|
mIDList(nsnull),
|
1998-12-11 02:50:43 +00:00
|
|
|
mClassList(nsnull),
|
|
|
|
mPseudoClassList(nsnull),
|
|
|
|
mAttrList(nsnull),
|
|
|
|
mOperator(aCopy.mOperator),
|
2001-03-20 11:49:20 +00:00
|
|
|
mNegations(nsnull),
|
1998-04-13 20:24:54 +00:00
|
|
|
mNext(nsnull)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCSSSelector);
|
2001-02-13 14:06:29 +00:00
|
|
|
NS_IF_COPY(mIDList, aCopy.mIDList, nsAtomList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_COPY(mClassList, aCopy.mClassList, nsAtomList);
|
2002-08-14 12:34:39 +00:00
|
|
|
NS_IF_COPY(mPseudoClassList, aCopy.mPseudoClassList, nsAtomStringList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_COPY(mAttrList, aCopy.mAttrList, nsAttrSelector);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_COPY(mNegations, aCopy.mNegations, nsCSSSelector);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
nsCSSSelector::~nsCSSSelector(void)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsCSSSelector);
|
1998-12-11 02:50:43 +00:00
|
|
|
Reset();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelector& nsCSSSelector::operator=(const nsCSSSelector& aCopy)
|
|
|
|
{
|
2001-02-13 14:06:29 +00:00
|
|
|
NS_IF_DELETE(mIDList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_DELETE(mClassList);
|
|
|
|
NS_IF_DELETE(mPseudoClassList);
|
|
|
|
NS_IF_DELETE(mAttrList);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_DELETE(mNegations);
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
mNameSpace = aCopy.mNameSpace;
|
1998-04-13 20:24:54 +00:00
|
|
|
mTag = aCopy.mTag;
|
2001-02-13 14:06:29 +00:00
|
|
|
NS_IF_COPY(mIDList, aCopy.mIDList, nsAtomList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_COPY(mClassList, aCopy.mClassList, nsAtomList);
|
2002-08-14 12:34:39 +00:00
|
|
|
NS_IF_COPY(mPseudoClassList, aCopy.mPseudoClassList, nsAtomStringList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_COPY(mAttrList, aCopy.mAttrList, nsAttrSelector);
|
|
|
|
mOperator = aCopy.mOperator;
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_COPY(mNegations, aCopy.mNegations, nsCSSSelector);
|
1998-12-11 02:50:43 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsCSSSelector::Equals(const nsCSSSelector* aOther) const
|
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
if (this == aOther) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != aOther) {
|
1998-12-11 02:50:43 +00:00
|
|
|
if ((aOther->mNameSpace == mNameSpace) &&
|
|
|
|
(aOther->mTag == mTag) &&
|
|
|
|
(aOther->mOperator == mOperator)) {
|
2001-02-13 14:06:29 +00:00
|
|
|
if (nsnull != mIDList) {
|
|
|
|
if (PR_FALSE == mIDList->Equals(aOther->mIDList)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != aOther->mIDList) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != mClassList) {
|
|
|
|
if (PR_FALSE == mClassList->Equals(aOther->mClassList)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != aOther->mClassList) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nsnull != mPseudoClassList) {
|
|
|
|
if (PR_FALSE == mPseudoClassList->Equals(aOther->mPseudoClassList)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != aOther->mPseudoClassList) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nsnull != mAttrList) {
|
|
|
|
if (PR_FALSE == mAttrList->Equals(aOther->mAttrList)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != aOther->mAttrList) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
if (nsnull != mNegations) {
|
|
|
|
if (PR_FALSE == mNegations->Equals(aOther->mNegations)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
void nsCSSSelector::Reset(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
mNameSpace = kNameSpaceID_Unknown;
|
2002-08-14 12:34:39 +00:00
|
|
|
mTag = nsnull;
|
2001-02-13 14:06:29 +00:00
|
|
|
NS_IF_DELETE(mIDList);
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_IF_DELETE(mClassList);
|
|
|
|
NS_IF_DELETE(mPseudoClassList);
|
|
|
|
NS_IF_DELETE(mAttrList);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_DELETE(mNegations);
|
1999-02-27 07:16:57 +00:00
|
|
|
mOperator = PRUnichar(0);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetNameSpace(PRInt32 aNameSpace)
|
|
|
|
{
|
|
|
|
mNameSpace = aNameSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetTag(const nsString& aTag)
|
|
|
|
{
|
2002-08-14 12:34:39 +00:00
|
|
|
if (aTag.IsEmpty())
|
|
|
|
mTag = nsnull;
|
|
|
|
else
|
|
|
|
mTag = do_GetAtom(aTag);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
2001-02-13 14:06:29 +00:00
|
|
|
void nsCSSSelector::AddID(const nsString& aID)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aID.IsEmpty()) {
|
2001-02-13 14:06:29 +00:00
|
|
|
nsAtomList** list = &mIDList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
|
|
|
*list = new nsAtomList(aID);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::AddClass(const nsString& aClass)
|
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aClass.IsEmpty()) {
|
1998-12-11 02:50:43 +00:00
|
|
|
nsAtomList** list = &mClassList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
|
|
|
*list = new nsAtomList(aClass);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 12:34:39 +00:00
|
|
|
void nsCSSSelector::AddPseudoClass(const nsString& aPseudoClass,
|
|
|
|
const PRUnichar* aString)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aPseudoClass.IsEmpty()) {
|
2002-08-14 12:34:39 +00:00
|
|
|
nsAtomStringList** list = &mPseudoClassList;
|
1998-12-11 02:50:43 +00:00
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
2002-08-14 12:34:39 +00:00
|
|
|
*list = new nsAtomStringList(aPseudoClass, aString);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 12:34:39 +00:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsIAtom* aPseudoClass,
|
|
|
|
const PRUnichar* aString)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
|
|
|
if (nsnull != aPseudoClass) {
|
2002-08-14 12:34:39 +00:00
|
|
|
nsAtomStringList** list = &mPseudoClassList;
|
1998-12-11 02:50:43 +00:00
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
1998-05-18 21:09:43 +00:00
|
|
|
}
|
2002-08-14 12:34:39 +00:00
|
|
|
*list = new nsAtomStringList(aPseudoClass, aString);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
void nsCSSSelector::AddAttribute(PRInt32 aNameSpace, const nsString& aAttr)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aAttr.IsEmpty()) {
|
1998-12-11 02:50:43 +00:00
|
|
|
nsAttrSelector** list = &mAttrList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
1999-06-10 05:28:32 +00:00
|
|
|
*list = new nsAttrSelector(aNameSpace, aAttr);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
void nsCSSSelector::AddAttribute(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunc,
|
|
|
|
const nsString& aValue, PRBool aCaseSensitive)
|
1998-12-11 02:50:43 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!aAttr.IsEmpty()) {
|
1998-12-11 02:50:43 +00:00
|
|
|
nsAttrSelector** list = &mAttrList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
1999-06-10 05:28:32 +00:00
|
|
|
*list = new nsAttrSelector(aNameSpace, aAttr, aFunc, aValue, aCaseSensitive);
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetOperator(PRUnichar aOperator)
|
|
|
|
{
|
|
|
|
mOperator = aOperator;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsCSSSelector::CalcWeight(void) const
|
|
|
|
{
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
|
|
|
|
if (nsnull != mTag) {
|
|
|
|
weight += 0x000001;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2001-02-13 14:06:29 +00:00
|
|
|
nsAtomList* list = mIDList;
|
|
|
|
while (nsnull != list) {
|
1998-12-11 02:50:43 +00:00
|
|
|
weight += 0x010000;
|
2001-02-13 14:06:29 +00:00
|
|
|
list = list->mNext;
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
2001-02-13 14:06:29 +00:00
|
|
|
list = mClassList;
|
1998-12-11 02:50:43 +00:00
|
|
|
while (nsnull != list) {
|
|
|
|
weight += 0x000100;
|
|
|
|
list = list->mNext;
|
|
|
|
}
|
2002-08-14 12:34:39 +00:00
|
|
|
nsAtomStringList *plist = mPseudoClassList;
|
|
|
|
while (nsnull != plist) {
|
1998-12-11 02:50:43 +00:00
|
|
|
weight += 0x000100;
|
2002-08-14 12:34:39 +00:00
|
|
|
plist = plist->mNext;
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
nsAttrSelector* attr = mAttrList;
|
|
|
|
while (nsnull != attr) {
|
|
|
|
weight += 0x000100;
|
|
|
|
attr = attr->mNext;
|
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
if (nsnull != mNegations) {
|
|
|
|
weight += mNegations->CalcWeight();
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
return weight;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2001-02-12 13:04:06 +00:00
|
|
|
// pseudo-elements are stored in the selectors' chain using fictional elements;
|
|
|
|
// these fictional elements have mTag starting with a colon
|
|
|
|
static PRBool IsPseudoElement(nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
if (aAtom) {
|
2003-03-25 18:55:59 +00:00
|
|
|
const char* str;
|
|
|
|
aAtom->GetUTF8String(&str);
|
2001-02-12 13:04:06 +00:00
|
|
|
return str && (*str == ':');
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-23 22:56:05 +00:00
|
|
|
void nsCSSSelector::AppendNegationToString(nsAString& aString)
|
2001-03-20 11:49:20 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aString.AppendLiteral(":not(");
|
2001-03-20 11:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Builds the textual representation of a selector. Called by DOM 2 CSS
|
|
|
|
// StyleRule:selectorText
|
|
|
|
//
|
2003-06-14 23:50:54 +00:00
|
|
|
void
|
|
|
|
nsCSSSelector::ToString(nsAString& aString, nsICSSStyleSheet* aSheet) const
|
|
|
|
{
|
|
|
|
ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::ToStringInternal(nsAString& aString,
|
|
|
|
nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aIsPseudoElem,
|
|
|
|
PRIntn aNegatedIndex) const
|
2000-09-13 00:05:04 +00:00
|
|
|
{
|
2003-03-25 18:55:59 +00:00
|
|
|
nsAutoString temp;
|
2001-03-20 11:49:20 +00:00
|
|
|
PRBool aIsNegated = PRBool(0 < aNegatedIndex);
|
2004-05-18 02:42:13 +00:00
|
|
|
PRBool isPseudoElement = IsPseudoElement(mTag);
|
2001-01-22 04:03:48 +00:00
|
|
|
|
|
|
|
// selectors are linked from right-to-left, so the next selector in the linked list
|
|
|
|
// actually precedes this one in the resulting string
|
2001-03-20 11:49:20 +00:00
|
|
|
if (mNext) {
|
2003-06-14 23:50:54 +00:00
|
|
|
mNext->ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
|
2004-05-18 02:42:13 +00:00
|
|
|
if (!aIsNegated && !isPseudoElement) {
|
2001-02-12 13:04:06 +00:00
|
|
|
// don't add a leading whitespace if we have a pseudo-element
|
2001-03-20 11:49:20 +00:00
|
|
|
// or a negated simple selector
|
2001-02-12 13:04:06 +00:00
|
|
|
aString.Append(PRUnichar(' '));
|
|
|
|
}
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
if (1 < aNegatedIndex) {
|
|
|
|
// the first mNegations does not contain a negated type element selector
|
|
|
|
// or a negated universal selector
|
|
|
|
NS_IF_NEGATED_START(aIsNegated, aString)
|
|
|
|
}
|
2001-01-22 04:03:48 +00:00
|
|
|
|
2004-05-18 02:42:13 +00:00
|
|
|
// For non-pseudo-element selectors or for lone pseudo-elements, deal with
|
|
|
|
// namespace prefixes.
|
|
|
|
if (!isPseudoElement || !mNext) {
|
|
|
|
// append the namespace prefix if needed
|
|
|
|
if (mNameSpace == kNameSpaceID_None) {
|
|
|
|
// The only way to do this in CSS is to have an explicit namespace
|
|
|
|
// of "none" specified in the sheet by having a '|' with nothing
|
|
|
|
// before it.
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(PRUnichar('|'));
|
2004-05-18 02:42:13 +00:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsINameSpace> sheetNS;
|
|
|
|
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
|
|
|
|
|
|
|
|
// sheetNS is non-null if and only if we had an @namespace rule. If it's
|
|
|
|
// null, that means that the only namespaces we could have are the
|
|
|
|
// wildcard namespace (which can be implicit in this case) and the "none"
|
|
|
|
// namespace, which we handled above. So no need to output anything when
|
|
|
|
// sheetNS is null.
|
|
|
|
if (sheetNS) {
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
|
|
|
// prefixAtom is non-null if and only if we have a prefix other than
|
|
|
|
// '*'
|
|
|
|
if (mNameSpace != kNameSpaceID_Unknown) {
|
|
|
|
sheetNS->FindNameSpacePrefix(mNameSpace, getter_AddRefs(prefixAtom));
|
|
|
|
}
|
|
|
|
if (prefixAtom) {
|
|
|
|
nsAutoString prefix;
|
|
|
|
prefixAtom->ToString(prefix);
|
|
|
|
aString.Append(prefix);
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
} else if (mNameSpace == kNameSpaceID_Unknown) {
|
|
|
|
// explicit *| or only non-default namespace rules and we're not
|
|
|
|
// using any of those namespaces
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
}
|
|
|
|
// else we are in the default namespace and don't need to output
|
|
|
|
// anything
|
|
|
|
}
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-18 02:42:13 +00:00
|
|
|
|
2001-01-22 04:03:48 +00:00
|
|
|
// smells like a universal selector
|
2001-02-13 14:06:29 +00:00
|
|
|
if (!mTag && !mIDList && !mClassList) {
|
2001-03-20 11:49:20 +00:00
|
|
|
if (1 != aNegatedIndex) {
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
}
|
|
|
|
if (1 < aNegatedIndex) {
|
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
|
|
|
}
|
2001-01-22 04:03:48 +00:00
|
|
|
} else {
|
|
|
|
// Append the tag name, if there is one
|
|
|
|
if (mTag) {
|
2004-05-18 02:42:13 +00:00
|
|
|
if (isPseudoElement) {
|
|
|
|
if (!mNext) {
|
|
|
|
// Lone pseudo-element selector -- toss in a wildcard type selector
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
}
|
|
|
|
if (!nsCSSPseudoElements::IsCSS2PseudoElement(mTag)) {
|
|
|
|
aString.Append(PRUnichar(':'));
|
|
|
|
}
|
2003-07-04 01:33:10 +00:00
|
|
|
}
|
2003-03-25 18:55:59 +00:00
|
|
|
nsAutoString prefix;
|
|
|
|
mTag->ToString(prefix);
|
|
|
|
aString.Append(prefix);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
|
|
|
// Append the id, if there is one
|
2001-02-13 14:06:29 +00:00
|
|
|
if (mIDList) {
|
|
|
|
nsAtomList* list = mIDList;
|
|
|
|
while (list != nsnull) {
|
2003-03-25 18:55:59 +00:00
|
|
|
list->mAtom->ToString(temp);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_START(aIsNegated, aString)
|
2001-02-13 14:06:29 +00:00
|
|
|
aString.Append(PRUnichar('#'));
|
|
|
|
aString.Append(temp);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
2001-02-13 14:06:29 +00:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
|
|
|
// Append each class in the linked list
|
|
|
|
if (mClassList) {
|
|
|
|
nsAtomList* list = mClassList;
|
|
|
|
while (list != nsnull) {
|
2003-03-25 18:55:59 +00:00
|
|
|
list->mAtom->ToString(temp);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_START(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(PRUnichar('.'));
|
|
|
|
aString.Append(temp);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each attribute selector in the linked list
|
|
|
|
if (mAttrList) {
|
|
|
|
nsAttrSelector* list = mAttrList;
|
|
|
|
while (list != nsnull) {
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_START(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(PRUnichar('['));
|
|
|
|
// Append the namespace prefix
|
|
|
|
if (list->mNameSpace > 0) {
|
|
|
|
nsCOMPtr<nsINameSpace> sheetNS;
|
|
|
|
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
|
|
|
// will return null if namespace was the default
|
2003-06-13 20:10:01 +00:00
|
|
|
sheetNS->FindNameSpacePrefix(list->mNameSpace,
|
|
|
|
getter_AddRefs(prefixAtom));
|
2001-01-22 04:03:48 +00:00
|
|
|
if (prefixAtom) {
|
2003-03-25 18:55:59 +00:00
|
|
|
nsAutoString prefix;
|
|
|
|
prefixAtom->ToString(prefix);
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(prefix);
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Append the attribute name
|
2003-03-25 18:55:59 +00:00
|
|
|
list->mAttr->ToString(temp);
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(temp);
|
|
|
|
// Append the function
|
|
|
|
if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
|
|
|
|
aString.Append(PRUnichar('='));
|
|
|
|
} else if (list->mFunction == NS_ATTR_FUNC_INCLUDES) {
|
|
|
|
aString.Append(PRUnichar('~'));
|
|
|
|
aString.Append(PRUnichar('='));
|
|
|
|
} else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH) {
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
aString.Append(PRUnichar('='));
|
2001-03-03 00:54:04 +00:00
|
|
|
} else if (list->mFunction == NS_ATTR_FUNC_BEGINSMATCH) {
|
|
|
|
aString.Append(PRUnichar('^'));
|
|
|
|
aString.Append(PRUnichar('='));
|
|
|
|
} else if (list->mFunction == NS_ATTR_FUNC_ENDSMATCH) {
|
|
|
|
aString.Append(PRUnichar('$'));
|
|
|
|
aString.Append(PRUnichar('='));
|
|
|
|
} else if (list->mFunction == NS_ATTR_FUNC_CONTAINSMATCH) {
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
aString.Append(PRUnichar('='));
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
|
|
|
// Append the value
|
|
|
|
aString.Append(list->mValue);
|
|
|
|
aString.Append(PRUnichar(']'));
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each pseudo-class in the linked list
|
|
|
|
if (mPseudoClassList) {
|
2002-08-14 12:34:39 +00:00
|
|
|
nsAtomStringList* list = mPseudoClassList;
|
2001-01-22 04:03:48 +00:00
|
|
|
while (list != nsnull) {
|
2003-03-25 18:55:59 +00:00
|
|
|
list->mAtom->ToString(temp);
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_START(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(temp);
|
2002-08-14 12:34:39 +00:00
|
|
|
if (nsnull != list->mString) {
|
|
|
|
aString.Append(PRUnichar('('));
|
|
|
|
aString.Append(list->mString);
|
|
|
|
aString.Append(PRUnichar(')'));
|
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
NS_IF_NEGATED_END(aIsNegated, aString)
|
2001-01-22 04:03:48 +00:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
|
|
|
|
if (mNegations) {
|
|
|
|
// chain all the negated selectors
|
2003-06-14 23:50:54 +00:00
|
|
|
mNegations->ToStringInternal(aString, aSheet, PR_FALSE, aNegatedIndex + 1);
|
2001-03-20 11:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Append the operator only if the selector is not negated and is not
|
|
|
|
// a pseudo-element
|
|
|
|
if (!aIsNegated && mOperator && !aIsPseudoElem) {
|
2001-01-22 04:03:48 +00:00
|
|
|
aString.Append(PRUnichar(' '));
|
|
|
|
aString.Append(mOperator);
|
|
|
|
}
|
2000-09-13 00:05:04 +00:00
|
|
|
}
|
|
|
|
|
2003-06-14 23:50:54 +00:00
|
|
|
// -- nsCSSSelectorList -------------------------------
|
|
|
|
|
|
|
|
MOZ_DECL_CTOR_COUNTER(nsCSSSelectorList)
|
|
|
|
|
|
|
|
nsCSSSelectorList::nsCSSSelectorList(void)
|
|
|
|
: mSelectors(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSSelectorList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelectorList::~nsCSSSelectorList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSSelectorList);
|
|
|
|
nsCSSSelector* sel = mSelectors;
|
|
|
|
while (sel) {
|
|
|
|
nsCSSSelector* dead = sel;
|
|
|
|
sel = sel->mNext;
|
|
|
|
delete dead;
|
|
|
|
}
|
|
|
|
if (mNext) {
|
|
|
|
delete mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelectorList::AddSelector(const nsCSSSelector& aSelector)
|
|
|
|
{ // prepend to list
|
|
|
|
nsCSSSelector* newSel = new nsCSSSelector(aSelector);
|
|
|
|
if (newSel) {
|
|
|
|
newSel->mNext = mSelectors;
|
|
|
|
mSelectors = newSel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSSelectorList::ToString(nsAString& aResult, nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
nsCSSSelectorList *p = this;
|
|
|
|
for (;;) {
|
|
|
|
p->mSelectors->ToString(aResult, aSheet);
|
|
|
|
p = p->mNext;
|
|
|
|
if (!p)
|
|
|
|
break;
|
2004-06-17 00:13:25 +00:00
|
|
|
aResult.AppendLiteral(", ");
|
2003-06-14 23:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelectorList*
|
|
|
|
nsCSSSelectorList::Clone()
|
|
|
|
{
|
|
|
|
nsCSSSelectorList *list = nsnull;
|
|
|
|
nsCSSSelectorList **list_cur = &list;
|
|
|
|
for (nsCSSSelectorList *l = this; l; l = l->mNext) {
|
|
|
|
nsCSSSelectorList *lcopy = new nsCSSSelectorList();
|
|
|
|
if (!lcopy) {
|
|
|
|
delete list;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
*list_cur = lcopy;
|
|
|
|
list_cur = &lcopy->mNext;
|
|
|
|
|
|
|
|
nsCSSSelector **sel_cur = &lcopy->mSelectors;
|
|
|
|
for (nsCSSSelector *s = l->mSelectors; s; s = s->mNext) {
|
|
|
|
nsCSSSelector *scopy = new nsCSSSelector(*s);
|
|
|
|
if (!scopy) {
|
|
|
|
delete list;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
*sel_cur = scopy;
|
|
|
|
sel_cur = &scopy->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2001-03-20 11:49:20 +00:00
|
|
|
|
1998-09-11 02:07:05 +00:00
|
|
|
// -- CSSImportantRule -------------------------------
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
class CSSStyleRuleImpl;
|
|
|
|
|
1998-09-11 02:07:05 +00:00
|
|
|
class CSSImportantRule : public nsIStyleRule {
|
|
|
|
public:
|
2002-01-15 22:43:37 +00:00
|
|
|
CSSImportantRule(nsICSSStyleSheet* aSheet, nsCSSDeclaration* aDeclaration);
|
1998-09-11 02:07:05 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
// The new mapping function.
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
1998-09-11 02:07:05 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
1998-09-11 02:07:05 +00:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-09-11 02:07:05 +00:00
|
|
|
protected:
|
1999-02-12 17:45:58 +00:00
|
|
|
virtual ~CSSImportantRule(void);
|
1998-09-11 02:07:05 +00:00
|
|
|
|
2002-01-15 22:43:37 +00:00
|
|
|
nsCSSDeclaration* mDeclaration;
|
2003-06-30 21:31:25 +00:00
|
|
|
nsICSSStyleSheet* mSheet;
|
1998-11-26 01:34:53 +00:00
|
|
|
|
1999-04-21 04:16:46 +00:00
|
|
|
friend class CSSStyleRuleImpl;
|
1998-09-11 02:07:05 +00:00
|
|
|
};
|
|
|
|
|
2002-01-15 22:43:37 +00:00
|
|
|
CSSImportantRule::CSSImportantRule(nsICSSStyleSheet* aSheet, nsCSSDeclaration* aDeclaration)
|
1999-02-12 17:45:58 +00:00
|
|
|
: mDeclaration(aDeclaration),
|
|
|
|
mSheet(aSheet)
|
1998-09-11 02:07:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportantRule::~CSSImportantRule(void)
|
|
|
|
{
|
2002-01-15 22:43:37 +00:00
|
|
|
mDeclaration = nsnull;
|
1998-09-11 02:07:05 +00:00
|
|
|
}
|
|
|
|
|
2001-08-21 01:48:11 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(CSSImportantRule, nsIStyleRule)
|
1998-09-11 02:07:05 +00:00
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportantRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mSheet);
|
|
|
|
aSheet = mSheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-15 21:23:05 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-31 22:19:43 +00:00
|
|
|
CSSImportantRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2003-06-07 22:14:42 +00:00
|
|
|
return mDeclaration->MapImportantRuleInfoInto(aRuleData);
|
1998-09-11 02:07:05 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
1998-09-11 02:07:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("! Important rule ", out);
|
|
|
|
if (nsnull != mDeclaration) {
|
|
|
|
mDeclaration->List(out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("{ null declaration }", out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
|
|
|
|
class DOMCSSStyleRuleImpl;
|
1998-10-06 01:39:33 +00:00
|
|
|
|
|
|
|
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
|
2003-06-24 05:40:37 +00:00
|
|
|
virtual ~DOMCSSDeclarationImpl(void);
|
1998-10-06 01:39:33 +00:00
|
|
|
|
2003-06-24 06:20:18 +00:00
|
|
|
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
|
1999-06-10 05:28:32 +00:00
|
|
|
virtual void DropReference(void);
|
2002-01-15 22:43:37 +00:00
|
|
|
virtual nsresult GetCSSDeclaration(nsCSSDeclaration **aDecl,
|
1998-10-06 01:39:33 +00:00
|
|
|
PRBool aAllocate);
|
2003-06-18 01:59:57 +00:00
|
|
|
virtual nsresult GetCSSParsingEnvironment(nsIURI** aURI,
|
2001-10-19 13:50:30 +00:00
|
|
|
nsICSSLoader** aCSSLoader,
|
|
|
|
nsICSSParser** aCSSParser);
|
2003-06-18 01:59:57 +00:00
|
|
|
virtual nsresult DeclarationChanged();
|
1998-10-06 01:39:33 +00:00
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
// Override |AddRef| and |Release| for being a member of
|
|
|
|
// |DOMCSSStyleRuleImpl|.
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
|
|
|
|
friend class DOMCSSStyleRuleImpl;
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
protected:
|
2003-06-24 05:40:37 +00:00
|
|
|
// This reference is not reference-counted. The rule object tells us
|
|
|
|
// when it's about to go away.
|
1998-10-06 01:39:33 +00:00
|
|
|
nsICSSStyleRule *mRule;
|
2003-06-24 05:40:37 +00:00
|
|
|
|
|
|
|
inline DOMCSSStyleRuleImpl* DomRule();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// NOT TO BE IMPLEMENTED
|
|
|
|
// This object cannot be allocated on its own. It must be a member of
|
|
|
|
// DOMCSSStyleRuleImpl.
|
|
|
|
void* operator new(size_t size) CPP_THROW_NEW;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DOMCSSStyleRuleImpl : public nsICSSStyleRuleDOMWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DOMCSSStyleRuleImpl(nsICSSStyleRule *aRule);
|
|
|
|
virtual ~DOMCSSStyleRuleImpl();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMCSSRULE
|
|
|
|
NS_DECL_NSIDOMCSSSTYLERULE
|
|
|
|
|
|
|
|
// nsICSSStyleRuleDOMWrapper
|
|
|
|
NS_IMETHOD GetCSSStyleRule(nsICSSStyleRule **aResult);
|
|
|
|
|
|
|
|
DOMCSSDeclarationImpl* DOMDeclaration() { return &mDOMDeclaration; }
|
|
|
|
|
|
|
|
friend class DOMCSSDeclarationImpl;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DOMCSSDeclarationImpl mDOMDeclaration;
|
|
|
|
|
|
|
|
nsICSSStyleRule* Rule() {
|
|
|
|
return mDOMDeclaration.mRule;
|
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
};
|
|
|
|
|
2001-01-27 23:06:33 +00:00
|
|
|
MOZ_DECL_CTOR_COUNTER(DOMCSSDeclarationImpl)
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
|
2003-06-24 05:40:37 +00:00
|
|
|
: mRule(aRule)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(DOMCSSDeclarationImpl);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl(void)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_ASSERTION(!mRule, "DropReference not called.");
|
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(DOMCSSDeclarationImpl);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
inline DOMCSSStyleRuleImpl* DOMCSSDeclarationImpl::DomRule()
|
|
|
|
{
|
|
|
|
return NS_REINTERPRET_CAST(DOMCSSStyleRuleImpl*,
|
|
|
|
NS_REINTERPRET_CAST(char*, this) -
|
|
|
|
offsetof(DOMCSSStyleRuleImpl, mDOMDeclaration));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule())
|
|
|
|
NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule())
|
|
|
|
|
|
|
|
void
|
1999-06-10 05:28:32 +00:00
|
|
|
DOMCSSDeclarationImpl::DropReference(void)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
mRule = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-15 22:43:37 +00:00
|
|
|
DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
|
2002-10-09 01:59:43 +00:00
|
|
|
PRBool aAllocate)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
2002-10-09 01:59:43 +00:00
|
|
|
if (mRule) {
|
1998-10-06 01:39:33 +00:00
|
|
|
*aDecl = mRule->GetDeclaration();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aDecl = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-19 13:50:30 +00:00
|
|
|
/*
|
|
|
|
* This is a utility function. It will only fail if it can't get a
|
2003-06-18 01:59:57 +00:00
|
|
|
* parser. This means it can return NS_OK without aURI or aCSSLoader
|
|
|
|
* being initialized.
|
2001-10-19 13:50:30 +00:00
|
|
|
*/
|
|
|
|
nsresult
|
2003-06-18 01:59:57 +00:00
|
|
|
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aURI,
|
2001-10-19 13:50:30 +00:00
|
|
|
nsICSSLoader** aCSSLoader,
|
|
|
|
nsICSSParser** aCSSParser)
|
|
|
|
{
|
|
|
|
// null out the out params since some of them may not get initialized below
|
|
|
|
*aURI = nsnull;
|
|
|
|
*aCSSLoader = nsnull;
|
|
|
|
*aCSSParser = nsnull;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
2003-06-18 01:59:57 +00:00
|
|
|
if (mRule) {
|
|
|
|
mRule->GetStyleSheet(*getter_AddRefs(sheet));
|
2001-10-19 13:50:30 +00:00
|
|
|
if (sheet) {
|
|
|
|
sheet->GetURL(*aURI);
|
2003-06-18 01:59:57 +00:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
sheet->GetOwningDocument(*getter_AddRefs(document));
|
2004-01-13 23:14:49 +00:00
|
|
|
if (document) {
|
|
|
|
NS_IF_ADDREF(*aCSSLoader = document->GetCSSLoader());
|
2003-06-18 01:59:57 +00:00
|
|
|
NS_ASSERTION(*aCSSLoader, "Document with no CSS loader!");
|
|
|
|
}
|
2001-10-19 13:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
2003-06-24 05:40:37 +00:00
|
|
|
// XXXldb Why bother if |mRule| is null?
|
2001-10-19 13:50:30 +00:00
|
|
|
if (*aCSSLoader) {
|
|
|
|
result = (*aCSSLoader)->GetParserFor(nsnull, aCSSParser);
|
|
|
|
} else {
|
|
|
|
result = NS_NewCSSParser(aCSSParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-06-24 06:20:18 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-24 05:40:37 +00:00
|
|
|
DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
if (!mRule) {
|
|
|
|
*aParent = nsnull;
|
|
|
|
return NS_OK;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
return mRule->GetDOMRule(aParent);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
1998-09-11 02:07:05 +00:00
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
nsresult
|
|
|
|
DOMCSSDeclarationImpl::DeclarationChanged()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mRule,
|
|
|
|
"can only be called when |GetCSSDeclaration| returned a declaration");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> owningDoc;
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
mRule->GetStyleSheet(*getter_AddRefs(sheet));
|
|
|
|
if (sheet) {
|
|
|
|
sheet->GetOwningDocument(*getter_AddRefs(owningDoc));
|
|
|
|
}
|
|
|
|
|
2003-10-16 18:14:25 +00:00
|
|
|
mozAutoDocUpdate updateBatch(owningDoc, UPDATE_STYLE, PR_TRUE);
|
2003-06-18 01:59:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsICSSStyleRule> oldRule = mRule;
|
|
|
|
mRule = oldRule->DeclarationChanged(PR_TRUE).get();
|
2003-06-18 03:02:01 +00:00
|
|
|
if (!mRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-18 01:59:57 +00:00
|
|
|
nsrefcnt cnt = mRule->Release();
|
2003-06-24 05:40:37 +00:00
|
|
|
if (cnt == 0) {
|
|
|
|
NS_NOTREACHED("container didn't take ownership");
|
|
|
|
mRule = nsnull;
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2003-06-18 01:59:57 +00:00
|
|
|
|
|
|
|
if (owningDoc) {
|
|
|
|
owningDoc->StyleRuleChanged(sheet, oldRule, mRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
DOMCSSStyleRuleImpl::DOMCSSStyleRuleImpl(nsICSSStyleRule* aRule)
|
|
|
|
: mDOMDeclaration(aRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMCSSStyleRuleImpl::~DOMCSSStyleRuleImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMCSSStyleRuleImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(DOMCSSStyleRuleImpl)
|
|
|
|
NS_IMPL_RELEASE(DOMCSSStyleRuleImpl)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::STYLE_RULE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
aCssText.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return Rule()->GetCssText(aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return Rule()->SetCssText(aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
Rule()->GetParentStyleSheet(getter_AddRefs(sheet));
|
|
|
|
if (!sheet) {
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return CallQueryInterface(sheet, aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsICSSGroupRule> rule;
|
|
|
|
Rule()->GetParentRule(getter_AddRefs(rule));
|
|
|
|
if (!rule) {
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return rule->GetDOMRule(aParentRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetSelectorText(nsAString& aSelectorText)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
aSelectorText.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return Rule()->GetSelectorText(aSelectorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::SetSelectorText(const nsAString& aSelectorText)
|
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return Rule()->SetSelectorText(aSelectorText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
|
|
|
*aStyle = &mDOMDeclaration;
|
|
|
|
NS_ADDREF(*aStyle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRuleImpl::GetCSSStyleRule(nsICSSStyleRule **aResult)
|
|
|
|
{
|
|
|
|
*aResult = Rule();
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// -- nsCSSStyleRule -------------------------------
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
class CSSStyleRuleImpl : public nsCSSRule,
|
2003-06-24 05:40:37 +00:00
|
|
|
public nsICSSStyleRule
|
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
|
|
|
{
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
2003-06-18 01:59:57 +00:00
|
|
|
CSSStyleRuleImpl(nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration *aDeclaration);
|
|
|
|
private:
|
|
|
|
// for |Clone|
|
1999-06-03 01:57:13 +00:00
|
|
|
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
2003-06-18 01:59:57 +00:00
|
|
|
// for |DeclarationChanged|
|
|
|
|
CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy,
|
|
|
|
nsCSSDeclaration *aDeclaration);
|
|
|
|
public:
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-06-14 23:50:54 +00:00
|
|
|
virtual nsCSSSelectorList* Selector(void);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-01-22 04:03:48 +00:00
|
|
|
virtual PRUint32 GetLineNumber(void) const;
|
|
|
|
virtual void SetLineNumber(PRUint32 aLineNumber);
|
|
|
|
|
2002-01-15 22:43:37 +00:00
|
|
|
virtual nsCSSDeclaration* GetDeclaration(void) const;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-10-09 01:59:43 +00:00
|
|
|
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void);
|
1998-09-02 02:09:43 +00:00
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
|
|
|
|
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
|
2001-09-19 14:16:34 +00:00
|
|
|
|
|
|
|
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
|
1998-10-06 01:39:33 +00:00
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
virtual nsresult GetCssText(nsAString& aCssText);
|
|
|
|
virtual nsresult SetCssText(const nsAString& aCssText);
|
|
|
|
virtual nsresult GetParentStyleSheet(nsICSSStyleSheet** aSheet);
|
|
|
|
virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule);
|
|
|
|
virtual nsresult GetSelectorText(nsAString& aSelectorText);
|
|
|
|
virtual nsresult SetSelectorText(const nsAString& aSelectorText);
|
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
NS_IMETHOD GetType(PRInt32& aType) const;
|
|
|
|
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
|
1999-06-03 01:57:13 +00:00
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule);
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
virtual already_AddRefed<nsICSSStyleRule>
|
|
|
|
DeclarationChanged(PRBool aHandleContainer);
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
// The new mapping function.
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
1998-08-29 20:20:38 +00:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
CSSStyleRuleImpl& operator=(const CSSStyleRuleImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
1999-06-10 05:28:32 +00:00
|
|
|
virtual ~CSSStyleRuleImpl(void);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
protected:
|
2003-06-14 23:50:54 +00:00
|
|
|
nsCSSSelectorList* mSelector; // null for style attribute
|
|
|
|
nsCSSDeclaration* mDeclaration;
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSImportantRule* mImportantRule;
|
2003-06-24 05:40:37 +00:00
|
|
|
DOMCSSStyleRuleImpl* mDOMRule;
|
2001-01-22 04:03:48 +00:00
|
|
|
PRUint32 mLineNumber;
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
1999-06-10 05:28:32 +00:00
|
|
|
: nsCSSRule(),
|
2003-06-18 01:59:57 +00:00
|
|
|
mSelector(aSelector),
|
|
|
|
mDeclaration(aDeclaration),
|
2003-06-14 23:50:54 +00:00
|
|
|
mImportantRule(nsnull),
|
2003-06-24 05:40:37 +00:00
|
|
|
mDOMRule(nsnull)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-30 21:31:25 +00:00
|
|
|
mDeclaration->AddRef();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
// for |Clone|
|
1999-06-03 01:57:13 +00:00
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy)
|
1999-06-10 05:28:32 +00:00
|
|
|
: nsCSSRule(aCopy),
|
2003-06-14 23:50:54 +00:00
|
|
|
mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nsnull),
|
2003-06-30 21:31:25 +00:00
|
|
|
mDeclaration(aCopy.mDeclaration->Clone()),
|
1999-06-03 01:57:13 +00:00
|
|
|
mImportantRule(nsnull),
|
2003-06-24 05:40:37 +00:00
|
|
|
mDOMRule(nsnull)
|
1999-06-03 01:57:13 +00:00
|
|
|
{
|
2003-06-18 01:59:57 +00:00
|
|
|
if (mDeclaration)
|
|
|
|
mDeclaration->AddRef();
|
1999-06-03 01:57:13 +00:00
|
|
|
// rest is constructed lazily on existing data
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
// for |DeclarationChanged|
|
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
|
|
|
: nsCSSRule(aCopy),
|
|
|
|
mSelector(aCopy.mSelector),
|
|
|
|
mDeclaration(aDeclaration),
|
|
|
|
mImportantRule(nsnull),
|
2003-06-24 05:40:37 +00:00
|
|
|
mDOMRule(aCopy.mDOMRule)
|
2003-06-18 01:59:57 +00:00
|
|
|
{
|
2003-06-24 05:40:37 +00:00
|
|
|
// The DOM rule is replacing |aCopy| with |this|, so transfer
|
|
|
|
// the reverse pointer as well (and transfer ownership).
|
|
|
|
aCopy.mDOMRule = nsnull;
|
2003-06-18 01:59:57 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(aDeclaration == aCopy.mDeclaration, "declaration mismatch");
|
2003-06-30 21:31:25 +00:00
|
|
|
// Transfer ownership of selector and declaration:
|
2003-06-18 01:59:57 +00:00
|
|
|
aCopy.mSelector = nsnull;
|
2003-06-30 21:31:25 +00:00
|
|
|
#if 0
|
2003-06-18 01:59:57 +00:00
|
|
|
aCopy.mDeclaration = nsnull;
|
2003-06-30 21:31:25 +00:00
|
|
|
#else
|
|
|
|
// We ought to be able to transfer ownership of the selector and the
|
|
|
|
// declaration since this rule should now be unused, but unfortunately
|
2004-02-24 23:55:18 +00:00
|
|
|
// SetInlineStyleRule might use it before setting the new rule (see
|
2003-06-30 21:31:25 +00:00
|
|
|
// stack in bug 209575). So leave the declaration pointer on the old
|
|
|
|
// rule.
|
|
|
|
mDeclaration->AddRef();
|
|
|
|
#endif
|
2003-06-18 01:59:57 +00:00
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:13 +00:00
|
|
|
|
1999-06-10 05:28:32 +00:00
|
|
|
CSSStyleRuleImpl::~CSSStyleRuleImpl(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-14 23:50:54 +00:00
|
|
|
if (mSelector) {
|
|
|
|
delete mSelector;
|
|
|
|
mSelector = nsnull;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2002-01-15 22:43:37 +00:00
|
|
|
if (nsnull != mDeclaration) {
|
|
|
|
mDeclaration->Release();
|
|
|
|
mDeclaration = nsnull;
|
|
|
|
}
|
1998-11-26 01:34:53 +00:00
|
|
|
if (nsnull != mImportantRule) {
|
|
|
|
mImportantRule->mSheet = nsnull;
|
2002-01-24 18:28:25 +00:00
|
|
|
NS_RELEASE(mImportantRule);
|
2002-01-15 22:43:37 +00:00
|
|
|
mImportantRule = nsnull;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
2003-06-24 05:40:37 +00:00
|
|
|
if (mDOMRule) {
|
|
|
|
mDOMRule->DOMDeclaration()->DropReference();
|
|
|
|
NS_RELEASE(mDOMRule);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
1998-04-22 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
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 CSSStyleRuleImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSStyleRuleImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSStyleRuleImpl, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSStyleRuleImpl, nsCSSRule)
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-06-14 23:50:54 +00:00
|
|
|
nsCSSSelectorList* CSSStyleRuleImpl::Selector(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-14 23:50:54 +00:00
|
|
|
return mSelector;
|
2001-01-22 04:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 CSSStyleRuleImpl::GetLineNumber(void) const
|
|
|
|
{
|
|
|
|
return mLineNumber;
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
|
2001-01-22 04:03:48 +00:00
|
|
|
void CSSStyleRuleImpl::SetLineNumber(PRUint32 aLineNumber)
|
|
|
|
{
|
|
|
|
mLineNumber = aLineNumber;
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
|
2002-01-15 22:43:37 +00:00
|
|
|
nsCSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-18 01:59:57 +00:00
|
|
|
return mDeclaration;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2002-10-09 01:59:43 +00:00
|
|
|
already_AddRefed<nsIStyleRule> CSSStyleRuleImpl::GetImportantRule(void)
|
1998-09-11 02:07:05 +00:00
|
|
|
{
|
2003-06-30 21:31:25 +00:00
|
|
|
if (!mImportantRule && mDeclaration->HasImportantData()) {
|
|
|
|
mImportantRule = new CSSImportantRule(mSheet, mDeclaration);
|
|
|
|
NS_IF_ADDREF(mImportantRule);
|
1998-09-11 02:07:05 +00:00
|
|
|
}
|
|
|
|
NS_IF_ADDREF(mImportantRule);
|
|
|
|
return mImportantRule;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1999-06-10 05:28:32 +00:00
|
|
|
return nsCSSRule::GetStyleSheet(aSheet);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1999-06-10 05:28:32 +00:00
|
|
|
nsCSSRule::SetStyleSheet(aSheet);
|
1998-11-26 01:34:53 +00:00
|
|
|
if (nsnull != mImportantRule) { // we're responsible for this guy too
|
|
|
|
mImportantRule->mSheet = aSheet;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-19 14:16:34 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::SetParentRule(nsICSSGroupRule* aRule)
|
|
|
|
{
|
|
|
|
return nsCSSRule::SetParentRule(aRule);
|
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:13 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-10 05:28:32 +00:00
|
|
|
CSSStyleRuleImpl::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::STYLE_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::Clone(nsICSSRule*& aClone) const
|
1999-06-03 01:57:13 +00:00
|
|
|
{
|
|
|
|
CSSStyleRuleImpl* clone = new CSSStyleRuleImpl(*this);
|
2003-06-30 21:31:25 +00:00
|
|
|
if (!clone || !clone->mDeclaration || (!clone->mSelector != !mSelector)) {
|
|
|
|
delete clone;
|
2003-06-18 01:59:57 +00:00
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-03 01:57:13 +00:00
|
|
|
}
|
2003-06-18 01:59:57 +00:00
|
|
|
return CallQueryInterface(clone, &aClone);
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::GetDOMRule(nsIDOMCSSRule** aDOMRule)
|
|
|
|
{
|
2003-09-13 19:18:52 +00:00
|
|
|
if (!mSheet) {
|
|
|
|
// inline style rules aren't supposed to have a DOM rule object, only
|
|
|
|
// a declaration.
|
|
|
|
*aDOMRule = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-06-24 05:40:37 +00:00
|
|
|
if (!mDOMRule) {
|
|
|
|
mDOMRule = new DOMCSSStyleRuleImpl(this);
|
|
|
|
if (!mDOMRule) {
|
|
|
|
*aDOMRule = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mDOMRule);
|
|
|
|
}
|
|
|
|
*aDOMRule = mDOMRule;
|
|
|
|
NS_ADDREF(*aDOMRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
/* virtual */ already_AddRefed<nsICSSStyleRule>
|
|
|
|
CSSStyleRuleImpl::DeclarationChanged(PRBool aHandleContainer)
|
|
|
|
{
|
|
|
|
CSSStyleRuleImpl* clone = new CSSStyleRuleImpl(*this, mDeclaration);
|
|
|
|
if (!clone) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(clone); // for return
|
|
|
|
|
2003-06-30 21:31:25 +00:00
|
|
|
if (aHandleContainer) {
|
|
|
|
NS_ASSERTION(mSheet, "rule must be in a sheet");
|
2003-06-18 01:59:57 +00:00
|
|
|
if (mParentRule) {
|
|
|
|
mSheet->ReplaceRuleInGroup(mParentRule, this, clone);
|
|
|
|
} else {
|
|
|
|
mSheet->ReplaceStyleRule(this, clone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
1999-06-03 01:57:13 +00:00
|
|
|
}
|
|
|
|
|
1999-04-15 21:23:05 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-31 22:19:43 +00:00
|
|
|
CSSStyleRuleImpl::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2003-06-07 22:14:42 +00:00
|
|
|
return mDeclaration->MapRuleInfoInto(aRuleData);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
1998-08-29 20:20:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
2003-06-14 23:50:54 +00:00
|
|
|
if (mSelector)
|
|
|
|
mSelector->ToString(buffer, mSheet);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2004-06-17 00:13:25 +00:00
|
|
|
buffer.AppendLiteral(" ");
|
2001-10-16 03:53:44 +00:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out);
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != mDeclaration) {
|
|
|
|
mDeclaration->List(out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("{ null declaration }", out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
1998-08-29 20:20:38 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2000-03-31 07:08:36 +00:00
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
2002-03-23 22:56:05 +00:00
|
|
|
CSSStyleRuleImpl::GetCssText(nsAString& aCssText)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2003-06-14 23:50:54 +00:00
|
|
|
if (mSelector) {
|
|
|
|
mSelector->ToString(aCssText, mSheet);
|
|
|
|
aCssText.Append(PRUnichar(' '));
|
|
|
|
}
|
2001-02-13 14:10:38 +00:00
|
|
|
aCssText.Append(PRUnichar('{'));
|
|
|
|
aCssText.Append(PRUnichar(' '));
|
2000-09-13 00:05:04 +00:00
|
|
|
if (mDeclaration)
|
|
|
|
{
|
|
|
|
nsAutoString tempString;
|
|
|
|
mDeclaration->ToString( tempString );
|
|
|
|
aCssText.Append( tempString );
|
|
|
|
}
|
2001-02-13 14:10:38 +00:00
|
|
|
aCssText.Append(PRUnichar(' '));
|
|
|
|
aCssText.Append(PRUnichar('}'));
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
2002-03-23 22:56:05 +00:00
|
|
|
CSSStyleRuleImpl::SetCssText(const nsAString& aCssText)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1999-02-07 21:48:45 +00:00
|
|
|
// XXX TBI - need to re-parse rule & declaration
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
|
|
|
CSSStyleRuleImpl::GetParentStyleSheet(nsICSSStyleSheet** aSheet)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
2003-06-24 05:40:37 +00:00
|
|
|
*aSheet = mSheet;
|
|
|
|
NS_IF_ADDREF(*aSheet);
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
|
|
|
CSSStyleRuleImpl::GetParentRule(nsICSSGroupRule** aParentRule)
|
2000-04-26 13:58:56 +00:00
|
|
|
{
|
2003-06-24 05:40:37 +00:00
|
|
|
*aParentRule = mParentRule;
|
|
|
|
NS_IF_ADDREF(*aParentRule);
|
2001-09-19 14:16:34 +00:00
|
|
|
return NS_OK;
|
2000-04-26 13:58:56 +00:00
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
2002-03-23 22:56:05 +00:00
|
|
|
CSSStyleRuleImpl::GetSelectorText(nsAString& aSelectorText)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
2003-06-14 23:50:54 +00:00
|
|
|
if (mSelector)
|
|
|
|
mSelector->ToString(aSelectorText, mSheet);
|
|
|
|
else
|
|
|
|
aSelectorText.Truncate();
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:40:37 +00:00
|
|
|
/* virtual */ nsresult
|
2002-03-23 22:56:05 +00:00
|
|
|
CSSStyleRuleImpl::SetSelectorText(const nsAString& aSelectorText)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
// XXX TBI - get a parser and re-parse the selectors,
|
|
|
|
// XXX then need to re-compute the cascade
|
1999-06-03 01:57:13 +00:00
|
|
|
// XXX and dirty sheet
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 15:08:41 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
|
2003-06-18 01:59:57 +00:00
|
|
|
nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2003-06-30 21:31:25 +00:00
|
|
|
NS_PRECONDITION(aDeclaration, "must have a declaration");
|
2003-06-18 01:59:57 +00:00
|
|
|
CSSStyleRuleImpl *it = new CSSStyleRuleImpl(aSelector, aDeclaration);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (!it) {
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|