diff --git a/content/base/src/nsStyleContext.cpp b/content/base/src/nsStyleContext.cpp index 154d872778b..71331cf051b 100644 --- a/content/base/src/nsStyleContext.cpp +++ b/content/base/src/nsStyleContext.cpp @@ -161,6 +161,7 @@ static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord, NS_RELEASE(parentContext); } } + break; case eStyleUnit_Percent: { @@ -651,10 +652,14 @@ public: virtual void ForceUnique(void); virtual void RecalcAutomaticData(nsIPresContext* aPresContext); + virtual void ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext); + virtual void List(FILE* out, PRInt32 aIndent); protected: void AppendChild(StyleContextImpl* aChild); + void RemoveChild(StyleContextImpl* aChild); StyleContextImpl* mParent; StyleContextImpl* mChild; @@ -769,8 +774,6 @@ StyleContextImpl::~StyleContextImpl() #endif } - - #ifdef DEBUG_REFS NS_IMPL_QUERY_INTERFACE(StyleContextImpl, kIStyleContextIID) @@ -825,6 +828,48 @@ void StyleContextImpl::AppendChild(StyleContextImpl* aChild) NS_ADDREF(aChild); } +void StyleContextImpl::RemoveChild(StyleContextImpl* aChild) +{ + NS_ASSERTION((nsnull != aChild) && (this == mChild->mParent), "bad argument"); + + if ((nsnull == aChild) || (this != mChild->mParent)) { + return; + } + + if (mEmptyChild == aChild) { + mEmptyChild = nsnull; + } + else { + if (aChild->mPrevSibling != aChild) { + if (mChild == aChild) { + mChild = mChild->mNextSibling; + } + aChild->mPrevSibling->mNextSibling = aChild->mNextSibling; + aChild->mNextSibling->mPrevSibling = aChild->mPrevSibling; + aChild->mNextSibling = aChild; + aChild->mPrevSibling = aChild; + } + else { + NS_ASSERTION(mChild == aChild, "bad sibling pointers"); + if (mChild == aChild) { + mChild = nsnull; + } + } + } + NS_RELEASE(aChild); +} + +void StyleContextImpl::ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext) +{ + if (aNewParentContext != mParent) { + mParent->RemoveChild(this); + mParent = (StyleContextImpl*)aNewParentContext; // weak ref + mParent->AppendChild(this); + RemapStyle(aPresContext); + } +} + nsISupportsArray* StyleContextImpl::GetStyleRules(void) const { NS_IF_ADDREF(mRules); @@ -1071,6 +1116,17 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mRules->EnumerateForwards(MapStyleRule, &data); } } + + if (nsnull != mChild) { + StyleContextImpl* child = mChild; + do { + child->RemapStyle(aPresContext); + child = child->mNextSibling; + } while (mChild != child); + } + if (nsnull != mEmptyChild) { + mEmptyChild->RemapStyle(aPresContext); + } return NS_OK; } diff --git a/layout/base/public/nsIStyleContext.h b/layout/base/public/nsIStyleContext.h index 32c7d532e28..4e59f73f748 100644 --- a/layout/base/public/nsIStyleContext.h +++ b/layout/base/public/nsIStyleContext.h @@ -203,6 +203,11 @@ public: // call if you change style data after creation virtual void RecalcAutomaticData(nsIPresContext* aPresContext) = 0; + // Change the parent of the context, only to be used for + // inserting or removing pseudo contexts + virtual void ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext) = 0; + // debugging virtual void List(FILE* out, PRInt32 aIndent) = 0; }; diff --git a/layout/base/src/nsStyleContext.cpp b/layout/base/src/nsStyleContext.cpp index 154d872778b..71331cf051b 100644 --- a/layout/base/src/nsStyleContext.cpp +++ b/layout/base/src/nsStyleContext.cpp @@ -161,6 +161,7 @@ static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord, NS_RELEASE(parentContext); } } + break; case eStyleUnit_Percent: { @@ -651,10 +652,14 @@ public: virtual void ForceUnique(void); virtual void RecalcAutomaticData(nsIPresContext* aPresContext); + virtual void ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext); + virtual void List(FILE* out, PRInt32 aIndent); protected: void AppendChild(StyleContextImpl* aChild); + void RemoveChild(StyleContextImpl* aChild); StyleContextImpl* mParent; StyleContextImpl* mChild; @@ -769,8 +774,6 @@ StyleContextImpl::~StyleContextImpl() #endif } - - #ifdef DEBUG_REFS NS_IMPL_QUERY_INTERFACE(StyleContextImpl, kIStyleContextIID) @@ -825,6 +828,48 @@ void StyleContextImpl::AppendChild(StyleContextImpl* aChild) NS_ADDREF(aChild); } +void StyleContextImpl::RemoveChild(StyleContextImpl* aChild) +{ + NS_ASSERTION((nsnull != aChild) && (this == mChild->mParent), "bad argument"); + + if ((nsnull == aChild) || (this != mChild->mParent)) { + return; + } + + if (mEmptyChild == aChild) { + mEmptyChild = nsnull; + } + else { + if (aChild->mPrevSibling != aChild) { + if (mChild == aChild) { + mChild = mChild->mNextSibling; + } + aChild->mPrevSibling->mNextSibling = aChild->mNextSibling; + aChild->mNextSibling->mPrevSibling = aChild->mPrevSibling; + aChild->mNextSibling = aChild; + aChild->mPrevSibling = aChild; + } + else { + NS_ASSERTION(mChild == aChild, "bad sibling pointers"); + if (mChild == aChild) { + mChild = nsnull; + } + } + } + NS_RELEASE(aChild); +} + +void StyleContextImpl::ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext) +{ + if (aNewParentContext != mParent) { + mParent->RemoveChild(this); + mParent = (StyleContextImpl*)aNewParentContext; // weak ref + mParent->AppendChild(this); + RemapStyle(aPresContext); + } +} + nsISupportsArray* StyleContextImpl::GetStyleRules(void) const { NS_IF_ADDREF(mRules); @@ -1071,6 +1116,17 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mRules->EnumerateForwards(MapStyleRule, &data); } } + + if (nsnull != mChild) { + StyleContextImpl* child = mChild; + do { + child->RemapStyle(aPresContext); + child = child->mNextSibling; + } while (mChild != child); + } + if (nsnull != mEmptyChild) { + mEmptyChild->RemapStyle(aPresContext); + } return NS_OK; } diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index 154d872778b..71331cf051b 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -161,6 +161,7 @@ static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord, NS_RELEASE(parentContext); } } + break; case eStyleUnit_Percent: { @@ -651,10 +652,14 @@ public: virtual void ForceUnique(void); virtual void RecalcAutomaticData(nsIPresContext* aPresContext); + virtual void ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext); + virtual void List(FILE* out, PRInt32 aIndent); protected: void AppendChild(StyleContextImpl* aChild); + void RemoveChild(StyleContextImpl* aChild); StyleContextImpl* mParent; StyleContextImpl* mChild; @@ -769,8 +774,6 @@ StyleContextImpl::~StyleContextImpl() #endif } - - #ifdef DEBUG_REFS NS_IMPL_QUERY_INTERFACE(StyleContextImpl, kIStyleContextIID) @@ -825,6 +828,48 @@ void StyleContextImpl::AppendChild(StyleContextImpl* aChild) NS_ADDREF(aChild); } +void StyleContextImpl::RemoveChild(StyleContextImpl* aChild) +{ + NS_ASSERTION((nsnull != aChild) && (this == mChild->mParent), "bad argument"); + + if ((nsnull == aChild) || (this != mChild->mParent)) { + return; + } + + if (mEmptyChild == aChild) { + mEmptyChild = nsnull; + } + else { + if (aChild->mPrevSibling != aChild) { + if (mChild == aChild) { + mChild = mChild->mNextSibling; + } + aChild->mPrevSibling->mNextSibling = aChild->mNextSibling; + aChild->mNextSibling->mPrevSibling = aChild->mPrevSibling; + aChild->mNextSibling = aChild; + aChild->mPrevSibling = aChild; + } + else { + NS_ASSERTION(mChild == aChild, "bad sibling pointers"); + if (mChild == aChild) { + mChild = nsnull; + } + } + } + NS_RELEASE(aChild); +} + +void StyleContextImpl::ReParent(nsIStyleContext* aNewParentContext, + nsIPresContext* aPresContext) +{ + if (aNewParentContext != mParent) { + mParent->RemoveChild(this); + mParent = (StyleContextImpl*)aNewParentContext; // weak ref + mParent->AppendChild(this); + RemapStyle(aPresContext); + } +} + nsISupportsArray* StyleContextImpl::GetStyleRules(void) const { NS_IF_ADDREF(mRules); @@ -1071,6 +1116,17 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext) mRules->EnumerateForwards(MapStyleRule, &data); } } + + if (nsnull != mChild) { + StyleContextImpl* child = mChild; + do { + child->RemapStyle(aPresContext); + child = child->mNextSibling; + } while (mChild != child); + } + if (nsnull != mEmptyChild) { + mEmptyChild->RemapStyle(aPresContext); + } return NS_OK; }