From 2d98616fca7d2e7e03cf471571274cccc30ea44b Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Sat, 24 Jul 1999 18:59:43 +0000 Subject: [PATCH] added some experimental CSS3 properties fixed style context impact reporting git-svn-id: svn://10.0.0.236/trunk@40987 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsStyleContext.cpp | 259 +++++++++---------- mozilla/layout/base/nsStyleConsts.h | 1 + mozilla/layout/base/public/nsIStyleContext.h | 15 ++ mozilla/layout/base/public/nsStyleConsts.h | 1 + mozilla/layout/base/public/nsStyleStruct.h | 19 +- mozilla/layout/base/src/nsStyleContext.cpp | 259 +++++++++---------- mozilla/layout/style/nsStyleContext.cpp | 259 +++++++++---------- 7 files changed, 387 insertions(+), 426 deletions(-) diff --git a/mozilla/content/base/src/nsStyleContext.cpp b/mozilla/content/base/src/nsStyleContext.cpp index ff4d5e8ebcb..db1c3273bf7 100644 --- a/mozilla/content/base/src/nsStyleContext.cpp +++ b/mozilla/content/base/src/nsStyleContext.cpp @@ -489,6 +489,8 @@ void StyleSpacingImpl::ResetFrom(const nsStyleSpacing* aParent, nsIPresContext* mOutlineWidth = medium; mOutlineStyle = NS_STYLE_BORDER_STYLE_NONE; mOutlineColor = NS_RGB(0, 0, 0); + + mFloatEdge = NS_STYLE_FLOAT_EDGE_CONTENT; mHasCachedMargin = PR_FALSE; mHasCachedPadding = PR_FALSE; @@ -649,13 +651,15 @@ PRInt32 StyleSpacingImpl::CalcDifference(const StyleSpacingImpl& aOther) const { if ((mMargin == aOther.mMargin) && (mPadding == aOther.mPadding) && - (mBorder == aOther.mBorder)) { + (mBorder == aOther.mBorder) && + (mFloatEdge == aOther.mFloatEdge)) { PRInt32 ix; for (ix = 0; ix < 4; ix++) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) || (mBorderColor[ix] != aOther.mBorderColor[ix])) { - if ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || - (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix])) { + if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) && + ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || + (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix]))) { return NS_STYLE_HINT_REFLOW; // border on or off } return NS_STYLE_HINT_VISUAL; @@ -746,6 +750,7 @@ void StylePositionImpl::ResetFrom(const nsStylePosition* aParent, nsIPresContext mHeight.SetAutoValue(); mMinHeight.SetCoordValue(0); mMaxHeight.Reset(); + mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT; mZIndex.SetAutoValue(); } @@ -759,6 +764,7 @@ PRInt32 StylePositionImpl::CalcDifference(const StylePositionImpl& aOther) const (mHeight == aOther.mHeight) && (mMinHeight == aOther.mMinHeight) && (mMaxHeight == aOther.mMaxHeight) && + (mBoxSizing == aOther.mBoxSizing) && (mZIndex == aOther.mZIndex)) { return NS_STYLE_HINT_NONE; } @@ -875,6 +881,11 @@ PRInt32 StyleDisplayImpl::CalcDifference(const StyleDisplayImpl& aOther) const (mClip == aOther.mClip)) { return NS_STYLE_HINT_NONE; } + if ((mVisible != aOther.mVisible) && + ((NS_STYLE_VISIBILITY_COLLAPSE == mVisible) || + (NS_STYLE_VISIBILITY_COLLAPSE == aOther.mVisible))) { + return NS_STYLE_HINT_REFLOW; + } return NS_STYLE_HINT_VISUAL; } return NS_STYLE_HINT_REFLOW; @@ -1214,6 +1225,67 @@ StyleContentImpl::CalcDifference(const StyleContentImpl& aOther) const return NS_STYLE_HINT_FRAMECHANGE; } +//----------------------- +// nsStyleUserInterface +// + +nsStyleUserInterface::nsStyleUserInterface(void) { } + +struct StyleUserInterfaceImpl: public nsStyleUserInterface { + StyleUserInterfaceImpl(void) { } + + void ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext); + PRInt32 CalcDifference(const StyleUserInterfaceImpl& aOther) const; + +private: // These are not allowed + StyleUserInterfaceImpl(const StyleUserInterfaceImpl& aOther); + StyleUserInterfaceImpl& operator=(const StyleUserInterfaceImpl& aOther); +}; + +void StyleUserInterfaceImpl::ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext) +{ + if (aParent) { + mUserInput = aParent->mUserInput; + mModifyContent = aParent->mModifyContent; + mAutoSelect = aParent->mAutoSelect; + mAutoTab = aParent->mAutoTab; + } + else { + mUserInput = NS_STYLE_USER_INPUT_AUTO; + mModifyContent = NS_STYLE_MODIFY_CONTENT_READ_ONLY; + mAutoSelect = NS_STYLE_AUTO_SELECT_NONE; + mAutoTab = NS_STYLE_AUTO_TAB_AUTO; + } + + mSelectionStyle = NS_STYLE_SELECTION_STYLE_ANY; + mKeyEquivalent = PRUnichar(0); // XXX what type should this be? + mResizer = NS_STYLE_RESIZER_AUTO; +} + +PRInt32 StyleUserInterfaceImpl::CalcDifference(const StyleUserInterfaceImpl& aOther) const +{ + if ((mUserInput == aOther.mUserInput) && + (mResizer == aOther.mResizer)) { + if ((mModifyContent == aOther.mModifyContent) && + (mSelectionStyle == aOther.mSelectionStyle)) { + if ((mAutoSelect == aOther.mAutoSelect) && + (mKeyEquivalent == aOther.mKeyEquivalent) && + (mAutoTab == aOther.mAutoTab) && + (mResizer == aOther.mResizer)) { + return NS_STYLE_HINT_NONE; + } + return NS_STYLE_HINT_CONTENT; + } + return NS_STYLE_HINT_VISUAL; + } + if ((mUserInput != aOther.mUserInput) && + ((NS_STYLE_USER_INPUT_NONE == mUserInput) || + (NS_STYLE_USER_INPUT_NONE == aOther.mUserInput))) { + return NS_STYLE_HINT_FRAMECHANGE; + } + return NS_STYLE_HINT_VISUAL; +} + //---------------------------------------------------------------------- class StyleContextImpl : public nsIStyleContext { @@ -1266,15 +1338,16 @@ protected: PRInt32 mDataCode; // the style data... - StyleFontImpl mFont; - StyleColorImpl mColor; - StyleSpacingImpl mSpacing; - StyleListImpl mList; - StylePositionImpl mPosition; - StyleTextImpl mText; - StyleDisplayImpl mDisplay; - StyleTableImpl* mTable; - StyleContentImpl* mContent; + StyleFontImpl mFont; + StyleColorImpl mColor; + StyleSpacingImpl mSpacing; + StyleListImpl mList; + StylePositionImpl mPosition; + StyleTextImpl mText; + StyleDisplayImpl mDisplay; + StyleTableImpl mTable; + StyleContentImpl mContent; + StyleUserInterfaceImpl mUserInterface; #ifdef DEBUG_REFS PRInt32 mInstance; @@ -1311,8 +1384,9 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, mPosition(), mText(), mDisplay(), - mTable(nsnull), - mContent(nsnull) + mTable(), + mContent(), + mUserInterface() { NS_INIT_REFCNT(); NS_IF_ADDREF(mPseudoTag); @@ -1351,16 +1425,6 @@ StyleContextImpl::~StyleContextImpl() NS_IF_RELEASE(mRules); - if (mTable) { - delete mTable; - mTable = nsnull; - } - - if (mContent) { - delete mContent; - mContent = nsnull; - } - #ifdef DEBUG_REFS fprintf(stdout, "%d of %d - StyleContext\n", mInstance, gInstanceCount); --gInstanceCount; @@ -1639,43 +1703,14 @@ const nsStyleStruct* StyleContextImpl::GetStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // lazy creation - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has content data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1710,43 +1745,14 @@ nsStyleStruct* StyleContextImpl::GetMutableStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // this one gets created lazily - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1795,18 +1801,24 @@ StyleContextImpl::RemapStyle(nsIPresContext* 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); + mText.ResetFrom(&(mParent->mText), aPresContext); mDisplay.ResetFrom(&(mParent->mDisplay), aPresContext); + mTable.ResetFrom(&(mParent->mTable), aPresContext); + mContent.ResetFrom(&(mParent->mContent), aPresContext); + mUserInterface.ResetFrom(&(mParent->mUserInterface), 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); + mText.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); } PRUint32 cnt = 0; @@ -1851,6 +1863,9 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mText.ResetFrom(nsnull, aPresContext); mPosition.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); mDisplay.mVisible = visible; mDisplay.mDirection = direction; @@ -1951,53 +1966,19 @@ StyleContextImpl::CalcStyleDifference(nsIStyleContext* aOther, PRInt32& aHint) c } } if (aHint < NS_STYLE_HINT_MAX) { - if (mTable) { - if (other->mTable) { - hint = mTable->CalcDifference(*(other->mTable)); - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - if (other->mTable) { - hint = NS_STYLE_HINT_REFLOW; - } - else { - hint = NS_STYLE_HINT_NONE; - } - } + hint = mTable.CalcDifference(other->mTable); if (aHint < hint) { aHint = hint; } } if (aHint < NS_STYLE_HINT_MAX) { - if (mContent) { - if (other->mContent) { - hint = mContent->CalcDifference(*(other->mContent)); - } - else { - if (mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - } - else { - if (other->mContent) { - if (other->mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - hint = NS_STYLE_HINT_NONE; - } + hint = mContent.CalcDifference(other->mContent); + if (aHint < hint) { + aHint = hint; } + } + if (aHint < NS_STYLE_HINT_MAX) { + hint = mUserInterface.CalcDifference(other->mUserInterface); if (aHint < hint) { aHint = hint; } diff --git a/mozilla/layout/base/nsStyleConsts.h b/mozilla/layout/base/nsStyleConsts.h index 08b2090369c..8f3d612b5d2 100644 --- a/mozilla/layout/base/nsStyleConsts.h +++ b/mozilla/layout/base/nsStyleConsts.h @@ -264,6 +264,7 @@ #define NS_STYLE_DISPLAY_TABLE_ROW 15 #define NS_STYLE_DISPLAY_TABLE_CELL 16 #define NS_STYLE_DISPLAY_TABLE_CAPTION 17 +#define NS_STYLE_DISPLAY_MENU 18 // See nsStyleDisplay #define NS_STYLE_FLOAT_NONE 0 diff --git a/mozilla/layout/base/public/nsIStyleContext.h b/mozilla/layout/base/public/nsIStyleContext.h index cf06ee8ca78..77fdb6aa11c 100644 --- a/mozilla/layout/base/public/nsIStyleContext.h +++ b/mozilla/layout/base/public/nsIStyleContext.h @@ -81,6 +81,8 @@ struct nsStyleSpacing: public nsStyleStruct { 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; @@ -145,6 +147,7 @@ struct nsStylePosition : public nsStyleStruct { 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] @@ -280,6 +283,18 @@ protected: nsString* mQuotes; }; +struct nsStyleUserInterface: public nsStyleStruct { + PRUint8 mUserInput; // [inherited] + PRUint8 mModifyContent; // [inherited] + PRUint8 mSelectionStyle; // [reset] + PRUint8 mAutoSelect; // [inherited] + PRUnichar mKeyEquivalent; // [reset] XXX what type should this be? + PRUint8 mAutoTab; // [inherited] + PRUint8 mResizer; // [reset] +protected: + nsStyleUserInterface(void); +}; + #define BORDER_PRECEDENT_EQUAL 0 #define BORDER_PRECEDENT_LOWER 1 #define BORDER_PRECEDENT_HIGHER 2 diff --git a/mozilla/layout/base/public/nsStyleConsts.h b/mozilla/layout/base/public/nsStyleConsts.h index 08b2090369c..8f3d612b5d2 100644 --- a/mozilla/layout/base/public/nsStyleConsts.h +++ b/mozilla/layout/base/public/nsStyleConsts.h @@ -264,6 +264,7 @@ #define NS_STYLE_DISPLAY_TABLE_ROW 15 #define NS_STYLE_DISPLAY_TABLE_CELL 16 #define NS_STYLE_DISPLAY_TABLE_CAPTION 17 +#define NS_STYLE_DISPLAY_MENU 18 // See nsStyleDisplay #define NS_STYLE_FLOAT_NONE 0 diff --git a/mozilla/layout/base/public/nsStyleStruct.h b/mozilla/layout/base/public/nsStyleStruct.h index a387c0cf630..081a2dc28bd 100644 --- a/mozilla/layout/base/public/nsStyleStruct.h +++ b/mozilla/layout/base/public/nsStyleStruct.h @@ -19,15 +19,16 @@ #define nsStyleStruct_h___ enum nsStyleStructID { - eStyleStruct_Font = 1, - eStyleStruct_Color = 2, - eStyleStruct_Spacing = 3, - eStyleStruct_List = 4, - eStyleStruct_Position = 5, - eStyleStruct_Text = 6, - eStyleStruct_Display = 7, - eStyleStruct_Table = 8, - eStyleStruct_Content = 9 + eStyleStruct_Font = 1, + eStyleStruct_Color = 2, + eStyleStruct_Spacing = 3, + eStyleStruct_List = 4, + eStyleStruct_Position = 5, + eStyleStruct_Text = 6, + eStyleStruct_Display = 7, + eStyleStruct_Table = 8, + eStyleStruct_Content = 9, + eStyleStruct_UserInterface = 10 }; diff --git a/mozilla/layout/base/src/nsStyleContext.cpp b/mozilla/layout/base/src/nsStyleContext.cpp index ff4d5e8ebcb..db1c3273bf7 100644 --- a/mozilla/layout/base/src/nsStyleContext.cpp +++ b/mozilla/layout/base/src/nsStyleContext.cpp @@ -489,6 +489,8 @@ void StyleSpacingImpl::ResetFrom(const nsStyleSpacing* aParent, nsIPresContext* mOutlineWidth = medium; mOutlineStyle = NS_STYLE_BORDER_STYLE_NONE; mOutlineColor = NS_RGB(0, 0, 0); + + mFloatEdge = NS_STYLE_FLOAT_EDGE_CONTENT; mHasCachedMargin = PR_FALSE; mHasCachedPadding = PR_FALSE; @@ -649,13 +651,15 @@ PRInt32 StyleSpacingImpl::CalcDifference(const StyleSpacingImpl& aOther) const { if ((mMargin == aOther.mMargin) && (mPadding == aOther.mPadding) && - (mBorder == aOther.mBorder)) { + (mBorder == aOther.mBorder) && + (mFloatEdge == aOther.mFloatEdge)) { PRInt32 ix; for (ix = 0; ix < 4; ix++) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) || (mBorderColor[ix] != aOther.mBorderColor[ix])) { - if ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || - (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix])) { + if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) && + ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || + (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix]))) { return NS_STYLE_HINT_REFLOW; // border on or off } return NS_STYLE_HINT_VISUAL; @@ -746,6 +750,7 @@ void StylePositionImpl::ResetFrom(const nsStylePosition* aParent, nsIPresContext mHeight.SetAutoValue(); mMinHeight.SetCoordValue(0); mMaxHeight.Reset(); + mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT; mZIndex.SetAutoValue(); } @@ -759,6 +764,7 @@ PRInt32 StylePositionImpl::CalcDifference(const StylePositionImpl& aOther) const (mHeight == aOther.mHeight) && (mMinHeight == aOther.mMinHeight) && (mMaxHeight == aOther.mMaxHeight) && + (mBoxSizing == aOther.mBoxSizing) && (mZIndex == aOther.mZIndex)) { return NS_STYLE_HINT_NONE; } @@ -875,6 +881,11 @@ PRInt32 StyleDisplayImpl::CalcDifference(const StyleDisplayImpl& aOther) const (mClip == aOther.mClip)) { return NS_STYLE_HINT_NONE; } + if ((mVisible != aOther.mVisible) && + ((NS_STYLE_VISIBILITY_COLLAPSE == mVisible) || + (NS_STYLE_VISIBILITY_COLLAPSE == aOther.mVisible))) { + return NS_STYLE_HINT_REFLOW; + } return NS_STYLE_HINT_VISUAL; } return NS_STYLE_HINT_REFLOW; @@ -1214,6 +1225,67 @@ StyleContentImpl::CalcDifference(const StyleContentImpl& aOther) const return NS_STYLE_HINT_FRAMECHANGE; } +//----------------------- +// nsStyleUserInterface +// + +nsStyleUserInterface::nsStyleUserInterface(void) { } + +struct StyleUserInterfaceImpl: public nsStyleUserInterface { + StyleUserInterfaceImpl(void) { } + + void ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext); + PRInt32 CalcDifference(const StyleUserInterfaceImpl& aOther) const; + +private: // These are not allowed + StyleUserInterfaceImpl(const StyleUserInterfaceImpl& aOther); + StyleUserInterfaceImpl& operator=(const StyleUserInterfaceImpl& aOther); +}; + +void StyleUserInterfaceImpl::ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext) +{ + if (aParent) { + mUserInput = aParent->mUserInput; + mModifyContent = aParent->mModifyContent; + mAutoSelect = aParent->mAutoSelect; + mAutoTab = aParent->mAutoTab; + } + else { + mUserInput = NS_STYLE_USER_INPUT_AUTO; + mModifyContent = NS_STYLE_MODIFY_CONTENT_READ_ONLY; + mAutoSelect = NS_STYLE_AUTO_SELECT_NONE; + mAutoTab = NS_STYLE_AUTO_TAB_AUTO; + } + + mSelectionStyle = NS_STYLE_SELECTION_STYLE_ANY; + mKeyEquivalent = PRUnichar(0); // XXX what type should this be? + mResizer = NS_STYLE_RESIZER_AUTO; +} + +PRInt32 StyleUserInterfaceImpl::CalcDifference(const StyleUserInterfaceImpl& aOther) const +{ + if ((mUserInput == aOther.mUserInput) && + (mResizer == aOther.mResizer)) { + if ((mModifyContent == aOther.mModifyContent) && + (mSelectionStyle == aOther.mSelectionStyle)) { + if ((mAutoSelect == aOther.mAutoSelect) && + (mKeyEquivalent == aOther.mKeyEquivalent) && + (mAutoTab == aOther.mAutoTab) && + (mResizer == aOther.mResizer)) { + return NS_STYLE_HINT_NONE; + } + return NS_STYLE_HINT_CONTENT; + } + return NS_STYLE_HINT_VISUAL; + } + if ((mUserInput != aOther.mUserInput) && + ((NS_STYLE_USER_INPUT_NONE == mUserInput) || + (NS_STYLE_USER_INPUT_NONE == aOther.mUserInput))) { + return NS_STYLE_HINT_FRAMECHANGE; + } + return NS_STYLE_HINT_VISUAL; +} + //---------------------------------------------------------------------- class StyleContextImpl : public nsIStyleContext { @@ -1266,15 +1338,16 @@ protected: PRInt32 mDataCode; // the style data... - StyleFontImpl mFont; - StyleColorImpl mColor; - StyleSpacingImpl mSpacing; - StyleListImpl mList; - StylePositionImpl mPosition; - StyleTextImpl mText; - StyleDisplayImpl mDisplay; - StyleTableImpl* mTable; - StyleContentImpl* mContent; + StyleFontImpl mFont; + StyleColorImpl mColor; + StyleSpacingImpl mSpacing; + StyleListImpl mList; + StylePositionImpl mPosition; + StyleTextImpl mText; + StyleDisplayImpl mDisplay; + StyleTableImpl mTable; + StyleContentImpl mContent; + StyleUserInterfaceImpl mUserInterface; #ifdef DEBUG_REFS PRInt32 mInstance; @@ -1311,8 +1384,9 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, mPosition(), mText(), mDisplay(), - mTable(nsnull), - mContent(nsnull) + mTable(), + mContent(), + mUserInterface() { NS_INIT_REFCNT(); NS_IF_ADDREF(mPseudoTag); @@ -1351,16 +1425,6 @@ StyleContextImpl::~StyleContextImpl() NS_IF_RELEASE(mRules); - if (mTable) { - delete mTable; - mTable = nsnull; - } - - if (mContent) { - delete mContent; - mContent = nsnull; - } - #ifdef DEBUG_REFS fprintf(stdout, "%d of %d - StyleContext\n", mInstance, gInstanceCount); --gInstanceCount; @@ -1639,43 +1703,14 @@ const nsStyleStruct* StyleContextImpl::GetStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // lazy creation - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has content data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1710,43 +1745,14 @@ nsStyleStruct* StyleContextImpl::GetMutableStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // this one gets created lazily - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1795,18 +1801,24 @@ StyleContextImpl::RemapStyle(nsIPresContext* 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); + mText.ResetFrom(&(mParent->mText), aPresContext); mDisplay.ResetFrom(&(mParent->mDisplay), aPresContext); + mTable.ResetFrom(&(mParent->mTable), aPresContext); + mContent.ResetFrom(&(mParent->mContent), aPresContext); + mUserInterface.ResetFrom(&(mParent->mUserInterface), 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); + mText.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); } PRUint32 cnt = 0; @@ -1851,6 +1863,9 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mText.ResetFrom(nsnull, aPresContext); mPosition.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); mDisplay.mVisible = visible; mDisplay.mDirection = direction; @@ -1951,53 +1966,19 @@ StyleContextImpl::CalcStyleDifference(nsIStyleContext* aOther, PRInt32& aHint) c } } if (aHint < NS_STYLE_HINT_MAX) { - if (mTable) { - if (other->mTable) { - hint = mTable->CalcDifference(*(other->mTable)); - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - if (other->mTable) { - hint = NS_STYLE_HINT_REFLOW; - } - else { - hint = NS_STYLE_HINT_NONE; - } - } + hint = mTable.CalcDifference(other->mTable); if (aHint < hint) { aHint = hint; } } if (aHint < NS_STYLE_HINT_MAX) { - if (mContent) { - if (other->mContent) { - hint = mContent->CalcDifference(*(other->mContent)); - } - else { - if (mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - } - else { - if (other->mContent) { - if (other->mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - hint = NS_STYLE_HINT_NONE; - } + hint = mContent.CalcDifference(other->mContent); + if (aHint < hint) { + aHint = hint; } + } + if (aHint < NS_STYLE_HINT_MAX) { + hint = mUserInterface.CalcDifference(other->mUserInterface); if (aHint < hint) { aHint = hint; } diff --git a/mozilla/layout/style/nsStyleContext.cpp b/mozilla/layout/style/nsStyleContext.cpp index ff4d5e8ebcb..db1c3273bf7 100644 --- a/mozilla/layout/style/nsStyleContext.cpp +++ b/mozilla/layout/style/nsStyleContext.cpp @@ -489,6 +489,8 @@ void StyleSpacingImpl::ResetFrom(const nsStyleSpacing* aParent, nsIPresContext* mOutlineWidth = medium; mOutlineStyle = NS_STYLE_BORDER_STYLE_NONE; mOutlineColor = NS_RGB(0, 0, 0); + + mFloatEdge = NS_STYLE_FLOAT_EDGE_CONTENT; mHasCachedMargin = PR_FALSE; mHasCachedPadding = PR_FALSE; @@ -649,13 +651,15 @@ PRInt32 StyleSpacingImpl::CalcDifference(const StyleSpacingImpl& aOther) const { if ((mMargin == aOther.mMargin) && (mPadding == aOther.mPadding) && - (mBorder == aOther.mBorder)) { + (mBorder == aOther.mBorder) && + (mFloatEdge == aOther.mFloatEdge)) { PRInt32 ix; for (ix = 0; ix < 4; ix++) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) || (mBorderColor[ix] != aOther.mBorderColor[ix])) { - if ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || - (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix])) { + if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) && + ((NS_STYLE_BORDER_STYLE_NONE == mBorderStyle[ix]) || + (NS_STYLE_BORDER_STYLE_NONE == aOther.mBorderStyle[ix]))) { return NS_STYLE_HINT_REFLOW; // border on or off } return NS_STYLE_HINT_VISUAL; @@ -746,6 +750,7 @@ void StylePositionImpl::ResetFrom(const nsStylePosition* aParent, nsIPresContext mHeight.SetAutoValue(); mMinHeight.SetCoordValue(0); mMaxHeight.Reset(); + mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT; mZIndex.SetAutoValue(); } @@ -759,6 +764,7 @@ PRInt32 StylePositionImpl::CalcDifference(const StylePositionImpl& aOther) const (mHeight == aOther.mHeight) && (mMinHeight == aOther.mMinHeight) && (mMaxHeight == aOther.mMaxHeight) && + (mBoxSizing == aOther.mBoxSizing) && (mZIndex == aOther.mZIndex)) { return NS_STYLE_HINT_NONE; } @@ -875,6 +881,11 @@ PRInt32 StyleDisplayImpl::CalcDifference(const StyleDisplayImpl& aOther) const (mClip == aOther.mClip)) { return NS_STYLE_HINT_NONE; } + if ((mVisible != aOther.mVisible) && + ((NS_STYLE_VISIBILITY_COLLAPSE == mVisible) || + (NS_STYLE_VISIBILITY_COLLAPSE == aOther.mVisible))) { + return NS_STYLE_HINT_REFLOW; + } return NS_STYLE_HINT_VISUAL; } return NS_STYLE_HINT_REFLOW; @@ -1214,6 +1225,67 @@ StyleContentImpl::CalcDifference(const StyleContentImpl& aOther) const return NS_STYLE_HINT_FRAMECHANGE; } +//----------------------- +// nsStyleUserInterface +// + +nsStyleUserInterface::nsStyleUserInterface(void) { } + +struct StyleUserInterfaceImpl: public nsStyleUserInterface { + StyleUserInterfaceImpl(void) { } + + void ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext); + PRInt32 CalcDifference(const StyleUserInterfaceImpl& aOther) const; + +private: // These are not allowed + StyleUserInterfaceImpl(const StyleUserInterfaceImpl& aOther); + StyleUserInterfaceImpl& operator=(const StyleUserInterfaceImpl& aOther); +}; + +void StyleUserInterfaceImpl::ResetFrom(const nsStyleUserInterface* aParent, nsIPresContext* aPresContext) +{ + if (aParent) { + mUserInput = aParent->mUserInput; + mModifyContent = aParent->mModifyContent; + mAutoSelect = aParent->mAutoSelect; + mAutoTab = aParent->mAutoTab; + } + else { + mUserInput = NS_STYLE_USER_INPUT_AUTO; + mModifyContent = NS_STYLE_MODIFY_CONTENT_READ_ONLY; + mAutoSelect = NS_STYLE_AUTO_SELECT_NONE; + mAutoTab = NS_STYLE_AUTO_TAB_AUTO; + } + + mSelectionStyle = NS_STYLE_SELECTION_STYLE_ANY; + mKeyEquivalent = PRUnichar(0); // XXX what type should this be? + mResizer = NS_STYLE_RESIZER_AUTO; +} + +PRInt32 StyleUserInterfaceImpl::CalcDifference(const StyleUserInterfaceImpl& aOther) const +{ + if ((mUserInput == aOther.mUserInput) && + (mResizer == aOther.mResizer)) { + if ((mModifyContent == aOther.mModifyContent) && + (mSelectionStyle == aOther.mSelectionStyle)) { + if ((mAutoSelect == aOther.mAutoSelect) && + (mKeyEquivalent == aOther.mKeyEquivalent) && + (mAutoTab == aOther.mAutoTab) && + (mResizer == aOther.mResizer)) { + return NS_STYLE_HINT_NONE; + } + return NS_STYLE_HINT_CONTENT; + } + return NS_STYLE_HINT_VISUAL; + } + if ((mUserInput != aOther.mUserInput) && + ((NS_STYLE_USER_INPUT_NONE == mUserInput) || + (NS_STYLE_USER_INPUT_NONE == aOther.mUserInput))) { + return NS_STYLE_HINT_FRAMECHANGE; + } + return NS_STYLE_HINT_VISUAL; +} + //---------------------------------------------------------------------- class StyleContextImpl : public nsIStyleContext { @@ -1266,15 +1338,16 @@ protected: PRInt32 mDataCode; // the style data... - StyleFontImpl mFont; - StyleColorImpl mColor; - StyleSpacingImpl mSpacing; - StyleListImpl mList; - StylePositionImpl mPosition; - StyleTextImpl mText; - StyleDisplayImpl mDisplay; - StyleTableImpl* mTable; - StyleContentImpl* mContent; + StyleFontImpl mFont; + StyleColorImpl mColor; + StyleSpacingImpl mSpacing; + StyleListImpl mList; + StylePositionImpl mPosition; + StyleTextImpl mText; + StyleDisplayImpl mDisplay; + StyleTableImpl mTable; + StyleContentImpl mContent; + StyleUserInterfaceImpl mUserInterface; #ifdef DEBUG_REFS PRInt32 mInstance; @@ -1311,8 +1384,9 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, mPosition(), mText(), mDisplay(), - mTable(nsnull), - mContent(nsnull) + mTable(), + mContent(), + mUserInterface() { NS_INIT_REFCNT(); NS_IF_ADDREF(mPseudoTag); @@ -1351,16 +1425,6 @@ StyleContextImpl::~StyleContextImpl() NS_IF_RELEASE(mRules); - if (mTable) { - delete mTable; - mTable = nsnull; - } - - if (mContent) { - delete mContent; - mContent = nsnull; - } - #ifdef DEBUG_REFS fprintf(stdout, "%d of %d - StyleContext\n", mInstance, gInstanceCount); --gInstanceCount; @@ -1639,43 +1703,14 @@ const nsStyleStruct* StyleContextImpl::GetStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // lazy creation - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has content data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1710,43 +1745,14 @@ nsStyleStruct* StyleContextImpl::GetMutableStyleData(nsStyleStructID aSID) case eStyleStruct_Display: result = &mDisplay; break; - case eStyleStruct_Table: // this one gets created lazily - if (nsnull == mTable) { - mTable = new StyleTableImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mTable) { - break; - } - parent = parent->mParent; - } - if (parent) { - mTable->ResetFrom(parent->mTable, nsnull); - } - else { - mTable->ResetFrom(nsnull, nsnull); - } - } - result = mTable; + case eStyleStruct_Table: + result = &mTable; break; - case eStyleStruct_Content: // this one gets created lazily - if (nsnull == mContent) { - mContent = new StyleContentImpl(); - StyleContextImpl* parent = mParent; - while (parent) { // find first parent that has table data so we can inherit from it - if (parent->mContent) { - break; - } - parent = parent->mParent; - } - if (parent) { - mContent->ResetFrom(parent->mContent, nsnull); - } - else { - mContent->ResetFrom(nsnull, nsnull); - } - } - result = mContent; + case eStyleStruct_Content: + result = &mContent; + break; + case eStyleStruct_UserInterface: + result = &mUserInterface; break; default: NS_ERROR("Invalid style struct id"); @@ -1795,18 +1801,24 @@ StyleContextImpl::RemapStyle(nsIPresContext* 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); + mText.ResetFrom(&(mParent->mText), aPresContext); mDisplay.ResetFrom(&(mParent->mDisplay), aPresContext); + mTable.ResetFrom(&(mParent->mTable), aPresContext); + mContent.ResetFrom(&(mParent->mContent), aPresContext); + mUserInterface.ResetFrom(&(mParent->mUserInterface), 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); + mText.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); } PRUint32 cnt = 0; @@ -1851,6 +1863,9 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mText.ResetFrom(nsnull, aPresContext); mPosition.ResetFrom(nsnull, aPresContext); mDisplay.ResetFrom(nsnull, aPresContext); + mTable.ResetFrom(nsnull, aPresContext); + mContent.ResetFrom(nsnull, aPresContext); + mUserInterface.ResetFrom(nsnull, aPresContext); mDisplay.mVisible = visible; mDisplay.mDirection = direction; @@ -1951,53 +1966,19 @@ StyleContextImpl::CalcStyleDifference(nsIStyleContext* aOther, PRInt32& aHint) c } } if (aHint < NS_STYLE_HINT_MAX) { - if (mTable) { - if (other->mTable) { - hint = mTable->CalcDifference(*(other->mTable)); - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - if (other->mTable) { - hint = NS_STYLE_HINT_REFLOW; - } - else { - hint = NS_STYLE_HINT_NONE; - } - } + hint = mTable.CalcDifference(other->mTable); if (aHint < hint) { aHint = hint; } } if (aHint < NS_STYLE_HINT_MAX) { - if (mContent) { - if (other->mContent) { - hint = mContent->CalcDifference(*(other->mContent)); - } - else { - if (mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - } - else { - if (other->mContent) { - if (other->mContent->ContentCount()) { - hint = NS_STYLE_HINT_FRAMECHANGE; - } - else { - hint = NS_STYLE_HINT_REFLOW; - } - } - else { - hint = NS_STYLE_HINT_NONE; - } + hint = mContent.CalcDifference(other->mContent); + if (aHint < hint) { + aHint = hint; } + } + if (aHint < NS_STYLE_HINT_MAX) { + hint = mUserInterface.CalcDifference(other->mUserInterface); if (aHint < hint) { aHint = hint; }