2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04: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-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04: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-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2001-06-01 02:19:43 +04:00
|
|
|
* David Hyatt <hyatt@netscape.com>
|
2001-02-13 17:06:29 +03:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04: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 05:32:19 +04: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-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04: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-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of CSS style rules (selectors+declaration), CSS
|
|
|
|
* selectors, and DOM objects for style rules, selectors, and
|
|
|
|
* declarations
|
|
|
|
*/
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-06-10 09:28:32 +04:00
|
|
|
#include "nsCSSRule.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
2001-09-19 18:16:34 +04:00
|
|
|
#include "nsICSSGroupRule.h"
|
2002-01-16 01:43:37 +03:00
|
|
|
#include "nsCSSDeclaration.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1999-08-04 09:07:10 +04:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsICSSLoader.h"
|
|
|
|
#include "nsIURL.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.h"
|
1998-08-07 06:16:38 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2005-01-30 21:01:57 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2007-03-23 02:01:14 +03:00
|
|
|
#include "nsUnitConversion.h"
|
1998-09-17 04:19:47 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2003-06-24 09:40:37 +04:00
|
|
|
#include "nsICSSStyleRuleDOMWrapper.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
|
|
|
#include "nsDOMCSSDeclaration.h"
|
1998-12-11 05:50:43 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2005-02-19 03:10:38 +03:00
|
|
|
#include "nsXMLNameSpaceMap.h"
|
1999-09-10 09:56:19 +04:00
|
|
|
#include "nsILookAndFeel.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleNode.h"
|
2002-08-14 16:34:39 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2003-07-04 05:33:10 +04:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2007-05-03 05:15:53 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
1998-04-14 00:24:54 +04: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 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2003-02-22 03:32:13 +03: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 20:46:42 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
#define NS_IF_CLONE(member_) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (member_) { \
|
|
|
|
result->member_ = member_->Clone(); \
|
|
|
|
if (!result->member_) { \
|
|
|
|
delete result; \
|
|
|
|
return nsnull; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2006-04-28 22:02:53 +04:00
|
|
|
#define NS_IF_DEEP_CLONE(type_, member_, args_) \
|
2006-04-26 01:48:11 +04:00
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
type_ *dest = result; \
|
|
|
|
for (type_ *src = member_; src; src = src->member_) { \
|
2006-04-28 22:02:53 +04:00
|
|
|
type_ *clone = src->Clone args_; \
|
2006-04-26 01:48:11 +04:00
|
|
|
if (!clone) { \
|
|
|
|
delete result; \
|
|
|
|
return nsnull; \
|
|
|
|
} \
|
|
|
|
dest->member_ = clone; \
|
|
|
|
dest = clone; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NS_IF_DELETE(ptr) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (ptr) { \
|
|
|
|
delete ptr; \
|
|
|
|
ptr = nsnull; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NS_IF_DEEP_DELETE(type_, member_) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
type_ *cur = member_; \
|
|
|
|
member_ = nsnull; \
|
|
|
|
while (cur) { \
|
|
|
|
type_ *next = cur->member_; \
|
|
|
|
cur->member_ = nsnull; \
|
|
|
|
delete cur; \
|
|
|
|
cur = next; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
/* ************************************************************************** */
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
nsAtomList::nsAtomList(nsIAtom* aAtom)
|
|
|
|
: mAtom(aAtom),
|
1998-04-14 00:24:54 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAtomList);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
nsAtomList::nsAtomList(const nsString& aAtomValue)
|
|
|
|
: mAtom(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAtomList);
|
2002-08-14 16:34:39 +04:00
|
|
|
mAtom = do_GetAtom(aAtomValue);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsAtomList*
|
|
|
|
nsAtomList::Clone(PRBool aDeep) const
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2006-04-26 01:48:11 +04:00
|
|
|
nsAtomList *result = new nsAtomList(mAtom);
|
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (aDeep)
|
2006-04-28 22:02:53 +04:00
|
|
|
NS_IF_DEEP_CLONE(nsAtomList, mNext, (PR_FALSE));
|
2006-04-26 01:48:11 +04:00
|
|
|
return result;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomList::~nsAtomList(void)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsAtomList);
|
2006-04-26 01:48:11 +04:00
|
|
|
NS_IF_DEEP_DELETE(nsAtomList, mNext);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList::nsAtomStringList(nsIAtom* aAtom, const PRUnichar* aString)
|
|
|
|
: mAtom(aAtom),
|
|
|
|
mString(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAtomStringList);
|
|
|
|
if (aString)
|
2006-11-17 04:49:06 +03:00
|
|
|
mString = NS_strdup(aString);
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomStringList::nsAtomStringList(const nsString& aAtomValue,
|
|
|
|
const PRUnichar* aString)
|
|
|
|
: mAtom(nsnull),
|
|
|
|
mString(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsAtomStringList);
|
|
|
|
mAtom = do_GetAtom(aAtomValue);
|
|
|
|
if (aString)
|
2006-11-17 04:49:06 +03:00
|
|
|
mString = NS_strdup(aString);
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsAtomStringList*
|
|
|
|
nsAtomStringList::Clone(PRBool aDeep) const
|
2002-08-14 16:34:39 +04:00
|
|
|
{
|
2006-04-26 01:48:11 +04:00
|
|
|
nsAtomStringList *result = new nsAtomStringList(mAtom, mString);
|
|
|
|
|
|
|
|
if (aDeep)
|
2006-04-28 22:02:53 +04:00
|
|
|
NS_IF_DEEP_CLONE(nsAtomStringList, mNext, (PR_FALSE));
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
return result;
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAtomStringList::~nsAtomStringList(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsAtomStringList);
|
|
|
|
if (mString)
|
2006-11-17 04:49:06 +03:00
|
|
|
NS_Free(mString);
|
2006-04-26 01:48:11 +04:00
|
|
|
NS_IF_DEEP_DELETE(nsAtomStringList, mNext);
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr)
|
|
|
|
: mNameSpace(aNameSpace),
|
|
|
|
mAttr(nsnull),
|
1998-12-11 05:50:43 +03:00
|
|
|
mFunction(NS_ATTR_FUNC_SET),
|
1998-12-21 08:58:58 +03:00
|
|
|
mCaseSensitive(1),
|
1998-12-11 05:50:43 +03:00
|
|
|
mValue(),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
mAttr = do_GetAtom(aAttr);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunction,
|
|
|
|
const nsString& aValue, PRBool aCaseSensitive)
|
|
|
|
: mNameSpace(aNameSpace),
|
|
|
|
mAttr(nsnull),
|
1998-12-11 05:50:43 +03:00
|
|
|
mFunction(aFunction),
|
1998-12-21 08:58:58 +03:00
|
|
|
mCaseSensitive(aCaseSensitive),
|
1998-12-11 05:50:43 +03:00
|
|
|
mValue(aValue),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
mAttr = do_GetAtom(aAttr);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, nsIAtom* aAttr,
|
|
|
|
PRUint8 aFunction, const nsString& aValue,
|
|
|
|
PRBool aCaseSensitive)
|
|
|
|
: mNameSpace(aNameSpace),
|
|
|
|
mAttr(aAttr),
|
|
|
|
mFunction(aFunction),
|
|
|
|
mCaseSensitive(aCaseSensitive),
|
|
|
|
mValue(aValue),
|
1998-12-11 05:50:43 +03:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2006-04-26 01:48:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrSelector*
|
|
|
|
nsAttrSelector::Clone(PRBool aDeep) const
|
|
|
|
{
|
|
|
|
nsAttrSelector *result =
|
|
|
|
new nsAttrSelector(mNameSpace, mAttr, mFunction, mValue, mCaseSensitive);
|
|
|
|
|
|
|
|
if (aDeep)
|
2006-04-28 22:02:53 +04:00
|
|
|
NS_IF_DEEP_CLONE(nsAttrSelector, mNext, (PR_FALSE));
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
return result;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrSelector::~nsAttrSelector(void)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsAttrSelector);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
NS_IF_DEEP_DELETE(nsAttrSelector, mNext);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
// -- nsCSSSelector -------------------------------
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
nsCSSSelector::nsCSSSelector(void)
|
|
|
|
: mNameSpace(kNameSpaceID_Unknown), mTag(nsnull),
|
2001-02-13 17:06:29 +03:00
|
|
|
mIDList(nsnull),
|
1998-12-11 05:50:43 +03:00
|
|
|
mClassList(nsnull),
|
|
|
|
mPseudoClassList(nsnull),
|
|
|
|
mAttrList(nsnull),
|
|
|
|
mOperator(0),
|
2001-03-20 14:49:20 +03:00
|
|
|
mNegations(nsnull),
|
1998-04-14 00:24:54 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSSelector);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsCSSSelector*
|
2006-04-28 22:02:53 +04:00
|
|
|
nsCSSSelector::Clone(PRBool aDeepNext, PRBool aDeepNegations) const
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2006-04-26 01:48:11 +04:00
|
|
|
nsCSSSelector *result = new nsCSSSelector();
|
|
|
|
if (!result)
|
|
|
|
return nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
result->mNameSpace = mNameSpace;
|
|
|
|
result->mTag = mTag;
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
NS_IF_CLONE(mIDList);
|
|
|
|
NS_IF_CLONE(mClassList);
|
|
|
|
NS_IF_CLONE(mPseudoClassList);
|
|
|
|
NS_IF_CLONE(mAttrList);
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2006-04-28 22:02:53 +04:00
|
|
|
// No need to worry about multiple levels of recursion since an
|
|
|
|
// mNegations can't have an mNext.
|
|
|
|
if (aDeepNegations) {
|
|
|
|
NS_IF_DEEP_CLONE(nsCSSSelector, mNegations, (PR_TRUE, PR_FALSE));
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-04-28 22:02:53 +04:00
|
|
|
if (aDeepNext) {
|
|
|
|
NS_IF_DEEP_CLONE(nsCSSSelector, mNext, (PR_FALSE, PR_TRUE));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsCSSSelector::~nsCSSSelector(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSSelector);
|
|
|
|
Reset();
|
|
|
|
// No need to worry about multiple levels of recursion since an
|
|
|
|
// mNegations can't have an mNext.
|
|
|
|
NS_IF_DEEP_DELETE(nsCSSSelector, mNext);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
void nsCSSSelector::Reset(void)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
mNameSpace = kNameSpaceID_Unknown;
|
2002-08-14 16:34:39 +04:00
|
|
|
mTag = nsnull;
|
2001-02-13 17:06:29 +03:00
|
|
|
NS_IF_DELETE(mIDList);
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_IF_DELETE(mClassList);
|
|
|
|
NS_IF_DELETE(mPseudoClassList);
|
|
|
|
NS_IF_DELETE(mAttrList);
|
2006-04-26 01:48:11 +04:00
|
|
|
// No need to worry about multiple levels of recursion since an
|
|
|
|
// mNegations can't have an mNext.
|
|
|
|
NS_IF_DEEP_DELETE(nsCSSSelector, mNegations);
|
1999-02-27 10:16:57 +03:00
|
|
|
mOperator = PRUnichar(0);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetNameSpace(PRInt32 aNameSpace)
|
|
|
|
{
|
|
|
|
mNameSpace = aNameSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetTag(const nsString& aTag)
|
|
|
|
{
|
2002-08-14 16:34:39 +04:00
|
|
|
if (aTag.IsEmpty())
|
|
|
|
mTag = nsnull;
|
|
|
|
else
|
|
|
|
mTag = do_GetAtom(aTag);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2001-02-13 17:06:29 +03:00
|
|
|
void nsCSSSelector::AddID(const nsString& aID)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aID.IsEmpty()) {
|
2001-02-13 17:06:29 +03:00
|
|
|
nsAtomList** list = &mIDList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
|
|
|
*list = new nsAtomList(aID);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::AddClass(const nsString& aClass)
|
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aClass.IsEmpty()) {
|
1998-12-11 05:50:43 +03:00
|
|
|
nsAtomList** list = &mClassList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
|
|
|
*list = new nsAtomList(aClass);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2002-08-14 16:34:39 +04:00
|
|
|
void nsCSSSelector::AddPseudoClass(const nsString& aPseudoClass,
|
|
|
|
const PRUnichar* aString)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aPseudoClass.IsEmpty()) {
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList** list = &mPseudoClassList;
|
1998-12-11 05:50:43 +03:00
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
*list = new nsAtomStringList(aPseudoClass, aString);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 16:34:39 +04:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsIAtom* aPseudoClass,
|
|
|
|
const PRUnichar* aString)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
|
|
|
if (nsnull != aPseudoClass) {
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList** list = &mPseudoClassList;
|
1998-12-11 05:50:43 +03:00
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
1998-05-19 01:09:43 +04:00
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
*list = new nsAtomStringList(aPseudoClass, aString);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
void nsCSSSelector::AddAttribute(PRInt32 aNameSpace, const nsString& aAttr)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aAttr.IsEmpty()) {
|
1998-12-11 05:50:43 +03:00
|
|
|
nsAttrSelector** list = &mAttrList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
1999-06-10 09:28:32 +04:00
|
|
|
*list = new nsAttrSelector(aNameSpace, aAttr);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
void nsCSSSelector::AddAttribute(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunc,
|
|
|
|
const nsString& aValue, PRBool aCaseSensitive)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aAttr.IsEmpty()) {
|
1998-12-11 05:50:43 +03:00
|
|
|
nsAttrSelector** list = &mAttrList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
1999-06-10 09:28:32 +04:00
|
|
|
*list = new nsAttrSelector(aNameSpace, aAttr, aFunc, aValue, aCaseSensitive);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::SetOperator(PRUnichar aOperator)
|
|
|
|
{
|
|
|
|
mOperator = aOperator;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsCSSSelector::CalcWeight(void) const
|
|
|
|
{
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
|
|
|
|
if (nsnull != mTag) {
|
|
|
|
weight += 0x000001;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-02-13 17:06:29 +03:00
|
|
|
nsAtomList* list = mIDList;
|
|
|
|
while (nsnull != list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
weight += 0x010000;
|
2001-02-13 17:06:29 +03:00
|
|
|
list = list->mNext;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-02-13 17:06:29 +03:00
|
|
|
list = mClassList;
|
1998-12-11 05:50:43 +03:00
|
|
|
while (nsnull != list) {
|
|
|
|
weight += 0x000100;
|
|
|
|
list = list->mNext;
|
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList *plist = mPseudoClassList;
|
|
|
|
while (nsnull != plist) {
|
1998-12-11 05:50:43 +03:00
|
|
|
weight += 0x000100;
|
2002-08-14 16:34:39 +04:00
|
|
|
plist = plist->mNext;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
nsAttrSelector* attr = mAttrList;
|
|
|
|
while (nsnull != attr) {
|
|
|
|
weight += 0x000100;
|
|
|
|
attr = attr->mNext;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
if (nsnull != mNegations) {
|
|
|
|
weight += mNegations->CalcWeight();
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
return weight;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-02-12 16:04:06 +03: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 21:55:59 +03:00
|
|
|
const char* str;
|
|
|
|
aAtom->GetUTF8String(&str);
|
2001-02-12 16:04:06 +03:00
|
|
|
return str && (*str == ':');
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
void nsCSSSelector::AppendNegationToString(nsAString& aString)
|
2001-03-20 14:49:20 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aString.AppendLiteral(":not(");
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Builds the textual representation of a selector. Called by DOM 2 CSS
|
|
|
|
// StyleRule:selectorText
|
|
|
|
//
|
2003-06-15 03:50:54 +04:00
|
|
|
void
|
2005-02-03 21:31:24 +03:00
|
|
|
nsCSSSelector::ToString(nsAString& aString, nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aAppend) const
|
2003-06-15 03:50:54 +04:00
|
|
|
{
|
2005-02-03 21:31:24 +03:00
|
|
|
if (!aAppend)
|
|
|
|
aString.Truncate();
|
|
|
|
|
2005-11-09 07:17:26 +03:00
|
|
|
ToStringInternal(aString, aSheet, IsPseudoElement(mTag), PR_FALSE);
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSSelector::ToStringInternal(nsAString& aString,
|
|
|
|
nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aIsPseudoElem,
|
2005-11-09 07:17:26 +03:00
|
|
|
PRBool aIsNegated) const
|
2000-09-13 04:05:04 +04:00
|
|
|
{
|
2003-03-25 21:55:59 +03:00
|
|
|
nsAutoString temp;
|
2004-05-18 06:42:13 +04:00
|
|
|
PRBool isPseudoElement = IsPseudoElement(mTag);
|
2005-02-03 21:31:24 +03:00
|
|
|
|
2001-01-22 07:03:48 +03: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 14:49:20 +03:00
|
|
|
if (mNext) {
|
2003-06-15 03:50:54 +04:00
|
|
|
mNext->ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
|
2004-05-18 06:42:13 +04:00
|
|
|
if (!aIsNegated && !isPseudoElement) {
|
2001-02-12 16:04:06 +03:00
|
|
|
// don't add a leading whitespace if we have a pseudo-element
|
2001-03-20 14:49:20 +03:00
|
|
|
// or a negated simple selector
|
2001-02-12 16:04:06 +03:00
|
|
|
aString.Append(PRUnichar(' '));
|
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
|
2004-05-18 06:42:13 +04:00
|
|
|
// For non-pseudo-element selectors or for lone pseudo-elements, deal with
|
|
|
|
// namespace prefixes.
|
2005-11-15 02:40:37 +03:00
|
|
|
PRBool wroteNamespace = PR_FALSE;
|
2004-05-18 06:42:13 +04:00
|
|
|
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 07:03:48 +03:00
|
|
|
aString.Append(PRUnichar('|'));
|
2005-11-15 02:40:37 +03:00
|
|
|
wroteNamespace = PR_TRUE;
|
2004-05-18 06:42:13 +04:00
|
|
|
} else {
|
2007-04-12 20:23:43 +04:00
|
|
|
if (aSheet) {
|
|
|
|
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
|
2004-05-18 06:42:13 +04:00
|
|
|
|
2007-04-12 20:23:43 +04:00
|
|
|
// 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) {
|
|
|
|
if (mNameSpace != kNameSpaceID_Unknown) {
|
|
|
|
if (sheetNS->FindNameSpaceID(nsnull) != mNameSpace) {
|
|
|
|
nsIAtom *prefixAtom = sheetNS->FindPrefix(mNameSpace);
|
|
|
|
NS_ASSERTION(prefixAtom, "how'd we get a non-default namespace "
|
|
|
|
"without a prefix?");
|
|
|
|
nsAutoString prefix;
|
|
|
|
prefixAtom->ToString(prefix);
|
|
|
|
aString.Append(prefix);
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
wroteNamespace = PR_TRUE;
|
|
|
|
}
|
|
|
|
// otherwise it must be the default namespace
|
|
|
|
} else {
|
|
|
|
// A selector for an element in any namespace.
|
|
|
|
if (// Use explicit "*|" only when it's not implied
|
|
|
|
sheetNS->FindNameSpaceID(nsnull) != kNameSpaceID_None &&
|
|
|
|
// :not() is special in that the default namespace is
|
|
|
|
// not implied for non-type selectors
|
|
|
|
(!aIsNegated || (!mIDList && !mClassList &&
|
|
|
|
!mPseudoClassList && !mAttrList))) {
|
|
|
|
aString.AppendLiteral("*|");
|
|
|
|
wroteNamespace = PR_TRUE;
|
|
|
|
}
|
2005-11-15 02:40:37 +03:00
|
|
|
}
|
2004-05-18 06:42:13 +04:00
|
|
|
}
|
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-18 06:42:13 +04:00
|
|
|
|
2005-11-15 02:40:37 +03:00
|
|
|
if (!mTag) {
|
|
|
|
// Universal selector: avoid writing the universal selector when we
|
|
|
|
// can avoid it, especially since we're required to avoid it for the
|
|
|
|
// inside of :not()
|
|
|
|
if (wroteNamespace ||
|
|
|
|
(!mIDList && !mClassList && !mPseudoClassList && !mAttrList &&
|
|
|
|
(aIsNegated || !mNegations))) {
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
} else {
|
2005-11-15 02:40:37 +03:00
|
|
|
// Append the tag name
|
|
|
|
if (isPseudoElement) {
|
|
|
|
if (!mNext) {
|
|
|
|
// Lone pseudo-element selector -- toss in a wildcard type selector
|
|
|
|
// XXXldb Why?
|
|
|
|
aString.Append(PRUnichar('*'));
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
2005-11-15 02:40:37 +03:00
|
|
|
if (!nsCSSPseudoElements::IsCSS2PseudoElement(mTag)) {
|
|
|
|
aString.Append(PRUnichar(':'));
|
2001-02-13 17:06:29 +03:00
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
2005-11-15 02:40:37 +03:00
|
|
|
nsAutoString prefix;
|
|
|
|
mTag->ToString(prefix);
|
|
|
|
aString.Append(prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the id, if there is one
|
|
|
|
if (mIDList) {
|
|
|
|
nsAtomList* list = mIDList;
|
|
|
|
while (list != nsnull) {
|
|
|
|
list->mAtom->ToString(temp);
|
|
|
|
aString.Append(PRUnichar('#'));
|
|
|
|
aString.Append(temp);
|
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each class in the linked list
|
|
|
|
if (mClassList) {
|
|
|
|
nsAtomList* list = mClassList;
|
|
|
|
while (list != nsnull) {
|
|
|
|
list->mAtom->ToString(temp);
|
|
|
|
aString.Append(PRUnichar('.'));
|
|
|
|
aString.Append(temp);
|
|
|
|
list = list->mNext;
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each attribute selector in the linked list
|
|
|
|
if (mAttrList) {
|
|
|
|
nsAttrSelector* list = mAttrList;
|
|
|
|
while (list != nsnull) {
|
|
|
|
aString.Append(PRUnichar('['));
|
|
|
|
// Append the namespace prefix
|
|
|
|
if (list->mNameSpace > 0) {
|
2007-04-12 20:23:43 +04:00
|
|
|
if (aSheet) {
|
|
|
|
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
|
|
|
|
// will return null if namespace was the default
|
|
|
|
nsIAtom *prefixAtom = sheetNS->FindPrefix(list->mNameSpace);
|
|
|
|
if (prefixAtom) {
|
|
|
|
nsAutoString prefix;
|
|
|
|
prefixAtom->ToString(prefix);
|
|
|
|
aString.Append(prefix);
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Append the attribute name
|
2003-03-25 21:55:59 +03:00
|
|
|
list->mAttr->ToString(temp);
|
2001-01-22 07:03:48 +03:00
|
|
|
aString.Append(temp);
|
2005-03-26 05:36:15 +03:00
|
|
|
|
|
|
|
if (list->mFunction != NS_ATTR_FUNC_SET) {
|
|
|
|
// Append the function
|
|
|
|
if (list->mFunction == NS_ATTR_FUNC_INCLUDES)
|
|
|
|
aString.Append(PRUnichar('~'));
|
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH)
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_BEGINSMATCH)
|
|
|
|
aString.Append(PRUnichar('^'));
|
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_ENDSMATCH)
|
|
|
|
aString.Append(PRUnichar('$'));
|
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_CONTAINSMATCH)
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
|
|
|
|
aString.Append(PRUnichar('='));
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2005-03-26 05:36:15 +03:00
|
|
|
// Append the value
|
|
|
|
nsAutoString escaped;
|
|
|
|
nsStyleUtil::EscapeCSSString(list->mValue, escaped);
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2005-03-26 05:36:15 +03:00
|
|
|
aString.Append(PRUnichar('\"'));
|
|
|
|
aString.Append(escaped);
|
|
|
|
aString.Append(PRUnichar('\"'));
|
|
|
|
}
|
|
|
|
|
|
|
|
aString.Append(PRUnichar(']'));
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2001-01-22 07:03:48 +03:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each pseudo-class in the linked list
|
|
|
|
if (mPseudoClassList) {
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList* list = mPseudoClassList;
|
2001-01-22 07:03:48 +03:00
|
|
|
while (list != nsnull) {
|
2003-03-25 21:55:59 +03:00
|
|
|
list->mAtom->ToString(temp);
|
2001-01-22 07:03:48 +03:00
|
|
|
aString.Append(temp);
|
2002-08-14 16:34:39 +04:00
|
|
|
if (nsnull != list->mString) {
|
|
|
|
aString.Append(PRUnichar('('));
|
|
|
|
aString.Append(list->mString);
|
|
|
|
aString.Append(PRUnichar(')'));
|
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2005-11-09 07:17:26 +03:00
|
|
|
if (!aIsNegated) {
|
|
|
|
for (nsCSSSelector* negation = mNegations; negation;
|
|
|
|
negation = negation->mNegations) {
|
|
|
|
aString.AppendLiteral(":not(");
|
|
|
|
negation->ToStringInternal(aString, aSheet, PR_FALSE, PR_TRUE);
|
|
|
|
aString.Append(PRUnichar(')'));
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Append the operator only if the selector is not negated and is not
|
|
|
|
// a pseudo-element
|
|
|
|
if (!aIsNegated && mOperator && !aIsPseudoElem) {
|
2001-01-22 07:03:48 +03:00
|
|
|
aString.Append(PRUnichar(' '));
|
|
|
|
aString.Append(mOperator);
|
|
|
|
}
|
2000-09-13 04:05:04 +04:00
|
|
|
}
|
|
|
|
|
2003-06-15 03:50:54 +04:00
|
|
|
// -- nsCSSSelectorList -------------------------------
|
|
|
|
|
|
|
|
nsCSSSelectorList::nsCSSSelectorList(void)
|
|
|
|
: mSelectors(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mWeight(0),
|
2003-06-15 03:50:54 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSSelectorList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelectorList::~nsCSSSelectorList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSSelectorList);
|
2006-04-26 01:48:11 +04:00
|
|
|
NS_IF_DELETE(mSelectors);
|
|
|
|
NS_IF_DEEP_DELETE(nsCSSSelectorList, mNext);
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
void nsCSSSelectorList::AddSelector(const nsCSSSelector& aSelector)
|
2003-06-15 03:50:54 +04:00
|
|
|
{ // prepend to list
|
2007-03-23 02:01:14 +03:00
|
|
|
nsCSSSelector* newSel = aSelector.Clone();
|
2003-06-15 03:50:54 +04:00
|
|
|
if (newSel) {
|
|
|
|
newSel->mNext = mSelectors;
|
|
|
|
mSelectors = newSel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSSelectorList::ToString(nsAString& aResult, nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
2005-02-03 21:31:24 +03:00
|
|
|
aResult.Truncate();
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList *p = this;
|
|
|
|
for (;;) {
|
2005-02-03 21:31:24 +03:00
|
|
|
p->mSelectors->ToString(aResult, aSheet, PR_TRUE);
|
2003-06-15 03:50:54 +04:00
|
|
|
p = p->mNext;
|
|
|
|
if (!p)
|
|
|
|
break;
|
2004-06-17 04:13:25 +04:00
|
|
|
aResult.AppendLiteral(", ");
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSSelectorList*
|
2006-04-26 01:48:11 +04:00
|
|
|
nsCSSSelectorList::Clone(PRBool aDeep) const
|
|
|
|
{
|
|
|
|
nsCSSSelectorList *result = new nsCSSSelectorList();
|
|
|
|
result->mWeight = mWeight;
|
|
|
|
NS_IF_CLONE(mSelectors);
|
|
|
|
|
|
|
|
if (aDeep) {
|
2006-04-28 22:02:53 +04:00
|
|
|
NS_IF_DEEP_CLONE(nsCSSSelectorList, mNext, (PR_FALSE));
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
2006-04-26 01:48:11 +04:00
|
|
|
return result;
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
1998-09-11 06:07:05 +04:00
|
|
|
// -- CSSImportantRule -------------------------------
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
class CSSStyleRuleImpl;
|
|
|
|
|
1998-09-11 06:07:05 +04:00
|
|
|
class CSSImportantRule : public nsIStyleRule {
|
|
|
|
public:
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSImportantRule(nsCSSDeclaration* aDeclaration);
|
1998-09-11 06:07:05 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
// nsIStyleRule interface
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-09-11 06:07:05 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1998-09-11 06:07:05 +04:00
|
|
|
protected:
|
1999-02-12 20:45:58 +03:00
|
|
|
virtual ~CSSImportantRule(void);
|
1998-09-11 06:07:05 +04:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* mDeclaration;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
friend class CSSStyleRuleImpl;
|
1998-09-11 06:07:05 +04:00
|
|
|
};
|
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSImportantRule::CSSImportantRule(nsCSSDeclaration* aDeclaration)
|
|
|
|
: mDeclaration(aDeclaration)
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportantRule::~CSSImportantRule(void)
|
|
|
|
{
|
2002-01-16 01:43:37 +03:00
|
|
|
mDeclaration = nsnull;
|
1998-09-11 06:07:05 +04:00
|
|
|
}
|
|
|
|
|
2001-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(CSSImportantRule, nsIStyleRule)
|
1998-09-11 06:07:05 +04:00
|
|
|
|
1999-04-16 01:23:05 +04:00
|
|
|
NS_IMETHODIMP
|
2001-06-01 02:19:43 +04:00
|
|
|
CSSImportantRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2005-03-25 07:09:13 +03:00
|
|
|
// Check this at runtime because it might be hit in some out-of-memory cases.
|
|
|
|
NS_ENSURE_TRUE(mDeclaration->HasImportantData(), NS_ERROR_UNEXPECTED);
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
return mDeclaration->MapImportantRuleInfoInto(aRuleData);
|
1998-09-11 06:07:05 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-09-11 06:07:05 +04: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 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
// --------------------------------------------------------
|
|
|
|
|
|
|
|
class DOMCSSStyleRuleImpl;
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
|
2003-06-24 09:40:37 +04:00
|
|
|
virtual ~DOMCSSDeclarationImpl(void);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2003-06-24 10:20:18 +04:00
|
|
|
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
|
1999-06-10 09:28:32 +04:00
|
|
|
virtual void DropReference(void);
|
2002-01-16 01:43:37 +03:00
|
|
|
virtual nsresult GetCSSDeclaration(nsCSSDeclaration **aDecl,
|
1998-10-06 05:39:33 +04:00
|
|
|
PRBool aAllocate);
|
2004-09-11 03:31:48 +04:00
|
|
|
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
|
|
|
|
nsIURI** aBaseURI,
|
2007-05-03 05:15:53 +04:00
|
|
|
nsIPrincipal** aSheetPrincipal,
|
2001-10-19 17:50:30 +04:00
|
|
|
nsICSSLoader** aCSSLoader,
|
|
|
|
nsICSSParser** aCSSParser);
|
2003-06-18 05:59:57 +04:00
|
|
|
virtual nsresult DeclarationChanged();
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2003-06-24 09:40:37 +04: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 05:39:33 +04:00
|
|
|
protected:
|
2003-06-24 09:40:37 +04:00
|
|
|
// This reference is not reference-counted. The rule object tells us
|
|
|
|
// when it's about to go away.
|
1998-10-06 05:39:33 +04:00
|
|
|
nsICSSStyleRule *mRule;
|
2003-06-24 09:40:37 +04: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 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
: mRule(aRule)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(DOMCSSDeclarationImpl);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl(void)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_ASSERTION(!mRule, "DropReference not called.");
|
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(DOMCSSDeclarationImpl);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
inline DOMCSSStyleRuleImpl* DOMCSSDeclarationImpl::DomRule()
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
return NS_REINTERPRET_CAST(DOMCSSStyleRuleImpl*,
|
|
|
|
NS_REINTERPRET_CAST(char*, this) -
|
2003-06-24 09:40:37 +04:00
|
|
|
offsetof(DOMCSSStyleRuleImpl, mDOMDeclaration));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule())
|
|
|
|
NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule())
|
|
|
|
|
|
|
|
void
|
1999-06-10 09:28:32 +04:00
|
|
|
DOMCSSDeclarationImpl::DropReference(void)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
mRule = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-16 01:43:37 +03:00
|
|
|
DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
|
2002-10-09 05:59:43 +04:00
|
|
|
PRBool aAllocate)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2002-10-09 05:59:43 +04:00
|
|
|
if (mRule) {
|
1998-10-06 05:39:33 +04:00
|
|
|
*aDecl = mRule->GetDeclaration();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aDecl = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-19 17:50:30 +04:00
|
|
|
/*
|
|
|
|
* This is a utility function. It will only fail if it can't get a
|
2003-06-18 05:59:57 +04:00
|
|
|
* parser. This means it can return NS_OK without aURI or aCSSLoader
|
|
|
|
* being initialized.
|
2001-10-19 17:50:30 +04:00
|
|
|
*/
|
|
|
|
nsresult
|
2004-09-11 03:31:48 +04:00
|
|
|
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
|
|
|
|
nsIURI** aBaseURI,
|
2007-05-03 05:15:53 +04:00
|
|
|
nsIPrincipal** aSheetPrincipal,
|
2001-10-19 17:50:30 +04:00
|
|
|
nsICSSLoader** aCSSLoader,
|
|
|
|
nsICSSParser** aCSSParser)
|
|
|
|
{
|
|
|
|
// null out the out params since some of them may not get initialized below
|
2004-09-11 03:31:48 +04:00
|
|
|
*aSheetURI = nsnull;
|
2004-09-10 10:45:59 +04:00
|
|
|
*aBaseURI = nsnull;
|
2007-05-03 05:15:53 +04:00
|
|
|
*aSheetPrincipal = nsnull;
|
2001-10-19 17:50:30 +04:00
|
|
|
*aCSSLoader = nsnull;
|
|
|
|
*aCSSParser = nsnull;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
2003-06-18 05:59:57 +04:00
|
|
|
if (mRule) {
|
|
|
|
mRule->GetStyleSheet(*getter_AddRefs(sheet));
|
2001-10-19 17:50:30 +04:00
|
|
|
if (sheet) {
|
2004-09-11 03:31:48 +04:00
|
|
|
sheet->GetSheetURI(aSheetURI);
|
2004-09-10 10:45:59 +04:00
|
|
|
sheet->GetBaseURI(aBaseURI);
|
2007-05-03 05:15:53 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> cssSheet(do_QueryInterface(sheet));
|
|
|
|
if (cssSheet) {
|
|
|
|
NS_ADDREF(*aSheetPrincipal = cssSheet->Principal());
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
sheet->GetOwningDocument(*getter_AddRefs(document));
|
2004-01-14 02:14:49 +03:00
|
|
|
if (document) {
|
2005-04-19 05:27:11 +04:00
|
|
|
NS_ADDREF(*aCSSLoader = document->CSSLoader());
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
2001-10-19 17:50:30 +04:00
|
|
|
}
|
|
|
|
}
|
2003-06-24 09:40:37 +04:00
|
|
|
// XXXldb Why bother if |mRule| is null?
|
2001-10-19 17:50:30 +04:00
|
|
|
if (*aCSSLoader) {
|
|
|
|
result = (*aCSSLoader)->GetParserFor(nsnull, aCSSParser);
|
|
|
|
} else {
|
|
|
|
result = NS_NewCSSParser(aCSSParser);
|
|
|
|
}
|
|
|
|
|
2007-05-03 05:15:53 +04:00
|
|
|
if (NS_SUCCEEDED(result) && !*aSheetPrincipal) {
|
|
|
|
result = CallCreateInstance("@mozilla.org/nullprincipal;1",
|
|
|
|
aSheetPrincipal);
|
|
|
|
}
|
|
|
|
|
2001-10-19 17:50:30 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-06-24 10:20:18 +04:00
|
|
|
NS_IMETHODIMP
|
2003-06-24 09:40:37 +04:00
|
|
|
DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2002-12-11 17:24:49 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
if (!mRule) {
|
|
|
|
*aParent = nsnull;
|
|
|
|
return NS_OK;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
return mRule->GetDOMRule(aParent);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1998-09-11 06:07:05 +04:00
|
|
|
|
2003-06-18 05:59:57 +04: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 22:14:25 +04:00
|
|
|
mozAutoDocUpdate updateBatch(owningDoc, UPDATE_STYLE, PR_TRUE);
|
2003-06-18 05:59:57 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsICSSStyleRule> oldRule = mRule;
|
|
|
|
mRule = oldRule->DeclarationChanged(PR_TRUE).get();
|
2003-06-18 07:02:01 +04:00
|
|
|
if (!mRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-18 05:59:57 +04:00
|
|
|
nsrefcnt cnt = mRule->Release();
|
2003-06-24 09:40:37 +04:00
|
|
|
if (cnt == 0) {
|
|
|
|
NS_NOTREACHED("container didn't take ownership");
|
|
|
|
mRule = nsnull;
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2003-06-18 05:59:57 +04:00
|
|
|
|
|
|
|
if (owningDoc) {
|
|
|
|
owningDoc->StyleRuleChanged(sheet, oldRule, mRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04: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-14 00:24:54 +04:00
|
|
|
// -- nsCSSStyleRule -------------------------------
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
class CSSStyleRuleImpl : public nsCSSRule,
|
2003-06-24 09:40:37 +04: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 20:46:42 +04:00
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
2003-06-18 05:59:57 +04:00
|
|
|
CSSStyleRuleImpl(nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration *aDeclaration);
|
|
|
|
private:
|
|
|
|
// for |Clone|
|
1999-06-03 05:57:13 +04:00
|
|
|
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
2003-06-18 05:59:57 +04:00
|
|
|
// for |DeclarationChanged|
|
|
|
|
CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy,
|
|
|
|
nsCSSDeclaration *aDeclaration);
|
|
|
|
public:
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-06-15 03:50:54 +04:00
|
|
|
virtual nsCSSSelectorList* Selector(void);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-01-22 07:03:48 +03:00
|
|
|
virtual PRUint32 GetLineNumber(void) const;
|
|
|
|
virtual void SetLineNumber(PRUint32 aLineNumber);
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
virtual nsCSSDeclaration* GetDeclaration(void) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-09 05:59:43 +04:00
|
|
|
virtual already_AddRefed<nsIStyleRule> GetImportantRule(void);
|
1998-09-02 06:09:43 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
|
|
|
|
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
|
2001-09-19 18:16:34 +04:00
|
|
|
|
|
|
|
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2003-06-24 09:40:37 +04: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 09:28:32 +04:00
|
|
|
NS_IMETHOD GetType(PRInt32& aType) const;
|
|
|
|
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
|
1999-06-03 05:57:13 +04:00
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule);
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
virtual already_AddRefed<nsICSSStyleRule>
|
|
|
|
DeclarationChanged(PRBool aHandleContainer);
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// The new mapping function.
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-08-30 00:20:38 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
CSSStyleRuleImpl& operator=(const CSSStyleRuleImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
1999-06-10 09:28:32 +04:00
|
|
|
virtual ~CSSStyleRuleImpl(void);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
protected:
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* mSelector; // null for style attribute
|
|
|
|
nsCSSDeclaration* mDeclaration;
|
1998-11-26 04:34:53 +03:00
|
|
|
CSSImportantRule* mImportantRule;
|
2003-06-24 09:40:37 +04:00
|
|
|
DOMCSSStyleRuleImpl* mDOMRule;
|
2001-01-22 07:03:48 +03:00
|
|
|
PRUint32 mLineNumber;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
1999-06-10 09:28:32 +04:00
|
|
|
: nsCSSRule(),
|
2003-06-18 05:59:57 +04:00
|
|
|
mSelector(aSelector),
|
|
|
|
mDeclaration(aDeclaration),
|
2003-06-15 03:50:54 +04:00
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(nsnull),
|
|
|
|
mLineNumber(0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-07-01 01:31:25 +04:00
|
|
|
mDeclaration->AddRef();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
// for |Clone|
|
1999-06-03 05:57:13 +04:00
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy)
|
1999-06-10 09:28:32 +04:00
|
|
|
: nsCSSRule(aCopy),
|
2003-06-15 03:50:54 +04:00
|
|
|
mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nsnull),
|
2003-07-01 01:31:25 +04:00
|
|
|
mDeclaration(aCopy.mDeclaration->Clone()),
|
1999-06-03 05:57:13 +04:00
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(nsnull),
|
|
|
|
mLineNumber(aCopy.mLineNumber)
|
1999-06-03 05:57:13 +04:00
|
|
|
{
|
2003-06-18 05:59:57 +04:00
|
|
|
if (mDeclaration)
|
|
|
|
mDeclaration->AddRef();
|
1999-06-03 05:57:13 +04:00
|
|
|
// rest is constructed lazily on existing data
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
// for |DeclarationChanged|
|
|
|
|
CSSStyleRuleImpl::CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
|
|
|
: nsCSSRule(aCopy),
|
|
|
|
mSelector(aCopy.mSelector),
|
|
|
|
mDeclaration(aDeclaration),
|
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(aCopy.mDOMRule),
|
|
|
|
mLineNumber(aCopy.mLineNumber)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2003-06-24 09:40:37 +04: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 05:59:57 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(aDeclaration == aCopy.mDeclaration, "declaration mismatch");
|
2003-07-01 01:31:25 +04:00
|
|
|
// Transfer ownership of selector and declaration:
|
2003-06-18 05:59:57 +04:00
|
|
|
aCopy.mSelector = nsnull;
|
2003-07-01 01:31:25 +04:00
|
|
|
#if 0
|
2003-06-18 05:59:57 +04:00
|
|
|
aCopy.mDeclaration = nsnull;
|
2003-07-01 01:31:25 +04: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-25 02:55:18 +03:00
|
|
|
// SetInlineStyleRule might use it before setting the new rule (see
|
2003-07-01 01:31:25 +04:00
|
|
|
// stack in bug 209575). So leave the declaration pointer on the old
|
|
|
|
// rule.
|
|
|
|
mDeclaration->AddRef();
|
|
|
|
#endif
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:13 +04:00
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
CSSStyleRuleImpl::~CSSStyleRuleImpl(void)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
if (mSelector) {
|
|
|
|
delete mSelector;
|
|
|
|
mSelector = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
if (nsnull != mDeclaration) {
|
|
|
|
mDeclaration->Release();
|
|
|
|
mDeclaration = nsnull;
|
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
if (nsnull != mImportantRule) {
|
2002-01-24 21:28:25 +03:00
|
|
|
NS_RELEASE(mImportantRule);
|
2002-01-16 01:43:37 +03:00
|
|
|
mImportantRule = nsnull;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
2003-06-24 09:40:37 +04:00
|
|
|
if (mDOMRule) {
|
|
|
|
mDOMRule->DOMDeclaration()->DropReference();
|
|
|
|
NS_RELEASE(mDOMRule);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1998-04-22 10:40:21 +04: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 20:46:42 +04: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 09:40:37 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSStyleRuleImpl, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSStyleRuleImpl, nsCSSRule)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* CSSStyleRuleImpl::Selector(void)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
return mSelector;
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 CSSStyleRuleImpl::GetLineNumber(void) const
|
|
|
|
{
|
|
|
|
return mLineNumber;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2001-01-22 07:03:48 +03:00
|
|
|
void CSSStyleRuleImpl::SetLineNumber(PRUint32 aLineNumber)
|
|
|
|
{
|
|
|
|
mLineNumber = aLineNumber;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-18 05:59:57 +04:00
|
|
|
return mDeclaration;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-10-09 05:59:43 +04:00
|
|
|
already_AddRefed<nsIStyleRule> CSSStyleRuleImpl::GetImportantRule(void)
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
2005-03-25 07:09:13 +03:00
|
|
|
if (!mDeclaration->HasImportantData()) {
|
|
|
|
NS_ASSERTION(!mImportantRule, "immutable, so should be no important rule");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mImportantRule) {
|
2004-10-31 20:33:50 +03:00
|
|
|
mImportantRule = new CSSImportantRule(mDeclaration);
|
2005-03-25 07:09:13 +03:00
|
|
|
if (!mImportantRule)
|
|
|
|
return nsnull;
|
|
|
|
NS_ADDREF(mImportantRule);
|
1998-09-11 06:07:05 +04:00
|
|
|
}
|
2005-03-25 07:09:13 +03:00
|
|
|
NS_ADDREF(mImportantRule);
|
1998-09-11 06:07:05 +04:00
|
|
|
return mImportantRule;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2005-03-25 07:09:13 +03:00
|
|
|
// XXX What about inner, etc.
|
1999-06-10 09:28:32 +04:00
|
|
|
return nsCSSRule::GetStyleSheet(aSheet);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2004-10-31 20:33:50 +03:00
|
|
|
return nsCSSRule::SetStyleSheet(aSheet);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2001-09-19 18:16:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::SetParentRule(nsICSSGroupRule* aRule)
|
|
|
|
{
|
|
|
|
return nsCSSRule::SetParentRule(aRule);
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:13 +04:00
|
|
|
NS_IMETHODIMP
|
1999-06-10 09:28:32 +04:00
|
|
|
CSSStyleRuleImpl::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::STYLE_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::Clone(nsICSSRule*& aClone) const
|
1999-06-03 05:57:13 +04:00
|
|
|
{
|
|
|
|
CSSStyleRuleImpl* clone = new CSSStyleRuleImpl(*this);
|
2003-07-01 01:31:25 +04:00
|
|
|
if (!clone || !clone->mDeclaration || (!clone->mSelector != !mSelector)) {
|
|
|
|
delete clone;
|
2003-06-18 05:59:57 +04:00
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-03 05:57:13 +04:00
|
|
|
}
|
2003-06-18 05:59:57 +04:00
|
|
|
return CallQueryInterface(clone, &aClone);
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::GetDOMRule(nsIDOMCSSRule** aDOMRule)
|
|
|
|
{
|
2003-09-13 23:18:52 +04: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 09:40:37 +04: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 05:59:57 +04: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-07-01 01:31:25 +04:00
|
|
|
if (aHandleContainer) {
|
|
|
|
NS_ASSERTION(mSheet, "rule must be in a sheet");
|
2003-06-18 05:59:57 +04:00
|
|
|
if (mParentRule) {
|
|
|
|
mSheet->ReplaceRuleInGroup(mParentRule, this, clone);
|
|
|
|
} else {
|
|
|
|
mSheet->ReplaceStyleRule(this, clone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
1999-06-03 05:57:13 +04:00
|
|
|
}
|
|
|
|
|
1999-04-16 01:23:05 +04:00
|
|
|
NS_IMETHODIMP
|
2001-06-01 02:19:43 +04:00
|
|
|
CSSStyleRuleImpl::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return mDeclaration->MapRuleInfoInto(aRuleData);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-08-30 00:20:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
2003-06-15 03:50:54 +04:00
|
|
|
if (mSelector)
|
|
|
|
mSelector->ToString(buffer, mSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
buffer.AppendLiteral(" ");
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != mDeclaration) {
|
|
|
|
mDeclaration->List(out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("{ null declaration }", out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
1998-08-30 00:20:38 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleRuleImpl::GetCssText(nsAString& aCssText)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
if (mSelector) {
|
|
|
|
mSelector->ToString(aCssText, mSheet);
|
|
|
|
aCssText.Append(PRUnichar(' '));
|
|
|
|
}
|
2001-02-13 17:10:38 +03:00
|
|
|
aCssText.Append(PRUnichar('{'));
|
|
|
|
aCssText.Append(PRUnichar(' '));
|
2000-09-13 04:05:04 +04:00
|
|
|
if (mDeclaration)
|
|
|
|
{
|
|
|
|
nsAutoString tempString;
|
|
|
|
mDeclaration->ToString( tempString );
|
|
|
|
aCssText.Append( tempString );
|
|
|
|
}
|
2001-02-13 17:10:38 +03:00
|
|
|
aCssText.Append(PRUnichar(' '));
|
|
|
|
aCssText.Append(PRUnichar('}'));
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleRuleImpl::SetCssText(const nsAString& aCssText)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-02-08 00:48:45 +03:00
|
|
|
// XXX TBI - need to re-parse rule & declaration
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
|
|
|
CSSStyleRuleImpl::GetParentStyleSheet(nsICSSStyleSheet** aSheet)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2003-06-24 09:40:37 +04:00
|
|
|
*aSheet = mSheet;
|
|
|
|
NS_IF_ADDREF(*aSheet);
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
|
|
|
CSSStyleRuleImpl::GetParentRule(nsICSSGroupRule** aParentRule)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2003-06-24 09:40:37 +04:00
|
|
|
*aParentRule = mParentRule;
|
|
|
|
NS_IF_ADDREF(*aParentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
return NS_OK;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleRuleImpl::GetSelectorText(nsAString& aSelectorText)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
if (mSelector)
|
|
|
|
mSelector->ToString(aSelectorText, mSheet);
|
|
|
|
else
|
|
|
|
aSelectorText.Truncate();
|
1998-10-06 05:39:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
/* virtual */ nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleRuleImpl::SetSelectorText(const nsAString& aSelectorText)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
// XXX TBI - get a parser and re-parse the selectors,
|
|
|
|
// XXX then need to re-compute the cascade
|
1999-06-03 05:57:13 +04:00
|
|
|
// XXX and dirty sheet
|
1998-10-06 05:39:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
|
2003-06-18 05:59:57 +04:00
|
|
|
nsCSSSelectorList* aSelector,
|
|
|
|
nsCSSDeclaration* aDeclaration)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-07-01 01:31:25 +04:00
|
|
|
NS_PRECONDITION(aDeclaration, "must have a declaration");
|
2003-06-18 05:59:57 +04:00
|
|
|
CSSStyleRuleImpl *it = new CSSStyleRuleImpl(aSelector, aDeclaration);
|
2002-12-11 17:24:49 +03:00
|
|
|
if (!it) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-12-11 17:24:49 +03:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|