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(kIStyleContextIID, NS_ISTYLECONTEXT_IID);
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// nsStyleFont
|
|
|
|
//
|
1998-07-17 09:43:31 +04:00
|
|
|
nsStyleFont::nsStyleFont(const nsFont& aVariableFont, const nsFont& aFixedFont)
|
|
|
|
: mFont(aVariableFont),
|
|
|
|
mFixedFont(aFixedFont)
|
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 {
|
1998-07-17 09:43:31 +04:00
|
|
|
StyleFontImpl(const nsFont& aVariableFont, const nsFont& aFixedFont)
|
|
|
|
: nsStyleFont(aVariableFont, aFixedFont)
|
1998-04-14 00:24:54 +04:00
|
|
|
{}
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleFont* aParent, nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StyleFontImpl(const StyleFontImpl& aOther);
|
|
|
|
StyleFontImpl& operator=(const StyleFontImpl& aOther);
|
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleFontImpl::ResetFrom(const nsStyleFont* aParent, nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
mFont = aParent->mFont;
|
1998-07-17 09:43:31 +04:00
|
|
|
mFixedFont = aParent->mFixedFont;
|
1998-07-23 21:57:16 +04:00
|
|
|
mFlags = aParent->mFlags;
|
1998-05-27 03:14:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFont = aPresContext->GetDefaultFont();
|
1998-07-17 09:43:31 +04:00
|
|
|
mFixedFont = aPresContext->GetDefaultFixedFont();
|
1998-07-23 21:57:16 +04:00
|
|
|
mFlags = NS_STYLE_FONT_DEFAULT;
|
1998-05-27 03:14:09 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
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 {
|
1998-05-27 03:14:09 +04:00
|
|
|
StyleColorImpl(void) { }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleColor* aParent, nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StyleColorImpl(const StyleColorImpl& aOther);
|
|
|
|
StyleColorImpl& operator=(const StyleColorImpl& aOther);
|
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleColorImpl::ResetFrom(const nsStyleColor* aParent, nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
mColor = aParent->mColor;
|
1998-05-28 06:01:19 +04:00
|
|
|
mOpacity = aParent->mOpacity;
|
1998-05-27 03:14:09 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-07-17 09:43:31 +04:00
|
|
|
if (nsnull != aPresContext) {
|
|
|
|
aPresContext->GetDefaultColor(mColor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mColor = NS_RGB(0x00, 0x00, 0x00);
|
|
|
|
}
|
1998-05-28 23:55:15 +04:00
|
|
|
mOpacity = 1.0F;
|
1998-05-27 03:14:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBackgroundAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
|
|
|
|
mBackgroundFlags = NS_STYLE_BG_COLOR_TRANSPARENT;
|
|
|
|
mBackgroundRepeat = NS_STYLE_BG_REPEAT_XY;
|
1998-07-17 09:43:31 +04:00
|
|
|
if (nsnull != aPresContext) {
|
|
|
|
aPresContext->GetDefaultBackgroundColor(mBackgroundColor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBackgroundColor = NS_RGB(192,192,192);
|
|
|
|
}
|
1998-05-27 03:14:09 +04:00
|
|
|
mBackgroundXPosition = 0;
|
|
|
|
mBackgroundYPosition = 0;
|
|
|
|
|
|
|
|
mCursor = NS_STYLE_CURSOR_INHERIT;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleSpacing
|
|
|
|
//
|
1998-05-27 03:14:09 +04:00
|
|
|
nsStyleSpacing::nsStyleSpacing(void) { }
|
1998-05-13 02:23:13 +04:00
|
|
|
|
|
|
|
#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:
|
1998-05-14 02:38:54 +04:00
|
|
|
aFrame->GetAutoMarginSize(aSide, result);
|
1998-05-13 02:23:13 +04:00
|
|
|
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) {
|
1998-06-05 10:01:55 +04:00
|
|
|
const nsStyleSpacing* parentSpacing = (const nsStyleSpacing*)parentContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-13 02:23:13 +04:00
|
|
|
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:
|
1998-05-14 02:38:54 +04:00
|
|
|
{
|
|
|
|
nscoord baseWidth = 0;
|
|
|
|
PRBool isBase = PR_FALSE;
|
|
|
|
nsIFrame* frame;
|
|
|
|
aFrame->GetGeometricParent(frame);
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->IsPercentageBase(isBase);
|
|
|
|
if (isBase) {
|
|
|
|
nsSize size;
|
|
|
|
frame->GetSize(size);
|
1998-05-19 01:04:26 +04:00
|
|
|
baseWidth = size.width; // not really width, need to subtract out padding...
|
1998-05-14 02:38:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame->GetGeometricParent(frame);
|
|
|
|
}
|
|
|
|
result = (nscoord)((float)baseWidth * aCoord.GetPercentValue());
|
|
|
|
}
|
1998-05-13 02:23:13 +04:00
|
|
|
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] =
|
1998-08-01 03:34:45 +04:00
|
|
|
{ NSIntPointsToTwips(1),
|
|
|
|
NSIntPointsToTwips(3),
|
|
|
|
NSIntPointsToTwips(5) };
|
1998-05-13 02:23:13 +04:00
|
|
|
|
|
|
|
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-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleSpacing* aParent, nsIPresContext* aPresContext);
|
1998-05-13 02:23:13 +04:00
|
|
|
void RecalcData(nsIPresContext* aPresContext);
|
1998-04-21 04:02:44 +04:00
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleSpacingImpl::ResetFrom(const nsStyleSpacing* aParent, nsIPresContext* aPresContext)
|
1998-04-21 04:02:44 +04:00
|
|
|
{
|
|
|
|
// spacing values not inherited
|
1998-05-27 03:14:09 +04:00
|
|
|
mMargin.Reset();
|
|
|
|
mPadding.Reset();
|
|
|
|
mBorder.Reset();
|
|
|
|
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);
|
|
|
|
|
|
|
|
mHasCachedMargin = PR_FALSE;
|
|
|
|
mHasCachedPadding = PR_FALSE;
|
|
|
|
mHasCachedBorder = PR_FALSE;
|
1998-04-21 04:02:44 +04:00
|
|
|
}
|
|
|
|
|
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 {
|
1998-05-27 03:14:09 +04:00
|
|
|
StyleListImpl(void) { }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleList* aParent, nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleListImpl::ResetFrom(const nsStyleList* aParent, nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
mListStyleType = aParent->mListStyleType;
|
|
|
|
mListStyleImage = aParent->mListStyleImage;
|
|
|
|
mListStylePosition = aParent->mListStylePosition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mListStyleType = NS_STYLE_LIST_STYLE_BASIC;
|
|
|
|
mListStylePosition = NS_STYLE_LIST_STYLE_POSITION_OUTSIDE;
|
|
|
|
mListStyleImage.Truncate();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
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 {
|
1998-05-27 03:14:09 +04:00
|
|
|
StylePositionImpl(void) { }
|
1998-04-23 03:29:01 +04:00
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStylePosition* aParent, nsIPresContext* aPresContext);
|
1998-04-23 03:29:01 +04:00
|
|
|
|
|
|
|
private: // These are not allowed
|
|
|
|
StylePositionImpl(const StylePositionImpl& aOther);
|
|
|
|
StylePositionImpl& operator=(const StylePositionImpl& aOther);
|
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StylePositionImpl::ResetFrom(const nsStylePosition* aParent, nsIPresContext* aPresContext)
|
1998-04-23 03:29:01 +04:00
|
|
|
{
|
|
|
|
// positioning values not inherited
|
1998-05-27 03:14:09 +04:00
|
|
|
mPosition = NS_STYLE_POSITION_NORMAL;
|
|
|
|
mLeftOffset.SetAutoValue();
|
|
|
|
mTopOffset.SetAutoValue();
|
|
|
|
mWidth.SetAutoValue();
|
|
|
|
mHeight.SetAutoValue();
|
|
|
|
mZIndex.SetAutoValue();
|
1998-04-23 03:29:01 +04:00
|
|
|
}
|
|
|
|
|
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-27 03:14:09 +04:00
|
|
|
StyleTextImpl(void) { }
|
|
|
|
|
|
|
|
void ResetFrom(const nsStyleText* aParent, nsIPresContext* aPresContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
void StyleTextImpl::ResetFrom(const nsStyleText* aParent, nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// These properties not inherited
|
|
|
|
mTextDecoration = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_BASELINE, eStyleUnit_Enumerated);
|
|
|
|
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
mTextAlign = aParent->mTextAlign;
|
|
|
|
mTextTransform = aParent->mTextTransform;
|
|
|
|
mWhiteSpace = aParent->mWhiteSpace;
|
|
|
|
|
|
|
|
mLetterSpacing = aParent->mLetterSpacing;
|
|
|
|
mLineHeight = aParent->mLineHeight;
|
|
|
|
mTextIndent = aParent->mTextIndent;
|
|
|
|
mWordSpacing = aParent->mWordSpacing;
|
|
|
|
}
|
|
|
|
else {
|
1998-05-28 06:01:19 +04:00
|
|
|
mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
|
1998-04-25 22:33:32 +04:00
|
|
|
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();
|
1998-04-25 22:33:32 +04:00
|
|
|
}
|
|
|
|
|
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-27 03:14:09 +04:00
|
|
|
StyleDisplayImpl(void) { }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleDisplay* aParent, nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleDisplayImpl::ResetFrom(const nsStyleDisplay* aParent, nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
mDirection = aParent->mDirection;
|
|
|
|
mVisible = aParent->mVisible;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mDirection = NS_STYLE_DIRECTION_LTR;
|
|
|
|
mVisible = PR_TRUE;
|
|
|
|
}
|
|
|
|
mDisplay = NS_STYLE_DISPLAY_INLINE;
|
|
|
|
mFloats = NS_STYLE_FLOAT_NONE;
|
|
|
|
mBreakType = NS_STYLE_CLEAR_NONE;
|
|
|
|
mBreakBefore = PR_FALSE;
|
|
|
|
mBreakAfter = PR_FALSE;
|
|
|
|
mOverflow = NS_STYLE_OVERFLOW_VISIBLE;
|
|
|
|
mClipFlags = NS_STYLE_CLIP_AUTO;
|
|
|
|
mClip.SizeTo(0,0,0,0);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-13 02:23:13 +04:00
|
|
|
// --------------------
|
|
|
|
// nsStyleTable
|
|
|
|
//
|
|
|
|
|
|
|
|
nsStyleTable::nsStyleTable(void) { }
|
|
|
|
|
|
|
|
struct StyleTableImpl: public nsStyleTable {
|
1998-06-11 21:50:51 +04:00
|
|
|
StyleTableImpl(void);
|
1998-05-13 02:23:13 +04:00
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void ResetFrom(const nsStyleTable* aParent, nsIPresContext* aPresContext);
|
1998-05-13 02:23:13 +04:00
|
|
|
};
|
|
|
|
|
1998-06-11 21:50:51 +04:00
|
|
|
StyleTableImpl::StyleTableImpl()
|
|
|
|
{
|
|
|
|
ResetFrom(nsnull, nsnull);
|
|
|
|
}
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
void StyleTableImpl::ResetFrom(const nsStyleTable* aParent, nsIPresContext* aPresContext)
|
1998-05-13 02:23:13 +04:00
|
|
|
{
|
1998-05-27 03:14:09 +04:00
|
|
|
// values not inherited
|
1998-06-11 21:50:51 +04:00
|
|
|
mCols = NS_STYLE_TABLE_COLS_NONE;
|
1998-05-27 03:14:09 +04:00
|
|
|
mFrame = NS_STYLE_TABLE_FRAME_NONE;
|
|
|
|
mRules = NS_STYLE_TABLE_RULES_NONE;
|
|
|
|
mCellPadding.Reset();
|
|
|
|
mCellSpacing.Reset();
|
1998-06-17 20:38:24 +04:00
|
|
|
mSpan=0;
|
1998-05-13 02:23:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class StyleContextImpl : public nsIStyleContext {
|
|
|
|
public:
|
1998-07-17 09:43:31 +04:00
|
|
|
StyleContextImpl(nsIStyleContext* aParent, nsISupportsArray* aRules,
|
|
|
|
nsIContent* aContent, nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
~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;
|
1998-05-21 00:32:57 +04:00
|
|
|
virtual PRInt32 GetStyleRuleCount(void) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
virtual nsIStyleContext* FindChildWithContent(nsIContent* aContent);
|
1998-05-27 03:14:09 +04:00
|
|
|
virtual nsIStyleContext* FindChildWithRules(nsISupportsArray* aRules);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual PRBool Equals(const nsIStyleContext* aOther) const;
|
|
|
|
virtual PRUint32 HashValue(void) const;
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
virtual void RemapStyle(nsIPresContext* aPresContext);
|
|
|
|
|
1998-06-05 10:01:55 +04:00
|
|
|
virtual const nsStyleStruct* GetStyleData(nsStyleStructID aSID);
|
|
|
|
virtual nsStyleStruct* GetMutableStyleData(nsStyleStructID aSID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-05 10:01:55 +04:00
|
|
|
virtual void ForceUnique(void);
|
1998-05-13 02:23:13 +04:00
|
|
|
virtual void RecalcAutomaticData(nsIPresContext* aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 01:04:26 +04:00
|
|
|
virtual void List(FILE* out, PRInt32 aIndent);
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
protected:
|
1998-07-17 09:43:31 +04:00
|
|
|
void AppendChild(StyleContextImpl* aChild);
|
1998-05-27 03:14:09 +04:00
|
|
|
|
|
|
|
StyleContextImpl* mParent;
|
|
|
|
StyleContextImpl* mChild;
|
1998-07-17 09:43:31 +04:00
|
|
|
StyleContextImpl* mPrevSibling;
|
|
|
|
StyleContextImpl* mNextSibling;
|
|
|
|
|
|
|
|
StyleContextImpl* mPrevLinear;
|
|
|
|
StyleContextImpl* mNextLinear;
|
|
|
|
|
|
|
|
nsIContent* mContent;
|
1998-05-27 03:14:09 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRUint32 mHashValid: 1;
|
|
|
|
PRUint32 mHashValue: 31;
|
|
|
|
nsISupportsArray* mRules;
|
1998-06-05 10:01:55 +04:00
|
|
|
PRInt32 mDataCode;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// 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-05-19 01:04:26 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
PRInt32 mInstance;
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-06-05 10:01:55 +04:00
|
|
|
static PRInt32 gLastDataCode;
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
static PRInt32 gInstanceCount;
|
1998-05-19 01:04:26 +04:00
|
|
|
static PRInt32 gInstrument = 6;
|
1998-04-21 04:02:44 +04:00
|
|
|
#endif
|
|
|
|
|
1998-04-25 22:33:32 +04:00
|
|
|
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent,
|
|
|
|
nsISupportsArray* aRules,
|
1998-07-17 09:43:31 +04:00
|
|
|
nsIContent* aContent,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIPresContext* aPresContext)
|
1998-05-27 03:14:09 +04:00
|
|
|
: mParent((StyleContextImpl*)aParent), // weak ref
|
|
|
|
mChild(nsnull),
|
1998-07-17 09:43:31 +04:00
|
|
|
mContent(aContent),
|
1998-04-14 00:24:54 +04:00
|
|
|
mRules(aRules),
|
1998-06-05 10:01:55 +04:00
|
|
|
mDataCode(-1),
|
1998-07-17 09:43:31 +04:00
|
|
|
mFont(aPresContext->GetDefaultFont(), aPresContext->GetDefaultFixedFont()),
|
1998-04-14 00:24:54 +04:00
|
|
|
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();
|
1998-07-17 09:43:31 +04:00
|
|
|
NS_IF_ADDREF(mContent);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IF_ADDREF(mRules);
|
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
mNextSibling = this;
|
|
|
|
mPrevSibling = this;
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != mParent) {
|
1998-07-17 09:43:31 +04:00
|
|
|
mParent->AppendChild(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
mNextLinear = this;
|
|
|
|
mPrevLinear = this;
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
RemapStyle(aPresContext);
|
|
|
|
|
1998-04-21 04:02:44 +04:00
|
|
|
#ifdef DEBUG_REFS
|
1998-05-19 01:04:26 +04:00
|
|
|
mInstance = ++gInstanceCount;
|
|
|
|
fprintf(stdout, "%d of %d + StyleContext\n", mInstance, gInstanceCount);
|
1998-04-21 04:02:44 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleContextImpl::~StyleContextImpl()
|
|
|
|
{
|
|
|
|
mParent = nsnull; // weak ref
|
1998-05-27 03:14:09 +04:00
|
|
|
|
|
|
|
if (nsnull != mChild) {
|
|
|
|
StyleContextImpl* child = mChild;
|
|
|
|
do {
|
|
|
|
StyleContextImpl* goner = child;
|
1998-07-17 09:43:31 +04:00
|
|
|
child = child->mNextSibling;
|
1998-05-27 03:14:09 +04:00
|
|
|
NS_RELEASE(goner);
|
|
|
|
} while (child != mChild);
|
|
|
|
mChild = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IF_RELEASE(mRules);
|
1998-07-17 09:43:31 +04:00
|
|
|
NS_IF_RELEASE(mContent);
|
|
|
|
|
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
|
1998-05-19 01:04:26 +04:00
|
|
|
fprintf(stdout, "%d of %d - StyleContext\n", mInstance, gInstanceCount);
|
1998-04-21 04:02:44 +04:00
|
|
|
--gInstanceCount;
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-19 01:04:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
NS_IMPL_QUERY_INTERFACE(StyleContextImpl, kIStyleContextIID)
|
|
|
|
|
|
|
|
nsrefcnt StyleContextImpl::AddRef(void)
|
|
|
|
{
|
|
|
|
if ((gInstrument == -1) || (mInstance == gInstrument)) {
|
|
|
|
fprintf(stdout, "%d AddRef StyleContext %d\n", mRefCnt + 1, mInstance);
|
|
|
|
}
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt StyleContextImpl::Release(void)
|
|
|
|
{
|
|
|
|
if ((gInstrument == -1) || (mInstance == gInstrument)) {
|
|
|
|
fprintf(stdout, "%d Release StyleContext %d\n", mRefCnt - 1, mInstance);
|
|
|
|
}
|
|
|
|
if (--mRefCnt == 0) {
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
#else
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IMPL_ISUPPORTS(StyleContextImpl, kIStyleContextIID)
|
1998-05-19 01:04:26 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsIStyleContext* StyleContextImpl::GetParent(void) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mParent);
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
void StyleContextImpl::AppendChild(StyleContextImpl* aChild)
|
1998-05-27 03:14:09 +04:00
|
|
|
{
|
|
|
|
if (nsnull == mChild) {
|
|
|
|
mChild = aChild;
|
|
|
|
}
|
|
|
|
else {
|
1998-07-17 09:43:31 +04:00
|
|
|
aChild->mNextSibling = mChild;
|
|
|
|
aChild->mPrevSibling = mChild->mPrevSibling;
|
|
|
|
mChild->mPrevSibling->mNextSibling = aChild;
|
|
|
|
mChild->mPrevSibling = aChild;
|
1998-05-27 03:14:09 +04:00
|
|
|
}
|
|
|
|
NS_ADDREF(aChild);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mRules);
|
|
|
|
return mRules;
|
|
|
|
}
|
|
|
|
|
1998-05-21 00:32:57 +04:00
|
|
|
PRInt32 StyleContextImpl::GetStyleRuleCount(void) const
|
|
|
|
{
|
|
|
|
if (nsnull != mRules) {
|
|
|
|
return mRules->Count();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
nsIStyleContext* StyleContextImpl::FindChildWithContent(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != mChild) {
|
|
|
|
StyleContextImpl* child = mChild->mPrevSibling;
|
|
|
|
do {
|
|
|
|
if ((0 == child->mDataCode) && // only look at children with un-twiddled data
|
|
|
|
(child->mContent == aContent)) {
|
|
|
|
result = child;
|
|
|
|
NS_ADDREF(result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
child = child->mPrevSibling;
|
|
|
|
} while (child != mChild->mPrevSibling);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
nsIStyleContext* StyleContextImpl::FindChildWithRules(nsISupportsArray* aRules)
|
|
|
|
{
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != mChild) {
|
|
|
|
StyleContextImpl* child = mChild;
|
|
|
|
PRInt32 ruleCount = aRules->Count();
|
|
|
|
do {
|
1998-06-05 10:01:55 +04:00
|
|
|
if ((0 == child->mDataCode) && // only look at children with un-twiddled data
|
|
|
|
(child->GetStyleRuleCount() == ruleCount)) {
|
1998-05-27 03:14:09 +04:00
|
|
|
if (child->mRules->Equals(aRules)) {
|
|
|
|
result = child;
|
|
|
|
NS_ADDREF(result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-07-17 09:43:31 +04:00
|
|
|
child = child->mNextSibling;
|
1998-05-27 03:14:09 +04:00
|
|
|
} while (child != mChild);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1998-06-05 10:01:55 +04:00
|
|
|
else if (mDataCode != other->mDataCode) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
1998-07-17 09:43:31 +04:00
|
|
|
else if (mContent != other->mContent) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-05 10:01:55 +04:00
|
|
|
const nsStyleStruct* StyleContextImpl::GetStyleData(nsStyleStructID aSID)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-21 06:34:13 +04:00
|
|
|
nsStyleStruct* result = nsnull;
|
|
|
|
|
|
|
|
switch (aSID) {
|
|
|
|
case eStyleStruct_Font:
|
|
|
|
result = &mFont;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Color:
|
|
|
|
result = &mColor;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Spacing:
|
|
|
|
result = &mSpacing;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_List:
|
|
|
|
result = &mList;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Position:
|
|
|
|
result = &mPosition;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Text:
|
|
|
|
result = &mText;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Display:
|
|
|
|
result = &mDisplay;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Table: // this one gets created lazily
|
|
|
|
if (nsnull == mTable) {
|
|
|
|
mTable = new StyleTableImpl();
|
|
|
|
if (nsnull != mParent) {
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != mParent->mTable) {
|
|
|
|
mTable->ResetFrom(mParent->mTable, nsnull);
|
1998-05-21 06:34:13 +04:00
|
|
|
}
|
1998-05-13 02:23:13 +04:00
|
|
|
}
|
|
|
|
}
|
1998-05-21 06:34:13 +04:00
|
|
|
result = mTable;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid style struct id");
|
|
|
|
break;
|
1998-05-13 02:23:13 +04:00
|
|
|
}
|
1998-05-21 06:34:13 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-05 10:01:55 +04:00
|
|
|
nsStyleStruct* StyleContextImpl::GetMutableStyleData(nsStyleStructID aSID)
|
|
|
|
{
|
|
|
|
nsStyleStruct* result = nsnull;
|
|
|
|
|
|
|
|
switch (aSID) {
|
|
|
|
case eStyleStruct_Font:
|
|
|
|
result = &mFont;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Color:
|
|
|
|
result = &mColor;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Spacing:
|
|
|
|
result = &mSpacing;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_List:
|
|
|
|
result = &mList;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Position:
|
|
|
|
result = &mPosition;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Text:
|
|
|
|
result = &mText;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Display:
|
|
|
|
result = &mDisplay;
|
|
|
|
break;
|
|
|
|
case eStyleStruct_Table: // this one gets created lazily
|
|
|
|
if (nsnull == mTable) {
|
|
|
|
mTable = new StyleTableImpl();
|
|
|
|
if (nsnull != mParent) {
|
|
|
|
if (nsnull != mParent->mTable) {
|
|
|
|
mTable->ResetFrom(mParent->mTable, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = mTable;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid style struct id");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nsnull != result) {
|
|
|
|
if (0 == mDataCode) {
|
|
|
|
mDataCode = ++gLastDataCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-27 03:14:09 +04:00
|
|
|
struct MapStyleData {
|
|
|
|
MapStyleData(nsIStyleContext* aStyleContext, nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
mStyleContext = aStyleContext;
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
}
|
|
|
|
nsIStyleContext* mStyleContext;
|
|
|
|
nsIPresContext* mPresContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
PRBool MapStyleRule(nsISupports* aRule, void* aData)
|
|
|
|
{
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)aRule;
|
|
|
|
MapStyleData* data = (MapStyleData*)aData;
|
|
|
|
rule->MapStyleInto(data->mStyleContext, data->mPresContext);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-05 10:01:55 +04:00
|
|
|
mDataCode = -1;
|
1998-05-27 03:14:09 +04:00
|
|
|
if (nsnull != mParent) {
|
|
|
|
mFont.ResetFrom(&(mParent->mFont), aPresContext);
|
|
|
|
mColor.ResetFrom(&(mParent->mColor), aPresContext);
|
|
|
|
mSpacing.ResetFrom(&(mParent->mSpacing), aPresContext);
|
|
|
|
mList.ResetFrom(&(mParent->mList), aPresContext);
|
|
|
|
mText.ResetFrom(&(mParent->mText), aPresContext);
|
|
|
|
mPosition.ResetFrom(&(mParent->mPosition), aPresContext);
|
|
|
|
mDisplay.ResetFrom(&(mParent->mDisplay), aPresContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFont.ResetFrom(nsnull, aPresContext);
|
|
|
|
mColor.ResetFrom(nsnull, aPresContext);
|
|
|
|
mSpacing.ResetFrom(nsnull, aPresContext);
|
|
|
|
mList.ResetFrom(nsnull, aPresContext);
|
|
|
|
mText.ResetFrom(nsnull, aPresContext);
|
|
|
|
mPosition.ResetFrom(nsnull, aPresContext);
|
|
|
|
mDisplay.ResetFrom(nsnull, aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
|
|
|
MapStyleData data(this, aPresContext);
|
|
|
|
mRules->EnumerateBackwards(MapStyleRule, &data);
|
|
|
|
}
|
1998-06-05 10:01:55 +04:00
|
|
|
if (-1 == mDataCode) {
|
|
|
|
mDataCode = 0;
|
|
|
|
}
|
1998-07-17 09:43:31 +04:00
|
|
|
if ((mDisplay.mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) ||
|
|
|
|
(mDisplay.mDisplay == NS_STYLE_DISPLAY_TABLE_CAPTION)) {
|
|
|
|
// time to emulate a sub-document
|
|
|
|
// This is ugly, but we need to map style once to determine display type
|
|
|
|
// then reset and map it again so that all local style is preserved
|
|
|
|
mFont.ResetFrom(nsnull, aPresContext);
|
|
|
|
mColor.ResetFrom(nsnull, aPresContext);
|
|
|
|
mSpacing.ResetFrom(nsnull, aPresContext);
|
|
|
|
mList.ResetFrom(nsnull, aPresContext);
|
|
|
|
mText.ResetFrom(nsnull, aPresContext);
|
|
|
|
mPosition.ResetFrom(nsnull, aPresContext);
|
|
|
|
mDisplay.ResetFrom(nsnull, aPresContext);
|
|
|
|
|
|
|
|
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
|
|
|
MapStyleData data(this, aPresContext);
|
|
|
|
mRules->EnumerateBackwards(MapStyleRule, &data);
|
|
|
|
}
|
|
|
|
}
|
1998-06-05 10:01:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleContextImpl::ForceUnique(void)
|
|
|
|
{
|
|
|
|
if (mDataCode <= 0) {
|
|
|
|
mDataCode = ++gLastDataCode;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
1998-05-19 01:04:26 +04:00
|
|
|
void StyleContextImpl::List(FILE* out, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
PRInt32 count = mRules->Count();
|
|
|
|
if (0 < count) {
|
|
|
|
fputs("{\n", out);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(index);
|
|
|
|
rule->List(out, aIndent + 1);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
fputs("}\n", out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("{}\n", out);
|
|
|
|
}
|
|
|
|
|
1998-06-26 09:49:01 +04:00
|
|
|
if (nsnull != mChild) {
|
|
|
|
StyleContextImpl* child = mChild;
|
|
|
|
do {
|
|
|
|
child->List(out, aIndent + 1);
|
1998-07-17 09:43:31 +04:00
|
|
|
child = child->mNextSibling;
|
1998-06-26 09:49:01 +04:00
|
|
|
} while (mChild != child);
|
|
|
|
}
|
1998-05-19 01:04:26 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_LAYOUT nsresult
|
|
|
|
NS_NewStyleContext(nsIStyleContext** aInstancePtrResult,
|
1998-05-27 03:14:09 +04:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsISupportsArray* aRules,
|
1998-07-17 09:43:31 +04:00
|
|
|
nsIContent* aContent,
|
1998-05-27 03:14:09 +04:00
|
|
|
nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-07-17 09:43:31 +04:00
|
|
|
StyleContextImpl* context = new StyleContextImpl(aParentContext, aRules, aContent, aPresContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
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);
|
|
|
|
}
|