1998-05-13 23:42:18 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1999-02-27 01:35:25 +00:00
|
|
|
|
1998-05-13 23:42:18 +00: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-18 21:11:08 +00:00
|
|
|
#include "nsIFrame.h"
|
1998-09-05 04:00:06 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-09-12 02:46:59 +00:00
|
|
|
#include "nsICSSStyleRule.h"
|
1998-09-17 00:19:47 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-05-13 23:42:18 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
1998-09-12 02:46:59 +00:00
|
|
|
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
|
1998-09-17 00:19:47 +00:00
|
|
|
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
1998-05-13 23:42:18 +00:00
|
|
|
|
1999-04-20 00:28:40 +00: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;
|
|
|
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext);
|
|
|
|
NS_IMETHOD MapFontStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext);
|
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
|
|
|
nsIHTMLCSSStyleSheet* mSheet;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSFirstLineRule::CSSFirstLineRule(nsIHTMLCSSStyleSheet* aSheet)
|
|
|
|
: mSheet(aSheet)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSFirstLineRule::~CSSFirstLineRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(CSSFirstLineRule, kIStyleRuleIID);
|
|
|
|
|
|
|
|
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
|
|
|
|
CSSFirstLineRule::MapFontStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixup the style context so that all of the properties that don't
|
|
|
|
// apply (CSS2 spec section 5.12.1) don't apply.
|
|
|
|
//
|
|
|
|
// The properties that apply: font-properties, color-properties,
|
|
|
|
// backgorund-properties, word-spacing, letter-spacing,
|
|
|
|
// text-decoration, vertical-align, text-transform, line-height,
|
|
|
|
// text-shadow, and clear.
|
|
|
|
//
|
|
|
|
// Everything else doesn't apply.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::MapStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIStyleContext* parentContext;
|
|
|
|
parentContext = aContext->GetParent();
|
|
|
|
|
|
|
|
// Disable border
|
|
|
|
nsStyleSpacing* spacing = (nsStyleSpacing*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Spacing);
|
|
|
|
if (spacing) {
|
|
|
|
spacing->SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
|
|
|
|
spacing->SetBorderStyle(NS_SIDE_RIGHT, NS_STYLE_BORDER_STYLE_NONE);
|
|
|
|
spacing->SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_NONE);
|
|
|
|
spacing->SetBorderStyle(NS_SIDE_LEFT, NS_STYLE_BORDER_STYLE_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undo any change made to "direction"
|
|
|
|
nsStyleDisplay* display = (nsStyleDisplay*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Display);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleDisplay* parentDisplay = (const nsStyleDisplay*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (parentDisplay) {
|
|
|
|
display->mDirection = parentDisplay->mDirection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undo any change made to "cursor"
|
|
|
|
nsStyleColor* color = (nsStyleColor*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Color);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleColor* parentColor = (const nsStyleColor*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
if (parentColor) {
|
|
|
|
color->mCursor = parentColor->mCursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undo any change to quotes
|
|
|
|
nsStyleContent* content = (nsStyleContent*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Content);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleContent* parentContent = (const nsStyleContent*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Content);
|
|
|
|
if (parentContent) {
|
|
|
|
nsAutoString open, close;
|
|
|
|
PRUint32 i, n = parentContent->QuotesCount();
|
|
|
|
content->AllocateQuotes(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
parentContent->GetQuotesAt(i, open, close);
|
|
|
|
content->SetQuotesAt(i, open, close);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-28 01:16:45 +00:00
|
|
|
|
|
|
|
NS_RELEASE(parentContext);
|
1999-04-20 00:28:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLineRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
class CSSFirstLetterRule : public CSSFirstLineRule {
|
|
|
|
public:
|
|
|
|
CSSFirstLetterRule(nsIHTMLCSSStyleSheet* aSheet);
|
|
|
|
|
|
|
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSFirstLetterRule::CSSFirstLetterRule(nsIHTMLCSSStyleSheet* aSheet)
|
|
|
|
: CSSFirstLineRule(aSheet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-04-28 01:16:45 +00:00
|
|
|
// Fixup the style context so that all of the properties that don't
|
|
|
|
// apply (CSS2 spec section 5.12.2) don't apply.
|
|
|
|
//
|
|
|
|
// These properties apply: font-properties, color-properties,
|
|
|
|
// backgorund-properties, text-decoration, vertical-align,
|
|
|
|
// text-transform, line-height, margin-properties,
|
|
|
|
// padding-properties, border-properties, float, text-shadow and
|
|
|
|
// clear.
|
|
|
|
//
|
|
|
|
// Everything else doesn't apply.
|
1999-04-20 00:28:40 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLetterRule::MapStyleInto(nsIStyleContext* aContext,
|
|
|
|
nsIPresContext* aPresContext)
|
|
|
|
{
|
1999-04-28 01:16:45 +00:00
|
|
|
nsIStyleContext* parentContext;
|
|
|
|
parentContext = aContext->GetParent();
|
1999-04-20 00:28:40 +00:00
|
|
|
|
1999-04-28 01:16:45 +00:00
|
|
|
// Undo any change made to "direction"
|
|
|
|
nsStyleDisplay* display = (nsStyleDisplay*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Display);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleDisplay* parentDisplay = (const nsStyleDisplay*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (parentDisplay) {
|
|
|
|
display->mDirection = parentDisplay->mDirection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undo any change made to "cursor"
|
|
|
|
nsStyleColor* color = (nsStyleColor*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Color);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleColor* parentColor = (const nsStyleColor*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
if (parentColor) {
|
|
|
|
color->mCursor = parentColor->mCursor;
|
|
|
|
}
|
1999-04-20 00:28:40 +00:00
|
|
|
}
|
1999-04-28 01:16:45 +00:00
|
|
|
|
|
|
|
// Undo any change to quotes
|
|
|
|
nsStyleContent* content = (nsStyleContent*)
|
|
|
|
aContext->GetMutableStyleData(eStyleStruct_Content);
|
|
|
|
if (parentContext) {
|
|
|
|
const nsStyleContent* parentContent = (const nsStyleContent*)
|
|
|
|
parentContext->GetStyleData(eStyleStruct_Content);
|
|
|
|
if (parentContent) {
|
|
|
|
nsAutoString open, close;
|
|
|
|
PRUint32 i, n = parentContent->QuotesCount();
|
|
|
|
content->AllocateQuotes(n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
parentContent->GetQuotesAt(i, open, close);
|
|
|
|
content->SetQuotesAt(i, open, close);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(parentContext);
|
1999-04-20 00:28:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
1998-05-13 23:42:18 +00:00
|
|
|
|
|
|
|
class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet {
|
|
|
|
public:
|
|
|
|
void* operator new(size_t size);
|
|
|
|
void* operator new(size_t size, nsIArena* aArena);
|
1999-02-26 19:26:29 +00:00
|
|
|
void operator delete(void* ptr);
|
1998-05-13 23:42:18 +00:00
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
HTMLCSSStyleSheetImpl();
|
1998-05-13 23:42:18 +00:00
|
|
|
|
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
// basic style sheet data
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
|
|
|
|
NS_IMETHOD Reset(nsIURI* aURL);
|
|
|
|
NS_IMETHOD GetURL(nsIURI*& aURL) const;
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
|
1998-12-02 00:38:33 +00:00
|
|
|
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const;
|
1999-06-15 06:21:47 +00:00
|
|
|
NS_IMETHOD UseForMedium(nsIAtom* aMedium) const;
|
1998-11-26 01:34:53 +00: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);
|
|
|
|
|
1998-05-13 23:42:18 +00:00
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-13 23:42:18 +00:00
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
1998-05-18 21:11:08 +00:00
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIContent* aParentContent,
|
1998-05-18 21:11:08 +00:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-18 21:11:08 +00:00
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
|
1998-05-13 23:42:18 +00:00
|
|
|
// XXX style rule enumerations
|
|
|
|
|
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* mURL;
|
1998-11-26 01:34:53 +00:00
|
|
|
nsIDocument* mDocument;
|
1999-04-20 00:28:40 +00:00
|
|
|
|
|
|
|
CSSFirstLineRule* mFirstLineRule;
|
1999-04-28 01:16:45 +00:00
|
|
|
CSSFirstLetterRule* mFirstLetterRule;
|
1998-05-13 23:42:18 +00: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 19:26:29 +00:00
|
|
|
void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
|
1998-05-13 23:42:18 +00:00
|
|
|
{
|
|
|
|
HTMLCSSStyleSheetImpl* sheet = (HTMLCSSStyleSheetImpl*) ptr;
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (sheet->mInHeap) {
|
1999-02-26 17:13:10 +00:00
|
|
|
::operator delete(ptr);
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
|
1998-05-13 23:42:18 +00:00
|
|
|
: nsIHTMLCSSStyleSheet(),
|
1998-12-03 20:20:35 +00:00
|
|
|
mURL(nsnull),
|
1999-04-20 00:28:40 +00:00
|
|
|
mDocument(nsnull),
|
1999-04-28 01:16:45 +00:00
|
|
|
mFirstLineRule(nsnull),
|
|
|
|
mFirstLetterRule(nsnull)
|
1998-05-13 23:42:18 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mURL);
|
1999-04-20 00:28:40 +00:00
|
|
|
if (nsnull != mFirstLineRule) {
|
|
|
|
mFirstLineRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLineRule);
|
|
|
|
}
|
1999-04-28 01:16:45 +00:00
|
|
|
if (nsnull != mFirstLetterRule) {
|
|
|
|
mFirstLetterRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLetterRule);
|
|
|
|
}
|
1998-05-13 23:42:18 +00: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);
|
|
|
|
if (aIID.Equals(kIHTMLCSSStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIHTMLCSSStyleSheet*)this);
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-13 23:42:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-13 23:42:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
1998-10-05 05:11:18 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-05-13 23:42:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-13 23:42:18 +00:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aContent, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aResults, "null arg");
|
|
|
|
|
|
|
|
PRInt32 matchCount = 0;
|
|
|
|
|
1999-02-27 01:35:25 +00:00
|
|
|
nsIStyledContent* styledContent;
|
|
|
|
|
1998-11-03 20:33:43 +00:00
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
1999-03-03 19:48:57 +00:00
|
|
|
if (NS_SUCCEEDED(aContent->QueryInterface(nsIStyledContent::GetIID(), (void**)&styledContent))) {
|
1998-12-02 00:38:33 +00:00
|
|
|
nsIStyleRule* rule = nsnull;
|
1999-05-26 23:55:49 +00:00
|
|
|
PRUint32 index = 0;
|
|
|
|
aResults->Count(&index);
|
|
|
|
if (NS_SUCCEEDED(styledContent->GetInlineStyleRules(aResults))) {
|
|
|
|
PRUint32 postCount = 0;
|
|
|
|
aResults->Count(&postCount);
|
|
|
|
while (index < postCount) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)aResults->ElementAt(index++);
|
1998-12-02 00:38:33 +00:00
|
|
|
matchCount++;
|
|
|
|
nsICSSStyleRule* cssRule;
|
|
|
|
if (NS_SUCCEEDED(rule->QueryInterface(kICSSStyleRuleIID, (void**)&cssRule))) {
|
|
|
|
nsIStyleRule* important = cssRule->GetImportantRule();
|
|
|
|
if (nsnull != important) {
|
|
|
|
aResults->AppendElement(important);
|
|
|
|
matchCount++;
|
|
|
|
NS_RELEASE(important);
|
1998-05-18 21:11:08 +00:00
|
|
|
}
|
1998-12-02 00:38:33 +00:00
|
|
|
NS_RELEASE(cssRule);
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
1998-12-02 00:38:33 +00:00
|
|
|
NS_RELEASE(rule);
|
1998-11-03 20:33:43 +00:00
|
|
|
}
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
1999-02-27 01:35:25 +00:00
|
|
|
|
|
|
|
NS_RELEASE(styledContent);
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return matchCount;
|
|
|
|
}
|
|
|
|
|
1998-05-18 21:11:08 +00:00
|
|
|
PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIContent* aParentContent,
|
1998-05-18 21:11:08 +00:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 20:33:43 +00:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-18 21:11:08 +00:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
1999-04-20 00:28:40 +00:00
|
|
|
if (aPseudoTag == nsHTMLAtoms::firstLinePseudo) {
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = aResults->Count(&cnt);
|
|
|
|
if (NS_SUCCEEDED(rv) && cnt) {
|
1999-04-20 00:28:40 +00:00
|
|
|
if (nsnull == mFirstLineRule) {
|
|
|
|
mFirstLineRule = new CSSFirstLineRule(this);
|
|
|
|
if (mFirstLineRule) {
|
|
|
|
NS_ADDREF(mFirstLineRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFirstLineRule) {
|
|
|
|
aResults->AppendElement(mFirstLineRule);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-28 01:16:45 +00:00
|
|
|
if (aPseudoTag == nsHTMLAtoms::firstLetterPseudo) {
|
1999-05-13 04:56:04 +00:00
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = aResults->Count(&cnt);
|
|
|
|
if (NS_SUCCEEDED(rv) && cnt) {
|
1999-04-28 01:16:45 +00:00
|
|
|
if (nsnull == mFirstLetterRule) {
|
|
|
|
mFirstLetterRule = new CSSFirstLetterRule(this);
|
|
|
|
if (mFirstLetterRule) {
|
|
|
|
NS_ADDREF(mFirstLetterRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFirstLetterRule) {
|
|
|
|
aResults->AppendElement(mFirstLetterRule);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-20 00:28:40 +00:00
|
|
|
// else no pseudo frame style...
|
1998-05-18 21:11:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
HTMLCSSStyleSheetImpl::Init(nsIURI* aURL, nsIDocument* aDocument)
|
1998-12-03 20:20:35 +00: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 00:05:54 +00:00
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::HasStateDependentStyle(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
return NS_COMFALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-03 19:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
HTMLCSSStyleSheetImpl::Reset(nsIURI* aURL)
|
1999-02-03 19:38:16 +00:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
1999-04-20 00:28:40 +00:00
|
|
|
if (nsnull != mFirstLineRule) {
|
|
|
|
mFirstLineRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLineRule);
|
|
|
|
}
|
1999-04-28 01:16:45 +00:00
|
|
|
if (nsnull != mFirstLetterRule) {
|
|
|
|
mFirstLetterRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mFirstLetterRule);
|
|
|
|
}
|
1999-02-03 19:38:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 03:29:44 +00:00
|
|
|
HTMLCSSStyleSheetImpl::GetURL(nsIURI*& aURL) const
|
1998-05-13 23:42:18 +00:00
|
|
|
{
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
aURL = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aTitle.Append("Internal HTML/CSS Style Sheet");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType.Truncate();
|
|
|
|
aType.Append("text/html");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-02 00:38:33 +00:00
|
|
|
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
1998-11-26 01:34:53 +00:00
|
|
|
{
|
1998-12-02 00:38:33 +00:00
|
|
|
aMedium = nsnull;
|
1998-11-26 01:34:53 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
1999-06-15 06:21:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
|
|
|
|
{
|
|
|
|
return NS_OK; // works for all media
|
|
|
|
}
|
|
|
|
|
1998-11-26 01:34:53 +00: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-13 23:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
1998-12-16 05:40:20 +00:00
|
|
|
PRUnichar* buffer;
|
1998-05-13 23:42:18 +00:00
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
1998-12-16 05:40:20 +00:00
|
|
|
mURL->ToString(&buffer);
|
1999-04-06 00:29:40 +00:00
|
|
|
nsAutoString as(buffer,0);
|
|
|
|
fputs(as, out);
|
1998-05-13 23:42:18 +00:00
|
|
|
fputs("\n", out);
|
1998-12-16 05:40:20 +00:00
|
|
|
delete buffer;
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
|
|
|
|
// XXX For backwards compatibility and convenience
|
1998-05-13 23:42:18 +00:00
|
|
|
NS_HTML nsresult
|
1999-06-23 03:29:44 +00:00
|
|
|
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURI* aURL,
|
1998-11-26 01:34:53 +00:00
|
|
|
nsIDocument* aDocument)
|
1998-12-03 20:20:35 +00: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-13 23:42:18 +00:00
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl();
|
1998-05-13 23:42:18 +00:00
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1998-12-03 20:20:35 +00:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|