gecko-dev/layout/style/nsCSSStyleRule.cpp

2154 lines
70 KiB
C++
Raw Normal View History

1998-04-13 20:24:54 +00:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsICSSStyleRule.h"
#include "nsICSSDeclaration.h"
1998-11-26 01:34:53 +00:00
#include "nsICSSStyleSheet.h"
1998-04-13 20:24:54 +00:00
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
1998-11-26 01:34:53 +00:00
#include "nsIDocument.h"
1998-08-07 02:16:38 +00:00
#include "nsIDeviceContext.h"
1998-04-13 20:24:54 +00:00
#include "nsIArena.h"
#include "nsIAtom.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsStyleConsts.h"
#include "nsHTMLAtoms.h"
1998-04-13 20:24:54 +00:00
#include "nsUnitConversion.h"
#include "nsStyleUtil.h"
#include "nsIFontMetrics.h"
#include "nsIDOMCSSStyleSheet.h"
1998-11-26 01:34:53 +00:00
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsDOMCSSDeclaration.h"
1998-12-11 02:50:43 +00:00
#include "nsINameSpaceManager.h"
1998-04-13 20:24:54 +00:00
//#define DEBUG_REFS
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
1998-04-13 20:24:54 +00:00
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kICSSDeclarationIID, NS_ICSS_DECLARATION_IID);
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
1998-11-26 01:34:53 +00:00
static NS_DEFINE_IID(kIDOMCSSRuleIID, NS_IDOMCSSRULE_IID);
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
1998-04-13 20:24:54 +00:00
static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID);
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
static NS_DEFINE_IID(kCSSTextSID, NS_CSS_TEXT_SID);
static NS_DEFINE_IID(kCSSMarginSID, NS_CSS_MARGIN_SID);
static NS_DEFINE_IID(kCSSPositionSID, NS_CSS_POSITION_SID);
static NS_DEFINE_IID(kCSSListSID, NS_CSS_LIST_SID);
static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID);
static NS_DEFINE_IID(kCSSTableSID, NS_CSS_TABLE_SID);
1998-04-13 20:24:54 +00:00
// -- nsCSSSelector -------------------------------
1998-12-11 02:50:43 +00:00
#define NS_IF_COPY(dest,source,type) \
if (nsnull != source) dest = new type(*(source))
#define NS_IF_DELETE(ptr) \
if (nsnull != ptr) { delete ptr; ptr = nsnull; }
nsAtomList::nsAtomList(nsIAtom* aAtom)
: mAtom(aAtom),
1998-04-13 20:24:54 +00:00
mNext(nsnull)
{
1998-12-11 02:50:43 +00:00
NS_IF_ADDREF(mAtom);
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
nsAtomList::nsAtomList(const nsString& aAtomValue)
: mAtom(nsnull),
mNext(nsnull)
{
mAtom = NS_NewAtom(aAtomValue);
}
nsAtomList::nsAtomList(const nsAtomList& aCopy)
: mAtom(aCopy.mAtom),
mNext(nsnull)
{
NS_IF_ADDREF(mAtom);
NS_IF_COPY(mNext, aCopy.mNext, nsAtomList);
}
nsAtomList::~nsAtomList(void)
{
NS_IF_RELEASE(mAtom);
NS_IF_DELETE(mNext);
}
PRBool nsAtomList::Equals(const nsAtomList* aOther) const
{
if (this == aOther) {
return PR_TRUE;
}
if (nsnull != aOther) {
if (mAtom == aOther->mAtom) {
if (nsnull != mNext) {
return mNext->Equals(aOther->mNext);
}
return PRBool(nsnull == aOther->mNext);
}
}
return PR_FALSE;
}
nsAttrSelector::nsAttrSelector(const nsString& aAttr)
: mAttr(nsnull),
mFunction(NS_ATTR_FUNC_SET),
1998-12-21 05:58:58 +00:00
mCaseSensitive(1),
1998-12-11 02:50:43 +00:00
mValue(),
mNext(nsnull)
{
mAttr = NS_NewAtom(aAttr);
}
nsAttrSelector::nsAttrSelector(const nsString& aAttr, PRUint8 aFunction, const nsString& aValue,
1998-12-21 05:58:58 +00:00
PRBool aCaseSensitive)
1998-12-11 02:50:43 +00:00
: mAttr(nsnull),
mFunction(aFunction),
1998-12-21 05:58:58 +00:00
mCaseSensitive(aCaseSensitive),
1998-12-11 02:50:43 +00:00
mValue(aValue),
mNext(nsnull)
{
mAttr = NS_NewAtom(aAttr);
}
nsAttrSelector::nsAttrSelector(const nsAttrSelector& aCopy)
: mAttr(aCopy.mAttr),
mFunction(aCopy.mFunction),
1998-12-21 05:58:58 +00:00
mCaseSensitive(aCopy.mCaseSensitive),
1998-12-11 02:50:43 +00:00
mValue(aCopy.mValue),
mNext(nsnull)
{
NS_IF_ADDREF(mAttr);
NS_IF_COPY(mNext, aCopy.mNext, nsAttrSelector);
}
nsAttrSelector::~nsAttrSelector(void)
{
NS_IF_RELEASE(mAttr);
NS_IF_DELETE(mNext);
}
PRBool nsAttrSelector::Equals(const nsAttrSelector* aOther) const
{
if (this == aOther) {
return PR_TRUE;
}
if (nsnull != aOther) {
if ((mAttr == aOther->mAttr) &&
(mFunction == aOther->mFunction) &&
1998-12-21 05:58:58 +00:00
(mCaseSensitive == aOther->mCaseSensitive) &&
1998-12-11 02:50:43 +00:00
mValue.Equals(aOther->mValue)) {
if (nsnull != mNext) {
return mNext->Equals(aOther->mNext);
}
return PRBool(nsnull == aOther->mNext);
}
}
return PR_FALSE;
}
nsCSSSelector::nsCSSSelector(void)
: mNameSpace(kNameSpaceID_Unknown), mTag(nsnull),
mID(nsnull),
mClassList(nsnull),
mPseudoClassList(nsnull),
mAttrList(nsnull),
mOperator(0),
1998-04-13 20:24:54 +00:00
mNext(nsnull)
{
}
nsCSSSelector::nsCSSSelector(const nsCSSSelector& aCopy)
1998-12-11 02:50:43 +00:00
: mNameSpace(aCopy.mNameSpace), mTag(aCopy.mTag),
mID(aCopy.mID),
mClassList(nsnull),
mPseudoClassList(nsnull),
mAttrList(nsnull),
mOperator(aCopy.mOperator),
1998-04-13 20:24:54 +00:00
mNext(nsnull)
1998-12-11 02:50:43 +00:00
{
1998-04-13 20:24:54 +00:00
NS_IF_ADDREF(mTag);
NS_IF_ADDREF(mID);
1998-12-11 02:50:43 +00:00
NS_IF_COPY(mClassList, aCopy.mClassList, nsAtomList);
NS_IF_COPY(mPseudoClassList, aCopy.mPseudoClassList, nsAtomList);
NS_IF_COPY(mAttrList, aCopy.mAttrList, nsAttrSelector);
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
nsCSSSelector::~nsCSSSelector(void)
{
Reset();
1998-04-13 20:24:54 +00:00
}
nsCSSSelector& nsCSSSelector::operator=(const nsCSSSelector& aCopy)
{
NS_IF_RELEASE(mTag);
NS_IF_RELEASE(mID);
1998-12-11 02:50:43 +00:00
NS_IF_DELETE(mClassList);
NS_IF_DELETE(mPseudoClassList);
NS_IF_DELETE(mAttrList);
mNameSpace = aCopy.mNameSpace;
1998-04-13 20:24:54 +00:00
mTag = aCopy.mTag;
mID = aCopy.mID;
1998-12-11 02:50:43 +00:00
NS_IF_COPY(mClassList, aCopy.mClassList, nsAtomList);
NS_IF_COPY(mPseudoClassList, aCopy.mPseudoClassList, nsAtomList);
NS_IF_COPY(mAttrList, aCopy.mAttrList, nsAttrSelector);
mOperator = aCopy.mOperator;
1998-04-13 20:24:54 +00:00
NS_IF_ADDREF(mTag);
NS_IF_ADDREF(mID);
return *this;
}
PRBool nsCSSSelector::Equals(const nsCSSSelector* aOther) const
{
1998-12-11 02:50:43 +00:00
if (this == aOther) {
return PR_TRUE;
}
1998-04-13 20:24:54 +00:00
if (nsnull != aOther) {
1998-12-11 02:50:43 +00:00
if ((aOther->mNameSpace == mNameSpace) &&
(aOther->mTag == mTag) &&
(aOther->mID == mID) &&
(aOther->mOperator == mOperator)) {
if (nsnull != mClassList) {
if (PR_FALSE == mClassList->Equals(aOther->mClassList)) {
return PR_FALSE;
}
}
else {
if (nsnull != aOther->mClassList) {
return PR_FALSE;
}
}
if (nsnull != mPseudoClassList) {
if (PR_FALSE == mPseudoClassList->Equals(aOther->mPseudoClassList)) {
return PR_FALSE;
}
}
else {
if (nsnull != aOther->mPseudoClassList) {
return PR_FALSE;
}
}
if (nsnull != mAttrList) {
if (PR_FALSE == mAttrList->Equals(aOther->mAttrList)) {
return PR_FALSE;
}
}
else {
if (nsnull != aOther->mAttrList) {
return PR_FALSE;
}
}
return PR_TRUE;
}
1998-04-13 20:24:54 +00:00
}
return PR_FALSE;
}
1998-12-11 02:50:43 +00:00
void nsCSSSelector::Reset(void)
1998-04-13 20:24:54 +00:00
{
1998-12-11 02:50:43 +00:00
mNameSpace = kNameSpaceID_Unknown;
1998-04-13 20:24:54 +00:00
NS_IF_RELEASE(mTag);
NS_IF_RELEASE(mID);
1998-12-11 02:50:43 +00:00
NS_IF_DELETE(mClassList);
NS_IF_DELETE(mPseudoClassList);
NS_IF_DELETE(mAttrList);
}
void nsCSSSelector::SetNameSpace(PRInt32 aNameSpace)
{
mNameSpace = aNameSpace;
}
void nsCSSSelector::SetTag(const nsString& aTag)
{
NS_IF_RELEASE(mTag);
1998-04-13 20:24:54 +00:00
if (0 < aTag.Length()) {
1998-12-11 02:50:43 +00:00
mTag = NS_NewAtom(aTag);
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
}
void nsCSSSelector::SetID(const nsString& aID)
{
NS_IF_RELEASE(mID);
1998-04-13 20:24:54 +00:00
if (0 < aID.Length()) {
mID = NS_NewAtom(aID);
}
1998-12-11 02:50:43 +00:00
}
void nsCSSSelector::AddClass(const nsString& aClass)
{
1998-04-13 20:24:54 +00:00
if (0 < aClass.Length()) {
1998-12-11 02:50:43 +00:00
nsAtomList** list = &mClassList;
while (nsnull != *list) {
list = &((*list)->mNext);
}
*list = new nsAtomList(aClass);
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
}
void nsCSSSelector::AddPseudoClass(const nsString& aPseudoClass)
{
1998-04-13 20:24:54 +00:00
if (0 < aPseudoClass.Length()) {
1998-12-11 02:50:43 +00:00
nsAtomList** list = &mPseudoClassList;
while (nsnull != *list) {
list = &((*list)->mNext);
}
*list = new nsAtomList(aPseudoClass);
}
}
void nsCSSSelector::AddPseudoClass(nsIAtom* aPseudoClass)
{
if (nsnull != aPseudoClass) {
nsAtomList** list = &mPseudoClassList;
while (nsnull != *list) {
list = &((*list)->mNext);
}
1998-12-11 02:50:43 +00:00
*list = new nsAtomList(aPseudoClass);
}
}
void nsCSSSelector::AddAttribute(const nsString& aAttr)
{
if (0 < aAttr.Length()) {
nsAttrSelector** list = &mAttrList;
while (nsnull != *list) {
list = &((*list)->mNext);
}
*list = new nsAttrSelector(aAttr);
}
}
void nsCSSSelector::AddAttribute(const nsString& aAttr, PRUint8 aFunc, const nsString& aValue,
1998-12-21 05:58:58 +00:00
PRBool aCaseSensitive)
1998-12-11 02:50:43 +00:00
{
if (0 < aAttr.Length()) {
nsAttrSelector** list = &mAttrList;
while (nsnull != *list) {
list = &((*list)->mNext);
}
1998-12-21 05:58:58 +00:00
*list = new nsAttrSelector(aAttr, aFunc, aValue, aCaseSensitive);
1998-12-11 02:50:43 +00:00
}
}
void nsCSSSelector::SetOperator(PRUnichar aOperator)
{
mOperator = aOperator;
}
PRInt32 nsCSSSelector::CalcWeight(void) const
{
PRInt32 weight = 0;
if (nsnull != mTag) {
weight += 0x000001;
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
if (nsnull != mID) {
weight += 0x010000;
}
nsAtomList* list = mClassList;
while (nsnull != list) {
weight += 0x000100;
list = list->mNext;
}
list = mPseudoClassList;
while (nsnull != list) {
weight += 0x000100;
list = list->mNext;
}
nsAttrSelector* attr = mAttrList;
while (nsnull != attr) {
weight += 0x000100;
attr = attr->mNext;
}
if (nsnull != mNext) {
weight += mNext->CalcWeight();
}
return weight;
1998-04-13 20:24:54 +00:00
}
// -- CSSImportantRule -------------------------------
static nscoord CalcLength(const nsCSSValue& aValue, const nsStyleFont* aFont,
nsIPresContext* aPresContext);
static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
PRInt32 aMask, const nsStyleFont* aFont,
nsIPresContext* aPresContext);
static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
nsIStyleContext* aContext, nsIPresContext* aPresContext);
1998-11-26 01:34:53 +00:00
class CSSStyleRuleImpl;
class CSSImportantRule : public nsIStyleRule {
public:
1998-11-26 01:34:53 +00:00
CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration);
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
1998-11-26 01:34:53 +00:00
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHOD GetStrength(PRInt32& aStrength) const;
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
protected:
~CSSImportantRule(void);
nsICSSDeclaration* mDeclaration;
1998-11-26 01:34:53 +00:00
nsICSSStyleSheet* mSheet;
friend CSSStyleRuleImpl;
};
1998-11-26 01:34:53 +00:00
CSSImportantRule::CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration)
: mSheet(aSheet),
mDeclaration(aDeclaration)
{
1998-09-12 02:43:48 +00:00
NS_INIT_REFCNT();
NS_IF_ADDREF(mDeclaration);
}
CSSImportantRule::~CSSImportantRule(void)
{
NS_IF_RELEASE(mDeclaration);
}
NS_IMPL_ISUPPORTS(CSSImportantRule, kIStyleRuleIID);
NS_IMETHODIMP
CSSImportantRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(aRule == this);
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::HashValue(PRUint32& aValue) const
{
aValue = PRUint32(mDeclaration);
return NS_OK;
}
1998-11-26 01:34:53 +00:00
NS_IMETHODIMP
CSSImportantRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHODIMP
CSSImportantRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 1;
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
MapDeclarationInto(mDeclaration, aContext, aPresContext);
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
{
// Indent
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
fputs("! Important rule ", out);
if (nsnull != mDeclaration) {
mDeclaration->List(out);
}
else {
fputs("{ null declaration }", out);
}
fputs("\n", out);
return NS_OK;
}
// -- nsDOMStyleRuleDeclaration -------------------------------
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
{
public:
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
~DOMCSSDeclarationImpl();
virtual void DropReference();
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
PRBool aAllocate);
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
PRInt32 aHint);
virtual nsresult GetParent(nsISupports **aParent);
protected:
nsICSSStyleRule *mRule;
};
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
{
// This reference is not reference-counted. The rule
// object tells us when its about to go away.
mRule = aRule;
}
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl()
{
}
void
DOMCSSDeclarationImpl::DropReference()
{
mRule = nsnull;
}
nsresult
DOMCSSDeclarationImpl::GetCSSDeclaration(nsICSSDeclaration **aDecl,
PRBool aAllocate)
{
if (nsnull != mRule) {
*aDecl = mRule->GetDeclaration();
}
else {
*aDecl = nsnull;
}
return NS_OK;
}
nsresult
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
PRInt32 aHint)
{
1998-11-26 01:34:53 +00:00
nsIStyleSheet* sheet = nsnull;
if (nsnull != mRule) {
mRule->GetStyleSheet(sheet);
if (nsnull != sheet) {
nsIDocument* doc = nsnull;
sheet->GetOwningDocument(doc);
if (nsnull != doc) {
doc->StyleRuleChanged(sheet, mRule, aHint);
}
}
}
return NS_OK;
}
nsresult
DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
{
if (nsnull != mRule) {
return mRule->QueryInterface(kISupportsIID, (void **)aParent);
}
return NS_OK;
}
1998-04-13 20:24:54 +00:00
// -- nsCSSStyleRule -------------------------------
class CSSStyleRuleImpl : public nsICSSStyleRule,
1998-11-26 01:34:53 +00:00
public nsIDOMCSSStyleRule,
public nsIScriptObjectOwner {
1998-04-13 20:24:54 +00:00
public:
void* operator new(size_t size);
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
CSSStyleRuleImpl(const nsCSSSelector& aSelector);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
1998-09-02 02:09:43 +00:00
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHOD GetStrength(PRInt32& aStrength) const;
1998-04-13 20:24:54 +00:00
virtual nsCSSSelector* FirstSelector(void);
virtual void AddSelector(const nsCSSSelector& aSelector);
virtual void DeleteSelector(nsCSSSelector* aSelector);
1998-12-11 02:50:43 +00:00
virtual void SetSourceSelectorText(const nsString& aSelectorText);
virtual void GetSourceSelectorText(nsString& aSelectorText) const;
1998-04-13 20:24:54 +00:00
virtual nsICSSDeclaration* GetDeclaration(void) const;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration);
virtual PRInt32 GetWeight(void) const;
virtual void SetWeight(PRInt32 aWeight);
virtual nsIStyleRule* GetImportantRule(void);
1998-09-02 02:09:43 +00:00
1998-11-26 01:34:53 +00:00
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
1998-04-13 20:24:54 +00:00
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
1998-04-13 20:24:54 +00:00
1998-11-26 01:34:53 +00:00
// nsIDOMCSSRule interface
NS_IMETHOD GetType(PRUint16* aType);
NS_IMETHOD GetCssText(nsString& aCssText);
NS_IMETHOD SetCssText(const nsString& aCssText);
NS_IMETHOD GetSheet(nsIDOMCSSStyleSheet** aSheet);
1998-11-26 01:34:53 +00:00
// nsIDOMCSSStyleRule interface
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
1998-11-26 01:34:53 +00:00
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
1998-04-13 20:24:54 +00:00
private:
// These are not supported and are not implemented!
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
CSSStyleRuleImpl& operator=(const CSSStyleRuleImpl& aCopy);
protected:
virtual ~CSSStyleRuleImpl();
protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
1998-11-26 01:34:53 +00:00
nsCSSSelector mSelector;
1998-12-11 02:50:43 +00:00
nsString mSelectorText;
1998-11-26 01:34:53 +00:00
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsICSSStyleSheet* mSheet;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif
1998-04-13 20:24:54 +00:00
};
void* CSSStyleRuleImpl::operator new(size_t size)
{
CSSStyleRuleImpl* rv = (CSSStyleRuleImpl*) ::operator new(size);
#ifdef NS_DEBUG
if (nsnull != rv) {
nsCRT::memset(rv, 0xEE, size);
}
#endif
rv->mInHeap = 1;
return (void*) rv;
}
void* CSSStyleRuleImpl::operator new(size_t size, nsIArena* aArena)
{
CSSStyleRuleImpl* rv = (CSSStyleRuleImpl*) aArena->Alloc(PRInt32(size));
#ifdef NS_DEBUG
if (nsnull != rv) {
nsCRT::memset(rv, 0xEE, size);
}
#endif
rv->mInHeap = 0;
return (void*) rv;
}
void CSSStyleRuleImpl::operator delete(void* ptr)
{
CSSStyleRuleImpl* rule = (CSSStyleRuleImpl*) ptr;
if (nsnull != rule) {
if (rule->mInHeap) {
::delete ptr;
}
}
}
#ifdef DEBUG_REFS
static PRInt32 gInstanceCount;
static const PRInt32 kInstrument = 1075;
#endif
1998-04-13 20:24:54 +00:00
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
1998-12-11 02:50:43 +00:00
: mSelector(aSelector), mSelectorText(), mDeclaration(nsnull),
mWeight(0), mImportantRule(nsnull)
1998-04-13 20:24:54 +00:00
{
NS_INIT_REFCNT();
mDOMDeclaration = nsnull;
mScriptObject = nsnull;
#ifdef DEBUG_REFS
mInstance = gInstanceCount++;
fprintf(stdout, "%d of %d + CSSStyleRule\n", mInstance, gInstanceCount);
#endif
1998-04-13 20:24:54 +00:00
}
CSSStyleRuleImpl::~CSSStyleRuleImpl()
{
nsCSSSelector* next = mSelector.mNext;
while (nsnull != next) {
nsCSSSelector* selector = next;
next = selector->mNext;
delete selector;
}
NS_IF_RELEASE(mDeclaration);
1998-11-26 01:34:53 +00:00
if (nsnull != mImportantRule) {
mImportantRule->mSheet = nsnull;
NS_RELEASE(mImportantRule);
}
if (nsnull != mDOMDeclaration) {
mDOMDeclaration->DropReference();
}
#ifdef DEBUG_REFS
--gInstanceCount;
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
#endif
1998-04-13 20:24:54 +00:00
}
#ifdef DEBUG_REFS
nsrefcnt CSSStyleRuleImpl::AddRef(void)
{
if (mInstance == kInstrument) {
fprintf(stdout, "%d AddRef CSSStyleRule\n", mRefCnt + 1);
}
return ++mRefCnt;
}
nsrefcnt CSSStyleRuleImpl::Release(void)
{
if (mInstance == kInstrument) {
fprintf(stdout, "%d Release CSSStyleRule\n", mRefCnt - 1);
}
if (--mRefCnt == 0) {
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
#else
1998-04-13 20:24:54 +00:00
NS_IMPL_ADDREF(CSSStyleRuleImpl)
NS_IMPL_RELEASE(CSSStyleRuleImpl)
#endif
1998-04-13 20:24:54 +00:00
nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kICSSStyleRuleIID)) {
*aInstancePtrResult = (void*) ((nsICSSStyleRule*)this);
NS_ADDREF_THIS();
1998-04-13 20:24:54 +00:00
return NS_OK;
}
if (aIID.Equals(kIStyleRuleIID)) {
*aInstancePtrResult = (void*) ((nsIStyleRule*)this);
NS_ADDREF_THIS();
1998-04-13 20:24:54 +00:00
return NS_OK;
}
1998-11-26 01:34:53 +00:00
if (aIID.Equals(kIDOMCSSRuleIID)) {
nsIDOMCSSRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
1998-11-26 01:34:53 +00:00
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
1998-04-13 20:24:54 +00:00
if (aIID.Equals(kISupportsIID)) {
nsICSSStyleRule *tmp = this;
nsISupports *tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
1998-04-13 20:24:54 +00:00
return NS_OK;
}
return NS_NOINTERFACE;
}
1998-09-02 02:09:43 +00:00
NS_IMETHODIMP CSSStyleRuleImpl::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
1998-04-13 20:24:54 +00:00
{
nsICSSStyleRule* iCSSRule;
if (this == aRule) {
1998-09-02 02:09:43 +00:00
aResult = PR_TRUE;
1998-04-13 20:24:54 +00:00
}
1998-09-02 02:09:43 +00:00
else {
aResult = PR_FALSE;
if ((nsnull != aRule) &&
(NS_OK == ((nsIStyleRule*)aRule)->QueryInterface(kICSSStyleRuleIID, (void**) &iCSSRule))) {
CSSStyleRuleImpl* rule = (CSSStyleRuleImpl*)iCSSRule;
const nsCSSSelector* local = &mSelector;
const nsCSSSelector* other = &(rule->mSelector);
aResult = PR_TRUE;
if ((rule->mDeclaration != mDeclaration) ||
(rule->mWeight != mWeight)) {
aResult = PR_FALSE;
1998-04-13 20:24:54 +00:00
}
1998-09-02 02:09:43 +00:00
while ((PR_TRUE == aResult) && (nsnull != local) && (nsnull != other)) {
if (! local->Equals(other)) {
aResult = PR_FALSE;
}
local = local->mNext;
other = other->mNext;
}
if ((nsnull != local) || (nsnull != other)) { // more were left
aResult = PR_FALSE;
}
NS_RELEASE(iCSSRule);
1998-04-13 20:24:54 +00:00
}
}
1998-09-02 02:09:43 +00:00
return NS_OK;
1998-04-13 20:24:54 +00:00
}
1998-09-02 02:09:43 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::HashValue(PRUint32& aValue) const
1998-04-13 20:24:54 +00:00
{
1998-09-02 02:09:43 +00:00
aValue = (PRUint32)this;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHODIMP
CSSStyleRuleImpl::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
1998-04-13 20:24:54 +00:00
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
{
return &mSelector;
}
void CSSStyleRuleImpl::AddSelector(const nsCSSSelector& aSelector)
{
1998-12-11 02:50:43 +00:00
nsCSSSelector* selector = new nsCSSSelector(aSelector);
nsCSSSelector* last = &mSelector;
1998-04-13 20:24:54 +00:00
1998-12-11 02:50:43 +00:00
while (nsnull != last->mNext) {
last = last->mNext;
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
last->mNext = selector;
1998-04-13 20:24:54 +00:00
}
void CSSStyleRuleImpl::DeleteSelector(nsCSSSelector* aSelector)
{
if (nsnull != aSelector) {
if (&mSelector == aSelector) { // handle first selector
1998-12-11 02:50:43 +00:00
if (nsnull != mSelector.mNext) {
nsCSSSelector* nextOne = mSelector.mNext;
mSelector = *nextOne; // assign values
mSelector.mNext = nextOne->mNext;
delete nextOne;
}
else {
mSelector.Reset();
}
1998-04-13 20:24:54 +00:00
}
else {
nsCSSSelector* selector = &mSelector;
while (nsnull != selector->mNext) {
if (aSelector == selector->mNext) {
selector->mNext = aSelector->mNext;
delete aSelector;
return;
}
selector = selector->mNext;
}
}
}
}
1998-12-11 02:50:43 +00:00
void CSSStyleRuleImpl::SetSourceSelectorText(const nsString& aSelectorText)
{
mSelectorText = aSelectorText;
}
void CSSStyleRuleImpl::GetSourceSelectorText(nsString& aSelectorText) const
{
aSelectorText = mSelectorText;
}
1998-04-13 20:24:54 +00:00
nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
{
NS_IF_ADDREF(mDeclaration);
return mDeclaration;
}
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
{
1998-11-26 01:34:53 +00:00
if (mDeclaration != aDeclaration) {
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
}
1998-04-13 20:24:54 +00:00
}
PRInt32 CSSStyleRuleImpl::GetWeight(void) const
{
return mWeight;
}
void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
{
mWeight = aWeight;
}
nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
{
if ((nsnull == mImportantRule) && (nsnull != mDeclaration)) {
nsICSSDeclaration* important;
mDeclaration->GetImportantValues(important);
if (nsnull != important) {
1998-11-26 01:34:53 +00:00
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
NS_RELEASE(important);
}
}
NS_IF_ADDREF(mImportantRule);
return mImportantRule;
}
1998-11-26 01:34:53 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
1998-11-26 01:34:53 +00:00
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
1998-11-26 01:34:53 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
1998-11-26 01:34:53 +00:00
// We don't reference count this up reference. The style sheet
// will tell us when it's going away or when we're detached from
// it.
1998-11-26 01:34:53 +00:00
mSheet = aSheet;
if (nsnull != mImportantRule) { // we're responsible for this guy too
mImportantRule->mSheet = aSheet;
}
return NS_OK;
}
nscoord CalcLength(const nsCSSValue& aValue,
const nsStyleFont* aFont,
nsIPresContext* aPresContext)
1998-04-13 20:24:54 +00:00
{
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
if (aValue.IsFixedLengthUnit()) {
return aValue.GetLengthTwips();
}
nsCSSUnit unit = aValue.GetUnit();
switch (unit) {
case eCSSUnit_EM:
return NSToCoordRound(aValue.GetFloatValue() * (float)aFont->mFont.size);
// XXX scale against font metrics height instead
1998-04-13 20:24:54 +00:00
case eCSSUnit_EN:
return NSToCoordRound((aValue.GetFloatValue() * (float)aFont->mFont.size) / 2.0f);
case eCSSUnit_XHeight: {
nsIFontMetrics* fm = aPresContext->GetMetricsFor(aFont->mFont);
NS_ASSERTION(nsnull != fm, "can't get font metrics");
nscoord xHeight;
if (nsnull != fm) {
fm->GetXHeight(xHeight);
NS_RELEASE(fm);
}
else {
xHeight = ((aFont->mFont.size / 3) * 2);
}
return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight);
}
case eCSSUnit_CapHeight: {
1998-04-13 20:24:54 +00:00
NS_NOTYETIMPLEMENTED("cap height unit");
nscoord capHeight = ((aFont->mFont.size / 3) * 2); // XXX HACK!
return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight);
}
1998-04-13 20:24:54 +00:00
case eCSSUnit_Pixel:
1998-11-14 01:52:27 +00:00
float p2t;
aPresContext->GetScaledPixelsToTwips(p2t);
return NSFloatPixelsToTwips(aValue.GetFloatValue(), p2t);
1998-04-13 20:24:54 +00:00
}
return 0;
}
#define SETCOORD_NORMAL 0x01
#define SETCOORD_AUTO 0x02
#define SETCOORD_INHERIT 0x04
#define SETCOORD_PERCENT 0x08
#define SETCOORD_FACTOR 0x10
#define SETCOORD_LENGTH 0x20
#define SETCOORD_INTEGER 0x40
#define SETCOORD_ENUMERATED 0x80
#define SETCOORD_LP (SETCOORD_LENGTH | SETCOORD_PERCENT)
#define SETCOORD_LH (SETCOORD_LENGTH | SETCOORD_INHERIT)
#define SETCOORD_AH (SETCOORD_AUTO | SETCOORD_INHERIT)
#define SETCOORD_LPH (SETCOORD_LP | SETCOORD_INHERIT)
#define SETCOORD_LPFHN (SETCOORD_LPH | SETCOORD_FACTOR | SETCOORD_NORMAL)
#define SETCOORD_LPAH (SETCOORD_LP | SETCOORD_AH)
#define SETCOORD_LPEH (SETCOORD_LP | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
#define SETCOORD_LEH (SETCOORD_LENGTH | SETCOORD_ENUMERATED | SETCOORD_INHERIT)
#define SETCOORD_IAH (SETCOORD_INTEGER | SETCOORD_AH)
static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord,
PRInt32 aMask, const nsStyleFont* aFont,
nsIPresContext* aPresContext)
1998-04-30 19:57:36 +00:00
{
PRBool result = PR_TRUE;
if (aValue.GetUnit() == eCSSUnit_Null) {
result = PR_FALSE;
}
else if (((aMask & SETCOORD_LENGTH) != 0) &&
aValue.IsLengthUnit()) {
1998-04-30 19:57:36 +00:00
aCoord.SetCoordValue(CalcLength(aValue, aFont, aPresContext));
}
else if (((aMask & SETCOORD_PERCENT) != 0) &&
(aValue.GetUnit() == eCSSUnit_Percent)) {
aCoord.SetPercentValue(aValue.GetPercentValue());
}
else if (((aMask & SETCOORD_INTEGER) != 0) &&
(aValue.GetUnit() == eCSSUnit_Integer)) {
aCoord.SetIntValue(aValue.GetIntValue(), eStyleUnit_Integer);
}
else if (((aMask & SETCOORD_ENUMERATED) != 0) &&
(aValue.GetUnit() == eCSSUnit_Enumerated)) {
aCoord.SetIntValue(aValue.GetIntValue(), eStyleUnit_Enumerated);
}
else if (((aMask & SETCOORD_AUTO) != 0) &&
(aValue.GetUnit() == eCSSUnit_Auto)) {
aCoord.SetAutoValue();
}
else if (((aMask & SETCOORD_INHERIT) != 0) &&
(aValue.GetUnit() == eCSSUnit_Inherit)) {
aCoord.SetInheritValue();
}
else if (((aMask & SETCOORD_NORMAL) != 0) &&
(aValue.GetUnit() == eCSSUnit_Normal)) {
aCoord.SetNormalValue();
}
else if (((aMask & SETCOORD_FACTOR) != 0) &&
(aValue.GetUnit() == eCSSUnit_Number)) {
aCoord.SetFactorValue(aValue.GetFloatValue());
}
else {
result = PR_FALSE; // didn't set anything
}
return result;
1998-04-30 19:57:36 +00:00
}
static PRBool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, nscolor& aResult)
{
PRBool result = PR_FALSE;
nsCSSUnit unit = aValue.GetUnit();
if (eCSSUnit_Color == unit) {
aResult = aValue.GetColorValue();
result = PR_TRUE;
}
else if (eCSSUnit_String == unit) {
nsAutoString value;
char cbuf[100];
aValue.GetStringValue(value);
value.ToCString(cbuf, sizeof(cbuf));
nscolor rgba;
if (NS_ColorNameToRGB(cbuf, &rgba)) {
aResult = rgba;
result = PR_TRUE;
}
}
return result;
}
1998-09-02 02:09:43 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
1998-04-13 20:24:54 +00:00
{
MapDeclarationInto(mDeclaration, aContext, aPresContext);
return NS_OK;
}
void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
nsIStyleContext* aContext, nsIPresContext* aPresContext)
{
if (nsnull != aDeclaration) {
nsIStyleContext* parentContext = aContext->GetParent();
1998-06-05 06:09:09 +00:00
nsStyleFont* font = (nsStyleFont*)aContext->GetMutableStyleData(eStyleStruct_Font);
const nsStyleFont* parentFont = font;
if (nsnull != parentContext) {
parentFont = (const nsStyleFont*)parentContext->GetStyleData(eStyleStruct_Font);
}
1998-04-13 20:24:54 +00:00
nsCSSFont* ourFont;
if (NS_OK == aDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
1998-04-13 20:24:54 +00:00
if (nsnull != ourFont) {
1998-08-07 02:16:38 +00:00
const nsFont& defaultFont = aPresContext->GetDefaultFont();
const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFont();
1998-04-13 20:24:54 +00:00
// font-family: string list, enum, inherit
if (eCSSUnit_String == ourFont->mFamily.GetUnit()) {
1998-08-07 02:16:38 +00:00
nsIDeviceContext* dc = aPresContext->GetDeviceContext();
if (nsnull != dc) {
nsAutoString familyList;
ourFont->mFamily.GetStringValue(familyList);
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
if (face.EqualsIgnoreCase("monospace")) {
font->mFont = font->mFixedFont;
}
else {
font->mFixedFont.name = familyList;
}
}
else {
font->mFont.name = defaultFont.name;
font->mFixedFont.name = defaultFixedFont.name;
}
font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT;
NS_RELEASE(dc);
1998-04-13 20:24:54 +00:00
}
}
else if (eCSSUnit_Enumerated == ourFont->mFamily.GetUnit()) {
NS_NOTYETIMPLEMENTED("system font");
}
else if (eCSSUnit_Inherit == ourFont->mFamily.GetUnit()) {
font->mFont.name = parentFont->mFont.name;
font->mFixedFont.name = parentFont->mFixedFont.name;
font->mFlags &= ~NS_STYLE_FONT_FACE_EXPLICIT;
font->mFlags |= (parentFont->mFlags & NS_STYLE_FONT_FACE_EXPLICIT);
}
1998-04-13 20:24:54 +00:00
// font-style: enum, normal, inherit
if (eCSSUnit_Enumerated == ourFont->mStyle.GetUnit()) {
1998-04-13 20:24:54 +00:00
font->mFont.style = ourFont->mStyle.GetIntValue();
font->mFixedFont.style = ourFont->mStyle.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Normal == ourFont->mStyle.GetUnit()) {
font->mFont.style = NS_STYLE_FONT_STYLE_NORMAL;
font->mFixedFont.style = NS_STYLE_FONT_STYLE_NORMAL;
}
else if (eCSSUnit_Inherit == ourFont->mStyle.GetUnit()) {
font->mFont.style = parentFont->mFont.style;
font->mFixedFont.style = parentFont->mFixedFont.style;
}
1998-04-13 20:24:54 +00:00
// font-variant: enum, normal, inherit
if (eCSSUnit_Enumerated == ourFont->mVariant.GetUnit()) {
1998-04-13 20:24:54 +00:00
font->mFont.variant = ourFont->mVariant.GetIntValue();
font->mFixedFont.variant = ourFont->mVariant.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Normal == ourFont->mVariant.GetUnit()) {
font->mFont.variant = NS_STYLE_FONT_VARIANT_NORMAL;
font->mFixedFont.variant = NS_STYLE_FONT_VARIANT_NORMAL;
}
else if (eCSSUnit_Inherit == ourFont->mVariant.GetUnit()) {
font->mFont.variant = parentFont->mFont.variant;
font->mFixedFont.variant = parentFont->mFixedFont.variant;
}
1998-04-13 20:24:54 +00:00
// font-weight: int, enum, normal, inherit
if (eCSSUnit_Integer == ourFont->mWeight.GetUnit()) {
font->mFont.weight = ourFont->mWeight.GetIntValue();
font->mFixedFont.weight = ourFont->mWeight.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Enumerated == ourFont->mWeight.GetUnit()) {
1998-04-13 20:24:54 +00:00
PRInt32 value = ourFont->mWeight.GetIntValue();
switch (value) {
case NS_STYLE_FONT_WEIGHT_NORMAL:
case NS_STYLE_FONT_WEIGHT_BOLD:
font->mFont.weight = value;
font->mFixedFont.weight = value;
1998-04-13 20:24:54 +00:00
break;
case NS_STYLE_FONT_WEIGHT_BOLDER:
case NS_STYLE_FONT_WEIGHT_LIGHTER:
font->mFont.weight = (parentFont->mFont.weight + value);
1998-07-17 05:49:03 +00:00
font->mFixedFont.weight = (parentFont->mFixedFont.weight + value);
1998-04-13 20:24:54 +00:00
break;
}
}
else if (eCSSUnit_Normal == ourFont->mWeight.GetUnit()) {
font->mFont.weight = NS_STYLE_FONT_WEIGHT_NORMAL;
font->mFixedFont.weight = NS_STYLE_FONT_WEIGHT_NORMAL;
}
else if (eCSSUnit_Inherit == ourFont->mWeight.GetUnit()) {
font->mFont.weight = parentFont->mFont.weight;
font->mFixedFont.weight = parentFont->mFixedFont.weight;
}
1998-04-13 20:24:54 +00:00
// font-size: enum, length, percent, inherit
if (eCSSUnit_Enumerated == ourFont->mSize.GetUnit()) {
1998-04-13 20:24:54 +00:00
PRInt32 value = ourFont->mSize.GetIntValue();
1998-11-26 18:14:41 +00:00
PRInt32 scaler;
aPresContext->GetFontScaler(scaler);
1998-07-25 01:22:10 +00:00
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
1998-04-13 20:24:54 +00:00
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
1998-10-13 19:13:59 +00:00
font->mFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFont.size, scaleFactor);
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFixedFont.size, scaleFactor);
1998-04-13 20:24:54 +00:00
}
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
1998-08-07 02:16:38 +00:00
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor);
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor);
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor);
1998-04-13 20:24:54 +00:00
}
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
1998-08-07 02:16:38 +00:00
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor);
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor);
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor);
1998-04-13 20:24:54 +00:00
}
// this does NOT explicitly set font size
font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT;
1998-04-13 20:24:54 +00:00
}
else if (ourFont->mSize.IsLengthUnit()) {
font->mFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);
font->mFixedFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);
font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Percent == ourFont->mSize.GetUnit()) {
1998-04-30 19:57:36 +00:00
font->mFont.size = (nscoord)((float)(parentFont->mFont.size) * ourFont->mSize.GetPercentValue());
1998-07-17 05:49:03 +00:00
font->mFixedFont.size = (nscoord)((float)(parentFont->mFixedFont.size) * ourFont->mSize.GetPercentValue());
font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Inherit == ourFont->mSize.GetUnit()) {
font->mFont.size = parentFont->mFont.size;
font->mFixedFont.size = parentFont->mFixedFont.size;
font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT;
font->mFlags |= (parentFont->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT);
}
1998-04-13 20:24:54 +00:00
}
}
nsCSSText* ourText;
if (NS_OK == aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
1998-04-13 20:24:54 +00:00
if (nsnull != ourText) {
// Get our text style and our parent's text style
1998-06-05 06:09:09 +00:00
nsStyleText* text = (nsStyleText*) aContext->GetMutableStyleData(eStyleStruct_Text);
const nsStyleText* parentText = text;
if (nsnull != parentContext) {
parentText = (const nsStyleText*)parentContext->GetStyleData(eStyleStruct_Text);
}
// letter-spacing: normal, length, inherit
1998-04-30 19:57:36 +00:00
SetCoord(ourText->mLetterSpacing, text->mLetterSpacing, SETCOORD_LH | SETCOORD_NORMAL,
font, aPresContext);
// line-height: normal, number, length, percent, inherit
SetCoord(ourText->mLineHeight, text->mLineHeight, SETCOORD_LPFHN, font, aPresContext);
// text-align: enum, string, inherit
if (eCSSUnit_Enumerated == ourText->mTextAlign.GetUnit()) {
text->mTextAlign = ourText->mTextAlign.GetIntValue();
}
else if (eCSSUnit_String == ourText->mTextAlign.GetUnit()) {
NS_NOTYETIMPLEMENTED("align string");
}
else if (eCSSUnit_Inherit == ourText->mTextAlign.GetUnit()) {
text->mTextAlign = parentText->mTextAlign;
}
// text-indent: length, percent, inherit
1998-04-30 19:57:36 +00:00
SetCoord(ourText->mTextIndent, text->mTextIndent, SETCOORD_LPH, font, aPresContext);
1998-04-13 20:24:54 +00:00
// text-decoration: none, enum (bit field), inherit
if (eCSSUnit_Enumerated == ourText->mDecoration.GetUnit()) {
PRInt32 td = ourText->mDecoration.GetIntValue();
1998-11-06 01:06:26 +00:00
font->mFont.decorations = (parentFont->mFont.decorations | td);
font->mFixedFont.decorations = (parentFont->mFixedFont.decorations | td);
text->mTextDecoration = td;
}
else if (eCSSUnit_None == ourText->mDecoration.GetUnit()) {
1998-12-11 02:50:43 +00:00
font->mFont.decorations = parentFont->mFont.decorations;
font->mFixedFont.decorations = parentFont->mFixedFont.decorations;
text->mTextDecoration = NS_STYLE_TEXT_DECORATION_NONE;
}
else if (eCSSUnit_Inherit == ourText->mDecoration.GetUnit()) {
font->mFont.decorations = parentFont->mFont.decorations;
font->mFixedFont.decorations = parentFont->mFixedFont.decorations;
text->mTextDecoration = parentText->mTextDecoration;
}
// text-transform: enum, none, inherit
if (eCSSUnit_Enumerated == ourText->mTextTransform.GetUnit()) {
text->mTextTransform = ourText->mTextTransform.GetIntValue();
}
else if (eCSSUnit_None == ourText->mTextTransform.GetUnit()) {
text->mTextTransform = NS_STYLE_TEXT_TRANSFORM_NONE;
}
else if (eCSSUnit_Inherit == ourText->mTextTransform.GetUnit()) {
text->mTextTransform = parentText->mTextTransform;
}
// vertical-align: enum, length, percent, inherit
if (! SetCoord(ourText->mVerticalAlign, text->mVerticalAlign, SETCOORD_LP | SETCOORD_ENUMERATED,
font, aPresContext)) {
// XXX this really needs to pass the inherit value along...
if (eCSSUnit_Inherit == ourText->mVerticalAlign.GetUnit()) {
text->mVerticalAlign = parentText->mVerticalAlign;
}
}
// white-space: enum, normal, inherit
if (eCSSUnit_Enumerated == ourText->mWhiteSpace.GetUnit()) {
text->mWhiteSpace = ourText->mWhiteSpace.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Normal == ourText->mWhiteSpace.GetUnit()) {
text->mWhiteSpace = NS_STYLE_WHITESPACE_NORMAL;
}
else if (eCSSUnit_Inherit == ourText->mWhiteSpace.GetUnit()) {
text->mWhiteSpace = parentText->mWhiteSpace;
}
// word-spacing: normal, length, inherit
1998-04-30 19:57:36 +00:00
SetCoord(ourText->mWordSpacing, text->mWordSpacing, SETCOORD_LH | SETCOORD_NORMAL,
font, aPresContext);
}
}
nsCSSDisplay* ourDisplay;
if (NS_OK == aDeclaration->GetData(kCSSDisplaySID, (nsCSSStruct**)&ourDisplay)) {
if (nsnull != ourDisplay) {
// Get our style and our parent's style
nsStyleDisplay* display = (nsStyleDisplay*)
1998-06-05 06:09:09 +00:00
aContext->GetMutableStyleData(eStyleStruct_Display);
1998-06-05 06:09:09 +00:00
const nsStyleDisplay* parentDisplay = display;
1998-05-26 23:16:55 +00:00
if (nsnull != parentContext) {
1998-06-05 06:09:09 +00:00
parentDisplay = (const nsStyleDisplay*)parentContext->GetStyleData(eStyleStruct_Display);
1998-05-26 23:16:55 +00:00
}
// display: enum, none, inherit
if (eCSSUnit_Enumerated == ourDisplay->mDisplay.GetUnit()) {
display->mDisplay = ourDisplay->mDisplay.GetIntValue();
}
else if (eCSSUnit_None == ourDisplay->mDisplay.GetUnit()) {
display->mDisplay = NS_STYLE_DISPLAY_NONE;
}
else if (eCSSUnit_Inherit == ourDisplay->mDisplay.GetUnit()) {
display->mDisplay = parentDisplay->mDisplay;
}
// direction: enum, inherit
if (eCSSUnit_Enumerated == ourDisplay->mDirection.GetUnit()) {
display->mDirection = ourDisplay->mDirection.GetIntValue();
}
else if (eCSSUnit_Inherit == ourDisplay->mDirection.GetUnit()) {
display->mDirection = parentDisplay->mDirection;
}
// clear: enum, none, inherit
if (eCSSUnit_Enumerated == ourDisplay->mClear.GetUnit()) {
display->mBreakType = ourDisplay->mClear.GetIntValue();
}
else if (eCSSUnit_None == ourDisplay->mClear.GetUnit()) {
display->mBreakType = NS_STYLE_CLEAR_NONE;
}
else if (eCSSUnit_Inherit == ourDisplay->mClear.GetUnit()) {
display->mBreakType = parentDisplay->mBreakType;
}
// float: enum, none, inherit
if (eCSSUnit_Enumerated == ourDisplay->mFloat.GetUnit()) {
display->mFloats = ourDisplay->mFloat.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_None == ourDisplay->mFloat.GetUnit()) {
display->mFloats = NS_STYLE_FLOAT_NONE;
}
else if (eCSSUnit_Inherit == ourDisplay->mFloat.GetUnit()) {
display->mFloats = parentDisplay->mFloats;
}
1998-05-26 23:16:55 +00:00
// visibility: enum, inherit
if (eCSSUnit_Enumerated == ourDisplay->mVisibility.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mVisible = PRBool (NS_STYLE_VISIBILITY_VISIBLE == ourDisplay->mVisibility.GetIntValue());
}
else if (eCSSUnit_Inherit == ourDisplay->mVisibility.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mVisible = parentDisplay->mVisible;
}
// overflow: enum, auto, inherit
if (eCSSUnit_Enumerated == ourDisplay->mOverflow.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mOverflow = ourDisplay->mOverflow.GetIntValue();
}
else if (eCSSUnit_Auto == ourDisplay->mOverflow.GetUnit()) {
display->mOverflow = NS_STYLE_OVERFLOW_AUTO;
}
else if (eCSSUnit_Inherit == ourDisplay->mOverflow.GetUnit()) {
display->mOverflow = parentDisplay->mOverflow;
}
1998-05-26 23:16:55 +00:00
// clip property: length, auto, inherit
if (nsnull != ourDisplay->mClip) {
if (eCSSUnit_Inherit == ourDisplay->mClip->mTop.GetUnit()) { // if one is inherit, they all are
1998-05-26 23:16:55 +00:00
display->mClipFlags = NS_STYLE_CLIP_INHERIT;
}
else {
PRBool fullAuto = PR_TRUE;
display->mClipFlags = 0; // clear it
if (eCSSUnit_Auto == ourDisplay->mClip->mTop.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.top = 0;
display->mClipFlags |= NS_STYLE_CLIP_TOP_AUTO;
}
else if (ourDisplay->mClip->mTop.IsLengthUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.top = CalcLength(ourDisplay->mClip->mTop, font, aPresContext);
fullAuto = PR_FALSE;
}
if (eCSSUnit_Auto == ourDisplay->mClip->mRight.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.right = 0;
display->mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO;
}
else if (ourDisplay->mClip->mRight.IsLengthUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.right = CalcLength(ourDisplay->mClip->mRight, font, aPresContext);
fullAuto = PR_FALSE;
}
if (eCSSUnit_Auto == ourDisplay->mClip->mBottom.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.bottom = 0;
display->mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO;
}
else if (ourDisplay->mClip->mBottom.IsLengthUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.bottom = CalcLength(ourDisplay->mClip->mBottom, font, aPresContext);
fullAuto = PR_FALSE;
}
if (eCSSUnit_Auto == ourDisplay->mClip->mLeft.GetUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.left = 0;
display->mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO;
}
else if (ourDisplay->mClip->mLeft.IsLengthUnit()) {
1998-05-26 23:16:55 +00:00
display->mClip.left = CalcLength(ourDisplay->mClip->mLeft, font, aPresContext);
fullAuto = PR_FALSE;
}
display->mClipFlags &= ~NS_STYLE_CLIP_TYPE_MASK;
if (fullAuto) {
display->mClipFlags |= NS_STYLE_CLIP_AUTO;
}
else {
display->mClipFlags |= NS_STYLE_CLIP_RECT;
}
}
}
1998-04-13 20:24:54 +00:00
}
}
nsCSSColor* ourColor;
if (NS_OK == aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
1998-04-13 20:24:54 +00:00
if (nsnull != ourColor) {
1998-06-05 06:09:09 +00:00
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
1998-04-13 20:24:54 +00:00
const nsStyleColor* parentColor = color;
if (nsnull != parentContext) {
parentColor = (const nsStyleColor*)parentContext->GetStyleData(eStyleStruct_Color);
1998-04-13 20:24:54 +00:00
}
// color: color, string, inherit
if (! SetColor(ourColor->mColor, parentColor->mColor, color->mColor)) {
if (eCSSUnit_Inherit == ourColor->mColor.GetUnit()) {
color->mColor = parentColor->mColor;
}
}
// cursor: enum, auto, url, inherit
nsCSSValueList* list = ourColor->mCursor;
if (nsnull != list) {
// XXX need to deal with multiple URL values
if (eCSSUnit_Enumerated == list->mValue.GetUnit()) {
color->mCursor = list->mValue.GetIntValue();
}
else if (eCSSUnit_Auto == list->mValue.GetUnit()) {
color->mCursor = NS_STYLE_CURSOR_AUTO;
}
else if (eCSSUnit_URL == list->mValue.GetUnit()) {
list->mValue.GetStringValue(color->mCursorImage);
}
else if (eCSSUnit_Inherit == list->mValue.GetUnit()) {
1998-11-18 02:11:54 +00:00
color->mCursor = parentColor->mCursor;
}
}
// background-color: color, string, enum (flags), inherit
if (SetColor(ourColor->mBackColor, parentColor->mBackgroundColor, color->mBackgroundColor)) {
1998-04-13 20:24:54 +00:00
color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
}
else if (eCSSUnit_Enumerated == ourColor->mBackColor.GetUnit()) {
1998-04-13 20:24:54 +00:00
color->mBackgroundFlags |= NS_STYLE_BG_COLOR_TRANSPARENT;
}
else if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) {
color->mBackgroundColor = parentColor->mBackgroundColor;
color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT);
}
1998-04-13 20:24:54 +00:00
// background-image: url, none, inherit
if (eCSSUnit_URL == ourColor->mBackImage.GetUnit()) {
1998-04-13 20:24:54 +00:00
ourColor->mBackImage.GetStringValue(color->mBackgroundImage);
color->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE;
}
else if (eCSSUnit_None == ourColor->mBackImage.GetUnit()) {
1998-04-30 19:57:36 +00:00
color->mBackgroundImage.Truncate();
1998-04-13 20:24:54 +00:00
color->mBackgroundFlags |= NS_STYLE_BG_IMAGE_NONE;
}
else if (eCSSUnit_Inherit == ourColor->mBackImage.GetUnit()) {
color->mBackgroundImage = parentColor->mBackgroundImage;
color->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE);
}
1998-04-13 20:24:54 +00:00
// background-repeat: enum, inherit
if (eCSSUnit_Enumerated == ourColor->mBackRepeat.GetUnit()) {
1998-04-13 20:24:54 +00:00
color->mBackgroundRepeat = ourColor->mBackRepeat.GetIntValue();
}
else if (eCSSUnit_Inherit == ourColor->mBackRepeat.GetUnit()) {
color->mBackgroundRepeat = parentColor->mBackgroundRepeat;
}
1998-04-13 20:24:54 +00:00
// background-attachment: enum, inherit
if (eCSSUnit_Enumerated == ourColor->mBackAttachment.GetUnit()) {
1998-04-13 20:24:54 +00:00
color->mBackgroundAttachment = ourColor->mBackAttachment.GetIntValue();
}
else if (eCSSUnit_Inherit == ourColor->mBackAttachment.GetUnit()) {
color->mBackgroundAttachment = parentColor->mBackgroundAttachment;
}
1998-04-13 20:24:54 +00:00
// background-position: enum, length, percent (flags), inherit
if (eCSSUnit_Percent == ourColor->mBackPositionX.GetUnit()) {
1998-04-30 19:57:36 +00:00
color->mBackgroundXPosition = (nscoord)(100.0f * ourColor->mBackPositionX.GetPercentValue());
color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT;
1998-04-13 20:24:54 +00:00
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
}
else if (ourColor->mBackPositionX.IsLengthUnit()) {
color->mBackgroundXPosition = CalcLength(ourColor->mBackPositionX,
font, aPresContext);
color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_LENGTH;
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_PERCENT;
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Enumerated == ourColor->mBackPositionX.GetUnit()) {
color->mBackgroundXPosition = (nscoord)ourColor->mBackPositionX.GetIntValue();
color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT;
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionX.GetUnit()) {
color->mBackgroundXPosition = parentColor->mBackgroundXPosition;
1998-11-26 01:34:53 +00:00
color->mBackgroundFlags &= ~(NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT));
}
if (eCSSUnit_Percent == ourColor->mBackPositionY.GetUnit()) {
1998-04-30 19:57:36 +00:00
color->mBackgroundYPosition = (nscoord)(100.0f * ourColor->mBackPositionY.GetPercentValue());
color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT;
1998-04-13 20:24:54 +00:00
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
}
else if (ourColor->mBackPositionY.IsLengthUnit()) {
color->mBackgroundYPosition = CalcLength(ourColor->mBackPositionY,
font, aPresContext);
color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_LENGTH;
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_PERCENT;
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Enumerated == ourColor->mBackPositionY.GetUnit()) {
color->mBackgroundYPosition = (nscoord)ourColor->mBackPositionY.GetIntValue();
color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT;
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionY.GetUnit()) {
color->mBackgroundYPosition = parentColor->mBackgroundYPosition;
1998-11-26 01:34:53 +00:00
color->mBackgroundFlags &= ~(NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT));
}
1998-04-13 20:24:54 +00:00
// opacity: factor, percent, inherit
if (eCSSUnit_Percent == ourColor->mOpacity.GetUnit()) {
color->mOpacity = ourColor->mOpacity.GetPercentValue();
}
else if (eCSSUnit_Number == ourColor->mOpacity.GetUnit()) {
color->mOpacity = ourColor->mOpacity.GetFloatValue();
}
else if (eCSSUnit_Inherit == ourColor->mOpacity.GetUnit()) {
color->mOpacity = parentColor->mOpacity;
}
1998-04-13 20:24:54 +00:00
// XXX: NYI nsCSSValue mBackFilter;
}
}
nsCSSMargin* ourMargin;
if (NS_OK == aDeclaration->GetData(kCSSMarginSID, (nsCSSStruct**)&ourMargin)) {
if (nsnull != ourMargin) {
nsStyleSpacing* spacing = (nsStyleSpacing*)
1998-06-05 06:09:09 +00:00
aContext->GetMutableStyleData(eStyleStruct_Spacing);
const nsStyleSpacing* parentSpacing = spacing;
if (nsnull != parentContext) {
parentSpacing = (const nsStyleSpacing*)parentContext->GetStyleData(eStyleStruct_Spacing);
}
// margin: length, percent, auto, inherit
if (nsnull != ourMargin->mMargin) {
nsStyleCoord coord;
if (SetCoord(ourMargin->mMargin->mLeft, coord, SETCOORD_LPAH, font, aPresContext)) {
spacing->mMargin.SetLeft(coord);
}
if (SetCoord(ourMargin->mMargin->mTop, coord, SETCOORD_LPAH, font, aPresContext)) {
spacing->mMargin.SetTop(coord);
}
if (SetCoord(ourMargin->mMargin->mRight, coord, SETCOORD_LPAH, font, aPresContext)) {
spacing->mMargin.SetRight(coord);
}
if (SetCoord(ourMargin->mMargin->mBottom, coord, SETCOORD_LPAH, font, aPresContext)) {
spacing->mMargin.SetBottom(coord);
}
}
// padding: length, percent, inherit
if (nsnull != ourMargin->mPadding) {
nsStyleCoord coord;
if (SetCoord(ourMargin->mPadding->mLeft, coord, SETCOORD_LPH, font, aPresContext)) {
spacing->mPadding.SetLeft(coord);
}
if (SetCoord(ourMargin->mPadding->mTop, coord, SETCOORD_LPH, font, aPresContext)) {
spacing->mPadding.SetTop(coord);
}
if (SetCoord(ourMargin->mPadding->mRight, coord, SETCOORD_LPH, font, aPresContext)) {
spacing->mPadding.SetRight(coord);
}
if (SetCoord(ourMargin->mPadding->mBottom, coord, SETCOORD_LPH, font, aPresContext)) {
spacing->mPadding.SetBottom(coord);
}
}
// border-size: length, enum, inherit
1998-10-08 01:31:38 +00:00
if (nsnull != ourMargin->mBorderWidth) {
nsStyleCoord coord;
if (SetCoord(ourMargin->mBorderWidth->mLeft, coord, SETCOORD_LEH, font, aPresContext)) {
spacing->mBorder.SetLeft(coord);
}
if (SetCoord(ourMargin->mBorderWidth->mTop, coord, SETCOORD_LEH, font, aPresContext)) {
spacing->mBorder.SetTop(coord);
}
if (SetCoord(ourMargin->mBorderWidth->mRight, coord, SETCOORD_LEH, font, aPresContext)) {
spacing->mBorder.SetRight(coord);
}
if (SetCoord(ourMargin->mBorderWidth->mBottom, coord, SETCOORD_LEH, font, aPresContext)) {
spacing->mBorder.SetBottom(coord);
}
}
// border-style: enum, none, inhert
1998-10-08 01:31:38 +00:00
if (nsnull != ourMargin->mBorderStyle) {
nsCSSRect* ourStyle = ourMargin->mBorderStyle;
if (eCSSUnit_Enumerated == ourStyle->mTop.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_TOP, ourStyle->mTop.GetIntValue());
}
else if (eCSSUnit_None == ourStyle->mTop.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_TOP, NS_STYLE_BORDER_STYLE_NONE);
}
else if (eCSSUnit_Inherit == ourStyle->mTop.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_TOP, parentSpacing->GetBorderStyle(NS_SIDE_TOP));
}
if (eCSSUnit_Enumerated == ourStyle->mRight.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_RIGHT, ourStyle->mRight.GetIntValue());
}
else if (eCSSUnit_None == ourStyle->mRight.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_RIGHT, NS_STYLE_BORDER_STYLE_NONE);
}
else if (eCSSUnit_Inherit == ourStyle->mRight.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_RIGHT, parentSpacing->GetBorderStyle(NS_SIDE_RIGHT));
}
if (eCSSUnit_Enumerated == ourStyle->mBottom.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_BOTTOM, ourStyle->mBottom.GetIntValue());
}
else if (eCSSUnit_None == ourStyle->mBottom.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_BOTTOM, NS_STYLE_BORDER_STYLE_NONE);
}
else if (eCSSUnit_Inherit == ourStyle->mBottom.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_BOTTOM, parentSpacing->GetBorderStyle(NS_SIDE_BOTTOM));
}
if (eCSSUnit_Enumerated == ourStyle->mLeft.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_LEFT, ourStyle->mLeft.GetIntValue());
}
else if (eCSSUnit_None == ourStyle->mLeft.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_LEFT, NS_STYLE_BORDER_STYLE_NONE);
}
else if (eCSSUnit_Inherit == ourStyle->mLeft.GetUnit()) {
spacing->SetBorderStyle(NS_SIDE_LEFT, parentSpacing->GetBorderStyle(NS_SIDE_LEFT));
}
}
// border-color: color. string, enum, inherit
1998-10-08 01:31:38 +00:00
if (nsnull != ourMargin->mBorderColor) {
nsCSSRect* ourColor = ourMargin->mBorderColor;
nscolor aBorderColor = NS_RGBA(0,0,0,0);
if (! SetColor(ourColor->mTop, parentSpacing->GetBorderColor(NS_SIDE_TOP),
aBorderColor)) {
if (eCSSUnit_Enumerated == ourColor->mTop.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_TOP ,NS_RGBA(0, 0, 0, 0)); // transparent
}
else if (eCSSUnit_Inherit == ourColor->mTop.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_TOP, parentSpacing->GetBorderColor(NS_SIDE_TOP));
}
}
else{
spacing->SetBorderColor(NS_SIDE_TOP, aBorderColor);
}
if (! SetColor(ourColor->mRight, parentSpacing->GetBorderColor(NS_SIDE_RIGHT),
aBorderColor)) {
if (eCSSUnit_Enumerated == ourColor->mRight.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_RIGHT ,NS_RGBA(0, 0, 0, 0)); // transparent
}
else if (eCSSUnit_Inherit == ourColor->mRight.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_RIGHT, parentSpacing->GetBorderColor(NS_SIDE_RIGHT));
}
}
else{
spacing->SetBorderColor(NS_SIDE_RIGHT, aBorderColor);
}
if (! SetColor(ourColor->mBottom, parentSpacing->GetBorderColor(NS_SIDE_BOTTOM),
aBorderColor)) {
if (eCSSUnit_Enumerated == ourColor->mBottom.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_BOTTOM ,NS_RGBA(0, 0, 0, 0)); // transparent
}
else if (eCSSUnit_Inherit == ourColor->mBottom.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_BOTTOM, parentSpacing->GetBorderColor(NS_SIDE_BOTTOM));
}
}
else{
spacing->SetBorderColor(NS_SIDE_BOTTOM, aBorderColor);
}
if (! SetColor(ourColor->mLeft, parentSpacing->GetBorderColor(NS_SIDE_LEFT),
aBorderColor)) {
if (eCSSUnit_Enumerated == ourColor->mLeft.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_LEFT ,NS_RGBA(0, 0, 0, 0)); // transparent
}
else if (eCSSUnit_Inherit == ourColor->mLeft.GetUnit()) {
spacing->SetBorderColor(NS_SIDE_LEFT, parentSpacing->GetBorderColor(NS_SIDE_LEFT));
}
}
else{
spacing->SetBorderColor(NS_SIDE_LEFT, aBorderColor);
}
}
}
}
1998-04-13 20:24:54 +00:00
nsCSSPosition* ourPosition;
if (NS_OK == aDeclaration->GetData(kCSSPositionSID, (nsCSSStruct**)&ourPosition)) {
if (nsnull != ourPosition) {
1998-06-05 06:09:09 +00:00
nsStylePosition* position = (nsStylePosition*)aContext->GetMutableStyleData(eStyleStruct_Position);
const nsStylePosition* parentPosition = position;
if (nsnull != parentContext) {
parentPosition = (const nsStylePosition*)parentContext->GetStyleData(eStyleStruct_Position);
1998-05-13 22:40:17 +00:00
}
// position: enum, inherit
if (eCSSUnit_Enumerated == ourPosition->mPosition.GetUnit()) {
1998-04-22 23:28:02 +00:00
position->mPosition = ourPosition->mPosition.GetIntValue();
}
else if (eCSSUnit_Inherit == ourPosition->mPosition.GetUnit()) {
position->mPosition = parentPosition->mPosition;
1998-05-13 22:40:17 +00:00
}
1998-04-22 23:28:02 +00:00
1998-04-30 19:57:36 +00:00
// box offsets: length, percent, auto, inherit
1998-10-08 01:31:38 +00:00
if (nsnull != ourPosition->mOffset) {
SetCoord(ourPosition->mOffset->mTop, position->mTopOffset, SETCOORD_LPAH, font, aPresContext);
// XXX right bottom
SetCoord(ourPosition->mOffset->mLeft, position->mLeftOffset, SETCOORD_LPAH, font, aPresContext);
}
1998-04-30 19:57:36 +00:00
SetCoord(ourPosition->mWidth, position->mWidth, SETCOORD_LPAH, font, aPresContext);
SetCoord(ourPosition->mMinWidth, position->mWidth, SETCOORD_LPH, font, aPresContext);
if (! SetCoord(ourPosition->mMaxWidth, position->mWidth, SETCOORD_LPH, font, aPresContext)) {
if (eCSSUnit_None == ourPosition->mMaxWidth.GetUnit()) {
position->mMaxWidth.Reset();
}
}
1998-04-30 19:57:36 +00:00
SetCoord(ourPosition->mHeight, position->mHeight, SETCOORD_LPAH, font, aPresContext);
SetCoord(ourPosition->mMinHeight, position->mHeight, SETCOORD_LPH, font, aPresContext);
if (! SetCoord(ourPosition->mMaxHeight, position->mHeight, SETCOORD_LPH, font, aPresContext)) {
if (eCSSUnit_None == ourPosition->mMaxHeight.GetUnit()) {
position->mMaxHeight.Reset();
}
}
// z-index
1998-04-30 19:57:36 +00:00
SetCoord(ourPosition->mZIndex, position->mZIndex, SETCOORD_IAH, nsnull, nsnull);
}
}
1998-04-13 20:24:54 +00:00
nsCSSList* ourList;
if (NS_OK == aDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
1998-04-13 20:24:54 +00:00
if (nsnull != ourList) {
1998-06-05 06:09:09 +00:00
nsStyleList* list = (nsStyleList*)aContext->GetMutableStyleData(eStyleStruct_List);
1998-04-13 20:24:54 +00:00
const nsStyleList* parentList = list;
if (nsnull != parentContext) {
parentList = (const nsStyleList*)parentContext->GetStyleData(eStyleStruct_List);
}
// list-style-type: enum, none, inherit
if (eCSSUnit_Enumerated == ourList->mType.GetUnit()) {
1998-04-13 20:24:54 +00:00
list->mListStyleType = ourList->mType.GetIntValue();
}
else if (eCSSUnit_None == ourList->mType.GetUnit()) {
list->mListStyleType = NS_STYLE_LIST_STYLE_NONE;
}
else if (eCSSUnit_Inherit == ourList->mType.GetUnit()) {
list->mListStyleType = parentList->mListStyleType;
}
1998-04-13 20:24:54 +00:00
// list-style-image: url, none, inherit
if (eCSSUnit_URL == ourList->mImage.GetUnit()) {
1998-04-13 20:24:54 +00:00
ourList->mImage.GetStringValue(list->mListStyleImage);
}
else if (eCSSUnit_None == ourList->mImage.GetUnit()) {
list->mListStyleImage.Truncate();
}
else if (eCSSUnit_Inherit == ourList->mImage.GetUnit()) {
list->mListStyleImage = parentList->mListStyleImage;
1998-04-13 20:24:54 +00:00
}
// list-style-position: enum, inherit
if (eCSSUnit_Enumerated == ourList->mPosition.GetUnit()) {
list->mListStylePosition = ourList->mPosition.GetIntValue();
1998-04-13 20:24:54 +00:00
}
else if (eCSSUnit_Inherit == ourList->mPosition.GetUnit()) {
list->mListStylePosition = parentList->mListStylePosition;
}
1998-04-13 20:24:54 +00:00
}
}
nsCSSTable* ourTable;
if (NS_OK == aDeclaration->GetData(kCSSTableSID, (nsCSSStruct**)&ourTable)) {
if (nsnull != ourTable) {
nsStyleTable* table = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);
const nsStyleTable* parentTable = table;
if (nsnull != parentContext) {
parentTable = (const nsStyleTable*)parentContext->GetStyleData(eStyleStruct_Table);
}
nsStyleCoord coord;
// border-collapse: enum, inherit
if (eCSSUnit_Enumerated == ourTable->mBorderCollapse.GetUnit()) {
table->mBorderCollapse = ourTable->mBorderCollapse.GetIntValue();
}
else if (eCSSUnit_Inherit == ourTable->mBorderCollapse.GetUnit()) {
table->mBorderCollapse = parentTable->mBorderCollapse;
}
// border-spacing-x: length, inherit
if (SetCoord(ourTable->mBorderSpacingX, coord, SETCOORD_LENGTH, font, aPresContext)) {
table->mBorderSpacingX = coord.GetCoordValue();
}
else if (eCSSUnit_Inherit == ourTable->mBorderSpacingX.GetUnit()) {
table->mBorderSpacingX = parentTable->mBorderSpacingX;
}
// border-spacing-y: length, inherit
if (SetCoord(ourTable->mBorderSpacingY, coord, SETCOORD_LENGTH, font, aPresContext)) {
table->mBorderSpacingY = coord.GetCoordValue();
}
else if (eCSSUnit_Inherit == ourTable->mBorderSpacingY.GetUnit()) {
table->mBorderSpacingY = parentTable->mBorderSpacingY;
}
// caption-side: enum, inherit
if (eCSSUnit_Enumerated == ourTable->mCaptionSide.GetUnit()) {
table->mCaptionSide = ourTable->mCaptionSide.GetIntValue();
}
else if (eCSSUnit_Inherit == ourTable->mCaptionSide.GetUnit()) {
table->mCaptionSide = parentTable->mCaptionSide;
}
// empty-cells: enum, inherit
if (eCSSUnit_Enumerated == ourTable->mEmptyCells.GetUnit()) {
table->mEmptyCells = ourTable->mEmptyCells.GetIntValue();
}
else if (eCSSUnit_Inherit == ourTable->mEmptyCells.GetUnit()) {
table->mEmptyCells = parentTable->mEmptyCells;
}
// table-layout: auto, enum, inherit
if (eCSSUnit_Enumerated == ourTable->mLayout.GetUnit()) {
table->mLayoutStrategy = ourTable->mLayout.GetIntValue();
}
else if (eCSSUnit_Auto == ourTable->mLayout.GetUnit()) {
table->mLayoutStrategy = NS_STYLE_TABLE_LAYOUT_AUTO;
}
else if (eCSSUnit_Inherit == ourTable->mLayout.GetUnit()) {
table->mLayoutStrategy = parentTable->mLayoutStrategy;
}
}
}
NS_IF_RELEASE(parentContext);
1998-04-13 20:24:54 +00:00
}
}
static void ListSelector(FILE* out, const nsCSSSelector* aSelector)
{
nsAutoString buffer;
1998-12-11 02:50:43 +00:00
if (kNameSpaceID_None < aSelector->mNameSpace) {
buffer.Append(aSelector->mNameSpace, 10);
fputs(buffer, out);
fputs("\\:", out);
}
1998-04-13 20:24:54 +00:00
if (nsnull != aSelector->mTag) {
aSelector->mTag->ToString(buffer);
fputs(buffer, out);
}
if (nsnull != aSelector->mID) {
aSelector->mID->ToString(buffer);
fputs("#", out);
fputs(buffer, out);
}
1998-12-11 02:50:43 +00:00
nsAtomList* list = aSelector->mClassList;
while (nsnull != list) {
list->mAtom->ToString(buffer);
1998-04-13 20:24:54 +00:00
fputs(".", out);
fputs(buffer, out);
1998-12-11 02:50:43 +00:00
list = list->mNext;
1998-04-13 20:24:54 +00:00
}
1998-12-11 02:50:43 +00:00
list = aSelector->mPseudoClassList;
while (nsnull != list) {
list->mAtom->ToString(buffer);
1998-04-13 20:24:54 +00:00
fputs(":", out);
fputs(buffer, out);
1998-12-11 02:50:43 +00:00
list = list->mNext;
}
nsAttrSelector* attr = aSelector->mAttrList;
while (nsnull != attr) {
fputs("[", out);
attr->mAttr->ToString(buffer);
fputs(buffer, out);
if (NS_ATTR_FUNC_SET != attr->mFunction) {
switch (attr->mFunction) {
case NS_ATTR_FUNC_EQUALS: fputs("=", out); break;
case NS_ATTR_FUNC_INCLUDES: fputs("~=", out); break;
case NS_ATTR_FUNC_DASHMATCH: fputs("|=", out); break;
}
fputs(attr->mValue, out);
}
fputs("]", out);
attr = attr->mNext;
1998-12-11 02:50:43 +00:00
}
if (0 != aSelector->mOperator) {
buffer = aSelector->mOperator;
buffer.Append(" ");
fputs(buffer, out);
1998-04-13 20:24:54 +00:00
}
}
NS_IMETHODIMP
CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
1998-04-13 20:24:54 +00:00
{
// Indent
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
const nsCSSSelector* selector = &mSelector;
while (nsnull != selector) {
ListSelector(out, selector);
fputs(" ", out);
selector = selector->mNext;
}
nsAutoString buffer;
buffer.Append("weight: ");
buffer.Append(mWeight, 10);
buffer.Append(" ");
fputs(buffer, out);
if (nsnull != mDeclaration) {
mDeclaration->List(out);
}
else {
fputs("{ null declaration }", out);
}
fputs("\n", out);
return NS_OK;
1998-04-13 20:24:54 +00:00
}
NS_IMETHODIMP
1998-11-26 01:34:53 +00:00
CSSStyleRuleImpl::GetType(PRUint16* aType)
{
1998-11-26 01:34:53 +00:00
*aType = nsIDOMCSSRule::STYLE_RULE;
return NS_OK;
}
1998-11-26 01:34:53 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSheet(nsIDOMCSSStyleSheet** aSheet)
{
if (nsnull != mSheet) {
return mSheet->QueryInterface(kIDOMCSSStyleSheetIID, (void**)aSheet);
}
*aSheet = nsnull;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
{
1998-12-11 02:50:43 +00:00
aSelectorText = mSelectorText;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetSelectorText(const nsString& aSelectorText)
{
1998-12-11 02:50:43 +00:00
// XXX TBI - get a parser and re-parse the selectors,
// XXX then need to re-compute the cascade
mSelectorText = aSelectorText;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
{
if (nsnull == mDOMDeclaration) {
mDOMDeclaration = new DOMCSSDeclarationImpl(this);
if (nsnull == mDOMDeclaration) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mDOMDeclaration);
}
*aStyle = mDOMDeclaration;
NS_ADDREF(mDOMDeclaration);
return NS_OK;
}
1998-11-26 01:34:53 +00:00
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyle(nsIDOMCSSStyleDeclaration* aStyle)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this;
// XXX Parent should be the style sheet
// XXX Should be done through factory
1998-11-26 01:34:53 +00:00
res = NS_NewScriptCSSStyleRule(aContext,
supports,
(nsISupports *)global,
(void**)&mScriptObject);
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return res;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
1998-04-13 20:24:54 +00:00
NS_HTML nsresult
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
CSSStyleRuleImpl *it = new CSSStyleRuleImpl(aSelector);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kICSSStyleRuleIID, (void **) aInstancePtrResult);
}