2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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"
|
2013-06-30 20:26:39 +04:00
|
|
|
|
|
|
|
#include "mozilla/MemoryReporting.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"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
2005-01-30 21:01:57 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2003-06-24 09:40:37 +04:00
|
|
|
#include "nsICSSStyleRuleDOMWrapper.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2005-02-19 03:10:38 +03:00
|
|
|
#include "nsXMLNameSpaceMap.h"
|
2003-07-04 05:33:10 +04:00
|
|
|
#include "nsCSSPseudoElements.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"
|
2012-07-20 20:42:08 +04:00
|
|
|
#include "nsDOMClassInfoID.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
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.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
|
|
|
|
2013-03-03 04:31:48 +04:00
|
|
|
class nsIDOMCSSStyleDeclaration;
|
|
|
|
class nsIDOMCSSStyleSheet;
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2013-11-15 06:42:57 +04:00
|
|
|
using namespace mozilla;
|
2010-06-29 02:49:35 +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; \
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; \
|
2006-04-26 01:48:11 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define NS_IF_DELETE(ptr) \
|
|
|
|
PR_BEGIN_MACRO \
|
2008-10-17 12:13:16 +04:00
|
|
|
delete ptr; \
|
2012-07-30 18:20:58 +04:00
|
|
|
ptr = nullptr; \
|
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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mAtom(nullptr),
|
|
|
|
mNext(nullptr)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
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)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-04-26 01:48:11 +04:00
|
|
|
|
|
|
|
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
|
2013-06-23 16:03:39 +04:00
|
|
|
nsAtomList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
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);
|
2012-07-30 18:20:58 +04:00
|
|
|
u.mMemory = nullptr;
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
nsPseudoClassList::nsPseudoClassList(nsCSSPseudoClasses::Type aType,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aString)
|
2011-03-23 16:52:25 +03:00
|
|
|
: mType(aType),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
2002-08-14 16:34:39 +04:00
|
|
|
{
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t* aIntPair)
|
2011-03-23 16:52:25 +03:00
|
|
|
: mType(aType),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
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 =
|
2012-08-22 19:56:38 +04:00
|
|
|
static_cast<int32_t*>(nsMemory::Clone(aIntPair, sizeof(int32_t) * 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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
2010-04-24 06:59:47 +04:00
|
|
|
{
|
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
|
2013-06-23 16:03:39 +04:00
|
|
|
nsPseudoClassList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(int32_t aNameSpace, const nsString& aAttr)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr),
|
|
|
|
mLowercaseAttr(nullptr),
|
|
|
|
mCasedAttr(nullptr),
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(int32_t aNameSpace, const nsString& aAttr, uint8_t aFunction,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsString& aValue, bool aCaseSensitive)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(aValue),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr),
|
|
|
|
mLowercaseAttr(nullptr),
|
|
|
|
mCasedAttr(nullptr),
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAttrSelector::nsAttrSelector(int32_t aNameSpace, nsIAtom* aLowercaseAttr,
|
|
|
|
nsIAtom* aCasedAttr, uint8_t aFunction,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsString& aValue, bool aCaseSensitive)
|
2009-05-13 12:26:48 +04:00
|
|
|
: mValue(aValue),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr),
|
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)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mLowercaseTag(nullptr),
|
|
|
|
mCasedTag(nullptr),
|
|
|
|
mIDList(nullptr),
|
|
|
|
mClassList(nullptr),
|
|
|
|
mPseudoClassList(nullptr),
|
|
|
|
mAttrList(nullptr),
|
|
|
|
mNegations(nullptr),
|
|
|
|
mNext(nullptr),
|
2009-05-13 12:26:48 +04:00
|
|
|
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);
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(nsCSSPseudoElements::ePseudo_MAX < 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)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
mLowercaseTag = nullptr;
|
|
|
|
mCasedTag = nullptr;
|
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);
|
2014-01-04 19:02:17 +04:00
|
|
|
mOperator = char16_t(0);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsCSSSelector::SetNameSpace(int32_t aNameSpace)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
|
|
|
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()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mLowercaseTag = mCasedTag = nullptr;
|
2009-08-01 19:53:40 +04:00
|
|
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != *list) {
|
2001-02-13 17:06:29 +03:00
|
|
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != *list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
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,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* 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,
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t* aIntPair)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != *list) {
|
2008-06-03 07:17:35 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsCSSSelector::AddAttribute(int32_t 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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != *list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
list = &((*list)->mNext);
|
|
|
|
}
|
1999-06-10 09:28:32 +04:00
|
|
|
*list = new nsAttrSelector(aNameSpace, aAttr);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsCSSSelector::AddAttribute(int32_t aNameSpace, const nsString& aAttr, uint8_t 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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != *list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
void nsCSSSelector::SetOperator(char16_t aOperator)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
|
|
|
mOperator = aOperator;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsCSSSelector::CalcWeightWithoutNegations() const
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t weight = 0;
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2013-11-28 10:46:38 +04:00
|
|
|
MOZ_ASSERT(!IsPseudoElement() ||
|
|
|
|
mPseudoType >= nsCSSPseudoElements::ePseudo_PseudoElementCount ||
|
|
|
|
(!mIDList && !mClassList && !mAttrList),
|
|
|
|
"if pseudo-elements can have ID, class or attribute selectors "
|
|
|
|
"after them, specificity calculation must be updated");
|
|
|
|
|
|
|
|
if (nullptr != mCasedTag) {
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != 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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != 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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != attr) {
|
1998-12-11 05:50:43 +03:00
|
|
|
weight += 0x000100;
|
|
|
|
attr = attr->mNext;
|
|
|
|
}
|
2009-01-17 06:44:21 +03:00
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsCSSSelector::CalcWeight() const
|
2009-01-17 06:44:21 +03:00
|
|
|
{
|
|
|
|
// Loop over this selector and all its negations.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t weight = 0;
|
2009-01-17 06:44:21 +03:00
|
|
|
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()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t index = stack.Length() - 1;
|
2009-02-20 00:55:48 +03:00
|
|
|
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);
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t oper = s->mOperator;
|
2010-03-31 22:08:09 +04:00
|
|
|
if (next->IsPseudoElement()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(oper == char16_t(':'),
|
2010-03-31 22:08:09 +04:00
|
|
|
"improperly chained pseudo element");
|
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(oper != char16_t(0),
|
2010-03-31 22:08:09 +04:00
|
|
|
"compound selector without combinator");
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(' '));
|
|
|
|
if (oper != char16_t(' ')) {
|
2009-02-20 00:55:48 +03:00
|
|
|
aString.Append(oper);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(' '));
|
2009-02-20 00:55:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(')'));
|
2009-02-20 00:55:48 +03:00
|
|
|
}
|
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
|
2012-07-30 18:20:58 +04:00
|
|
|
nsXMLNameSpaceMap *sheetNS = aSheet ? aSheet->GetNameSpaceMap() : nullptr;
|
2008-11-12 06:36:20 +03: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 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) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('|'));
|
2011-10-17 18:59:28 +04:00
|
|
|
wroteNamespace = true;
|
2008-11-12 06:36:20 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
} else if (sheetNS->FindNameSpaceID(nullptr) == mNameSpace) {
|
2008-11-12 06:36:20 +03:00
|
|
|
// 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?");
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('|'));
|
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);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('|'));
|
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))) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('*'));
|
2005-11-15 02:40:37 +03:00
|
|
|
}
|
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?
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('*'));
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
2009-08-01 19:53:40 +04:00
|
|
|
if (!nsCSSPseudoElements::IsCSS2PseudoElement(mLowercaseTag)) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(':'));
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (list != nullptr) {
|
2005-11-15 02:40:37 +03:00
|
|
|
list->mAtom->ToString(temp);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('#'));
|
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");
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('('));
|
2011-03-24 00:25:42 +03:00
|
|
|
for (nsAtomList* list = mClassList; list; list = list->mNext) {
|
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(nsDependentAtomString(list->mAtom), aString);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(','));
|
2011-03-24 00:25:42 +03:00
|
|
|
}
|
|
|
|
// replace the final comma with a close-paren
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Replace(aString.Length() - 1, 1, char16_t(')'));
|
2011-03-24 00:25:42 +03:00
|
|
|
#else
|
|
|
|
NS_ERROR("Can't happen");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
nsAtomList* list = mClassList;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (list != nullptr) {
|
2011-03-24 00:25:42 +03:00
|
|
|
list->mAtom->ToString(temp);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('.'));
|
2011-03-24 00:25:42 +03:00
|
|
|
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;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (list != nullptr) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('['));
|
2001-01-22 07:03:48 +03:00
|
|
|
// Append the namespace prefix
|
2009-10-20 21:27:47 +04:00
|
|
|
if (list->mNameSpace == kNameSpaceID_Unknown) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('*'));
|
|
|
|
aString.Append(char16_t('|'));
|
2009-10-20 21:27:47 +04:00
|
|
|
} 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);
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('|'));
|
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)
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('~'));
|
2005-03-26 05:36:15 +03:00
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH)
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('|'));
|
2005-03-26 05:36:15 +03:00
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_BEGINSMATCH)
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('^'));
|
2005-03-26 05:36:15 +03:00
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_ENDSMATCH)
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('$'));
|
2005-03-26 05:36:15 +03:00
|
|
|
else if (list->mFunction == NS_ATTR_FUNC_CONTAINSMATCH)
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('*'));
|
2005-03-26 05:36:15 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('='));
|
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
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(']'));
|
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) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t('('));
|
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)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t a = list->u.mNumbers[0],
|
2011-03-24 00:25:42 +03:00
|
|
|
b = list->u.mNumbers[1];
|
|
|
|
temp.Truncate();
|
|
|
|
if (a != 0) {
|
|
|
|
if (a == -1) {
|
2014-01-04 19:02:17 +04:00
|
|
|
temp.Append(char16_t('-'));
|
2011-03-24 00:25:42 +03:00
|
|
|
} else if (a != 1) {
|
|
|
|
temp.AppendInt(a);
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
temp.Append(char16_t('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
|
2014-01-04 19:02:17 +04:00
|
|
|
temp.Append(char16_t('+'));
|
2011-03-24 00:25:42 +03:00
|
|
|
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
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aString.Append(char16_t(')'));
|
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
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSSelector::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
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)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mSelectors(nullptr),
|
2005-12-24 00:04:35 +03:00
|
|
|
mWeight(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext(nullptr)
|
2003-06-15 03:50:54 +04:00
|
|
|
{
|
|
|
|
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*
|
2014-01-04 19:02:17 +04:00
|
|
|
nsCSSSelectorList::AddSelector(char16_t aOperator)
|
2010-03-31 22:08:09 +04:00
|
|
|
{
|
|
|
|
nsCSSSelector* newSel = new nsCSSSelector();
|
|
|
|
|
|
|
|
if (mSelectors) {
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(aOperator != char16_t(0), "chaining without combinator");
|
2010-03-31 22:08:09 +04:00
|
|
|
mSelectors->SetOperator(aOperator);
|
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(aOperator == char16_t(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
|
2013-06-23 16:03:39 +04:00
|
|
|
nsCSSSelectorList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
ImportantRule::List(FILE* out, int32_t aIndent) const
|
1998-09-11 06:07:05 +04:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
1998-09-11 06:07:05 +04:00
|
|
|
|
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
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) MOZ_OVERRIDE;
|
2009-07-13 15:14:57 +04:00
|
|
|
void DropReference(void);
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual css::Declaration* GetCSSDeclaration(bool aAllocate) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult SetCSSDeclaration(css::Declaration* aDecl) MOZ_OVERRIDE;
|
|
|
|
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) MOZ_OVERRIDE;
|
|
|
|
virtual nsIDocument* DocToUpdate() MOZ_OVERRIDE;
|
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
|
2012-08-06 06:16:30 +04:00
|
|
|
// |DOMCSSStyleRule|. Also, we need to forward QI for cycle
|
|
|
|
// collection things to DOMCSSStyleRule.
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2003-06-24 09:40:37 +04:00
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsINode *GetParentObject() MOZ_OVERRIDE
|
2009-07-13 15:14:57 +04:00
|
|
|
{
|
2012-08-06 06:14:52 +04:00
|
|
|
return mRule ? mRule->GetDocument() : nullptr;
|
2009-07-13 15:14:57 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMCSSStyleRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
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())
|
|
|
|
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMCSSDeclarationImpl)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
// We forward the cycle collection interfaces to DomRule(), which is
|
|
|
|
// never null (in fact, we're part of that object!)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
|
|
|
|
return DomRule()->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
2012-08-06 09:24:43 +04:00
|
|
|
else
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration)
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
void
|
1999-06-10 09:28:32 +04:00
|
|
|
DOMCSSDeclarationImpl::DropReference(void)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mRule = nullptr;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
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 {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
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) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aParent = nullptr;
|
2003-06-24 09:40:37 +04:00
|
|
|
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");
|
2012-07-30 18:20:58 +04:00
|
|
|
mRule = nullptr;
|
2003-06-24 09:40:37 +04:00
|
|
|
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()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(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
|
|
|
|
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCSSStyleRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCSSStyleRule)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMCSSStyleRule)
|
|
|
|
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMCSSStyleRule)
|
|
|
|
// Trace the wrapper for our declaration. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
2013-05-27 15:50:49 +04:00
|
|
|
tmp->DOMDeclaration()->TraceWrapper(aCallbacks, aClosure);
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMCSSStyleRule)
|
|
|
|
// Unlink the wrapper for our declaraton. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
2013-08-02 11:04:01 +04:00
|
|
|
tmp->DOMDeclaration()->ReleaseWrapper(static_cast<nsISupports*>(p));
|
2012-08-06 06:16:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMCSSStyleRule)
|
|
|
|
// Just NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS here: that will call
|
|
|
|
// into our Trace hook, where we do the right thing with declarations
|
|
|
|
// already.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2003-06-24 09:40:37 +04:00
|
|
|
|
2011-03-11 05:47:52 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
DOMCSSStyleRule::GetType(uint16_t* 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()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aSheet = nullptr;
|
2003-06-24 09:40:37 +04:00
|
|
|
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()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aParentRule = nullptr;
|
2003-06-24 09:40:37 +04:00
|
|
|
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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mImportantRule(nullptr),
|
|
|
|
mDOMRule(nullptr),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(0),
|
2013-04-06 21:38:56 +04:00
|
|
|
mColumnNumber(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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr),
|
2011-03-11 05:47:08 +03:00
|
|
|
mDeclaration(new Declaration(*aCopy.mDeclaration)),
|
2012-07-30 18:20:58 +04:00
|
|
|
mImportantRule(nullptr),
|
|
|
|
mDOMRule(nullptr),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(aCopy.mLineNumber),
|
2013-04-06 21:38:56 +04:00
|
|
|
mColumnNumber(aCopy.mColumnNumber),
|
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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mImportantRule(nullptr),
|
2005-12-24 00:04:35 +03:00
|
|
|
mDOMRule(aCopy.mDOMRule),
|
2010-08-03 02:40:35 +04:00
|
|
|
mLineNumber(aCopy.mLineNumber),
|
2013-04-06 21:38:56 +04:00
|
|
|
mColumnNumber(aCopy.mColumnNumber),
|
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).
|
2012-07-30 18:20:58 +04:00
|
|
|
aCopy.mDOMRule = nullptr;
|
2003-06-18 05:59:57 +04:00
|
|
|
|
2010-07-23 22:00:52 +04:00
|
|
|
// Similarly for the selector.
|
2012-07-30 18:20:58 +04:00
|
|
|
aCopy.mSelector = nullptr;
|
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();
|
2012-07-30 18:20:58 +04:00
|
|
|
aCopy.mDeclaration = nullptr;
|
2010-07-23 22:00:52 +04:00
|
|
|
}
|
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
|
|
|
|
|
2012-10-08 06:39:09 +04:00
|
|
|
NS_IMPL_ADDREF(StyleRule)
|
|
|
|
NS_IMPL_RELEASE(StyleRule)
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
/* virtual */ int32_t
|
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
|
|
|
{
|
|
|
|
if (!mDOMRule) {
|
2013-05-16 11:13:36 +04:00
|
|
|
if (!GetStyleSheet()) {
|
|
|
|
// Inline style rules aren't supposed to have a DOM rule object, only
|
|
|
|
// a declaration. But if we do have one already, from a style sheet
|
|
|
|
// rule that used to be in a document, we still want to return it.
|
|
|
|
return nullptr;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-10-08 06:39:08 +04:00
|
|
|
/* virtual */ nsIDOMCSSRule*
|
|
|
|
StyleRule::GetExistingDOMRule()
|
|
|
|
{
|
|
|
|
return mDOMRule;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-04-22 15:15:59 +04:00
|
|
|
nsRefPtr<StyleRule> clone = new StyleRule(*this, aDecl);
|
2003-06-18 05:59:57 +04:00
|
|
|
|
2003-07-01 01:31:25 +04:00
|
|
|
if (aHandleContainer) {
|
2012-09-30 20:40:24 +04:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
2003-06-18 05:59:57 +04:00
|
|
|
if (mParentRule) {
|
2012-09-30 20:40:24 +04:00
|
|
|
if (sheet) {
|
|
|
|
sheet->ReplaceRuleInGroup(mParentRule, this, clone);
|
2011-05-03 05:43:44 +04:00
|
|
|
} else {
|
|
|
|
mParentRule->ReplaceStyleRule(this, clone);
|
|
|
|
}
|
2012-09-30 20:40:24 +04:00
|
|
|
} else if (sheet) {
|
|
|
|
sheet->ReplaceStyleRule(this, clone);
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return clone.forget();
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
StyleRule::List(FILE* out, int32_t aIndent) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsAutoString buffer;
|
2003-06-15 03:50:54 +04:00
|
|
|
if (mSelector)
|
2012-09-30 20:40:24 +04:00
|
|
|
mSelector->ToString(buffer, GetStyleSheet());
|
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);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != mDeclaration) {
|
1998-04-14 00:24:54 +04:00
|
|
|
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) {
|
2012-09-30 20:40:24 +04:00
|
|
|
mSelector->ToString(aCssText, GetStyleSheet());
|
2014-01-04 19:02:17 +04:00
|
|
|
aCssText.Append(char16_t(' '));
|
2003-06-15 03:50:54 +04:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aCssText.Append(char16_t('{'));
|
|
|
|
aCssText.Append(char16_t(' '));
|
2000-09-13 04:05:04 +04:00
|
|
|
if (mDeclaration)
|
|
|
|
{
|
|
|
|
nsAutoString tempString;
|
|
|
|
mDeclaration->ToString( tempString );
|
|
|
|
aCssText.Append( tempString );
|
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
aCssText.Append(char16_t(' '));
|
|
|
|
aCssText.Append(char16_t('}'));
|
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)
|
2012-09-30 20:40:24 +04:00
|
|
|
mSelector->ToString(aSelectorText, GetStyleSheet());
|
2003-06-15 03:50:54 +04:00
|
|
|
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
|
2013-06-23 16:03:39 +04:00
|
|
|
StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
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
|