From fb99c83e0139816e8aeec604f9f2a89f2b7cb917 Mon Sep 17 00:00:00 2001 From: "troy%netscape.com" Date: Tue, 19 Oct 1999 14:41:55 +0000 Subject: [PATCH] Changes to frame property API (code's not being used yet) --- layout/base/nsFrameManager.cpp | 66 ++++++++++++++++--------- layout/base/public/nsIFrameManager.h | 7 +-- layout/html/base/src/nsFrameManager.cpp | 66 ++++++++++++++++--------- 3 files changed, 90 insertions(+), 49 deletions(-) diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index 03adda70c4b..befc2f938d2 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -255,7 +255,10 @@ private: // Removes the property associated with the given frame, and destroys // the property value - void RemovePropertyForFrame(nsIFrame* aFrame); + void RemovePropertyForFrame(nsIPresContext* aPresContext, nsIFrame* aFrame); + + // Remove and destroy all remaining properties + void RemoveAllProperties(nsIPresContext* aPresContext); }; nsIPresShell* mPresShell; // weak link, because the pres shell owns us @@ -281,9 +284,9 @@ private: void RevokePostedEvents(); CantRenderReplacedElementEvent** FindPostedEventFor(nsIFrame* aFrame); void DequeuePostedEventFor(nsIFrame* aFrame); - void DestroyPropertyList(); + void DestroyPropertyList(nsIPresContext* aPresContext); PropertyList* GetPropertyListFor(nsIAtom* aPropertyName) const; - void RemoveAllPropertiesFor(nsIFrame* aFrame); + void RemoveAllPropertiesFor(nsIPresContext* aPresContext, nsIFrame* aFrame); friend struct CantRenderReplacedElementEvent; static void HandlePLEvent(CantRenderReplacedElementEvent* aEvent); @@ -316,6 +319,9 @@ NS_IMPL_RELEASE(FrameManager) FrameManager::~FrameManager() { + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + // Revoke any events posted to the event queue that we haven't processed yet RevokePostedEvents(); @@ -327,15 +333,11 @@ FrameManager::~FrameManager() // we've destroyed the frame hierarchy because some frames may expect to be // able to retrieve their properties during destruction if (mRootFrame) { - nsIPresContext* presContext; - - mPresShell->GetPresContext(&presContext); mRootFrame->Destroy(*presContext); mRootFrame = nsnull; - NS_IF_RELEASE(presContext); } - DestroyPropertyList(); + DestroyPropertyList(presContext); } nsresult @@ -641,7 +643,10 @@ FrameManager::NotifyDestroyingFrame(nsIFrame* aFrame) DequeuePostedEventFor(aFrame); // Remove all properties associated with the frame - RemoveAllPropertiesFor(aFrame); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + RemoveAllPropertiesFor(presContext, aFrame); return NS_OK; } @@ -1551,13 +1556,14 @@ FrameHashTable::Dump(FILE* fp) #endif void -FrameManager::DestroyPropertyList() +FrameManager::DestroyPropertyList(nsIPresContext* aPresContext) { if (mPropertyList) { while (mPropertyList) { PropertyList* tmp = mPropertyList; mPropertyList = mPropertyList->mNext; + tmp->RemoveAllProperties(aPresContext); delete tmp; } } @@ -1578,10 +1584,11 @@ FrameManager::GetPropertyListFor(nsIAtom* aPropertyName) const } void -FrameManager::RemoveAllPropertiesFor(nsIFrame* aFrame) +FrameManager::RemoveAllPropertiesFor(nsIPresContext* aPresContext, + nsIFrame* aFrame) { for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) { - prop->RemovePropertyForFrame(aFrame); + prop->RemovePropertyForFrame(aPresContext, aFrame); } } @@ -1639,7 +1646,10 @@ FrameManager::SetFrameProperty(nsIFrame* aFrame, aOldValue = propertyList->mFrameValueMap->Insert(aFrame, aPropertyValue); if (aOldValue && propertyList->mDtorFunc) { - propertyList->mDtorFunc(aFrame, aPropertyName, aOldValue); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + propertyList->mDtorFunc(presContext, aFrame, aPropertyName, aOldValue); } return NS_OK; @@ -1653,7 +1663,10 @@ FrameManager::RemoveFrameProperty(nsIFrame* aFrame, PropertyList* propertyList = GetPropertyListFor(aPropertyName); if (propertyList) { - propertyList->RemovePropertyForFrame(aFrame); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + propertyList->RemovePropertyForFrame(presContext, aFrame); } return NS_OK; @@ -1821,40 +1834,47 @@ FrameManager::PropertyList::PropertyList(nsIAtom* aName, { } +FrameManager::PropertyList::~PropertyList() +{ + delete mFrameValueMap; +} + class DestroyPropertyValuesFunctor : public nsDSTNodeFunctor { public: - DestroyPropertyValuesFunctor(nsIAtom* aPropertyName, + DestroyPropertyValuesFunctor(nsIPresContext* aPresContext, + nsIAtom* aPropertyName, FMPropertyDtorFunc aDtorFunc) - : mPropertyName(aPropertyName), mDtorFunc(aDtorFunc) {} + : mPresContext(aPresContext), mPropertyName(aPropertyName), mDtorFunc(aDtorFunc) {} virtual void operator () (void *aKey, void *aValue) { - mDtorFunc((nsIFrame*)aKey, mPropertyName, aValue); + mDtorFunc(mPresContext, (nsIFrame*)aKey, mPropertyName, aValue); } + nsIPresContext* mPresContext; nsIAtom* mPropertyName; FMPropertyDtorFunc mDtorFunc; }; -FrameManager::PropertyList::~PropertyList() +void +FrameManager::PropertyList::RemoveAllProperties(nsIPresContext* aPresContext) { if (mDtorFunc) { - DestroyPropertyValuesFunctor functor(mName, mDtorFunc); + DestroyPropertyValuesFunctor functor(aPresContext, mName, mDtorFunc); // Enumerate any remaining frame/value pairs and destroy the value object mFrameValueMap->Enumerate(functor); } - - delete mFrameValueMap; } void -FrameManager::PropertyList::RemovePropertyForFrame(nsIFrame* aFrame) +FrameManager::PropertyList::RemovePropertyForFrame(nsIPresContext* aPresContext, + nsIFrame* aFrame) { void* value = mFrameValueMap->Remove(aFrame); if (value && mDtorFunc) { // Destroy the property value - mDtorFunc(aFrame, mName, value); + mDtorFunc(aPresContext, aFrame, mName, value); } } diff --git a/layout/base/public/nsIFrameManager.h b/layout/base/public/nsIFrameManager.h index c9fdff47523..67871d3d283 100644 --- a/layout/base/public/nsIFrameManager.h +++ b/layout/base/public/nsIFrameManager.h @@ -38,9 +38,10 @@ class nsStyleChangeList; // Calback function used to destroy the value associated with a // given property. used by RemoveFrameProperty() typedef void -(*FMPropertyDtorFunc)(nsIFrame* aFrame, - nsIAtom* aPropertyName, - void* aPropertyValue); +(*FMPropertyDtorFunc)(nsIPresContext* aPresContext, + nsIFrame* aFrame, + nsIAtom* aPropertyName, + void* aPropertyValue); // Option flags for GetFrameProperty() member function #define NS_IFRAME_MGR_REMOVE_PROPERTY 0x0001 diff --git a/layout/html/base/src/nsFrameManager.cpp b/layout/html/base/src/nsFrameManager.cpp index 03adda70c4b..befc2f938d2 100644 --- a/layout/html/base/src/nsFrameManager.cpp +++ b/layout/html/base/src/nsFrameManager.cpp @@ -255,7 +255,10 @@ private: // Removes the property associated with the given frame, and destroys // the property value - void RemovePropertyForFrame(nsIFrame* aFrame); + void RemovePropertyForFrame(nsIPresContext* aPresContext, nsIFrame* aFrame); + + // Remove and destroy all remaining properties + void RemoveAllProperties(nsIPresContext* aPresContext); }; nsIPresShell* mPresShell; // weak link, because the pres shell owns us @@ -281,9 +284,9 @@ private: void RevokePostedEvents(); CantRenderReplacedElementEvent** FindPostedEventFor(nsIFrame* aFrame); void DequeuePostedEventFor(nsIFrame* aFrame); - void DestroyPropertyList(); + void DestroyPropertyList(nsIPresContext* aPresContext); PropertyList* GetPropertyListFor(nsIAtom* aPropertyName) const; - void RemoveAllPropertiesFor(nsIFrame* aFrame); + void RemoveAllPropertiesFor(nsIPresContext* aPresContext, nsIFrame* aFrame); friend struct CantRenderReplacedElementEvent; static void HandlePLEvent(CantRenderReplacedElementEvent* aEvent); @@ -316,6 +319,9 @@ NS_IMPL_RELEASE(FrameManager) FrameManager::~FrameManager() { + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + // Revoke any events posted to the event queue that we haven't processed yet RevokePostedEvents(); @@ -327,15 +333,11 @@ FrameManager::~FrameManager() // we've destroyed the frame hierarchy because some frames may expect to be // able to retrieve their properties during destruction if (mRootFrame) { - nsIPresContext* presContext; - - mPresShell->GetPresContext(&presContext); mRootFrame->Destroy(*presContext); mRootFrame = nsnull; - NS_IF_RELEASE(presContext); } - DestroyPropertyList(); + DestroyPropertyList(presContext); } nsresult @@ -641,7 +643,10 @@ FrameManager::NotifyDestroyingFrame(nsIFrame* aFrame) DequeuePostedEventFor(aFrame); // Remove all properties associated with the frame - RemoveAllPropertiesFor(aFrame); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + RemoveAllPropertiesFor(presContext, aFrame); return NS_OK; } @@ -1551,13 +1556,14 @@ FrameHashTable::Dump(FILE* fp) #endif void -FrameManager::DestroyPropertyList() +FrameManager::DestroyPropertyList(nsIPresContext* aPresContext) { if (mPropertyList) { while (mPropertyList) { PropertyList* tmp = mPropertyList; mPropertyList = mPropertyList->mNext; + tmp->RemoveAllProperties(aPresContext); delete tmp; } } @@ -1578,10 +1584,11 @@ FrameManager::GetPropertyListFor(nsIAtom* aPropertyName) const } void -FrameManager::RemoveAllPropertiesFor(nsIFrame* aFrame) +FrameManager::RemoveAllPropertiesFor(nsIPresContext* aPresContext, + nsIFrame* aFrame) { for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) { - prop->RemovePropertyForFrame(aFrame); + prop->RemovePropertyForFrame(aPresContext, aFrame); } } @@ -1639,7 +1646,10 @@ FrameManager::SetFrameProperty(nsIFrame* aFrame, aOldValue = propertyList->mFrameValueMap->Insert(aFrame, aPropertyValue); if (aOldValue && propertyList->mDtorFunc) { - propertyList->mDtorFunc(aFrame, aPropertyName, aOldValue); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + propertyList->mDtorFunc(presContext, aFrame, aPropertyName, aOldValue); } return NS_OK; @@ -1653,7 +1663,10 @@ FrameManager::RemoveFrameProperty(nsIFrame* aFrame, PropertyList* propertyList = GetPropertyListFor(aPropertyName); if (propertyList) { - propertyList->RemovePropertyForFrame(aFrame); + nsCOMPtr presContext; + mPresShell->GetPresContext(getter_AddRefs(presContext)); + + propertyList->RemovePropertyForFrame(presContext, aFrame); } return NS_OK; @@ -1821,40 +1834,47 @@ FrameManager::PropertyList::PropertyList(nsIAtom* aName, { } +FrameManager::PropertyList::~PropertyList() +{ + delete mFrameValueMap; +} + class DestroyPropertyValuesFunctor : public nsDSTNodeFunctor { public: - DestroyPropertyValuesFunctor(nsIAtom* aPropertyName, + DestroyPropertyValuesFunctor(nsIPresContext* aPresContext, + nsIAtom* aPropertyName, FMPropertyDtorFunc aDtorFunc) - : mPropertyName(aPropertyName), mDtorFunc(aDtorFunc) {} + : mPresContext(aPresContext), mPropertyName(aPropertyName), mDtorFunc(aDtorFunc) {} virtual void operator () (void *aKey, void *aValue) { - mDtorFunc((nsIFrame*)aKey, mPropertyName, aValue); + mDtorFunc(mPresContext, (nsIFrame*)aKey, mPropertyName, aValue); } + nsIPresContext* mPresContext; nsIAtom* mPropertyName; FMPropertyDtorFunc mDtorFunc; }; -FrameManager::PropertyList::~PropertyList() +void +FrameManager::PropertyList::RemoveAllProperties(nsIPresContext* aPresContext) { if (mDtorFunc) { - DestroyPropertyValuesFunctor functor(mName, mDtorFunc); + DestroyPropertyValuesFunctor functor(aPresContext, mName, mDtorFunc); // Enumerate any remaining frame/value pairs and destroy the value object mFrameValueMap->Enumerate(functor); } - - delete mFrameValueMap; } void -FrameManager::PropertyList::RemovePropertyForFrame(nsIFrame* aFrame) +FrameManager::PropertyList::RemovePropertyForFrame(nsIPresContext* aPresContext, + nsIFrame* aFrame) { void* value = mFrameValueMap->Remove(aFrame); if (value && mDtorFunc) { // Destroy the property value - mDtorFunc(aFrame, mName, value); + mDtorFunc(aPresContext, aFrame, mName, value); } }