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>
|
2008-06-03 07:17:35 +04:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
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
|
|
|
|
*/
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2010-08-08 09:28:33 +04:00
|
|
|
#include "mozilla/css/GroupRule.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
1999-08-04 09:07:10 +04:00
|
|
|
#include "nsIURL.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.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"
|
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"
|
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"
|
2008-06-03 07:17:35 +04:00
|
|
|
#include "nsCSSPseudoClasses.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2009-02-20 00:55:48 +03:00
|
|
|
#include "nsTArray.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"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.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
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#include "prlog.h"
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#define NS_IF_DELETE(ptr) \
|
|
|
|
PR_BEGIN_MACRO \
|
2008-10-17 12:13:16 +04:00
|
|
|
delete ptr; \
|
|
|
|
ptr = nsnull; \
|
2006-04-26 01:48:11 +04:00
|
|
|
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*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsAtomList::Clone(bool 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)
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsAtomList, this, mNext, result, (false));
|
2006-04-26 01:48:11 +04:00
|
|
|
return result;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
nsAtomList::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsAtomList* a = this;
|
|
|
|
while (a) {
|
|
|
|
n += aMallocSizeOf(a);
|
|
|
|
|
|
|
|
// The following members aren't measured:
|
|
|
|
// - a->mAtom, because it may be shared
|
|
|
|
|
|
|
|
a = a->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
nsAtomList::~nsAtomList(void)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsAtomList);
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsAtomList, this, mNext);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
nsPseudoClassList::nsPseudoClassList(nsCSSPseudoClasses::Type aType)
|
|
|
|
: mType(aType),
|
2008-06-03 07:17:35 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
NS_ASSERTION(!nsCSSPseudoClasses::HasStringArg(aType) &&
|
|
|
|
!nsCSSPseudoClasses::HasNthPairArg(aType),
|
2008-06-03 07:17:35 +04:00
|
|
|
"unexpected pseudo-class");
|
|
|
|
MOZ_COUNT_CTOR(nsPseudoClassList);
|
|
|
|
u.mMemory = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
nsPseudoClassList::nsPseudoClassList(nsCSSPseudoClasses::Type aType,
|
2009-12-11 10:37:41 +03:00
|
|
|
const PRUnichar* aString)
|
2011-03-23 16:52:25 +03:00
|
|
|
: mType(aType),
|
2002-08-14 16:34:39 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasStringArg(aType),
|
2008-06-03 07:17:35 +04:00
|
|
|
"unexpected pseudo-class");
|
|
|
|
NS_ASSERTION(aString, "string expected");
|
|
|
|
MOZ_COUNT_CTOR(nsPseudoClassList);
|
|
|
|
u.mString = NS_strdup(aString);
|
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
nsPseudoClassList::nsPseudoClassList(nsCSSPseudoClasses::Type aType,
|
2009-12-11 10:37:41 +03:00
|
|
|
const PRInt32* aIntPair)
|
2011-03-23 16:52:25 +03:00
|
|
|
: mType(aType),
|
2008-06-03 07:17:35 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasNthPairArg(aType),
|
2008-06-03 07:17:35 +04:00
|
|
|
"unexpected pseudo-class");
|
|
|
|
NS_ASSERTION(aIntPair, "integer pair expected");
|
2008-06-03 07:17:35 +04:00
|
|
|
MOZ_COUNT_CTOR(nsPseudoClassList);
|
2008-06-03 07:17:35 +04:00
|
|
|
u.mNumbers =
|
|
|
|
static_cast<PRInt32*>(nsMemory::Clone(aIntPair, sizeof(PRInt32) * 2));
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
2010-04-24 06:59:47 +04:00
|
|
|
// adopts aSelectorList
|
2011-03-23 16:52:25 +03:00
|
|
|
nsPseudoClassList::nsPseudoClassList(nsCSSPseudoClasses::Type aType,
|
2010-04-24 06:59:47 +04:00
|
|
|
nsCSSSelectorList* aSelectorList)
|
2011-03-23 16:52:25 +03:00
|
|
|
: mType(aType),
|
2010-04-24 06:59:47 +04:00
|
|
|
mNext(nsnull)
|
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(aType),
|
2010-04-24 06:59:47 +04:00
|
|
|
"unexpected pseudo-class");
|
|
|
|
NS_ASSERTION(aSelectorList, "selector list expected");
|
|
|
|
MOZ_COUNT_CTOR(nsPseudoClassList);
|
|
|
|
u.mSelectors = aSelectorList;
|
|
|
|
}
|
|
|
|
|
2008-06-03 07:17:35 +04:00
|
|
|
nsPseudoClassList*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPseudoClassList::Clone(bool aDeep) const
|
2002-08-14 16:34:39 +04:00
|
|
|
{
|
2008-06-03 07:17:35 +04:00
|
|
|
nsPseudoClassList *result;
|
|
|
|
if (!u.mMemory) {
|
2011-03-23 16:52:25 +03:00
|
|
|
result = new nsPseudoClassList(mType);
|
2011-03-23 16:52:24 +03:00
|
|
|
} else if (nsCSSPseudoClasses::HasStringArg(mType)) {
|
2011-03-23 16:52:25 +03:00
|
|
|
result = new nsPseudoClassList(mType, u.mString);
|
2011-03-23 16:52:24 +03:00
|
|
|
} else if (nsCSSPseudoClasses::HasNthPairArg(mType)) {
|
2011-03-23 16:52:25 +03:00
|
|
|
result = new nsPseudoClassList(mType, u.mNumbers);
|
2008-06-03 07:17:35 +04:00
|
|
|
} else {
|
2011-03-23 16:52:24 +03:00
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(mType),
|
2008-06-03 07:17:35 +04:00
|
|
|
"unexpected pseudo-class");
|
2010-04-24 06:59:47 +04:00
|
|
|
// This constructor adopts its selector list argument.
|
2011-03-23 16:52:25 +03:00
|
|
|
result = new nsPseudoClassList(mType, u.mSelectors->Clone());
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
if (aDeep)
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsPseudoClassList, this, mNext, result,
|
2011-10-17 18:59:28 +04:00
|
|
|
(false));
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
return result;
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
nsPseudoClassList::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsPseudoClassList* p = this;
|
|
|
|
while (p) {
|
|
|
|
n += aMallocSizeOf(p);
|
|
|
|
if (!p->u.mMemory) {
|
|
|
|
// do nothing
|
|
|
|
|
|
|
|
} else if (nsCSSPseudoClasses::HasStringArg(p->mType)) {
|
|
|
|
n += aMallocSizeOf(p->u.mString);
|
|
|
|
|
|
|
|
} else if (nsCSSPseudoClasses::HasNthPairArg(p->mType)) {
|
|
|
|
n += aMallocSizeOf(p->u.mNumbers);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(p->mType),
|
|
|
|
"unexpected pseudo-class");
|
|
|
|
n += p->u.mSelectors->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
p = p->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-06-03 07:17:35 +04:00
|
|
|
nsPseudoClassList::~nsPseudoClassList(void)
|
2002-08-14 16:34:39 +04:00
|
|
|
{
|
2008-06-03 07:17:35 +04:00
|
|
|
MOZ_COUNT_DTOR(nsPseudoClassList);
|
2011-03-23 16:52:24 +03:00
|
|
|
if (nsCSSPseudoClasses::HasSelectorListArg(mType)) {
|
2010-04-24 06:59:47 +04:00
|
|
|
delete u.mSelectors;
|
|
|
|
} else if (u.mMemory) {
|
2008-06-03 07:17:35 +04:00
|
|
|
NS_Free(u.mMemory);
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsPseudoClassList, this, mNext);
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:28:32 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(),
|
|
|
|
mNext(nsnull),
|
2009-09-29 10:07:45 +04:00
|
|
|
mLowercaseAttr(nsnull),
|
|
|
|
mCasedAttr(nsnull),
|
2009-05-13 12:26:48 +04:00
|
|
|
mNameSpace(aNameSpace),
|
1998-12-11 05:50:43 +03:00
|
|
|
mFunction(NS_ATTR_FUNC_SET),
|
2009-05-13 12:26:48 +04:00
|
|
|
mCaseSensitive(1)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
nsAutoString lowercase;
|
2010-08-03 02:19:04 +04:00
|
|
|
nsContentUtils::ASCIIToLower(aAttr, lowercase);
|
2009-09-29 10:07:45 +04:00
|
|
|
|
|
|
|
mCasedAttr = do_GetAtom(aAttr);
|
|
|
|
mLowercaseAttr = do_GetAtom(lowercase);
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsString& aValue, bool aCaseSensitive)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(aValue),
|
|
|
|
mNext(nsnull),
|
2009-09-29 10:07:45 +04:00
|
|
|
mLowercaseAttr(nsnull),
|
|
|
|
mCasedAttr(nsnull),
|
2009-05-13 12:26:48 +04:00
|
|
|
mNameSpace(aNameSpace),
|
1998-12-11 05:50:43 +03:00
|
|
|
mFunction(aFunction),
|
2009-05-13 12:26:48 +04:00
|
|
|
mCaseSensitive(aCaseSensitive)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
nsAutoString lowercase;
|
2010-08-03 02:19:04 +04:00
|
|
|
nsContentUtils::ASCIIToLower(aAttr, lowercase);
|
2009-09-29 10:07:45 +04:00
|
|
|
|
|
|
|
mCasedAttr = do_GetAtom(aAttr);
|
|
|
|
mLowercaseAttr = do_GetAtom(lowercase);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(PRInt32 aNameSpace, nsIAtom* aLowercaseAttr,
|
|
|
|
nsIAtom* aCasedAttr, PRUint8 aFunction,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsString& aValue, bool aCaseSensitive)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(aValue),
|
|
|
|
mNext(nsnull),
|
2009-09-29 10:07:45 +04:00
|
|
|
mLowercaseAttr(aLowercaseAttr),
|
|
|
|
mCasedAttr(aCasedAttr),
|
2009-05-13 12:26:48 +04:00
|
|
|
mNameSpace(aNameSpace),
|
2006-04-26 01:48:11 +04:00
|
|
|
mFunction(aFunction),
|
2009-05-13 12:26:48 +04:00
|
|
|
mCaseSensitive(aCaseSensitive)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsAttrSelector);
|
2006-04-26 01:48:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrSelector*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsAttrSelector::Clone(bool aDeep) const
|
2006-04-26 01:48:11 +04:00
|
|
|
{
|
|
|
|
nsAttrSelector *result =
|
2009-09-29 10:07:45 +04:00
|
|
|
new nsAttrSelector(mNameSpace, mLowercaseAttr, mCasedAttr,
|
|
|
|
mFunction, mValue, mCaseSensitive);
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
if (aDeep)
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsAttrSelector, this, mNext, result, (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
|
|
|
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsAttrSelector, this, 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)
|
2009-08-01 19:53:40 +04:00
|
|
|
: mLowercaseTag(nsnull),
|
|
|
|
mCasedTag(nsnull),
|
2009-05-13 12:26:48 +04:00
|
|
|
mIDList(nsnull),
|
|
|
|
mClassList(nsnull),
|
1998-12-11 05:50:43 +03:00
|
|
|
mPseudoClassList(nsnull),
|
2009-05-13 12:26:48 +04:00
|
|
|
mAttrList(nsnull),
|
2001-03-20 14:49:20 +03:00
|
|
|
mNegations(nsnull),
|
2009-05-13 12:26:48 +04:00
|
|
|
mNext(nsnull),
|
|
|
|
mNameSpace(kNameSpaceID_Unknown),
|
2009-12-11 10:37:40 +03:00
|
|
|
mOperator(0),
|
|
|
|
mPseudoType(nsCSSPseudoElements::ePseudo_NotPseudoElement)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSSelector);
|
2012-02-23 20:19:00 +04:00
|
|
|
MOZ_STATIC_ASSERT(nsCSSPseudoElements::ePseudo_MAX < PR_INT16_MAX,
|
|
|
|
"nsCSSPseudoElements::Type values overflow mPseudoType");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 01:48:11 +04:00
|
|
|
nsCSSSelector*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsCSSSelector::Clone(bool aDeepNext, bool 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;
|
2009-08-01 19:53:40 +04:00
|
|
|
result->mLowercaseTag = mLowercaseTag;
|
|
|
|
result->mCasedTag = mCasedTag;
|
2009-05-29 04:41:27 +04:00
|
|
|
result->mOperator = mOperator;
|
2009-12-11 10:37:40 +03:00
|
|
|
result->mPseudoType = mPseudoType;
|
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.
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_ASSERTION(!mNegations || !mNegations->mNext,
|
|
|
|
"mNegations can't have non-null mNext");
|
2006-04-28 22:02:53 +04:00
|
|
|
if (aDeepNegations) {
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsCSSSelector, this, mNegations, result,
|
2011-10-17 18:59:28 +04:00
|
|
|
(true, false));
|
2006-04-28 22:02:53 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-04-28 22:02:53 +04:00
|
|
|
if (aDeepNext) {
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsCSSSelector, this, mNext, result,
|
2011-10-17 18:59:28 +04:00
|
|
|
(false, 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.
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSSelector, this, mNext);
|
2006-04-26 01:48:11 +04:00
|
|
|
}
|
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;
|
2009-08-01 19:53:40 +04:00
|
|
|
mLowercaseTag = nsnull;
|
|
|
|
mCasedTag = 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.
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_ASSERTION(!mNegations || !mNegations->mNext,
|
|
|
|
"mNegations can't have non-null mNext");
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSSelector, this, 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;
|
|
|
|
}
|
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
void nsCSSSelector::SetTag(const nsString& aTag)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2009-08-01 19:53:40 +04:00
|
|
|
if (aTag.IsEmpty()) {
|
|
|
|
mLowercaseTag = mCasedTag = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCasedTag = do_GetAtom(aTag);
|
|
|
|
|
2009-09-29 10:07:45 +04:00
|
|
|
nsAutoString lowercase;
|
2010-08-03 02:19:04 +04:00
|
|
|
nsContentUtils::ASCIIToLower(aTag, lowercase);
|
2009-09-29 10:07:45 +04:00
|
|
|
mLowercaseTag = do_GetAtom(lowercase);
|
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
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsCSSPseudoClasses::Type aType)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
2011-03-23 16:52:25 +03:00
|
|
|
AddPseudoClassInternal(new nsPseudoClassList(aType));
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsCSSPseudoClasses::Type aType,
|
2002-08-14 16:34:39 +04:00
|
|
|
const PRUnichar* aString)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2011-03-23 16:52:25 +03:00
|
|
|
AddPseudoClassInternal(new nsPseudoClassList(aType, aString));
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsCSSPseudoClasses::Type aType,
|
2008-06-03 07:17:35 +04:00
|
|
|
const PRInt32* aIntPair)
|
|
|
|
{
|
2011-03-23 16:52:25 +03:00
|
|
|
AddPseudoClassInternal(new nsPseudoClassList(aType, aIntPair));
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void nsCSSSelector::AddPseudoClass(nsCSSPseudoClasses::Type aType,
|
2010-04-24 06:59:47 +04:00
|
|
|
nsCSSSelectorList* aSelectorList)
|
|
|
|
{
|
|
|
|
// Take ownership of nsCSSSelectorList instead of copying.
|
2011-03-23 16:52:25 +03:00
|
|
|
AddPseudoClassInternal(new nsPseudoClassList(aType, aSelectorList));
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
|
2008-06-03 07:17:35 +04:00
|
|
|
void nsCSSSelector::AddPseudoClassInternal(nsPseudoClassList *aPseudoClass)
|
|
|
|
{
|
|
|
|
nsPseudoClassList** list = &mPseudoClassList;
|
|
|
|
while (nsnull != *list) {
|
|
|
|
list = &((*list)->mNext);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2008-06-03 07:17:35 +04:00
|
|
|
*list = aPseudoClass;
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsString& aValue, bool 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;
|
|
|
|
}
|
|
|
|
|
2009-01-17 06:44:21 +03:00
|
|
|
PRInt32 nsCSSSelector::CalcWeightWithoutNegations() const
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
if (nsnull != mLowercaseTag) {
|
1998-12-11 05:50:43 +03:00
|
|
|
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;
|
|
|
|
}
|
2010-04-24 06:59:47 +04:00
|
|
|
// FIXME (bug 561154): This is incorrect for :-moz-any(), which isn't
|
|
|
|
// really a pseudo-class. In order to handle :-moz-any() correctly,
|
|
|
|
// we need to compute specificity after we match, based on which
|
|
|
|
// option we matched with (and thus also need to try the
|
|
|
|
// highest-specificity options first).
|
2008-06-03 07:17:35 +04:00
|
|
|
nsPseudoClassList *plist = mPseudoClassList;
|
2002-08-14 16:34:39 +04:00
|
|
|
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;
|
|
|
|
}
|
2009-01-17 06:44:21 +03:00
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsCSSSelector::CalcWeight() const
|
|
|
|
{
|
|
|
|
// Loop over this selector and all its negations.
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
for (const nsCSSSelector *n = this; n; n = n->mNegations) {
|
|
|
|
weight += n->CalcWeightWithoutNegations();
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
return weight;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
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
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSSelector::ToString(nsAString& aString, nsCSSStyleSheet* aSheet,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAppend) const
|
2003-06-15 03:50:54 +04:00
|
|
|
{
|
2005-02-03 21:31:24 +03:00
|
|
|
if (!aAppend)
|
|
|
|
aString.Truncate();
|
2009-02-20 00:55: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
|
|
|
|
nsAutoTArray<const nsCSSSelector*, 8> stack;
|
|
|
|
for (const nsCSSSelector *s = this; s; s = s->mNext) {
|
|
|
|
stack.AppendElement(s);
|
|
|
|
}
|
2010-03-31 22:08:09 +04:00
|
|
|
|
2009-02-20 00:55:48 +03:00
|
|
|
while (!stack.IsEmpty()) {
|
|
|
|
PRUint32 index = stack.Length() - 1;
|
|
|
|
const nsCSSSelector *s = stack.ElementAt(index);
|
|
|
|
stack.RemoveElementAt(index);
|
|
|
|
|
|
|
|
s->AppendToStringWithoutCombinators(aString, aSheet);
|
|
|
|
|
|
|
|
// Append the combinator, if needed.
|
|
|
|
if (!stack.IsEmpty()) {
|
|
|
|
const nsCSSSelector *next = stack.ElementAt(index - 1);
|
2010-03-31 22:08:09 +04:00
|
|
|
PRUnichar oper = s->mOperator;
|
|
|
|
if (next->IsPseudoElement()) {
|
|
|
|
NS_ASSERTION(oper == PRUnichar('>'),
|
|
|
|
"improperly chained pseudo element");
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(oper != PRUnichar(0),
|
|
|
|
"compound selector without combinator");
|
|
|
|
|
2009-02-20 00:55:48 +03:00
|
|
|
aString.Append(PRUnichar(' '));
|
2010-03-31 22:08:09 +04:00
|
|
|
if (oper != PRUnichar(' ')) {
|
2009-02-20 00:55:48 +03:00
|
|
|
aString.Append(oper);
|
|
|
|
aString.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSSelector::AppendToStringWithoutCombinators
|
2010-05-12 00:41:47 +04:00
|
|
|
(nsAString& aString, nsCSSStyleSheet* aSheet) const
|
2009-02-20 00:55:48 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
AppendToStringWithoutCombinatorsOrNegations(aString, aSheet, false);
|
2009-02-20 00:55:48 +03:00
|
|
|
|
|
|
|
for (const nsCSSSelector* negation = mNegations; negation;
|
|
|
|
negation = negation->mNegations) {
|
|
|
|
aString.AppendLiteral(":not(");
|
|
|
|
negation->AppendToStringWithoutCombinatorsOrNegations(aString, aSheet,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2009-02-20 00:55:48 +03:00
|
|
|
aString.Append(PRUnichar(')'));
|
|
|
|
}
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:55:48 +03:00
|
|
|
void
|
|
|
|
nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations
|
2010-05-12 00:41:47 +04:00
|
|
|
(nsAString& aString, nsCSSStyleSheet* aSheet,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsNegated) const
|
2000-09-13 04:05:04 +04:00
|
|
|
{
|
2003-03-25 21:55:59 +03:00
|
|
|
nsAutoString temp;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isPseudoElement = IsPseudoElement();
|
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.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wroteNamespace = false;
|
2004-05-18 06:42:13 +04:00
|
|
|
if (!isPseudoElement || !mNext) {
|
|
|
|
// append the namespace prefix if needed
|
2008-11-12 06:36:20 +03:00
|
|
|
nsXMLNameSpaceMap *sheetNS = aSheet ? aSheet->GetNameSpaceMap() : nsnull;
|
|
|
|
|
|
|
|
// 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 then needs to be explicitly specified.
|
|
|
|
if (!sheetNS) {
|
|
|
|
NS_ASSERTION(mNameSpace == kNameSpaceID_Unknown ||
|
|
|
|
mNameSpace == kNameSpaceID_None,
|
|
|
|
"How did we get this namespace?");
|
|
|
|
if (mNameSpace == kNameSpaceID_None) {
|
|
|
|
aString.Append(PRUnichar('|'));
|
2011-10-17 18:59:28 +04:00
|
|
|
wroteNamespace = true;
|
2008-11-12 06:36:20 +03:00
|
|
|
}
|
|
|
|
} else if (sheetNS->FindNameSpaceID(nsnull) == mNameSpace) {
|
|
|
|
// We have the default namespace (possibly including the wildcard
|
|
|
|
// namespace). Do nothing.
|
|
|
|
NS_ASSERTION(mNameSpace == kNameSpaceID_Unknown ||
|
|
|
|
CanBeNamespaced(aIsNegated),
|
|
|
|
"How did we end up with this namespace?");
|
2009-02-20 00:55:48 +03:00
|
|
|
} else if (mNameSpace == kNameSpaceID_None) {
|
|
|
|
NS_ASSERTION(CanBeNamespaced(aIsNegated),
|
|
|
|
"How did we end up with this namespace?");
|
|
|
|
aString.Append(PRUnichar('|'));
|
2011-10-17 18:59:28 +04:00
|
|
|
wroteNamespace = true;
|
2008-11-12 06:36:20 +03:00
|
|
|
} else if (mNameSpace != kNameSpaceID_Unknown) {
|
|
|
|
NS_ASSERTION(CanBeNamespaced(aIsNegated),
|
|
|
|
"How did we end up with this namespace?");
|
|
|
|
nsIAtom *prefixAtom = sheetNS->FindPrefix(mNameSpace);
|
|
|
|
NS_ASSERTION(prefixAtom, "how'd we get a non-default namespace "
|
|
|
|
"without a prefix?");
|
2010-03-08 18:45:00 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(nsDependentAtomString(prefixAtom),
|
|
|
|
aString);
|
2001-01-22 07:03:48 +03:00
|
|
|
aString.Append(PRUnichar('|'));
|
2011-10-17 18:59:28 +04:00
|
|
|
wroteNamespace = true;
|
2004-05-18 06:42:13 +04:00
|
|
|
} else {
|
2008-11-12 06:36:20 +03:00
|
|
|
// A selector for an element in any namespace, while the default
|
|
|
|
// namespace is something else. :not() is special in that the default
|
|
|
|
// namespace is not implied for non-type selectors, so if this is a
|
|
|
|
// negated non-type selector we don't need to output an explicit wildcard
|
|
|
|
// namespace here, since those default to a wildcard namespace.
|
|
|
|
if (CanBeNamespaced(aIsNegated)) {
|
|
|
|
aString.AppendLiteral("*|");
|
2011-10-17 18:59:28 +04:00
|
|
|
wroteNamespace = true;
|
2004-05-18 06:42:13 +04:00
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-18 06:42:13 +04:00
|
|
|
|
2009-08-01 19:53:40 +04:00
|
|
|
if (!mLowercaseTag) {
|
2005-11-15 02:40:37 +03:00
|
|
|
// 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
|
2010-02-04 23:49:29 +03:00
|
|
|
nsAutoString tag;
|
|
|
|
(isPseudoElement ? mLowercaseTag : mCasedTag)->ToString(tag);
|
2005-11-15 02:40:37 +03:00
|
|
|
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
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
if (!nsCSSPseudoElements::IsCSS2PseudoElement(mLowercaseTag)) {
|
2005-11-15 02:40:37 +03:00
|
|
|
aString.Append(PRUnichar(':'));
|
2001-02-13 17:06:29 +03:00
|
|
|
}
|
2010-02-04 23:49:29 +03:00
|
|
|
// This should not be escaped since (a) the pseudo-element string
|
|
|
|
// has a ":" that can't be escaped and (b) all pseudo-elements at
|
|
|
|
// this point are known, and therefore we know they don't need
|
|
|
|
// escaping.
|
|
|
|
aString.Append(tag);
|
|
|
|
} else {
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(tag, aString);
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
2005-11-15 02:40:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Append the id, if there is one
|
|
|
|
if (mIDList) {
|
|
|
|
nsAtomList* list = mIDList;
|
|
|
|
while (list != nsnull) {
|
|
|
|
list->mAtom->ToString(temp);
|
|
|
|
aString.Append(PRUnichar('#'));
|
2010-02-04 23:49:29 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(temp, aString);
|
2005-11-15 02:40:37 +03:00
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append each class in the linked list
|
|
|
|
if (mClassList) {
|
2011-03-24 00:25:42 +03:00
|
|
|
if (isPseudoElement) {
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSAnonBoxes::IsTreePseudoElement(mLowercaseTag),
|
|
|
|
"must be tree pseudo-element");
|
|
|
|
|
|
|
|
aString.Append(PRUnichar('('));
|
|
|
|
for (nsAtomList* list = mClassList; list; list = list->mNext) {
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(nsDependentAtomString(list->mAtom), aString);
|
|
|
|
aString.Append(PRUnichar(','));
|
|
|
|
}
|
|
|
|
// replace the final comma with a close-paren
|
|
|
|
aString.Replace(aString.Length() - 1, 1, PRUnichar(')'));
|
|
|
|
#else
|
|
|
|
NS_ERROR("Can't happen");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
nsAtomList* list = mClassList;
|
|
|
|
while (list != nsnull) {
|
|
|
|
list->mAtom->ToString(temp);
|
|
|
|
aString.Append(PRUnichar('.'));
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(temp, aString);
|
|
|
|
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
|
2009-10-20 21:27:47 +04:00
|
|
|
if (list->mNameSpace == kNameSpaceID_Unknown) {
|
|
|
|
aString.Append(PRUnichar('*'));
|
|
|
|
aString.Append(PRUnichar('|'));
|
|
|
|
} else if (list->mNameSpace != kNameSpaceID_None) {
|
2007-04-12 20:23:43 +04:00
|
|
|
if (aSheet) {
|
|
|
|
nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
|
|
|
|
nsIAtom *prefixAtom = sheetNS->FindPrefix(list->mNameSpace);
|
2009-10-20 21:27:47 +04:00
|
|
|
// Default namespaces don't apply to attribute selectors, so
|
|
|
|
// we must have a useful prefix.
|
|
|
|
NS_ASSERTION(prefixAtom,
|
|
|
|
"How did we end up with a namespace if the prefix "
|
|
|
|
"is unknown?");
|
|
|
|
nsAutoString prefix;
|
|
|
|
prefixAtom->ToString(prefix);
|
2010-02-04 23:49:29 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(prefix, aString);
|
2009-10-20 21:27:47 +04:00
|
|
|
aString.Append(PRUnichar('|'));
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Append the attribute name
|
2009-09-29 10:07:45 +04:00
|
|
|
list->mCasedAttr->ToString(temp);
|
2010-02-04 23:49:29 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(temp, aString);
|
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
|
2009-03-06 07:05:00 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(list->mValue, aString);
|
2005-03-26 05:36:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2011-03-24 00:25:42 +03:00
|
|
|
for (nsPseudoClassList* list = mPseudoClassList; list; list = list->mNext) {
|
|
|
|
nsCSSPseudoClasses::PseudoTypeToString(list->mType, temp);
|
|
|
|
// This should not be escaped since (a) the pseudo-class string
|
|
|
|
// has a ":" that can't be escaped and (b) all pseudo-classes at
|
|
|
|
// this point are known, and therefore we know they don't need
|
|
|
|
// escaping.
|
|
|
|
aString.Append(temp);
|
|
|
|
if (list->u.mMemory) {
|
2009-10-08 07:22:42 +04:00
|
|
|
aString.Append(PRUnichar('('));
|
2011-03-24 00:25:42 +03:00
|
|
|
if (nsCSSPseudoClasses::HasStringArg(list->mType)) {
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(
|
|
|
|
nsDependentString(list->u.mString), aString);
|
|
|
|
} else if (nsCSSPseudoClasses::HasNthPairArg(list->mType)) {
|
|
|
|
PRInt32 a = list->u.mNumbers[0],
|
|
|
|
b = list->u.mNumbers[1];
|
|
|
|
temp.Truncate();
|
|
|
|
if (a != 0) {
|
|
|
|
if (a == -1) {
|
|
|
|
temp.Append(PRUnichar('-'));
|
|
|
|
} else if (a != 1) {
|
|
|
|
temp.AppendInt(a);
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
2011-03-24 00:25:42 +03:00
|
|
|
temp.Append(PRUnichar('n'));
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
2011-03-24 00:25:42 +03:00
|
|
|
if (b != 0 || a == 0) {
|
|
|
|
if (b >= 0 && a != 0) // check a != 0 for whether we printed above
|
|
|
|
temp.Append(PRUnichar('+'));
|
|
|
|
temp.AppendInt(b);
|
|
|
|
}
|
|
|
|
aString.Append(temp);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(list->mType),
|
|
|
|
"unexpected pseudo-class");
|
|
|
|
nsString tmp;
|
|
|
|
list->u.mSelectors->ToString(tmp, aSheet);
|
|
|
|
aString.Append(tmp);
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
2011-03-24 00:25:42 +03:00
|
|
|
aString.Append(PRUnichar(')'));
|
2001-01-22 07:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
2000-09-13 04:05:04 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsCSSSelector::CanBeNamespaced(bool aIsNegated) const
|
2008-11-12 06:36:20 +03:00
|
|
|
{
|
|
|
|
return !aIsNegated ||
|
|
|
|
(!mIDList && !mClassList && !mPseudoClassList && !mAttrList);
|
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
nsCSSSelector::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSSelector* s = this;
|
|
|
|
while (s) {
|
|
|
|
n += aMallocSizeOf(s);
|
|
|
|
|
|
|
|
#define MEASURE(x) n += x ? x->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
|
|
|
|
MEASURE(s->mIDList);
|
|
|
|
MEASURE(s->mClassList);
|
|
|
|
MEASURE(s->mPseudoClassList);
|
|
|
|
MEASURE(s->mNegations);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - s->mAttrList
|
|
|
|
//
|
|
|
|
// The following members aren't measured:
|
|
|
|
// - s->mLowercaseTag, because it's an atom and therefore shared
|
|
|
|
// - s->mCasedTag, because it's an atom and therefore shared
|
|
|
|
|
|
|
|
s = s->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
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);
|
2008-10-17 12:13:16 +04:00
|
|
|
delete mSelectors;
|
|
|
|
NS_CSS_DELETE_LIST_MEMBER(nsCSSSelectorList, this, mNext);
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
|
2010-03-31 22:08:09 +04:00
|
|
|
nsCSSSelector*
|
|
|
|
nsCSSSelectorList::AddSelector(PRUnichar aOperator)
|
|
|
|
{
|
|
|
|
nsCSSSelector* newSel = new nsCSSSelector();
|
|
|
|
|
|
|
|
if (mSelectors) {
|
|
|
|
NS_ASSERTION(aOperator != PRUnichar(0), "chaining without combinator");
|
|
|
|
mSelectors->SetOperator(aOperator);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aOperator == PRUnichar(0), "combinator without chaining");
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
2010-03-31 22:08:09 +04:00
|
|
|
|
|
|
|
newSel->mNext = mSelectors;
|
|
|
|
mSelectors = newSel;
|
|
|
|
return newSel;
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSSelectorList::ToString(nsAString& aResult, nsCSSStyleSheet* aSheet)
|
2003-06-15 03:50:54 +04:00
|
|
|
{
|
2005-02-03 21:31:24 +03:00
|
|
|
aResult.Truncate();
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList *p = this;
|
|
|
|
for (;;) {
|
2011-10-17 18:59:28 +04:00
|
|
|
p->mSelectors->ToString(aResult, aSheet, 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*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsCSSSelectorList::Clone(bool aDeep) const
|
2006-04-26 01:48:11 +04:00
|
|
|
{
|
|
|
|
nsCSSSelectorList *result = new nsCSSSelectorList();
|
|
|
|
result->mWeight = mWeight;
|
|
|
|
NS_IF_CLONE(mSelectors);
|
|
|
|
|
|
|
|
if (aDeep) {
|
2008-10-17 12:13:16 +04:00
|
|
|
NS_CSS_CLONE_LIST_MEMBER(nsCSSSelectorList, this, mNext, result,
|
2011-10-17 18:59:28 +04:00
|
|
|
(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
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
|
|
|
nsCSSSelectorList::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
const nsCSSSelectorList* s = this;
|
|
|
|
while (s) {
|
|
|
|
n += aMallocSizeOf(s);
|
|
|
|
n += s->mSelectors ? s->mSelectors->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
s = s->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:48:26 +03:00
|
|
|
// -- ImportantRule ----------------------------------
|
1998-09-11 06:07:05 +04:00
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2011-03-11 05:48:26 +03:00
|
|
|
|
|
|
|
ImportantRule::ImportantRule(Declaration* aDeclaration)
|
2010-07-23 22:00:52 +04:00
|
|
|
: mDeclaration(aDeclaration)
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:48:26 +03:00
|
|
|
ImportantRule::~ImportantRule()
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:48:26 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(ImportantRule, nsIStyleRule)
|
1998-09-11 06:07:05 +04:00
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-11 05:48:26 +03:00
|
|
|
ImportantRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2010-07-23 22:00:52 +04:00
|
|
|
mDeclaration->MapImportantRuleInfoInto(aRuleData);
|
1998-09-11 06:07:05 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-11 05:48:26 +03:00
|
|
|
ImportantRule::List(FILE* out, PRInt32 aIndent) const
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
fprintf(out, "! Important declaration=%p\n",
|
|
|
|
static_cast<void*>(mDeclaration));
|
1998-09-11 06:07:05 +04:00
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2011-03-11 05:48:26 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
// --------------------------------------------------------
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class DOMCSSStyleRule;
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
|
|
|
{
|
|
|
|
public:
|
2011-03-11 05:48:57 +03:00
|
|
|
DOMCSSDeclarationImpl(css::StyleRule *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);
|
2009-07-13 15:14:57 +04:00
|
|
|
void DropReference(void);
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual css::Declaration* GetCSSDeclaration(bool aAllocate);
|
2010-07-23 22:00:47 +04:00
|
|
|
virtual nsresult SetCSSDeclaration(css::Declaration* aDecl);
|
2011-04-28 00:53:49 +04:00
|
|
|
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
|
2009-12-11 19:13:19 +03:00
|
|
|
virtual nsIDocument* DocToUpdate();
|
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
|
2011-03-11 05:47:52 +03:00
|
|
|
// |DOMCSSStyleRule|.
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
|
2009-10-06 03:16:22 +04:00
|
|
|
virtual nsINode *GetParentObject()
|
2009-07-13 15:14:57 +04:00
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
friend class css::DOMCSSStyleRule;
|
2003-06-24 09:40:37 +04:00
|
|
|
|
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.
|
2011-03-11 05:48:57 +03:00
|
|
|
css::StyleRule *mRule;
|
2003-06-24 09:40:37 +04:00
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
inline css::DOMCSSStyleRule* DomRule();
|
2003-06-24 09:40:37 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// NOT TO BE IMPLEMENTED
|
|
|
|
// This object cannot be allocated on its own. It must be a member of
|
2011-03-11 05:47:52 +03:00
|
|
|
// DOMCSSStyleRule.
|
2003-06-24 09:40:37 +04:00
|
|
|
void* operator new(size_t size) CPP_THROW_NEW;
|
|
|
|
};
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
class DOMCSSStyleRule : public nsICSSStyleRuleDOMWrapper
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
public:
|
2011-03-11 05:48:57 +03:00
|
|
|
DOMCSSStyleRule(StyleRule *aRule);
|
2011-03-11 05:47:52 +03:00
|
|
|
virtual ~DOMCSSStyleRule();
|
2003-06-24 09:40:37 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMCSSRULE
|
|
|
|
NS_DECL_NSIDOMCSSSTYLERULE
|
|
|
|
|
|
|
|
// nsICSSStyleRuleDOMWrapper
|
2011-03-11 05:48:57 +03:00
|
|
|
NS_IMETHOD GetCSSStyleRule(StyleRule **aResult);
|
2003-06-24 09:40:37 +04:00
|
|
|
|
|
|
|
DOMCSSDeclarationImpl* DOMDeclaration() { return &mDOMDeclaration; }
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
friend class ::DOMCSSDeclarationImpl;
|
2003-06-24 09:40:37 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
DOMCSSDeclarationImpl mDOMDeclaration;
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
StyleRule* Rule() {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mDOMDeclaration.mRule;
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *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
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
inline css::DOMCSSStyleRule* DOMCSSDeclarationImpl::DomRule()
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
2011-03-11 05:47:52 +03:00
|
|
|
return reinterpret_cast<css::DOMCSSStyleRule*>
|
2007-07-08 11:08:04 +04:00
|
|
|
(reinterpret_cast<char*>(this) -
|
2011-03-11 05:47:52 +03:00
|
|
|
offsetof(css::DOMCSSStyleRule, mDOMDeclaration));
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
css::Declaration*
|
2011-09-29 10:19:26 +04:00
|
|
|
DOMCSSDeclarationImpl::GetCSSDeclaration(bool aAllocate)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2002-10-09 05:59:43 +04:00
|
|
|
if (mRule) {
|
2010-07-23 22:00:34 +04:00
|
|
|
return mRule->GetDeclaration();
|
|
|
|
} else {
|
|
|
|
return nsnull;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 00:53:49 +04:00
|
|
|
void
|
|
|
|
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
|
2001-10-19 17:50:30 +04:00
|
|
|
{
|
2011-04-28 00:53:49 +04:00
|
|
|
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
|
2001-10-19 17:50:30 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-04-08 10:36:09 +04:00
|
|
|
NS_IF_ADDREF(*aParent = mRule->GetDOMRule());
|
|
|
|
return NS_OK;
|
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
|
2010-07-23 22:00:47 +04:00
|
|
|
DOMCSSDeclarationImpl::SetCSSDeclaration(css::Declaration* aDecl)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mRule,
|
|
|
|
"can only be called when |GetCSSDeclaration| returned a declaration");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> owningDoc;
|
2010-07-18 18:39:20 +04:00
|
|
|
nsCOMPtr<nsIStyleSheet> sheet = mRule->GetStyleSheet();
|
2003-06-18 05:59:57 +04:00
|
|
|
if (sheet) {
|
2010-05-13 00:18:47 +04:00
|
|
|
owningDoc = sheet->GetOwningDocument();
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(owningDoc, UPDATE_STYLE, true);
|
2003-06-18 05:59:57 +04:00
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
nsRefPtr<css::StyleRule> oldRule = mRule;
|
2011-10-17 18:59:28 +04:00
|
|
|
mRule = oldRule->DeclarationChanged(aDecl, 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;
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
nsIDocument*
|
|
|
|
DOMCSSDeclarationImpl::DocToUpdate()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
// needs to be outside the namespace
|
|
|
|
DOMCI_DATA(CSSStyleRule, css::DOMCSSStyleRule)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
DOMCSSStyleRule::DOMCSSStyleRule(StyleRule* aRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
: mDOMDeclaration(aRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
DOMCSSStyleRule::~DOMCSSStyleRule()
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMCSSStyleRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMPL_ADDREF(DOMCSSStyleRule)
|
|
|
|
NS_IMPL_RELEASE(DOMCSSStyleRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetType(PRUint16* aType)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::STYLE_RULE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetCssText(nsAString& aCssText)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
aCssText.Truncate();
|
2011-03-11 05:50:20 +03:00
|
|
|
} else {
|
|
|
|
Rule()->GetCssText(aCssText);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
2011-03-11 05:50:20 +03:00
|
|
|
return NS_OK;
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::SetCssText(const nsAString& aCssText)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
2011-03-11 05:50:20 +03:00
|
|
|
if (Rule()) {
|
|
|
|
Rule()->SetCssText(aCssText);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
2011-03-11 05:50:20 +03:00
|
|
|
return NS_OK;
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule()->GetParentStyleSheet(aSheet);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule()->GetParentRule(aParentRule);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetSelectorText(nsAString& aSelectorText)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
if (!Rule()) {
|
|
|
|
aSelectorText.Truncate();
|
2011-03-11 05:50:20 +03:00
|
|
|
} else {
|
|
|
|
Rule()->GetSelectorText(aSelectorText);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
2011-03-11 05:50:20 +03:00
|
|
|
return NS_OK;
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::SetSelectorText(const nsAString& aSelectorText)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
2011-03-11 05:50:20 +03:00
|
|
|
if (Rule()) {
|
|
|
|
Rule()->SetSelectorText(aSelectorText);
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
2011-03-11 05:50:20 +03:00
|
|
|
return NS_OK;
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMCSSStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
*aStyle = &mDOMDeclaration;
|
|
|
|
NS_ADDREF(*aStyle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-11 05:48:57 +03:00
|
|
|
DOMCSSStyleRule::GetCSSStyleRule(StyleRule **aResult)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
*aResult = Rule();
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
// -- StyleRule ------------------------------------
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
StyleRule::StyleRule(nsCSSSelectorList* aSelector,
|
|
|
|
Declaration* aDeclaration)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(),
|
2003-06-18 05:59:57 +04:00
|
|
|
mSelector(aSelector),
|
2010-06-29 02:49:35 +04:00
|
|
|
mDeclaration(aDeclaration),
|
2003-06-15 03:50:54 +04:00
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(nsnull),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasMatched(false)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2011-03-23 05:56:47 +03:00
|
|
|
NS_PRECONDITION(aDeclaration, "must have a declaration");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
// for |Clone|
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::StyleRule(const StyleRule& aCopy)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(aCopy),
|
2003-06-15 03:50:54 +04:00
|
|
|
mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nsnull),
|
2011-03-11 05:47:08 +03:00
|
|
|
mDeclaration(new Declaration(*aCopy.mDeclaration)),
|
1999-06-03 05:57:13 +04:00
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(nsnull),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(aCopy.mLineNumber),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasMatched(false)
|
1999-06-03 05:57:13 +04:00
|
|
|
{
|
|
|
|
// rest is constructed lazily on existing data
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:47 +04:00
|
|
|
// for |SetCSSDeclaration|
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::StyleRule(StyleRule& aCopy,
|
|
|
|
Declaration* aDeclaration)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(aCopy),
|
2003-06-18 05:59:57 +04:00
|
|
|
mSelector(aCopy.mSelector),
|
|
|
|
mDeclaration(aDeclaration),
|
|
|
|
mImportantRule(nsnull),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(aCopy.mDOMRule),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(aCopy.mLineNumber),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasMatched(false)
|
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
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
// Similarly for the selector.
|
2003-06-18 05:59:57 +04:00
|
|
|
aCopy.mSelector = nsnull;
|
2010-07-23 22:00:52 +04:00
|
|
|
|
|
|
|
// We are probably replacing the old declaration with |aDeclaration|
|
|
|
|
// instead of taking ownership of the old declaration; only null out
|
|
|
|
// aCopy.mDeclaration if we are taking ownership.
|
|
|
|
if (mDeclaration == aCopy.mDeclaration) {
|
|
|
|
// This should only ever happen if the declaration was modifiable.
|
|
|
|
mDeclaration->AssertMutable();
|
|
|
|
aCopy.mDeclaration = nsnull;
|
|
|
|
}
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::~StyleRule()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2010-07-23 22:00:52 +04:00
|
|
|
delete mSelector;
|
|
|
|
delete mDeclaration;
|
|
|
|
NS_IF_RELEASE(mImportantRule);
|
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
|
|
|
}
|
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
// QueryInterface implementation for StyleRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(StyleRule)
|
2011-03-11 05:48:57 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(mozilla::css::StyleRule))) {
|
|
|
|
*aInstancePtr = this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
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
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
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
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(StyleRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(StyleRule, Rule)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2011-03-11 05:50:12 +03:00
|
|
|
void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::RuleMatched()
|
2009-12-11 19:13:19 +03:00
|
|
|
{
|
2010-08-03 02:40:35 +04:00
|
|
|
if (!mWasMatched) {
|
2010-07-23 22:00:52 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mImportantRule, "should not have important rule yet");
|
2009-12-11 19:13:20 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasMatched = true;
|
2010-07-23 22:00:52 +04:00
|
|
|
mDeclaration->SetImmutable();
|
|
|
|
if (mDeclaration->HasImportantData()) {
|
2011-03-11 05:48:26 +03:00
|
|
|
NS_ADDREF(mImportantRule = new ImportantRule(mDeclaration));
|
2010-07-23 22:00:52 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::GetType() const
|
1999-06-10 09:28:32 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::STYLE_RULE;
|
1999-06-10 09:28:32 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::Clone() const
|
1999-06-03 05:57:13 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new StyleRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 10:36:09 +04:00
|
|
|
/* virtual */ nsIDOMCSSRule*
|
|
|
|
StyleRule::GetDOMRule()
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
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.
|
2008-10-22 18:31:14 +04:00
|
|
|
return nsnull;
|
2003-09-13 23:18:52 +04:00
|
|
|
}
|
2003-06-24 09:40:37 +04:00
|
|
|
if (!mDOMRule) {
|
2011-03-11 05:47:52 +03:00
|
|
|
mDOMRule = new DOMCSSStyleRule(this);
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_ADDREF(mDOMRule);
|
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
return mDOMRule;
|
2003-06-24 09:40:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-11 05:48:57 +03:00
|
|
|
/* virtual */ already_AddRefed<StyleRule>
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::DeclarationChanged(Declaration* aDecl,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHandleContainer)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule* clone = new StyleRule(*this, aDecl);
|
2003-06-18 05:59:57 +04:00
|
|
|
if (!clone) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(clone); // for return
|
|
|
|
|
2003-07-01 01:31:25 +04:00
|
|
|
if (aHandleContainer) {
|
2003-06-18 05:59:57 +04:00
|
|
|
if (mParentRule) {
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->ReplaceRuleInGroup(mParentRule, this, clone);
|
|
|
|
} else {
|
|
|
|
mParentRule->ReplaceStyleRule(this, clone);
|
|
|
|
}
|
|
|
|
} else if (mSheet) {
|
2003-06-18 05:59:57 +04:00
|
|
|
mSheet->ReplaceStyleRule(this, clone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
1999-06-03 05:57:13 +04:00
|
|
|
}
|
|
|
|
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2010-08-03 02:40:35 +04:00
|
|
|
NS_ABORT_IF_FALSE(mWasMatched,
|
2011-03-11 05:48:57 +03:00
|
|
|
"somebody forgot to call css::StyleRule::RuleMatched");
|
2010-07-23 22:00:52 +04:00
|
|
|
mDeclaration->MapNormalRuleInfoInto(aRuleData);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::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);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2011-03-11 05:50:20 +03:00
|
|
|
void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::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
|
|
|
}
|
|
|
|
|
2011-03-11 05:50:20 +03:00
|
|
|
void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::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
|
|
|
}
|
|
|
|
|
2011-03-11 05:50:20 +03:00
|
|
|
void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::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
|
|
|
}
|
|
|
|
|
2011-03-11 05:50:20 +03:00
|
|
|
void
|
2011-03-11 05:47:08 +03:00
|
|
|
StyleRule::SetSelectorText(const nsAString& aSelectorText)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2011-03-11 05:50:20 +03:00
|
|
|
// XXX TBI - get a parser and re-parse the selectors,
|
1998-12-11 05:50:43 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
/* virtual */ size_t
|
|
|
|
StyleRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mSelector ? mSelector->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
n += mDeclaration ? mDeclaration->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mImportantRule;
|
|
|
|
// - mDOMRule;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-11 05:47:08 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|