pjs/layout/base/public/nsIStyleContext.h

462 строки
17 KiB
C
Исходник Обычный вид История

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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1998-04-14 00:24:54 +04:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1998-04-14 00:24:54 +04:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-04-14 00:24:54 +04:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-04-14 00:24:54 +04:00
*/
#ifndef nsIStyleContext_h___
#define nsIStyleContext_h___
#include "nslayout.h"
#include "nsISupports.h"
#include "nsColor.h"
#include "nsCoord.h"
#include "nsMargin.h"
#include "nsRect.h"
1998-04-14 00:24:54 +04:00
#include "nsFont.h"
1998-12-18 01:58:23 +03:00
#include "nsVoidArray.h"
1998-04-29 03:54:06 +04:00
#include "nsStyleCoord.h"
#include "nsStyleStruct.h"
#include "nsStyleConsts.h"
#include "nsIStyleSet.h"
#include "nsCOMPtr.h"
#include "nsILanguageAtom.h"
1998-04-29 03:54:06 +04:00
class nsISizeOfHandler;
1998-04-14 00:24:54 +04:00
class nsIFrame;
class nsIPresContext;
class nsISupportsArray;
#define SHARE_STYLECONTEXTS
1998-04-14 00:24:54 +04:00
// The lifetime of these objects is managed by the nsIStyleContext.
struct nsStyleFont : public nsStyleStruct {
nsStyleFont(void);
~nsStyleFont(void);
nsFont mFont; // [inherited]
nsFont mFixedFont; // [inherited]
PRUint8 mFlags; // [inherited] See nsStyleConsts.h
1998-04-14 00:24:54 +04:00
protected:
nsStyleFont(const nsFont& aVariableFont, const nsFont& aFixedFont);
nsStyleFont(nsIPresContext* aPresContext);
1998-04-14 00:24:54 +04:00
};
struct nsStyleColor : public nsStyleStruct {
nsStyleColor(void);
~nsStyleColor(void);
nscolor mColor; // [inherited]
1998-04-14 00:24:54 +04:00
PRUint8 mBackgroundAttachment; // [reset] See nsStyleConsts.h
PRUint8 mBackgroundFlags; // [reset] See nsStyleConsts.h
PRUint8 mBackgroundRepeat; // [reset] See nsStyleConsts.h
1998-04-14 00:24:54 +04:00
nscolor mBackgroundColor; // [reset]
nscoord mBackgroundXPosition; // [reset]
nscoord mBackgroundYPosition; // [reset]
nsString mBackgroundImage; // [reset] absolute url string
PRUint8 mCursor; // [reset] See nsStyleConsts.h NS_STYLE_CURSOR_*
nsString mCursorImage; // [reset] url string
float mOpacity; // [inherited] percentage
PRBool BackgroundIsTransparent() const {return (mBackgroundFlags &
(NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE)) ==
(NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE);}
1998-04-14 00:24:54 +04:00
};
1998-04-21 04:02:44 +04:00
struct nsStyleSpacing: public nsStyleStruct {
nsStyleSpacing(void);
nsStyleSides mMargin; // [reset] length, percent, auto, inherit
nsStyleSides mPadding; // [reset] length, percent, inherit
1999-04-03 07:15:24 +04:00
nsStyleSides mBorder; // [reset] length, enum (see nsStyleConsts.h)
nsStyleSides mBorderRadius; // [reset] length, percent, inherit
nsStyleSides mOutlineRadius; // [reset] length, percent, inherit
// (top=topLeft, right=topRight, bottom=bottomRight, left=bottomLeft)
nsStyleCoord mOutlineWidth; // [reset] length, enum (see nsStyleConsts.h)
PRUint8 mFloatEdge; // [reset] see nsStyleConsts.h
PRBool GetMargin(nsMargin& aMargin) const;
PRBool GetPadding(nsMargin& aPadding) const;
PRBool GetBorder(nsMargin& aBorder) const;
PRBool GetBorderPadding(nsMargin& aBorderPadding) const;
PRUint8 GetBorderStyle(PRUint8 aSide) const;
void SetBorderStyle(PRUint8 aSide, PRUint8 aStyle);
PRBool GetBorderColor(PRUint8 aSide, nscolor& aColor) const; // PR_FALSE means TRANSPARENT
void SetBorderColor(PRUint8 aSide, nscolor aColor);
void SetBorderTransparent(PRUint8 aSide);
void UnsetBorderColor(PRUint8 aSide);
PRBool GetOutlineWidth(nscoord& aWidth) const; // PR_TRUE if pre-computed
PRUint8 GetOutlineStyle(void) const;
void SetOutlineStyle(PRUint8 aStyle);
PRBool GetOutlineColor(nscolor& aColor) const; // PR_FALSE means INVERT
void SetOutlineColor(nscolor aColor);
void SetOutlineInvert(void);
// XXX these are deprecated methods
void CalcMarginFor(const nsIFrame* aFrame, nsMargin& aMargin) const;
void CalcPaddingFor(const nsIFrame* aFrame, nsMargin& aPadding) const;
void CalcBorderFor(const nsIFrame* aFrame, nsMargin& aBorder) const;
void CalcBorderPaddingFor(const nsIFrame* aFrame, nsMargin& aBorderPadding) const;
1998-04-21 04:02:44 +04:00
protected:
PRPackedBool mHasCachedMargin;
PRPackedBool mHasCachedPadding;
PRPackedBool mHasCachedBorder;
PRPackedBool mHasCachedOutline;
nsMargin mCachedMargin;
nsMargin mCachedPadding;
nsMargin mCachedBorder;
nsMargin mCachedBorderPadding;
nscoord mCachedOutlineWidth;
PRUint8 mBorderStyle[4]; // [reset] See nsStyleConsts.h
nscolor mBorderColor[4]; // [reset]
PRUint8 mOutlineStyle; // [reset] See nsStyleConsts.h
nscolor mOutlineColor; // [reset]
1998-04-21 04:02:44 +04:00
};
1998-04-14 00:24:54 +04:00
struct nsStyleList : public nsStyleStruct {
nsStyleList(void);
~nsStyleList(void);
PRUint8 mListStyleType; // [inherited] See nsStyleConsts.h
PRUint8 mListStylePosition; // [inherited]
nsString mListStyleImage; // [inherited] absolute url string
1998-04-14 00:24:54 +04:00
};
1998-04-23 03:29:01 +04:00
struct nsStylePosition : public nsStyleStruct {
nsStylePosition(void);
PRUint8 mPosition; // [reset] see nsStyleConsts.h
nsStyleSides mOffset; // [reset]
1998-11-06 03:48:14 +03:00
nsStyleCoord mWidth; // [reset] coord, percent, auto, inherit
nsStyleCoord mMinWidth; // [reset] coord, percent, inherit
nsStyleCoord mMaxWidth; // [reset] coord, percent, null, inherit
nsStyleCoord mHeight; // [reset] coord, percent, auto, inherit
nsStyleCoord mMinHeight; // [reset] coord, percent, inherit
nsStyleCoord mMaxHeight; // [reset] coord, percent, null, inherit
PRUint8 mBoxSizing; // [reset] see nsStyleConsts.h
nsStyleCoord mZIndex; // [reset]
PRBool IsAbsolutelyPositioned() const {return (NS_STYLE_POSITION_ABSOLUTE == mPosition) ||
(NS_STYLE_POSITION_FIXED == mPosition);}
PRBool IsPositioned() const {return IsAbsolutelyPositioned() ||
(NS_STYLE_POSITION_RELATIVE == mPosition);}
1998-04-23 03:29:01 +04:00
};
struct nsStyleText : public nsStyleStruct {
nsStyleText(void);
PRUint8 mTextAlign; // [inherited] see nsStyleConsts.h
PRUint8 mTextDecoration; // [reset] see nsStyleConsts.h
PRUint8 mTextTransform; // [inherited] see nsStyleConsts.h
PRUint8 mWhiteSpace; // [inherited] see nsStyleConsts.h
nsStyleCoord mLetterSpacing; // [inherited]
nsStyleCoord mLineHeight; // [inherited]
nsStyleCoord mTextIndent; // [inherited]
nsStyleCoord mWordSpacing; // [inherited]
nsStyleCoord mVerticalAlign; // [reset] see nsStyleConsts.h for enums
PRBool WhiteSpaceIsSignificant() const {
1999-04-28 02:07:02 +04:00
return mWhiteSpace == NS_STYLE_WHITESPACE_PRE;
}
};
struct nsStyleDisplay : public nsStyleStruct {
nsStyleDisplay(void);
PRUint8 mDirection; // [inherited] see nsStyleConsts.h NS_STYLE_DIRECTION_*
PRUint8 mDisplay; // [reset] see nsStyleConsts.h NS_STYLE_DISPLAY_*
PRUint8 mFloats; // [reset] see nsStyleConsts.h NS_STYLE_FLOAT_*
PRUint8 mBreakType; // [reset] see nsStyleConsts.h NS_STYLE_CLEAR_*
PRPackedBool mBreakBefore; // [reset]
PRPackedBool mBreakAfter; // [reset]
1999-02-02 06:24:23 +03:00
PRUint8 mVisible; // [inherited]
PRUint8 mOverflow; // [reset] see nsStyleConsts.h
PRUint8 mClipFlags; // [reset] see nsStyleConsts.h
#if 0
// XXX This is how it is defined in the CSS2 spec, but the errata
// changed it to be consistent with the positioning draft and how
// Nav and IE implement it
nsMargin mClip; // [reset] offsets from respective edge
#else
nsRect mClip; // [reset] offsets from upper-left border edge
#endif
nsCOMPtr<nsILanguageAtom> mLanguage; // [inherited]
1998-04-14 00:24:54 +04:00
PRBool IsBlockLevel() const {return (NS_STYLE_DISPLAY_BLOCK == mDisplay) ||
(NS_STYLE_DISPLAY_LIST_ITEM == mDisplay) ||
(NS_STYLE_DISPLAY_TABLE == mDisplay);}
1999-02-26 20:02:05 +03:00
PRBool IsFloating() const {
return NS_STYLE_FLOAT_NONE != mFloats;
}
PRBool IsVisible() const {
return (mVisible == NS_STYLE_VISIBILITY_VISIBLE);
}
PRBool IsVisibleOrCollapsed() const {
return ((mVisible == NS_STYLE_VISIBILITY_VISIBLE) ||
(mVisible == NS_STYLE_VISIBILITY_COLLAPSE));
}
};
struct nsStyleTable: public nsStyleStruct {
nsStyleTable(void);
PRUint8 mLayoutStrategy;// [reset] see nsStyleConsts.h NS_STYLE_TABLE_LAYOUT_*
PRUint8 mFrame; // [reset] see nsStyleConsts.h NS_STYLE_TABLE_FRAME_*
PRUint8 mRules; // [reset] see nsStyleConsts.h NS_STYLE_TABLE_RULES_*
1999-04-02 22:48:55 +04:00
PRUint8 mBorderCollapse;// [inherited]
nsStyleCoord mBorderSpacingX;// [inherited]
nsStyleCoord mBorderSpacingY;// [inherited]
nsStyleCoord mCellPadding; // [reset]
1999-04-02 22:48:55 +04:00
PRUint8 mCaptionSide; // [inherited]
PRUint8 mEmptyCells; // [inherited]
PRInt32 mCols; // [reset] an integer if set, or see nsStyleConsts.h NS_STYLE_TABLE_COLS_*
PRInt32 mSpan; // [reset] the number of columns spanned by a colgroup or col
nsStyleCoord mSpanWidth; // [reset] the amount of width this col gets from a spanning cell, if any
1998-04-14 00:24:54 +04:00
};
1999-04-02 22:48:55 +04:00
enum nsStyleContentType {
eStyleContentType_String = 1,
eStyleContentType_URL = 10,
eStyleContentType_Attr = 20,
eStyleContentType_Counter = 30,
eStyleContentType_Counters = 31,
eStyleContentType_OpenQuote = 40,
eStyleContentType_CloseQuote = 41,
eStyleContentType_NoOpenQuote = 42,
eStyleContentType_NoCloseQuote = 43
};
struct nsStyleContentData {
nsStyleContentType mType;
nsString mContent;
};
struct nsStyleCounterData {
nsString mCounter;
PRInt32 mValue;
};
struct nsStyleContent: public nsStyleStruct {
nsStyleContent(void);
~nsStyleContent(void);
1999-04-02 22:48:55 +04:00
PRUint32 ContentCount(void) const { return mContentCount; } // [reset]
nsresult GetContentAt(PRUint32 aIndex, nsStyleContentType& aType, nsString& aContent) const;
nsresult AllocateContents(PRUint32 aCount);
nsresult SetContentAt(PRUint32 aIndex, nsStyleContentType aType, const nsString& aContent);
PRUint32 CounterIncrementCount(void) const { return mIncrementCount; } // [reset]
nsresult GetCounterIncrementAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aIncrement) const;
nsresult AllocateCounterIncrements(PRUint32 aCount);
nsresult SetCounterIncrementAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aIncrement);
PRUint32 CounterResetCount(void) const { return mResetCount; } // [reset]
nsresult GetCounterResetAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aValue) const;
nsresult AllocateCounterResets(PRUint32 aCount);
nsresult SetCounterResetAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aValue);
nsStyleCoord mMarkerOffset; // [reset]
PRUint32 QuotesCount(void) const { return mQuotesCount; } // [inherited]
nsresult GetQuotesAt(PRUint32 aIndex, nsString& aOpen, nsString& aClose) const;
nsresult AllocateQuotes(PRUint32 aCount);
nsresult SetQuotesAt(PRUint32 aIndex, const nsString& aOpen, const nsString& aClose);
protected:
1999-04-02 22:48:55 +04:00
PRUint32 mContentCount;
nsStyleContentData* mContents;
PRUint32 mIncrementCount;
nsStyleCounterData* mIncrements;
PRUint32 mResetCount;
nsStyleCounterData* mResets;
PRUint32 mQuotesCount;
nsString* mQuotes;
};
struct nsStyleUserInterface: public nsStyleStruct {
nsStyleUserInterface(void);
PRUint8 mUserInput; // [inherited]
PRUint8 mUserModify; // [inherited] (modify-content)
PRUint8 mUserSelect; // [reset] (selection-style)
PRUint8 mUserFocus; // [inherited] (auto-select)
PRUnichar mKeyEquivalent; // [reset] XXX what type should this be?
PRUint8 mResizer; // [reset]
nsString mBehavior; // [reset] absolute url string
};
struct nsStylePrint: public nsStyleStruct {
nsStylePrint(void);
PRUint8 mPageBreakBefore; // [reset] see nsStyleConsts.h NS_STYLE_PAGE_BREAK_*
PRUint8 mPageBreakAfter; // [reset] see nsStyleConsts.h NS_STYLE_PAGE_BREAK_*
PRUint8 mPageBreakInside; // [reset] see nsStyleConsts.h NS_STYLE_PAGE_BREAK_*
nsString mPage;
PRUint32 mWidows; // [reset] = 2, number of isolated lines at the top of a page
PRUint32 mOrphans; // [reset] = 2, number of isolated lines at the bottom of a page
PRUint8 mMarks; // [reset] see nsStyleConsts.h NS_STYLE_PAGE_MARKS_*
nsStyleCoord mSizeWidth; // [reset] length, enum: see nsStyleConsts.h NS_STYLE_PAGE_SIZE_*
nsStyleCoord mSizeHeight; // [reset] length, enum: see nsStyleConsts.h NS_STYLE_PAGE_SIZE_*
};
1998-12-21 09:35:45 +03:00
#define BORDER_PRECEDENT_EQUAL 0
#define BORDER_PRECEDENT_LOWER 1
1998-12-18 01:58:23 +03:00
#define BORDER_PRECEDENT_HIGHER 2
struct nsBorderEdges;
1998-12-18 01:58:23 +03:00
/** an encapsulation of border edge info */
struct nsBorderEdge
{
/** the thickness of the edge */
1998-12-18 01:58:23 +03:00
nscoord mWidth;
/** the length of the edge */
1998-12-21 09:35:45 +03:00
nscoord mLength;
1998-12-18 01:58:23 +03:00
PRUint8 mStyle;
nscolor mColor;
/** which side does this edge represent? */
1998-12-18 01:58:23 +03:00
PRUint8 mSide;
/** if this edge is an outside edge, the border infor for the adjacent inside object */
nsBorderEdges * mInsideNeighbor;
1998-12-18 01:58:23 +03:00
nsBorderEdge();
};
inline nsBorderEdge::nsBorderEdge()
{
mWidth=0;
1998-12-21 09:35:45 +03:00
mLength=0;
1998-12-18 01:58:23 +03:00
mStyle=NS_STYLE_BORDER_STYLE_NONE;
mColor=0;
mSide=NS_SIDE_LEFT;
mInsideNeighbor = nsnull;
1998-12-18 01:58:23 +03:00
};
/** an encapsulation of a border defined by its edges
* owner of this struct is responsible for freeing any data stored in mEdges
*/
1998-12-18 01:58:23 +03:00
struct nsBorderEdges
{
nsVoidArray mEdges[4];
nsMargin mMaxBorderWidth;
PRPackedBool mOutsideEdge;
1998-12-18 01:58:23 +03:00
nsBorderEdges();
};
inline nsBorderEdges::nsBorderEdges()
{
mMaxBorderWidth.SizeTo(0,0,0,0);
1999-10-05 03:44:44 +04:00
mOutsideEdge = PR_TRUE;
1998-12-18 01:58:23 +03:00
};
1998-04-14 00:24:54 +04:00
//----------------------------------------------------------------------
#define NS_ISTYLECONTEXT_IID \
{ 0x26a4d970, 0xa342, 0x11d1, \
{0x89, 0x74, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
class nsIStyleContext : public nsISupports {
public:
1999-03-03 22:48:57 +03:00
static const nsIID& GetIID() { static nsIID iid = NS_ISTYLECONTEXT_IID; return iid; }
1998-04-14 00:24:54 +04:00
virtual PRBool Equals(const nsIStyleContext* aOther) const = 0;
virtual PRUint32 HashValue(void) const = 0;
virtual nsIStyleContext* GetParent(void) const = 0;
virtual nsISupportsArray* GetStyleRules(void) const = 0;
1998-05-21 00:32:57 +04:00
virtual PRInt32 GetStyleRuleCount(void) const = 0;
1998-11-03 23:15:59 +03:00
NS_IMETHOD GetPseudoType(nsIAtom*& aPseudoTag) const = 0;
1998-04-14 00:24:54 +04:00
1998-11-03 23:15:59 +03:00
NS_IMETHOD FindChildWithRules(const nsIAtom* aPseudoTag,
nsISupportsArray* aRules,
1998-11-03 23:15:59 +03:00
nsIStyleContext*& aResult) = 0;
// Fill a style struct with data
NS_IMETHOD GetStyle(nsStyleStructID aSID, nsStyleStruct& aStruct) const = 0;
// compute the effective difference between two contexts
NS_IMETHOD CalcStyleDifference(nsIStyleContext* aOther, PRInt32& aHint, PRBool aStopAtFirst = PR_FALSE) const = 0;
// debugging
virtual void List(FILE* out, PRInt32 aIndent) = 0;
virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) = 0;
#ifdef SHARE_STYLECONTEXTS
// sets aMatches to PR_TRUE if the style data of aStyleContextToMatch matches the
// style data of this, PR_FALSE otherwise
NS_IMETHOD StyleDataMatches(nsIStyleContext* aStyleContextToMatch, PRBool *aMatches) = 0;
NS_IMETHOD GetStyleContextKey(scKey &aKey) const = 0;
#endif
// -------------------------------------------------------------
// DEPRECATED METHODS - these are all going away, stop using them
1998-04-14 00:24:54 +04:00
// get a style data struct by ID, may return null
// Replace calls to this with calls to GetStyle();
virtual const nsStyleStruct* GetStyleData(nsStyleStructID aSID) = 0;
// get a style data struct by ID, may return null
virtual nsStyleStruct* GetMutableStyleData(nsStyleStructID aSID) = 0;
// call this to prevent context from getting shared
virtual void ForceUnique(void) = 0;
1998-04-29 03:54:06 +04:00
NS_IMETHOD RemapStyle(nsIPresContext* aPresContext, PRBool aRecurse = PR_TRUE) = 0;
1998-09-25 03:55:48 +04:00
1998-04-29 03:54:06 +04:00
// call if you change style data after creation
virtual void RecalcAutomaticData(nsIPresContext* aPresContext) = 0;
1998-04-14 00:24:54 +04:00
};
// this is private to nsStyleSet, don't call it
extern NS_LAYOUT nsresult
NS_NewStyleContext(nsIStyleContext** aInstancePtrResult,
nsIStyleContext* aParentContext,
1998-11-03 23:15:59 +03:00
nsIAtom* aPseudoType,
1998-04-14 00:24:54 +04:00
nsISupportsArray* aRules,
nsIPresContext* aPresContext);
1998-04-14 00:24:54 +04:00
#endif /* nsIStyleContext_h___ */