Bug 586041. Part 2: refactor RemoveChild. r=bas
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 01 Jun 2010 11:32:05 +1200
changeset 42957 5134171b7a015b9843f73c07be3ca7eb390658b7
parent 42956 6c0d9d3b28c2ff462cba349f2a0adfcca890faa2
child 42958 dd0f1f0a96b3f7e0d9a4beb6c393c05e3e39937a
push idunknown
push userunknown
push dateunknown
reviewersbas
bugs586041
milestone1.9.3a5pre
Bug 586041. Part 2: refactor RemoveChild. r=bas
gfx/layers/basic/BasicLayers.cpp
gfx/layers/d3d9/ContainerLayerD3D9.cpp
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -117,31 +117,28 @@ public:
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ContainerLayer::SetVisibleRegion(aRegion);
   }
   virtual void InsertAfter(Layer* aChild, Layer* aAfter);
   virtual void RemoveChild(Layer* aChild);
 
 protected:
+  void RemoveChildInternal(Layer* aChild);
+
   BasicLayerManager* BasicManager()
   {
     return static_cast<BasicLayerManager*>(mManager);
   }
 };
 
 BasicContainerLayer::~BasicContainerLayer()
 {
   while (mFirstChild) {
-    Layer* next = mFirstChild->GetNextSibling();
-    mFirstChild->SetNextSibling(nsnull);
-    mFirstChild->SetPrevSibling(nsnull);
-    mFirstChild->SetParent(nsnull);
-    NS_RELEASE(mFirstChild);
-    mFirstChild = next;
+    RemoveChildInternal(mFirstChild);
   }
 
   MOZ_COUNT_DTOR(BasicContainerLayer);
 }
 
 void
 BasicContainerLayer::InsertAfter(Layer* aChild, Layer* aAfter)
 {
@@ -179,16 +176,22 @@ BasicContainerLayer::InsertAfter(Layer* 
   aAfter->SetNextSibling(aChild);
 }
 
 void
 BasicContainerLayer::RemoveChild(Layer* aChild)
 {
   NS_ASSERTION(BasicManager()->InConstruction(),
                "Can only set properties in construction phase");
+  RemoveChildInternal(aChild);
+}
+
+void
+BasicContainerLayer::RemoveChildInternal(Layer* aChild)
+{
   NS_ASSERTION(aChild->Manager() == Manager(),
                "Child has wrong manager");
   NS_ASSERTION(aChild->GetParent() == this,
                "aChild not our child");
 
   Layer* prev = aChild->GetPrevSibling();
   Layer* next = aChild->GetNextSibling();
   if (prev) {
--- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp
@@ -45,22 +45,17 @@ ContainerLayerD3D9::ContainerLayerD3D9(L
   , LayerD3D9(aManager)
 {
   mImplData = static_cast<LayerD3D9*>(this);
 }
 
 ContainerLayerD3D9::~ContainerLayerD3D9()
 {
   while (mFirstChild) {
-    Layer* next = mFirstChild->GetNextSibling();
-    mFirstChild->SetNextSibling(nsnull);
-    mFirstChild->SetPrevSibling(nsnull);
-    mFirstChild->SetParent(nsnull);
-    NS_RELEASE(mFirstChild);
-    mFirstChild = next;
+    RemoveChild(mFirstChild);
   }
 }
 
 void
 ContainerLayerD3D9::InsertAfter(Layer* aChild, Layer* aAfter)
 {
   aChild->SetParent(this);
   if (!aAfter) {
@@ -90,21 +85,23 @@ ContainerLayerD3D9::InsertAfter(Layer* a
   }
   NS_WARNING("Failed to find aAfter layer!");
 }
 
 void
 ContainerLayerD3D9::RemoveChild(Layer *aChild)
 {
   if (GetFirstChild() == aChild) {
-    mFirstChild = GetFirstChild()->GetNextSibling() ?
-      GetFirstChild()->GetNextSibling() : nsnull;
+    mFirstChild = GetFirstChild()->GetNextSibling();
     if (mFirstChild) {
       mFirstChild->SetPrevSibling(nsnull);
     }
+    aChild->SetNextSibling(nsnull);
+    aChild->SetPrevSibling(nsnull);
+    aChild->SetParent(nsnull);
     NS_RELEASE(aChild);
     return;
   }
   Layer *lastChild = nsnull;
   for (Layer *child = GetFirstChild(); child;
        child = child->GetNextSibling()) {
     if (child == aChild) {
       // We're sure this is not our first child. So lastChild != NULL.