1998-04-14 00:24:54 +04: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 "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
//#define DEBUG_REFS
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID);
|
|
|
|
static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID);
|
1998-04-21 04:02:44 +04:00
|
|
|
static NS_DEFINE_IID(kStyleSpacingSID, NS_STYLESPACING_SID);
|
1998-04-14 00:24:54 +04:00
|
|
|
static NS_DEFINE_IID(kStyleListSID, NS_STYLELIST_SID);
|
1998-04-23 03:29:01 +04:00
|
|
|
static NS_DEFINE_IID(kStylePositionSID, NS_STYLEPOSITION_SID);
|
1998-04-25 22:33:32 +04:00
|
|
|
static NS_DEFINE_IID(kStyleTextSID, NS_STYLETEXT_SID);
|
|
|
|
static NS_DEFINE_IID(kStyleDisplaySID, NS_STYLEDISPLAY_SID);
|
1998-05-13 02:23:13 +04:00
|
|
|
static NS_DEFINE_IID(kStyleTableSID, NS_STYLETABLE_SID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIStyleContextIID, NS_ISTYLECONTEXT_IID);
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// nsStyleFont
|
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
nsStyleFont::nsStyleFont(const nsFont& aFont)
|
|
|
|
: mFont(aFont)
|
1998-04-30 01:06:15 +04:00
|
|
|
{ }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-04-30 01:06:15 +04:00
|
|
|
nsStyleFont::~nsStyleFont(void) { }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
struct StyleFontImpl : public nsStyleFont {
|
|
|
|
StyleFontImpl(const nsFont& aFont)
|
|
|
|
: nsStyleFont(aFont)
|
|
|
|
{}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleFont& aCopy);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StyleFontImpl(const StyleFontImpl& aOther);
|
|
|
|
StyleFontImpl& operator=(const StyleFontImpl& aOther);
|
|
|
|
};
|
|
|
|
|
|
|
|
void StyleFontImpl::InheritFrom(const nsStyleFont& aCopy)
|
|
|
|
{
|
|
|
|
mFont = aCopy.mFont;
|
|
|
|
mThreeD = aCopy.mThreeD;
|
|
|
|
}
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleColor
|
|
|
|
//
|
1998-05-13 02:23:13 +04:00
|
|
|
nsStyleColor::nsStyleColor(void) { }
|
|
|
|
nsStyleColor::~nsStyleColor(void) { }
|
1998-04-25 22:33:32 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
struct StyleColorImpl: public nsStyleColor {
|
|
|
|
StyleColorImpl(void)
|
|
|
|
{
|
|
|
|
mBackgroundAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
|
|
|
|
mBackgroundFlags = NS_STYLE_BG_COLOR_TRANSPARENT;
|
1998-05-02 04:55:29 +04:00
|
|
|
mBackgroundRepeat = NS_STYLE_BG_REPEAT_XY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
mBackgroundColor = NS_RGB(192,192,192);
|
1998-04-25 22:33:32 +04:00
|
|
|
mCursor = NS_STYLE_CURSOR_INHERIT;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleColor& aCopy);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StyleColorImpl(const StyleColorImpl& aOther);
|
|
|
|
StyleColorImpl& operator=(const StyleColorImpl& aOther);
|
|
|
|
};
|
|
|
|
|
|
|
|
void StyleColorImpl::InheritFrom(const nsStyleColor& aCopy)
|
|
|
|
{
|
1998-04-25 22:33:32 +04:00
|
|
|
mColor = aCopy.mColor;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleSpacing
|
|
|
|
//
|
|
|
|
nsStyleSpacing::nsStyleSpacing(void)
|
1998-05-13 02:23:13 +04:00
|
|
|
: mMargin(),
|
|
|
|
mPadding(),
|
|
|
|
mBorder(),
|
|
|
|
mHasCachedMargin(PR_FALSE),
|
|
|
|
mHasCachedPadding(PR_FALSE),
|
|
|
|
mHasCachedBorder(PR_FALSE)
|
|
|
|
{
|
|
|
|
mBorderStyle[0] = NS_STYLE_BORDER_STYLE_NONE;
|
|
|
|
mBorderStyle[1] = NS_STYLE_BORDER_STYLE_NONE;
|
|
|
|
mBorderStyle[2] = NS_STYLE_BORDER_STYLE_NONE;
|
|
|
|
mBorderStyle[3] = NS_STYLE_BORDER_STYLE_NONE;
|
|
|
|
mBorderColor[0] = NS_RGB(0, 0, 0);
|
|
|
|
mBorderColor[1] = NS_RGB(0, 0, 0);
|
|
|
|
mBorderColor[2] = NS_RGB(0, 0, 0);
|
|
|
|
mBorderColor[3] = NS_RGB(0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_SPACING_MARGIN 0
|
|
|
|
#define NS_SPACING_PADDING 1
|
|
|
|
#define NS_SPACING_BORDER 2
|
|
|
|
|
|
|
|
static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord,
|
|
|
|
PRUint8 aSpacing, PRUint8 aSide,
|
|
|
|
const nscoord* aEnumTable, PRInt32 aNumEnums)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
// XXX need to call back to frame to compute
|
|
|
|
NS_NOTYETIMPLEMENTED("auto value");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
nsIFrame* parentFrame;
|
|
|
|
aFrame->GetGeometricParent(parentFrame); // XXX may not be direct parent...
|
|
|
|
if (nsnull != parentFrame) {
|
|
|
|
nsIStyleContext* parentContext;
|
|
|
|
parentFrame->GetStyleContext(nsnull, parentContext);
|
|
|
|
if (nsnull != parentContext) {
|
|
|
|
nsStyleSpacing* parentSpacing = (nsStyleSpacing*)parentContext->GetData(kStyleSpacingSID);
|
|
|
|
nsMargin parentMargin;
|
|
|
|
switch (aSpacing) {
|
|
|
|
case NS_SPACING_MARGIN: parentSpacing->CalcMarginFor(parentFrame, parentMargin);
|
|
|
|
break;
|
|
|
|
case NS_SPACING_PADDING: parentSpacing->CalcPaddingFor(parentFrame, parentMargin);
|
|
|
|
break;
|
|
|
|
case NS_SPACING_BORDER: parentSpacing->CalcBorderFor(parentFrame, parentMargin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (aSide) {
|
|
|
|
case NS_SIDE_LEFT: result = parentMargin.left; break;
|
|
|
|
case NS_SIDE_TOP: result = parentMargin.top; break;
|
|
|
|
case NS_SIDE_RIGHT: result = parentMargin.right; break;
|
|
|
|
case NS_SIDE_BOTTOM: result = parentMargin.bottom; break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(parentContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
// XXX call frame to get percent base, do the math
|
|
|
|
NS_NOTYETIMPLEMENTED("percent value");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
result = aCoord.GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
if (nsnull != aEnumTable) {
|
|
|
|
PRInt32 value = aCoord.GetIntValue();
|
|
|
|
if ((0 <= value) && (value < aNumEnums)) {
|
|
|
|
return aEnumTable[aCoord.GetIntValue()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Null:
|
|
|
|
case eStyleUnit_Normal:
|
|
|
|
case eStyleUnit_Integer:
|
|
|
|
case eStyleUnit_Proportional:
|
|
|
|
default:
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CalcSidesFor(const nsIFrame* aFrame, const nsStyleSides& aSides,
|
|
|
|
PRUint8 aSpacing,
|
|
|
|
const nscoord* aEnumTable, PRInt32 aNumEnums,
|
|
|
|
nsMargin& aResult)
|
|
|
|
{
|
|
|
|
nsStyleCoord coord;
|
|
|
|
|
|
|
|
aResult.left = CalcSideFor(aFrame, aSides.GetLeft(coord), aSpacing, NS_SIDE_LEFT,
|
|
|
|
aEnumTable, aNumEnums);
|
|
|
|
aResult.top = CalcSideFor(aFrame, aSides.GetTop(coord), aSpacing, NS_SIDE_TOP,
|
|
|
|
aEnumTable, aNumEnums);
|
|
|
|
aResult.right = CalcSideFor(aFrame, aSides.GetRight(coord), aSpacing, NS_SIDE_RIGHT,
|
|
|
|
aEnumTable, aNumEnums);
|
|
|
|
aResult.bottom = CalcSideFor(aFrame, aSides.GetBottom(coord), aSpacing, NS_SIDE_BOTTOM,
|
|
|
|
aEnumTable, aNumEnums);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsStyleSpacing::CalcMarginFor(const nsIFrame* aFrame, nsMargin& aMargin) const
|
|
|
|
{
|
|
|
|
if (mHasCachedMargin) {
|
|
|
|
aMargin = mCachedMargin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CalcSidesFor(aFrame, mMargin, NS_SPACING_MARGIN, nsnull, 0, aMargin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsStyleSpacing::CalcPaddingFor(const nsIFrame* aFrame, nsMargin& aPadding) const
|
|
|
|
{
|
|
|
|
if (mHasCachedPadding) {
|
|
|
|
aPadding = mCachedPadding;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CalcSidesFor(aFrame, mPadding, NS_SPACING_PADDING, nsnull, 0, aPadding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nscoord kBorderWidths[3] =
|
|
|
|
{ NS_POINTS_TO_TWIPS_INT(1),
|
|
|
|
NS_POINTS_TO_TWIPS_INT(3),
|
|
|
|
NS_POINTS_TO_TWIPS_INT(5) };
|
|
|
|
|
|
|
|
void nsStyleSpacing::CalcBorderFor(const nsIFrame* aFrame, nsMargin& aBorder) const
|
|
|
|
{
|
|
|
|
if (mHasCachedBorder) {
|
|
|
|
aBorder = mCachedBorder;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CalcSidesFor(aFrame, mBorder, NS_SPACING_BORDER, kBorderWidths, 3, aBorder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsStyleSpacing::CalcBorderPaddingFor(const nsIFrame* aFrame, nsMargin& aBorderPadding) const
|
1998-04-21 04:02:44 +04:00
|
|
|
{
|
1998-05-13 02:23:13 +04:00
|
|
|
if (mHasCachedPadding && mHasCachedBorder) {
|
|
|
|
aBorderPadding = mCachedBorderPadding;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsMargin border;
|
|
|
|
CalcBorderFor(aFrame, border);
|
|
|
|
CalcPaddingFor(aFrame, aBorderPadding);
|
|
|
|
aBorderPadding += border;
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
struct StyleSpacingImpl: public nsStyleSpacing {
|
|
|
|
StyleSpacingImpl(void)
|
|
|
|
: nsStyleSpacing()
|
|
|
|
{}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleSpacing& aCopy);
|
|
|
|
void RecalcData(nsIPresContext* aPresContext);
|
1998-04-21 04:02:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void StyleSpacingImpl::InheritFrom(const nsStyleSpacing& aCopy)
|
|
|
|
{
|
|
|
|
// spacing values not inherited
|
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
inline PRBool IsFixedUnit(nsStyleUnit aUnit, PRBool aEnumOK)
|
|
|
|
{
|
|
|
|
return PRBool((aUnit == eStyleUnit_Null) ||
|
|
|
|
(aUnit == eStyleUnit_Coord) ||
|
|
|
|
(aEnumOK && (aUnit == eStyleUnit_Enumerated)));
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
static PRBool IsFixedData(const nsStyleSides& aSides, PRBool aEnumOK)
|
1998-04-21 04:02:44 +04:00
|
|
|
{
|
1998-05-13 02:23:13 +04:00
|
|
|
return PRBool(IsFixedUnit(aSides.GetLeftUnit(), aEnumOK) &&
|
|
|
|
IsFixedUnit(aSides.GetTopUnit(), aEnumOK) &&
|
|
|
|
IsFixedUnit(aSides.GetRightUnit(), aEnumOK) &&
|
|
|
|
IsFixedUnit(aSides.GetBottomUnit(), aEnumOK));
|
1998-04-21 04:02:44 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
static nscoord CalcCoord(const nsStyleCoord& aCoord,
|
|
|
|
const nscoord* aEnumTable,
|
|
|
|
PRInt32 aNumEnums)
|
|
|
|
{
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Null:
|
|
|
|
return 0;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
return aCoord.GetCoordValue();
|
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
if (nsnull != aEnumTable) {
|
|
|
|
PRInt32 value = aCoord.GetIntValue();
|
|
|
|
if ((0 <= value) && (value < aNumEnums)) {
|
|
|
|
return aEnumTable[aCoord.GetIntValue()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad unit type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void StyleSpacingImpl::RecalcData(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (IsFixedData(mMargin, PR_FALSE)) {
|
|
|
|
nsStyleCoord coord;
|
|
|
|
mCachedMargin.left = CalcCoord(mMargin.GetLeft(coord), nsnull, 0);
|
|
|
|
mCachedMargin.top = CalcCoord(mMargin.GetTop(coord), nsnull, 0);
|
|
|
|
mCachedMargin.right = CalcCoord(mMargin.GetRight(coord), nsnull, 0);
|
|
|
|
mCachedMargin.bottom = CalcCoord(mMargin.GetBottom(coord), nsnull, 0);
|
|
|
|
|
|
|
|
mHasCachedMargin = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHasCachedMargin = PR_FALSE;
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
if (IsFixedData(mPadding, PR_FALSE)) {
|
|
|
|
nsStyleCoord coord;
|
|
|
|
mCachedPadding.left = CalcCoord(mPadding.GetLeft(coord), nsnull, 0);
|
|
|
|
mCachedPadding.top = CalcCoord(mPadding.GetTop(coord), nsnull, 0);
|
|
|
|
mCachedPadding.right = CalcCoord(mPadding.GetRight(coord), nsnull, 0);
|
|
|
|
mCachedPadding.bottom = CalcCoord(mPadding.GetBottom(coord), nsnull, 0);
|
|
|
|
|
|
|
|
mHasCachedPadding = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHasCachedPadding = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsFixedData(mBorder, PR_TRUE)) {
|
|
|
|
nsStyleCoord coord;
|
|
|
|
mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), kBorderWidths, 3);
|
|
|
|
mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), kBorderWidths, 3);
|
|
|
|
mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), kBorderWidths, 3);
|
|
|
|
mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), kBorderWidths, 3);
|
|
|
|
|
|
|
|
mHasCachedPadding = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHasCachedPadding = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHasCachedBorder && mHasCachedPadding) {
|
|
|
|
mCachedBorderPadding = mCachedPadding;
|
|
|
|
mCachedBorderPadding += mCachedBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// XXX fixup missing border colors
|
1998-04-21 04:02:44 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleList
|
|
|
|
//
|
1998-05-13 02:23:13 +04:00
|
|
|
nsStyleList::nsStyleList(void) { }
|
|
|
|
nsStyleList::~nsStyleList(void) { }
|
1998-04-25 22:33:32 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
struct StyleListImpl: public nsStyleList {
|
|
|
|
StyleListImpl(void)
|
|
|
|
{
|
|
|
|
mListStyleType = NS_STYLE_LIST_STYLE_BASIC;
|
|
|
|
mListStylePosition = NS_STYLE_LIST_STYLE_POSITION_OUTSIDE;
|
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleList& aCopy);
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void StyleListImpl::InheritFrom(const nsStyleList& aCopy)
|
|
|
|
{
|
|
|
|
mListStyleType = aCopy.mListStyleType;
|
|
|
|
mListStyleImage = aCopy.mListStyleImage;
|
|
|
|
mListStylePosition = aCopy.mListStylePosition;
|
|
|
|
}
|
|
|
|
|
1998-04-23 03:29:01 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStylePosition
|
|
|
|
//
|
1998-05-13 02:23:13 +04:00
|
|
|
nsStylePosition::nsStylePosition(void) { }
|
1998-04-25 22:33:32 +04:00
|
|
|
|
1998-04-23 03:29:01 +04:00
|
|
|
struct StylePositionImpl: public nsStylePosition {
|
|
|
|
StylePositionImpl(void)
|
|
|
|
{
|
|
|
|
mPosition = NS_STYLE_POSITION_STATIC;
|
1998-04-25 08:07:18 +04:00
|
|
|
mOverflow = NS_STYLE_OVERFLOW_VISIBLE;
|
1998-04-30 23:52:26 +04:00
|
|
|
mLeftOffset.SetAutoValue();
|
|
|
|
mTopOffset.SetAutoValue();
|
|
|
|
mWidth.SetAutoValue();
|
|
|
|
mHeight.SetAutoValue();
|
|
|
|
mZIndex.SetAutoValue();
|
1998-04-28 07:21:18 +04:00
|
|
|
mClipFlags = NS_STYLE_CLIP_AUTO;
|
|
|
|
mClip.SizeTo(0,0,0,0);
|
1998-04-23 03:29:01 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStylePosition& aCopy);
|
1998-04-23 03:29:01 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StylePositionImpl(const StylePositionImpl& aOther);
|
|
|
|
StylePositionImpl& operator=(const StylePositionImpl& aOther);
|
|
|
|
};
|
|
|
|
|
|
|
|
void StylePositionImpl::InheritFrom(const nsStylePosition& aCopy)
|
|
|
|
{
|
|
|
|
// positioning values not inherited
|
|
|
|
}
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
// --------------------
|
1998-04-25 22:33:32 +04:00
|
|
|
// nsStyleText
|
1998-04-21 04:02:44 +04:00
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
nsStyleText::nsStyleText(void) { }
|
1998-04-25 22:33:32 +04:00
|
|
|
|
|
|
|
struct StyleTextImpl: public nsStyleText {
|
1998-05-13 02:23:13 +04:00
|
|
|
StyleTextImpl(void) {
|
1998-04-25 22:33:32 +04:00
|
|
|
mTextAlign = NS_STYLE_TEXT_ALIGN_LEFT;
|
|
|
|
mTextDecoration = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
mTextTransform = NS_STYLE_TEXT_TRANSFORM_NONE;
|
|
|
|
mWhiteSpace = NS_STYLE_WHITESPACE_NORMAL;
|
1998-04-30 01:06:15 +04:00
|
|
|
|
1998-04-30 23:52:26 +04:00
|
|
|
mLetterSpacing.SetNormalValue();
|
|
|
|
mLineHeight.SetNormalValue();
|
|
|
|
mTextIndent.SetCoordValue(0);
|
|
|
|
mWordSpacing.SetNormalValue();
|
|
|
|
mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_BASELINE, eStyleUnit_Enumerated);
|
1998-04-25 22:33:32 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleText& aCopy);
|
1998-04-25 22:33:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void StyleTextImpl::InheritFrom(const nsStyleText& aCopy)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-25 22:33:32 +04:00
|
|
|
// Properties not listed here are not inherited: mVerticalAlign,
|
|
|
|
// mTextDecoration
|
|
|
|
mTextAlign = aCopy.mTextAlign;
|
|
|
|
mTextTransform = aCopy.mTextTransform;
|
|
|
|
mWhiteSpace = aCopy.mWhiteSpace;
|
|
|
|
|
|
|
|
mLetterSpacing = aCopy.mLetterSpacing;
|
|
|
|
mLineHeight = aCopy.mLineHeight;
|
|
|
|
mTextIndent = aCopy.mTextIndent;
|
|
|
|
mWordSpacing = aCopy.mWordSpacing;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-25 22:33:32 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleDisplay
|
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
nsStyleDisplay::nsStyleDisplay(void) { }
|
1998-04-25 22:33:32 +04:00
|
|
|
|
|
|
|
struct StyleDisplayImpl: public nsStyleDisplay {
|
1998-05-13 02:23:13 +04:00
|
|
|
StyleDisplayImpl(void) {
|
1998-04-25 22:33:32 +04:00
|
|
|
mDirection = NS_STYLE_DIRECTION_LTR;
|
|
|
|
mDisplay = NS_STYLE_DISPLAY_INLINE;
|
|
|
|
mFloats = NS_STYLE_FLOAT_NONE;
|
|
|
|
mBreakType = NS_STYLE_CLEAR_NONE;
|
|
|
|
mBreakBefore = PR_FALSE;
|
|
|
|
mBreakAfter = PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void InheritFrom(const nsStyleDisplay& aCopy);
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-04-25 22:33:32 +04:00
|
|
|
void StyleDisplayImpl::InheritFrom(const nsStyleDisplay& aCopy)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-25 22:33:32 +04:00
|
|
|
mDirection = aCopy.mDirection;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleTable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsStyleTable::nsStyleTable(void) { }
|
|
|
|
|
|
|
|
struct StyleTableImpl: public nsStyleTable {
|
|
|
|
StyleTableImpl(void) {
|
|
|
|
mFrame = NS_STYLE_TABLE_FRAME_NONE;
|
|
|
|
mRules = NS_STYLE_TABLE_RULES_NONE;
|
|
|
|
mCellPadding.Reset();
|
|
|
|
mCellSpacing.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InheritFrom(const nsStyleTable& aCopy);
|
|
|
|
};
|
|
|
|
|
|
|
|
void StyleTableImpl::InheritFrom(const nsStyleTable& aCopy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class StyleContextImpl : public nsIStyleContext {
|
|
|
|
public:
|
|
|
|
StyleContextImpl(nsIStyleContext* aParent, nsISupportsArray* aRules, nsIPresContext* aPresContext);
|
|
|
|
~StyleContextImpl();
|
|
|
|
|
|
|
|
void* operator new(size_t sz) {
|
|
|
|
void* rv = new char[sz];
|
|
|
|
nsCRT::zero(rv, sz);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
virtual nsIStyleContext* GetParent(void) const;
|
|
|
|
virtual nsISupportsArray* GetStyleRules(void) const;
|
|
|
|
|
|
|
|
virtual PRBool Equals(const nsIStyleContext* aOther) const;
|
|
|
|
virtual PRUint32 HashValue(void) const;
|
|
|
|
|
|
|
|
virtual nsStyleStruct* GetData(const nsIID& aSID);
|
|
|
|
|
|
|
|
virtual void InheritFrom(const StyleContextImpl& aParent);
|
1998-05-13 02:23:13 +04:00
|
|
|
virtual void RecalcAutomaticData(nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsIStyleContext* mParent;
|
|
|
|
PRUint32 mHashValid: 1;
|
|
|
|
PRUint32 mHashValue: 31;
|
|
|
|
nsISupportsArray* mRules;
|
|
|
|
|
|
|
|
// the style data...
|
|
|
|
StyleFontImpl mFont;
|
|
|
|
StyleColorImpl mColor;
|
1998-04-21 04:02:44 +04:00
|
|
|
StyleSpacingImpl mSpacing;
|
1998-04-14 00:24:54 +04:00
|
|
|
StyleListImpl mList;
|
1998-04-23 03:29:01 +04:00
|
|
|
StylePositionImpl mPosition;
|
1998-04-25 22:33:32 +04:00
|
|
|
StyleTextImpl mText;
|
|
|
|
StyleDisplayImpl mDisplay;
|
1998-05-13 02:23:13 +04:00
|
|
|
StyleTableImpl* mTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
static PRInt32 gInstanceCount;
|
|
|
|
#endif
|
|
|
|
|
1998-04-25 22:33:32 +04:00
|
|
|
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
|
|
|
|
nsISupportsArray* aRules,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIPresContext* aPresContext)
|
|
|
|
: mParent(aParent), // weak ref
|
|
|
|
mRules(aRules),
|
|
|
|
mFont(aPresContext->GetDefaultFont()),
|
|
|
|
mColor(),
|
1998-04-21 04:02:44 +04:00
|
|
|
mSpacing(),
|
1998-04-14 00:24:54 +04:00
|
|
|
mList(),
|
1998-04-25 22:33:32 +04:00
|
|
|
mPosition(),
|
|
|
|
mText(),
|
1998-05-13 02:23:13 +04:00
|
|
|
mDisplay(),
|
|
|
|
mTable(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
NS_IF_ADDREF(mRules);
|
|
|
|
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
InheritFrom((StyleContextImpl&)*aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mRules) {
|
|
|
|
PRInt32 index = mRules->Count();
|
|
|
|
while (0 < index) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(--index);
|
|
|
|
rule->MapStyleInto(this, aPresContext);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
++gInstanceCount;
|
|
|
|
fprintf(stdout, "%d + StyleContext\n", gInstanceCount);
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleContextImpl::~StyleContextImpl()
|
|
|
|
{
|
|
|
|
mParent = nsnull; // weak ref
|
|
|
|
NS_IF_RELEASE(mRules);
|
1998-05-13 02:23:13 +04:00
|
|
|
if (nsnull != mTable) {
|
|
|
|
delete mTable;
|
|
|
|
mTable = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
--gInstanceCount;
|
|
|
|
fprintf(stdout, "%d - StyleContext\n", gInstanceCount);
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(StyleContextImpl, kIStyleContextIID)
|
|
|
|
|
|
|
|
nsIStyleContext* StyleContextImpl::GetParent(void) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mParent);
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mRules);
|
|
|
|
return mRules;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool StyleContextImpl::Equals(const nsIStyleContext* aOther) const
|
|
|
|
{
|
|
|
|
PRBool result = PR_TRUE;
|
|
|
|
const StyleContextImpl* other = (StyleContextImpl*)aOther;
|
|
|
|
|
|
|
|
if (other != this) {
|
|
|
|
if (mParent != other->mParent) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((nsnull != mRules) && (nsnull != other->mRules)) {
|
|
|
|
result = mRules->Equals(other->mRules);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = PRBool((nsnull == mRules) && (nsnull == other->mRules));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 StyleContextImpl::HashValue(void) const
|
|
|
|
{
|
|
|
|
if (0 == mHashValid) {
|
|
|
|
((StyleContextImpl*)this)->mHashValue = ((nsnull != mParent) ? mParent->HashValue() : 0);
|
|
|
|
if (nsnull != mRules) {
|
|
|
|
PRInt32 index = mRules->Count();
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(index);
|
|
|
|
PRUint32 hash = rule->HashValue();
|
|
|
|
((StyleContextImpl*)this)->mHashValue ^= (hash & 0x7FFFFFFF);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
((StyleContextImpl*)this)->mHashValid = 1;
|
|
|
|
}
|
|
|
|
return mHashValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsStyleStruct* StyleContextImpl::GetData(const nsIID& aSID)
|
|
|
|
{
|
|
|
|
if (aSID.Equals(kStyleFontSID)) {
|
|
|
|
return &mFont;
|
|
|
|
}
|
|
|
|
if (aSID.Equals(kStyleColorSID)) {
|
|
|
|
return &mColor;
|
|
|
|
}
|
1998-04-21 04:02:44 +04:00
|
|
|
if (aSID.Equals(kStyleSpacingSID)) {
|
|
|
|
return &mSpacing;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (aSID.Equals(kStyleListSID)) {
|
|
|
|
return &mList;
|
|
|
|
}
|
1998-04-23 19:39:48 +04:00
|
|
|
if (aSID.Equals(kStylePositionSID)) {
|
|
|
|
return &mPosition;
|
|
|
|
}
|
1998-04-25 22:33:32 +04:00
|
|
|
if (aSID.Equals(kStyleTextSID)) {
|
|
|
|
return &mText;
|
|
|
|
}
|
|
|
|
if (aSID.Equals(kStyleDisplaySID)) {
|
|
|
|
return &mDisplay;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-05-13 02:23:13 +04:00
|
|
|
if (aSID.Equals(kStyleTableSID)) { // this one gets created lazily
|
|
|
|
if (nsnull == mTable) {
|
|
|
|
mTable = new StyleTableImpl();
|
|
|
|
if (nsnull != mParent) {
|
|
|
|
StyleContextImpl* parent = (StyleContextImpl*)mParent;
|
|
|
|
if (nsnull != parent->mTable) {
|
|
|
|
mTable->InheritFrom(*(parent->mTable));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mTable;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleContextImpl::InheritFrom(const StyleContextImpl& aParent)
|
|
|
|
{
|
|
|
|
mFont.InheritFrom(aParent.mFont);
|
|
|
|
mColor.InheritFrom(aParent.mColor);
|
1998-04-21 04:02:44 +04:00
|
|
|
mSpacing.InheritFrom(aParent.mSpacing);
|
1998-04-14 00:24:54 +04:00
|
|
|
mList.InheritFrom(aParent.mList);
|
1998-04-25 22:33:32 +04:00
|
|
|
mText.InheritFrom(aParent.mText);
|
|
|
|
mPosition.InheritFrom(aParent.mPosition);
|
|
|
|
mDisplay.InheritFrom(aParent.mDisplay);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
void StyleContextImpl::RecalcAutomaticData(nsIPresContext* aPresContext)
|
1998-04-21 04:02:44 +04:00
|
|
|
{
|
1998-05-13 02:23:13 +04:00
|
|
|
mSpacing.RecalcData(aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewStyleContext(nsIStyleContext** aInstancePtrResult,
|
|
|
|
nsISupportsArray* aRules,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleContext* parent = nsnull;
|
|
|
|
if (nsnull != aParentFrame) {
|
1998-04-17 05:41:24 +04:00
|
|
|
aParentFrame->GetStyleContext(aPresContext, parent);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(nsnull != parent, "parent frame must have style context");
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleContextImpl* context = new StyleContextImpl(parent, aRules, aPresContext);
|
|
|
|
NS_IF_RELEASE(parent);
|
|
|
|
if (nsnull == context) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-05-13 02:23:13 +04:00
|
|
|
context->RecalcAutomaticData(aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
return context->QueryInterface(kIStyleContextIID, (void **) aInstancePtrResult);
|
|
|
|
}
|