1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1999-02-27 01:35:51 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsIArena.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-07-11 15:46:10 +00:00
|
|
|
#include "nsNeckoUtil.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
#endif // NECKO
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1998-05-20 20:34:17 +00:00
|
|
|
#include "nsHashtable.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-06-10 05:29:22 +00:00
|
|
|
#include "nsICSSNameSpaceRule.h"
|
|
|
|
#include "nsICSSMediaRule.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-05-19 00:09:29 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsILinkHandler.h"
|
1999-02-27 07:17:52 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
1998-05-19 00:09:29 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-12-02 00:37:32 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsString.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsVoidArray.h"
|
1998-04-22 06:41:10 +00:00
|
|
|
#include "nsIPtr.h"
|
1998-09-05 04:00:06 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-10-06 01:39:33 +00:00
|
|
|
#include "nsIDOMStyleSheetCollection.h"
|
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSStyleRule.h"
|
|
|
|
#include "nsIDOMCSSStyleRuleCollection.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsIDOMNode.h"
|
1998-10-06 01:39:33 +00:00
|
|
|
#include "nsIScriptObjectOwner.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsICSSParser.h"
|
1998-12-11 02:50:43 +00:00
|
|
|
#include "nsCSSAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
1999-06-10 05:29:22 +00:00
|
|
|
#include "nsINameSpace.h"
|
1998-12-03 20:20:35 +00:00
|
|
|
#include "prlog.h"
|
1998-04-22 06:41:10 +00:00
|
|
|
|
|
|
|
//#define DEBUG_REFS
|
1999-04-20 14:22:37 +00:00
|
|
|
//#define DEBUG_RULES
|
1999-06-15 06:20:46 +00:00
|
|
|
#define DEBUG_CASCADE
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
1998-10-06 01:39:33 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMCSSStyleRuleCollectionIID, NS_IDOMCSSSTYLERULECOLLECTION_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
|
|
|
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-22 06:41:10 +00:00
|
|
|
NS_DEF_PTR(nsIHTMLContent);
|
|
|
|
NS_DEF_PTR(nsIContent);
|
|
|
|
NS_DEF_PTR(nsIStyleRule);
|
|
|
|
NS_DEF_PTR(nsICSSStyleRule);
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_DEF_PTR(nsIURI);
|
1998-04-22 06:41:10 +00:00
|
|
|
NS_DEF_PTR(nsISupportsArray);
|
|
|
|
NS_DEF_PTR(nsICSSStyleSheet);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-20 20:34:17 +00:00
|
|
|
// ----------------------
|
|
|
|
// Rule hash key
|
|
|
|
//
|
1999-05-26 23:55:12 +00:00
|
|
|
class AtomKey: public nsHashKey {
|
1998-05-20 20:34:17 +00:00
|
|
|
public:
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey(nsIAtom* aAtom);
|
|
|
|
AtomKey(const AtomKey& aKey);
|
|
|
|
virtual ~AtomKey(void);
|
1998-05-20 20:34:17 +00:00
|
|
|
virtual PRUint32 HashValue(void) const;
|
|
|
|
virtual PRBool Equals(const nsHashKey *aKey) const;
|
|
|
|
virtual nsHashKey *Clone(void) const;
|
|
|
|
nsIAtom* mAtom;
|
|
|
|
};
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey::AtomKey(nsIAtom* aAtom)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
mAtom = aAtom;
|
|
|
|
NS_ADDREF(mAtom);
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey::AtomKey(const AtomKey& aKey)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
mAtom = aKey.mAtom;
|
|
|
|
NS_ADDREF(mAtom);
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey::~AtomKey(void)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
NS_RELEASE(mAtom);
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
PRUint32 AtomKey::HashValue(void) const
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
return (PRUint32)mAtom;
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
PRBool AtomKey::Equals(const nsHashKey* aKey) const
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
1999-05-26 23:55:12 +00:00
|
|
|
return PRBool (((AtomKey*)aKey)->mAtom == mAtom);
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
nsHashKey* AtomKey::Clone(void) const
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
1999-05-26 23:55:12 +00:00
|
|
|
return new AtomKey(*this);
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct RuleValue {
|
|
|
|
RuleValue(nsICSSStyleRule* aRule, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mRule = aRule;
|
|
|
|
mIndex = aIndex;
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
|
|
|
~RuleValue(void)
|
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
if ((nsnull != mNext) && (nsnull != mNext->mNext)) {
|
|
|
|
delete mNext; // don't delete that last in the chain, it's shared
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsICSSStyleRule* mRule;
|
|
|
|
PRInt32 mIndex;
|
|
|
|
RuleValue* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Rule hash table
|
|
|
|
//
|
|
|
|
|
|
|
|
// Enumerator callback function.
|
|
|
|
typedef void (*RuleEnumFunc)(nsICSSStyleRule* aRule, void *aData);
|
|
|
|
|
|
|
|
class RuleHash {
|
|
|
|
public:
|
|
|
|
RuleHash(void);
|
|
|
|
~RuleHash(void);
|
|
|
|
void AppendRule(nsICSSStyleRule* aRule);
|
1998-12-11 02:50:43 +00:00
|
|
|
void EnumerateAllRules(nsIAtom* aTag, nsIAtom* aID, const nsVoidArray& aClassList,
|
1998-05-20 20:34:17 +00:00
|
|
|
RuleEnumFunc aFunc, void* aData);
|
|
|
|
void EnumerateTagRules(nsIAtom* aTag,
|
|
|
|
RuleEnumFunc aFunc, void* aData);
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1998-05-20 20:34:17 +00:00
|
|
|
protected:
|
|
|
|
void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule);
|
|
|
|
|
|
|
|
PRInt32 mRuleCount;
|
|
|
|
nsHashtable mTagTable;
|
|
|
|
nsHashtable mIdTable;
|
|
|
|
nsHashtable mClassTable;
|
1998-12-11 02:50:43 +00:00
|
|
|
|
|
|
|
RuleValue** mEnumList;
|
|
|
|
PRInt32 mEnumListSize;
|
|
|
|
RuleValue mEndValue;
|
1998-05-20 20:34:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RuleHash::RuleHash(void)
|
|
|
|
: mRuleCount(0),
|
1998-12-11 02:50:43 +00:00
|
|
|
mTagTable(), mIdTable(), mClassTable(),
|
|
|
|
mEnumList(nsnull), mEnumListSize(0),
|
|
|
|
mEndValue(nsnull, -1)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-01 00:16:47 +00:00
|
|
|
static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
delete ((RuleValue*)aValue);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RuleHash::~RuleHash(void)
|
|
|
|
{
|
|
|
|
mTagTable.Enumerate(DeleteValue);
|
|
|
|
mIdTable.Enumerate(DeleteValue);
|
|
|
|
mClassTable.Enumerate(DeleteValue);
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != mEnumList) {
|
|
|
|
delete [] mEnumList;
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule)
|
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
NS_ASSERTION(nsnull != aAtom, "null hash key");
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey key(aAtom);
|
1998-05-20 20:34:17 +00:00
|
|
|
RuleValue* value = (RuleValue*)aTable.Get(&key);
|
|
|
|
|
|
|
|
if (nsnull == value) {
|
|
|
|
value = new RuleValue(aRule, mRuleCount++);
|
|
|
|
aTable.Put(&key, value);
|
1998-12-11 02:50:43 +00:00
|
|
|
value->mNext = &mEndValue;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-12-11 02:50:43 +00:00
|
|
|
while (&mEndValue != value->mNext) {
|
1998-05-20 20:34:17 +00:00
|
|
|
value = value->mNext;
|
|
|
|
}
|
|
|
|
value->mNext = new RuleValue(aRule, mRuleCount++);
|
1998-12-11 02:50:43 +00:00
|
|
|
value->mNext->mNext = &mEndValue;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
mEndValue.mIndex = mRuleCount;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::AppendRule(nsICSSStyleRule* aRule)
|
|
|
|
{
|
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
|
|
|
if (nsnull != selector->mID) {
|
|
|
|
AppendRuleToTable(mIdTable, selector->mID, aRule);
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
else if (nsnull != selector->mClassList) {
|
|
|
|
AppendRuleToTable(mClassTable, selector->mClassList->mAtom, aRule);
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
else if (nsnull != selector->mTag) {
|
|
|
|
AppendRuleToTable(mTagTable, selector->mTag, aRule);
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
else { // universal tag selector
|
|
|
|
AppendRuleToTable(mTagTable, nsCSSAtoms::universalSelector, aRule);
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
void RuleHash::EnumerateAllRules(nsIAtom* aTag, nsIAtom* aID, const nsVoidArray& aClassList,
|
1998-05-20 20:34:17 +00:00
|
|
|
RuleEnumFunc aFunc, void* aData)
|
|
|
|
{
|
1998-12-11 02:50:43 +00:00
|
|
|
PRInt32 classCount = aClassList.Count();
|
|
|
|
PRInt32 testCount = classCount + 1; // + 1 for universal selector
|
1998-05-20 21:28:36 +00:00
|
|
|
if (nsnull != aTag) {
|
1998-12-11 02:50:43 +00:00
|
|
|
testCount++;
|
1998-05-20 21:28:36 +00:00
|
|
|
}
|
|
|
|
if (nsnull != aID) {
|
1998-12-11 02:50:43 +00:00
|
|
|
testCount++;
|
1998-05-20 21:28:36 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
|
|
|
|
if (mEnumListSize < testCount) {
|
|
|
|
delete [] mEnumList;
|
|
|
|
mEnumList = new RuleValue*[testCount];
|
|
|
|
mEnumListSize = testCount;
|
1998-05-20 21:28:36 +00:00
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
PRInt32 index;
|
|
|
|
PRInt32 valueCount = 0;
|
1998-05-20 20:34:17 +00:00
|
|
|
|
1998-12-11 02:50:43 +00:00
|
|
|
{ // universal tag rules
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey universalKey(nsCSSAtoms::universalSelector);
|
1998-12-21 05:58:31 +00:00
|
|
|
RuleValue* value = (RuleValue*)mTagTable.Get(&universalKey);
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
if (nsnull != aTag) {
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey tagKey(aTag);
|
1998-12-21 05:58:31 +00:00
|
|
|
RuleValue* value = (RuleValue*)mTagTable.Get(&tagKey);
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
if (nsnull != aID) {
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey idKey(aID);
|
1998-12-21 05:58:31 +00:00
|
|
|
RuleValue* value = (RuleValue*)mIdTable.Get(&idKey);
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = 0; index < classCount; index++) {
|
|
|
|
nsIAtom* classAtom = (nsIAtom*)aClassList.ElementAt(index);
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey classKey(classAtom);
|
1998-12-21 05:58:31 +00:00
|
|
|
RuleValue* value = (RuleValue*)mClassTable.Get(&classKey);
|
1998-12-11 02:50:43 +00:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(valueCount <= testCount, "values exceeded list size");
|
|
|
|
|
|
|
|
if (1 < valueCount) {
|
|
|
|
PRInt32 ruleIndex = mRuleCount;
|
|
|
|
PRInt32 valueIndex = -1;
|
|
|
|
|
|
|
|
for (index = 0; index < valueCount; index++) {
|
|
|
|
if (mEnumList[index]->mIndex < ruleIndex) {
|
|
|
|
ruleIndex = mEnumList[index]->mIndex;
|
|
|
|
valueIndex = index;
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
do {
|
|
|
|
(*aFunc)(mEnumList[valueIndex]->mRule, aData);
|
|
|
|
mEnumList[valueIndex] = mEnumList[valueIndex]->mNext;
|
|
|
|
ruleIndex = mEnumList[valueIndex]->mIndex;
|
|
|
|
for (index = 0; index < valueCount; index++) {
|
|
|
|
if (mEnumList[index]->mIndex < ruleIndex) {
|
|
|
|
ruleIndex = mEnumList[index]->mIndex;
|
|
|
|
valueIndex = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (ruleIndex < mRuleCount);
|
|
|
|
}
|
|
|
|
else if (0 < valueCount) { // fast loop over single value
|
|
|
|
RuleValue* value = mEnumList[0];
|
|
|
|
do {
|
|
|
|
(*aFunc)(value->mRule, aData);
|
|
|
|
value = value->mNext;
|
|
|
|
} while (&mEndValue != value);
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::EnumerateTagRules(nsIAtom* aTag, RuleEnumFunc aFunc, void* aData)
|
|
|
|
{
|
1999-05-26 23:55:12 +00:00
|
|
|
AtomKey tagKey(aTag);
|
|
|
|
AtomKey universalKey(nsCSSAtoms::universalSelector);
|
1998-12-21 05:58:31 +00:00
|
|
|
RuleValue* tagValue = (RuleValue*)mTagTable.Get(&tagKey);
|
|
|
|
RuleValue* uniValue = (RuleValue*)mTagTable.Get(&universalKey);
|
1998-12-11 02:50:43 +00:00
|
|
|
|
|
|
|
if (nsnull == tagValue) {
|
|
|
|
if (nsnull != uniValue) {
|
|
|
|
do {
|
|
|
|
(*aFunc)(uniValue->mRule, aData);
|
|
|
|
uniValue = uniValue->mNext;
|
|
|
|
} while (&mEndValue != uniValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull == uniValue) {
|
|
|
|
do {
|
|
|
|
(*aFunc)(tagValue->mRule, aData);
|
|
|
|
tagValue = tagValue->mNext;
|
|
|
|
} while (&mEndValue != tagValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
do {
|
|
|
|
if (tagValue->mIndex < uniValue->mIndex) {
|
|
|
|
(*aFunc)(tagValue->mRule, aData);
|
|
|
|
tagValue = tagValue->mNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(*aFunc)(uniValue->mRule, aData);
|
|
|
|
uniValue = uniValue->mNext;
|
|
|
|
}
|
|
|
|
} while ((&mEndValue != tagValue) || (&mEndValue != uniValue));
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet Inner Data Container
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSStyleSheetInner {
|
|
|
|
public:
|
|
|
|
CSSStyleSheetInner(nsICSSStyleSheet* aParentSheet);
|
|
|
|
CSSStyleSheetInner(CSSStyleSheetInner& aCopy, nsICSSStyleSheet* aParentSheet);
|
|
|
|
virtual ~CSSStyleSheetInner(void);
|
|
|
|
|
|
|
|
virtual CSSStyleSheetInner* CloneFor(nsICSSStyleSheet* aParentSheet);
|
|
|
|
virtual void AddSheet(nsICSSStyleSheet* aParentSheet);
|
|
|
|
virtual void RemoveSheet(nsICSSStyleSheet* aParentSheet);
|
|
|
|
|
|
|
|
virtual void ClearRuleCascades(void);
|
1999-06-15 06:20:46 +00:00
|
|
|
virtual void RebuildNameSpaces(void);
|
1999-06-03 01:57:52 +00:00
|
|
|
|
|
|
|
nsVoidArray mSheets;
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* mURL;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
|
|
|
nsISupportsArray* mOrderedRules;
|
|
|
|
nsHashtable* mMediumCascadeTable;
|
1999-06-10 05:29:22 +00:00
|
|
|
|
|
|
|
nsINameSpace* mNameSpace;
|
1999-06-15 06:20:46 +00:00
|
|
|
PRInt32 mDefaultNameSpaceID;
|
1999-06-03 01:57:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
struct RuleCascadeData {
|
|
|
|
RuleCascadeData(void)
|
|
|
|
: mWeightedRules(nsnull),
|
|
|
|
mRuleHash(),
|
|
|
|
mStateSelectors()
|
|
|
|
{
|
|
|
|
NS_NewISupportsArray(&mWeightedRules);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RuleCascadeData(void)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mWeightedRules);
|
|
|
|
}
|
|
|
|
nsISupportsArray* mWeightedRules;
|
|
|
|
RuleHash mRuleHash;
|
|
|
|
nsVoidArray mStateSelectors;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSImportsCollectionImpl;
|
|
|
|
class CSSStyleRuleCollectionImpl;
|
|
|
|
|
|
|
|
class CSSStyleSheetImpl : public nsICSSStyleSheet,
|
|
|
|
public nsIDOMCSSStyleSheet,
|
|
|
|
public nsIScriptObjectOwner {
|
|
|
|
public:
|
|
|
|
void* operator new(size_t size);
|
|
|
|
void* operator new(size_t size, nsIArena* aArena);
|
|
|
|
void operator delete(void* ptr);
|
|
|
|
|
|
|
|
CSSStyleSheetImpl();
|
|
|
|
|
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
|
|
|
|
// basic style sheet data
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL);
|
|
|
|
NS_IMETHOD GetURL(nsIURI*& aURL) const;
|
1999-06-03 01:57:52 +00:00
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD SetTitle(const nsString& aTitle);
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const;
|
1999-06-15 06:20:46 +00:00
|
|
|
NS_IMETHOD UseForMedium(nsIAtom* aMedium) const;
|
1999-06-03 01:57:52 +00:00
|
|
|
NS_IMETHOD AppendMedium(nsIAtom* aMedium);
|
|
|
|
NS_IMETHOD ClearMedia(void);
|
|
|
|
|
|
|
|
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
|
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled);
|
|
|
|
|
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
|
|
|
|
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
|
|
|
|
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
|
|
|
|
NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
|
|
|
|
|
|
|
|
|
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
|
|
|
NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_IMETHOD ContainsStyleSheet(nsIURI* aURL) const;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aSheet);
|
1999-06-03 01:57:52 +00:00
|
|
|
NS_IMETHOD InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
|
|
|
|
|
|
|
|
// XXX do these belong here or are they generic?
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHOD PrependStyleRule(nsICSSRule* aRule);
|
|
|
|
NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
|
|
|
|
|
|
|
|
NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHOD StyleSheetCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHOD GetNameSpace(nsINameSpace*& aNameSpace) const;
|
1999-06-15 06:20:46 +00:00
|
|
|
NS_IMETHOD SetDefaultNameSpaceID(PRInt32 aDefaultNameSpaceID);
|
1999-06-03 01:57:52 +00:00
|
|
|
|
|
|
|
NS_IMETHOD Clone(nsICSSStyleSheet*& aClone) const;
|
|
|
|
|
|
|
|
NS_IMETHOD IsUnmodified(void) const;
|
|
|
|
NS_IMETHOD SetModified(PRBool aModified);
|
|
|
|
|
|
|
|
nsresult EnsureUniqueInner(void);
|
|
|
|
|
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHOD GetType(nsString& aType);
|
|
|
|
NS_IMETHOD GetDisabled(PRBool* aDisabled);
|
|
|
|
NS_IMETHOD SetDisabled(PRBool aDisabled);
|
|
|
|
NS_IMETHOD GetReadOnly(PRBool* aReadOnly);
|
|
|
|
|
|
|
|
// nsIDOMCSSStyleSheet interface
|
|
|
|
NS_IMETHOD GetOwningNode(nsIDOMNode** aOwningNode);
|
|
|
|
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet);
|
|
|
|
NS_IMETHOD GetHref(nsString& aHref);
|
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle);
|
|
|
|
NS_IMETHOD GetMedia(nsString& aMedia);
|
|
|
|
NS_IMETHOD GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules);
|
|
|
|
NS_IMETHOD InsertRule(const nsString& aRule, PRUint32 aIndex, PRUint32* aReturn);
|
|
|
|
NS_IMETHOD DeleteRule(PRUint32 aIndex);
|
|
|
|
|
|
|
|
// nsIScriptObjectOwner interface
|
|
|
|
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
|
|
|
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
|
|
|
CSSStyleSheetImpl& operator=(const CSSStyleSheetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSStyleSheetImpl();
|
|
|
|
|
|
|
|
void ClearRuleCascades(void);
|
1999-06-15 06:20:46 +00:00
|
|
|
#ifdef DEBUG_CASCADE
|
|
|
|
nsresult SlowCascadeRulesInto(nsIAtom* aMedium, nsISupportsArray* aRules);
|
|
|
|
#endif
|
|
|
|
nsresult GatherRulesFor(nsIAtom* aMedium, nsISupportsArray* aRules);
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult CascadeRulesInto(nsIAtom* aMedium, nsISupportsArray* aRules);
|
|
|
|
RuleCascadeData* GetRuleCascade(nsIAtom* aMedium);
|
|
|
|
|
|
|
|
nsresult WillDirty(void);
|
|
|
|
void DidDirty(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRUint32 mInHeap : 1;
|
|
|
|
PRUint32 mRefCnt : 31;
|
|
|
|
|
|
|
|
nsString mTitle;
|
|
|
|
nsISupportsArray* mMedia;
|
|
|
|
CSSStyleSheetImpl* mFirstChild;
|
|
|
|
CSSStyleSheetImpl* mNext;
|
|
|
|
nsICSSStyleSheet* mParent;
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl* mImportsCollection;
|
|
|
|
CSSStyleRuleCollectionImpl* mRuleCollection;
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
nsIDOMNode* mOwningNode;
|
|
|
|
PRBool mDisabled;
|
|
|
|
PRBool mDirty; // has been modified
|
|
|
|
void* mScriptObject;
|
|
|
|
|
|
|
|
CSSStyleSheetInner* mInner;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
// -------------------------------
|
|
|
|
// Style Rule Collection for the DOM
|
|
|
|
//
|
|
|
|
class CSSStyleRuleCollectionImpl : public nsIDOMCSSStyleRuleCollection,
|
|
|
|
public nsIScriptObjectOwner
|
|
|
|
{
|
|
|
|
public:
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleRuleCollectionImpl(CSSStyleSheetImpl *aStyleSheet);
|
1998-10-06 01:39:33 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMCSSStyleRuleCollection interface
|
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn);
|
|
|
|
|
|
|
|
// nsIScriptObjectOwner interface
|
|
|
|
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
|
|
|
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSStyleRuleCollectionImpl();
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetImpl* mStyleSheet;
|
|
|
|
void* mScriptObject;
|
|
|
|
public:
|
|
|
|
PRBool mRulesAccessed;
|
1998-10-06 01:39:33 +00:00
|
|
|
};
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleRuleCollectionImpl::CSSStyleRuleCollectionImpl(CSSStyleSheetImpl *aStyleSheet)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
|
|
|
mScriptObject = nsnull;
|
1999-06-03 01:57:52 +00:00
|
|
|
mRulesAccessed = PR_FALSE;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSStyleRuleCollectionImpl::~CSSStyleRuleCollectionImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(CSSStyleRuleCollectionImpl);
|
|
|
|
NS_IMPL_RELEASE(CSSStyleRuleCollectionImpl);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSStyleRuleCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kIDOMCSSStyleRuleCollectionIID)) {
|
|
|
|
nsIDOMCSSStyleRuleCollection *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
nsIScriptObjectOwner *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
nsIDOMCSSStyleRuleCollection *tmp = this;
|
|
|
|
nsISupports *tmp2 = tmp;
|
|
|
|
*aInstancePtrResult = (void*) tmp2;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleCollectionImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 05:29:22 +00:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleRuleCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleCollectionImpl::Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-03 01:57:52 +00:00
|
|
|
result = mStyleSheet->EnsureUniqueInner(); // needed to ensure rules have correct parent
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule *rule;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
|
|
|
result = mStyleSheet->GetStyleRuleAt(aIndex, rule);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
result = rule->QueryInterface(kIDOMCSSStyleRuleIID, (void **)aReturn);
|
|
|
|
mRulesAccessed = PR_TRUE; // signal to never share rules again
|
|
|
|
}
|
|
|
|
NS_RELEASE(rule);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
|
|
|
void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == mScriptObject) {
|
|
|
|
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleRuleCollection *)this;
|
|
|
|
|
|
|
|
// XXX Should be done through factory
|
|
|
|
res = NS_NewScriptCSSStyleRuleCollection(aContext,
|
|
|
|
supports,
|
1999-06-03 01:57:52 +00:00
|
|
|
(nsISupports *)(nsICSSStyleSheet*)mStyleSheet,
|
1998-10-06 01:39:33 +00:00
|
|
|
(void**)&mScriptObject);
|
|
|
|
}
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleRuleCollectionImpl::SetScriptObject(void* aScriptObject)
|
|
|
|
{
|
|
|
|
mScriptObject = aScriptObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// Imports Collection for the DOM
|
|
|
|
//
|
|
|
|
class CSSImportsCollectionImpl : public nsIDOMStyleSheetCollection,
|
|
|
|
public nsIScriptObjectOwner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMCSSStyleSheetCollection interface
|
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
|
|
|
|
|
|
|
// nsIScriptObjectOwner interface
|
|
|
|
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
|
|
|
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSImportsCollectionImpl();
|
|
|
|
|
|
|
|
nsICSSStyleSheet* mStyleSheet;
|
|
|
|
void* mScriptObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
|
|
|
mScriptObject = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(CSSImportsCollectionImpl);
|
|
|
|
NS_IMPL_RELEASE(CSSImportsCollectionImpl);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
|
|
|
nsIDOMStyleSheetCollection *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
nsIScriptObjectOwner *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
nsIDOMStyleSheetCollection *tmp = this;
|
|
|
|
nsISupports *tmp2 = tmp;
|
|
|
|
*aInstancePtrResult = (void*) tmp2;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 05:29:22 +00:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleSheetCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
|
|
|
if (nsnull != mStyleSheet) {
|
|
|
|
nsICSSStyleSheet *sheet;
|
|
|
|
|
|
|
|
result = mStyleSheet->GetStyleSheetAt(aIndex, sheet);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
result = sheet->QueryInterface(kIDOMStyleSheetIID, (void **)aReturn);
|
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
|
|
|
void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == mScriptObject) {
|
|
|
|
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
|
|
|
|
|
|
|
// XXX Should be done through factory
|
|
|
|
res = NS_NewScriptStyleSheetCollection(aContext,
|
|
|
|
supports,
|
|
|
|
(nsISupports *)mStyleSheet,
|
|
|
|
(void**)&mScriptObject);
|
|
|
|
}
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject)
|
|
|
|
{
|
|
|
|
mScriptObject = aScriptObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
|
|
|
|
// -------------------------------
|
1999-06-03 01:57:52 +00:00
|
|
|
// CSS Style Sheet Inner Data Container
|
1998-05-20 20:34:17 +00:00
|
|
|
//
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
static PRBool SetStyleSheetReference(nsISupports* aElement, void* aSheet)
|
|
|
|
{
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aElement;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (nsnull != rule) {
|
|
|
|
rule->SetStyleSheet((nsICSSStyleSheet*)aSheet);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1998-11-17 02:14:38 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(nsICSSStyleSheet* aParentSheet)
|
|
|
|
: mSheets(),
|
|
|
|
mURL(nsnull),
|
|
|
|
mOrderedRules(nsnull),
|
1999-06-10 05:29:22 +00:00
|
|
|
mMediumCascadeTable(nsnull),
|
1999-06-15 06:20:46 +00:00
|
|
|
mNameSpace(nsnull),
|
|
|
|
mDefaultNameSpaceID(kNameSpaceID_None)
|
1999-06-03 01:57:52 +00:00
|
|
|
{
|
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
}
|
1999-05-18 23:14:29 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
static PRBool
|
|
|
|
CloneRuleInto(nsISupports* aRule, void* aArray)
|
|
|
|
{
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
|
|
|
nsICSSRule* clone = nsnull;
|
1999-06-03 01:57:52 +00:00
|
|
|
rule->Clone(clone);
|
|
|
|
if (clone) {
|
|
|
|
nsISupportsArray* array = (nsISupportsArray*)aArray;
|
|
|
|
array->AppendElement(clone);
|
|
|
|
NS_RELEASE(clone);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
|
|
|
|
nsICSSStyleSheet* aParentSheet)
|
|
|
|
: mSheets(),
|
|
|
|
mURL(aCopy.mURL),
|
1999-06-10 05:29:22 +00:00
|
|
|
mMediumCascadeTable(nsnull),
|
1999-06-15 06:20:46 +00:00
|
|
|
mNameSpace(nsnull),
|
|
|
|
mDefaultNameSpaceID(aCopy.mDefaultNameSpaceID)
|
1999-06-03 01:57:52 +00:00
|
|
|
{
|
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
if (aCopy.mOrderedRules) {
|
|
|
|
NS_NewISupportsArray(&mOrderedRules);
|
|
|
|
if (mOrderedRules) {
|
|
|
|
aCopy.mOrderedRules->EnumerateForwards(CloneRuleInto, mOrderedRules);
|
|
|
|
mOrderedRules->EnumerateForwards(SetStyleSheetReference, aParentSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mOrderedRules = nsnull;
|
|
|
|
}
|
1999-06-15 06:20:46 +00:00
|
|
|
RebuildNameSpaces();
|
1999-06-03 01:57:52 +00:00
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetInner::~CSSStyleSheetInner(void)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
if (mOrderedRules) {
|
|
|
|
mOrderedRules->EnumerateForwards(SetStyleSheetReference, nsnull);
|
|
|
|
NS_RELEASE(mOrderedRules);
|
|
|
|
}
|
|
|
|
ClearRuleCascades();
|
1999-06-15 06:20:46 +00:00
|
|
|
NS_IF_RELEASE(mNameSpace);
|
1999-06-03 01:57:52 +00:00
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetInner*
|
|
|
|
CSSStyleSheetInner::CloneFor(nsICSSStyleSheet* aParentSheet)
|
|
|
|
{
|
|
|
|
return new CSSStyleSheetInner(*this, aParentSheet);
|
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
void
|
|
|
|
CSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aParentSheet)
|
|
|
|
{
|
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
void
|
|
|
|
CSSStyleSheetInner::RemoveSheet(nsICSSStyleSheet* aParentSheet)
|
|
|
|
{
|
|
|
|
if (1 == mSheets.Count()) {
|
|
|
|
NS_ASSERTION(aParentSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0), "bad parent");
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aParentSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0)) {
|
|
|
|
mSheets.RemoveElementAt(0);
|
|
|
|
NS_ASSERTION(mSheets.Count(), "no parents");
|
|
|
|
if (mOrderedRules) {
|
|
|
|
mOrderedRules->EnumerateForwards(SetStyleSheetReference,
|
|
|
|
(nsICSSStyleSheet*)mSheets.ElementAt(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSheets.RemoveElement(aParentSheet);
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
static PRBool DeleteRuleCascade(nsHashKey* aKey, void* aValue, void* closure)
|
|
|
|
{
|
|
|
|
delete ((RuleCascadeData*)aValue);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
void
|
|
|
|
CSSStyleSheetInner::ClearRuleCascades(void)
|
|
|
|
{
|
|
|
|
if (mMediumCascadeTable) {
|
|
|
|
mMediumCascadeTable->Enumerate(DeleteRuleCascade, nsnull);
|
|
|
|
delete mMediumCascadeTable;
|
|
|
|
mMediumCascadeTable = nsnull;
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
|
1999-06-15 06:20:46 +00:00
|
|
|
static PRBool
|
|
|
|
CreateNameSpace(nsISupports* aRule, void* aNameSpacePtr)
|
|
|
|
{
|
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
|
|
|
PRInt32 type;
|
|
|
|
rule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
nsICSSNameSpaceRule* nameSpaceRule = (nsICSSNameSpaceRule*)rule;
|
|
|
|
nsINameSpace** nameSpacePtr = (nsINameSpace**)aNameSpacePtr;
|
|
|
|
nsINameSpace* lastNameSpace = *nameSpacePtr;
|
|
|
|
nsINameSpace* newNameSpace;
|
|
|
|
|
|
|
|
nsIAtom* prefix = nsnull;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(prefix);
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
lastNameSpace->CreateChildNameSpace(prefix, urlSpec, newNameSpace);
|
|
|
|
NS_IF_RELEASE(prefix);
|
|
|
|
if (newNameSpace) {
|
|
|
|
NS_RELEASE(lastNameSpace);
|
|
|
|
(*nameSpacePtr) = newNameSpace; // takes ref
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// stop if not namespace, import or charset because namespace can't follow anything else
|
|
|
|
return (((nsICSSRule::CHARSET_RULE == type) ||
|
|
|
|
(nsICSSRule::IMPORT_RULE)) ? PR_TRUE : PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSStyleSheetInner::RebuildNameSpaces(void)
|
|
|
|
{
|
|
|
|
nsINameSpaceManager* nameSpaceMgr;
|
|
|
|
if (mNameSpace) {
|
|
|
|
mNameSpace->GetNameSpaceManager(nameSpaceMgr);
|
|
|
|
NS_RELEASE(mNameSpace);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NewNameSpaceManager(&nameSpaceMgr);
|
|
|
|
}
|
|
|
|
if (nameSpaceMgr) {
|
|
|
|
nameSpaceMgr->CreateRootNameSpace(mNameSpace);
|
|
|
|
if (kNameSpaceID_Unknown != mDefaultNameSpaceID) {
|
|
|
|
nsINameSpace* defaultNameSpace;
|
|
|
|
mNameSpace->CreateChildNameSpace(nsnull, mDefaultNameSpaceID, defaultNameSpace);
|
|
|
|
if (defaultNameSpace) {
|
|
|
|
NS_RELEASE(mNameSpace);
|
|
|
|
mNameSpace = defaultNameSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(nameSpaceMgr);
|
|
|
|
if (mOrderedRules) {
|
|
|
|
mOrderedRules->EnumerateForwards(CreateNameSpace, &mNameSpace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
void* CSSStyleSheetImpl::operator new(size_t size)
|
|
|
|
{
|
|
|
|
CSSStyleSheetImpl* rv = (CSSStyleSheetImpl*) ::operator new(size);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 1;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* CSSStyleSheetImpl::operator new(size_t size, nsIArena* aArena)
|
|
|
|
{
|
|
|
|
CSSStyleSheetImpl* rv = (CSSStyleSheetImpl*) aArena->Alloc(PRInt32(size));
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 0;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
1999-02-26 19:26:29 +00:00
|
|
|
void CSSStyleSheetImpl::operator delete(void* ptr)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*) ptr;
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (sheet->mInHeap) {
|
1999-02-26 17:13:10 +00:00
|
|
|
::operator delete(ptr);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-22 06:41:10 +00:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
static PRInt32 gInstanceCount;
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
CSSStyleSheetImpl::CSSStyleSheetImpl()
|
1998-04-13 20:24:54 +00:00
|
|
|
: nsICSSStyleSheet(),
|
1999-06-03 01:57:52 +00:00
|
|
|
mTitle(),
|
|
|
|
mMedia(nsnull),
|
1998-11-26 01:34:53 +00:00
|
|
|
mFirstChild(nsnull),
|
1998-06-05 06:06:50 +00:00
|
|
|
mNext(nsnull),
|
1999-06-03 01:57:52 +00:00
|
|
|
mParent(nsnull),
|
|
|
|
mImportsCollection(nsnull),
|
|
|
|
mRuleCollection(nsnull),
|
|
|
|
mDocument(nsnull),
|
|
|
|
mOwningNode(nsnull),
|
|
|
|
mDisabled(PR_FALSE),
|
1999-07-16 17:40:39 +00:00
|
|
|
mDirty(PR_FALSE),
|
|
|
|
mScriptObject(nsnull)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-07-18 00:27:40 +00:00
|
|
|
nsCSSAtoms::AddRefAtoms();
|
1998-12-11 02:50:43 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner = new CSSStyleSheetInner(this);
|
|
|
|
|
1998-04-22 06:41:10 +00:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
++gInstanceCount;
|
|
|
|
fprintf(stdout, "%d + CSSStyleSheet size: %d\n", gInstanceCount, sizeof(*this));
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy)
|
|
|
|
: nsICSSStyleSheet(),
|
|
|
|
mTitle(aCopy.mTitle),
|
|
|
|
mMedia(nsnull),
|
|
|
|
mFirstChild(nsnull),
|
|
|
|
mNext(nsnull),
|
|
|
|
mParent(aCopy.mParent),
|
|
|
|
mImportsCollection(nsnull), // re-created lazily
|
|
|
|
mRuleCollection(nsnull), // re-created lazily
|
|
|
|
mDocument(aCopy.mDocument),
|
|
|
|
mOwningNode(aCopy.mOwningNode),
|
|
|
|
mDisabled(aCopy.mDisabled),
|
1999-07-16 17:40:39 +00:00
|
|
|
mDirty(PR_FALSE),
|
1999-06-03 01:57:52 +00:00
|
|
|
mScriptObject(nsnull),
|
1999-07-16 17:40:39 +00:00
|
|
|
mInner(aCopy.mInner)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1999-06-03 01:57:52 +00:00
|
|
|
NS_INIT_REFCNT();
|
1999-07-18 00:27:40 +00:00
|
|
|
nsCSSAtoms::AddRefAtoms();
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->AddSheet(this);
|
|
|
|
|
|
|
|
if (aCopy.mRuleCollection &&
|
|
|
|
aCopy.mRuleCollection->mRulesAccessed) { // CSSOM's been there, force full copy now
|
|
|
|
EnsureUniqueInner();
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (aCopy.mMedia) {
|
|
|
|
NS_NewISupportsArray(&mMedia);
|
|
|
|
if (mMedia) {
|
|
|
|
mMedia->AppendElements(aCopy.mMedia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCopy.mFirstChild) {
|
|
|
|
CSSStyleSheetImpl* otherChild = aCopy.mFirstChild;
|
|
|
|
CSSStyleSheetImpl** ourSlot = &mFirstChild;
|
|
|
|
do {
|
|
|
|
CSSStyleSheetImpl* child = new CSSStyleSheetImpl(*otherChild);
|
|
|
|
if (child) {
|
|
|
|
NS_ADDREF(child);
|
|
|
|
(*ourSlot) = child;
|
|
|
|
ourSlot = &(child->mNext);
|
|
|
|
}
|
|
|
|
otherChild = otherChild->mNext;
|
|
|
|
}
|
|
|
|
while (otherChild && ourSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
++gInstanceCount;
|
|
|
|
fprintf(stdout, "%d + CSSStyleSheet size: %d\n", gInstanceCount, sizeof(*this));
|
|
|
|
#endif
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
|
|
|
{
|
1998-04-22 06:41:10 +00:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
--gInstanceCount;
|
|
|
|
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
|
|
|
|
#endif
|
1998-12-02 00:37:32 +00:00
|
|
|
NS_IF_RELEASE(mMedia);
|
1999-05-18 23:14:29 +00:00
|
|
|
if (mFirstChild) {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
do {
|
|
|
|
child->mParent = nsnull;
|
|
|
|
child = child->mNext;
|
|
|
|
} while (child);
|
|
|
|
NS_RELEASE(mFirstChild);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
1999-05-18 23:14:29 +00:00
|
|
|
NS_IF_RELEASE(mNext);
|
1998-10-06 01:39:33 +00:00
|
|
|
if (nsnull != mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
NS_RELEASE(mRuleCollection);
|
|
|
|
}
|
|
|
|
if (nsnull != mImportsCollection) {
|
|
|
|
mImportsCollection->DropReference();
|
|
|
|
NS_RELEASE(mImportsCollection);
|
|
|
|
}
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->RemoveSheet(this);
|
1998-11-17 02:14:38 +00:00
|
|
|
// XXX The document reference is not reference counted and should
|
|
|
|
// not be released. The document will let us know when it is going
|
|
|
|
// away.
|
1998-12-11 02:50:43 +00:00
|
|
|
nsCSSAtoms::ReleaseAtoms();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(CSSStyleSheetImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSStyleSheetImpl)
|
|
|
|
|
|
|
|
nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kICSSStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsICSSStyleSheet*)this);
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
if (aIID.Equals(kIDOMStyleSheetIID)) {
|
|
|
|
nsIDOMStyleSheet *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMCSSStyleSheetIID)) {
|
|
|
|
nsIDOMCSSStyleSheet *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
nsIScriptObjectOwner *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1998-10-06 01:39:33 +00:00
|
|
|
nsICSSStyleSheet *tmp = this;
|
|
|
|
nsISupports *tmp2 = tmp;
|
|
|
|
*aInstancePtrResult = (void*) tmp2;
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-13 20:24:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1998-12-20 01:17:05 +00:00
|
|
|
static const PRUnichar kNullCh = PRUnichar('\0');
|
|
|
|
|
1999-02-11 06:42:49 +00:00
|
|
|
static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive)
|
1998-12-20 01:17:05 +00:00
|
|
|
{
|
|
|
|
nsAutoString valueList(aValueList);
|
|
|
|
|
|
|
|
valueList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
1999-04-21 23:48:41 +00:00
|
|
|
PRUnichar* value = (PRUnichar*)(const PRUnichar*)aValue.GetUnicode();
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)valueList.GetUnicode();
|
1998-12-20 01:17:05 +00:00
|
|
|
PRUnichar* end = start;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
|
|
|
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (PR_FALSE == nsString::IsSpace(*end))) { // look for space or end
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
1999-02-11 06:42:49 +00:00
|
|
|
if (start < end) {
|
|
|
|
if (aCaseSensitive) {
|
|
|
|
if (aValue.Equals(value, start)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aValue.EqualsIgnoreCase(value, start)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-20 01:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PRUnichar kDashCh = PRUnichar('-');
|
|
|
|
|
1999-02-11 06:42:49 +00:00
|
|
|
static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive)
|
1998-12-20 01:17:05 +00:00
|
|
|
{
|
|
|
|
nsAutoString valueList(aValueList);
|
|
|
|
|
|
|
|
valueList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
1999-04-21 23:48:41 +00:00
|
|
|
PRUnichar* value = (PRUnichar*)(const PRUnichar*)aValue.GetUnicode();
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)valueList.GetUnicode();
|
1998-12-20 01:17:05 +00:00
|
|
|
PRUnichar* end = start;
|
|
|
|
|
|
|
|
if (kNullCh != *start) {
|
|
|
|
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (kDashCh != *end)) { // look for dash or end
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
1999-02-11 06:42:49 +00:00
|
|
|
if (start < end) {
|
|
|
|
if (aCaseSensitive) {
|
|
|
|
if (aValue.Equals(value, start)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aValue.EqualsIgnoreCase(value, start)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-20 01:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-27 07:17:52 +00:00
|
|
|
static PRBool IsEventPseudo(nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
return PRBool ((nsCSSAtoms::activePseudo == aAtom) ||
|
1999-05-18 23:14:29 +00:00
|
|
|
(nsCSSAtoms::dragOverPseudo == aAtom) ||
|
|
|
|
// (nsCSSAtoms::dragPseudo == aAtom) || // not real yet
|
1999-02-27 07:17:52 +00:00
|
|
|
(nsCSSAtoms::focusPseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::hoverPseudo == aAtom));
|
|
|
|
// XXX selected, enabled, disabled, selection?
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool IsLinkPseudo(nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
return PRBool ((nsCSSAtoms::linkPseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::outOfDatePseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::visitedPseudo == aAtom));
|
|
|
|
}
|
1998-12-20 01:17:05 +00:00
|
|
|
|
1998-05-20 20:34:17 +00:00
|
|
|
static PRBool SelectorMatches(nsIPresContext* aPresContext,
|
1999-04-20 00:05:54 +00:00
|
|
|
nsCSSSelector* aSelector, nsIContent* aContent,
|
|
|
|
PRBool aTestState)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom* contentTag;
|
|
|
|
aContent->GetTag(contentTag);
|
1998-12-11 02:50:43 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
aContent->GetNameSpaceID(nameSpaceID);
|
|
|
|
|
|
|
|
if (((nsnull == aSelector->mTag) || (aSelector->mTag == contentTag)) &&
|
|
|
|
((kNameSpaceID_Unknown == aSelector->mNameSpace) || (nameSpaceID == aSelector->mNameSpace))) {
|
|
|
|
result = PR_TRUE;
|
|
|
|
// namespace/tag match
|
|
|
|
if (nsnull != aSelector->mAttrList) { // test for attribute match
|
1998-12-20 01:17:05 +00:00
|
|
|
nsAttrSelector* attr = aSelector->mAttrList;
|
|
|
|
do {
|
|
|
|
nsAutoString value;
|
1999-06-10 05:29:22 +00:00
|
|
|
nsresult attrState = aContent->GetAttribute(attr->mNameSpace, attr->mAttr, value);
|
|
|
|
if (NS_FAILED(attrState) || (NS_CONTENT_ATTR_NOT_THERE == attrState)) {
|
1998-12-20 01:17:05 +00:00
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (attr->mFunction) {
|
|
|
|
case NS_ATTR_FUNC_SET: break;
|
|
|
|
case NS_ATTR_FUNC_EQUALS:
|
1998-12-21 05:58:31 +00:00
|
|
|
if (attr->mCaseSensitive) {
|
1998-12-20 01:17:05 +00:00
|
|
|
result = value.Equals(attr->mValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = value.EqualsIgnoreCase(attr->mValue);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_INCLUDES:
|
1999-02-11 06:42:49 +00:00
|
|
|
result = ValueIncludes(value, attr->mValue, attr->mCaseSensitive);
|
1998-12-20 01:17:05 +00:00
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_DASHMATCH:
|
1999-02-11 06:42:49 +00:00
|
|
|
result = ValueDashMatch(value, attr->mValue, attr->mCaseSensitive);
|
1998-12-20 01:17:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attr = attr->mNext;
|
|
|
|
} while ((PR_TRUE == result) && (nsnull != attr));
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
if ((PR_TRUE == result) &&
|
|
|
|
((nsnull != aSelector->mID) || (nsnull != aSelector->mClassList))) { // test for ID & class match
|
|
|
|
result = PR_FALSE;
|
1999-02-27 01:35:51 +00:00
|
|
|
nsIStyledContent* styledContent;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(nsIStyledContent::GetIID(), (void**)&styledContent))) {
|
1998-08-29 20:20:38 +00:00
|
|
|
nsIAtom* contentID;
|
1999-02-27 01:35:51 +00:00
|
|
|
styledContent->GetID(contentID);
|
1998-12-11 02:50:43 +00:00
|
|
|
if ((nsnull == aSelector->mID) || (aSelector->mID == contentID)) {
|
1998-12-20 01:17:05 +00:00
|
|
|
result = PR_TRUE;
|
|
|
|
nsAtomList* classList = aSelector->mClassList;
|
|
|
|
while (nsnull != classList) {
|
1999-02-27 01:35:51 +00:00
|
|
|
if (NS_COMFALSE == styledContent->HasClass(classList->mAtom)) {
|
1998-12-20 01:17:05 +00:00
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
classList = classList->mNext;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
NS_IF_RELEASE(contentID);
|
1999-02-27 01:35:51 +00:00
|
|
|
NS_RELEASE(styledContent);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
if ((PR_TRUE == result) &&
|
1998-12-11 02:50:43 +00:00
|
|
|
(nsnull != aSelector->mPseudoClassList)) { // test for pseudo class match
|
1999-02-27 07:17:52 +00:00
|
|
|
// first-child, lang, active, focus, hover, link, outOfDate, visited
|
|
|
|
// XXX disabled, enabled, selected, selection
|
|
|
|
nsAtomList* pseudoClass = aSelector->mPseudoClassList;
|
1999-03-28 22:22:54 +00:00
|
|
|
PRInt32 eventState = NS_EVENT_STATE_UNSPECIFIED;
|
1999-02-27 07:17:52 +00:00
|
|
|
nsLinkState linkState = nsLinkState(-1); // not a link
|
|
|
|
nsILinkHandler* linkHandler = nsnull;
|
|
|
|
nsIEventStateManager* eventStateManager = nsnull;
|
|
|
|
|
|
|
|
while ((PR_TRUE == result) && (nsnull != pseudoClass)) {
|
|
|
|
if (nsCSSAtoms::firstChildPseudo == pseudoClass->mAtom) {
|
|
|
|
nsIContent* firstChild = nsnull;
|
|
|
|
nsIContent* parent;
|
|
|
|
aContent->GetParent(parent);
|
|
|
|
if (parent) {
|
|
|
|
PRInt32 index = -1;
|
|
|
|
do {
|
|
|
|
parent->ChildAt(++index, firstChild);
|
|
|
|
if (firstChild) { // skip text & comments
|
|
|
|
nsIAtom* tag;
|
|
|
|
firstChild->GetTag(tag);
|
|
|
|
if ((tag != nsLayoutAtoms::textTagName) &&
|
1999-03-31 20:49:25 +00:00
|
|
|
(tag != nsLayoutAtoms::commentTagName) &&
|
|
|
|
(tag != nsLayoutAtoms::processingInstructionTagName)) {
|
1999-02-27 07:17:52 +00:00
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
NS_RELEASE(firstChild);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
1999-01-15 02:07:15 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
} while (1 == 1);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
result = PRBool(aContent == firstChild);
|
|
|
|
NS_IF_RELEASE(firstChild);
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::langPseudo == pseudoClass->mAtom) {
|
|
|
|
// XXX not yet implemented
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (IsEventPseudo(pseudoClass->mAtom)) {
|
1999-04-20 00:05:54 +00:00
|
|
|
if (aTestState) {
|
|
|
|
if (! eventStateManager) {
|
|
|
|
aPresContext->GetEventStateManager(&eventStateManager);
|
|
|
|
if (eventStateManager) {
|
|
|
|
eventStateManager->GetContentState(aContent, eventState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nsCSSAtoms::activePseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(0 != (eventState & NS_EVENT_STATE_ACTIVE));
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::focusPseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(0 != (eventState & NS_EVENT_STATE_FOCUS));
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::hoverPseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(0 != (eventState & NS_EVENT_STATE_HOVER));
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
1999-05-18 23:14:29 +00:00
|
|
|
else if (nsCSSAtoms::dragOverPseudo == pseudoClass->mAtom) {
|
1999-06-22 14:21:27 +00:00
|
|
|
result = PRBool(0 != (eventState & NS_EVENT_STATE_DRAGOVER));
|
1999-05-18 23:14:29 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsLinkPseudo(pseudoClass->mAtom)) {
|
|
|
|
// XXX xml link too
|
|
|
|
if (nsHTMLAtoms::a == contentTag) {
|
1999-04-20 00:05:54 +00:00
|
|
|
if (aTestState) {
|
|
|
|
if (! linkHandler) {
|
|
|
|
aPresContext->GetLinkHandler(&linkHandler);
|
|
|
|
if (linkHandler) {
|
|
|
|
nsAutoString base, href;
|
|
|
|
nsresult attrState = aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::href, href);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* docURL = nsnull;
|
1999-04-20 00:05:54 +00:00
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
|
|
|
|
htmlContent->GetBaseURL(docURL);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
aContent->GetDocument(doc);
|
|
|
|
if (nsnull != doc) {
|
|
|
|
doc->GetBaseURL(docURL);
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
}
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
nsAutoString absURLSpec;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-04-20 00:05:54 +00:00
|
|
|
NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsIURI *baseUri = nsnull;
|
|
|
|
rv = docURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri);
|
|
|
|
if (NS_FAILED(rv)) return PR_FALSE;
|
|
|
|
|
1999-07-11 15:46:10 +00:00
|
|
|
NS_MakeAbsoluteURI(href, baseUri, absURLSpec);
|
1999-06-18 17:34:08 +00:00
|
|
|
NS_RELEASE(baseUri);
|
|
|
|
#endif // NECKO
|
1999-04-20 00:05:54 +00:00
|
|
|
NS_IF_RELEASE(docURL);
|
1999-02-27 07:17:52 +00:00
|
|
|
|
1999-04-21 23:48:41 +00:00
|
|
|
linkHandler->GetLinkState(absURLSpec.GetUnicode(), linkState);
|
1999-04-20 00:05:54 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
}
|
1999-06-21 07:47:29 +00:00
|
|
|
else {
|
|
|
|
// no link handler? then all links are unvisited
|
|
|
|
linkState = eLinkState_Unvisited;
|
|
|
|
}
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
if (nsCSSAtoms::linkPseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(eLinkState_Unvisited == linkState);
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::outOfDatePseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(eLinkState_OutOfDate == linkState);
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::visitedPseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(eLinkState_Visited == linkState);
|
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = PR_FALSE; // not a link
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
else {
|
|
|
|
result = PR_FALSE; // unknown pseudo class
|
|
|
|
}
|
|
|
|
pseudoClass = pseudoClass->mNext;
|
1998-12-11 02:50:43 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(linkHandler);
|
|
|
|
NS_IF_RELEASE(eventStateManager);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
NS_IF_RELEASE(contentTag);
|
1998-04-13 20:24:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-20 20:34:17 +00:00
|
|
|
struct ContentEnumData {
|
|
|
|
ContentEnumData(nsIPresContext* aPresContext, nsIContent* aContent,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext, nsISupportsArray* aResults)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
mContent = aContent;
|
1998-11-03 20:33:43 +00:00
|
|
|
mParentContext = aParentContext;
|
1998-05-20 20:34:17 +00:00
|
|
|
mResults = aResults;
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIContent* mContent;
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* mParentContext;
|
1998-05-20 20:34:17 +00:00
|
|
|
nsISupportsArray* mResults;
|
|
|
|
PRInt32 mCount;
|
|
|
|
};
|
|
|
|
|
1999-02-27 07:17:52 +00:00
|
|
|
static PRBool SelectorMatchesTree(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aLastContent,
|
|
|
|
nsCSSSelector* aSelector)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
1999-02-27 07:17:52 +00:00
|
|
|
nsCSSSelector* selector = aSelector;
|
1998-11-03 20:33:43 +00:00
|
|
|
|
1999-02-27 07:17:52 +00:00
|
|
|
if (selector) {
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIContent* content = nsnull;
|
1999-02-27 07:17:52 +00:00
|
|
|
nsIContent* lastContent = aLastContent;
|
|
|
|
NS_ADDREF(lastContent);
|
|
|
|
while (nsnull != selector) { // check compound selectors
|
|
|
|
if (PRUnichar('+') == selector->mOperator) { // fetch previous sibling
|
|
|
|
nsIContent* parent;
|
|
|
|
PRInt32 index;
|
|
|
|
lastContent->GetParent(parent);
|
|
|
|
if (parent) {
|
|
|
|
parent->IndexOf(lastContent, index);
|
|
|
|
while (0 <= --index) { // skip text & comment nodes
|
|
|
|
parent->ChildAt(index, content);
|
|
|
|
nsIAtom* tag;
|
|
|
|
content->GetTag(tag);
|
|
|
|
if ((tag != nsLayoutAtoms::textTagName) &&
|
|
|
|
(tag != nsLayoutAtoms::commentTagName)) {
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
}
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // fetch parent
|
|
|
|
lastContent->GetParent(content);
|
|
|
|
}
|
|
|
|
if (! content) {
|
|
|
|
break;
|
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
if (SelectorMatches(aPresContext, selector, content, PR_TRUE)) {
|
1998-05-20 20:34:17 +00:00
|
|
|
selector = selector->mNext;
|
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
else {
|
|
|
|
if (PRUnichar(0) != selector->mOperator) {
|
|
|
|
NS_RELEASE(content);
|
|
|
|
break; // parent was required to match
|
|
|
|
}
|
|
|
|
}
|
1998-11-03 20:33:43 +00:00
|
|
|
NS_IF_RELEASE(lastContent);
|
1999-02-27 07:17:52 +00:00
|
|
|
lastContent = content; // take refcount
|
|
|
|
content = nsnull;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
NS_IF_RELEASE(lastContent);
|
|
|
|
}
|
|
|
|
return PRBool(nsnull == selector); // matches if ran out of selectors
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ContentEnumFunc(nsICSSStyleRule* aRule, void* aData)
|
|
|
|
{
|
|
|
|
ContentEnumData* data = (ContentEnumData*)aData;
|
|
|
|
|
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
1999-04-20 00:05:54 +00:00
|
|
|
if (SelectorMatches(data->mPresContext, selector, data->mContent, PR_TRUE)) {
|
1999-02-27 07:17:52 +00:00
|
|
|
selector = selector->mNext;
|
|
|
|
if (SelectorMatchesTree(data->mPresContext, data->mContent, selector)) {
|
1998-05-20 20:34:17 +00:00
|
|
|
nsIStyleRule* iRule;
|
|
|
|
if (NS_OK == aRule->QueryInterface(kIStyleRuleIID, (void**)&iRule)) {
|
|
|
|
data->mResults->AppendElement(iRule);
|
|
|
|
data->mCount++;
|
|
|
|
NS_RELEASE(iRule);
|
1998-09-11 02:07:46 +00:00
|
|
|
iRule = aRule->GetImportantRule();
|
|
|
|
if (nsnull != iRule) {
|
|
|
|
data->mResults->AppendElement(iRule);
|
|
|
|
data->mCount++;
|
|
|
|
NS_RELEASE(iRule);
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_RULES
|
|
|
|
static PRBool ContentEnumWrap(nsISupports* aRule, void* aData)
|
|
|
|
{
|
|
|
|
ContentEnumFunc((nsICSSStyleRule*)aRule, aData);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-04-13 20:24:54 +00:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aContent, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aResults, "null arg");
|
|
|
|
|
|
|
|
PRInt32 matchCount = 0;
|
1998-05-18 21:10:19 +00:00
|
|
|
|
1998-12-02 00:37:32 +00:00
|
|
|
nsIAtom* presMedium = nsnull;
|
1999-06-19 21:18:13 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext->GetMedium(&presMedium);
|
1998-05-18 21:10:19 +00:00
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(presMedium);
|
|
|
|
|
|
|
|
if (cascade) {
|
1998-11-03 20:33:43 +00:00
|
|
|
ContentEnumData data(aPresContext, aContent, aParentContext, aResults);
|
|
|
|
nsIAtom* tagAtom;
|
|
|
|
aContent->GetTag(tagAtom);
|
|
|
|
nsIAtom* idAtom = nsnull;
|
1998-12-20 01:17:05 +00:00
|
|
|
nsVoidArray classArray; // XXX need to recycle this guy (or make nsAutoVoidArray?)
|
1998-11-03 20:33:43 +00:00
|
|
|
|
1999-02-27 01:35:51 +00:00
|
|
|
nsIStyledContent* styledContent;
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(nsIStyledContent::GetIID(), (void**)&styledContent))) {
|
1999-02-27 01:35:51 +00:00
|
|
|
styledContent->GetID(idAtom);
|
|
|
|
styledContent->GetClasses(classArray);
|
|
|
|
NS_RELEASE(styledContent);
|
1998-05-18 21:10:19 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mRuleHash.EnumerateAllRules(tagAtom, idAtom, classArray, ContentEnumFunc, &data);
|
1998-11-03 20:33:43 +00:00
|
|
|
matchCount += data.mCount;
|
1998-05-20 20:34:17 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_RULES
|
1998-11-03 20:33:43 +00:00
|
|
|
nsISupportsArray* list1;
|
|
|
|
nsISupportsArray* list2;
|
|
|
|
NS_NewISupportsArray(&list1);
|
|
|
|
NS_NewISupportsArray(&list2);
|
|
|
|
|
|
|
|
data.mResults = list1;
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mRuleHash.EnumerateAllRules(tagAtom, idAtom, classArray, ContentEnumFunc, &data);
|
1998-11-03 20:33:43 +00:00
|
|
|
data.mResults = list2;
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mWeightedRules->EnumerateBackwards(ContentEnumWrap, &data);
|
1998-11-03 20:33:43 +00:00
|
|
|
NS_ASSERTION(list1->Equals(list2), "lists not equal");
|
|
|
|
NS_RELEASE(list1);
|
|
|
|
NS_RELEASE(list2);
|
1998-05-20 20:34:17 +00:00
|
|
|
#endif
|
1998-05-18 21:10:19 +00:00
|
|
|
|
1998-11-03 20:33:43 +00:00
|
|
|
NS_IF_RELEASE(tagAtom);
|
|
|
|
NS_IF_RELEASE(idAtom);
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1998-12-02 00:37:32 +00:00
|
|
|
NS_IF_RELEASE(presMedium);
|
1998-05-20 20:34:17 +00:00
|
|
|
return matchCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PseudoEnumData {
|
1998-11-03 20:33:43 +00:00
|
|
|
PseudoEnumData(nsIPresContext* aPresContext, nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag, nsIStyleContext* aParentContext,
|
|
|
|
nsISupportsArray* aResults)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
mPresContext = aPresContext;
|
1998-11-03 20:33:43 +00:00
|
|
|
mParentContent = aParentContent;
|
1998-05-20 20:34:17 +00:00
|
|
|
mPseudoTag = aPseudoTag;
|
1998-11-03 20:33:43 +00:00
|
|
|
mParentContext = aParentContext;
|
1998-05-20 20:34:17 +00:00
|
|
|
mResults = aResults;
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresContext* mPresContext;
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIContent* mParentContent;
|
1998-05-20 20:34:17 +00:00
|
|
|
nsIAtom* mPseudoTag;
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* mParentContext;
|
1998-05-20 20:34:17 +00:00
|
|
|
nsISupportsArray* mResults;
|
|
|
|
PRInt32 mCount;
|
|
|
|
};
|
|
|
|
|
1998-10-26 23:19:28 +00:00
|
|
|
static void PseudoEnumFunc(nsICSSStyleRule* aRule, void* aData)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
|
|
|
PseudoEnumData* data = (PseudoEnumData*)aData;
|
|
|
|
|
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
|
|
|
if (selector->mTag == data->mPseudoTag) {
|
|
|
|
selector = selector->mNext;
|
1999-02-27 07:17:52 +00:00
|
|
|
|
|
|
|
if (selector) { // test next selector specially
|
|
|
|
if (PRUnichar('+') == selector->mOperator) {
|
|
|
|
return; // not valid here, can't match
|
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
if (SelectorMatches(data->mPresContext, selector, data->mParentContent, PR_TRUE)) {
|
1998-05-18 21:10:19 +00:00
|
|
|
selector = selector->mNext;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
else {
|
|
|
|
if (PRUnichar('>') == selector->mOperator) {
|
|
|
|
return; // immediate parent didn't match
|
|
|
|
}
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1999-02-27 07:17:52 +00:00
|
|
|
|
|
|
|
if (selector &&
|
|
|
|
(! SelectorMatchesTree(data->mPresContext, data->mParentContent, selector))) {
|
|
|
|
return; // remaining selectors didn't match
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleRule* iRule;
|
|
|
|
if (NS_OK == aRule->QueryInterface(kIStyleRuleIID, (void**)&iRule)) {
|
|
|
|
data->mResults->AppendElement(iRule);
|
|
|
|
data->mCount++;
|
|
|
|
NS_RELEASE(iRule);
|
|
|
|
iRule = aRule->GetImportantRule();
|
|
|
|
if (nsnull != iRule) {
|
1998-05-20 20:34:17 +00:00
|
|
|
data->mResults->AppendElement(iRule);
|
|
|
|
data->mCount++;
|
|
|
|
NS_RELEASE(iRule);
|
1998-05-18 21:10:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-20 20:34:17 +00:00
|
|
|
#ifdef DEBUG_RULES
|
|
|
|
static PRBool PseudoEnumWrap(nsISupports* aRule, void* aData)
|
|
|
|
{
|
|
|
|
PseudoEnumFunc((nsICSSStyleRule*)aRule, aData);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-05-18 21:10:19 +00:00
|
|
|
PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIContent* aParentContent,
|
1998-05-18 21:10:19 +00:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-18 21:10:19 +00:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aPseudoTag, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aResults, "null arg");
|
|
|
|
|
|
|
|
PRInt32 matchCount = 0;
|
|
|
|
|
1998-12-02 00:37:32 +00:00
|
|
|
nsIAtom* presMedium = nsnull;
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext->GetMedium(&presMedium);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(presMedium);
|
|
|
|
|
|
|
|
if (cascade) {
|
1998-11-03 20:33:43 +00:00
|
|
|
PseudoEnumData data(aPresContext, aParentContent, aPseudoTag, aParentContext, aResults);
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mRuleHash.EnumerateTagRules(aPseudoTag, PseudoEnumFunc, &data);
|
1998-05-20 20:34:17 +00:00
|
|
|
matchCount += data.mCount;
|
|
|
|
|
|
|
|
#ifdef DEBUG_RULES
|
|
|
|
nsISupportsArray* list1;
|
|
|
|
nsISupportsArray* list2;
|
|
|
|
NS_NewISupportsArray(&list1);
|
|
|
|
NS_NewISupportsArray(&list2);
|
|
|
|
data.mResults = list1;
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mRuleHash.EnumerateTagRules(aPseudoTag, PseudoEnumFunc, &data);
|
1998-05-20 20:34:17 +00:00
|
|
|
data.mResults = list2;
|
1999-05-26 23:55:12 +00:00
|
|
|
cascade->mWeightedRules->EnumerateBackwards(PseudoEnumWrap, &data);
|
1998-05-20 20:34:17 +00:00
|
|
|
NS_ASSERTION(list1->Equals(list2), "lists not equal");
|
|
|
|
NS_RELEASE(list1);
|
|
|
|
NS_RELEASE(list2);
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-12-02 00:37:32 +00:00
|
|
|
NS_IF_RELEASE(presMedium);
|
1998-04-13 20:24:54 +00:00
|
|
|
return matchCount;
|
|
|
|
}
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
struct StateEnumData
|
|
|
|
{
|
|
|
|
StateEnumData(nsIPresContext* aPresContext, nsIContent* aContent)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mContent(aContent) {}
|
|
|
|
|
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
nsIContent* mContent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
PRBool StateEnumFunc(void* aSelector, void* aData)
|
|
|
|
{
|
|
|
|
StateEnumData* data = (StateEnumData*)aData;
|
|
|
|
|
|
|
|
nsCSSSelector* selector = (nsCSSSelector*)aSelector;
|
|
|
|
if (SelectorMatches(data->mPresContext, selector, data->mContent, PR_FALSE)) {
|
|
|
|
selector = selector->mNext;
|
|
|
|
if (SelectorMatchesTree(data->mPresContext, data->mContent, selector)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PRBool isStateful = PR_FALSE;
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
nsIAtom* presMedium = nsnull;
|
|
|
|
aPresContext->GetMedium(&presMedium);
|
|
|
|
|
|
|
|
RuleCascadeData* cascade = GetRuleCascade(presMedium);
|
|
|
|
|
|
|
|
if (cascade) {
|
|
|
|
// look up content in state rule list
|
|
|
|
StateEnumData data(aPresContext, aContent);
|
|
|
|
isStateful = (! cascade->mStateSelectors.EnumerateForwards(StateEnumFunc, &data)); // if stopped, have state
|
1999-04-20 00:05:54 +00:00
|
|
|
}
|
1999-05-26 23:55:12 +00:00
|
|
|
NS_IF_RELEASE(presMedium);
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
return ((isStateful) ? NS_OK : NS_COMFALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
CSSStyleSheetImpl::Init(nsIURI* aURL)
|
1998-12-03 20:20:35 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL, "null ptr");
|
|
|
|
if (! aURL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (! mInner) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(! mInner->mURL, "already initialized");
|
|
|
|
if (mInner->mURL)
|
1998-12-03 20:20:35 +00:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner->mURL) {
|
1999-06-26 06:36:26 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool eq;
|
|
|
|
nsresult rv = mInner->mURL->Equals(aURL, &eq);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && eq, "bad inner");
|
|
|
|
#endif
|
|
|
|
#else
|
1999-06-03 01:57:52 +00:00
|
|
|
NS_ASSERTION(mInner->mURL->Equals(aURL), "bad inner");
|
1999-06-26 06:36:26 +00:00
|
|
|
#endif
|
1999-06-03 01:57:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mInner->mURL = aURL;
|
|
|
|
NS_ADDREF(mInner->mURL);
|
|
|
|
}
|
1998-12-03 20:20:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
CSSStyleSheetImpl::GetURL(nsIURI*& aURL) const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1999-06-23 03:29:44 +00:00
|
|
|
const nsIURI* url = ((mInner) ? mInner->mURL : nsnull);
|
|
|
|
aURL = (nsIURI*)url;
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IF_ADDREF(aURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle = mTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetTitle(const nsString& aTitle)
|
|
|
|
{
|
|
|
|
mTitle = aTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType.Truncate();
|
|
|
|
aType.Append("text/css");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
1999-05-13 04:56:04 +00:00
|
|
|
if (mMedia) {
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mMedia->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
aCount = cnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aCount = 0;
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-02 00:37:32 +00:00
|
|
|
CSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1998-12-02 00:37:32 +00:00
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
if (nsnull != mMedia) {
|
|
|
|
medium = (nsIAtom*)mMedia->ElementAt(aIndex);
|
|
|
|
}
|
1998-11-26 01:34:53 +00:00
|
|
|
if (nsnull != medium) {
|
1998-12-02 00:37:32 +00:00
|
|
|
aMedium = medium;
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-02 00:37:32 +00:00
|
|
|
aMedium = nsnull;
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
1999-06-15 06:20:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
if (-1 != mMedia->IndexOf(aMedium)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (-1 != mMedia->IndexOf(nsLayoutAtoms::all)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_COMFALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
1998-12-02 00:37:32 +00:00
|
|
|
CSSStyleSheetImpl::AppendMedium(nsIAtom* aMedium)
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1998-12-02 00:37:32 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (nsnull == mMedia) {
|
|
|
|
result = NS_NewISupportsArray(&mMedia);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result) && (nsnull != mMedia)) {
|
|
|
|
mMedia->AppendElement(aMedium);
|
|
|
|
}
|
|
|
|
return result;
|
1998-11-26 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::ClearMedia(void)
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
mMedia->Clear();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
|
|
|
|
{
|
|
|
|
aEnabled = ((PR_TRUE == mDisabled) ? PR_FALSE : PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
PRBool oldState = mDisabled;
|
|
|
|
mDisabled = ((PR_TRUE == aEnabled) ? PR_FALSE : PR_TRUE);
|
|
|
|
|
|
|
|
if ((nsnull != mDocument) && (mDisabled != oldState)) {
|
|
|
|
mDocument->SetStyleSheetDisabledState(this, mDisabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mParent);
|
|
|
|
aParent = mParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-11-26 01:34:53 +00:00
|
|
|
nsIDocument* doc = mDocument;
|
|
|
|
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
|
|
|
|
while ((nsnull == doc) && (nsnull != parent)) {
|
|
|
|
doc = parent->mDocument;
|
|
|
|
parent = (CSSStyleSheetImpl*)(parent->mParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(doc);
|
|
|
|
aDocument = doc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{ // not ref counted
|
|
|
|
mDocument = aDocument;
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode)
|
|
|
|
{ // not ref counted
|
|
|
|
mOwningNode = aOwningNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
CSSStyleSheetImpl::ContainsStyleSheet(nsIURI* aURL) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aURL, "null arg");
|
|
|
|
|
1999-06-26 06:36:26 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
PRBool result;
|
|
|
|
nsresult rv = mInner->mURL->Equals(aURL, &result);
|
|
|
|
if (NS_FAILED(rv)) result = PR_FALSE;
|
|
|
|
#else
|
1999-06-03 01:57:52 +00:00
|
|
|
PRBool result = mInner->mURL->Equals(aURL);
|
1999-06-26 06:36:26 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-05-18 23:14:29 +00:00
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
1998-04-13 20:24:54 +00:00
|
|
|
while ((PR_FALSE == result) && (nsnull != child)) {
|
1999-06-10 05:29:22 +00:00
|
|
|
result = (NS_OK == child->ContainsStyleSheet(aURL));
|
1999-05-18 23:14:29 +00:00
|
|
|
child = child->mNext;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-06-10 05:29:22 +00:00
|
|
|
return ((result) ? NS_OK : NS_COMFALSE);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*)aSheet;
|
1999-05-18 23:14:29 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (! mFirstChild) {
|
|
|
|
mFirstChild = sheet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (child->mNext) {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
child->mNext = sheet;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
DidDirty();
|
|
|
|
}
|
1999-06-10 05:29:22 +00:00
|
|
|
return NS_OK;
|
1999-05-18 23:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult result = WillDirty();
|
1999-05-18 23:14:29 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*)aSheet;
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
|
|
|
|
if (aIndex && child) {
|
|
|
|
while ((0 < --aIndex) && child->mNext) {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
sheet->mNext = child->mNext;
|
|
|
|
child->mNext = sheet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sheet->mNext = mFirstChild;
|
|
|
|
mFirstChild = sheet;
|
1999-05-18 23:14:29 +00:00
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
DidDirty();
|
|
|
|
}
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::PrependStyleRule(nsICSSRule* aRule)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
1998-05-20 20:34:17 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
if (! mInner->mOrderedRules) {
|
|
|
|
NS_NewISupportsArray(&(mInner->mOrderedRules));
|
|
|
|
}
|
|
|
|
if (mInner->mOrderedRules) {
|
|
|
|
mInner->mOrderedRules->InsertElementAt(aRule, 0);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
1999-06-10 05:29:22 +00:00
|
|
|
|
|
|
|
PRInt32 type;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
// no api to prepend a namespace (ugh), release old ones and re-create them all
|
1999-06-15 06:20:46 +00:00
|
|
|
mInner->RebuildNameSpaces();
|
1999-06-10 05:29:22 +00:00
|
|
|
}
|
1999-06-03 01:57:52 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-06-10 05:29:22 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::AppendStyleRule(nsICSSRule* aRule)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
if (! mInner->mOrderedRules) {
|
|
|
|
NS_NewISupportsArray(&(mInner->mOrderedRules));
|
|
|
|
}
|
|
|
|
if (mInner->mOrderedRules) {
|
|
|
|
mInner->mOrderedRules->AppendElement(aRule);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
1999-06-10 05:29:22 +00:00
|
|
|
|
|
|
|
PRInt32 type;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
if (! mInner->mNameSpace) {
|
|
|
|
nsINameSpaceManager* nameSpaceMgr;
|
|
|
|
NS_NewNameSpaceManager(&nameSpaceMgr);
|
|
|
|
if (nameSpaceMgr) {
|
|
|
|
nameSpaceMgr->CreateRootNameSpace(mInner->mNameSpace);
|
|
|
|
NS_RELEASE(nameSpaceMgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInner->mNameSpace) {
|
|
|
|
nsICSSNameSpaceRule* nameSpaceRule = (nsICSSNameSpaceRule*)aRule;
|
|
|
|
nsINameSpace* newNameSpace = nsnull;
|
|
|
|
|
|
|
|
nsIAtom* prefix = nsnull;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(prefix);
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
mInner->mNameSpace->CreateChildNameSpace(prefix, urlSpec, newNameSpace);
|
|
|
|
NS_IF_RELEASE(prefix);
|
|
|
|
if (newNameSpace) {
|
|
|
|
NS_RELEASE(mInner->mNameSpace);
|
|
|
|
mInner->mNameSpace = newNameSpace; // takes ref
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-06-03 01:57:52 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-06-10 05:29:22 +00:00
|
|
|
return NS_OK;
|
1998-06-05 06:06:50 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::StyleRuleCount(PRInt32& aCount) const
|
1998-06-05 06:06:50 +00:00
|
|
|
{
|
1999-06-10 05:29:22 +00:00
|
|
|
aCount = 0;
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult rv = ((CSSStyleSheetImpl*)this)->mInner->mOrderedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
1999-06-10 05:29:22 +00:00
|
|
|
aCount = (PRInt32)cnt;
|
|
|
|
return rv;
|
1998-06-05 06:06:50 +00:00
|
|
|
}
|
1999-06-10 05:29:22 +00:00
|
|
|
return NS_OK;
|
1998-06-05 06:06:50 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
|
1998-06-05 06:06:50 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
1999-06-10 05:29:22 +00:00
|
|
|
aRule = (nsICSSRule*)(mInner->mOrderedRules->ElementAt(aIndex));
|
1998-06-05 06:06:50 +00:00
|
|
|
if (nsnull != aRule) {
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRule = nsnull;
|
|
|
|
}
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetNameSpace(nsINameSpace*& aNameSpace) const
|
|
|
|
{
|
|
|
|
aNameSpace = ((mInner) ? mInner->mNameSpace : nsnull);
|
|
|
|
NS_IF_ADDREF(aNameSpace);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-15 06:20:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetDefaultNameSpaceID(PRInt32 aDefaultNameSpaceID)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
mInner->mDefaultNameSpaceID = aDefaultNameSpaceID;
|
|
|
|
mInner->RebuildNameSpaces();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::StyleSheetCount(PRInt32& aCount) const
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
// XXX Far from an ideal way to do this, but the hope is that
|
|
|
|
// it won't be done too often. If it is, we might want to
|
|
|
|
// consider storing the children in an array.
|
1999-06-10 05:29:22 +00:00
|
|
|
aCount = 0;
|
1999-05-18 23:14:29 +00:00
|
|
|
|
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (child) {
|
1999-06-10 05:29:22 +00:00
|
|
|
aCount++;
|
1999-05-18 23:14:29 +00:00
|
|
|
child = child->mNext;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
return NS_OK;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
|
|
|
// that this isn't done too often. If it is, we need to change the
|
|
|
|
// underlying storage mechanism
|
|
|
|
aSheet = nsnull;
|
1999-05-18 23:14:29 +00:00
|
|
|
|
|
|
|
if (mFirstChild) {
|
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while ((child) && (0 != aIndex)) {
|
1998-10-06 01:39:33 +00:00
|
|
|
--aIndex;
|
1999-05-18 23:14:29 +00:00
|
|
|
child = child->mNext;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 04:53:49 +00:00
|
|
|
aSheet = (nsICSSStyleSheet*)child;
|
|
|
|
NS_IF_ADDREF(aSheet);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::EnsureUniqueInner(void)
|
|
|
|
{
|
|
|
|
if (! mInner) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
if (1 < mInner->mSheets.Count()) {
|
|
|
|
CSSStyleSheetInner* clone = mInner->CloneFor(this);
|
|
|
|
if (clone) {
|
|
|
|
mInner->RemoveSheet(this);
|
|
|
|
mInner = clone;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-18 23:14:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::Clone(nsICSSStyleSheet*& aClone) const
|
|
|
|
{
|
|
|
|
// XXX no, really need to clone
|
1999-06-03 01:57:52 +00:00
|
|
|
CSSStyleSheetImpl* clone = new CSSStyleSheetImpl(*this);
|
|
|
|
if (clone) {
|
|
|
|
aClone = (nsICSSStyleSheet*)clone;
|
|
|
|
NS_ADDREF(aClone);
|
|
|
|
}
|
1999-05-18 23:14:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
static void
|
|
|
|
ListRules(nsISupportsArray* aRules, FILE* aOut, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
PRUint32 count;
|
|
|
|
PRUint32 index;
|
|
|
|
if (aRules) {
|
|
|
|
aRules->Count(&count);
|
|
|
|
for (index = 0; index < count; index++) {
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRules->ElementAt(index);
|
1999-05-26 23:55:12 +00:00
|
|
|
rule->List(aOut, aIndent);
|
1999-06-10 05:29:22 +00:00
|
|
|
NS_RELEASE(rule);
|
1999-05-26 23:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ListEnumData {
|
|
|
|
ListEnumData(FILE* aOut, PRInt32 aIndent)
|
|
|
|
: mOut(aOut),
|
|
|
|
mIndent(aIndent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FILE* mOut;
|
|
|
|
PRInt32 mIndent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool ListCascade(nsHashKey* aKey, void* aValue, void* aClosure)
|
|
|
|
{
|
|
|
|
AtomKey* key = (AtomKey*)aKey;
|
|
|
|
RuleCascadeData* cascade = (RuleCascadeData*)aValue;
|
|
|
|
ListEnumData* data = (ListEnumData*)aClosure;
|
|
|
|
|
|
|
|
fputs("\nRules in cascade order for medium: \"", data->mOut);
|
|
|
|
nsAutoString buffer;
|
|
|
|
key->mAtom->ToString(buffer);
|
|
|
|
fputs(buffer, data->mOut);
|
|
|
|
fputs("\"\n", data->mOut);
|
|
|
|
|
|
|
|
ListRules(cascade->mWeightedRules, data->mOut, data->mIndent);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
1999-06-03 01:57:52 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (! mInner) {
|
|
|
|
fputs("CSS Style Sheet - without inner data storage - ERROR\n", out);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
fputs("CSS Style Sheet: ", out);
|
1999-06-26 06:36:26 +00:00
|
|
|
#ifdef NECKO
|
1999-06-27 21:16:16 +00:00
|
|
|
char* urlSpec = nsnull;
|
|
|
|
nsresult rv = mInner->mURL->GetSpec(&urlSpec);
|
|
|
|
if (urlSpec) {
|
|
|
|
fputs(urlSpec, out);
|
|
|
|
nsCRT::free(urlSpec);
|
|
|
|
}
|
1999-06-26 06:36:26 +00:00
|
|
|
#else
|
1999-06-27 21:16:16 +00:00
|
|
|
PRUnichar* urlSpec = nsnull;
|
|
|
|
mInner->mURL->ToString(&urlSpec);
|
|
|
|
if (urlSpec) {
|
|
|
|
nsAutoString buffer(urlSpec);
|
|
|
|
delete [] urlSpec;
|
|
|
|
fputs(buffer, out);
|
|
|
|
}
|
1999-06-27 20:42:45 +00:00
|
|
|
#endif
|
1999-06-03 01:57:52 +00:00
|
|
|
|
|
|
|
if (mMedia) {
|
|
|
|
fputs(" media: ", out);
|
1999-07-18 00:27:40 +00:00
|
|
|
index = 0;
|
1999-06-03 01:57:52 +00:00
|
|
|
PRUint32 count;
|
|
|
|
mMedia->Count(&count);
|
1999-06-27 21:16:16 +00:00
|
|
|
nsAutoString buffer;
|
1999-07-18 00:27:40 +00:00
|
|
|
while (index < PRInt32(count)) {
|
1999-06-03 01:57:52 +00:00
|
|
|
nsIAtom* medium = (nsIAtom*)mMedia->ElementAt(index++);
|
1999-06-27 21:16:16 +00:00
|
|
|
medium->ToString(buffer);
|
|
|
|
fputs(buffer, out);
|
1999-07-18 00:27:40 +00:00
|
|
|
if (index < PRInt32(count)) {
|
1999-06-03 01:57:52 +00:00
|
|
|
fputs(", ", out);
|
|
|
|
}
|
|
|
|
NS_RELEASE(medium);
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
fputs("\n", out);
|
|
|
|
|
1999-05-18 23:14:29 +00:00
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
1998-04-13 20:24:54 +00:00
|
|
|
while (nsnull != child) {
|
|
|
|
child->List(out, aIndent + 1);
|
1999-05-18 23:14:29 +00:00
|
|
|
child = child->mNext;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
fputs("Rules in source order:\n", out);
|
1999-06-03 01:57:52 +00:00
|
|
|
ListRules(mInner->mOrderedRules, out, aIndent);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner->mMediumCascadeTable) {
|
1999-05-26 23:55:12 +00:00
|
|
|
ListEnumData data(out, aIndent);
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->mMediumCascadeTable->Enumerate(ListCascade, &data);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
void
|
|
|
|
CSSStyleSheetImpl::ClearRuleCascades(void)
|
1999-05-26 23:55:12 +00:00
|
|
|
{
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->ClearRuleCascades();
|
1999-05-26 23:55:12 +00:00
|
|
|
if (mParent) {
|
|
|
|
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
|
|
|
|
parent->ClearRuleCascades();
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::WillDirty(void)
|
|
|
|
{
|
|
|
|
return EnsureUniqueInner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSStyleSheetImpl::DidDirty(void)
|
|
|
|
{
|
|
|
|
ClearRuleCascades();
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::IsUnmodified(void) const
|
|
|
|
{
|
|
|
|
return ((mDirty) ? NS_COMFALSE : NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetModified(PRBool aModified)
|
|
|
|
{
|
|
|
|
mDirty = aModified;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-06 18:41:05 +00:00
|
|
|
static
|
1998-05-20 20:34:17 +00:00
|
|
|
PRBool BuildHashEnum(nsISupports* aRule, void* aHash)
|
|
|
|
{
|
|
|
|
nsICSSStyleRule* rule = (nsICSSStyleRule*)aRule;
|
|
|
|
RuleHash* hash = (RuleHash*)aHash;
|
|
|
|
hash->AppendRule(rule);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
static
|
|
|
|
PRBool IsStateSelector(nsCSSSelector& aSelector)
|
|
|
|
{
|
|
|
|
nsAtomList* pseudoClass = aSelector.mPseudoClassList;
|
|
|
|
while (pseudoClass) {
|
|
|
|
if ((pseudoClass->mAtom == nsCSSAtoms::activePseudo) ||
|
1999-07-18 00:27:40 +00:00
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::checkedPseudo) ||
|
1999-04-20 00:05:54 +00:00
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::disabledPseudo) ||
|
1999-05-18 23:14:29 +00:00
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::dragOverPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::dragPseudo) ||
|
1999-04-20 00:05:54 +00:00
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::enabledPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::focusPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::hoverPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::linkPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::outOfDatePseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::selectionPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::visitedPseudo)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
pseudoClass = pseudoClass->mNext;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
PRBool BuildStateEnum(nsISupports* aRule, void* aArray)
|
|
|
|
{
|
|
|
|
nsICSSStyleRule* rule = (nsICSSStyleRule*)aRule;
|
|
|
|
nsVoidArray* array = (nsVoidArray*)aArray;
|
|
|
|
|
|
|
|
nsCSSSelector* selector = rule->FirstSelector();
|
|
|
|
|
|
|
|
while (selector) {
|
|
|
|
if (IsStateSelector(*selector)) {
|
|
|
|
array->AppendElement(selector);
|
|
|
|
}
|
|
|
|
selector = selector->mNext;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
struct CascadeEnumData {
|
|
|
|
CascadeEnumData(nsIAtom* aMedium, nsISupportsArray* aRules)
|
|
|
|
: mMedium(aMedium),
|
|
|
|
mRules(aRules)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
nsIAtom* mMedium;
|
|
|
|
nsISupportsArray* mRules;
|
|
|
|
};
|
|
|
|
|
1999-06-15 06:20:46 +00:00
|
|
|
static PRBool
|
|
|
|
GatherStyleRulesForMedium(nsISupports* aRule, void* aData)
|
|
|
|
{
|
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
|
|
|
PRInt32 type;
|
|
|
|
rule->GetType(type);
|
|
|
|
|
|
|
|
if (nsICSSRule::STYLE_RULE == type) {
|
|
|
|
nsICSSStyleRule* styleRule = (nsICSSStyleRule*)rule;
|
|
|
|
data->mRules->AppendElement(styleRule);
|
|
|
|
}
|
|
|
|
else if (nsICSSRule::MEDIA_RULE == type) {
|
|
|
|
nsICSSMediaRule* mediaRule = (nsICSSMediaRule*)rule;
|
|
|
|
if (NS_OK == mediaRule->UseForMedium(data->mMedium)) {
|
|
|
|
mediaRule->EnumerateRulesForwards(GatherStyleRulesForMedium, aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::GatherRulesFor(nsIAtom* aMedium, nsISupportsArray* aRules)
|
|
|
|
{
|
|
|
|
if (aRules) {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (nsnull != child) {
|
|
|
|
if (NS_OK == child->UseForMedium(aMedium)) {
|
|
|
|
child->GatherRulesFor(aMedium, aRules);
|
|
|
|
}
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInner && mInner->mOrderedRules) {
|
|
|
|
CascadeEnumData data(aMedium, aRules);
|
|
|
|
mInner->mOrderedRules->EnumerateForwards(GatherStyleRulesForMedium, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_CASCADE
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
struct WeightEnumData {
|
|
|
|
WeightEnumData(PRInt32 aWeight)
|
|
|
|
: mWeight(aWeight),
|
|
|
|
mIndex(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PRInt32 mWeight;
|
|
|
|
PRInt32 mIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
FindEndOfWeight(nsISupports* aRule, void* aData)
|
|
|
|
{
|
|
|
|
nsICSSStyleRule* rule = (nsICSSStyleRule*)aRule;
|
|
|
|
WeightEnumData* data = (WeightEnumData*)aData;
|
|
|
|
if (rule->GetWeight() <= data->mWeight) {
|
|
|
|
return PR_FALSE; // stop loop
|
|
|
|
}
|
|
|
|
data->mIndex++;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
InsertRuleByWeight(nsISupports* aRule, void* aData)
|
1998-05-20 20:34:17 +00:00
|
|
|
{
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
1999-05-26 23:55:12 +00:00
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
1999-06-10 05:29:22 +00:00
|
|
|
PRInt32 type;
|
|
|
|
rule->GetType(type);
|
|
|
|
|
|
|
|
if (nsICSSRule::STYLE_RULE == type) {
|
|
|
|
nsICSSStyleRule* styleRule = (nsICSSStyleRule*)rule;
|
1999-05-26 23:55:12 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
WeightEnumData weight(styleRule->GetWeight());
|
|
|
|
data->mRules->EnumerateForwards(FindEndOfWeight, &weight);
|
1998-05-20 20:34:17 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
data->mRules->InsertElementAt(styleRule, weight.mIndex);
|
|
|
|
}
|
|
|
|
else if (nsICSSRule::MEDIA_RULE == type) {
|
|
|
|
nsICSSMediaRule* mediaRule = (nsICSSMediaRule*)rule;
|
1999-06-15 06:20:46 +00:00
|
|
|
if (NS_OK == mediaRule->UseForMedium(data->mMedium)) {
|
1999-06-10 05:29:22 +00:00
|
|
|
mediaRule->EnumerateRulesForwards(InsertRuleByWeight, aData);
|
|
|
|
}
|
|
|
|
}
|
1999-05-26 23:55:12 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-06-15 06:20:46 +00:00
|
|
|
CSSStyleSheetImpl::SlowCascadeRulesInto(nsIAtom* aMedium, nsISupportsArray* aRules)
|
1999-05-26 23:55:12 +00:00
|
|
|
{
|
|
|
|
if (aRules) {
|
|
|
|
// get child rules first
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (nsnull != child) {
|
1999-06-15 06:20:46 +00:00
|
|
|
if (NS_OK == child->UseForMedium(aMedium)) {
|
|
|
|
child->SlowCascadeRulesInto(aMedium, aRules);
|
1999-05-26 23:55:12 +00:00
|
|
|
}
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
1999-06-15 06:20:46 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
1999-05-26 23:55:12 +00:00
|
|
|
CascadeEnumData data(aMedium, aRules);
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->mOrderedRules->EnumerateForwards(InsertRuleByWeight, &data);
|
1999-05-26 23:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-15 06:20:46 +00:00
|
|
|
#endif
|
|
|
|
|
1999-07-18 00:27:40 +00:00
|
|
|
#ifdef FAST_CASCADE
|
1999-06-15 06:20:46 +00:00
|
|
|
static PRInt32
|
|
|
|
CompareStyleRuleWeight(nsISupports* aRule1, nsISupports* aRule2, void* aData)
|
|
|
|
{
|
|
|
|
nsICSSStyleRule* rule1 = (nsICSSStyleRule*)aRule1;
|
|
|
|
nsICSSStyleRule* rule2 = (nsICSSStyleRule*)aRule2;
|
|
|
|
return (rule2->GetWeight() - rule1->GetWeight());
|
|
|
|
}
|
1999-07-18 00:27:40 +00:00
|
|
|
#endif
|
1999-06-15 06:20:46 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::CascadeRulesInto(nsIAtom* aMedium, nsISupportsArray* aRules)
|
|
|
|
{
|
|
|
|
#ifdef FAST_CASCADE
|
|
|
|
if (aRules) {
|
|
|
|
GatherRulesFor(aMedium, aRules);
|
|
|
|
aRules->ShellSort(CompareStyleRuleWeight, nsnull);
|
|
|
|
|
|
|
|
#ifdef DEBUG_CASCADE
|
|
|
|
nsISupportsArray* verifyArray = nsnull;
|
|
|
|
NS_NewISupportsArray(&verifyArray);
|
|
|
|
if (verifyArray) {
|
|
|
|
SlowCascadeRulesInto(aMedium, verifyArray);
|
|
|
|
NS_ASSERTION(verifyArray->Equals(aRules), "fast cascade failed");
|
|
|
|
NS_RELEASE(verifyArray);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return SlowCascadeRulesInto(aMedium, aRules);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-05-26 23:55:12 +00:00
|
|
|
|
|
|
|
RuleCascadeData*
|
|
|
|
CSSStyleSheetImpl::GetRuleCascade(nsIAtom* aMedium)
|
|
|
|
{
|
|
|
|
AtomKey mediumKey(aMedium);
|
|
|
|
RuleCascadeData* cascade = nsnull;
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner) {
|
|
|
|
if (mInner->mMediumCascadeTable) {
|
|
|
|
cascade = (RuleCascadeData*)mInner->mMediumCascadeTable->Get(&mediumKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! cascade) {
|
|
|
|
if (mInner->mOrderedRules || mFirstChild) {
|
|
|
|
if (! mInner->mMediumCascadeTable) {
|
|
|
|
mInner->mMediumCascadeTable = new nsHashtable();
|
|
|
|
}
|
|
|
|
if (mInner->mMediumCascadeTable) {
|
|
|
|
cascade = new RuleCascadeData();
|
|
|
|
if (cascade) {
|
|
|
|
mInner->mMediumCascadeTable->Put(&mediumKey, cascade);
|
|
|
|
|
|
|
|
CascadeRulesInto(aMedium, cascade->mWeightedRules);
|
|
|
|
cascade->mWeightedRules->EnumerateBackwards(BuildHashEnum, &(cascade->mRuleHash));
|
|
|
|
cascade->mWeightedRules->EnumerateBackwards(BuildStateEnum, &(cascade->mStateSelectors));
|
|
|
|
}
|
1999-05-26 23:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
1999-05-26 23:55:12 +00:00
|
|
|
return cascade;
|
1998-05-20 20:34:17 +00:00
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetType(nsString& aType)
|
|
|
|
{
|
|
|
|
aType.Truncate();
|
|
|
|
aType.Append("text/css");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
|
|
|
|
{
|
1998-11-17 02:14:38 +00:00
|
|
|
*aDisabled = mDisabled;
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
|
|
|
|
{
|
1998-11-26 01:34:53 +00:00
|
|
|
PRBool oldState = mDisabled;
|
|
|
|
mDisabled = aDisabled;
|
1998-11-17 02:14:38 +00:00
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
if ((nsnull != mDocument) && (mDisabled != oldState)) {
|
|
|
|
mDocument->SetStyleSheetDisabledState(this, mDisabled);
|
1998-11-17 02:14:38 +00:00
|
|
|
}
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
|
|
|
|
{
|
|
|
|
// XXX TBI
|
|
|
|
*aReadOnly = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSStyleSheetImpl::GetOwningNode(nsIDOMNode** aOwningNode)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IF_ADDREF(mOwningNode);
|
|
|
|
*aOwningNode = mOwningNode;
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mParent) {
|
1998-11-26 01:34:53 +00:00
|
|
|
return mParent->QueryInterface(kIDOMStyleSheetIID, (void **)aParentStyleSheet);
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aParentStyleSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetHref(nsString& aHref)
|
|
|
|
{
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mURL) {
|
1999-06-26 06:36:26 +00:00
|
|
|
#ifdef NECKO
|
1999-06-27 21:16:16 +00:00
|
|
|
char* str = nsnull;
|
1999-06-26 06:36:26 +00:00
|
|
|
mInner->mURL->GetSpec(&str);
|
|
|
|
aHref = str;
|
1999-06-27 21:16:16 +00:00
|
|
|
if (str) {
|
|
|
|
nsCRT::free(str);
|
|
|
|
}
|
1999-06-26 06:36:26 +00:00
|
|
|
#else
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUnichar* str;
|
1999-06-03 01:57:52 +00:00
|
|
|
mInner->mURL->ToString(&str);
|
1998-12-16 05:40:20 +00:00
|
|
|
aHref = str;
|
1999-06-03 01:57:52 +00:00
|
|
|
delete [] str;
|
1999-06-26 06:36:26 +00:00
|
|
|
#endif
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aHref.SetLength(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-06 01:39:33 +00:00
|
|
|
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
|
|
|
|
{
|
1998-11-26 01:34:53 +00:00
|
|
|
aTitle = mTitle;
|
1998-10-06 01:39:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetMedia(nsString& aMedia)
|
|
|
|
{
|
|
|
|
aMedia.Truncate();
|
1998-12-02 00:37:32 +00:00
|
|
|
if (nsnull != mMedia) {
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mMedia->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
PRInt32 count = cnt;
|
1998-12-02 00:37:32 +00:00
|
|
|
PRInt32 index = 0;
|
|
|
|
nsAutoString buffer;
|
|
|
|
while (index < count) {
|
|
|
|
nsIAtom* medium = (nsIAtom*)mMedia->ElementAt(index++);
|
|
|
|
medium->ToString(buffer);
|
|
|
|
aMedia.Append(buffer);
|
|
|
|
if (index < count) {
|
|
|
|
aMedia.Append(", ");
|
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSStyleSheetImpl::GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
|
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
*aCssRules = mRuleCollection;
|
1998-10-06 01:39:33 +00:00
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSStyleSheetImpl::InsertRule(const nsString& aRule,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* aReturn)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
|
|
|
nsICSSParser* css;
|
1999-06-03 01:57:52 +00:00
|
|
|
// XXX should get parser from CSS loader
|
1998-10-06 01:39:33 +00:00
|
|
|
nsresult result = NS_NewCSSParser(&css);
|
|
|
|
if (NS_OK == result) {
|
1999-03-10 01:17:49 +00:00
|
|
|
nsString* str = new nsString(aRule); // will be deleted by the input stream
|
1998-10-06 01:39:33 +00:00
|
|
|
nsIUnicharInputStream* input = nsnull;
|
1999-03-10 01:17:49 +00:00
|
|
|
result = NS_NewStringUnicharInputStream(&input, str);
|
1998-10-06 01:39:33 +00:00
|
|
|
if (NS_OK == result) {
|
1998-11-26 01:34:53 +00:00
|
|
|
nsICSSStyleSheet* tmp;
|
1998-10-06 01:39:33 +00:00
|
|
|
css->SetStyleSheet(this);
|
|
|
|
// XXX Currently, the parser will append the rule to the
|
|
|
|
// style sheet. We shouldn't ignore the index.
|
1999-06-03 01:57:52 +00:00
|
|
|
result = css->Parse(input, mInner->mURL, tmp);
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
|
|
|
|
NS_RELEASE(tmp);
|
1998-10-06 01:39:33 +00:00
|
|
|
NS_RELEASE(input);
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
|
|
|
result = mInner->mOrderedRules->Count(&cnt);
|
1999-05-26 23:55:12 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
*aReturn = cnt;
|
|
|
|
if (nsnull != mDocument) {
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule* rule;
|
1999-05-26 23:55:12 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
rule = (nsICSSRule*)(mInner->mOrderedRules->ElementAt(aIndex));
|
1999-05-26 23:55:12 +00:00
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
|
|
|
NS_IF_RELEASE(rule);
|
|
|
|
}
|
1999-05-13 04:56:04 +00:00
|
|
|
}
|
1999-03-10 01:17:49 +00:00
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(css);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-26 01:34:53 +00:00
|
|
|
CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex)
|
1998-10-06 01:39:33 +00:00
|
|
|
{
|
1999-06-03 01:57:52 +00:00
|
|
|
nsresult result = NS_ERROR_INVALID_ARG;
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
// XXX TBI: handle @rule types
|
1999-06-03 01:57:52 +00:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
|
|
|
result = WillDirty();
|
1998-10-06 01:39:33 +00:00
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-06-10 05:29:22 +00:00
|
|
|
nsICSSRule *rule;
|
1999-06-03 01:57:52 +00:00
|
|
|
|
1999-06-10 05:29:22 +00:00
|
|
|
rule = (nsICSSRule*)(mInner->mOrderedRules->ElementAt(aIndex));
|
1999-06-03 01:57:52 +00:00
|
|
|
if (nsnull != rule) {
|
|
|
|
mInner->mOrderedRules->RemoveElementAt(aIndex);
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
DidDirty();
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
1999-05-26 23:55:12 +00:00
|
|
|
}
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
1999-06-03 01:57:52 +00:00
|
|
|
return result;
|
1998-10-06 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
|
|
|
|
|
|
|
if (nsnull == mScriptObject) {
|
|
|
|
nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this;
|
|
|
|
// XXX Should be done through factory
|
|
|
|
res = NS_NewScriptCSSStyleSheet(aContext,
|
|
|
|
supports,
|
|
|
|
(nsISupports *)global,
|
|
|
|
(void**)&mScriptObject);
|
|
|
|
}
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
|
|
|
|
NS_RELEASE(global);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetScriptObject(void* aScriptObject)
|
|
|
|
{
|
|
|
|
mScriptObject = aScriptObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
|
|
|
|
// XXX for backwards compatibility and convenience
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_HTML nsresult
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL)
|
1998-12-03 20:20:35 +00:00
|
|
|
{
|
|
|
|
nsICSSStyleSheet* sheet;
|
|
|
|
nsresult rv;
|
|
|
|
if (NS_FAILED(rv = NS_NewCSSStyleSheet(&sheet)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = sheet->Init(aURL))) {
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = sheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_HTML nsresult
|
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
CSSStyleSheetImpl *it = new CSSStyleSheetImpl();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|