1998-05-14 03:42:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03: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-05-14 03:42:18 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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-05-14 03:42:18 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-05-14 03:42:18 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1998-05-14 03:42:18 +04:00
|
|
|
*/
|
1999-02-27 04:35:25 +03:00
|
|
|
|
1998-05-14 03:42:18 +04:00
|
|
|
#include "nsIHTMLCSSStyleSheet.h"
|
|
|
|
#include "nsIArena.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsIStyleRule.h"
|
1998-05-19 01:11:08 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 08:00:06 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-09-12 06:46:59 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-10-08 07:09:31 +04:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
1998-09-17 04:19:47 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsIStyleSet.h"
|
2001-06-01 02:19:43 +04:00
|
|
|
#include "nsIRuleWalker.h"
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
1998-05-14 03:42:18 +04:00
|
|
|
|
|
|
|
|
1999-04-20 04:28:40 +04:00
|
|
|
class CSSFirstLineRule : public nsIStyleRule {
|
|
|
|
public:
|
|
|
|
CSSFirstLineRule(nsIHTMLCSSStyleSheet* aSheet);
|
|
|
|
virtual ~CSSFirstLineRule();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
|
|
|
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
|
|
|
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
|
|
|
|
NS_IMETHOD GetStrength(PRInt32& aStrength) const;
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// The new mapping function.
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
|
|
|
|
1999-04-20 04:28:40 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize);
|
|
|
|
|
1999-04-20 04:28:40 +04:00
|
|
|
nsIHTMLCSSStyleSheet* mSheet;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSFirstLineRule::CSSFirstLineRule(nsIHTMLCSSStyleSheet* aSheet)
|
|
|
|
: mSheet(aSheet)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSFirstLineRule::~CSSFirstLineRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(CSSFirstLineRule, nsIStyleRule)
|
1999-04-20 04:28:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
|
|
|
|
{
|
|
|
|
aResult = PRBool(this == aRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::HashValue(PRUint32& aValue) const
|
|
|
|
{
|
|
|
|
aValue = (PRUint32)7; // XXX got a better suggestion?
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mSheet);
|
|
|
|
aSheet = mSheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strength is an out-of-band weighting, always 0 here
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::GetStrength(PRInt32& aStrength) const
|
|
|
|
{
|
|
|
|
aStrength = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-06-01 02:19:43 +04:00
|
|
|
CSSFirstLineRule::MapRuleInfoInto(nsRuleData* aData)
|
1999-04-20 04:28:40 +04:00
|
|
|
{
|
2001-06-01 02:19:43 +04:00
|
|
|
if (!aData)
|
|
|
|
return NS_OK;
|
1999-04-20 04:28:40 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
if (aData->mSID == eStyleStruct_Border && aData->mMarginData) {
|
|
|
|
// Disable the border.
|
|
|
|
nsCSSValue styleVal(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
|
|
|
if (aData->mMarginData->mBorderStyle->mLeft.GetUnit() == eCSSUnit_Null)
|
|
|
|
aData->mMarginData->mBorderStyle->mLeft = styleVal;
|
|
|
|
if (aData->mMarginData->mBorderStyle->mRight.GetUnit() == eCSSUnit_Null)
|
|
|
|
aData->mMarginData->mBorderStyle->mRight = styleVal;
|
|
|
|
if (aData->mMarginData->mBorderStyle->mTop.GetUnit() == eCSSUnit_Null)
|
|
|
|
aData->mMarginData->mBorderStyle->mTop = styleVal;
|
|
|
|
if (aData->mMarginData->mBorderStyle->mBottom.GetUnit() == eCSSUnit_Null)
|
|
|
|
aData->mMarginData->mBorderStyle->mBottom = styleVal;
|
1999-04-20 04:28:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as CSSFirstLineRule's size):
|
|
|
|
* 1) sizeof(*this)
|
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as CSSFirstLineRule's size):
|
|
|
|
* 1) Delegate to mSheet if it exists
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void CSSFirstLineRule::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) ){
|
|
|
|
// object has already been accounted for
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get or create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("CSSFirstLine-LetterRule"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(*this);
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
|
|
|
|
if(mSheet){
|
|
|
|
PRUint32 localSize=0;
|
|
|
|
mSheet->SizeOf(aSizeOfHandler, localSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:28:40 +04:00
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
class CSSFirstLetterRule : public CSSFirstLineRule {
|
|
|
|
public:
|
|
|
|
CSSFirstLetterRule(nsIHTMLCSSStyleSheet* aSheet);
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSFirstLetterRule::CSSFirstLetterRule(nsIHTMLCSSStyleSheet* aSheet)
|
|
|
|
: CSSFirstLineRule(aSheet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet,
|
|
|
|
public nsIStyleRuleProcessor {
|
1998-05-14 03:42:18 +04:00
|
|
|
public:
|
|
|
|
void* operator new(size_t size);
|
|
|
|
void* operator new(size_t size, nsIArena* aArena);
|
1999-02-26 22:26:29 +03:00
|
|
|
void operator delete(void* ptr);
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl();
|
1998-05-14 03:42:18 +04:00
|
|
|
|
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// basic style sheet data
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
|
|
|
|
NS_IMETHOD Reset(nsIURI* aURL);
|
|
|
|
NS_IMETHOD GetURL(nsIURI*& aURL) const;
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
|
1998-12-02 03:38:33 +03:00
|
|
|
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const;
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHOD_(PRBool) UseForMedium(nsIAtom* aMedium) const;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
|
|
|
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
|
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled);
|
|
|
|
|
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
|
|
|
|
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
|
|
|
|
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHOD GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor,
|
|
|
|
nsIStyleRuleProcessor* aPrevProcessor);
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
// nsIStyleRuleProcessor api
|
|
|
|
NS_IMETHOD RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aParentContext,
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIRuleWalker* aRuleWalker);
|
1998-05-19 01:11:08 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHOD RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
2001-02-16 00:25:31 +03:00
|
|
|
nsICSSPseudoComparator* aComparator,
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIRuleWalker* aRuleWalker);
|
1999-10-08 07:09:31 +04:00
|
|
|
|
|
|
|
NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent);
|
1999-04-20 04:05:54 +04:00
|
|
|
|
1998-05-14 03:42:18 +04:00
|
|
|
// XXX style rule enumerations
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
1998-05-14 03:42:18 +04:00
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
HTMLCSSStyleSheetImpl(const HTMLCSSStyleSheetImpl& aCopy);
|
|
|
|
HTMLCSSStyleSheetImpl& operator=(const HTMLCSSStyleSheetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~HTMLCSSStyleSheetImpl();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRUint32 mInHeap : 1;
|
|
|
|
PRUint32 mRefCnt : 31;
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_DECL_OWNINGTHREAD // for thread-safety checking
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* mURL;
|
1998-11-26 04:34:53 +03:00
|
|
|
nsIDocument* mDocument;
|
1999-04-20 04:28:40 +04:00
|
|
|
|
|
|
|
CSSFirstLineRule* mFirstLineRule;
|
1999-04-28 05:16:45 +04:00
|
|
|
CSSFirstLetterRule* mFirstLetterRule;
|
1998-05-14 03:42:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void* HTMLCSSStyleSheetImpl::operator new(size_t size)
|
|
|
|
{
|
|
|
|
HTMLCSSStyleSheetImpl* rv = (HTMLCSSStyleSheetImpl*) ::operator new(size);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 1;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* HTMLCSSStyleSheetImpl::operator new(size_t size, nsIArena* aArena)
|
|
|
|
{
|
|
|
|
HTMLCSSStyleSheetImpl* rv = (HTMLCSSStyleSheetImpl*) aArena->Alloc(PRInt32(size));
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 0;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
1999-02-26 22:26:29 +03:00
|
|
|
void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
HTMLCSSStyleSheetImpl* sheet = (HTMLCSSStyleSheetImpl*) ptr;
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (sheet->mInHeap) {
|
1999-02-26 20:13:10 +03:00
|
|
|
::operator delete(ptr);
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
|
1998-05-14 03:42:18 +04:00
|
|
|
: nsIHTMLCSSStyleSheet(),
|
1998-12-03 23:20:35 +03:00
|
|
|
mURL(nsnull),
|
1999-04-20 04:28:40 +04:00
|
|
|
mDocument(nsnull),
|
1999-04-28 05:16:45 +04:00
|
|
|
mFirstLineRule(nsnull),
|
|
|
|
mFirstLetterRule(nsnull)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mURL);
|
1999-04-20 04:28:40 +04:00
|
|
|
if (nsnull != mFirstLineRule) {
|
|
|
|
mFirstLineRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLineRule);
|
|
|
|
}
|
1999-04-28 05:16:45 +04:00
|
|
|
if (nsnull != mFirstLetterRule) {
|
|
|
|
mFirstLetterRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLetterRule);
|
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl)
|
|
|
|
NS_IMPL_RELEASE(HTMLCSSStyleSheetImpl)
|
|
|
|
|
|
|
|
nsresult HTMLCSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
2001-01-04 23:44:42 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIHTMLCSSStyleSheet))) {
|
1998-05-14 03:42:18 +04:00
|
|
|
*aInstancePtrResult = (void*) ((nsIHTMLCSSStyleSheet*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-14 03:42:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-04 23:44:42 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIStyleSheet))) {
|
1998-05-14 03:42:18 +04:00
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-14 03:42:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-03 01:24:56 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIStyleRuleProcessor))) {
|
1999-10-08 07:09:31 +04:00
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleRuleProcessor*)this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1999-10-08 07:09:31 +04:00
|
|
|
*aInstancePtrResult = (void*) ((nsISupports*)(nsIStyleSheet*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-14 03:42:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor,
|
|
|
|
nsIStyleRuleProcessor* /*aPrevProcessor*/)
|
|
|
|
{
|
|
|
|
aProcessor = this;
|
|
|
|
NS_ADDREF(aProcessor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aParentContext,
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIRuleWalker* aRuleWalker)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aContent, "null arg");
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_PRECONDITION(nsnull != aRuleWalker, "null arg");
|
1999-02-27 04:35:25 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
nsCOMPtr<nsIStyledContent> styledContent(do_QueryInterface(aContent));
|
|
|
|
|
|
|
|
if (styledContent)
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
|
|
|
styledContent->WalkInlineStyleRules(aRuleWalker);
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aMedium,
|
|
|
|
nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
2001-02-16 00:25:31 +03:00
|
|
|
nsICSSPseudoComparator* aComparator,
|
2001-06-01 02:19:43 +04:00
|
|
|
nsIRuleWalker* aRuleWalker)
|
1998-05-19 01:11:08 +04:00
|
|
|
{
|
1999-04-20 04:28:40 +04:00
|
|
|
if (aPseudoTag == nsHTMLAtoms::firstLinePseudo) {
|
2001-06-01 02:19:43 +04:00
|
|
|
PRBool atRoot = PR_FALSE;
|
|
|
|
aRuleWalker->AtRoot(&atRoot);
|
|
|
|
if (!atRoot) {
|
1999-04-20 04:28:40 +04:00
|
|
|
if (nsnull == mFirstLineRule) {
|
|
|
|
mFirstLineRule = new CSSFirstLineRule(this);
|
|
|
|
if (mFirstLineRule) {
|
|
|
|
NS_ADDREF(mFirstLineRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFirstLineRule) {
|
2001-06-01 02:19:43 +04:00
|
|
|
aRuleWalker->Forward(mFirstLineRule);
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1999-04-20 04:28:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-28 05:16:45 +04:00
|
|
|
if (aPseudoTag == nsHTMLAtoms::firstLetterPseudo) {
|
2001-06-01 02:19:43 +04:00
|
|
|
PRBool atRoot = PR_FALSE;
|
|
|
|
aRuleWalker->AtRoot(&atRoot);
|
|
|
|
if (!atRoot) {
|
1999-04-28 05:16:45 +04:00
|
|
|
if (nsnull == mFirstLetterRule) {
|
|
|
|
mFirstLetterRule = new CSSFirstLetterRule(this);
|
|
|
|
if (mFirstLetterRule) {
|
|
|
|
NS_ADDREF(mFirstLetterRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFirstLetterRule) {
|
2001-06-01 02:19:43 +04:00
|
|
|
aRuleWalker->Forward(mFirstLetterRule);
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1999-04-28 05:16:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-20 04:28:40 +04:00
|
|
|
// else no pseudo frame style...
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-19 01:11:08 +04:00
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
HTMLCSSStyleSheetImpl::Init(nsIURI* aURL, nsIDocument* aDocument)
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL && aDocument, "null ptr");
|
|
|
|
if (! aURL || ! aDocument)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mURL || mDocument)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
|
|
|
mDocument = aDocument; // not refcounted!
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
|
1999-10-08 07:09:31 +04:00
|
|
|
nsIAtom* aMedium,
|
1999-04-20 04:05:54 +04:00
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
return NS_COMFALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-03 22:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
HTMLCSSStyleSheetImpl::Reset(nsIURI* aURL)
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
1999-04-20 04:28:40 +04:00
|
|
|
if (nsnull != mFirstLineRule) {
|
|
|
|
mFirstLineRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLineRule);
|
|
|
|
}
|
1999-04-28 05:16:45 +04:00
|
|
|
if (nsnull != mFirstLetterRule) {
|
|
|
|
mFirstLetterRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLetterRule);
|
|
|
|
}
|
1999-02-03 22:38:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
HTMLCSSStyleSheetImpl::GetURL(nsIURI*& aURL) const
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
aURL = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
2000-04-16 00:15:37 +04:00
|
|
|
aTitle.AssignWithConversion("Internal HTML/CSS Style Sheet");
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
|
|
|
|
{
|
2000-04-16 00:15:37 +04:00
|
|
|
aType.AssignWithConversion("text/html");
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-02 03:38:33 +03:00
|
|
|
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1998-12-02 03:38:33 +03:00
|
|
|
aMedium = nsnull;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
1999-06-15 10:21:47 +04:00
|
|
|
HTMLCSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
|
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
return PR_TRUE; // works for all media
|
1999-06-15 10:21:47 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
|
|
|
|
{
|
|
|
|
aEnabled = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
|
|
|
|
{ // these can't be disabled
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
aDocument = mDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
1999-06-28 01:17:39 +04:00
|
|
|
char* urlSpec = nsnull;
|
|
|
|
mURL->GetSpec(&urlSpec);
|
|
|
|
if (urlSpec) {
|
|
|
|
fputs(urlSpec, out);
|
|
|
|
nsCRT::free(urlSpec);
|
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* SizeOf method:
|
|
|
|
*
|
|
|
|
* Self (reported as HTMLCSSStyleSheetImpl's size):
|
|
|
|
* 1) sizeof(*this)
|
|
|
|
*
|
|
|
|
* Contained / Aggregated data (not reported as HTMLCSSStyleSheetImpl's size):
|
|
|
|
* 1) We don't really delegate but count seperately the FirstLineRule and
|
|
|
|
* the FirstLetterRule if the exist and are unique instances
|
|
|
|
*
|
|
|
|
* Children / siblings / parents:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
void HTMLCSSStyleSheetImpl::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;
|
|
|
|
|
|
|
|
// create a tag for this instance
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("HTMLCSSStyleSheet"));
|
|
|
|
// get the size of an empty instance and add to the sizeof handler
|
|
|
|
aSize = sizeof(HTMLCSSStyleSheetImpl);
|
|
|
|
aSizeOfHandler->AddSize(tag,aSize);
|
|
|
|
|
|
|
|
// Now the associated rules (if they exist)
|
|
|
|
// - mFirstLineRule
|
|
|
|
// - mFirstLetterRule
|
|
|
|
if(mFirstLineRule && uniqueItems->AddItem((void*)mFirstLineRule)){
|
|
|
|
localSize = sizeof(*mFirstLineRule);
|
|
|
|
aSize += localSize;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("FirstLineRule"));
|
|
|
|
aSizeOfHandler->AddSize(tag,localSize);
|
|
|
|
}
|
|
|
|
if(mFirstLetterRule && uniqueItems->AddItem((void*)mFirstLetterRule)){
|
|
|
|
localSize = sizeof(*mFirstLetterRule);
|
|
|
|
aSize += localSize;
|
|
|
|
tag = getter_AddRefs(NS_NewAtom("FirstLetterRule"));
|
|
|
|
aSizeOfHandler->AddSize(tag,localSize);
|
|
|
|
}
|
|
|
|
}
|
1998-12-03 23:20:35 +03:00
|
|
|
|
2000-05-16 06:43:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::AttributeAffectsStyle(nsIAtom *aAttribute,
|
|
|
|
nsIContent *aContent,
|
|
|
|
PRBool &aAffects)
|
|
|
|
{
|
|
|
|
// XXX can attributes affect rules in these?
|
|
|
|
aAffects = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
// XXX For backwards compatibility and convenience
|
1998-05-14 03:42:18 +04:00
|
|
|
NS_HTML nsresult
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURI* aURL,
|
1998-11-26 04:34:53 +03:00
|
|
|
nsIDocument* aDocument)
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIHTMLCSSStyleSheet* sheet;
|
|
|
|
if (NS_FAILED(rv = NS_NewHTMLCSSStyleSheet(&sheet)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = sheet->Init(aURL, aDocument))) {
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = sheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_HTML nsresult
|
|
|
|
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl();
|
1998-05-14 03:42:18 +04:00
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|