2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-02-13 17:06:29 +03:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-27 04:35:51 +03:00
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
2002-03-22 09:28:16 +03:00
|
|
|
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
|
|
|
#define NS_RULEHASH_ARENA_BLOCK_SIZE (256)
|
|
|
|
#include "plarena.h"
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsIArena.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsISupportsArray.h"
|
1998-05-21 00:34:17 +04:00
|
|
|
#include "nsHashtable.h"
|
2001-02-16 00:25:31 +03:00
|
|
|
#include "nsICSSPseudoComparator.h"
|
1999-10-08 07:09:31 +04:00
|
|
|
#include "nsICSSStyleRuleProcessor.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-06-10 09:29:22 +04:00
|
|
|
#include "nsICSSNameSpaceRule.h"
|
|
|
|
#include "nsICSSMediaRule.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIMediaList.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-05-19 04:09:29 +04:00
|
|
|
#include "nsIDocument.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
1998-05-19 04:09:29 +04:00
|
|
|
#include "nsIPresContext.h"
|
1999-02-27 10:17:52 +03:00
|
|
|
#include "nsIEventStateManager.h"
|
1998-05-19 04:09:29 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-12-02 03:37:32 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-10-13 04:16:32 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsVoidArray.h"
|
2001-01-27 19:58:15 +03:00
|
|
|
#include "nsIUnicharInputStream.h"
|
1998-09-05 08:00:06 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
2000-06-02 08:27:47 +04:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
2000-06-22 03:48:21 +04:00
|
|
|
#include "nsIDOMHTMLLinkElement.h"
|
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
2002-03-13 13:12:33 +03:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2002-03-07 06:34:29 +03:00
|
|
|
#include "nsIDOMHTMLOptionElement.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsIDOMStyleSheetList.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSStyleRule.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsIDOMCSSRuleList.h"
|
|
|
|
#include "nsIDOMMediaList.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsDOMError.h"
|
2001-03-13 05:34:02 +03:00
|
|
|
#include "nsIPresShell.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsICSSParser.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsICSSLoader.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
1998-12-11 05:50:43 +03:00
|
|
|
#include "nsCSSAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
1999-06-10 09:29:22 +04:00
|
|
|
#include "nsINameSpace.h"
|
1999-09-11 04:08:30 +04:00
|
|
|
#include "nsITextContent.h"
|
1998-12-03 23:20:35 +03:00
|
|
|
#include "prlog.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsISizeOfHandler.h"
|
2000-07-28 03:17:53 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2001-04-28 06:16:16 +04:00
|
|
|
#include "nsQuickSort.h"
|
2001-02-22 06:01:34 +03:00
|
|
|
#ifdef MOZ_XUL
|
2001-01-27 08:48:41 +03:00
|
|
|
#include "nsIXULContent.h"
|
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
//#define DEBUG_HASH
|
2001-10-19 18:02:36 +04:00
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
#ifdef DEBUG_HASH
|
|
|
|
static void DebugHashCount(PRBool hash) {
|
|
|
|
static gCountHash = 0;
|
|
|
|
static gCountCompStr = 0;
|
|
|
|
if (hash) {
|
|
|
|
if (++gCountHash % 100 == 0) {
|
|
|
|
printf("gCountHash = %ld\n", gCountHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (++gCountCompStr % 100 == 0) {
|
|
|
|
printf("gCountCompStr = %ld\n", gCountCompStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //DEBUG_HASH
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
// ----------------------
|
2001-06-05 05:00:11 +04:00
|
|
|
// Rule hash keys
|
1998-05-21 00:34:17 +04:00
|
|
|
//
|
2001-06-05 05:00:11 +04:00
|
|
|
// An |AtomKey| is to be used for storage in the hashtable, and a
|
|
|
|
// |DependentAtomKey| should be used on the stack to avoid the performance
|
|
|
|
// cost of refcounting an atom that one is assured to own for the lifetime
|
|
|
|
// of the key.
|
|
|
|
|
|
|
|
class AtomKey_base : public nsHashKey {
|
1998-05-21 00:34:17 +04:00
|
|
|
public:
|
2000-08-10 10:19:37 +04:00
|
|
|
virtual PRUint32 HashCode(void) const;
|
1998-05-21 00:34:17 +04:00
|
|
|
virtual PRBool Equals(const nsHashKey *aKey) const;
|
2001-09-07 04:23:37 +04:00
|
|
|
virtual void SetKeyCaseSensitive(PRBool aCaseSensitive);
|
1998-05-21 00:34:17 +04:00
|
|
|
nsIAtom* mAtom;
|
2001-09-07 04:23:37 +04:00
|
|
|
PRBool mCaseSensitive;
|
1998-05-21 00:34:17 +04:00
|
|
|
};
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
class AtomKey : public AtomKey_base {
|
|
|
|
public:
|
|
|
|
AtomKey(nsIAtom* aAtom);
|
|
|
|
AtomKey(const AtomKey_base& aKey);
|
|
|
|
virtual ~AtomKey(void);
|
|
|
|
virtual nsHashKey *Clone(void) const;
|
|
|
|
};
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
class DependentAtomKey : public AtomKey_base {
|
|
|
|
public:
|
|
|
|
DependentAtomKey(nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
mAtom = aAtom;
|
2001-09-07 04:23:37 +04:00
|
|
|
SetKeyCaseSensitive(PR_TRUE);
|
2001-06-05 05:00:11 +04:00
|
|
|
}
|
|
|
|
DependentAtomKey(const DependentAtomKey& aKey);
|
|
|
|
virtual ~DependentAtomKey(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual nsHashKey *Clone(void) const;
|
|
|
|
};
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
void AtomKey_base::SetKeyCaseSensitive(PRBool aCaseSensitive)
|
|
|
|
{
|
|
|
|
mCaseSensitive = aCaseSensitive;
|
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
PRUint32 AtomKey_base::HashCode(void) const
|
|
|
|
{
|
2001-09-07 04:23:37 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
return NS_PTR_TO_INT32(mAtom);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef DEBUG_HASH
|
2002-04-16 02:49:26 +04:00
|
|
|
DebugHashCount(PR_TRUE);
|
2001-09-07 04:23:37 +04:00
|
|
|
#endif
|
|
|
|
nsAutoString myStr;
|
|
|
|
mAtom->ToString(myStr);
|
2001-12-17 10:14:49 +03:00
|
|
|
ToUpperCase(myStr);
|
2001-09-07 04:23:37 +04:00
|
|
|
return nsCRT::HashCode(myStr.get());
|
|
|
|
}
|
2001-06-05 05:00:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool AtomKey_base::Equals(const nsHashKey* aKey) const
|
|
|
|
{
|
2001-09-07 04:23:37 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
return PRBool (((AtomKey_base*)aKey)->mAtom == mAtom);
|
|
|
|
}
|
|
|
|
|
2001-10-13 04:16:32 +04:00
|
|
|
// first try case-sensitive match
|
|
|
|
if (((AtomKey_base*)aKey)->mAtom == mAtom)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
#ifdef DEBUG_HASH
|
|
|
|
DebugHashCount(PR_FALSE);
|
|
|
|
#endif
|
|
|
|
const PRUnichar *myStr = nsnull;
|
|
|
|
mAtom->GetUnicode(&myStr);
|
|
|
|
|
|
|
|
nsIAtom* theirAtom = ((AtomKey_base*)aKey)->mAtom;
|
|
|
|
|
|
|
|
const PRUnichar *theirStr = nsnull;
|
|
|
|
theirAtom->GetUnicode(&theirStr);
|
|
|
|
|
2002-02-10 18:49:46 +03:00
|
|
|
return nsDependentString(myStr).Equals(nsDependentString(theirStr),
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2001-06-05 05:00:11 +04:00
|
|
|
}
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
|
1999-05-27 03:55:12 +04:00
|
|
|
AtomKey::AtomKey(nsIAtom* aAtom)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
|
|
|
mAtom = aAtom;
|
|
|
|
NS_ADDREF(mAtom);
|
2001-09-07 04:23:37 +04:00
|
|
|
SetKeyCaseSensitive(PR_TRUE);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
AtomKey::AtomKey(const AtomKey_base& aKey)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
|
|
|
mAtom = aKey.mAtom;
|
|
|
|
NS_ADDREF(mAtom);
|
2001-09-07 04:23:37 +04:00
|
|
|
SetKeyCaseSensitive(PR_TRUE);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
1999-05-27 03:55:12 +04:00
|
|
|
AtomKey::~AtomKey(void)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
|
|
|
NS_RELEASE(mAtom);
|
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
nsHashKey* AtomKey::Clone(void) const
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
return new AtomKey(*this);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
|
|
|
|
DependentAtomKey::DependentAtomKey(const DependentAtomKey& aKey)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
NS_NOTREACHED("Should never clone to a dependent atom key.");
|
|
|
|
mAtom = aKey.mAtom;
|
2001-09-07 04:23:37 +04:00
|
|
|
SetKeyCaseSensitive(PR_TRUE);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
nsHashKey* DependentAtomKey::Clone(void) const
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
return new AtomKey(*this); // return a non-dependent key
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-04-28 06:16:16 +04:00
|
|
|
// ----------------------
|
|
|
|
// Rule array hash key
|
|
|
|
//
|
2001-06-05 05:00:11 +04:00
|
|
|
class nsInt32Key: public nsHashKey {
|
2001-04-28 06:16:16 +04:00
|
|
|
public:
|
2001-06-05 05:00:11 +04:00
|
|
|
nsInt32Key(PRInt32 aInt);
|
|
|
|
nsInt32Key(const nsInt32Key& aKey);
|
|
|
|
virtual ~nsInt32Key(void);
|
2001-04-28 06:16:16 +04:00
|
|
|
virtual PRUint32 HashCode(void) const;
|
|
|
|
virtual PRBool Equals(const nsHashKey *aKey) const;
|
|
|
|
virtual nsHashKey *Clone(void) const;
|
2001-06-05 05:00:11 +04:00
|
|
|
PRInt32 mInt;
|
2001-04-28 06:16:16 +04:00
|
|
|
};
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
nsInt32Key::nsInt32Key(PRInt32 aInt) :
|
|
|
|
mInt(aInt)
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
nsInt32Key::~nsInt32Key(void)
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
PRUint32 nsInt32Key::HashCode(void) const
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
return (PRUint32)mInt;
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
PRBool nsInt32Key::Equals(const nsHashKey* aKey) const
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
return PRBool (((nsInt32Key*)aKey)->mInt == mInt);
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
nsHashKey* nsInt32Key::Clone(void) const
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
return new nsInt32Key(mInt);
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
struct RuleValue {
|
|
|
|
RuleValue(nsICSSStyleRule* aRule, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mRule = aRule;
|
|
|
|
mIndex = aIndex;
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
2002-03-22 09:28:16 +03:00
|
|
|
|
|
|
|
// CAUTION: ~RuleValue will never get called as RuleValues are arena
|
|
|
|
// allocated and arena cleanup will take care of deleting memory.
|
|
|
|
// Add code to RuleHash::~RuleHash to get it to call the destructor
|
|
|
|
// if any more cleanup needs to happen.
|
1998-05-21 00:34:17 +04:00
|
|
|
~RuleValue(void)
|
|
|
|
{
|
2002-03-22 09:28:16 +03:00
|
|
|
// Rule values are arena allocated. No need for any deletion.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placement new to arena allocate the RuleValues
|
|
|
|
void *operator new(size_t aSize, PLArenaPool &aArena) {
|
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &aArena, aSize);
|
|
|
|
return mem;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsICSSStyleRule* mRule;
|
|
|
|
PRInt32 mIndex;
|
|
|
|
RuleValue* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// Rule hash table
|
|
|
|
//
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
#undef RULE_HASH_STATS
|
|
|
|
#undef PRINT_UNIVERSAL_RULES
|
|
|
|
|
|
|
|
#ifdef DEBUG_dbaron
|
|
|
|
#define RULE_HASH_STATS
|
|
|
|
#define PRINT_UNIVERSAL_RULES
|
|
|
|
#endif
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
#define RULE_HASH_STAT_INCREMENT(var_) PR_BEGIN_MACRO ++(var_); PR_END_MACRO
|
|
|
|
#else
|
|
|
|
#define RULE_HASH_STAT_INCREMENT(var_) PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
// Enumerator callback function.
|
|
|
|
typedef void (*RuleEnumFunc)(nsICSSStyleRule* aRule, void *aData);
|
|
|
|
|
|
|
|
class RuleHash {
|
|
|
|
public:
|
|
|
|
RuleHash(void);
|
|
|
|
~RuleHash(void);
|
|
|
|
void AppendRule(nsICSSStyleRule* aRule);
|
2001-06-05 05:00:11 +04:00
|
|
|
void EnumerateAllRules(PRInt32 aNameSpace, nsIAtom* aTag, nsIAtom* aID,
|
|
|
|
const nsVoidArray& aClassList,
|
1998-05-21 00:34:17 +04:00
|
|
|
RuleEnumFunc aFunc, void* aData);
|
|
|
|
void EnumerateTagRules(nsIAtom* aTag,
|
|
|
|
RuleEnumFunc aFunc, void* aData);
|
2002-04-16 02:49:26 +04:00
|
|
|
void SetCaseSensitive(PRBool aCaseSensitive) {
|
|
|
|
mCaseSensitive = aCaseSensitive;
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
protected:
|
2001-09-07 04:23:37 +04:00
|
|
|
void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive = PR_TRUE);
|
2001-06-05 05:00:11 +04:00
|
|
|
void AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSSStyleRule* aRule);
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2002-03-22 09:28:16 +03:00
|
|
|
// All rule values in these hashtables are arena allocated
|
1998-05-21 00:34:17 +04:00
|
|
|
PRInt32 mRuleCount;
|
|
|
|
nsHashtable mIdTable;
|
|
|
|
nsHashtable mClassTable;
|
2001-06-05 05:00:11 +04:00
|
|
|
nsHashtable mTagTable;
|
|
|
|
nsHashtable mNameSpaceTable;
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
RuleValue** mEnumList;
|
|
|
|
PRInt32 mEnumListSize;
|
|
|
|
RuleValue mEndValue;
|
2001-09-07 04:23:37 +04:00
|
|
|
PRBool mCaseSensitive;
|
2001-06-05 05:00:11 +04:00
|
|
|
|
2002-03-22 09:28:16 +03:00
|
|
|
PLArenaPool mArena;
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
PRUint32 mUniversalSelectors;
|
|
|
|
PRUint32 mNameSpaceSelectors;
|
|
|
|
PRUint32 mTagSelectors;
|
|
|
|
PRUint32 mClassSelectors;
|
|
|
|
PRUint32 mIdSelectors;
|
|
|
|
|
|
|
|
PRUint32 mElementsMatched;
|
|
|
|
PRUint32 mPseudosMatched;
|
|
|
|
|
|
|
|
PRUint32 mElementUniversalCalls;
|
|
|
|
PRUint32 mElementNameSpaceCalls;
|
|
|
|
PRUint32 mElementTagCalls;
|
|
|
|
PRUint32 mElementClassCalls;
|
|
|
|
PRUint32 mElementIdCalls;
|
|
|
|
|
|
|
|
PRUint32 mPseudoTagCalls;
|
|
|
|
#endif // RULE_HASH_STATS
|
1998-05-21 00:34:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
RuleHash::RuleHash(void)
|
|
|
|
: mRuleCount(0),
|
2001-06-05 05:00:11 +04:00
|
|
|
mIdTable(), mClassTable(), mTagTable(), mNameSpaceTable(),
|
1998-12-11 05:50:43 +03:00
|
|
|
mEnumList(nsnull), mEnumListSize(0),
|
2001-09-07 04:23:37 +04:00
|
|
|
mEndValue(nsnull, -1),
|
|
|
|
mCaseSensitive(PR_TRUE)
|
2001-06-05 05:00:11 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
,
|
|
|
|
mUniversalSelectors(0),
|
|
|
|
mNameSpaceSelectors(0),
|
|
|
|
mTagSelectors(0),
|
|
|
|
mClassSelectors(0),
|
|
|
|
mIdSelectors(0),
|
|
|
|
mElementsMatched(0),
|
|
|
|
mPseudosMatched(0),
|
|
|
|
mElementUniversalCalls(0),
|
|
|
|
mElementNameSpaceCalls(0),
|
|
|
|
mElementTagCalls(0),
|
|
|
|
mElementClassCalls(0),
|
|
|
|
mElementIdCalls(0),
|
|
|
|
mPseudoTagCalls(0)
|
|
|
|
#endif
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2002-03-22 09:28:16 +03:00
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "RuleHashArena", NS_RULEHASH_ARENA_BLOCK_SIZE);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleHash::~RuleHash(void)
|
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
printf(
|
|
|
|
"RuleHash(%p):\n"
|
|
|
|
" Selectors: Universal (%lu) NameSpace(%lu) Tag(%lu) Class(%lu) Id(%lu)\n"
|
|
|
|
" Content Nodes: Elements(%lu) Pseudo-Elements(%lu)\n"
|
|
|
|
" Element Calls: Universal(%lu) NameSpace(%lu) Tag(%lu) Class(%lu) Id(%lu)\n"
|
|
|
|
" Pseudo-Element Calls: Tag(%lu)\n",
|
|
|
|
this,
|
|
|
|
mUniversalSelectors, mNameSpaceSelectors, mTagSelectors,
|
|
|
|
mClassSelectors, mIdSelectors,
|
|
|
|
mElementsMatched,
|
|
|
|
mPseudosMatched,
|
|
|
|
mElementUniversalCalls, mElementNameSpaceCalls, mElementTagCalls,
|
|
|
|
mElementClassCalls, mElementIdCalls,
|
|
|
|
mPseudoTagCalls);
|
|
|
|
#ifdef PRINT_UNIVERSAL_RULES
|
|
|
|
{
|
|
|
|
DependentAtomKey universalKey(nsCSSAtoms::universalSelector);
|
|
|
|
RuleValue* value = (RuleValue*)mTagTable.Get(&universalKey);
|
|
|
|
if (value) {
|
|
|
|
printf(" Universal rules:\n");
|
|
|
|
do {
|
|
|
|
nsAutoString selectorText;
|
|
|
|
PRUint32 lineNumber = value->mRule->GetLineNumber();
|
|
|
|
value->mRule->GetSourceSelectorText(selectorText);
|
|
|
|
printf(" line %d, %s\n",
|
|
|
|
lineNumber, NS_ConvertUCS2toUTF8(selectorText).get());
|
|
|
|
value = value->mNext;
|
|
|
|
} while (value != &mEndValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // PRINT_UNIVERSAL_RULES
|
|
|
|
#endif // RULE_HASH_STATS
|
2002-03-22 09:28:16 +03:00
|
|
|
// Rule Values are arena allocated no need to delete them. Their destructor
|
|
|
|
// isn't doing any cleanup. So we dont even bother to enumerate through
|
|
|
|
// the hash tables and call their destructors.
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != mEnumList) {
|
|
|
|
delete [] mEnumList;
|
|
|
|
}
|
2002-03-22 09:28:16 +03:00
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_FinishArenaPool(&mArena);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
// XXX When this is converted to pldhash, it will be quite easy to
|
|
|
|
// convert this to |PrependRuleToTable|, which would fix the worst-case
|
|
|
|
// O(N^2) nature of appending all the rules. Then we could just
|
|
|
|
// |EnumerateBackwards| instead of |EnumerateForwards| when calling
|
|
|
|
// |BuildRuleHashAndStateSelectors|.
|
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule, PRBool aCaseSensitive)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_ASSERTION(nsnull != aAtom, "null hash key");
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey key(aAtom);
|
2001-09-07 04:23:37 +04:00
|
|
|
key.SetKeyCaseSensitive(aCaseSensitive);
|
2001-06-05 05:00:11 +04:00
|
|
|
RuleValue* value = (RuleValue*)aTable.Get(&key);
|
|
|
|
|
|
|
|
if (nsnull == value) {
|
2002-03-22 09:28:16 +03:00
|
|
|
value = new (mArena) RuleValue(aRule, mRuleCount++);
|
2001-06-05 05:00:11 +04:00
|
|
|
aTable.Put(&key, value);
|
|
|
|
value->mNext = &mEndValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (&mEndValue != value->mNext) {
|
|
|
|
value = value->mNext;
|
|
|
|
}
|
2002-03-22 09:28:16 +03:00
|
|
|
value->mNext = new (mArena) RuleValue(aRule, mRuleCount++);
|
2001-06-05 05:00:11 +04:00
|
|
|
value->mNext->mNext = &mEndValue;
|
|
|
|
}
|
|
|
|
mEndValue.mIndex = mRuleCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::AppendRuleToTable(nsHashtable& aTable, PRInt32 aNameSpace, nsICSSStyleRule* aRule)
|
|
|
|
{
|
|
|
|
nsInt32Key key(aNameSpace);
|
1998-05-21 00:34:17 +04:00
|
|
|
RuleValue* value = (RuleValue*)aTable.Get(&key);
|
|
|
|
|
|
|
|
if (nsnull == value) {
|
2002-03-22 09:28:16 +03:00
|
|
|
value = new (mArena) RuleValue(aRule, mRuleCount++);
|
1998-05-21 00:34:17 +04:00
|
|
|
aTable.Put(&key, value);
|
1998-12-11 05:50:43 +03:00
|
|
|
value->mNext = &mEndValue;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-12-11 05:50:43 +03:00
|
|
|
while (&mEndValue != value->mNext) {
|
1998-05-21 00:34:17 +04:00
|
|
|
value = value->mNext;
|
|
|
|
}
|
2002-03-22 09:28:16 +03:00
|
|
|
value->mNext = new (mArena) RuleValue(aRule, mRuleCount++);
|
1998-12-11 05:50:43 +03:00
|
|
|
value->mNext->mNext = &mEndValue;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
mEndValue.mIndex = mRuleCount;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::AppendRule(nsICSSStyleRule* aRule)
|
|
|
|
{
|
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
2001-02-13 17:06:29 +03:00
|
|
|
if (nsnull != selector->mIDList) {
|
2001-09-07 04:23:37 +04:00
|
|
|
AppendRuleToTable(mIdTable, selector->mIDList->mAtom, aRule, mCaseSensitive);
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mIdSelectors);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
else if (nsnull != selector->mClassList) {
|
2001-09-07 04:23:37 +04:00
|
|
|
AppendRuleToTable(mClassTable, selector->mClassList->mAtom, aRule, mCaseSensitive);
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mClassSelectors);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
else if (nsnull != selector->mTag) {
|
|
|
|
AppendRuleToTable(mTagTable, selector->mTag, aRule);
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mTagSelectors);
|
2001-06-05 05:00:11 +04:00
|
|
|
}
|
|
|
|
else if (kNameSpaceID_Unknown != selector->mNameSpace) {
|
|
|
|
AppendRuleToTable(mNameSpaceTable, selector->mNameSpace, aRule);
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mNameSpaceSelectors);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
else { // universal tag selector
|
|
|
|
AppendRuleToTable(mTagTable, nsCSSAtoms::universalSelector, aRule);
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mUniversalSelectors);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
// this should cover practically all cases so we don't need to reallocate
|
|
|
|
#define MIN_ENUM_LIST_SIZE 8
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
#ifdef RULE_HASH_STATS
|
|
|
|
#define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
|
|
|
|
do { ++(var_); (list_) = (list_)->mNext; } while ((list_) != &mEndValue)
|
|
|
|
#else
|
|
|
|
#define RULE_HASH_STAT_INCREMENT_LIST_COUNT(list_, var_) \
|
|
|
|
PR_BEGIN_MACRO PR_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
void RuleHash::EnumerateAllRules(PRInt32 aNameSpace, nsIAtom* aTag,
|
|
|
|
nsIAtom* aID, const nsVoidArray& aClassList,
|
1998-05-21 00:34:17 +04:00
|
|
|
RuleEnumFunc aFunc, void* aData)
|
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
PRInt32 classCount = aClassList.Count();
|
|
|
|
PRInt32 testCount = classCount + 1; // + 1 for universal selector
|
1998-05-21 01:28:36 +04:00
|
|
|
if (nsnull != aTag) {
|
1998-12-11 05:50:43 +03:00
|
|
|
testCount++;
|
1998-05-21 01:28:36 +04:00
|
|
|
}
|
|
|
|
if (nsnull != aID) {
|
1998-12-11 05:50:43 +03:00
|
|
|
testCount++;
|
1998-05-21 01:28:36 +04:00
|
|
|
}
|
2001-06-05 05:00:11 +04:00
|
|
|
if (kNameSpaceID_Unknown != aNameSpace) {
|
|
|
|
testCount++;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
if (mEnumListSize < testCount) {
|
|
|
|
delete [] mEnumList;
|
2001-06-05 05:00:11 +04:00
|
|
|
mEnumListSize = PR_MAX(testCount, MIN_ENUM_LIST_SIZE);
|
|
|
|
mEnumList = new RuleValue*[mEnumListSize];
|
1998-05-21 01:28:36 +04:00
|
|
|
}
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
PRInt32 index;
|
|
|
|
PRInt32 valueCount = 0;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mElementsMatched);
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
{ // universal tag rules
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey universalKey(nsCSSAtoms::universalSelector);
|
1998-12-21 08:58:31 +03:00
|
|
|
RuleValue* value = (RuleValue*)mTagTable.Get(&universalKey);
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(value, mElementUniversalCalls);
|
2001-06-05 05:00:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// universal rules within the namespace
|
|
|
|
if (kNameSpaceID_Unknown != aNameSpace) {
|
|
|
|
nsInt32Key nameSpaceKey(aNameSpace);
|
|
|
|
RuleValue* value = (RuleValue*)mNameSpaceTable.Get(&nameSpaceKey);
|
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(value, mElementNameSpaceCalls);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
if (nsnull != aTag) {
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey tagKey(aTag);
|
1998-12-21 08:58:31 +03:00
|
|
|
RuleValue* value = (RuleValue*)mTagTable.Get(&tagKey);
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(value, mElementTagCalls);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
if (nsnull != aID) {
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey idKey(aID);
|
2001-09-07 04:23:37 +04:00
|
|
|
idKey.SetKeyCaseSensitive(mCaseSensitive);
|
1998-12-21 08:58:31 +03:00
|
|
|
RuleValue* value = (RuleValue*)mIdTable.Get(&idKey);
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(value, mElementIdCalls);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = 0; index < classCount; index++) {
|
|
|
|
nsIAtom* classAtom = (nsIAtom*)aClassList.ElementAt(index);
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey classKey(classAtom);
|
2001-09-07 04:23:37 +04:00
|
|
|
classKey.SetKeyCaseSensitive(mCaseSensitive);
|
1998-12-21 08:58:31 +03:00
|
|
|
RuleValue* value = (RuleValue*)mClassTable.Get(&classKey);
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != value) {
|
|
|
|
mEnumList[valueCount++] = value;
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT_LIST_COUNT(value, mElementClassCalls);
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-21 00:34:17 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03: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-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleHash::EnumerateTagRules(nsIAtom* aTag, RuleEnumFunc aFunc, void* aData)
|
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey tagKey(aTag);
|
1998-12-21 08:58:31 +03:00
|
|
|
RuleValue* tagValue = (RuleValue*)mTagTable.Get(&tagKey);
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mPseudosMatched);
|
2001-06-05 05:00:11 +04:00
|
|
|
if (tagValue) {
|
|
|
|
do {
|
2002-04-16 02:49:26 +04:00
|
|
|
RULE_HASH_STAT_INCREMENT(mPseudoTagCalls);
|
2001-06-05 05:00:11 +04:00
|
|
|
(*aFunc)(tagValue->mRule, aData);
|
|
|
|
tagValue = tagValue->mNext;
|
|
|
|
} while (&mEndValue != tagValue);
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
struct RuleCascadeData {
|
2001-07-17 00:59:28 +04:00
|
|
|
RuleCascadeData(nsIAtom *aMedium)
|
1999-10-14 04:59:21 +04:00
|
|
|
: mWeightedRules(nsnull),
|
|
|
|
mRuleHash(),
|
2001-07-17 00:59:28 +04:00
|
|
|
mStateSelectors(),
|
|
|
|
mMedium(aMedium),
|
|
|
|
mNext(nsnull)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
NS_NewISupportsArray(&mWeightedRules);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RuleCascadeData(void)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mWeightedRules);
|
|
|
|
}
|
|
|
|
nsISupportsArray* mWeightedRules;
|
|
|
|
RuleHash mRuleHash;
|
|
|
|
nsVoidArray mStateSelectors;
|
2001-07-17 00:59:28 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> mMedium;
|
|
|
|
RuleCascadeData* mNext; // for a different medium
|
1999-10-14 04:59:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Rule processor
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSRuleProcessor: public nsICSSStyleRuleProcessor {
|
|
|
|
public:
|
|
|
|
CSSRuleProcessor(void);
|
|
|
|
virtual ~CSSRuleProcessor(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
// nsICSSStyleRuleProcessor
|
|
|
|
NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aStyleSheet);
|
|
|
|
|
|
|
|
NS_IMETHOD ClearRuleCascades(void);
|
|
|
|
|
|
|
|
// nsIStyleRuleProcessor
|
2001-11-11 02:51:45 +03:00
|
|
|
NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData,
|
|
|
|
nsIAtom* aMedium);
|
|
|
|
|
|
|
|
NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData,
|
|
|
|
nsIAtom* aMedium);
|
|
|
|
|
|
|
|
NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
|
2002-04-11 07:49:30 +04:00
|
|
|
nsIAtom* aMedium,
|
|
|
|
PRBool* aResult);
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize);
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
protected:
|
2001-09-07 04:23:37 +04:00
|
|
|
RuleCascadeData* GetRuleCascade(nsIPresContext* aPresContext, nsIAtom* aMedium);
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
static PRBool CascadeSheetRulesInto(nsISupports* aSheet, void* aData);
|
|
|
|
|
|
|
|
nsISupportsArray* mSheets;
|
|
|
|
|
2001-07-17 00:59:28 +04:00
|
|
|
RuleCascadeData* mRuleCascades;
|
1999-10-14 04:59:21 +04:00
|
|
|
};
|
|
|
|
|
1999-06-03 05:57:52 +04: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);
|
|
|
|
|
1999-06-15 10:20:46 +04:00
|
|
|
virtual void RebuildNameSpaces(void);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize);
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2001-09-06 23:16:03 +04:00
|
|
|
nsAutoVoidArray mSheets;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* mURL;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
nsISupportsArray* mOrderedRules;
|
1999-06-10 09:29:22 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsINameSpace> mNameSpace;
|
1999-06-15 10:20:46 +04:00
|
|
|
PRInt32 mDefaultNameSpaceID;
|
2000-05-16 06:43:33 +04:00
|
|
|
nsHashtable mRelevantAttributes;
|
1999-06-03 05:57:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSImportsCollectionImpl;
|
2000-04-26 17:58:56 +04:00
|
|
|
class CSSRuleListImpl;
|
|
|
|
class DOMMediaListImpl;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
class CSSStyleSheetImpl : public nsICSSStyleSheet,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
public nsIDOMCSSStyleSheet
|
|
|
|
{
|
1999-06-03 05:57:52 +04:00
|
|
|
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 07:29:44 +04:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL);
|
|
|
|
NS_IMETHOD GetURL(nsIURI*& aURL) const;
|
1999-06-03 05:57:52 +04: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;
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHOD_(PRBool) UseForMedium(nsIAtom* aMedium) const;
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_IMETHOD AppendMedium(nsIAtom* aMedium);
|
|
|
|
NS_IMETHOD ClearMedia(void);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHOD DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
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);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHOD GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor,
|
|
|
|
nsIStyleRuleProcessor* aPrevProcessor);
|
|
|
|
NS_IMETHOD DropRuleProcessorReference(nsICSSStyleRuleProcessor* aProcessor);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
NS_IMETHOD ContainsStyleSheet(nsIURI* aURL, PRBool& aContains, nsIStyleSheet** aTheChild=nsnull);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aSheet);
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_IMETHOD InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
|
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
|
|
|
|
// If changing the given attribute cannot affect style context, aAffects
|
|
|
|
// will be PR_FALSE on return.
|
|
|
|
NS_IMETHOD AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent,
|
|
|
|
PRBool &aAffects);
|
|
|
|
|
|
|
|
// Find attributes in selector for rule, for use with AttributeAffectsStyle
|
|
|
|
NS_IMETHOD CheckRuleForAttributes(nsICSSRule* aRule);
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
// XXX do these belong here or are they generic?
|
1999-06-10 09:29:22 +04: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 05:57:52 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
NS_IMETHOD StyleSheetCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
NS_IMETHOD GetNameSpace(nsINameSpace*& aNameSpace) const;
|
1999-06-15 10:20:46 +04:00
|
|
|
NS_IMETHOD SetDefaultNameSpaceID(PRInt32 aDefaultNameSpaceID);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Clone(nsICSSStyleSheet*& aClone) const;
|
|
|
|
|
2000-04-16 04:23:57 +04:00
|
|
|
NS_IMETHOD IsModified(PRBool* aSheetModified) const;
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_IMETHOD SetModified(PRBool aModified);
|
|
|
|
|
|
|
|
nsresult EnsureUniqueInner(void);
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-03 05:57:52 +04:00
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize);
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
// nsIDOMStyleSheet interface
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIDOMSTYLESHEET
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
// nsIDOMCSSStyleSheet interface
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIDOMCSSSTYLESHEET
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
|
|
|
CSSStyleSheetImpl& operator=(const CSSStyleSheetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSStyleSheetImpl();
|
|
|
|
|
|
|
|
void ClearRuleCascades(void);
|
|
|
|
|
|
|
|
nsresult WillDirty(void);
|
|
|
|
void DidDirty(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRUint32 mInHeap : 1;
|
|
|
|
PRUint32 mRefCnt : 31;
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_DECL_OWNINGTHREAD // for thread-safety checking
|
1999-06-03 05:57:52 +04:00
|
|
|
|
|
|
|
nsString mTitle;
|
2000-04-26 17:58:56 +04:00
|
|
|
DOMMediaListImpl* mMedia;
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetImpl* mFirstChild;
|
|
|
|
CSSStyleSheetImpl* mNext;
|
|
|
|
nsICSSStyleSheet* mParent;
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl* mImportsCollection;
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl* mRuleCollection;
|
1999-06-03 05:57:52 +04:00
|
|
|
nsIDocument* mDocument;
|
|
|
|
nsIDOMNode* mOwningNode;
|
|
|
|
PRBool mDisabled;
|
|
|
|
PRBool mDirty; // has been modified
|
|
|
|
|
|
|
|
CSSStyleSheetInner* mInner;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2001-09-06 23:16:03 +04:00
|
|
|
nsAutoVoidArray* mRuleProcessors;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
friend class CSSRuleProcessor;
|
|
|
|
friend class DOMMediaListImpl;
|
1999-06-03 05:57:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
// -------------------------------
|
2000-04-26 17:58:56 +04:00
|
|
|
// Style Rule List for the DOM
|
1998-10-06 05:39:33 +04:00
|
|
|
//
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class CSSRuleListImpl : public nsIDOMCSSRuleList
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
public:
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
// nsIDOMCSSRuleList interface
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
2000-04-26 17:58:56 +04:00
|
|
|
virtual ~CSSRuleListImpl();
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetImpl* mStyleSheet;
|
|
|
|
public:
|
|
|
|
PRBool mRulesAccessed;
|
1998-10-06 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
1999-06-03 05:57:52 +04:00
|
|
|
mRulesAccessed = PR_FALSE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::~CSSRuleListImpl()
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
// QueryInterface implementation for CSSRuleList
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRuleList)
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMPL_ADDREF(CSSRuleListImpl);
|
|
|
|
NS_IMPL_RELEASE(CSSRuleListImpl);
|
|
|
|
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::GetLength(PRUint32* aLength)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 09:29:22 +04:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleRuleCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
2001-03-20 01:12:12 +03:00
|
|
|
if (mStyleSheet) {
|
1999-06-03 05:57:52 +04:00
|
|
|
result = mStyleSheet->EnsureUniqueInner(); // needed to ensure rules have correct parent
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-03-20 01:12:12 +03:00
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2001-03-20 01:12:12 +03:00
|
|
|
result = mStyleSheet->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
if (rule) {
|
|
|
|
result = CallQueryInterface(rule, aReturn);
|
1999-06-03 05:57:52 +04:00
|
|
|
mRulesAccessed = PR_TRUE; // signal to never share rules again
|
2001-03-20 01:12:12 +03:00
|
|
|
} else if (result == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
class DOMMediaListImpl : public nsIDOMMediaList,
|
2001-08-05 01:19:53 +04:00
|
|
|
public nsIMediaList
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_DECL_NSIDOMMEDIALIST
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
NS_FORWARD_NSISUPPORTSARRAY(mArray->)
|
|
|
|
NS_FORWARD_NSICOLLECTION(mArray->);
|
2001-07-31 23:05:34 +04:00
|
|
|
NS_FORWARD_NSISERIALIZABLE(mArray->); // XXXbe temporary
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& other) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD_(nsISupports*) operator[](PRUint32 aIndex) {
|
|
|
|
return mArray->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
// nsIMediaList methods
|
|
|
|
NS_DECL_NSIMEDIALIST
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
DOMMediaListImpl(nsISupportsArray *aArray, CSSStyleSheetImpl *aStyleSheet);
|
|
|
|
virtual ~DOMMediaListImpl();
|
|
|
|
|
|
|
|
private:
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult BeginMediaChange(void);
|
|
|
|
nsresult EndMediaChange(void);
|
2002-03-24 01:56:05 +03:00
|
|
|
nsresult Delete(const nsAString & aOldMedium);
|
|
|
|
nsresult Append(const nsAString & aOldMedium);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> mArray;
|
2001-09-05 04:00:18 +04:00
|
|
|
// not refcounted; sheet will let us know when it goes away
|
|
|
|
// mStyleSheet is the sheet that needs to be dirtied when this medialist
|
|
|
|
// changes
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSStyleSheetImpl* mStyleSheet;
|
|
|
|
};
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
// QueryInterface implementation for DOMMediaListImpl
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMediaList)
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsArray)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList)
|
2001-07-31 23:05:34 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISerializable)
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF(DOMMediaListImpl);
|
|
|
|
NS_IMPL_RELEASE(DOMMediaListImpl);
|
|
|
|
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
DOMMediaListImpl::DOMMediaListImpl(nsISupportsArray *aArray,
|
|
|
|
CSSStyleSheetImpl *aStyleSheet)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
: mArray(aArray), mStyleSheet(aStyleSheet)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2000-04-27 03:24:30 +04:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ABORT_IF_FALSE(mArray, "This can't be used without an array!!");
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMMediaListImpl::~DOMMediaListImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewMediaList(nsIMediaList** aInstancePtrResult) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_NewMediaList(NS_LITERAL_STRING(""), aInstancePtrResult);
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_NewMediaList(const nsAString& aMediaText, nsIMediaList** aInstancePtrResult) {
|
2001-08-05 01:19:53 +04:00
|
|
|
nsresult rv;
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ASSERTION(aInstancePtrResult, "Null out param.");
|
2001-08-05 01:19:53 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> array;
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(array));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
DOMMediaListImpl* medialist = new DOMMediaListImpl(array, nsnull);
|
2001-09-05 04:00:18 +04:00
|
|
|
*aInstancePtrResult = medialist;
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_TRUE(medialist, NS_ERROR_OUT_OF_MEMORY);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ADDREF(*aInstancePtrResult);
|
2001-08-05 01:19:53 +04:00
|
|
|
rv = medialist->SetMediaText(aMediaText);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(*aInstancePtrResult);
|
|
|
|
*aInstancePtrResult = nsnull;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewMediaList(nsISupportsArray* aArray, nsICSSStyleSheet* aSheet, nsIMediaList** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInstancePtrResult, "Null out param.");
|
|
|
|
DOMMediaListImpl* medialist = new DOMMediaListImpl(aArray, NS_STATIC_CAST(CSSStyleSheetImpl*, aSheet));
|
2001-08-05 01:19:53 +04:00
|
|
|
*aInstancePtrResult = medialist;
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_TRUE(medialist, NS_ERROR_OUT_OF_MEMORY);
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ADDREF(*aInstancePtrResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_OK;
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::GetText(nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
aMediaText.Truncate();
|
|
|
|
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRInt32 count = cnt, index = 0;
|
|
|
|
|
|
|
|
while (index < count) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsIAtom> medium;
|
|
|
|
QueryElementAt(index++, NS_GET_IID(nsIAtom), getter_AddRefs(medium));
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
const PRUnichar *buffer;
|
|
|
|
medium->GetUnicode(&buffer);
|
|
|
|
aMediaText.Append(buffer);
|
|
|
|
if (index < count) {
|
2000-08-23 21:27:06 +04:00
|
|
|
aMediaText.Append(NS_LITERAL_STRING(", "));
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::SetText(const nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
nsresult rv = Clear();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString buf(aMediaText);
|
|
|
|
PRInt32 n = buf.FindChar(',');
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (n < 0)
|
|
|
|
n = buf.Length();
|
|
|
|
|
|
|
|
nsAutoString tmp;
|
|
|
|
|
|
|
|
buf.Left(tmp, n);
|
|
|
|
|
|
|
|
tmp.CompressWhitespace();
|
|
|
|
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!tmp.IsEmpty()) {
|
2000-04-26 17:58:56 +04:00
|
|
|
rv = Append(tmp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.Cut(0, n + 1);
|
|
|
|
|
|
|
|
n = buf.FindChar(',');
|
2002-01-24 05:03:19 +03:00
|
|
|
} while (!buf.IsEmpty());
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
/*
|
|
|
|
* aMatch is true when we contain the desired medium or contain the
|
|
|
|
* "all" medium or contain no media at all, which is the same as
|
|
|
|
* containing "all"
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMMediaListImpl::MatchesMedium(nsIAtom* aMedium, PRBool* aMatch)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMatch);
|
|
|
|
*aMatch = PR_FALSE;
|
|
|
|
*aMatch = (-1 != IndexOf(aMedium)) ||
|
|
|
|
(-1 != IndexOf(nsLayoutAtoms::all));
|
|
|
|
if (*aMatch)
|
|
|
|
return NS_OK;
|
|
|
|
PRUint32 count;
|
|
|
|
nsresult rv = Count(&count);
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
*aMatch = (count == 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMMediaListImpl::DropReference(void)
|
|
|
|
{
|
|
|
|
mStyleSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::GetMediaText(nsAString& aMediaText)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
return GetText(aMediaText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::SetMediaText(const nsAString& aMediaText)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = BeginMediaChange();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = SetText(aMediaText);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = EndMediaChange();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMMediaListImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLength);
|
|
|
|
|
|
|
|
PRUint32 cnt;
|
|
|
|
|
|
|
|
nsresult rv = Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aLength = cnt;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::Item(PRUint32 aIndex, nsAString& aReturn)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> tmp(dont_AddRef(ElementAt(aIndex)));
|
|
|
|
|
|
|
|
if (tmp) {
|
|
|
|
nsCOMPtr<nsIAtom> medium(do_QueryInterface(tmp));
|
|
|
|
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
const PRUnichar *buffer;
|
|
|
|
medium->GetUnicode(&buffer);
|
2000-04-28 00:38:50 +04:00
|
|
|
aReturn.Assign(buffer);
|
2000-04-26 17:58:56 +04:00
|
|
|
} else {
|
|
|
|
aReturn.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::DeleteMedium(const nsAString& aOldMedium)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = BeginMediaChange();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = Delete(aOldMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = EndMediaChange();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::AppendMedium(const nsAString& aNewMedium)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
rv = BeginMediaChange();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = Append(aNewMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = EndMediaChange();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::Delete(const nsAString& aOldMedium)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (aOldMedium.IsEmpty())
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> old(dont_AddRef(NS_NewAtom(aOldMedium)));
|
|
|
|
NS_ENSURE_TRUE(old, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 indx = IndexOf(old);
|
|
|
|
|
|
|
|
if (indx < 0) {
|
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveElementAt(indx);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult
|
2002-03-24 01:56:05 +03:00
|
|
|
DOMMediaListImpl::Append(const nsAString& aNewMedium)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (aNewMedium.IsEmpty())
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> media(dont_AddRef(NS_NewAtom(aNewMedium)));
|
|
|
|
NS_ENSURE_TRUE(media, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
PRInt32 indx = IndexOf(media);
|
|
|
|
|
|
|
|
if (indx >= 0) {
|
|
|
|
RemoveElementAt(indx);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendElement(media);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult
|
|
|
|
DOMMediaListImpl::BeginMediaChange(void)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
if (mStyleSheet) {
|
|
|
|
rv = mStyleSheet->GetOwningDocument(*getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = doc->BeginUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mStyleSheet->WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DOMMediaListImpl::EndMediaChange(void)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (mStyleSheet) {
|
|
|
|
mStyleSheet->DidDirty();
|
|
|
|
rv = mStyleSheet->GetOwningDocument(*getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = doc->StyleRuleChanged(mStyleSheet, nsnull, NS_STYLE_HINT_RECONSTRUCT_ALL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = doc->EndUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
// -------------------------------
|
|
|
|
// Imports Collection for the DOM
|
|
|
|
//
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class CSSImportsCollectionImpl : public nsIDOMStyleSheetList
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
// nsIDOMCSSStyleSheetList interface
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSImportsCollectionImpl();
|
|
|
|
|
|
|
|
nsICSSStyleSheet* mStyleSheet;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
// QueryInterface implementation for CSSImportsCollectionImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSImportsCollectionImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(StyleSheetList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMPL_ADDREF(CSSImportsCollectionImpl);
|
|
|
|
NS_IMPL_RELEASE(CSSImportsCollectionImpl);
|
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-06 05:39:33 +04:00
|
|
|
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 09:29:22 +04:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleSheetCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 05:39:33 +04: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) {
|
2001-01-04 23:44:42 +03:00
|
|
|
result = sheet->QueryInterface(NS_GET_IID(nsIDOMStyleSheet), (void **)aReturn);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
// -------------------------------
|
1999-06-03 05:57:52 +04:00
|
|
|
// CSS Style Sheet Inner Data Container
|
1998-05-21 00:34:17 +04:00
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
static PRBool SetStyleSheetReference(nsISupports* aElement, void* aSheet)
|
|
|
|
{
|
1999-06-10 09:29:22 +04:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aElement;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
if (nsnull != rule) {
|
|
|
|
rule->SetStyleSheet((nsICSSStyleSheet*)aSheet);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(nsICSSStyleSheet* aParentSheet)
|
|
|
|
: mSheets(),
|
|
|
|
mURL(nsnull),
|
|
|
|
mOrderedRules(nsnull),
|
1999-06-15 10:20:46 +04:00
|
|
|
mNameSpace(nsnull),
|
2000-05-16 06:43:33 +04:00
|
|
|
mDefaultNameSpaceID(kNameSpaceID_None),
|
|
|
|
mRelevantAttributes()
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
MOZ_COUNT_CTOR(CSSStyleSheetInner);
|
1999-06-03 05:57:52 +04:00
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
static PRBool
|
|
|
|
CloneRuleInto(nsISupports* aRule, void* aArray)
|
|
|
|
{
|
1999-06-10 09:29:22 +04:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
|
|
|
nsICSSRule* clone = nsnull;
|
1999-06-03 05:57:52 +04:00
|
|
|
rule->Clone(clone);
|
|
|
|
if (clone) {
|
|
|
|
nsISupportsArray* array = (nsISupportsArray*)aArray;
|
|
|
|
array->AppendElement(clone);
|
|
|
|
NS_RELEASE(clone);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-06-05 23:15:32 +04:00
|
|
|
static PRBool PR_CALLBACK
|
2000-05-16 06:43:33 +04:00
|
|
|
CopyRelevantAttributes(nsHashKey *aAttrKey, void *aAtom, void *aTable)
|
|
|
|
{
|
|
|
|
nsHashtable *table = NS_STATIC_CAST(nsHashtable *, aTable);
|
|
|
|
AtomKey *key = NS_STATIC_CAST(AtomKey *, aAttrKey);
|
|
|
|
table->Put(key, key->mAtom);
|
|
|
|
// we don't need to addref the atom here, because we're also copying the
|
|
|
|
// rules when we clone, and that will add a ref for us
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
|
|
|
|
nsICSSStyleSheet* aParentSheet)
|
|
|
|
: mSheets(),
|
|
|
|
mURL(aCopy.mURL),
|
1999-06-15 10:20:46 +04:00
|
|
|
mNameSpace(nsnull),
|
2000-05-16 06:43:33 +04:00
|
|
|
mDefaultNameSpaceID(aCopy.mDefaultNameSpaceID),
|
|
|
|
mRelevantAttributes()
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
MOZ_COUNT_CTOR(CSSStyleSheetInner);
|
1999-06-03 05:57:52 +04: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;
|
|
|
|
}
|
2000-05-16 06:43:33 +04:00
|
|
|
aCopy.mRelevantAttributes.Enumerate(CopyRelevantAttributes,
|
|
|
|
&mRelevantAttributes);
|
1999-06-15 10:20:46 +04:00
|
|
|
RebuildNameSpaces();
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetInner::~CSSStyleSheetInner(void)
|
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
MOZ_COUNT_DTOR(CSSStyleSheetInner);
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
if (mOrderedRules) {
|
|
|
|
mOrderedRules->EnumerateForwards(SetStyleSheetReference, nsnull);
|
|
|
|
NS_RELEASE(mOrderedRules);
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
CSSStyleSheetInner*
|
|
|
|
CSSStyleSheetInner::CloneFor(nsICSSStyleSheet* aParentSheet)
|
|
|
|
{
|
|
|
|
return new CSSStyleSheetInner(*this, aParentSheet);
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
void
|
|
|
|
CSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aParentSheet)
|
|
|
|
{
|
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-03 05:57:52 +04: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-14 00:24:54 +04:00
|
|
|
|
1999-06-15 10:20:46 +04:00
|
|
|
static PRBool
|
|
|
|
CreateNameSpace(nsISupports* aRule, void* aNameSpacePtr)
|
|
|
|
{
|
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
1999-06-15 10:20:46 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsINameSpaceManager> nameSpaceMgr;
|
1999-06-15 10:20:46 +04:00
|
|
|
if (mNameSpace) {
|
2001-09-05 04:00:18 +04:00
|
|
|
mNameSpace->GetNameSpaceManager(*getter_AddRefs(nameSpaceMgr));
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_NewNameSpaceManager(getter_AddRefs(nameSpaceMgr));
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
if (nameSpaceMgr) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nameSpaceMgr->CreateRootNameSpace(*getter_AddRefs(mNameSpace));
|
1999-06-15 10:20:46 +04:00
|
|
|
if (kNameSpaceID_Unknown != mDefaultNameSpaceID) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsINameSpace> defaultNameSpace;
|
|
|
|
mNameSpace->CreateChildNameSpace(nsnull, mDefaultNameSpaceID,
|
|
|
|
*getter_AddRefs(defaultNameSpace));
|
1999-06-15 10:20:46 +04:00
|
|
|
if (defaultNameSpace) {
|
|
|
|
mNameSpace = defaultNameSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mOrderedRules) {
|
2001-09-06 17:14:35 +04:00
|
|
|
mOrderedRules->EnumerateForwards(CreateNameSpace, address_of(mNameSpace));
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2000-03-31 11:08:36 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as CSSStyleSheetInner's size):
|
|
|
|
* 1) sizeof(*this) + sizeof mSheets array (not contents though)
|
|
|
|
* + size of the mOrderedRules array (not the contents though)
|
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as CSSStyleSheetInner's size):
|
|
|
|
* 1) mSheets: each style sheet is sized seperately
|
|
|
|
* 2) mOrderedRules: each fule is sized seperately
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void CSSStyleSheetInner::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSizeOfHandler != nsnull, "SizeOf handler cannot be null");
|
|
|
|
|
|
|
|
// first get the unique items collection
|
|
|
|
UNIQUE_STYLE_ITEMS(uniqueItems);
|
|
|
|
if(! uniqueItems->AddItem((void*)this)){
|
|
|
|
// this style sheet is lared accounted for
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 localSize=0;
|
|
|
|
PRBool rulesCounted=PR_FALSE;
|
|
|
|
|
|
|
|
// create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("CSSStyleSheetInner"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(CSSStyleSheetInner);
|
|
|
|
|
|
|
|
// add in the size of the mSheets array itself
|
|
|
|
mSheets.SizeOf(aSizeOfHandler,&localSize);
|
|
|
|
aSize += localSize;
|
|
|
|
|
|
|
|
// and the mOrderedRules array (if there is one)
|
|
|
|
if(mOrderedRules && uniqueItems->AddItem(mOrderedRules)){
|
|
|
|
rulesCounted=PR_TRUE;
|
|
|
|
// no SizeOf method so we just get the basic object size
|
|
|
|
aSize += sizeof(*mOrderedRules);
|
|
|
|
}
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
|
|
|
|
|
|
|
|
// delegate to the contained containers
|
|
|
|
// mSheets : nsVoidArray
|
|
|
|
{
|
|
|
|
PRUint32 sheetCount, sheetCur;
|
|
|
|
sheetCount = mSheets.Count();
|
|
|
|
for(sheetCur=0; sheetCur < sheetCount; sheetCur++){
|
|
|
|
nsICSSStyleSheet* sheet = (nsICSSStyleSheet*)mSheets.ElementAt(sheetCur);
|
|
|
|
if(sheet){
|
|
|
|
sheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// mOrderedRules : nsISupportsArray*
|
|
|
|
if(mOrderedRules && rulesCounted){
|
|
|
|
PRUint32 ruleCount, ruleCur;
|
|
|
|
mOrderedRules->Count(&ruleCount);
|
|
|
|
for(ruleCur=0; ruleCur < ruleCount; ruleCur++){
|
|
|
|
nsICSSRule* rule = (nsICSSRule*)mOrderedRules->ElementAt(ruleCur);
|
|
|
|
if(rule){
|
|
|
|
rule->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
NS_IF_RELEASE(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-15 10:20:46 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
void* CSSStyleSheetImpl::operator new(size_t size)
|
|
|
|
{
|
|
|
|
CSSStyleSheetImpl* rv = (CSSStyleSheetImpl*) ::operator new(size);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
2002-02-05 04:41:13 +03:00
|
|
|
memset(rv, 0xEE, size);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
#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) {
|
2002-02-05 04:41:13 +03:00
|
|
|
memset(rv, 0xEE, size);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 0;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
1999-02-26 22:26:29 +03:00
|
|
|
void CSSStyleSheetImpl::operator delete(void* ptr)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*) ptr;
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (sheet->mInHeap) {
|
1999-02-26 20:13:10 +03:00
|
|
|
::operator delete(ptr);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(CSSStyleSheetImpl)
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
CSSStyleSheetImpl::CSSStyleSheetImpl()
|
1998-04-14 00:24:54 +04:00
|
|
|
: nsICSSStyleSheet(),
|
1999-06-03 05:57:52 +04:00
|
|
|
mTitle(),
|
|
|
|
mMedia(nsnull),
|
1998-11-26 04:34:53 +03:00
|
|
|
mFirstChild(nsnull),
|
1998-06-05 10:06:50 +04:00
|
|
|
mNext(nsnull),
|
1999-06-03 05:57:52 +04:00
|
|
|
mParent(nsnull),
|
|
|
|
mImportsCollection(nsnull),
|
|
|
|
mRuleCollection(nsnull),
|
|
|
|
mDocument(nsnull),
|
|
|
|
mOwningNode(nsnull),
|
|
|
|
mDisabled(PR_FALSE),
|
1999-07-16 21:40:39 +04:00
|
|
|
mDirty(PR_FALSE),
|
1999-10-14 04:59:21 +04:00
|
|
|
mRuleProcessors(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1998-12-11 05:50:43 +03:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner = new CSSStyleSheetInner(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:52 +04: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 21:40:39 +04:00
|
|
|
mDirty(PR_FALSE),
|
1999-10-14 04:59:21 +04:00
|
|
|
mInner(aCopy.mInner),
|
|
|
|
mRuleProcessors(nsnull)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_INIT_REFCNT();
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner->AddSheet(this);
|
|
|
|
|
|
|
|
if (aCopy.mRuleCollection &&
|
|
|
|
aCopy.mRuleCollection->mRulesAccessed) { // CSSOM's been there, force full copy now
|
|
|
|
EnsureUniqueInner();
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
if (aCopy.mMedia) {
|
2000-04-26 17:58:56 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> tmp;
|
2001-05-23 00:53:00 +04:00
|
|
|
(NS_STATIC_CAST(nsISupportsArray *, aCopy.mMedia))->Clone(getter_AddRefs(tmp));
|
|
|
|
mMedia = new DOMMediaListImpl(tmp, this);
|
|
|
|
NS_IF_ADDREF(mMedia);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
|
|
|
{
|
1999-05-19 03:14:29 +04:00
|
|
|
if (mFirstChild) {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
do {
|
|
|
|
child->mParent = nsnull;
|
|
|
|
child = child->mNext;
|
|
|
|
} while (child);
|
|
|
|
NS_RELEASE(mFirstChild);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
NS_IF_RELEASE(mNext);
|
1998-10-06 05:39:33 +04:00
|
|
|
if (nsnull != mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
NS_RELEASE(mRuleCollection);
|
|
|
|
}
|
|
|
|
if (nsnull != mImportsCollection) {
|
|
|
|
mImportsCollection->DropReference();
|
|
|
|
NS_RELEASE(mImportsCollection);
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
if (mMedia) {
|
|
|
|
mMedia->DropReference();
|
|
|
|
NS_RELEASE(mMedia);
|
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner->RemoveSheet(this);
|
1998-11-17 05:14:38 +03: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.
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mRuleProcessors) {
|
|
|
|
NS_ASSERTION(mRuleProcessors->Count() == 0, "destucting sheet with rule processor reference");
|
|
|
|
delete mRuleProcessors; // weak refs, should be empty here anyway
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
// QueryInterface implementation for CSSStyleSheetImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSStyleSheetImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IMPL_ADDREF(CSSStyleSheetImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSStyleSheetImpl)
|
|
|
|
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor,
|
1999-10-14 04:59:21 +04:00
|
|
|
nsIStyleRuleProcessor* aPrevProcessor)
|
1999-10-08 07:09:31 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsICSSStyleRuleProcessor* cssProcessor = nsnull;
|
|
|
|
|
|
|
|
if (aPrevProcessor) {
|
2000-02-03 01:24:56 +03:00
|
|
|
result = aPrevProcessor->QueryInterface(NS_GET_IID(nsICSSStyleRuleProcessor), (void**)&cssProcessor);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
if (! cssProcessor) {
|
|
|
|
CSSRuleProcessor* processor = new CSSRuleProcessor();
|
|
|
|
if (processor) {
|
2000-02-03 01:24:56 +03:00
|
|
|
result = processor->QueryInterface(NS_GET_IID(nsICSSStyleRuleProcessor), (void**)&cssProcessor);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
delete processor;
|
|
|
|
cssProcessor = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result) && cssProcessor) {
|
|
|
|
cssProcessor->AppendStyleSheet(this);
|
|
|
|
if (! mRuleProcessors) {
|
2001-09-06 23:16:03 +04:00
|
|
|
mRuleProcessors = new nsAutoVoidArray();
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
if (mRuleProcessors) {
|
|
|
|
NS_ASSERTION(-1 == mRuleProcessors->IndexOf(cssProcessor), "processor already registered");
|
|
|
|
mRuleProcessors->AppendElement(cssProcessor); // weak ref
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aProcessor = cssProcessor;
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::DropRuleProcessorReference(nsICSSStyleRuleProcessor* aProcessor)
|
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ASSERTION(mRuleProcessors, "no rule processors registered");
|
|
|
|
if (mRuleProcessors) {
|
|
|
|
NS_ASSERTION(-1 != mRuleProcessors->IndexOf(aProcessor), "not a registered processor");
|
|
|
|
mRuleProcessors->RemoveElement(aProcessor);
|
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-20 04:17:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::Init(nsIURI* aURL)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL, "null ptr");
|
|
|
|
if (! aURL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (! mInner) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ASSERTION(! mInner->mURL, "already initialized");
|
|
|
|
if (mInner->mURL)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mInner->mURL) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool eq;
|
|
|
|
nsresult rv = mInner->mURL->Equals(aURL, &eq);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && eq, "bad inner");
|
|
|
|
#endif
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
else {
|
|
|
|
mInner->mURL = aURL;
|
|
|
|
NS_ADDREF(mInner->mURL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetURL(nsIURI*& aURL) const
|
1998-12-20 04:17:05 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
const nsIURI* url = ((mInner) ? mInner->mURL : nsnull);
|
|
|
|
aURL = (nsIURI*)url;
|
|
|
|
NS_IF_ADDREF(aURL);
|
|
|
|
return NS_OK;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetTitle(const nsString& aTitle)
|
1999-02-27 10:17:52 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
mTitle = aTitle;
|
|
|
|
return NS_OK;
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetType(nsString& aType) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-12-16 14:58:03 +03:00
|
|
|
aType.Assign(NS_LITERAL_STRING("text/css"));
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mMedia->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
aCount = cnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-27 10:17:52 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
|
|
|
{
|
|
|
|
nsIAtom* medium = nsnull;
|
|
|
|
if (nsnull != mMedia) {
|
|
|
|
medium = (nsIAtom*)mMedia->ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
if (nsnull != medium) {
|
|
|
|
aMedium = medium;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
aMedium = nsnull;
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-02-27 10:17:52 +03:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
2001-09-05 04:00:18 +04:00
|
|
|
PRBool matches = PR_FALSE;
|
|
|
|
mMedia->MatchesMedium(aMedium, &matches);
|
|
|
|
return matches;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::AppendMedium(nsIAtom* aMedium)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult result = NS_OK;
|
2000-04-26 17:58:56 +04:00
|
|
|
if (!mMedia) {
|
|
|
|
nsCOMPtr<nsISupportsArray> tmp;
|
|
|
|
result = NS_NewISupportsArray(getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
mMedia = new DOMMediaListImpl(tmp, this);
|
|
|
|
NS_ENSURE_TRUE(mMedia, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
NS_ADDREF(mMedia);
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
if (mMedia) {
|
1999-10-14 04:59:21 +04:00
|
|
|
mMedia->AppendElement(aMedium);
|
|
|
|
}
|
|
|
|
return result;
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::ClearMedia(void)
|
1999-02-27 10:17:52 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mMedia) {
|
|
|
|
mMedia->Clear();
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
aEnabled = ((PR_TRUE == mDisabled) ? PR_FALSE : PR_TRUE);
|
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
PRBool oldState = mDisabled;
|
|
|
|
mDisabled = ((PR_TRUE == aEnabled) ? PR_FALSE : PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if ((nsnull != mDocument) && (mDisabled != oldState)) {
|
|
|
|
mDocument->SetStyleSheetDisabledState(this, mDisabled);
|
|
|
|
}
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
aParent = mParent;
|
2000-02-18 02:19:18 +03:00
|
|
|
NS_IF_ADDREF(aParent);
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
|
|
|
|
{
|
|
|
|
nsIDocument* doc = mDocument;
|
|
|
|
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
|
|
|
|
while ((nsnull == doc) && (nsnull != parent)) {
|
|
|
|
doc = parent->mDocument;
|
|
|
|
parent = (CSSStyleSheetImpl*)(parent->mParent);
|
|
|
|
}
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IF_ADDREF(doc);
|
|
|
|
aDocument = doc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{ // not ref counted
|
|
|
|
mDocument = aDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode)
|
|
|
|
{ // not ref counted
|
|
|
|
mOwningNode = aOwningNode;
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2000-06-03 01:45:06 +04:00
|
|
|
CSSStyleSheetImpl::ContainsStyleSheet(nsIURI* aURL, PRBool& aContains, nsIStyleSheet** aTheChild /*=nsnull*/)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aURL, "null arg");
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
// first check ourself out
|
|
|
|
nsresult rv = mInner->mURL->Equals(aURL, &aContains);
|
|
|
|
if (NS_FAILED(rv)) aContains = PR_FALSE;
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
if (aContains) {
|
|
|
|
// if we found it and the out-param is there, set it and addref
|
|
|
|
if (aTheChild) {
|
2001-01-04 23:44:42 +03:00
|
|
|
rv = QueryInterface( NS_GET_IID(nsIStyleSheet), (void **)aTheChild);
|
2000-06-03 01:45:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
// now check the chil'ins out (recursively)
|
|
|
|
while ((PR_FALSE == aContains) && (nsnull != child)) {
|
|
|
|
child->ContainsStyleSheet(aURL, aContains, aTheChild);
|
|
|
|
if (aContains) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2000-06-03 01:45:06 +04:00
|
|
|
|
|
|
|
// NOTE: if there are errors in the above we are handling them locally
|
|
|
|
// and not promoting them to the caller
|
|
|
|
return NS_OK;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
1999-02-27 10:17:52 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*)aSheet;
|
1999-02-27 10:17:52 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (! mFirstChild) {
|
|
|
|
mFirstChild = sheet;
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
else {
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (child->mNext) {
|
|
|
|
child = child->mNext;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
child->mNext = sheet;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
DidDirty();
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex)
|
1998-05-19 01:10:19 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult result = WillDirty();
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*)aSheet;
|
|
|
|
CSSStyleSheetImpl* child = mFirstChild;
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (aIndex && child) {
|
|
|
|
while ((0 < --aIndex) && child->mNext) {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
sheet->mNext = child->mNext;
|
|
|
|
child->mNext = sheet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sheet->mNext = mFirstChild;
|
|
|
|
mFirstChild = sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
DidDirty();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::AttributeAffectsStyle(nsIAtom *aAttribute,
|
|
|
|
nsIContent *aContent,
|
|
|
|
PRBool &aAffects)
|
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey key(aAttribute);
|
2000-05-16 06:43:33 +04:00
|
|
|
aAffects = !!mInner->mRelevantAttributes.Get(&key);
|
|
|
|
for (CSSStyleSheetImpl *child = mFirstChild;
|
|
|
|
child && !aAffects;
|
|
|
|
child = child->mNext) {
|
|
|
|
child->AttributeAffectsStyle(aAttribute, aContent, aAffects);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::PrependStyleRule(nsICSSRule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
1999-04-20 04:05:54 +04:00
|
|
|
|
1999-10-14 04:59:21 +04: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-04-20 04:05:54 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
1999-10-14 04:59:21 +04:00
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
// no api to prepend a namespace (ugh), release old ones and re-create them all
|
|
|
|
mInner->RebuildNameSpaces();
|
2000-05-16 06:43:33 +04:00
|
|
|
} else {
|
|
|
|
CheckRuleForAttributes(aRule);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::AppendStyleRule(nsICSSRule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
if (! mInner->mOrderedRules) {
|
|
|
|
NS_NewISupportsArray(&(mInner->mOrderedRules));
|
|
|
|
}
|
|
|
|
if (mInner->mOrderedRules) {
|
|
|
|
mInner->mOrderedRules->AppendElement(aRule);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
1999-05-27 03:55:12 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
1999-10-14 04:59:21 +04:00
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
if (! mInner->mNameSpace) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsINameSpaceManager> nameSpaceMgr;
|
|
|
|
NS_NewNameSpaceManager(getter_AddRefs(nameSpaceMgr));
|
1999-10-14 04:59:21 +04:00
|
|
|
if (nameSpaceMgr) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nameSpaceMgr->CreateRootNameSpace(*getter_AddRefs(mInner->mNameSpace));
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mInner->mNameSpace) {
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule(do_QueryInterface(aRule));
|
|
|
|
nsCOMPtr<nsINameSpace> newNameSpace;
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
1999-10-14 04:59:21 +04:00
|
|
|
nsAutoString urlSpec;
|
2001-09-05 04:00:18 +04:00
|
|
|
nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
|
1999-10-14 04:59:21 +04:00
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
2001-09-05 04:00:18 +04:00
|
|
|
mInner->mNameSpace->CreateChildNameSpace(prefix, urlSpec,
|
|
|
|
*getter_AddRefs(newNameSpace));
|
1999-10-14 04:59:21 +04:00
|
|
|
if (newNameSpace) {
|
2001-09-05 04:00:18 +04:00
|
|
|
mInner->mNameSpace = newNameSpace;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-16 06:43:33 +04:00
|
|
|
} else {
|
|
|
|
CheckRuleForAttributes(aRule);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2000-05-16 06:43:33 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
static PRBool
|
|
|
|
CheckRuleForAttributesEnum(nsISupports *aRule, void *aData)
|
|
|
|
{
|
|
|
|
nsICSSRule *rule = NS_STATIC_CAST(nsICSSRule *, aRule);
|
|
|
|
CSSStyleSheetImpl *sheet = NS_STATIC_CAST(CSSStyleSheetImpl *, aData);
|
|
|
|
return NS_SUCCEEDED(sheet->CheckRuleForAttributes(rule));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::CheckRuleForAttributes(nsICSSRule *aRule)
|
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 ruleType = nsICSSRule::UNKNOWN_RULE;
|
2000-05-16 06:43:33 +04:00
|
|
|
aRule->GetType(ruleType);
|
|
|
|
switch (ruleType) {
|
|
|
|
case nsICSSRule::MEDIA_RULE: {
|
|
|
|
nsICSSMediaRule *mediaRule = (nsICSSMediaRule *)aRule;
|
|
|
|
return mediaRule->EnumerateRulesForwards(CheckRuleForAttributesEnum,
|
|
|
|
(void *)this);
|
|
|
|
}
|
|
|
|
case nsICSSRule::STYLE_RULE: {
|
|
|
|
nsICSSStyleRule *styleRule = NS_STATIC_CAST(nsICSSStyleRule *, aRule);
|
|
|
|
nsCSSSelector *iter;
|
|
|
|
for (iter = styleRule->FirstSelector(); iter; iter = iter->mNext) {
|
2000-06-01 00:00:31 +04:00
|
|
|
/* P.classname means we have to check the attribute "class" */
|
2001-02-13 17:06:29 +03:00
|
|
|
if (iter->mIDList) {
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey idKey(nsHTMLAtoms::id);
|
2000-06-01 00:00:31 +04:00
|
|
|
mInner->mRelevantAttributes.Put(&idKey, nsHTMLAtoms::id);
|
|
|
|
}
|
|
|
|
if (iter->mClassList) {
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey classKey(nsHTMLAtoms::kClass);
|
2000-06-01 00:00:31 +04:00
|
|
|
mInner->mRelevantAttributes.Put(&classKey, nsHTMLAtoms::kClass);
|
|
|
|
}
|
|
|
|
for (nsAttrSelector *sel = iter->mAttrList; sel; sel = sel->mNext) {
|
2000-05-16 06:43:33 +04:00
|
|
|
/* store it in this sheet's attributes-that-matter table */
|
|
|
|
/* XXX store tag name too, but handle collisions */
|
|
|
|
#ifdef DEBUG_shaver_off
|
|
|
|
nsAutoString str;
|
|
|
|
sel->mAttr->ToString(str);
|
2001-09-29 12:28:41 +04:00
|
|
|
char * chars = ToNewCString(str);
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stderr, "[%s@%p]", chars, this);
|
2000-06-03 13:46:12 +04:00
|
|
|
nsMemory::Free(chars);
|
2000-05-16 06:43:33 +04:00
|
|
|
#endif
|
2001-06-05 05:00:11 +04:00
|
|
|
DependentAtomKey key(sel->mAttr);
|
2000-05-16 06:43:33 +04:00
|
|
|
mInner->mRelevantAttributes.Put(&key, sel->mAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* fall-through */
|
|
|
|
default:
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::StyleRuleCount(PRInt32& aCount) const
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
aCount = 0;
|
|
|
|
if (mInner && mInner->mOrderedRules) {
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = ((CSSStyleSheetImpl*)this)->mInner->mOrderedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
|
|
|
aCount = (PRInt32)cnt;
|
|
|
|
return rv;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_ILLEGAL_VALUE;
|
1998-12-03 23:20:35 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
|
|
|
aRule = (nsICSSRule*)(mInner->mOrderedRules->ElementAt(aIndex));
|
|
|
|
if (nsnull != aRule) {
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-10-14 04:59:21 +04:00
|
|
|
aRule = nsnull;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return result;
|
1998-12-03 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::GetNameSpace(nsINameSpace*& aNameSpace) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mInner) {
|
|
|
|
aNameSpace = mInner->mNameSpace;
|
|
|
|
NS_IF_ADDREF(aNameSpace);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNameSpace = nsnull;
|
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::SetDefaultNameSpaceID(PRInt32 aDefaultNameSpaceID)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mInner) {
|
|
|
|
mInner->mDefaultNameSpaceID = aDefaultNameSpaceID;
|
|
|
|
mInner->RebuildNameSpaces();
|
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::StyleSheetCount(PRInt32& aCount) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04: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.
|
|
|
|
aCount = 0;
|
|
|
|
|
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (child) {
|
|
|
|
aCount++;
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04: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;
|
|
|
|
|
|
|
|
if (mFirstChild) {
|
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while ((child) && (0 != aIndex)) {
|
|
|
|
--aIndex;
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSheet = (nsICSSStyleSheet*)child;
|
|
|
|
NS_IF_ADDREF(aSheet);
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::EnsureUniqueInner(void)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
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;
|
|
|
|
}
|
1999-05-13 08:56:04 +04:00
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::Clone(nsICSSStyleSheet*& aClone) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX no, really need to clone
|
|
|
|
CSSStyleSheetImpl* clone = new CSSStyleSheetImpl(*this);
|
|
|
|
if (clone) {
|
|
|
|
aClone = (nsICSSStyleSheet*)clone;
|
|
|
|
NS_ADDREF(aClone);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-10-14 04:59:21 +04:00
|
|
|
static void
|
|
|
|
ListRules(nsISupportsArray* aRules, FILE* aOut, PRInt32 aIndent)
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
PRUint32 count;
|
|
|
|
PRUint32 index;
|
|
|
|
if (aRules) {
|
|
|
|
aRules->Count(&count);
|
2002-04-16 02:49:26 +04:00
|
|
|
for (index = count - 1; index >= 0; --index) {
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSRule> rule = dont_AddRef((nsICSSRule*)aRules->ElementAt(index));
|
1999-10-14 04:59:21 +04:00
|
|
|
rule->List(aOut, aIndent);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
struct ListEnumData {
|
|
|
|
ListEnumData(FILE* aOut, PRInt32 aIndent)
|
|
|
|
: mOut(aOut),
|
|
|
|
mIndent(aIndent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FILE* mOut;
|
|
|
|
PRInt32 mIndent;
|
|
|
|
};
|
|
|
|
|
1999-10-16 03:29:21 +04:00
|
|
|
#if 0
|
1999-10-14 04:59:21 +04:00
|
|
|
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);
|
2001-10-16 07:53:44 +04:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(buffer).get(), data->mOut);
|
1999-10-14 04:59:21 +04:00
|
|
|
fputs("\"\n", data->mOut);
|
|
|
|
|
|
|
|
ListRules(cascade->mWeightedRules, data->mOut, data->mIndent);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-10-16 03:29:21 +04:00
|
|
|
#endif
|
1999-06-15 10:20:46 +04:00
|
|
|
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
if (! mInner) {
|
|
|
|
fputs("CSS Style Sheet - without inner data storage - ERROR\n", out);
|
|
|
|
return;
|
1998-12-02 03:37:32 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
fputs("CSS Style Sheet: ", out);
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString urlSpec;
|
|
|
|
nsresult rv = mInner->mURL->GetSpec(urlSpec);
|
|
|
|
if (NS_SUCCEEDED(rv) && !urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
1998-12-02 03:37:32 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
if (mMedia) {
|
|
|
|
fputs(" media: ", out);
|
|
|
|
index = 0;
|
|
|
|
PRUint32 count;
|
|
|
|
mMedia->Count(&count);
|
|
|
|
nsAutoString buffer;
|
|
|
|
while (index < PRInt32(count)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsIAtom> medium = dont_AddRef((nsIAtom*)mMedia->ElementAt(index++));
|
1999-10-14 04:59:21 +04:00
|
|
|
medium->ToString(buffer);
|
2001-10-16 07:53:44 +04:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(buffer).get(), out);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (index < PRInt32(count)) {
|
|
|
|
fputs(", ", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
const CSSStyleSheetImpl* child = mFirstChild;
|
|
|
|
while (nsnull != child) {
|
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("Rules in source order:\n", out);
|
|
|
|
ListRules(mInner->mOrderedRules, out, aIndent);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as CSSStyleSheetImpl's size):
|
|
|
|
* 1) sizeof(*this) + sizeof the mImportsCollection + sizeof mCuleCollection)
|
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as CSSStyleSheetImpl's size):
|
|
|
|
* 1) mInner is delegated to be counted seperately
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* 1) Recurse to mFirstChild
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void CSSStyleSheetImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSizeOfHandler != nsnull, "SizeOf handler cannot be null");
|
|
|
|
|
|
|
|
// first get the unique items collection
|
|
|
|
UNIQUE_STYLE_ITEMS(uniqueItems);
|
|
|
|
if(! uniqueItems->AddItem((void*)this)){
|
|
|
|
// this style sheet is already accounted for
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 localSize=0;
|
|
|
|
|
|
|
|
// create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("CSSStyleSheet"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(CSSStyleSheetImpl);
|
|
|
|
|
|
|
|
// add up the contained objects we won't delegate to:
|
|
|
|
// NOTE that we just add the sizeof the objects
|
|
|
|
// since the style data they contain is accounted for elsewhere
|
|
|
|
// - mImportsCollection
|
|
|
|
// - mRuleCollection
|
|
|
|
aSize += sizeof(mImportsCollection);
|
|
|
|
aSize += sizeof(mRuleCollection);
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
|
|
|
|
// size the inner
|
|
|
|
if(mInner){
|
|
|
|
mInner->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now travers the children (recursively, I'm sorry to say)
|
|
|
|
if(mFirstChild){
|
|
|
|
PRUint32 childSize=0;
|
|
|
|
mFirstChild->SizeOf(aSizeOfHandler, childSize);
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2000-05-03 03:07:11 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-10-14 04:59:21 +04:00
|
|
|
EnumClearRuleCascades(void* aProcessor, void* aData)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsICSSStyleRuleProcessor* processor = (nsICSSStyleRuleProcessor*)aProcessor;
|
|
|
|
processor->ClearRuleCascades();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSStyleSheetImpl::ClearRuleCascades(void)
|
|
|
|
{
|
|
|
|
if (mRuleProcessors) {
|
|
|
|
mRuleProcessors->EnumerateForwards(EnumClearRuleCascades, nsnull);
|
|
|
|
}
|
|
|
|
if (mParent) {
|
|
|
|
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
|
|
|
|
parent->ClearRuleCascades();
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSStyleSheetImpl::WillDirty(void)
|
|
|
|
{
|
|
|
|
return EnsureUniqueInner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSStyleSheetImpl::DidDirty(void)
|
|
|
|
{
|
|
|
|
ClearRuleCascades();
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-16 04:23:57 +04:00
|
|
|
CSSStyleSheetImpl::IsModified(PRBool* aSheetModified) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2000-04-16 04:23:57 +04:00
|
|
|
*aSheetModified = mDirty;
|
|
|
|
return NS_OK;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetModified(PRBool aModified)
|
|
|
|
{
|
|
|
|
mDirty = aModified;
|
1999-05-27 03:55:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleSheetImpl::GetType(nsAString& aType)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aType.Assign(NS_LITERAL_STRING("text/css"));
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
*aDisabled = mDisabled;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
PRBool oldState = mDisabled;
|
1999-10-14 04:59:21 +04:00
|
|
|
mDisabled = aDisabled;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
2002-04-17 08:17:16 +04:00
|
|
|
if (mDocument && (mDisabled != oldState)) {
|
1998-11-26 04:34:53 +03:00
|
|
|
mDocument->SetStyleSheetDisabledState(this, mDisabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
*aOwnerNode = mOwningNode;
|
|
|
|
NS_IF_ADDREF(*aOwnerNode);
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentStyleSheet);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
rv = mParent->QueryInterface(NS_GET_IID(nsIDOMStyleSheet),
|
|
|
|
(void **)aParentStyleSheet);
|
|
|
|
} else {
|
1999-10-14 04:59:21 +04:00
|
|
|
*aParentStyleSheet = nsnull;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
return rv;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleSheetImpl::GetHref(nsAString& aHref)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mInner && mInner->mURL) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString str;
|
|
|
|
mInner->mURL->GetSpec(str);
|
|
|
|
aHref.Assign(NS_ConvertUTF8toUCS2(str));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
else {
|
2000-04-26 17:58:56 +04:00
|
|
|
aHref.Truncate();
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
return NS_OK;
|
1999-05-19 03:14:29 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle = mTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:14:29 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleSheetImpl::GetTitle(nsAString& aTitle)
|
1999-05-19 03:14:29 +04:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aTitle.Assign(mTitle);
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSStyleSheetImpl::GetMedia(nsIDOMMediaList** aMedia)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
*aMedia = nsnull;
|
|
|
|
|
|
|
|
if (!mMedia) {
|
|
|
|
nsCOMPtr<nsISupportsArray> tmp;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_TRUE(tmp, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
mMedia = new DOMMediaListImpl(tmp, this);
|
|
|
|
NS_IF_ADDREF(mMedia);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
*aMedia = mMedia;
|
|
|
|
NS_IF_ADDREF(*aMedia);
|
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSStyleSheetImpl::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
|
|
|
|
{
|
2000-05-13 22:10:24 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aOwnerRule);
|
|
|
|
*aOwnerRule = nsnull;
|
|
|
|
|
|
|
|
// TBI: This should return the owner rule once the style system knows about
|
|
|
|
// owning rules...
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::GetCssRules(nsIDOMCSSRuleList** aCssRules)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (nsnull == mRuleCollection) {
|
2000-04-26 17:58:56 +04:00
|
|
|
mRuleCollection = new CSSRuleListImpl(this);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
*aCssRules = mRuleCollection;
|
|
|
|
NS_ADDREF(mRuleCollection);
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleSheetImpl::InsertRule(const nsAString& aRule,
|
1999-10-14 04:59:21 +04:00
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* aReturn)
|
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_FAILURE);
|
|
|
|
nsresult result;
|
2001-09-06 17:14:35 +04:00
|
|
|
result = WillDirty();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
if (! mInner->mOrderedRules) {
|
|
|
|
result = NS_NewISupportsArray(&(mInner->mOrderedRules));
|
|
|
|
}
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
mInner->mOrderedRules->Count(&count);
|
|
|
|
if (aIndex > count)
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICSSLoader> loader;
|
|
|
|
nsCOMPtr<nsICSSParser> css;
|
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer(do_QueryInterface(mDocument));
|
|
|
|
if (htmlContainer) {
|
|
|
|
htmlContainer->GetCSSLoader(*getter_AddRefs(loader));
|
|
|
|
}
|
2001-10-19 17:50:30 +04:00
|
|
|
NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!");
|
2001-09-05 04:00:18 +04:00
|
|
|
if (loader) {
|
|
|
|
result = loader->GetParserFor(this, getter_AddRefs(css));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = NS_NewCSSParser(getter_AddRefs(css));
|
2001-10-19 17:50:30 +04:00
|
|
|
if (css) {
|
|
|
|
css->SetStyleSheet(this);
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-10-19 17:50:30 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mDocument) {
|
|
|
|
result = mDocument->BeginUpdate();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> rules;
|
|
|
|
result = css->ParseRule(aRule, mInner->mURL, getter_AddRefs(rules));
|
2001-09-05 04:00:18 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-09-06 17:14:35 +04:00
|
|
|
|
|
|
|
PRUint32 rulecount = 0;
|
|
|
|
rules->Count(&rulecount);
|
|
|
|
if (rulecount == 0 && !aRule.IsEmpty()) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
// Hierarchy checking. Just check the first and last rule in the list.
|
|
|
|
|
|
|
|
// check that we're not inserting before a charset rule
|
|
|
|
nsCOMPtr<nsICSSRule> nextRule;
|
|
|
|
PRInt32 nextType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
nextRule = dont_AddRef((nsICSSRule*)mInner->mOrderedRules->ElementAt(aIndex));
|
|
|
|
if (nextRule) {
|
|
|
|
nextRule->GetType(nextType);
|
|
|
|
if (nextType == nsICSSRule::CHARSET_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
// check last rule in list
|
|
|
|
nsCOMPtr<nsICSSRule> lastRule = dont_AddRef((nsICSSRule*)rules->ElementAt(rulecount-1));
|
|
|
|
PRInt32 lastType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
lastRule->GetType(lastType);
|
|
|
|
|
|
|
|
if (nextType == nsICSSRule::IMPORT_RULE &&
|
|
|
|
lastType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
lastType != nsICSSRule::IMPORT_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextType == nsICSSRule::NAMESPACE_RULE &&
|
|
|
|
lastType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
lastType != nsICSSRule::IMPORT_RULE &&
|
|
|
|
lastType != nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check first rule in list
|
|
|
|
nsCOMPtr<nsICSSRule> firstRule = dont_AddRef((nsICSSRule*)rules->ElementAt(0));
|
|
|
|
PRInt32 firstType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
firstRule->GetType(firstType);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (aIndex != 0) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::CHARSET_RULE) { // no inserting charset at nonzero position
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSRule> prevRule = dont_AddRef((nsICSSRule*)mInner->mOrderedRules->ElementAt(aIndex-1));
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 prevType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
prevRule->GetType(prevType);
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::IMPORT_RULE &&
|
2001-09-05 04:00:18 +04:00
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::NAMESPACE_RULE &&
|
2001-09-05 04:00:18 +04:00
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE &&
|
|
|
|
prevType != nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
result = mInner->mOrderedRules->InsertElementsAt(rules, aIndex);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-10-19 17:50:30 +04:00
|
|
|
DidDirty();
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSRule> cssRule;
|
|
|
|
PRUint32 counter;
|
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
cssRule = dont_AddRef((nsICSSRule*)rules->ElementAt(counter));
|
|
|
|
cssRule->SetStyleSheet(this);
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
cssRule->GetType(type);
|
|
|
|
if (type == nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
if (! mInner->mNameSpace) {
|
|
|
|
nsCOMPtr<nsINameSpaceManager> nameSpaceMgr;
|
|
|
|
result = NS_NewNameSpaceManager(getter_AddRefs(nameSpaceMgr));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
nameSpaceMgr->CreateRootNameSpace(*getter_AddRefs(mInner->mNameSpace));
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
NS_ENSURE_TRUE(mInner->mNameSpace, NS_ERROR_FAILURE);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule(do_QueryInterface(cssRule));
|
|
|
|
nsCOMPtr<nsINameSpace> newNameSpace;
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
mInner->mNameSpace->CreateChildNameSpace(prefix, urlSpec,
|
|
|
|
*getter_AddRefs(newNameSpace));
|
|
|
|
if (newNameSpace) {
|
|
|
|
mInner->mNameSpace = newNameSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CheckRuleForAttributes(cssRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
result = mDocument->StyleRuleAdded(this, cssRule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
|
|
|
|
if (mDocument) {
|
2001-09-05 04:00:18 +04:00
|
|
|
result = mDocument->EndUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
}
|
2001-09-28 05:38:36 +04:00
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
loader->RecycleParser(css);
|
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
*aReturn = aIndex;
|
|
|
|
return NS_OK;
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex)
|
1998-06-05 10:06:50 +04:00
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult result = NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1998-06-05 10:06:50 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX TBI: handle @rule types
|
1999-06-03 05:57:52 +04:00
|
|
|
if (mInner && mInner->mOrderedRules) {
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mDocument) {
|
|
|
|
result = mDocument->BeginUpdate();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
result = WillDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-09-05 04:00:18 +04:00
|
|
|
PRUint32 count;
|
|
|
|
mInner->mOrderedRules->Count(&count);
|
|
|
|
if (aIndex >= count)
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSRule> rule =
|
|
|
|
dont_AddRef((nsICSSRule*)mInner->mOrderedRules->ElementAt(aIndex));
|
2001-09-05 04:00:18 +04:00
|
|
|
if (rule) {
|
1999-10-14 04:59:21 +04:00
|
|
|
mInner->mOrderedRules->RemoveElementAt(aIndex);
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
DidDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
result = mDocument->StyleRuleRemoved(this, rule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = mDocument->EndUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1998-06-05 10:06:50 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSStyleSheetImpl::DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroup);
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
result = aGroup->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
// check that the rule actually belongs to this sheet!
|
|
|
|
nsCOMPtr<nsIDOMCSSRule> domRule(do_QueryInterface(rule));
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> ruleSheet;
|
|
|
|
result = domRule->GetParentStyleSheet(getter_AddRefs(ruleSheet));
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> thisSheet;
|
|
|
|
this->QueryInterface(NS_GET_IID(nsIDOMCSSStyleSheet), getter_AddRefs(thisSheet));
|
|
|
|
|
|
|
|
if (thisSheet != ruleSheet) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = mDocument->BeginUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = aGroup->DeleteStyleRuleAt(aIndex);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
result = mDocument->StyleRuleRemoved(this, rule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = mDocument->EndUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSStyleSheetImpl::InsertRuleIntoGroup(const nsAString & aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
// check that the group actually belongs to this sheet!
|
|
|
|
nsCOMPtr<nsIDOMCSSRule> domGroup(do_QueryInterface(aGroup));
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> groupSheet;
|
|
|
|
result = domGroup->GetParentStyleSheet(getter_AddRefs(groupSheet));
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> thisSheet;
|
|
|
|
this->QueryInterface(NS_GET_IID(nsIDOMCSSStyleSheet), getter_AddRefs(thisSheet));
|
|
|
|
|
|
|
|
if (thisSheet != groupSheet) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the css parser
|
|
|
|
nsCOMPtr<nsICSSLoader> loader;
|
|
|
|
nsCOMPtr<nsICSSParser> css;
|
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer(do_QueryInterface(mDocument));
|
|
|
|
if (htmlContainer) {
|
|
|
|
htmlContainer->GetCSSLoader(*getter_AddRefs(loader));
|
|
|
|
}
|
2001-10-19 17:50:30 +04:00
|
|
|
NS_ASSERTION(loader || !mDocument, "Document with no CSS loader!");
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
if (loader) {
|
|
|
|
result = loader->GetParserFor(this, getter_AddRefs(css));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = NS_NewCSSParser(getter_AddRefs(css));
|
2001-10-19 17:50:30 +04:00
|
|
|
if (css) {
|
|
|
|
css->SetStyleSheet(this);
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
// parse and grab the rule
|
|
|
|
result = mDocument->BeginUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> rules;
|
|
|
|
result = css->ParseRule(aRule, mInner->mURL, getter_AddRefs(rules));
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRUint32 rulecount = 0;
|
|
|
|
rules->Count(&rulecount);
|
|
|
|
if (rulecount == 0 && !aRule.IsEmpty()) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRUint32 counter;
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
// Only rulesets are allowed in a group as of CSS2
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
rule = dont_AddRef((nsICSSRule*)rules->ElementAt(counter));
|
|
|
|
rule->GetType(type);
|
|
|
|
if (type != nsICSSRule::STYLE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
result = aGroup->InsertStyleRulesAt(aIndex, rules);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
DidDirty();
|
2001-09-06 17:14:35 +04:00
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
rule = dont_AddRef((nsICSSRule*)rules->ElementAt(counter));
|
|
|
|
CheckRuleForAttributes(rule);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
result = mDocument->StyleRuleAdded(this, rule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
result = mDocument->EndUpdate();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2001-09-28 05:38:36 +04:00
|
|
|
if (loader) {
|
|
|
|
loader->RecycleParser(css);
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
*_retval = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX for backwards compatibility and convenience
|
2001-10-20 01:02:39 +04:00
|
|
|
NS_EXPORT nsresult
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsICSSStyleSheet* sheet;
|
|
|
|
nsresult rv;
|
|
|
|
if (NS_FAILED(rv = NS_NewCSSStyleSheet(&sheet)))
|
|
|
|
return rv;
|
1999-05-19 03:14:29 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_FAILED(rv = sheet->Init(aURL))) {
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
return rv;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
*aInstancePtrResult = sheet;
|
1999-06-10 09:29:22 +04:00
|
|
|
return NS_OK;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2001-10-20 01:02:39 +04:00
|
|
|
NS_EXPORT nsresult
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl *it = new CSSStyleSheetImpl();
|
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = it;
|
1998-10-06 05:39:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style rule processor implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
CSSRuleProcessor::CSSRuleProcessor(void)
|
|
|
|
: mSheets(nsnull),
|
2001-07-17 00:59:28 +04:00
|
|
|
mRuleCascades(nsnull)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_INIT_REFCNT();
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static PRBool
|
|
|
|
DropProcessorReference(nsISupports* aSheet, void* aProcessor)
|
1999-05-19 03:14:29 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsICSSStyleSheet* sheet = (nsICSSStyleSheet*)aSheet;
|
|
|
|
nsICSSStyleRuleProcessor* processor = (nsICSSStyleRuleProcessor*)aProcessor;
|
|
|
|
sheet->DropRuleProcessorReference(processor);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSRuleProcessor::~CSSRuleProcessor(void)
|
|
|
|
{
|
|
|
|
if (mSheets) {
|
|
|
|
mSheets->EnumerateForwards(DropProcessorReference, this);
|
|
|
|
NS_RELEASE(mSheets);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
ClearRuleCascades();
|
1999-05-19 03:14:29 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMPL_ADDREF(CSSRuleProcessor);
|
|
|
|
NS_IMPL_RELEASE(CSSRuleProcessor);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSRuleProcessor::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NULL == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsICSSStyleRuleProcessor))) {
|
1999-10-14 04:59:21 +04:00
|
|
|
*aInstancePtrResult = (void*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIStyleRuleProcessor))) {
|
1999-10-14 04:59:21 +04:00
|
|
|
*aInstancePtrResult = (void*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSRuleProcessor::AppendStyleSheet(nsICSSStyleSheet* aStyleSheet)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (! mSheets) {
|
|
|
|
result = NS_NewISupportsArray(&mSheets);
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mSheets) {
|
|
|
|
mSheets->AppendElement(aStyleSheet);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1999-05-27 03:55:12 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(RuleProcessorData)
|
2001-01-27 08:48:41 +03:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsRuleWalker* aRuleWalker,
|
|
|
|
nsCompatibility* aCompat /*= nsnull*/)
|
2001-01-27 08:48:41 +03:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
MOZ_COUNT_CTOR(RuleProcessorData);
|
2001-04-28 06:16:16 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
NS_PRECONDITION(aPresContext, "null pointer");
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_ASSERTION(!aContent || aContent->IsContentOfType(nsIContent::eELEMENT),
|
|
|
|
"non-element leaked into SelectorMatches");
|
|
|
|
|
2001-01-27 08:48:41 +03:00
|
|
|
mPresContext = aPresContext;
|
|
|
|
mContent = aContent;
|
|
|
|
mParentContent = nsnull;
|
2001-06-01 02:19:43 +04:00
|
|
|
mRuleWalker = aRuleWalker;
|
2001-11-11 02:51:45 +03:00
|
|
|
mScopedRoot = nsnull;
|
2001-01-27 08:48:41 +03:00
|
|
|
|
|
|
|
mContentTag = nsnull;
|
|
|
|
mContentID = nsnull;
|
|
|
|
mStyledContent = nsnull;
|
|
|
|
mIsHTMLContent = PR_FALSE;
|
|
|
|
mIsHTMLLink = PR_FALSE;
|
|
|
|
mIsSimpleXLink = PR_FALSE;
|
2002-03-07 06:34:29 +03:00
|
|
|
mIsChecked = PR_FALSE;
|
2001-01-27 08:48:41 +03:00
|
|
|
mLinkState = eLinkState_Unknown;
|
|
|
|
mEventState = NS_EVENT_STATE_UNSPECIFIED;
|
|
|
|
mNameSpaceID = kNameSpaceID_Unknown;
|
2001-04-28 06:16:16 +04:00
|
|
|
mPreviousSiblingData = nsnull;
|
|
|
|
mParentData = nsnull;
|
2001-01-27 08:48:41 +03:00
|
|
|
|
|
|
|
if(!aCompat) {
|
|
|
|
// get the compat. mode (unless it is provided)
|
|
|
|
nsCompatibility quirkMode = eCompatibility_Standard;
|
|
|
|
mPresContext->GetCompatibilityMode(&quirkMode);
|
|
|
|
mIsQuirkMode = eCompatibility_Standard == quirkMode ? PR_FALSE : PR_TRUE;
|
|
|
|
} else {
|
|
|
|
mIsQuirkMode = eCompatibility_Standard == *aCompat ? PR_FALSE : PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(aContent){
|
|
|
|
// we hold no ref to the content...
|
|
|
|
mContent = aContent;
|
|
|
|
|
|
|
|
// get the namespace
|
|
|
|
aContent->GetNameSpaceID(mNameSpaceID);
|
|
|
|
|
|
|
|
// get the tag and parent
|
|
|
|
aContent->GetTag(mContentTag);
|
|
|
|
aContent->GetParent(mParentContent);
|
|
|
|
|
|
|
|
// get the event state
|
|
|
|
nsIEventStateManager* eventStateManager = nsnull;
|
|
|
|
mPresContext->GetEventStateManager(&eventStateManager);
|
|
|
|
if(eventStateManager) {
|
|
|
|
eventStateManager->GetContentState(aContent, mEventState);
|
|
|
|
NS_RELEASE(eventStateManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the styledcontent interface and the ID
|
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&mStyledContent))) {
|
|
|
|
NS_ASSERTION(mStyledContent, "Succeeded but returned null");
|
|
|
|
mStyledContent->GetID(mContentID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if there are attributes for the content
|
|
|
|
PRInt32 attrCount = 0;
|
2001-08-17 12:14:14 +04:00
|
|
|
aContent->GetAttrCount(attrCount);
|
2001-01-27 08:48:41 +03:00
|
|
|
mHasAttributes = PRBool(attrCount > 0);
|
|
|
|
|
|
|
|
// check for HTMLContent and Link status
|
2001-06-01 02:19:43 +04:00
|
|
|
if (aContent->IsContentOfType(nsIContent::eHTML))
|
2001-01-27 08:48:41 +03:00
|
|
|
mIsHTMLContent = PR_TRUE;
|
|
|
|
|
|
|
|
// if HTML content and it has some attributes, check for an HTML link
|
|
|
|
// NOTE: optimization: cannot be a link if no attributes (since it needs an href)
|
|
|
|
if (PR_TRUE == mIsHTMLContent && mHasAttributes) {
|
|
|
|
// check if it is an HTML Link
|
|
|
|
if(nsStyleUtil::IsHTMLLink(aContent, mContentTag, mPresContext, &mLinkState)) {
|
|
|
|
mIsHTMLLink = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if not an HTML link, check for a simple xlink (cannot be both HTML link and xlink)
|
|
|
|
// NOTE: optimization: cannot be an XLink if no attributes (since it needs an
|
|
|
|
if(PR_FALSE == mIsHTMLLink &&
|
2001-06-01 02:19:43 +04:00
|
|
|
mHasAttributes &&
|
|
|
|
!(aContent->IsContentOfType(nsIContent::eHTML) || aContent->IsContentOfType(nsIContent::eXUL)) &&
|
2001-01-27 08:48:41 +03:00
|
|
|
nsStyleUtil::IsSimpleXlink(aContent, mPresContext, &mLinkState)) {
|
|
|
|
mIsSimpleXLink = PR_TRUE;
|
|
|
|
}
|
2002-03-07 06:34:29 +03:00
|
|
|
|
|
|
|
if (mIsHTMLContent) {
|
|
|
|
PRBool isChecked = PR_FALSE;
|
|
|
|
if (mContentTag == nsHTMLAtoms::option) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLOptionElement> optEl = do_QueryInterface(mContent);
|
|
|
|
optEl->GetSelected(&isChecked);
|
2002-03-13 13:12:33 +03:00
|
|
|
} else if (mContentTag == nsHTMLAtoms::input) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputEl = do_QueryInterface(mContent);
|
|
|
|
inputEl->GetChecked(&isChecked);
|
2002-03-07 06:34:29 +03:00
|
|
|
}
|
|
|
|
mIsChecked = isChecked;
|
|
|
|
}
|
2001-01-27 08:48:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorData::~RuleProcessorData()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(RuleProcessorData);
|
|
|
|
|
|
|
|
if (mPreviousSiblingData)
|
|
|
|
mPreviousSiblingData->Destroy(mPresContext);
|
|
|
|
if (mParentData)
|
|
|
|
mParentData->Destroy(mPresContext);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mParentContent);
|
|
|
|
NS_IF_RELEASE(mContentTag);
|
|
|
|
NS_IF_RELEASE(mContentID);
|
|
|
|
NS_IF_RELEASE(mStyledContent);
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static const PRUnichar kNullCh = PRUnichar('\0');
|
|
|
|
|
|
|
|
static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsAutoString valueList(aValueList);
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
valueList.Append(kNullCh); // put an extra null at the end
|
1999-05-27 03:55:12 +04:00
|
|
|
|
2001-06-30 15:02:25 +04:00
|
|
|
PRUnichar* value = (PRUnichar*)(const PRUnichar*)aValue.get();
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)valueList.get();
|
1999-10-14 04:59:21 +04:00
|
|
|
PRUnichar* end = start;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
2000-03-12 14:10:07 +03:00
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
1999-10-14 04:59:21 +04:00
|
|
|
start++;
|
|
|
|
}
|
|
|
|
end = start;
|
|
|
|
|
2000-03-12 14:10:07 +03:00
|
|
|
while ((kNullCh != *end) && (PR_FALSE == nsCRT::IsAsciiSpace(*end))) { // look for space or end
|
1999-10-14 04:59:21 +04:00
|
|
|
end++;
|
|
|
|
}
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
if (start < end) {
|
|
|
|
if (aCaseSensitive) {
|
2000-04-27 04:07:12 +04:00
|
|
|
if (!nsCRT::strcmp(value, start)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-02-10 18:49:46 +03:00
|
|
|
if (nsDependentString(value).Equals(nsDependentString(start),
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
inline PRBool IsEventPseudo(nsIAtom* aAtom)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
2001-01-27 08:48:41 +03:00
|
|
|
return PRBool ((nsCSSAtoms::activePseudo == aAtom) ||
|
1999-10-14 04:59:21 +04:00
|
|
|
(nsCSSAtoms::dragOverPseudo == aAtom) ||
|
2001-01-27 08:48:41 +03:00
|
|
|
(nsCSSAtoms::focusPseudo == aAtom) ||
|
1999-10-14 04:59:21 +04:00
|
|
|
(nsCSSAtoms::hoverPseudo == aAtom));
|
2001-01-27 08:48:41 +03:00
|
|
|
// XXX selected, enabled, disabled, selection?
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
inline PRBool IsLinkPseudo(nsIAtom* aAtom)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
return PRBool ((nsCSSAtoms::linkPseudo == aAtom) ||
|
2001-06-05 05:00:11 +04:00
|
|
|
(nsCSSAtoms::visitedPseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::anyLinkPseudo == aAtom));
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
inline PRBool IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTag, PRBool aSelectorIsGlobal)
|
2000-03-31 11:08:36 +04:00
|
|
|
{
|
|
|
|
// if the selector is global, meaning it is not tied to a tag, then
|
|
|
|
// we restrict the application of the event pseudo to the following tags
|
|
|
|
if (aSelectorIsGlobal) {
|
|
|
|
return PRBool ((nsHTMLAtoms::a == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::button == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::img == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::input == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::li == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::label == aContentTag) ||
|
|
|
|
(nsHTMLAtoms::select == aContentTag) ||
|
2001-10-30 09:02:05 +03:00
|
|
|
(nsHTMLAtoms::textarea == aContentTag));
|
2000-03-31 11:08:36 +04:00
|
|
|
} else {
|
|
|
|
// selector is not global, so apply the event pseudo to everything except HTML and BODY
|
|
|
|
return PRBool ((nsHTMLAtoms::html != aContentTag) &&
|
|
|
|
(nsHTMLAtoms::body != aContentTag));
|
|
|
|
}
|
|
|
|
}
|
2000-04-28 14:02:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
static PRBool IsSignificantChild(nsIContent* aChild, PRBool aAcceptNonWhitespaceText)
|
|
|
|
{
|
|
|
|
nsIAtom* tag;
|
|
|
|
aChild->GetTag(tag); // skip text & comments
|
|
|
|
if ((tag != nsLayoutAtoms::textTagName) &&
|
|
|
|
(tag != nsLayoutAtoms::commentTagName) &&
|
|
|
|
(tag != nsLayoutAtoms::processingInstructionTagName)) {
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (aAcceptNonWhitespaceText) {
|
|
|
|
if (tag == nsLayoutAtoms::textTagName) { // skip only whitespace text
|
2001-01-27 08:48:41 +03:00
|
|
|
nsITextContent* text = nsnull;
|
|
|
|
if (NS_SUCCEEDED(aChild->QueryInterface(NS_GET_IID(nsITextContent), (void**)&text))) {
|
|
|
|
PRBool isWhite;
|
|
|
|
text->IsOnlyWhitespace(&isWhite);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
if (! isWhite) {
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-28 14:02:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-11 07:49:30 +04:00
|
|
|
// NOTE: The |aStateMask| code isn't going to work correctly anymore if
|
|
|
|
// we start batching style changes, because if multiple states change in
|
|
|
|
// separate notifications then we might determine the style is not
|
|
|
|
// state-dependent when it really is (e.g., determining that a
|
|
|
|
// :hover:active rule no longer matches when both states are unset).
|
2001-11-11 02:51:45 +03:00
|
|
|
static PRBool SelectorMatches(RuleProcessorData &data,
|
2001-01-27 08:48:41 +03:00
|
|
|
nsCSSSelector* aSelector,
|
2002-04-11 07:49:30 +04:00
|
|
|
PRInt32 aStateMask, // states NOT to test
|
2001-03-20 14:49:20 +03:00
|
|
|
PRInt8 aNegationIndex)
|
|
|
|
|
|
|
|
{
|
|
|
|
// if we are dealing with negations, reverse the values of PR_TRUE and PR_FALSE
|
|
|
|
PRBool localFalse = PRBool(0 < aNegationIndex);
|
|
|
|
PRBool localTrue = PRBool(0 == aNegationIndex);
|
2001-04-10 17:43:20 +04:00
|
|
|
PRBool result = localTrue;
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2001-04-10 17:43:20 +04:00
|
|
|
// Do not perform the test if aNegationIndex==1
|
2001-03-20 14:49:20 +03:00
|
|
|
// because it then contains only negated IDs, classes, attributes and pseudo-
|
|
|
|
// classes
|
2001-06-05 05:00:11 +04:00
|
|
|
if (1 != aNegationIndex) {
|
2001-03-20 14:49:20 +03:00
|
|
|
if (kNameSpaceID_Unknown != aSelector->mNameSpace) {
|
|
|
|
if (data.mNameSpaceID != aSelector->mNameSpace) {
|
2001-04-10 17:43:20 +04:00
|
|
|
result = localFalse;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 17:43:20 +04:00
|
|
|
if (localTrue == result) {
|
|
|
|
if ((nsnull != aSelector->mTag) && (aSelector->mTag != data.mContentTag)) {
|
|
|
|
result = localFalse;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
2001-06-05 05:00:11 +04:00
|
|
|
// optimization : bail out early if we can
|
|
|
|
if (!result) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2001-04-10 17:43:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
result = PR_TRUE;
|
|
|
|
|
|
|
|
if (nsnull != aSelector->mPseudoClassList) { // test for pseudo class match
|
2001-04-05 23:53:13 +04:00
|
|
|
// first-child, root, lang, active, focus, hover, link, visited...
|
2001-03-20 14:49:20 +03:00
|
|
|
// XXX disabled, enabled, selected, selection
|
|
|
|
nsAtomList* pseudoClass = aSelector->mPseudoClassList;
|
|
|
|
|
2001-04-10 17:43:20 +04:00
|
|
|
while (result && (nsnull != pseudoClass)) {
|
2001-03-20 14:49:20 +03:00
|
|
|
if ((nsCSSAtoms::firstChildPseudo == pseudoClass->mAtom) ||
|
|
|
|
(nsCSSAtoms::firstNodePseudo == pseudoClass->mAtom) ) {
|
|
|
|
nsIContent* firstChild = nsnull;
|
|
|
|
nsIContent* parent = data.mParentContent;
|
|
|
|
if (parent) {
|
|
|
|
PRInt32 index = -1;
|
|
|
|
do {
|
|
|
|
parent->ChildAt(++index, firstChild);
|
2001-03-30 14:20:57 +04:00
|
|
|
if (firstChild) { // stop at first non-comment and non-whitespace node (and non-text node for firstChild)
|
2001-03-20 14:49:20 +03:00
|
|
|
if (IsSignificantChild(firstChild, (nsCSSAtoms::firstNodePseudo == pseudoClass->mAtom))) {
|
1999-10-14 04:59:21 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
NS_RELEASE(firstChild);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1 == 1);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
result = PRBool(localTrue == (data.mContent == firstChild));
|
|
|
|
NS_IF_RELEASE(firstChild);
|
|
|
|
}
|
2001-03-30 14:20:57 +04:00
|
|
|
else if ((nsCSSAtoms::lastChildPseudo == pseudoClass->mAtom) ||
|
|
|
|
(nsCSSAtoms::lastNodePseudo == pseudoClass->mAtom)) {
|
2001-03-20 14:49:20 +03:00
|
|
|
nsIContent* lastChild = nsnull;
|
|
|
|
nsIContent* parent = data.mParentContent;
|
|
|
|
if (parent) {
|
|
|
|
PRInt32 index;
|
|
|
|
parent->ChildCount(index);
|
|
|
|
do {
|
|
|
|
parent->ChildAt(--index, lastChild);
|
2001-03-30 14:20:57 +04:00
|
|
|
if (lastChild) { // stop at first non-comment and non-whitespace node (and non-text node for lastChild)
|
|
|
|
if (IsSignificantChild(lastChild, (nsCSSAtoms::lastNodePseudo == pseudoClass->mAtom))) {
|
2000-04-28 14:02:12 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
NS_RELEASE(lastChild);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1 == 1);
|
2000-04-28 14:02:12 +04:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
result = PRBool(localTrue == (data.mContent == lastChild));
|
|
|
|
NS_IF_RELEASE(lastChild);
|
|
|
|
}
|
2001-04-11 06:55:41 +04:00
|
|
|
else if (nsCSSAtoms::emptyPseudo == pseudoClass->mAtom) {
|
|
|
|
nsIContent* child = nsnull;
|
|
|
|
nsIContent* element = data.mContent;
|
|
|
|
PRInt32 index = -1;
|
|
|
|
do {
|
|
|
|
element->ChildAt(++index, child);
|
|
|
|
if (child) { // stop at first non-comment and non-whitespace node
|
|
|
|
if (IsSignificantChild(child, PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1 == 1);
|
|
|
|
result = PRBool(localTrue == (child == nsnull));
|
|
|
|
NS_IF_RELEASE(child);
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
else if (nsCSSAtoms::rootPseudo == pseudoClass->mAtom) {
|
|
|
|
if (data.mParentContent) {
|
|
|
|
result = localFalse;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = localTrue;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 02:22:47 +04:00
|
|
|
else if (nsCSSAtoms::xblBoundElementPseudo == pseudoClass->mAtom) {
|
2001-11-11 02:51:45 +03:00
|
|
|
result = (data.mScopedRoot && data.mScopedRoot == data.mContent)
|
|
|
|
? localTrue : localFalse;
|
2001-04-09 02:22:47 +04:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
else if (nsCSSAtoms::langPseudo == pseudoClass->mAtom) {
|
|
|
|
// XXX not yet implemented
|
2001-04-10 17:43:20 +04:00
|
|
|
result = PR_FALSE;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
else if (IsEventPseudo(pseudoClass->mAtom)) {
|
|
|
|
// check if the element is event-sensitive
|
|
|
|
// NOTE: we distinguish between global and subjected selectors so
|
|
|
|
// pass that information on to the determining routine
|
2001-04-12 03:47:34 +04:00
|
|
|
// ALSO NOTE: we used to do this only in Quirks mode, but because of
|
|
|
|
// performance problems we do it all the time now (bug 68821)
|
|
|
|
// When style resolution due to state changes is optimized this
|
|
|
|
// should go back to QuirksMode only behavour (see also bug 75559)
|
2001-03-20 14:49:20 +03:00
|
|
|
PRBool isSelectorGlobal = aSelector->mTag==nsnull ? PR_TRUE : PR_FALSE;
|
2001-04-14 10:34:50 +04:00
|
|
|
if ((data.mIsHTMLContent) &&
|
|
|
|
(!IsEventSensitive(pseudoClass->mAtom, data.mContentTag, isSelectorGlobal))){
|
2001-03-20 14:49:20 +03:00
|
|
|
result = localFalse;
|
2002-04-11 07:49:30 +04:00
|
|
|
} else {
|
2001-03-20 14:49:20 +03:00
|
|
|
if (nsCSSAtoms::activePseudo == pseudoClass->mAtom) {
|
2002-04-11 07:49:30 +04:00
|
|
|
result = (aStateMask & NS_EVENT_STATE_ACTIVE) ||
|
|
|
|
(localTrue == (0 != (data.mEventState & NS_EVENT_STATE_ACTIVE)));
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
else if (nsCSSAtoms::focusPseudo == pseudoClass->mAtom) {
|
2002-04-11 07:49:30 +04:00
|
|
|
result = (aStateMask & NS_EVENT_STATE_FOCUS) ||
|
|
|
|
(localTrue == (0 != (data.mEventState & NS_EVENT_STATE_FOCUS)));
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::hoverPseudo == pseudoClass->mAtom) {
|
2002-04-11 07:49:30 +04:00
|
|
|
result = (aStateMask & NS_EVENT_STATE_HOVER) ||
|
|
|
|
(localTrue == (0 != (data.mEventState & NS_EVENT_STATE_HOVER)));
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::dragOverPseudo == pseudoClass->mAtom) {
|
2002-04-11 07:49:30 +04:00
|
|
|
result = (aStateMask & NS_EVENT_STATE_DRAGOVER) ||
|
|
|
|
(localTrue == (0 != (data.mEventState & NS_EVENT_STATE_DRAGOVER)));
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsLinkPseudo(pseudoClass->mAtom)) {
|
|
|
|
if (data.mIsHTMLLink || data.mIsSimpleXLink) {
|
2002-04-11 07:49:30 +04:00
|
|
|
if (result) {
|
2001-06-05 05:00:11 +04:00
|
|
|
if (nsCSSAtoms::anyLinkPseudo == pseudoClass->mAtom) {
|
|
|
|
result = localTrue;
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::linkPseudo == pseudoClass->mAtom) {
|
2001-03-20 14:49:20 +03:00
|
|
|
result = PRBool(localTrue == (eLinkState_Unvisited == data.mLinkState));
|
|
|
|
}
|
|
|
|
else if (nsCSSAtoms::visitedPseudo == pseudoClass->mAtom) {
|
|
|
|
result = PRBool(localTrue == (eLinkState_Visited == data.mLinkState));
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-03-20 14:49:20 +03:00
|
|
|
result = localFalse; // not a link
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
2002-03-07 06:34:29 +03:00
|
|
|
else if (nsCSSAtoms::checkedPseudo == pseudoClass->mAtom) {
|
|
|
|
// This pseudoclass matches the selected state on the following elements:
|
|
|
|
// <option>
|
|
|
|
// <input type=checkbox>
|
|
|
|
// <input type=radio>
|
2002-04-11 07:49:30 +04:00
|
|
|
if (!(aStateMask & NS_EVENT_STATE_CHECKED))
|
2002-03-07 06:34:29 +03:00
|
|
|
result = data.mIsChecked ? localTrue : localFalse;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
else {
|
|
|
|
result = localFalse; // unknown pseudo class
|
|
|
|
}
|
|
|
|
pseudoClass = pseudoClass->mNext;
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-21 11:10:20 +03:00
|
|
|
|
|
|
|
// namespace/tag match
|
2001-04-10 17:43:20 +04:00
|
|
|
if (result && aSelector->mAttrList) { // test for attribute match
|
2001-03-21 11:10:20 +03:00
|
|
|
// if no attributes on the content, no match
|
|
|
|
if(!data.mHasAttributes) {
|
|
|
|
result = localFalse;
|
|
|
|
} else {
|
2001-04-10 17:43:20 +04:00
|
|
|
result = localTrue;
|
2001-03-21 11:10:20 +03:00
|
|
|
nsAttrSelector* attr = aSelector->mAttrList;
|
|
|
|
do {
|
2002-03-16 18:24:08 +03:00
|
|
|
if (!data.mContent->HasAttr(attr->mNameSpace, attr->mAttr)) {
|
2001-03-21 11:10:20 +03:00
|
|
|
result = localFalse;
|
|
|
|
}
|
2002-03-16 18:24:08 +03:00
|
|
|
else if (attr->mFunction != NS_ATTR_FUNC_SET) {
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult attrState =
|
|
|
|
data.mContent->GetAttr(attr->mNameSpace, attr->mAttr, value);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(attrState) &&
|
|
|
|
NS_CONTENT_ATTR_NOT_THERE != attrState,
|
|
|
|
"HasAttr lied or GetAttr failed");
|
2001-04-18 08:36:52 +04:00
|
|
|
PRBool isCaseSensitive = attr->mCaseSensitive;
|
2001-03-21 11:10:20 +03:00
|
|
|
switch (attr->mFunction) {
|
|
|
|
case NS_ATTR_FUNC_EQUALS:
|
|
|
|
if (isCaseSensitive) {
|
|
|
|
result = PRBool(localTrue == value.Equals(attr->mValue));
|
|
|
|
}
|
|
|
|
else {
|
2002-03-19 09:46:56 +03:00
|
|
|
result = PRBool(localTrue == value.Equals(attr->mValue, nsCaseInsensitiveStringComparator()));
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_INCLUDES:
|
|
|
|
result = PRBool(localTrue == ValueIncludes(value, attr->mValue, isCaseSensitive));
|
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_DASHMATCH:
|
2001-06-20 02:46:08 +04:00
|
|
|
{
|
|
|
|
PRUint32 selLen = attr->mValue.Length();
|
|
|
|
PRUint32 valLen = value.Length();
|
|
|
|
if (selLen > valLen) {
|
|
|
|
result = localFalse;
|
|
|
|
} else {
|
|
|
|
if (selLen != valLen &&
|
|
|
|
value.CharAt(selLen) != PRUnichar('-')) {
|
|
|
|
// to match, the value must have a dash after the end of
|
|
|
|
// the selector's text (unless the selector and the value
|
|
|
|
// have the same text)
|
|
|
|
result = localFalse;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isCaseSensitive)
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, 0, selLen).Equals(attr->mValue, nsDefaultStringComparator()));
|
2001-06-20 02:46:08 +04:00
|
|
|
else
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, 0, selLen).Equals(attr->mValue, nsCaseInsensitiveStringComparator()));
|
2001-06-20 02:46:08 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-21 11:10:20 +03:00
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_ENDSMATCH:
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
|
|
|
PRUint32 selLen = attr->mValue.Length();
|
|
|
|
PRUint32 valLen = value.Length();
|
|
|
|
if (selLen > valLen) {
|
2001-06-20 02:46:08 +04:00
|
|
|
result = localFalse;
|
2001-04-28 06:16:16 +04:00
|
|
|
} else {
|
|
|
|
if (isCaseSensitive)
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, valLen - selLen, selLen).Equals(attr->mValue, nsDefaultStringComparator()));
|
2001-04-28 06:16:16 +04:00
|
|
|
else
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, valLen - selLen, selLen).Equals(attr->mValue, nsCaseInsensitiveStringComparator()));
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_BEGINSMATCH:
|
2001-04-28 06:16:16 +04:00
|
|
|
{
|
|
|
|
PRUint32 selLen = attr->mValue.Length();
|
|
|
|
PRUint32 valLen = value.Length();
|
|
|
|
if (selLen > valLen) {
|
2001-06-20 02:46:08 +04:00
|
|
|
result = localFalse;
|
2001-04-28 06:16:16 +04:00
|
|
|
} else {
|
|
|
|
if (isCaseSensitive)
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, 0, selLen).Equals(attr->mValue, nsDefaultStringComparator()));
|
2001-04-28 06:16:16 +04:00
|
|
|
else
|
2002-02-10 18:49:46 +03:00
|
|
|
result = PRBool(localTrue == Substring(value, 0, selLen).Equals(attr->mValue, nsCaseInsensitiveStringComparator()));
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_ATTR_FUNC_CONTAINSMATCH:
|
2002-03-19 09:46:56 +03:00
|
|
|
result = PRBool(localTrue == (FindInReadable(attr->mValue, value, nsCaseInsensitiveStringComparator())));
|
2001-03-21 11:10:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attr = attr->mNext;
|
2001-04-10 17:43:20 +04:00
|
|
|
} while (result && (nsnull != attr));
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 17:43:20 +04:00
|
|
|
if (result &&
|
2001-03-21 11:10:20 +03:00
|
|
|
((nsnull != aSelector->mIDList) || (nsnull != aSelector->mClassList))) { // test for ID & class match
|
|
|
|
result = localFalse;
|
|
|
|
if (data.mStyledContent) {
|
2001-09-07 04:23:37 +04:00
|
|
|
PRBool isCaseSensitive = !data.mIsQuirkMode; // bug 93371
|
2001-03-21 11:10:20 +03:00
|
|
|
nsAtomList* IDList = aSelector->mIDList;
|
|
|
|
if (nsnull == IDList) {
|
2001-04-10 17:43:20 +04:00
|
|
|
result = PR_TRUE;
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
else if (nsnull != data.mContentID) {
|
2001-06-20 02:46:08 +04:00
|
|
|
result = PR_TRUE;
|
2001-11-21 06:30:44 +03:00
|
|
|
if (isCaseSensitive) {
|
|
|
|
do {
|
|
|
|
if (localTrue == (IDList->mAtom != data.mContentID)) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
|
|
|
} else {
|
|
|
|
const PRUnichar* id1Str;
|
|
|
|
data.mContentID->GetUnicode(&id1Str);
|
|
|
|
nsDependentString id1(id1Str);
|
|
|
|
do {
|
|
|
|
const PRUnichar* id2Str;
|
|
|
|
IDList->mAtom->GetUnicode(&id2Str);
|
|
|
|
nsDependentString id2(id2Str);
|
2002-02-10 18:49:46 +03:00
|
|
|
if (localTrue !=
|
|
|
|
id1.Equals(id2, nsCaseInsensitiveStringComparator())) {
|
2001-11-21 06:30:44 +03:00
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
IDList = IDList->mNext;
|
|
|
|
} while (IDList);
|
2001-03-21 11:10:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-10 17:43:20 +04:00
|
|
|
if (result) {
|
2001-03-21 11:10:20 +03:00
|
|
|
nsAtomList* classList = aSelector->mClassList;
|
|
|
|
while (nsnull != classList) {
|
2001-09-07 04:23:37 +04:00
|
|
|
if (localTrue == (NS_COMFALSE == data.mStyledContent->HasClass(classList->mAtom, isCaseSensitive))) {
|
2001-06-20 02:46:08 +04:00
|
|
|
result = PR_FALSE;
|
2001-03-21 11:10:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
classList = classList->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
// apply SelectorMatches to the negated selectors in the chain
|
2001-04-10 17:43:20 +04:00
|
|
|
if (result && (nsnull != aSelector->mNegations)) {
|
2002-04-11 07:49:30 +04:00
|
|
|
result = SelectorMatches(data, aSelector->mNegations, aStateMask,
|
|
|
|
aNegationIndex+1);
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return result;
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
static PRBool SelectorMatchesTree(RuleProcessorData &data,
|
1999-10-14 04:59:21 +04:00
|
|
|
nsCSSSelector* aSelector)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsCSSSelector* selector = aSelector;
|
|
|
|
|
|
|
|
if (selector) {
|
|
|
|
nsIContent* content = nsnull;
|
2001-01-27 08:48:41 +03:00
|
|
|
nsIContent* lastContent = data.mContent;
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ADDREF(lastContent);
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorData* curdata = &data;
|
1999-10-14 04:59:21 +04:00
|
|
|
while (nsnull != selector) { // check compound selectors
|
2001-04-28 06:16:16 +04:00
|
|
|
// Find the appropriate content (whether parent or previous sibling)
|
2001-11-11 02:51:45 +03:00
|
|
|
// to check next, and if we don't already have a RuleProcessorData
|
2001-04-28 06:16:16 +04:00
|
|
|
// for it, create one.
|
|
|
|
|
2000-04-22 04:47:18 +04:00
|
|
|
// for adjacent sibling combinators, the content to test against the
|
|
|
|
// selector is the previous sibling
|
2001-04-28 06:16:16 +04:00
|
|
|
nsCompatibility compat = curdata->mIsQuirkMode ? eCompatibility_NavQuirks : eCompatibility_Standard;
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleProcessorData* newdata;
|
2000-04-22 04:47:18 +04:00
|
|
|
if (PRUnichar('+') == selector->mOperator) {
|
2001-04-28 06:16:16 +04:00
|
|
|
newdata = curdata->mPreviousSiblingData;
|
|
|
|
if (!newdata) {
|
|
|
|
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);
|
|
|
|
newdata =
|
2001-11-11 02:51:45 +03:00
|
|
|
new (curdata->mPresContext) RuleProcessorData(curdata->mPresContext, content,
|
2001-06-01 02:19:43 +04:00
|
|
|
curdata->mRuleWalker, &compat);
|
2001-04-28 06:16:16 +04:00
|
|
|
curdata->mPreviousSiblingData = newdata;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
}
|
2001-04-28 06:16:16 +04:00
|
|
|
NS_RELEASE(parent);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2001-04-28 06:16:16 +04:00
|
|
|
} else {
|
|
|
|
content = newdata->mContent;
|
|
|
|
NS_ADDREF(content);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-22 04:47:18 +04:00
|
|
|
// for descendant combinators and child combinators, the content
|
|
|
|
// to test against is the parent
|
|
|
|
else {
|
2001-04-28 06:16:16 +04:00
|
|
|
newdata = curdata->mParentData;
|
|
|
|
if (!newdata) {
|
|
|
|
lastContent->GetParent(content);
|
|
|
|
if (content) {
|
2001-11-11 02:51:45 +03:00
|
|
|
newdata = new (curdata->mPresContext) RuleProcessorData(curdata->mPresContext, content,
|
2001-06-01 02:19:43 +04:00
|
|
|
curdata->mRuleWalker, &compat);
|
2001-04-28 06:16:16 +04:00
|
|
|
curdata->mParentData = newdata;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
content = newdata->mContent;
|
|
|
|
NS_ADDREF(content);
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2001-04-28 06:16:16 +04:00
|
|
|
if (! newdata) {
|
|
|
|
NS_ASSERTION(!content, "content must be null");
|
1999-10-14 04:59:21 +04:00
|
|
|
break;
|
|
|
|
}
|
2002-04-11 07:49:30 +04:00
|
|
|
if (SelectorMatches(*newdata, selector, 0, 0)) {
|
2000-04-22 04:47:18 +04:00
|
|
|
// to avoid greedy matching, we need to recurse if this is a
|
|
|
|
// descendant combinator and the next combinator is not
|
|
|
|
if ((NS_IS_GREEDY_OPERATOR(selector->mOperator)) &&
|
|
|
|
(selector->mNext) &&
|
|
|
|
(!NS_IS_GREEDY_OPERATOR(selector->mNext->mOperator))) {
|
|
|
|
|
|
|
|
// pretend the selector didn't match, and step through content
|
|
|
|
// while testing the same selector
|
|
|
|
|
|
|
|
// This approach is slightly strange is that when it recurses
|
|
|
|
// it tests from the top of the content tree, down. This
|
|
|
|
// doesn't matter much for performance since most selectors
|
|
|
|
// don't match. (If most did, it might be faster...)
|
2001-04-28 06:16:16 +04:00
|
|
|
if (SelectorMatchesTree(*newdata, selector)) {
|
2000-04-22 04:47:18 +04:00
|
|
|
selector = nsnull; // indicate success
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
selector = selector->mNext;
|
|
|
|
}
|
|
|
|
else {
|
2000-04-22 04:47:18 +04:00
|
|
|
// for adjacent sibling and child combinators, if we didn't find
|
|
|
|
// a match, we're done
|
|
|
|
if (!NS_IS_GREEDY_OPERATOR(selector->mOperator)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_RELEASE(content);
|
|
|
|
break; // parent was required to match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(lastContent);
|
|
|
|
lastContent = content; // take refcount
|
|
|
|
content = nsnull;
|
2001-04-28 06:16:16 +04:00
|
|
|
curdata = newdata;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(lastContent);
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return PRBool(nsnull == selector); // matches if ran out of selectors
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static void ContentEnumFunc(nsICSSStyleRule* aRule, void* aData)
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
ElementRuleProcessorData* data = (ElementRuleProcessorData*)aData;
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
2002-04-11 07:49:30 +04:00
|
|
|
if (SelectorMatches(*data, selector, 0, 0)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
selector = selector->mNext;
|
2001-01-27 08:48:41 +03:00
|
|
|
if (SelectorMatchesTree(*data, selector)) {
|
2001-11-21 06:30:44 +03:00
|
|
|
// for performance, require that every implementation of
|
|
|
|
// nsICSSStyleRule return the same pointer for nsIStyleRule (why
|
|
|
|
// would anything multiply inherit nsIStyleRule anyway?)
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(aRule);
|
|
|
|
NS_ASSERTION(NS_STATIC_CAST(nsIStyleRule*, aRule) == iRule.get(),
|
|
|
|
"Please fix QI so this performance optimization is valid");
|
|
|
|
#endif
|
|
|
|
data->mRuleWalker->Forward(NS_STATIC_CAST(nsIStyleRule*, aRule));
|
|
|
|
// nsStyleSet will deal with the !important rule
|
1999-06-10 09:29:22 +04:00
|
|
|
}
|
|
|
|
}
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-11 02:51:45 +03:00
|
|
|
CSSRuleProcessor::RulesMatching(ElementRuleProcessorData *aData,
|
|
|
|
nsIAtom* aMedium)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData->mContent->IsContentOfType(nsIContent::eELEMENT),
|
2001-10-30 09:02:05 +03:00
|
|
|
"content must be element");
|
1999-06-15 10:20:46 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext, aMedium);
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
if (cascade) {
|
1999-12-01 06:27:25 +03:00
|
|
|
nsAutoVoidArray classArray;
|
1999-06-15 10:20:46 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
nsIStyledContent* styledContent = aData->mStyledContent;
|
|
|
|
if (styledContent)
|
1999-10-14 04:59:21 +04:00
|
|
|
styledContent->GetClasses(classArray);
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
cascade->mRuleHash.EnumerateAllRules(aData->mNameSpaceID, aData->mContentTag, aData->mContentID, classArray, ContentEnumFunc, aData);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static void PseudoEnumFunc(nsICSSStyleRule* aRule, void* aData)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
PseudoRuleProcessorData* data = (PseudoRuleProcessorData*)aData;
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsCSSSelector* selector = aRule->FirstSelector();
|
2001-02-16 00:25:31 +03:00
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
NS_ASSERTION(selector->mTag == data->mPseudoTag, "RuleHash failure");
|
|
|
|
PRBool matches = PR_TRUE;
|
2001-02-16 00:25:31 +03:00
|
|
|
if (data->mComparator)
|
|
|
|
data->mComparator->PseudoMatches(data->mPseudoTag, selector, &matches);
|
|
|
|
|
|
|
|
if (matches) {
|
1999-10-14 04:59:21 +04:00
|
|
|
selector = selector->mNext;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (selector) { // test next selector specially
|
|
|
|
if (PRUnichar('+') == selector->mOperator) {
|
|
|
|
return; // not valid here, can't match
|
|
|
|
}
|
2002-04-11 07:49:30 +04:00
|
|
|
if (SelectorMatches(*data, selector, 0, 0)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
selector = selector->mNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (PRUnichar('>') == selector->mOperator) {
|
|
|
|
return; // immediate parent didn't match
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
if (selector &&
|
2001-01-27 08:48:41 +03:00
|
|
|
(! SelectorMatchesTree(*data, selector))) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return; // remaining selectors didn't match
|
|
|
|
}
|
|
|
|
|
2001-11-21 06:30:44 +03:00
|
|
|
// for performance, require that every implementation of
|
|
|
|
// nsICSSStyleRule return the same pointer for nsIStyleRule (why
|
|
|
|
// would anything multiply inherit nsIStyleRule anyway?)
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIStyleRule> iRule = do_QueryInterface(aRule);
|
|
|
|
NS_ASSERTION(NS_STATIC_CAST(nsIStyleRule*, aRule) == iRule.get(),
|
|
|
|
"Please fix QI so this performance optimization is valid");
|
|
|
|
#endif
|
|
|
|
data->mRuleWalker->Forward(NS_STATIC_CAST(nsIStyleRule*, aRule));
|
|
|
|
// nsStyleSet will deal with the !important rule
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-11 02:51:45 +03:00
|
|
|
CSSRuleProcessor::RulesMatching(PseudoRuleProcessorData* aData,
|
|
|
|
nsIAtom* aMedium)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aData->mContent ||
|
|
|
|
aData->mContent->IsContentOfType(nsIContent::eELEMENT),
|
2001-10-30 09:02:05 +03:00
|
|
|
"content (if present) must be element");
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext, aMedium);
|
1998-11-17 05:14:38 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (cascade) {
|
2001-11-11 02:51:45 +03:00
|
|
|
cascade->mRuleHash.EnumerateTagRules(aData->mPseudoTag,
|
|
|
|
PseudoEnumFunc, aData);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static
|
2000-05-03 03:07:11 +04:00
|
|
|
PRBool PR_CALLBACK StateEnumFunc(void* aSelector, void* aData)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
StateRuleProcessorData* data = (StateRuleProcessorData*)aData;
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsCSSSelector* selector = (nsCSSSelector*)aSelector;
|
2002-04-11 07:49:30 +04:00
|
|
|
if (SelectorMatches(*data, selector, data->mStateMask, 0)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
selector = selector->mNext;
|
2001-01-27 08:48:41 +03:00
|
|
|
if (SelectorMatchesTree(*data, selector)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_FALSE;
|
1999-06-28 01:16:16 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-11 02:51:45 +03:00
|
|
|
CSSRuleProcessor::HasStateDependentStyle(StateRuleProcessorData* aData,
|
2002-04-11 07:49:30 +04:00
|
|
|
nsIAtom* aMedium,
|
|
|
|
PRBool* aResult)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
NS_PRECONDITION(aData->mContent->IsContentOfType(nsIContent::eELEMENT),
|
2001-10-30 09:02:05 +03:00
|
|
|
"content must be element");
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext, aMedium);
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
// Look up the content node in the state rule list, which points to
|
|
|
|
// any (CSS2 definition) simple selector (whether or not it is the
|
|
|
|
// subject) that has a state pseudo-class on it. This means that this
|
|
|
|
// code will be matching selectors that aren't real selectors in any
|
|
|
|
// stylesheet (e.g., if there is a selector "body > p:hover > a", then
|
|
|
|
// "body > p:hover" will be in |cascade->mStateSelectors|). Note that
|
|
|
|
// |IsStateSelector| below determines which selectors are in
|
|
|
|
// |cascade->mStateSelectors|.
|
|
|
|
// The enumeration function signals the presence of state by stopping
|
|
|
|
// the enumeration, which is reflected in the return value from
|
|
|
|
// |EnumerateForwards|.
|
2002-04-11 07:49:30 +04:00
|
|
|
*aResult = cascade &&
|
|
|
|
!cascade->mStateSelectors.EnumerateForwards(StateEnumFunc, aData);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2002-04-11 07:49:30 +04:00
|
|
|
return NS_OK;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2001-07-17 00:59:28 +04:00
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
struct CascadeSizeEnumData {
|
|
|
|
|
|
|
|
CascadeSizeEnumData(nsISizeOfHandler *aSizeOfHandler,
|
|
|
|
nsUniqueStyleItems *aUniqueStyleItem,
|
|
|
|
nsIAtom *aTag)
|
|
|
|
{
|
|
|
|
handler = aSizeOfHandler;
|
|
|
|
uniqueItems = aUniqueStyleItem;
|
|
|
|
tag = aTag;
|
|
|
|
}
|
|
|
|
// weak references all 'round
|
|
|
|
|
|
|
|
nsISizeOfHandler *handler;
|
|
|
|
nsUniqueStyleItems *uniqueItems;
|
|
|
|
nsIAtom *tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
2000-05-03 03:07:11 +04:00
|
|
|
PRBool PR_CALLBACK StateSelectorsSizeEnumFunc( void *aSelector, void *aData )
|
2000-03-31 11:08:36 +04:00
|
|
|
{
|
|
|
|
nsCSSSelector* selector = (nsCSSSelector*)aSelector;
|
|
|
|
CascadeSizeEnumData *pData = (CascadeSizeEnumData *)aData;
|
|
|
|
NS_ASSERTION(selector && pData, "null arguments not supported");
|
|
|
|
|
|
|
|
if(! pData->uniqueItems->AddItem((void*)selector)){
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass the call to the selector
|
|
|
|
PRUint32 localSize = 0;
|
|
|
|
selector->SizeOf(pData->handler, localSize);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2000-05-31 18:09:34 +04:00
|
|
|
PRBool WeightedRulesSizeEnumFunc( nsISupports *aRule, void *aData )
|
2000-03-31 11:08:36 +04:00
|
|
|
{
|
|
|
|
nsICSSStyleRule* rule = (nsICSSStyleRule*)aRule;
|
|
|
|
CascadeSizeEnumData *pData = (CascadeSizeEnumData *)aData;
|
|
|
|
NS_ASSERTION(rule && pData, "null arguments not supported");
|
|
|
|
|
|
|
|
if(! pData->uniqueItems->AddItem((void*)rule)){
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 localSize=0;
|
|
|
|
|
|
|
|
// pass the call to the rule
|
|
|
|
rule->SizeOf(pData->handler, localSize);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2001-07-17 00:59:28 +04:00
|
|
|
void CascadeSizeEnumFunc(RuleCascadeData *cascade, CascadeSizeEnumData *pData)
|
2000-03-31 11:08:36 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(cascade && pData, "null arguments not supported");
|
|
|
|
|
|
|
|
// see if the cascade has already been counted
|
|
|
|
if(!(pData->uniqueItems->AddItem(cascade))){
|
2001-07-17 00:59:28 +04:00
|
|
|
return;
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
|
|
|
// record the size of the cascade data itself
|
|
|
|
PRUint32 localSize = sizeof(RuleCascadeData);
|
|
|
|
pData->handler->AddSize(pData->tag, localSize);
|
|
|
|
|
|
|
|
// next add up the selectors and the weighted rules for the cascade
|
|
|
|
nsCOMPtr<nsIAtom> stateSelectorSizeTag;
|
|
|
|
stateSelectorSizeTag = getter_AddRefs(NS_NewAtom("CascadeStateSelectors"));
|
|
|
|
CascadeSizeEnumData stateData(pData->handler,pData->uniqueItems,stateSelectorSizeTag);
|
|
|
|
cascade->mStateSelectors.EnumerateForwards(StateSelectorsSizeEnumFunc, &stateData);
|
|
|
|
|
|
|
|
if(cascade->mWeightedRules){
|
|
|
|
nsCOMPtr<nsIAtom> weightedRulesSizeTag;
|
|
|
|
weightedRulesSizeTag = getter_AddRefs(NS_NewAtom("CascadeWeightedRules"));
|
2000-04-23 23:06:37 +04:00
|
|
|
CascadeSizeEnumData stateData2(pData->handler,pData->uniqueItems,weightedRulesSizeTag);
|
|
|
|
cascade->mWeightedRules->EnumerateForwards(WeightedRulesSizeEnumFunc, &stateData2);
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as CSSRuleProcessor's size):
|
2001-07-17 00:59:28 +04:00
|
|
|
* 1) sizeof(*this)
|
2000-03-31 11:08:36 +04:00
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as CSSRuleProcessor's size):
|
|
|
|
* 1) Delegate to the StyleSheets in the mSheets collection
|
|
|
|
* 2) Delegate to the Rules in the CascadeTable
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void CSSRuleProcessor::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSizeOfHandler != nsnull, "SizeOf handler cannot be null");
|
|
|
|
|
|
|
|
// first get the unique items collection
|
|
|
|
UNIQUE_STYLE_ITEMS(uniqueItems);
|
|
|
|
if(! uniqueItems->AddItem((void*)this)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("CSSRuleProcessor"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(CSSRuleProcessor);
|
|
|
|
|
|
|
|
// collect sizes for the data
|
|
|
|
// - mSheets
|
2001-07-17 00:59:28 +04:00
|
|
|
// - mRuleCascades
|
2000-03-31 11:08:36 +04:00
|
|
|
|
|
|
|
// sheets first
|
|
|
|
if(mSheets && uniqueItems->AddItem(mSheets)){
|
2000-04-23 23:06:37 +04:00
|
|
|
PRUint32 sheetCount, curSheet, localSize2;
|
2000-03-31 11:08:36 +04:00
|
|
|
mSheets->Count(&sheetCount);
|
|
|
|
for(curSheet=0; curSheet < sheetCount; curSheet++){
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSStyleSheet> pSheet =
|
|
|
|
dont_AddRef((nsICSSStyleSheet*)mSheets->ElementAt(curSheet));
|
2000-03-31 11:08:36 +04:00
|
|
|
if(pSheet && uniqueItems->AddItem((void*)pSheet)){
|
2000-04-23 23:06:37 +04:00
|
|
|
pSheet->SizeOf(aSizeOfHandler, localSize2);
|
|
|
|
// XXX aSize += localSize2;
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// and for the medium cascade table we account for the hash table overhead,
|
|
|
|
// and then compute the sizeof each rule-cascade in the table
|
2001-07-17 00:59:28 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> tag2 = getter_AddRefs(NS_NewAtom("RuleCascade"));
|
|
|
|
CascadeSizeEnumData data(aSizeOfHandler, uniqueItems, tag2);
|
|
|
|
for (RuleCascadeData *cascadeData = mRuleCascades;
|
2001-09-07 04:23:37 +04:00
|
|
|
cascadeData;
|
|
|
|
cascadeData = cascadeData->mNext) {
|
2001-07-17 00:59:28 +04:00
|
|
|
CascadeSizeEnumFunc(cascadeData, &data);
|
2000-03-31 11:08:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now add the size of the RuleProcessor
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSRuleProcessor::ClearRuleCascades(void)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2001-07-17 00:59:28 +04:00
|
|
|
RuleCascadeData *data = mRuleCascades;
|
2001-08-14 06:54:35 +04:00
|
|
|
mRuleCascades = nsnull;
|
2001-07-17 00:59:28 +04:00
|
|
|
while (data) {
|
|
|
|
RuleCascadeData *next = data->mNext;
|
|
|
|
delete data;
|
|
|
|
data = next;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
// This function should return true only for selectors that need to be
|
|
|
|
// checked by |HasStateDependentStyle|.
|
2001-10-30 09:02:05 +03:00
|
|
|
inline
|
1999-10-14 04:59:21 +04:00
|
|
|
PRBool IsStateSelector(nsCSSSelector& aSelector)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsAtomList* pseudoClass = aSelector.mPseudoClassList;
|
|
|
|
while (pseudoClass) {
|
|
|
|
if ((pseudoClass->mAtom == nsCSSAtoms::activePseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::checkedPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::dragOverPseudo) ||
|
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::focusPseudo) ||
|
2002-04-16 02:49:26 +04:00
|
|
|
(pseudoClass->mAtom == nsCSSAtoms::hoverPseudo)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_TRUE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
pseudoClass = pseudoClass->mNext;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_FALSE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
static PRBool
|
|
|
|
BuildRuleHashAndStateSelectors(nsISupports* aRule, void* aCascade)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2002-04-16 02:49:26 +04:00
|
|
|
nsICSSStyleRule* rule = NS_STATIC_CAST(nsICSSStyleRule*, aRule);
|
|
|
|
RuleCascadeData *cascade = NS_STATIC_CAST(RuleCascadeData*, aCascade);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
cascade->mRuleHash.AppendRule(rule);
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
nsVoidArray* array = &cascade->mStateSelectors;
|
|
|
|
for (nsCSSSelector* selector = rule->FirstSelector();
|
|
|
|
selector; selector = selector->mNext)
|
|
|
|
if (IsStateSelector(*selector))
|
1999-10-14 04:59:21 +04:00
|
|
|
array->AppendElement(selector);
|
2002-04-16 02:49:26 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
return PR_TRUE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
struct CascadeEnumData {
|
2001-04-28 06:16:16 +04:00
|
|
|
CascadeEnumData(nsIAtom* aMedium)
|
1999-10-14 04:59:21 +04:00
|
|
|
: mMedium(aMedium),
|
2001-04-28 06:16:16 +04:00
|
|
|
mRuleArrays(64)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2001-04-28 06:16:16 +04:00
|
|
|
nsIAtom* mMedium;
|
|
|
|
nsSupportsHashtable mRuleArrays; // of nsISupportsArray
|
1999-10-14 04:59:21 +04:00
|
|
|
};
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
static PRBool
|
|
|
|
InsertRuleByWeight(nsISupports* aRule, void* aData)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsICSSRule* rule = (nsICSSRule*)aRule;
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
1999-10-14 04:59:21 +04:00
|
|
|
rule->GetType(type);
|
|
|
|
|
|
|
|
if (nsICSSRule::STYLE_RULE == type) {
|
|
|
|
nsICSSStyleRule* styleRule = (nsICSSStyleRule*)rule;
|
|
|
|
|
2001-04-28 06:16:16 +04:00
|
|
|
PRInt32 weight = styleRule->GetWeight();
|
2001-06-05 05:00:11 +04:00
|
|
|
nsInt32Key key(weight);
|
2001-04-28 06:16:16 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> rules(dont_AddRef(
|
|
|
|
NS_STATIC_CAST(nsISupportsArray*, data->mRuleArrays.Get(&key))));
|
|
|
|
if (!rules) {
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(rules));
|
|
|
|
if (!rules) return PR_FALSE; // out of memory
|
|
|
|
data->mRuleArrays.Put(&key, rules);
|
|
|
|
}
|
|
|
|
rules->AppendElement(styleRule);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
else if (nsICSSRule::MEDIA_RULE == type) {
|
|
|
|
nsICSSMediaRule* mediaRule = (nsICSSMediaRule*)rule;
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mediaRule->UseForMedium(data->mMedium)) {
|
1999-10-14 04:59:21 +04:00
|
|
|
mediaRule->EnumerateRulesForwards(InsertRuleByWeight, aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
PRBool
|
|
|
|
CSSRuleProcessor::CascadeSheetRulesInto(nsISupports* aSheet, void* aData)
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
nsICSSStyleSheet* iSheet = (nsICSSStyleSheet*)aSheet;
|
|
|
|
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*)iSheet;
|
|
|
|
CascadeEnumData* data = (CascadeEnumData*)aData;
|
2000-06-03 01:45:06 +04:00
|
|
|
PRBool bSheetEnabled = PR_TRUE;
|
|
|
|
sheet->GetEnabled(bSheetEnabled);
|
1998-12-03 23:20:35 +03:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
if ((bSheetEnabled) && (sheet->UseForMedium(data->mMedium))) {
|
1999-10-14 04:59:21 +04:00
|
|
|
CSSStyleSheetImpl* child = sheet->mFirstChild;
|
|
|
|
while (child) {
|
|
|
|
CascadeSheetRulesInto((nsICSSStyleSheet*)child, data);
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
1998-12-03 23:20:35 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (sheet->mInner && sheet->mInner->mOrderedRules) {
|
|
|
|
sheet->mInner->mOrderedRules->EnumerateForwards(InsertRuleByWeight, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-12-03 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
2001-04-28 06:16:16 +04:00
|
|
|
struct RuleArrayData {
|
|
|
|
PRInt32 mWeight;
|
|
|
|
nsISupportsArray* mRuleArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(int) CompareArrayData(const void* aArg1, const void* aArg2,
|
|
|
|
void* closure)
|
|
|
|
{
|
|
|
|
const RuleArrayData* arg1 = NS_STATIC_CAST(const RuleArrayData*, aArg1);
|
|
|
|
const RuleArrayData* arg2 = NS_STATIC_CAST(const RuleArrayData*, aArg2);
|
2002-04-16 02:49:26 +04:00
|
|
|
return arg1->mWeight - arg2->mWeight; // put lower weight first
|
2001-04-28 06:16:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct FillArrayData {
|
|
|
|
FillArrayData(RuleArrayData* aArrayData) :
|
|
|
|
mIndex(0),
|
|
|
|
mArrayData(aArrayData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PRInt32 mIndex;
|
|
|
|
RuleArrayData* mArrayData;
|
|
|
|
};
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PRBool) FillArray(nsHashKey* aKey, void* aData,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
2001-06-05 05:00:11 +04:00
|
|
|
nsInt32Key* key = NS_STATIC_CAST(nsInt32Key*, aKey);
|
2001-04-28 06:16:16 +04:00
|
|
|
nsISupportsArray* weightArray = NS_STATIC_CAST(nsISupportsArray*, aData);
|
|
|
|
FillArrayData* data = NS_STATIC_CAST(FillArrayData*, aClosure);
|
|
|
|
|
|
|
|
RuleArrayData& ruleData = data->mArrayData[data->mIndex++];
|
|
|
|
ruleData.mRuleArray = weightArray;
|
2001-06-05 05:00:11 +04:00
|
|
|
ruleData.mWeight = key->mInt;
|
2001-04-28 06:16:16 +04:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the hashtable of arrays (keyed by weight, in order sort) and
|
|
|
|
* puts them all in one big array which has a primary sort by weight
|
2002-04-16 02:49:26 +04:00
|
|
|
* and secondary sort by order.
|
2001-04-28 06:16:16 +04:00
|
|
|
*/
|
|
|
|
static void PutRulesInList(nsSupportsHashtable* aRuleArrays,
|
|
|
|
nsISupportsArray* aWeightedRules)
|
|
|
|
{
|
|
|
|
PRInt32 arrayCount = aRuleArrays->Count();
|
|
|
|
RuleArrayData* arrayData = new RuleArrayData[arrayCount];
|
|
|
|
FillArrayData faData(arrayData);
|
|
|
|
aRuleArrays->Enumerate(FillArray, &faData);
|
|
|
|
NS_QuickSort(arrayData, arrayCount, sizeof(RuleArrayData),
|
|
|
|
CompareArrayData, nsnull);
|
2002-04-16 02:49:26 +04:00
|
|
|
for (PRInt32 i = 0; i < arrayCount; ++i)
|
|
|
|
aWeightedRules->AppendElements(arrayData[i].mRuleArray);
|
2001-04-28 06:16:16 +04:00
|
|
|
|
|
|
|
delete [] arrayData;
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
RuleCascadeData*
|
2001-09-07 04:23:37 +04:00
|
|
|
CSSRuleProcessor::GetRuleCascade(nsIPresContext* aPresContext, nsIAtom* aMedium)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-07-17 00:59:28 +04:00
|
|
|
RuleCascadeData **cascadep = &mRuleCascades;
|
|
|
|
RuleCascadeData *cascade;
|
|
|
|
while ((cascade = *cascadep)) {
|
|
|
|
if (cascade->mMedium == aMedium)
|
|
|
|
return cascade;
|
2001-08-14 06:54:35 +04:00
|
|
|
cascadep = &cascade->mNext;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-07-17 00:59:28 +04:00
|
|
|
if (mSheets) {
|
|
|
|
cascade = new RuleCascadeData(aMedium);
|
|
|
|
if (cascade) {
|
|
|
|
*cascadep = cascade;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-07-17 00:59:28 +04:00
|
|
|
CascadeEnumData data(aMedium);
|
|
|
|
mSheets->EnumerateForwards(CascadeSheetRulesInto, &data);
|
|
|
|
PutRulesInList(&data.mRuleArrays, cascade->mWeightedRules);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
nsCompatibility quirkMode = eCompatibility_Standard;
|
|
|
|
aPresContext->GetCompatibilityMode(&quirkMode);
|
|
|
|
|
2002-04-16 02:49:26 +04:00
|
|
|
cascade->mRuleHash.SetCaseSensitive(eCompatibility_Standard == quirkMode);
|
|
|
|
cascade->mWeightedRules->EnumerateForwards(
|
|
|
|
BuildRuleHashAndStateSelectors, cascade);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cascade;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|