Bug 474369 - get rid of nsVoidArray; layout part; r+sr=roc
authorArpad Borsos <arpad.borsos@googlemail.com>
Tue, 03 Feb 2009 15:42:18 +0100
changeset 24551 a206aff7a9c64104a2720ba597b75f88333672e2
parent 24550 e99cc373f724774ac0180c60d2f4164f0bb7268f
child 24552 cdd059f3d2005defcc2ebf66206fe264ac5e4191
push id5113
push usersgautherie.bz@free.fr
push dateTue, 03 Feb 2009 14:44:19 +0000
treeherdermozilla-central@c23d77b0d600 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs474369
milestone1.9.2a1pre
Bug 474369 - get rid of nsVoidArray; layout part; r+sr=roc
layout/base/nsBidiPresUtils.cpp
layout/base/nsBidiPresUtils.h
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
layout/base/nsCounterManager.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/forms/nsIComboboxControlFrame.h
layout/forms/nsListControlFrame.h
layout/generic/nsBlockFrame.cpp
layout/generic/nsContainerFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrameList.cpp
layout/generic/nsIFrame.h
layout/generic/nsImageMap.cpp
layout/generic/nsImageMap.h
layout/generic/nsTextFrameThebes.cpp
layout/inspector/src/inCSSValueSearch.cpp
layout/inspector/src/inCSSValueSearch.h
layout/inspector/src/inDOMView.cpp
layout/inspector/src/inDOMView.h
layout/inspector/src/inDeepTreeWalker.cpp
layout/inspector/src/inDeepTreeWalker.h
layout/mathml/base/src/nsMathMLmmultiscriptsFrame.cpp
layout/mathml/base/src/nsMathMLmtableFrame.cpp
layout/mathml/content/src/nsMathMLOperators.cpp
layout/printing/nsPrintData.cpp
layout/printing/nsPrintData.h
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
layout/style/nsCSSLoader.cpp
layout/style/nsCSSLoader.h
layout/style/nsCSSParser.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSStyleSheet.cpp
layout/style/nsCSSStyleSheet.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.h
layout/xul/base/src/tree/src/nsTreeContentView.cpp
layout/xul/base/src/tree/src/nsTreeContentView.h
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -252,34 +252,34 @@ AdvanceLineIteratorToFrame(nsIFrame* aFr
   }
   aPrevFrame = child;
 }
 
 /*
  * Overview of the implementation of Resolve():
  *
  *  Walk through the descendants of aBlockFrame and build:
- *   * mLogicalArray: an nsVoidArray of nsIFrame* pointers in logical order
+ *   * mLogicalFrames: an nsTArray of nsIFrame* pointers in logical order
  *   * mBuffer: an nsAutoString containing a representation of
  *     the content of the frames.
  *     In the case of text frames, this is the actual text context of the
  *     frames, but some other elements are represented in a symbolic form which
  *     will make the Unicode Bidi Algorithm give the correct results.
  *     Bidi embeddings and overrides set by CSS or <bdo> elements are
  *     represented by the corresponding Unicode control characters.
  *     <br> elements are represented by U+2028 LINE SEPARATOR
  *     Other inline elements are represented by U+FFFC OBJECT REPLACEMENT
  *     CHARACTER
  *
  *  Then pass mBuffer to the Bidi engine for resolving of embedding levels
  *  by nsBidi::SetPara() and division into directional runs by
  *  nsBidi::CountRuns().
  *
  *  Finally, walk these runs in logical order using nsBidi::GetLogicalRun() and
- *  correlate them with the frames indexed in mLogicalArray, setting the
+ *  correlate them with the frames indexed in mLogicalFrames, setting the
  *  baseLevel, embeddingLevel, and charType properties according to the results
  *  returned by the Bidi engine and CalculateCharType().
  *
  *  The rendering layer requires each text frame to contain text in only one
  *  direction and of only one character type, so we may need to call
  *  EnsureBidiContinuation() to split frames. We may also need to call
  *  RemoveBidiContinuation() to convert frames created by
  *  EnsureBidiContinuation() in previous reflows into fluid continuations.
@@ -356,17 +356,17 @@ nsBidiPresUtils::Resolve(nsBlockFrame*  
   mSuccess = mBidiEngine->CountRuns(&runCount);
   if (NS_FAILED(mSuccess) ) {
     return mSuccess;
   }
   PRInt32                  runLength      = 0;
   PRInt32                  fragmentLength = 0;
   PRInt32                  temp;
   PRInt32                  frameIndex     = -1;
-  PRInt32                  frameCount     = mLogicalFrames.Count();
+  PRInt32                  frameCount     = mLogicalFrames.Length();
   PRInt32                  contentOffset  = 0;   // offset within current frame
   PRInt32                  lineOffset     = 0;   // offset within mBuffer
   PRInt32                  logicalLimit   = 0;
   PRInt32                  numRun         = -1;
   PRUint8                  charType;
   PRUint8                  prevType       = eCharType_LeftToRight;
   PRBool                   isTextFrame    = PR_FALSE;
   nsIFrame*                frame = nsnull;
@@ -387,17 +387,17 @@ nsBidiPresUtils::Resolve(nsBlockFrame*  
   
   for (; ;) {
     if (fragmentLength <= 0) {
       if (++frameIndex >= frameCount) {
         break;
       }
       contentOffset = 0;
       
-      frame = (nsIFrame*) (mLogicalFrames[frameIndex]);
+      frame = mLogicalFrames[frameIndex];
       frameType = frame->GetType();
       lineNeedsUpdate = PR_TRUE;
       if (nsGkAtoms::textFrame == frameType) {
         content = frame->GetContent();
         if (!content) {
           mSuccess = NS_OK;
           break;
         }
@@ -511,17 +511,17 @@ nsBidiPresUtils::Resolve(nsBlockFrame*  
         nsIFrame* parent = frame->GetParent();
         JoinInlineAncestors(parent);
       }
     }
   } // for
   return mSuccess;
 }
 
-// Should this frame be treated as a leaf (e.g. when building mLogicalArray)?
+// Should this frame be treated as a leaf (e.g. when building mLogicalFrames)?
 PRBool IsBidiLeaf(nsIFrame* aFrame) {
   nsIFrame* kid = aFrame->GetFirstChild(nsnull);
   return !kid
     || !aFrame->IsFrameOfType(nsIFrame::eBidiInlineContainer);
 }
 
 void
 nsBidiPresUtils::InitLogicalArray(nsIFrame*       aCurrentFrame)
@@ -589,17 +589,17 @@ nsBidiPresUtils::InitLogicalArray(nsIFra
     if (IsBidiLeaf(frame)) {
       /* Bidi leaf frame: add the frame to the mLogicalFrames array,
        * and add its index to the mContentToFrameIndex hashtable. This
        * will be used in RemoveBidiContinuation() to identify the last
        * frame in the array with a given content.
        */
       nsIContent* content = frame->GetContent();
       if (content) {
-        mContentToFrameIndex.Put(content, mLogicalFrames.Count());
+        mContentToFrameIndex.Put(content, mLogicalFrames.Length());
       }
       mLogicalFrames.AppendElement(frame);
     }
     else {
       nsIFrame* kid = frame->GetFirstChild(nsnull);
       InitLogicalArray(kid);
     }
 
@@ -618,20 +618,20 @@ nsBidiPresUtils::InitLogicalArray(nsIFra
 void
 nsBidiPresUtils::CreateBlockBuffer()
 {
   mBuffer.SetLength(0);
 
   nsIFrame*                 frame;
   nsIContent*               prevContent = nsnull;
   PRUint32                  i;
-  PRUint32                  count = mLogicalFrames.Count();
+  PRUint32                  count = mLogicalFrames.Length();
 
   for (i = 0; i < count; i++) {
-    frame = (nsIFrame*) (mLogicalFrames[i]);
+    frame = mLogicalFrames[i];
     nsIAtom* frameType = frame->GetType();
 
     if (nsGkAtoms::textFrame == frameType) {
       nsIContent* content = frame->GetContent();
       if (!content) {
         mSuccess = NS_OK;
         break;
       }
@@ -681,17 +681,17 @@ nsBidiPresUtils::ReorderFrames(nsIFrame*
   RepositionInlineFrames(aFirstFrameOnLine);
 }
 
 nsresult
 nsBidiPresUtils::Reorder(PRBool& aReordered, PRBool& aHasRTLFrames)
 {
   aReordered = PR_FALSE;
   aHasRTLFrames = PR_FALSE;
-  PRInt32 count = mLogicalFrames.Count();
+  PRInt32 count = mLogicalFrames.Length();
 
   if (mArraySize < count) {
     mArraySize = count << 1;
     if (mLevels) {
       delete[] mLevels;
       mLevels = nsnull;
     }
     if (mIndexMap) {
@@ -706,17 +706,17 @@ nsBidiPresUtils::Reorder(PRBool& aReorde
     }
   }
   memset(mLevels, 0, sizeof(PRUint8) * mArraySize);
 
   nsIFrame* frame;
   PRInt32   i;
 
   for (i = 0; i < count; i++) {
-    frame = (nsIFrame*) (mLogicalFrames[i]);
+    frame = mLogicalFrames[i];
     mLevels[i] = GetFrameEmbeddingLevel(frame);
     if (mLevels[i] & 1) {
       aHasRTLFrames = PR_TRUE;
     }      
   }
   if (!mIndexMap) {
     mIndexMap = new PRInt32[mArraySize];
   }
@@ -880,37 +880,37 @@ nsBidiPresUtils::RepositionFrame(nsIFram
     nsMargin borderPadding = aFrame->GetUsedBorderAndPadding();
     if (isLeftMost) {
       x += borderPadding.left;
     }
 
     // If aIsOddLevel is true, so we need to traverse the child list
     // in reverse order, to make it O(n) we store the list locally and
     // iterate the list reversely
-    nsVoidArray childList;
+    nsTArray<nsIFrame*> childList;
     nsIFrame *frame = aFrame->GetFirstChild(nsnull);
     if (frame && aIsOddLevel) {
-      childList.AppendElement(nsnull);
+      childList.AppendElement((nsIFrame*)nsnull);
       while (frame) {
         childList.AppendElement(frame);
         frame = frame->GetNextSibling();
       }
-      frame = (nsIFrame*)childList[childList.Count() - 1];
+      frame = childList[childList.Length() - 1];
     }
 
     // Reposition the child frames
     PRInt32 index = 0;
     while (frame) {
       RepositionFrame(frame,
                       aIsOddLevel,
                       x,
                       aContinuationStates);
       index++;
       frame = aIsOddLevel ?
-                (nsIFrame*)childList[childList.Count() - index - 1] :
+                childList[childList.Length() - index - 1] :
                 frame->GetNextSibling();
     }
 
     if (isRightMost) {
       x += borderPadding.right;
     }
     aLeft += x;
   } else {
@@ -954,32 +954,31 @@ nsBidiPresUtils::RepositionInlineFrames(
   // bidiUtils->ReorderFrames, so this is guaranteed to be after the inlines
   // have been reflowed, which is required for GetUsedMargin/Border/Padding
   nsMargin margin = aFirstChild->GetUsedMargin();
   if (!aFirstChild->GetPrevContinuation())
     leftSpace = isLTR ? margin.left : margin.right;
 
   nscoord left = aFirstChild->GetPosition().x - leftSpace;
   nsIFrame* frame;
-  PRInt32 count = mVisualFrames.Count();
+  PRInt32 count = mVisualFrames.Length();
   PRInt32 index;
   nsContinuationStates continuationStates;
 
   continuationStates.Init();
 
   // Initialize continuation states to (nsnull, 0) for
   // each frame on the line.
   for (index = 0; index < count; index++) {
-    InitContinuationStates((nsIFrame*)mVisualFrames[index],
-                           &continuationStates);
+    InitContinuationStates(mVisualFrames[index], &continuationStates);
   }
 
   // Reposition frames in visual order
   for (index = 0; index < count; index++) {
-    frame = (nsIFrame*) (mVisualFrames[index]);
+    frame = mVisualFrames[index];
     RepositionFrame(frame,
                     (mLevels[mIndexMap[index]] & 1),
                     left,
                     &continuationStates);
   } // for
 }
 
 void 
@@ -999,71 +998,71 @@ nsBidiPresUtils::CheckLineOrder(nsIFrame
                                 nsIFrame** aFirstVisual,
                                 nsIFrame** aLastVisual)
 {
   InitLogicalArrayFromLine(aFirstFrameOnLine, aNumFramesOnLine);
   
   PRBool isReordered;
   PRBool hasRTLFrames;
   Reorder(isReordered, hasRTLFrames);
-  PRInt32 count = mLogicalFrames.Count();
+  PRInt32 count = mLogicalFrames.Length();
   
   if (aFirstVisual) {
-    *aFirstVisual = (nsIFrame*)mVisualFrames[0];
+    *aFirstVisual = mVisualFrames[0];
   }
   if (aLastVisual) {
-    *aLastVisual = (nsIFrame*)mVisualFrames[count-1];
+    *aLastVisual = mVisualFrames[count-1];
   }
   
   // If there's an RTL frame, assume the line is reordered
   return isReordered || hasRTLFrames;
 }
 
 nsIFrame*
 nsBidiPresUtils::GetFrameToRightOf(const nsIFrame*  aFrame,
                                    nsIFrame*        aFirstFrameOnLine,
                                    PRInt32          aNumFramesOnLine)
 {
   InitLogicalArrayFromLine(aFirstFrameOnLine, aNumFramesOnLine);
   
   PRBool isReordered;
   PRBool hasRTLFrames;
   Reorder(isReordered, hasRTLFrames);
-  PRInt32 count = mVisualFrames.Count();
+  PRInt32 count = mVisualFrames.Length();
 
   if (aFrame == nsnull)
-    return (nsIFrame*)mVisualFrames[0];
+    return mVisualFrames[0];
   
   for (PRInt32 i = 0; i < count - 1; i++) {
-    if ((nsIFrame*)mVisualFrames[i] == aFrame) {
-      return (nsIFrame*)mVisualFrames[i+1];
+    if (mVisualFrames[i] == aFrame) {
+      return mVisualFrames[i+1];
     }
   }
   
   return nsnull;
 }
 
 nsIFrame*
 nsBidiPresUtils::GetFrameToLeftOf(const nsIFrame*  aFrame,
                                   nsIFrame*        aFirstFrameOnLine,
                                   PRInt32          aNumFramesOnLine)
 {
   InitLogicalArrayFromLine(aFirstFrameOnLine, aNumFramesOnLine);
   
   PRBool isReordered;
   PRBool hasRTLFrames;
   Reorder(isReordered, hasRTLFrames);
-  PRInt32 count = mVisualFrames.Count();
+  PRInt32 count = mVisualFrames.Length();
   
   if (aFrame == nsnull)
-    return (nsIFrame*)mVisualFrames[count-1];
+    return mVisualFrames[count-1];
   
   for (PRInt32 i = 1; i < count; i++) {
-    if ((nsIFrame*)mVisualFrames[i] == aFrame) {
-      return (nsIFrame*)mVisualFrames[i-1];
+    if (mVisualFrames[i] == aFrame) {
+      return mVisualFrames[i-1];
     }
   }
   
   return nsnull;
 }
 
 PRBool
 nsBidiPresUtils::EnsureBidiContinuation(nsIFrame*       aFrame,
@@ -1079,18 +1078,18 @@ nsBidiPresUtils::EnsureBidiContinuation(
                "Calling EnsureBidiContinuation on non-first-in-flow");
 
   *aNewFrame = nsnull;
   nsBidiLevel embeddingLevel = NS_GET_EMBEDDING_LEVEL(aFrame);
   nsBidiLevel baseLevel = NS_GET_BASE_LEVEL(aFrame);
   nsCharType charType = (nsCharType)NS_PTR_TO_INT32(aFrame->GetProperty(nsGkAtoms::charType));
   
   // Skip fluid continuations
-  while (aFrameIndex + 1 < mLogicalFrames.Count()) {
-    nsIFrame* frame = (nsIFrame*)mLogicalFrames[aFrameIndex + 1];
+  while (aFrameIndex + 1 < PRInt32(mLogicalFrames.Length())) {
+    nsIFrame* frame = mLogicalFrames[aFrameIndex + 1];
     if (frame->GetPrevInFlow() != aFrame) {
       // If we found a non-fluid continuation, use it
       if (frame->GetPrevContinuation() == aFrame) {
         *aNewFrame = frame;
         aFrameIndex++;
         // The frame we found might be on another line. If so, the line iterator
         // should be updated.
         aLineNeedsUpdate = PR_TRUE;
@@ -1129,17 +1128,17 @@ nsBidiPresUtils::RemoveBidiContinuation(
   nsBidiLevel embeddingLevel = (nsCharType)NS_PTR_TO_INT32(aFrame->GetProperty(nsGkAtoms::embeddingLevel, &rv));
   NS_ASSERTION(NS_SUCCEEDED(rv), "embeddingLevel attribute missing from aFrame");
   nsBidiLevel baseLevel = (nsCharType)NS_PTR_TO_INT32(aFrame->GetProperty(nsGkAtoms::baseLevel, &rv));
   NS_ASSERTION(NS_SUCCEEDED(rv), "baseLevel attribute missing from aFrame");
   nsCharType charType = (nsCharType)NS_PTR_TO_INT32(aFrame->GetProperty(nsGkAtoms::charType, &rv));
   NS_ASSERTION(NS_SUCCEEDED(rv), "charType attribute missing from aFrame");
   
   for (PRInt32 index = aFirstIndex + 1; index <= aLastIndex; index++) {
-    nsIFrame* frame = (nsIFrame*) mLogicalFrames[index];
+    nsIFrame* frame = mLogicalFrames[index];
     if (nsGkAtoms::directionalFrame == frame->GetType()) {
       frame->Destroy();
       ++aOffset;
     }
     else {
       // Make the frame and its continuation ancestors fluid,
       // so they can be reused or deleted by normal reflow code
       frame->SetProperty(nsGkAtoms::embeddingLevel, NS_INT32_TO_PTR(embeddingLevel));
@@ -1423,17 +1422,17 @@ nsresult nsBidiPresUtils::ProcessText(co
 
     while (subRunCount > 0) {
       // CalculateCharType can increment subRunCount if the run
       // contains mixed character types
       CalculateCharType(lineOffset, typeLimit, subRunLimit, subRunLength, subRunCount, charType, prevType);
       
       nsAutoString runVisualText;
       runVisualText.Assign(aText + start, subRunLength);
-      if (runVisualText.Length() < subRunLength)
+      if (PRInt32(runVisualText.Length()) < subRunLength)
         return NS_ERROR_OUT_OF_MEMORY;
       FormatUnicodeText(aPresContext, runVisualText.BeginWriting(), subRunLength,
                         (nsCharType)charType, level & 1);
 
       aprocessor.SetText(runVisualText.get(), subRunLength, nsBidiDirection(level & 1));
       width = aprocessor.GetWidth();
       totalWidth += width;
       if (level & 1) {
--- a/layout/base/nsBidiPresUtils.h
+++ b/layout/base/nsBidiPresUtils.h
@@ -37,17 +37,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef IBMBIDI
 
 #ifndef nsBidiPresUtils_h___
 #define nsBidiPresUtils_h___
 
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsIFrame.h"
 #include "nsBidi.h"
 #include "nsBidiUtils.h"
 #include "nsCOMPtr.h"
 #include "nsDataHashtable.h"
 #include "nsBlockFrame.h"
 #include "nsTHashtable.h"
 
@@ -483,18 +483,18 @@ private:
                          PRInt32& aRunLength,
                          PRInt32& aRunCount,
                          PRUint8& aCharType,
                          PRUint8& aPrevCharType) const;
   
   void StripBidiControlCharacters(PRUnichar* aText,
                                   PRInt32&   aTextLength) const;
   nsAutoString    mBuffer;
-  nsVoidArray     mLogicalFrames;
-  nsVoidArray     mVisualFrames;
+  nsTArray<nsIFrame*> mLogicalFrames;
+  nsTArray<nsIFrame*> mVisualFrames;
   nsDataHashtable<nsISupportsHashKey, PRInt32> mContentToFrameIndex;
   PRInt32         mArraySize;
   PRInt32*        mIndexMap;
   PRUint8*        mLevels;
   nsresult        mSuccess;
 
   nsBidi*         mBidiEngine;
 };
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -118,16 +118,17 @@
 #include "nsImageFrame.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsContentErrors.h"
 #include "nsIPrincipal.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsStyleUtil.h"
 #include "nsIFocusEventSuppressor.h"
 #include "nsBox.h"
+#include "nsTArray.h"
 
 #ifdef MOZ_XUL
 #include "nsIRootBox.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIXULDocument.h"
 #endif
 #ifdef ACCESSIBILITY
@@ -8192,26 +8193,26 @@ nsCSSFrameConstructor::ReinsertContent(n
     // reinsert the content here
     res = ContentInserted(aContainer, aChild, ix, nsnull);
   }
 
   return res;
 }
 
 static void
-DoDeletingFrameSubtree(nsFrameManager* aFrameManager,
-                       nsVoidArray&    aDestroyQueue,
-                       nsIFrame*       aRemovedFrame,
-                       nsIFrame*       aFrame);
+DoDeletingFrameSubtree(nsFrameManager*      aFrameManager,
+                       nsTArray<nsIFrame*>& aDestroyQueue,
+                       nsIFrame*            aRemovedFrame,
+                       nsIFrame*            aFrame);
 
 static void
-DoDeletingOverflowContainers(nsFrameManager* aFrameManager,
-                             nsVoidArray&    aDestroyQueue,
-                             nsIFrame*       aRemovedFrame,
-                             nsIFrame*       aFrame)
+DoDeletingOverflowContainers(nsFrameManager*      aFrameManager,
+                             nsTArray<nsIFrame*>& aDestroyQueue,
+                             nsIFrame*            aRemovedFrame,
+                             nsIFrame*            aFrame)
 {
   // The invariant that "continuing frames should be found as part of the
   // walk over the top-most frame's continuing frames" does not hold for
   // out-of-flow overflow containers, so we need to walk them too.
   // Note that DoDeletingFrameSubtree() skips the child lists where
   // overflow containers live so we won't process them twice.
   const PRBool orphanSubtree = aRemovedFrame == aFrame;
   for (nsIFrame* next = aFrame->GetNextContinuation();
@@ -8242,20 +8243,20 @@ DoDeletingOverflowContainers(nsFrameMana
  *            content model. As we recurse we need to remember this so we
  *            can check if out-of-flow frames are a descendant of the frame
  *            being removed
  * @param   aFrame the local subtree that is being deleted. This is initially
  *            the same as aRemovedFrame, but as we recurse down the tree
  *            this changes
  */
 static void
-DoDeletingFrameSubtree(nsFrameManager* aFrameManager,
-                       nsVoidArray&    aDestroyQueue,
-                       nsIFrame*       aRemovedFrame,
-                       nsIFrame*       aFrame)
+DoDeletingFrameSubtree(nsFrameManager*      aFrameManager,
+                       nsTArray<nsIFrame*>& aDestroyQueue,
+                       nsIFrame*            aRemovedFrame,
+                       nsIFrame*            aFrame)
 {
 #undef RECURSE
 #define RECURSE(top, child)                                                  \
   DoDeletingFrameSubtree(aFrameManager, aDestroyQueue, (top), (child));      \
   DoDeletingOverflowContainers(aFrameManager, aDestroyQueue, (top), (child));
 
   // Remove the mapping from the content object to its frame.
   nsIContent* content = aFrame->GetContent();
@@ -8326,17 +8327,17 @@ DeletingFrameSubtree(nsFrameManager* aFr
   NS_ENSURE_TRUE(aFrame, NS_OK); // XXXldb Remove this sometime in the future.
 
   // If there's no frame manager it's probably because the pres shell is
   // being destroyed.
   if (NS_UNLIKELY(!aFrameManager)) {
     return NS_OK;
   }
 
-  nsAutoVoidArray destroyQueue;
+  nsAutoTArray<nsIFrame*, 8> destroyQueue;
 
   // If it's a "special" block-in-inline frame, then we can't really deal.
   // That really shouldn't be happening.
   NS_ASSERTION(!IsFrameSpecial(aFrame),
                "DeletingFrameSubtree on a special frame.  Prepare to crash.");
 
   do {
     DoDeletingFrameSubtree(aFrameManager, destroyQueue, aFrame, aFrame);
@@ -8350,18 +8351,18 @@ DeletingFrameSubtree(nsFrameManager* aFr
     // containers which we do walk because they *can* escape the subtree
     // we're deleting.  We skip [excess]overflowContainersList where
     // they live to avoid processing them more than once.
     aFrame = aFrame->GetNextContinuation();
   } while (aFrame);
 
   // Now destroy any out-of-flow frames that have been enqueued for
   // destruction.
-  for (PRInt32 i = destroyQueue.Count() - 1; i >= 0; --i) {
-    nsIFrame* outOfFlowFrame = static_cast<nsIFrame*>(destroyQueue[i]);
+  for (PRInt32 i = destroyQueue.Length() - 1; i >= 0; --i) {
+    nsIFrame* outOfFlowFrame = destroyQueue[i];
 
     // Ask the out-of-flow's parent to delete the out-of-flow
     // frame from the right list.
     aFrameManager->RemoveFrame(outOfFlowFrame->GetParent(),
                                GetChildListNameFor(outOfFlowFrame),
                                outOfFlowFrame);
   }
 
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -56,17 +56,16 @@
 
 class nsIDocument;
 struct nsFrameItems;
 struct nsAbsoluteItems;
 class nsStyleContext;
 struct nsStyleContent;
 struct nsStyleDisplay;
 class nsIPresShell;
-class nsVoidArray;
 class nsFrameManager;
 class nsIDOMHTMLSelectElement;
 class nsPresContext;
 class nsStyleChangeList;
 class nsIFrame;
 struct nsGenConInitializer;
 class ChildIterator;
 
--- a/layout/base/nsCounterManager.cpp
+++ b/layout/base/nsCounterManager.cpp
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* implementation of CSS counters (for numbering things) */
 
 #include "nsCounterManager.h"
 #include "nsBulletFrame.h" // legacy location for list style type to text code
 #include "nsContentUtils.h"
+#include "nsTArray.h"
 
 PRBool
 nsCounterUseNode::InitTextFrame(nsGenConList* aList,
         nsIFrame* aPseudoFrame, nsIFrame* aTextFrame)
 {
   nsCounterNode::InitTextFrame(aList, aPseudoFrame, aTextFrame);
 
   nsCounterList *counterList = static_cast<nsCounterList*>(aList);
@@ -93,30 +94,30 @@ void nsCounterChangeNode::Calc(nsCounter
 }
 
 // The text that should be displayed for this counter.
 void
 nsCounterUseNode::GetText(nsString& aResult)
 {
     aResult.Truncate();
 
-    nsAutoVoidArray stack;
+    nsAutoTArray<nsCounterNode*, 8> stack;
     stack.AppendElement(static_cast<nsCounterNode*>(this));
 
     if (mAllCounters && mScopeStart)
         for (nsCounterNode *n = mScopeStart; n->mScopePrev; n = n->mScopeStart)
             stack.AppendElement(n->mScopePrev);
 
     PRInt32 style = mCounterStyle->Item(mAllCounters ? 2 : 1).GetIntValue();
     const PRUnichar* separator;
     if (mAllCounters)
         separator = mCounterStyle->Item(1).GetStringBufferValue();
 
-    for (PRInt32 i = stack.Count() - 1;; --i) {
-        nsCounterNode *n = static_cast<nsCounterNode*>(stack[i]);
+    for (PRUint32 i = stack.Length() - 1;; --i) {
+        nsCounterNode *n = stack[i];
         nsBulletFrame::AppendCounterText(style, n->mValueAfter, aResult);
         if (i == 0)
             break;
         NS_ASSERTION(mAllCounters, "yikes, separator is uninitialized");
         aResult.Append(separator);
     }
 }
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -74,16 +74,17 @@
 #include "nsPIDOMWindow.h"
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIWidget.h"
 #include "gfxMatrix.h"
 #include "gfxTypes.h"
 #include "gfxUserFontSet.h"
+#include "nsTArray.h"
 
 #ifdef MOZ_SVG
 #include "nsSVGUtils.h"
 #include "nsSVGIntegrationUtils.h"
 #include "nsSVGForeignObjectFrame.h"
 #include "nsSVGOuterSVGFrame.h"
 #endif
 
@@ -1581,49 +1582,49 @@ nsLayoutUtils::GetClosestCommonAncestorV
 
   nsPresContext* presContext = aFrame1->PresContext();
   if (presContext != aFrame2->PresContext()) {
     // different documents, no common ancestor
     return nsnull;
   }
   nsFrameManager* frameManager = presContext->PresShell()->FrameManager();
 
-  nsAutoVoidArray frame1Ancestors;
+  nsAutoTArray<nsIFrame*, 8> frame1Ancestors;
   nsIFrame* f1;
   for (f1 = aFrame1; f1 && f1 != aKnownCommonAncestorHint;
        f1 = GetParentOrPlaceholderFor(frameManager, f1)) {
     frame1Ancestors.AppendElement(f1);
   }
   if (!f1 && aKnownCommonAncestorHint) {
     // So, it turns out aKnownCommonAncestorHint was not an ancestor of f1. Oops.
     // Never mind. We can continue as if aKnownCommonAncestorHint was null.
     aKnownCommonAncestorHint = nsnull;
   }
 
-  nsAutoVoidArray frame2Ancestors;
+  nsAutoTArray<nsIFrame*, 8> frame2Ancestors;
   nsIFrame* f2;
   for (f2 = aFrame2; f2 && f2 != aKnownCommonAncestorHint;
        f2 = GetParentOrPlaceholderFor(frameManager, f2)) {
     frame2Ancestors.AppendElement(f2);
   }
   if (!f2 && aKnownCommonAncestorHint) {
     // So, it turns out aKnownCommonAncestorHint was not an ancestor of f2.
     // We need to retry with no common ancestor hint.
     return GetClosestCommonAncestorViaPlaceholders(aFrame1, aFrame2, nsnull);
   }
 
   // now frame1Ancestors and frame2Ancestors give us the parent frame chain
   // up to aKnownCommonAncestorHint, or if that is null, up to and including
   // the root frame. We need to walk from the end (i.e., the top of the
   // frame (sub)tree) down to aFrame1/aFrame2 looking for the first difference.
   nsIFrame* lastCommonFrame = aKnownCommonAncestorHint;
-  PRInt32 last1 = frame1Ancestors.Count() - 1;
-  PRInt32 last2 = frame2Ancestors.Count() - 1;
+  PRInt32 last1 = frame1Ancestors.Length() - 1;
+  PRInt32 last2 = frame2Ancestors.Length() - 1;
   while (last1 >= 0 && last2 >= 0) {
-    nsIFrame* frame1 = static_cast<nsIFrame*>(frame1Ancestors.ElementAt(last1));
+    nsIFrame* frame1 = frame1Ancestors.ElementAt(last1);
     if (frame1 != frame2Ancestors.ElementAt(last2))
       break;
     lastCommonFrame = frame1;
     last1--;
     last2--;
   }
   return lastCommonFrame;
 }
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -71,17 +71,17 @@
 #include "nsFrame.h"
 #include "nsIViewManager.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "prlog.h"
 #include "prmem.h"
 #include "prprf.h"
 #include "prinrval.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsHashtable.h"
 #include "nsIViewObserver.h"
 #include "nsContainerFrame.h"
 #include "nsIDeviceContext.h"
 #include "nsEventStateManager.h"
 #include "nsDOMEvent.h"
 #include "nsGUIEvent.h"
@@ -1118,27 +1118,27 @@ protected:
                                        PRBool aInterruptibleReflow);
 
   nsCOMPtr<nsICSSStyleSheet> mPrefStyleSheet; // mStyleSet owns it but we
                                               // maintain a ref, may be null
 #ifdef DEBUG
   PRUint32                  mUpdateCount;
 #endif
   // reflow roots that need to be reflowed, as both a queue and a hashtable
-  nsVoidArray mDirtyRoots;
+  nsTArray<nsIFrame*> mDirtyRoots;
 
   PRPackedBool mDocumentLoading;
   PRPackedBool mIsReflowing;
 
   PRPackedBool mIgnoreFrameDestruction;
   PRPackedBool mHaveShutDown;
   
   nsIFrame*   mCurrentEventFrame;
   nsCOMPtr<nsIContent> mCurrentEventContent;
-  nsVoidArray mCurrentEventFrameStack;
+  nsTArray<nsIFrame*> mCurrentEventFrameStack;
   nsCOMArray<nsIContent> mCurrentEventContentStack;
 
   nsCOMPtr<nsIContent>          mLastAnchorScrolledTo;
   nscoord                       mLastAnchorScrollPositionY;
   nsRefPtr<nsCaret>             mCaret;
   nsRefPtr<nsCaret>             mOriginalCaret;
   PRInt16                       mSelectionFlags;
   FrameArena                    mFrameArena;
@@ -1659,19 +1659,19 @@ PresShell::Destroy()
 
   // The frames will be torn down, so remove them from the current
   // event frame stack (since they'd be dangling references if we'd
   // leave them in) and null out the mCurrentEventFrame pointer as
   // well.
 
   mCurrentEventFrame = nsnull;
 
-  PRInt32 i, count = mCurrentEventFrameStack.Count();
+  PRInt32 i, count = mCurrentEventFrameStack.Length();
   for (i = 0; i < count; i++) {
-    mCurrentEventFrameStack.ReplaceElementAt(nsnull, i);
+    mCurrentEventFrameStack[i] = nsnull;
   }
 
   if (mViewManager) {
     // Clear the view manager's weak pointer back to |this| in case it
     // was leaked.
     mViewManager->SetViewObserver(nsnull);
     mViewManager = nsnull;
   }
@@ -2435,24 +2435,24 @@ PresShell::InitialReflow(nscoord aWidth,
     // somehow.  Currently that can't happen, as long as mHaveShutDown is
     // false, but let's not rely on that.
     rootFrame = FrameManager()->GetRootFrame();
   }
 
   if (rootFrame) {
     // Note: Because the frame just got created, it has the NS_FRAME_IS_DIRTY
     // bit set.  Unset it so that FrameNeedsReflow() will work right.
-    NS_ASSERTION(mDirtyRoots.IndexOf(rootFrame) == -1,
+    NS_ASSERTION(!mDirtyRoots.Contains(rootFrame),
                  "Why is the root in mDirtyRoots already?");
 
     rootFrame->RemoveStateBits(NS_FRAME_IS_DIRTY |
                                NS_FRAME_HAS_DIRTY_CHILDREN);
     FrameNeedsReflow(rootFrame, eResize, NS_FRAME_IS_DIRTY);
 
-    NS_ASSERTION(mDirtyRoots.IndexOf(rootFrame) != -1,
+    NS_ASSERTION(mDirtyRoots.Contains(rootFrame),
                  "Should be in mDirtyRoots now");
     NS_ASSERTION(mReflowEvent.IsPending(), "Why no reflow event pending?");
   }
 
   // Restore our root scroll position now if we're getting here after EndLoad
   // got called, since this is our one chance to do it.  Note that we need not
   // have reflowed for this to work; when the scrollframe is finally reflowed
   // it'll puick up the position we store in it here.
@@ -2599,17 +2599,17 @@ PresShell::SetIgnoreFrameDestruction(PRB
 }
 
 NS_IMETHODIMP
 PresShell::NotifyDestroyingFrame(nsIFrame* aFrame)
 {
   if (!mIgnoreFrameDestruction) {
     mFrameConstructor->NotifyDestroyingFrame(aFrame);
 
-    for (PRInt32 idx = mDirtyRoots.Count(); idx; ) {
+    for (PRInt32 idx = mDirtyRoots.Length(); idx; ) {
       --idx;
       if (mDirtyRoots[idx] == aFrame) {
         mDirtyRoots.RemoveElementAt(idx);
       }
     }
 
     // Notify the frame manager
     FrameManager()->NotifyDestroyingFrame(aFrame);
@@ -3098,17 +3098,17 @@ PresShell::VerifyHasDirtyRootAncestor(ns
     return;
   }
         
   // Make sure that there is a reflow root ancestor of |aFrame| that's
   // in mDirtyRoots already.
   while (aFrame && (aFrame->GetStateBits() & NS_FRAME_HAS_DIRTY_CHILDREN)) {
     if (((aFrame->GetStateBits() & NS_FRAME_REFLOW_ROOT) ||
          !aFrame->GetParent()) &&
-        mDirtyRoots.IndexOf(aFrame) != -1) {
+        mDirtyRoots.Contains(aFrame)) {
       return;
     }
 
     aFrame = aFrame->GetParent();
   }
   NS_NOTREACHED("Frame has dirty bits set but isn't scheduled to be "
                 "reflowed?");
 }
@@ -3173,25 +3173,25 @@ PresShell::FrameNeedsReflow(nsIFrame *aF
     // dirty, or it could be some ancestor of aFrame.)
     for (nsIFrame *a = aFrame;
          a && !FRAME_IS_REFLOW_ROOT(a);
          a = a->GetParent())
       a->MarkIntrinsicWidthsDirty();
   }
 
   if (aIntrinsicDirty == eStyleChange) {
-    // Mark all descendants dirty (using an nsVoidArray stack rather than
+    // Mark all descendants dirty (using an nsTArray stack rather than
     // recursion).
-    nsVoidArray stack;
+    nsTArray<nsIFrame*> stack;
     stack.AppendElement(aFrame);
 
-    while (stack.Count() != 0) {
+    while (stack.Length() != 0) {
       nsIFrame *f =
-        static_cast<nsIFrame*>(stack.FastElementAt(stack.Count() - 1));
-      stack.RemoveElementAt(stack.Count() - 1);
+        stack.ElementAt(stack.Length() - 1);
+      stack.RemoveElementAt(stack.Length() - 1);
 
       PRInt32 childListIndex = 0;
       nsIAtom *childListName;
       do {
         childListName = f->GetAdditionalChildListName(childListIndex++);
         for (nsIFrame *kid = f->GetFirstChild(childListName); kid;
              kid = kid->GetNextSibling()) {
           kid->MarkIntrinsicWidthsDirty();
@@ -3353,23 +3353,23 @@ PresShell::ClearFrameRefs(nsIFrame* aFra
   }
 
 #ifdef NS_DEBUG
   if (aFrame == mDrawEventTargetFrame) {
     mDrawEventTargetFrame = nsnull;
   }
 #endif
 
-  for (int i=0; i<mCurrentEventFrameStack.Count(); i++) {
-    if (aFrame == (nsIFrame*)mCurrentEventFrameStack.ElementAt(i)) {
+  for (unsigned int i=0; i < mCurrentEventFrameStack.Length(); i++) {
+    if (aFrame == mCurrentEventFrameStack.ElementAt(i)) {
       //One of our stack frames was deleted.  Get its content so that when we
       //pop it we can still get its new frame from its content
       nsIContent *currentEventContent = aFrame->GetContent();
       mCurrentEventContentStack.ReplaceObjectAt(currentEventContent, i);
-      mCurrentEventFrameStack.ReplaceElementAt(nsnull, i);
+      mCurrentEventFrameStack[i] = nsnull;
     }
   }
 
   nsWeakFrame* weakFrame = mWeakFrames;
   while (weakFrame) {
     nsWeakFrame* prev = weakFrame->GetPreviousWeakFrame();
     if (weakFrame->GetFrame() == aFrame) {
       // This removes weakFrame from mWeakFrames.
@@ -4298,17 +4298,17 @@ PresShell::UnsuppressPainting()
 
   if (mIsDocumentGone || !mPaintingSuppressed)
     return NS_OK;
 
   // If we have reflows pending, just wait until we process
   // the reflows and get all the frames where we want them
   // before actually unlocking the painting.  Otherwise
   // go ahead and unlock now.
-  if (mDirtyRoots.Count() > 0)
+  if (mDirtyRoots.Length() > 0)
     mShouldUnsuppressPainting = PR_TRUE;
   else
     UnsuppressAndInvalidate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresShell::DisableThemeSupport()
@@ -5426,31 +5426,31 @@ PresShell::GetEventTargetContent(nsEvent
   }
   return NS_OK;
 }
 
 void
 PresShell::PushCurrentEventInfo(nsIFrame* aFrame, nsIContent* aContent)
 {
   if (mCurrentEventFrame || mCurrentEventContent) {
-    mCurrentEventFrameStack.InsertElementAt((void*)mCurrentEventFrame, 0);
+    mCurrentEventFrameStack.InsertElementAt(0, mCurrentEventFrame);
     mCurrentEventContentStack.InsertObjectAt(mCurrentEventContent, 0);
   }
   mCurrentEventFrame = aFrame;
   mCurrentEventContent = aContent;
 }
 
 void
 PresShell::PopCurrentEventInfo()
 {
   mCurrentEventFrame = nsnull;
   mCurrentEventContent = nsnull;
 
-  if (0 != mCurrentEventFrameStack.Count()) {
-    mCurrentEventFrame = (nsIFrame*)mCurrentEventFrameStack.ElementAt(0);
+  if (0 != mCurrentEventFrameStack.Length()) {
+    mCurrentEventFrame = mCurrentEventFrameStack.ElementAt(0);
     mCurrentEventFrameStack.RemoveElementAt(0);
     mCurrentEventContent = mCurrentEventContentStack.ObjectAt(0);
     mCurrentEventContentStack.RemoveObjectAt(0);
   }
 }
 
 PRBool PresShell::InZombieDocument(nsIContent *aContent)
 {
@@ -6498,17 +6498,17 @@ PresShell::ReflowEvent::Run() {
 }
 
 //-------------- End Reflow Event Definition ---------------------------
 
 void
 PresShell::PostReflowEvent()
 {
   if (mReflowEvent.IsPending() || mIsDestroying || mIsReflowing ||
-      mDirtyRoots.Count() == 0)
+      mDirtyRoots.Length() == 0)
     return;
 
   nsRefPtr<ReflowEvent> ev = new ReflowEvent(this);
   if (NS_FAILED(NS_DispatchToCurrentThread(ev))) {
     NS_WARNING("failed to dispatch reflow event");
   } else {
     mReflowEvent = ev;
 #ifdef DEBUG
@@ -6654,30 +6654,30 @@ PresShell::DoVerifyReflow()
     mInVerifyReflow = PR_TRUE;
     PRBool ok = VerifyIncrementalReflow();
     mInVerifyReflow = PR_FALSE;
     if (VERIFY_REFLOW_ALL & gVerifyReflowFlags) {
       printf("ProcessReflowCommands: finished (%s)\n",
              ok ? "ok" : "failed");
     }
 
-    if (0 != mDirtyRoots.Count()) {
+    if (0 != mDirtyRoots.Length()) {
       printf("XXX yikes! reflow commands queued during verify-reflow\n");
     }
   }
 }
 #endif
 
 nsresult
 PresShell::ProcessReflowCommands(PRBool aInterruptible)
 {
   MOZ_TIMER_DEBUGLOG(("Start: Reflow: PresShell::ProcessReflowCommands(), this=%p\n", this));
   MOZ_TIMER_START(mReflowWatch);  
 
-  if (0 != mDirtyRoots.Count()) {
+  if (0 != mDirtyRoots.Length()) {
 
 #ifdef DEBUG
     if (VERIFY_REFLOW_DUMP_COMMANDS & gVerifyReflowFlags) {
       printf("ProcessReflowCommands: begin incremental reflow\n");
     }
 #endif
 
     WillDoReflow();
@@ -6690,32 +6690,32 @@ PresShell::ProcessReflowCommands(PRBool 
     // Scope for the reflow entry point
     {
       nsAutoScriptBlocker scriptBlocker;
       AUTO_LAYOUT_PHASE_ENTRY_POINT(GetPresContext(), Reflow);
       mIsReflowing = PR_TRUE;
 
       do {
         // Send an incremental reflow notification to the target frame.
-        PRInt32 idx = mDirtyRoots.Count() - 1;
-        nsIFrame *target = static_cast<nsIFrame*>(mDirtyRoots[idx]);
+        PRInt32 idx = mDirtyRoots.Length() - 1;
+        nsIFrame *target = mDirtyRoots[idx];
         mDirtyRoots.RemoveElementAt(idx);
 
         if (!NS_SUBTREE_DIRTY(target)) {
           // It's not dirty anymore, which probably means the notification
           // was posted in the middle of a reflow (perhaps with a reflow
           // root in the middle).  Don't do anything.
           continue;
         }
 
         DoReflow(target);
 
         // Keep going until we're out of reflow commands, or we've run
         // past our deadline.
-      } while (mDirtyRoots.Count() &&
+      } while (mDirtyRoots.Length() &&
                (!aInterruptible || PR_IntervalNow() < deadline));
 
       // XXXwaterson for interruptible reflow, examine the tree and
       // re-enqueue any unflowed reflow targets.
 
       mIsReflowing = PR_FALSE;
     }
 
@@ -6734,26 +6734,26 @@ PresShell::ProcessReflowCommands(PRBool 
       DoVerifyReflow();
 #endif
 
       // If any new reflow commands were enqueued during the reflow, schedule
       // another reflow event to process them.  Note that we want to do this
       // after DidDoReflow(), since that method can change whether there are
       // dirty roots around by flushing, and there's no point in posting a
       // reflow event just to have the flush revoke it.
-      if (mDirtyRoots.Count())
+      if (mDirtyRoots.Length())
         PostReflowEvent();
     }
   }
   
   MOZ_TIMER_DEBUGLOG(("Stop: Reflow: PresShell::ProcessReflowCommands(), this=%p\n", this));
   MOZ_TIMER_STOP(mReflowWatch);  
 
   if (!mIsDestroying && mShouldUnsuppressPainting &&
-      mDirtyRoots.Count() == 0) {
+      mDirtyRoots.Length() == 0) {
     // We only unlock if we're out of reflows.  It's pointless
     // to unlock if reflows are still pending, since reflows
     // are just going to thrash the frames around some more.  By
     // waiting we avoid an overeager "jitter" effect.
     mShouldUnsuppressPainting = PR_FALSE;
     UnsuppressAndInvalidate();
   }
 
--- a/layout/forms/nsIComboboxControlFrame.h
+++ b/layout/forms/nsIComboboxControlFrame.h
@@ -39,17 +39,16 @@
 #define nsIComboboxControlFrame_h___
 
 #include "nsQueryFrame.h"
 #include "nsFont.h"
 
 class nsPresContext;
 class nsString;
 class nsIContent;
-class nsVoidArray;
 class nsCSSFrameConstructor;
 
 /** 
   * nsIComboboxControlFrame is the common interface for frames of form controls. It
   * provides a uniform way of creating widgets, resizing, and painting.
   * @see nsLeafFrame and its base classes for more info
   */
 class nsIComboboxControlFrame : public nsQueryFrame
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -58,19 +58,16 @@
 #include "nsAutoPtr.h"
 #include "nsSelectsAreaFrame.h"
 
 class nsIDOMHTMLSelectElement;
 class nsIDOMHTMLOptionsCollection;
 class nsIDOMHTMLOptionElement;
 class nsIComboboxControlFrame;
 class nsPresContext;
-class nsVoidArray;
-
-class nsVoidArray;
 class nsListEventListener;
 
 /**
  * Frame-based listbox.
  */
 
 class nsListControlFrame : public nsHTMLScrollFrame,
                            public nsIFormControlFrame, 
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -6710,51 +6710,51 @@ nsBlockFrame::CheckFloats(nsBlockReflowS
 {
 #ifdef DEBUG
   // If any line is still dirty, that must mean we're going to reflow this
   // block again soon (e.g. because we bailed out after noticing that
   // clearance was imposed), so don't worry if the floats are out of sync.
   PRBool anyLineDirty = PR_FALSE;
 
   // Check that the float list is what we would have built
-  nsAutoVoidArray lineFloats;
+  nsAutoTArray<nsIFrame*, 8> lineFloats;
   for (line_iterator line = begin_lines(), line_end = end_lines();
        line != line_end; ++line) {
     if (line->HasFloats()) {
       nsFloatCache* fc = line->GetFirstFloat();
       while (fc) {
         nsIFrame* floatFrame = fc->mPlaceholder->GetOutOfFlowFrame();
         lineFloats.AppendElement(floatFrame);
         fc = fc->Next();
       }
     }
     if (line->IsDirty()) {
       anyLineDirty = PR_TRUE;
     }
   }
   
-  nsAutoVoidArray storedFloats;
+  nsAutoTArray<nsIFrame*, 8> storedFloats;
   PRBool equal = PR_TRUE;
-  PRInt32 i = 0;
+  PRUint32 i = 0;
   for (nsIFrame* f = mFloats.FirstChild(); f; f = f->GetNextSibling()) {
     storedFloats.AppendElement(f);
-    if (i < lineFloats.Count() && lineFloats.ElementAt(i) != f) {
+    if (i < lineFloats.Length() && lineFloats.ElementAt(i) != f) {
       equal = PR_FALSE;
     }
     ++i;
   }
 
-  if ((!equal || lineFloats.Count() != storedFloats.Count()) && !anyLineDirty) {
+  if ((!equal || lineFloats.Length() != storedFloats.Length()) && !anyLineDirty) {
     NS_WARNING("nsBlockFrame::CheckFloats: Explicit float list is out of sync with float cache");
 #if defined(DEBUG_roc)
     nsIFrameDebug::RootFrameList(PresContext(), stdout, 0);
-    for (i = 0; i < lineFloats.Count(); ++i) {
+    for (i = 0; i < lineFloats.Length(); ++i) {
       printf("Line float: %p\n", lineFloats.ElementAt(i));
     }
-    for (i = 0; i < storedFloats.Count(); ++i) {
+    for (i = 0; i < storedFloats.Length(); ++i) {
       printf("Stored float: %p\n", storedFloats.ElementAt(i));
     }
 #endif
   }
 #endif
 
   nsFrameList oofs = GetOverflowOutOfFlows();
   if (oofs.NotEmpty()) {
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -1142,22 +1142,22 @@ nsContainerFrame::DeleteNextInFlowChild(
   NS_PRECONDITION(prevInFlow, "bad prev-in-flow");
 
   // If the next-in-flow has a next-in-flow then delete it, too (and
   // delete it first).
   // Do this in a loop so we don't overflow the stack for frames
   // with very many next-in-flows
   nsIFrame* nextNextInFlow = aNextInFlow->GetNextInFlow();
   if (nextNextInFlow) {
-    nsAutoVoidArray frames;
+    nsAutoTArray<nsIFrame*, 8> frames;
     for (nsIFrame* f = nextNextInFlow; f; f = f->GetNextInFlow()) {
       frames.AppendElement(f);
     }
-    for (PRInt32 i = frames.Count() - 1; i >= 0; --i) {
-      nsIFrame* delFrame = static_cast<nsIFrame*>(frames.ElementAt(i));
+    for (PRInt32 i = frames.Length() - 1; i >= 0; --i) {
+      nsIFrame* delFrame = frames.ElementAt(i);
       static_cast<nsContainerFrame*>(delFrame->GetParent())
         ->DeleteNextInFlowChild(aPresContext, delFrame, aDeletingEmptyFrames);
     }
   }
 
   aNextInFlow->Invalidate(aNextInFlow->GetOverflowRect());
 
   // Take the next-in-flow out of the parent's child list
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2912,18 +2912,18 @@ nsFrame::AddInlinePrefWidth(nsIRendering
 
 void
 nsIFrame::InlineMinWidthData::ForceBreak(nsIRenderingContext *aRenderingContext)
 {
   currentLine -= trailingWhitespace;
   prevLines = PR_MAX(prevLines, currentLine);
   currentLine = trailingWhitespace = 0;
 
-  for (PRInt32 i = 0, i_end = floats.Count(); i != i_end; ++i) {
-    nsIFrame *floatFrame = static_cast<nsIFrame*>(floats[i]);
+  for (PRUint32 i = 0, i_end = floats.Length(); i != i_end; ++i) {
+    nsIFrame *floatFrame = floats[i];
     nscoord float_min =
       nsLayoutUtils::IntrinsicForContainer(aRenderingContext, floatFrame,
                                            nsLayoutUtils::MIN_WIDTH);
     if (float_min > prevLines)
       prevLines = float_min;
   }
   floats.Clear();
   trailingTextFrame = nsnull;
@@ -2943,27 +2943,27 @@ nsIFrame::InlineMinWidthData::Optionally
   if (currentLine < 0 || atStartOfLine)
     return;
   ForceBreak(aRenderingContext);
 }
 
 void
 nsIFrame::InlinePrefWidthData::ForceBreak(nsIRenderingContext *aRenderingContext)
 {
-  if (floats.Count() != 0) {
+  if (floats.Length() != 0) {
             // preferred widths accumulated for floats that have already
             // been cleared past
     nscoord floats_done = 0,
             // preferred widths accumulated for floats that have not yet
             // been cleared past
             floats_cur_left = 0,
             floats_cur_right = 0;
 
-    for (PRInt32 i = 0, i_end = floats.Count(); i != i_end; ++i) {
-      nsIFrame *floatFrame = static_cast<nsIFrame*>(floats[i]);
+    for (PRUint32 i = 0, i_end = floats.Length(); i != i_end; ++i) {
+      nsIFrame *floatFrame = floats[i];
       const nsStyleDisplay *floatDisp = floatFrame->GetStyleDisplay();
       if (floatDisp->mBreakType == NS_STYLE_CLEAR_LEFT ||
           floatDisp->mBreakType == NS_STYLE_CLEAR_RIGHT ||
           floatDisp->mBreakType == NS_STYLE_CLEAR_LEFT_AND_RIGHT) {
         nscoord floats_cur = NSCoordSaturatingAdd(floats_cur_left,
                                                   floats_cur_right);
         if (floats_cur > floats_done)
           floats_done = floats_cur;
@@ -6941,39 +6941,38 @@ struct DR_State
                                    const nsHTMLReflowState* aReflowState);
   void FindMatchingRule(DR_FrameTreeNode& aNode);
   PRBool RuleMatches(DR_Rule&          aRule,
                      DR_FrameTreeNode& aNode);
   PRBool GetToken(FILE* aFile,
                   char* aBuf);
   DR_Rule* ParseRule(FILE* aFile);
   void ParseRulesFile();
-  void AddRule(nsVoidArray& aRules,
-               DR_Rule&     aRule);
+  void AddRule(nsTArray<DR_Rule*>& aRules,
+               DR_Rule&            aRule);
   PRBool IsWhiteSpace(int c);
   PRBool GetNumber(char*    aBuf, 
                  PRInt32&  aNumber);
   void PrettyUC(nscoord aSize,
                 char*   aBuf);
   void DisplayFrameTypeInfo(nsIFrame* aFrame,
                             PRInt32   aIndent);
   void DeleteTreeNode(DR_FrameTreeNode& aNode);
 
   PRBool      mInited;
   PRBool      mActive;
   PRInt32     mCount;
-  nsVoidArray mWildRules;
   PRInt32     mAssert;
   PRInt32     mIndent;
   PRBool      mIndentUndisplayedFrames;
-  nsVoidArray mFrameTypeTable;
   PRBool      mDisplayPixelErrors;
-
+  nsTArray<DR_Rule*>          mWildRules;
+  nsTArray<DR_FrameTypeInfo*> mFrameTypeTable;
   // reflow specific state
-  nsVoidArray mFrameTreeLeaves;
+  nsTArray<DR_FrameTreeNode*> mFrameTreeLeaves;
 };
 
 static DR_State *DR_state; // the one and only DR_State
 
 struct DR_RulePart 
 {
   DR_RulePart(nsIAtom* aFrameType) : mFrameType(aFrameType), mNext(0) {}
   void Destroy();
@@ -7015,26 +7014,26 @@ void DR_Rule::AddPart(nsIAtom* aFrameTyp
 }
 
 struct DR_FrameTypeInfo
 {
   DR_FrameTypeInfo(nsIAtom* aFrmeType, const char* aFrameNameAbbrev, const char* aFrameName);
   ~DR_FrameTypeInfo() { 
       MOZ_COUNT_DTOR(DR_FrameTypeInfo);
       PRInt32 numElements;
-      numElements = mRules.Count();
+      numElements = mRules.Length();
       for (PRInt32 i = numElements - 1; i >= 0; i--) {
-        delete (DR_Rule *)mRules.ElementAt(i);
+        delete mRules.ElementAt(i);
       }
    }
 
   nsIAtom*    mType;
   char        mNameAbbrev[16];
   char        mName[32];
-  nsVoidArray mRules;
+  nsTArray<DR_Rule*> mRules;
 };
 
 DR_FrameTypeInfo::DR_FrameTypeInfo(nsIAtom* aFrameType, 
                                    const char* aFrameNameAbbrev, 
                                    const char* aFrameName)
 {
   mType = aFrameType;
   strcpy(mNameAbbrev, aFrameNameAbbrev);
@@ -7108,27 +7107,27 @@ void DR_State::Init()
   ParseRulesFile();
   mInited = PR_TRUE;
 }
 
 DR_State::~DR_State()
 {
   MOZ_COUNT_DTOR(DR_State);
   PRInt32 numElements, i;
-  numElements = mWildRules.Count();
+  numElements = mWildRules.Length();
   for (i = numElements - 1; i >= 0; i--) {
-    delete (DR_Rule *)mWildRules.ElementAt(i);
-  }
-  numElements = mFrameTreeLeaves.Count();
+    delete mWildRules.ElementAt(i);
+  }
+  numElements = mFrameTreeLeaves.Length();
   for (i = numElements - 1; i >= 0; i--) {
-    delete (DR_FrameTreeNode *)mFrameTreeLeaves.ElementAt(i);
-  }
-  numElements = mFrameTypeTable.Count();
+    delete mFrameTreeLeaves.ElementAt(i);
+  }
+  numElements = mFrameTypeTable.Length();
   for (i = numElements - 1; i >= 0; i--) {
-    delete (DR_FrameTypeInfo *)mFrameTypeTable.ElementAt(i);
+    delete mFrameTypeTable.ElementAt(i);
   }
 }
 
 PRBool DR_State::GetNumber(char*     aBuf, 
                            PRInt32&  aNumber)
 {
   if (sscanf(aBuf, "%d", &aNumber) > 0) 
     return PR_TRUE;
@@ -7205,25 +7204,25 @@ DR_Rule* DR_State::ParseRule(FILE* aFile
           printf("invalid frame type - %s \n", buf);
         }
       }
     }
   }
   return rule;
 }
 
-void DR_State::AddRule(nsVoidArray& aRules,
-                       DR_Rule&     aRule)
-{
-  PRInt32 numRules = aRules.Count();
+void DR_State::AddRule(nsTArray<DR_Rule*>& aRules,
+                       DR_Rule&            aRule)
+{
+  PRInt32 numRules = aRules.Length();
   for (PRInt32 ruleX = 0; ruleX < numRules; ruleX++) {
-    DR_Rule* rule = (DR_Rule*)aRules.ElementAt(ruleX);
+    DR_Rule* rule = aRules.ElementAt(ruleX);
     NS_ASSERTION(rule, "program error");
     if (aRule.mLength > rule->mLength) {
-      aRules.InsertElementAt(&aRule, ruleX);
+      aRules.InsertElementAt(ruleX, &aRule);
       return;
     }
   }
   aRules.AppendElement(&aRule);
 }
 
 void DR_State::ParseRulesFile()
 {
@@ -7255,38 +7254,38 @@ void DR_State::AddFrameTypeInfo(nsIAtom*
                                 const char* aFrameNameAbbrev,
                                 const char* aFrameName)
 {
   mFrameTypeTable.AppendElement(new DR_FrameTypeInfo(aFrameType, aFrameNameAbbrev, aFrameName));
 }
 
 DR_FrameTypeInfo* DR_State::GetFrameTypeInfo(nsIAtom* aFrameType)
 {
-  PRInt32 numEntries = mFrameTypeTable.Count();
+  PRInt32 numEntries = mFrameTypeTable.Length();
   NS_ASSERTION(numEntries != 0, "empty FrameTypeTable");
   for (PRInt32 i = 0; i < numEntries; i++) {
-    DR_FrameTypeInfo* info = (DR_FrameTypeInfo*)mFrameTypeTable.ElementAt(i);
+    DR_FrameTypeInfo* info = mFrameTypeTable.ElementAt(i);
     if (info && (info->mType == aFrameType)) {
       return info;
     }
   }
-  return (DR_FrameTypeInfo*)mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type
+  return mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type
 }
 
 DR_FrameTypeInfo* DR_State::GetFrameTypeInfo(char* aFrameName)
 {
-  PRInt32 numEntries = mFrameTypeTable.Count();
+  PRInt32 numEntries = mFrameTypeTable.Length();
   NS_ASSERTION(numEntries != 0, "empty FrameTypeTable");
   for (PRInt32 i = 0; i < numEntries; i++) {
-    DR_FrameTypeInfo* info = (DR_FrameTypeInfo*)mFrameTypeTable.ElementAt(i);
+    DR_FrameTypeInfo* info = mFrameTypeTable.ElementAt(i);
     if (info && ((strcmp(aFrameName, info->mName) == 0) || (strcmp(aFrameName, info->mNameAbbrev) == 0))) {
       return info;
     }
   }
-  return (DR_FrameTypeInfo*)mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type
+  return mFrameTypeTable.ElementAt(numEntries - 1); // return unknown frame type
 }
 
 void DR_State::InitFrameTypeTable()
 {  
   AddFrameTypeInfo(nsGkAtoms::blockFrame,            "block",     "block");
   AddFrameTypeInfo(nsGkAtoms::brFrame,               "br",        "br");
   AddFrameTypeInfo(nsGkAtoms::bulletFrame,           "bullet",    "bullet");
   AddFrameTypeInfo(nsGkAtoms::gfxButtonControlFrame, "button",    "gfxButtonControl");
@@ -7378,29 +7377,29 @@ void DR_State::FindMatchingRule(DR_Frame
     NS_ASSERTION(PR_FALSE, "invalid DR_FrameTreeNode \n");
     return;
   }
 
   PRBool matchingRule = PR_FALSE;
 
   DR_FrameTypeInfo* info = GetFrameTypeInfo(aNode.mFrame->GetType());
   NS_ASSERTION(info, "program error");
-  PRInt32 numRules = info->mRules.Count();
+  PRInt32 numRules = info->mRules.Length();
   for (PRInt32 ruleX = 0; ruleX < numRules; ruleX++) {
-    DR_Rule* rule = (DR_Rule*)info->mRules.ElementAt(ruleX);
+    DR_Rule* rule = info->mRules.ElementAt(ruleX);
     if (rule && RuleMatches(*rule, aNode)) {
       aNode.mDisplay = rule->mDisplay;
       matchingRule = PR_TRUE;
       break;
     }
   }
   if (!matchingRule) {
-    PRInt32 numWildRules = mWildRules.Count();
+    PRInt32 numWildRules = mWildRules.Length();
     for (PRInt32 ruleX = 0; ruleX < numWildRules; ruleX++) {
-      DR_Rule* rule = (DR_Rule*)mWildRules.ElementAt(ruleX);
+      DR_Rule* rule = mWildRules.ElementAt(ruleX);
       if (rule && RuleMatches(*rule, aNode)) {
         aNode.mDisplay = rule->mDisplay;
         break;
       }
     }
   }
 }
     
@@ -7415,32 +7414,32 @@ DR_FrameTreeNode* DR_State::CreateTreeNo
   } else {
     parentFrame = aFrame->GetParent();
   }
 
   // find the parent tree node leaf
   DR_FrameTreeNode* parentNode = nsnull;
   
   DR_FrameTreeNode* lastLeaf = nsnull;
-  if(mFrameTreeLeaves.Count())
-    lastLeaf = (DR_FrameTreeNode*)mFrameTreeLeaves.ElementAt(mFrameTreeLeaves.Count() - 1);
+  if(mFrameTreeLeaves.Length())
+    lastLeaf = (DR_FrameTreeNode*)mFrameTreeLeaves.ElementAt(mFrameTreeLeaves.Length() - 1);
   if (lastLeaf) {
     for (parentNode = lastLeaf; parentNode && (parentNode->mFrame != parentFrame); parentNode = parentNode->mParent) {
     }
   }
   DR_FrameTreeNode* newNode = new DR_FrameTreeNode(aFrame, parentNode);
   FindMatchingRule(*newNode);
 
   newNode->mIndent = mIndent;
   if (newNode->mDisplay || mIndentUndisplayedFrames) {
     ++mIndent;
   }
 
   if (lastLeaf && (lastLeaf == parentNode)) {
-    mFrameTreeLeaves.RemoveElementAt(mFrameTreeLeaves.Count() - 1);
+    mFrameTreeLeaves.RemoveElementAt(mFrameTreeLeaves.Length() - 1);
   }
   mFrameTreeLeaves.AppendElement(newNode);
   mCount++;
 
   return newNode;
 }
 
 void DR_State::PrettyUC(nscoord aSize,
@@ -7458,18 +7457,18 @@ void DR_State::PrettyUC(nscoord aSize,
       sprintf(aBuf, "%d", aSize);
     }
   }
 }
 
 void DR_State::DeleteTreeNode(DR_FrameTreeNode& aNode)
 {
   mFrameTreeLeaves.RemoveElement(&aNode);
-  PRInt32 numLeaves = mFrameTreeLeaves.Count();
-  if ((0 == numLeaves) || (aNode.mParent != (DR_FrameTreeNode*)mFrameTreeLeaves.ElementAt(numLeaves - 1))) {
+  PRInt32 numLeaves = mFrameTreeLeaves.Length();
+  if ((0 == numLeaves) || (aNode.mParent != mFrameTreeLeaves.ElementAt(numLeaves - 1))) {
     mFrameTreeLeaves.AppendElement(aNode.mParent);
   }
 
   if (aNode.mDisplay || mIndentUndisplayedFrames) {
     --mIndent;
   }
   // delete the tree node 
   delete &aNode;
--- a/layout/generic/nsFrameList.cpp
+++ b/layout/generic/nsFrameList.cpp
@@ -322,61 +322,70 @@ nsFrameList::GetLength() const
   nsIFrame* frame = mFirstChild;
   while (frame) {
     count++;
     frame = frame->GetNextSibling();
   }
   return count;
 }
 
-static int CompareByContentOrder(const void* aF1, const void* aF2, void* aDummy)
+static int CompareByContentOrder(const nsIFrame* aF1, const nsIFrame* aF2)
 {
-  const nsIFrame* f1 = static_cast<const nsIFrame*>(aF1);
-  const nsIFrame* f2 = static_cast<const nsIFrame*>(aF2);
-  if (f1->GetContent() != f2->GetContent()) {
-    return nsLayoutUtils::CompareTreePosition(f1->GetContent(), f2->GetContent());
+  if (aF1->GetContent() != aF2->GetContent()) {
+    return nsLayoutUtils::CompareTreePosition(aF1->GetContent(), aF2->GetContent());
   }
 
-  if (f1 == f2) {
+  if (aF1 == aF2) {
     return 0;
   }
 
   const nsIFrame* f;
-  for (f = f2; f; f = f->GetPrevInFlow()) {
-    if (f == f1) {
+  for (f = aF2; f; f = f->GetPrevInFlow()) {
+    if (f == aF1) {
       // f1 comes before f2 in the flow
       return -1;
     }
   }
-  for (f = f1; f; f = f->GetPrevInFlow()) {
-    if (f == f2) {
+  for (f = aF1; f; f = f->GetPrevInFlow()) {
+    if (f == aF2) {
       // f1 comes after f2 in the flow
       return 1;
     }
   }
 
   NS_ASSERTION(PR_FALSE, "Frames for same content but not in relative flow order");
   return 0;
 }
 
+class CompareByContentOrderComparator
+{
+  public:
+  PRBool Equals(const nsIFrame* aA, const nsIFrame* aB) const {
+    return aA == aB;
+  }
+  PRBool LessThan(const nsIFrame* aA, const nsIFrame* aB) const {
+    return CompareByContentOrder(aA, aB) < 0;
+  }
+};
+
 void
 nsFrameList::SortByContentOrder()
 {
   if (!mFirstChild)
     return;
 
-  nsAutoVoidArray array;
+  nsAutoTArray<nsIFrame*, 8> array;
   nsIFrame* f;
   for (f = mFirstChild; f; f = f->GetNextSibling()) {
     array.AppendElement(f);
   }
-  array.Sort(CompareByContentOrder, nsnull);
-  f = mFirstChild = static_cast<nsIFrame*>(array.FastElementAt(0));
-  for (PRInt32 i = 1; i < array.Count(); ++i) {
-    nsIFrame* ff = static_cast<nsIFrame*>(array.FastElementAt(i));
+  array.Sort(CompareByContentOrderComparator());
+  f = mFirstChild = array.ElementAt(0);
+  for (PRUint32 i = 1; i < array.Length(); ++i) {
+    nsIFrame* ff = array.ElementAt(i);
     f->SetNextSibling(ff);
     f = ff;
   }
   f->SetNextSibling(nsnull);
 }
 
 nsIFrame*
 nsFrameList::GetPrevSiblingFor(nsIFrame* aFrame) const
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -1196,17 +1196,17 @@ public:
     // and when the last text ended with whitespace.
     PRBool skipWhitespace;
 
     // This contains the width of the trimmable whitespace at the end of
     // |currentLine|; it is zero if there is no such whitespace.
     nscoord trailingWhitespace;
 
     // Floats encountered in the lines.
-    nsVoidArray floats; // of nsIFrame*
+    nsTArray<nsIFrame*> floats;
   };
 
   struct InlineMinWidthData : public InlineIntrinsicWidthData {
     InlineMinWidthData()
       : trailingTextFrame(nsnull)
       , atStartOfLine(PR_TRUE)
     {}
 
--- a/layout/generic/nsImageMap.cpp
+++ b/layout/generic/nsImageMap.cpp
@@ -716,36 +716,36 @@ nsImageMap::nsImageMap() :
   mPresShell(nsnull),
   mImageFrame(nsnull),
   mContainsBlockContents(PR_FALSE)
 {
 }
 
 nsImageMap::~nsImageMap()
 {
-  NS_ASSERTION(mAreas.Count() == 0, "Destroy was not called");
+  NS_ASSERTION(mAreas.Length() == 0, "Destroy was not called");
 }
 
 NS_IMPL_ISUPPORTS4(nsImageMap,
                    nsIMutationObserver,
                    nsIDOMFocusListener,
                    nsIDOMEventListener,
                    nsIImageMap)
 
 NS_IMETHODIMP
 nsImageMap::GetBoundsForAreaContent(nsIContent *aContent, 
                                    nsPresContext* aPresContext, 
                                    nsRect& aBounds)
 {
   NS_ENSURE_TRUE(aContent && aPresContext, NS_ERROR_INVALID_ARG);
 
   // Find the Area struct associated with this content node, and return bounds
-  PRInt32 i, n = mAreas.Count();
+  PRUint32 i, n = mAreas.Length();
   for (i = 0; i < n; i++) {
-    Area* area = (Area*) mAreas.ElementAt(i);
+    Area* area = mAreas.ElementAt(i);
     if (area->mArea == aContent) {
       aBounds = nsRect();
       nsIPresShell* shell = aPresContext->PresShell();
       if (shell) {
         nsIFrame* frame = shell->GetPrimaryFrameFor(aContent);
         if (frame) {
           area->GetRect(frame, aBounds);
         }
@@ -756,19 +756,19 @@ nsImageMap::GetBoundsForAreaContent(nsIC
   return NS_ERROR_FAILURE;
 }
 
 void
 nsImageMap::FreeAreas()
 {
   nsFrameManager *frameManager = mPresShell->FrameManager();
 
-  PRInt32 i, n = mAreas.Count();
+  PRUint32 i, n = mAreas.Length();
   for (i = 0; i < n; i++) {
-    Area* area = (Area*) mAreas.ElementAt(i);
+    Area* area = mAreas.ElementAt(i);
     frameManager->RemoveAsPrimaryFrame(area->mArea, mImageFrame);
 
     nsCOMPtr<nsIContent> areaContent;
     area->GetArea(getter_AddRefs(areaContent));
     if (areaContent) {
       areaContent->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
     }
     delete area;
@@ -907,35 +907,35 @@ nsImageMap::AddArea(nsIContent* aArea)
   return NS_OK;
 }
 
 PRBool
 nsImageMap::IsInside(nscoord aX, nscoord aY,
                      nsIContent** aContent) const
 {
   NS_ASSERTION(mMap, "Not initialized");
-  PRInt32 i, n = mAreas.Count();
+  PRUint32 i, n = mAreas.Length();
   for (i = 0; i < n; i++) {
-    Area* area = (Area*) mAreas.ElementAt(i);
+    Area* area = mAreas.ElementAt(i);
     if (area->IsInside(aX, aY)) {
       area->GetArea(aContent);
 
       return PR_TRUE;
     }
   }
 
   return PR_FALSE;
 }
 
 void
 nsImageMap::Draw(nsIFrame* aFrame, nsIRenderingContext& aRC)
 {
-  PRInt32 i, n = mAreas.Count();
+  PRUint32 i, n = mAreas.Length();
   for (i = 0; i < n; i++) {
-    Area* area = (Area*) mAreas.ElementAt(i);
+    Area* area = mAreas.ElementAt(i);
     area->Draw(aFrame, aRC);
   }
 }
 
 void
 nsImageMap::MaybeUpdateAreas(nsIContent *aContent)
 {
   if (aContent == mMap || mContainsBlockContents) {
@@ -1006,19 +1006,19 @@ nsImageMap::Blur(nsIDOMEvent* aEvent)
 nsresult
 nsImageMap::ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus)
 {
   //Set which one of our areas changed focus
   nsCOMPtr<nsIDOMEventTarget> target;
   if (NS_SUCCEEDED(aEvent->GetTarget(getter_AddRefs(target))) && target) {
     nsCOMPtr<nsIContent> targetContent(do_QueryInterface(target));
     if (targetContent) {
-      PRInt32 i, n = mAreas.Count();
+      PRUint32 i, n = mAreas.Length();
       for (i = 0; i < n; i++) {
-        Area* area = (Area*) mAreas.ElementAt(i);
+        Area* area = mAreas.ElementAt(i);
         nsCOMPtr<nsIContent> areaContent;
         area->GetArea(getter_AddRefs(areaContent));
         if (areaContent.get() == targetContent.get()) {
           //Set or Remove internal focus
           area->HasFocus(aFocus);
           //Now invalidate the rect
           nsCOMPtr<nsIDocument> doc = targetContent->GetDocument();
           //This check is necessary to see if we're still attached to the doc
--- a/layout/generic/nsImageMap.h
+++ b/layout/generic/nsImageMap.h
@@ -37,29 +37,30 @@
 
 /* code for HTML client-side image maps */
 
 #ifndef nsImageMap_h___
 #define nsImageMap_h___
 
 #include "nsISupports.h"
 #include "nsCoord.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsStubMutationObserver.h"
 #include "nsIDOMFocusListener.h"
 #include "nsIFrame.h"
 #include "nsIImageMap.h"
 
 class nsIDOMHTMLAreaElement;
 class nsIDOMHTMLMapElement;
 class nsPresContext;
 class nsIRenderingContext;
 class nsIURI;
 class nsString;
 class nsIDOMEvent;
+class Area;
 
 class nsImageMap : public nsStubMutationObserver, public nsIDOMFocusListener,
                    public nsIImageMap
 {
 public:
   nsImageMap();
 
   nsresult Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap);
@@ -113,13 +114,13 @@ protected:
  
   nsresult ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus);
 
   void MaybeUpdateAreas(nsIContent *aContent);
 
   nsIPresShell* mPresShell; // WEAK - owns the frame that owns us
   nsIFrame* mImageFrame;  // the frame that owns us
   nsCOMPtr<nsIContent> mMap;
-  nsAutoVoidArray mAreas; // almost always has some entries
+  nsAutoTArray<Area*, 8> mAreas; // almost always has some entries
   PRBool mContainsBlockContents;
 };
 
 #endif /* nsImageMap_h___ */
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -62,17 +62,17 @@
 #include "nsIContent.h"
 #include "nsStyleConsts.h"
 #include "nsStyleContext.h"
 #include "nsCoord.h"
 #include "nsIFontMetrics.h"
 #include "nsIRenderingContext.h"
 #include "nsIPresShell.h"
 #include "nsITimer.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsIDOMText.h"
 #include "nsIDocument.h"
 #include "nsIDeviceContext.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCompatibility.h"
 #include "nsCSSColorUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
@@ -2742,17 +2742,17 @@ protected:
 
 
     FrameData(nsPresContext* aPresContext,
               nsIFrame*       aFrame)
       : mPresContext(aPresContext), mFrame(aFrame) {}
   };
 
   nsCOMPtr<nsITimer> mTimer;
-  nsVoidArray     mFrames;
+  nsTArray<FrameData*> mFrames;
   nsPresContext* mPresContext;
 
 protected:
 
   static nsBlinkTimer* sTextBlinker;
   static PRUint32      sState; // 0-2 == on; 3 == off
   
 };
@@ -2791,42 +2791,41 @@ void nsBlinkTimer::Stop()
   }
 }
 
 NS_IMPL_ISUPPORTS1(nsBlinkTimer, nsITimerCallback)
 
 void nsBlinkTimer::AddFrame(nsPresContext* aPresContext, nsIFrame* aFrame) {
   FrameData* frameData = new FrameData(aPresContext, aFrame);
   mFrames.AppendElement(frameData);
-  if (1 == mFrames.Count()) {
+  if (1 == mFrames.Length()) {
     Start();
   }
 }
 
 PRBool nsBlinkTimer::RemoveFrame(nsIFrame* aFrame) {
-  PRInt32 i, n = mFrames.Count();
-  PRBool rv = PR_FALSE;
+  PRUint32 i, n = mFrames.Length();
   for (i = 0; i < n; i++) {
-    FrameData* frameData = (FrameData*) mFrames.ElementAt(i);
+    FrameData* frameData = mFrames.ElementAt(i);
 
     if (frameData->mFrame == aFrame) {
-      rv = mFrames.RemoveElementAt(i);
+      mFrames.RemoveElementAt(i);
       delete frameData;
       break;
     }
   }
   
-  if (0 == mFrames.Count()) {
+  if (0 == mFrames.Length()) {
     Stop();
   }
-  return rv;
+  return PR_TRUE;
 }
 
 PRInt32 nsBlinkTimer::FrameCount() {
-  return mFrames.Count();
+  return PRInt32(mFrames.Length());
 }
 
 NS_IMETHODIMP nsBlinkTimer::Notify(nsITimer *timer)
 {
   // Toggle blink state bit so that text code knows whether or not to
   // render. All text code shares the same flag so that they all blink
   // in unison.
   sState = (sState + 1) % 4;
@@ -2839,19 +2838,19 @@ NS_IMETHODIMP nsBlinkTimer::Notify(nsITi
   char buf[50];
   PRTime delta;
   LL_SUB(delta, now, gLastTick);
   gLastTick = now;
   PR_snprintf(buf, sizeof(buf), "%lldusec", delta);
   printf("%s\n", buf);
 #endif
 
-  PRInt32 i, n = mFrames.Count();
+  PRUint32 i, n = mFrames.Length();
   for (i = 0; i < n; i++) {
-    FrameData* frameData = (FrameData*) mFrames.ElementAt(i);
+    FrameData* frameData = mFrames.ElementAt(i);
 
     // Determine damaged area and tell view manager to redraw it
     // blink doesn't blink outline ... I hope
     nsRect bounds(nsPoint(0, 0), frameData->mFrame->GetSize());
     frameData->mFrame->Invalidate(bounds);
   }
   return NS_OK;
 }
--- a/layout/inspector/src/inCSSValueSearch.cpp
+++ b/layout/inspector/src/inCSSValueSearch.cpp
@@ -168,17 +168,17 @@ inCSSValueSearch::SearchStep(PRBool* _re
   return NS_OK;
 }
 
 
 NS_IMETHODIMP 
 inCSSValueSearch::GetStringResultAt(PRInt32 aIndex, nsAString& _retval)
 {
   if (mHoldResults) {
-    nsAutoString* result = (nsAutoString*)mResults->ElementAt(aIndex);
+    nsAutoString* result = mResults->ElementAt(aIndex);
     _retval = *result;
   } else if (aIndex == mResultCount-1) {
     _retval = mLastResult;
   } else {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
@@ -283,17 +283,17 @@ inCSSValueSearch::SetTextCriteria(const 
 
 ///////////////////////////////////////////////////////////////////////////////
 // inCSSValueSearch
 
 nsresult
 inCSSValueSearch::InitSearch()
 {
   if (mHoldResults) {
-    mResults = new nsVoidArray();
+    mResults = new nsTArray<nsAutoString *>();
   }
   
   mResultCount = 0;
 
   return NS_OK;
 }
 
 nsresult
--- a/layout/inspector/src/inCSSValueSearch.h
+++ b/layout/inspector/src/inCSSValueSearch.h
@@ -39,17 +39,17 @@
 #define __inCSSValueSearch_h__
 
 #include "inICSSValueSearch.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIDOMDocument.h"
 #include "inISearchObserver.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsIInspectorCSSUtils.h"
 
 class nsIDOMCSSStyleSheet;
 class nsIDOMCSSRuleList;
 class nsIDOMCSSStyleRule;
 class nsIURI;
 
 class inCSSValueSearch : public inICSSValueSearch
@@ -61,17 +61,17 @@ public:
 
   inCSSValueSearch();
   virtual ~inCSSValueSearch();
 
 protected:
   nsCOMPtr<inISearchObserver> mObserver;
   nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
   nsCOMPtr<nsIDOMDocument> mDocument;
-  nsVoidArray* mResults;
+  nsTArray<nsAutoString *>* mResults;
   nsCSSProperty* mProperties;
   nsString mLastResult;
   nsString mBaseURL;
   nsString mTextCriteria;
   PRInt32 mResultCount;
   PRUint32 mPropertyCount;
   PRBool mIsActive;
   PRBool mHoldResults;
--- a/layout/inspector/src/inDOMView.cpp
+++ b/layout/inspector/src/inDOMView.cpp
@@ -975,23 +975,23 @@ inDOMView::ContentRemoved(nsIDocument *a
 ///////////////////////////////////////////////////////////////////////
 // inDOMView
 
 //////// NODE MANAGEMENT
 
 inDOMViewNode*
 inDOMView::GetNodeAt(PRInt32 aRow)
 {
-  return (inDOMViewNode*)mNodes.ElementAt(aRow);
+  return mNodes.ElementAt(aRow);
 }
 
 PRInt32
 inDOMView::GetRowCount()
 {
-  return mNodes.Count();
+  return mNodes.Length();
 }
 
 PRInt32
 inDOMView::NodeToRow(inDOMViewNode* aNode)
 {
   return mNodes.IndexOf(aNode);
 }
 
@@ -1021,17 +1021,17 @@ inDOMView::AppendNode(inDOMViewNode* aNo
 }
 
 void
 inDOMView::InsertNode(inDOMViewNode* aNode, PRInt32 aRow)
 {
   if (RowOutOfBounds(aRow, 1))
     AppendNode(aNode);
   else
-    mNodes.InsertElementAt(aNode, aRow);
+    mNodes.InsertElementAt(aRow, aNode);
 }
 
 void
 inDOMView::RemoveNode(PRInt32 aRow)
 {
   if (RowOutOfBounds(aRow, 1))
     return;
 
@@ -1041,26 +1041,26 @@ inDOMView::RemoveNode(PRInt32 aRow)
 
 void
 inDOMView::ReplaceNode(inDOMViewNode* aNode, PRInt32 aRow)
 {
   if (RowOutOfBounds(aRow, 1))
     return;
 
   delete GetNodeAt(aRow);
-  mNodes.ReplaceElementAt(aNode, aRow);
+  mNodes.ReplaceElementsAt(aRow, 1, aNode);
 }
 
 void
-inDOMView::InsertNodes(nsVoidArray& aNodes, PRInt32 aRow)
+inDOMView::InsertNodes(nsTArray<inDOMViewNode*>& aNodes, PRInt32 aRow)
 {
   if (aRow < 0 || aRow > GetRowCount())
     return;
 
-  mNodes.InsertElementsAt(aNodes, aRow);
+  mNodes.InsertElementsAt(aRow, aNodes);
 }
 
 void
 inDOMView::RemoveNodes(PRInt32 aRow, PRInt32 aCount)
 {
   if (aRow < 0)
     return;
 
@@ -1089,24 +1089,24 @@ inDOMView::ExpandNode(PRInt32 aRow)
   inDOMViewNode* node = nsnull;
   RowToNode(aRow, &node);
 
   nsCOMArray<nsIDOMNode> kids;
   GetChildNodesFor(node ? node->node : mRootNode,
                    kids);
   PRInt32 kidCount = kids.Count();
 
-  nsVoidArray list(kidCount);
+  nsTArray<inDOMViewNode*> list(kidCount);
 
   inDOMViewNode* newNode = nsnull;
   inDOMViewNode* prevNode = nsnull;
 
   for (PRInt32 i = 0; i < kidCount; ++i) {
     newNode = CreateNode(kids[i], node);
-    list.ReplaceElementAt(newNode, i);
+    list.ReplaceElementsAt(i, 1, newNode);
 
     if (prevNode)
       prevNode->next = newNode;
     newNode->previous = prevNode;
     prevNode = newNode;
   }
 
   InsertNodes(list, aRow+1);
--- a/layout/inspector/src/inDOMView.h
+++ b/layout/inspector/src/inDOMView.h
@@ -41,17 +41,17 @@
 #include "inIDOMView.h"
 #include "inIDOMUtils.h"
 
 #include "nsITreeView.h"
 #include "nsITreeSelection.h"
 #include "nsStubMutationObserver.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMDocument.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsStaticAtom.h"
 
 class inDOMViewNode;
 
 class inDOMView : public inIDOMView,
                   public nsITreeView,
                   public nsStubMutationObserver
@@ -99,28 +99,28 @@ protected:
   PRPackedBool mShowSubDocuments;
   PRPackedBool mShowWhitespaceNodes;
   PRPackedBool mShowAccessibleNodes;
   PRUint32 mWhatToShow;
 
   nsCOMPtr<nsIDOMNode> mRootNode;
   nsCOMPtr<nsIDOMDocument> mRootDocument;
 
-  nsVoidArray mNodes;
+  nsTArray<inDOMViewNode*> mNodes;
 
   inDOMViewNode* GetNodeAt(PRInt32 aIndex);
   PRInt32 GetRowCount();
   PRInt32 NodeToRow(inDOMViewNode* aNode);
   PRBool RowOutOfBounds(PRInt32 aRow, PRInt32 aCount);
   inDOMViewNode* CreateNode(nsIDOMNode* aNode, inDOMViewNode* aParent);
   void AppendNode(inDOMViewNode* aNode);
   void InsertNode(inDOMViewNode* aNode, PRInt32 aIndex);
   void RemoveNode(PRInt32 aIndex);
   void ReplaceNode(inDOMViewNode* aNode, PRInt32 aIndex);
-  void InsertNodes(nsVoidArray& aNodes, PRInt32 aIndex);
+  void InsertNodes(nsTArray<inDOMViewNode*>& aNodes, PRInt32 aIndex);
   void RemoveNodes(PRInt32 aIndex, PRInt32 aCount);
   void RemoveAllNodes();
   void ExpandNode(PRInt32 aRow);
   void CollapseNode(PRInt32 aRow);
 
   nsresult RowToNode(PRInt32 aRow, inDOMViewNode** aNode);
   nsresult NodeToRow(nsIDOMNode* aNode, PRInt32* aRow);
 
--- a/layout/inspector/src/inDeepTreeWalker.cpp
+++ b/layout/inspector/src/inDeepTreeWalker.cpp
@@ -69,18 +69,18 @@ inDeepTreeWalker::inDeepTreeWalker()
   : mShowAnonymousContent(PR_FALSE),
     mShowSubDocuments(PR_FALSE),
     mWhatToShow(nsIDOMNodeFilter::SHOW_ALL)
 {
 }
 
 inDeepTreeWalker::~inDeepTreeWalker() 
 { 
-  for (PRInt32 i = mStack.Count() - 1; i >= 0; --i) {
-    delete static_cast<DeepTreeStackItem*>(mStack[i]);
+  for (PRInt32 i = mStack.Length() - 1; i >= 0; --i) {
+    delete mStack[i];
   }
 }
 
 NS_IMPL_ISUPPORTS2(inDeepTreeWalker,
                    inIDeepTreeWalker,
                    nsIDOMTreeWalker)
 
 ////////////////////////////////////////////////////
@@ -223,25 +223,25 @@ inDeepTreeWalker::PreviousNode(nsIDOMNod
 NS_IMETHODIMP
 inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
 {
   if (!mCurrentNode) return NS_OK;
   
   nsCOMPtr<nsIDOMNode> next;
   
   while (1) {
-    DeepTreeStackItem* top = (DeepTreeStackItem*)mStack.ElementAt(mStack.Count()-1);
+    DeepTreeStackItem* top = mStack.ElementAt(mStack.Length()-1);
     nsCOMPtr<nsIDOMNodeList> kids = top->kids;
     PRUint32 childCount;
     kids->GetLength(&childCount);
 
     if (top->lastIndex == childCount) {
-      mStack.RemoveElementAt(mStack.Count()-1);
+      mStack.RemoveElementAt(mStack.Length()-1);
       delete top;
-      if (mStack.Count() == 0) {
+      if (mStack.Length() == 0) {
         mCurrentNode = nsnull;
         break;
       }
     } else {
       kids->Item(top->lastIndex++, getter_AddRefs(next));
       PushNode(next);
       break;      
     }
@@ -283,17 +283,17 @@ inDeepTreeWalker::PushNode(nsIDOMNode* a
         aNode->GetChildNodes(getter_AddRefs(kids));
       }
     } else
       aNode->GetChildNodes(getter_AddRefs(kids));
   }
   
   item->kids = kids;
   item->lastIndex = 0;
-  mStack.AppendElement((void*)item);
+  mStack.AppendElement(item);
 }
 
 /*
 // This NextNode implementation does not require the use of stacks, 
 // as does the one above. However, it does not handle anonymous 
 // content and sub-documents.
 NS_IMETHODIMP
 inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
--- a/layout/inspector/src/inDeepTreeWalker.h
+++ b/layout/inspector/src/inDeepTreeWalker.h
@@ -37,19 +37,20 @@
 
 #ifndef __inDeepTreeWalker_h___
 #define __inDeepTreeWalker_h___
 
 #include "inIDeepTreeWalker.h"
 
 #include "nsCOMPtr.h"
 #include "nsIDOMNode.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 
 class inIDOMUtils;
+class DeepTreeStackItem;
 
 class inDeepTreeWalker : public inIDeepTreeWalker
 {
 public:
 	NS_DECL_ISUPPORTS
 	NS_DECL_NSIDOMTREEWALKER
 	NS_DECL_INIDEEPTREEWALKER
 
@@ -60,17 +61,17 @@ protected:
   void PushNode(nsIDOMNode* aNode);
 
   PRBool mShowAnonymousContent;
   PRBool mShowSubDocuments;
   nsCOMPtr<nsIDOMNode> mRoot;
   nsCOMPtr<nsIDOMNode> mCurrentNode;
   PRUint32 mWhatToShow;
   
-  nsAutoVoidArray mStack;
+  nsAutoTArray<DeepTreeStackItem*, 8> mStack;
   nsCOMPtr<inIDOMUtils> mDOMUtils;
 };
 
 // {BFCB82C2-5611-4318-90D6-BAF4A7864252}
 #define IN_DEEPTREEWALKER_CID \
 { 0xbfcb82c2, 0x5611, 0x4318, { 0x90, 0xd6, 0xba, 0xf4, 0xa7, 0x86, 0x42, 0x52 } }
 
 #endif // __inDeepTreeWalker_h___
--- a/layout/mathml/base/src/nsMathMLmmultiscriptsFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLmmultiscriptsFrame.cpp
@@ -76,17 +76,17 @@ nsMathMLmmultiscriptsFrame::TransmitAuto
   UpdatePresentationDataFromChildAt(1, -1,
     ~NS_MATHML_DISPLAYSTYLE, NS_MATHML_DISPLAYSTYLE);
 
   // The TeXbook (Ch 17. p.141) says the superscript inherits the compression
   // while the subscript is compressed. So here we collect subscripts and set
   // the compression flag in them.
   PRInt32 count = 0;
   PRBool isSubScript = PR_FALSE;
-  nsAutoVoidArray subScriptFrames;
+  nsAutoTArray<nsIFrame*, 8> subScriptFrames;
   nsIFrame* childFrame = mFrames.FirstChild();
   while (childFrame) {
     if (childFrame->GetContent()->Tag() == nsGkAtoms::mprescripts_) {
       // mprescripts frame
     }
     else if (0 == count) {
       // base frame
     }
@@ -99,18 +99,18 @@ nsMathMLmmultiscriptsFrame::TransmitAuto
       else {
         // superscript
       }
       isSubScript = !isSubScript;
     }
     count++;
     childFrame = childFrame->GetNextSibling();
   }
-  for (PRInt32 i = subScriptFrames.Count() - 1; i >= 0; i--) {
-    childFrame = (nsIFrame*)subScriptFrames[i];
+  for (PRInt32 i = subScriptFrames.Length() - 1; i >= 0; i--) {
+    childFrame = subScriptFrames[i];
     PropagatePresentationDataFor(childFrame,
       NS_MATHML_COMPRESSED, NS_MATHML_COMPRESSED);
   }
 
   return NS_OK;
 }
 
 void
--- a/layout/mathml/base/src/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLmtableFrame.cpp
@@ -41,17 +41,17 @@
 #include "nsBlockFrame.h"
 #include "nsPresContext.h"
 #include "nsStyleContext.h"
 #include "nsStyleConsts.h"
 #include "nsINameSpaceManager.h"
 #include "nsIRenderingContext.h"
 #include "nsIFontMetrics.h"
 
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsTableOuterFrame.h"
 #include "nsTableFrame.h"
 #include "nsTableCellFrame.h"
 #include "celldata.h"
 
 #include "nsMathMLmtableFrame.h"
 
@@ -59,18 +59,18 @@
 // <mtable> -- table or matrix - implementation
 //
 
 // helper function to perform an in-place split of a space-delimited string,
 // and return an array of pointers for the beginning of each segment, i.e.,
 // aOffset[0] is the first string, aOffset[1] is the second string, etc.
 // Used to parse attributes like columnalign='left right', rowalign='top bottom'
 static void
-SplitString(nsString&    aString, // [IN/OUT]
-            nsVoidArray& aOffset) // [OUT]
+SplitString(nsString&             aString, // [IN/OUT]
+            nsTArray<PRUnichar*>& aOffset) // [OUT]
 {
   static const PRUnichar kNullCh = PRUnichar('\0');
 
   aString.Append(kNullCh);  // put an extra null at the end
 
   PRUnichar* start = aString.BeginWriting();
   PRUnichar* end   = start;
 
@@ -90,18 +90,18 @@ SplitString(nsString&    aString, // [IN
     }
 
     start = ++end;
   }
 }
 
 struct nsValueList
 {
-  nsString    mData;
-  nsVoidArray mArray;
+  nsString             mData;
+  nsTArray<PRUnichar*> mArray;
 
   nsValueList(nsString& aData) {
     mData.Assign(aData);
     SplitString(mData, mArray);
   }
 };
 
 // Each rowalign='top bottom' or columnalign='left right center' (from
@@ -128,26 +128,26 @@ GetValueAt(nsIFrame* aTableOrRowFrame,
   nsValueList* valueList = static_cast<nsValueList*>
                                       (aTableOrRowFrame->GetProperty(aAttribute));
   if (!valueList) {
     // The property isn't there yet, so set it
     nsAutoString values;
     aTableOrRowFrame->GetContent()->GetAttr(kNameSpaceID_None, aAttribute, values);
     if (!values.IsEmpty())
       valueList = new nsValueList(values);
-    if (!valueList || !valueList->mArray.Count()) {
+    if (!valueList || !valueList->mArray.Length()) {
       delete valueList; // ok either way, delete is null safe
       return nsnull;
     }
     aTableOrRowFrame->SetProperty(aAttribute, valueList, DestroyValueListFunc);
   }
-  PRInt32 count = valueList->mArray.Count();
+  PRInt32 count = valueList->mArray.Length();
   return (aRowOrColIndex < count)
-         ? (PRUnichar*)(valueList->mArray[aRowOrColIndex])
-         : (PRUnichar*)(valueList->mArray[count-1]);
+         ? valueList->mArray[aRowOrColIndex]
+         : valueList->mArray[count-1];
 }
 
 #ifdef NS_DEBUG
 static PRBool
 IsTable(PRUint8 aDisplay)
 {
   if ((aDisplay == NS_STYLE_DISPLAY_TABLE) ||
       (aDisplay == NS_STYLE_DISPLAY_INLINE_TABLE))
--- a/layout/mathml/content/src/nsMathMLOperators.cpp
+++ b/layout/mathml/content/src/nsMathMLOperators.cpp
@@ -35,17 +35,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsHashtable.h"
-#include "nsVoidArray.h"
 #include "nsTArray.h"
 
 #include "nsIComponentManager.h"
 #include "nsIPersistentProperties2.h"
 #include "nsNetUtil.h"
 #include "nsCRT.h"
 
 #include "nsMathMLOperators.h"
@@ -76,19 +75,19 @@ struct OperatorData {
   encountered in the Operator Dictionary.
 */
 static OperatorData*   gOperatorFound[4];
 
 static PRInt32         gTableRefCount = 0;
 static PRInt32         gOperatorCount = 0;
 static OperatorData*   gOperatorArray = nsnull;
 static nsHashtable*    gOperatorTable = nsnull;
-static nsVoidArray*    gStretchyOperatorArray = nsnull;
-static nsTArray<nsString>*  gInvariantCharArray = nsnull;
 static PRBool          gInitialized   = PR_FALSE;
+static nsTArray<OperatorData*>* gStretchyOperatorArray = nsnull;
+static nsTArray<nsString>*      gInvariantCharArray    = nsnull;
 
 static const PRUnichar kNullCh  = PRUnichar('\0');
 static const PRUnichar kDashCh  = PRUnichar('#');
 static const PRUnichar kEqualCh = PRUnichar('=');
 static const PRUnichar kColonCh = PRUnichar(':');
 
 static const char* const kMathVariant_name[] = {
   "normal",
@@ -373,17 +372,17 @@ InitOperators(void)
 }
 
 nsresult
 InitGlobals()
 {
   gInitialized = PR_TRUE;
   nsresult rv = NS_ERROR_OUT_OF_MEMORY;
   gInvariantCharArray = new nsTArray<nsString>();
-  gStretchyOperatorArray = new nsVoidArray();
+  gStretchyOperatorArray = new nsTArray<OperatorData*>();
   if (gInvariantCharArray && gStretchyOperatorArray) {
     gOperatorTable = new nsHashtable();
     if (gOperatorTable) {
       rv = InitOperators();
     }
   }
   if (NS_FAILED(rv))
     nsMathMLOperators::CleanUp();
@@ -561,61 +560,63 @@ nsMathMLOperators::IsMutableOperator(con
 }
 
 PRInt32
 nsMathMLOperators::CountStretchyOperator()
 {
   if (!gInitialized) {
     InitGlobals();
   }
-  return (gStretchyOperatorArray) ? gStretchyOperatorArray->Count() : 0;
+  return (gStretchyOperatorArray) ? gStretchyOperatorArray->Length() : 0;
 }
 
 PRInt32
 nsMathMLOperators::FindStretchyOperator(PRUnichar aOperator)
 {
   if (!gInitialized) {
     InitGlobals();
   }
   if (gStretchyOperatorArray) {
-    for (PRInt32 k = 0; k < gStretchyOperatorArray->Count(); k++) {
-      OperatorData* data = (OperatorData*)gStretchyOperatorArray->ElementAt(k);
+    for (PRUint32 k = 0; k < gStretchyOperatorArray->Length(); k++) {
+      OperatorData* data = gStretchyOperatorArray->ElementAt(k);
       if (data && (aOperator == data->mStr[0])) {
         return k;
       }
     }
   }
   return kNotFound;
 }
 
 nsStretchDirection
 nsMathMLOperators::GetStretchyDirectionAt(PRInt32 aIndex)
 {
   NS_ASSERTION(gStretchyOperatorArray, "invalid call");
   if (gStretchyOperatorArray) {
-    NS_ASSERTION(aIndex < gStretchyOperatorArray->Count(), "invalid call");
-    OperatorData* data = (OperatorData*)gStretchyOperatorArray->ElementAt(aIndex);
+    NS_ASSERTION(aIndex < PRInt32(gStretchyOperatorArray->Length()),
+                 "invalid call");
+    OperatorData* data = gStretchyOperatorArray->ElementAt(aIndex);
     if (data) {
       if (NS_MATHML_OPERATOR_IS_STRETCHY_VERT(data->mFlags))
         return NS_STRETCH_DIRECTION_VERTICAL;
       else if (NS_MATHML_OPERATOR_IS_STRETCHY_HORIZ(data->mFlags))
         return NS_STRETCH_DIRECTION_HORIZONTAL;
       NS_ASSERTION(PR_FALSE, "*** bad setup ***");
     }
   }
   return NS_STRETCH_DIRECTION_UNSUPPORTED;
 }
 
 void
 nsMathMLOperators::DisableStretchyOperatorAt(PRInt32 aIndex)
 {
   NS_ASSERTION(gStretchyOperatorArray, "invalid call");
   if (gStretchyOperatorArray) {
-    NS_ASSERTION(aIndex < gStretchyOperatorArray->Count(), "invalid call");
-    gStretchyOperatorArray->ReplaceElementAt(nsnull, aIndex);
+    NS_ASSERTION(aIndex < PRInt32(gStretchyOperatorArray->Length()),
+                 "invalid call");
+    (*gStretchyOperatorArray)[aIndex] = nsnull;
   }
 }
 
 /* static */ eMATHVARIANT
 nsMathMLOperators::LookupInvariantChar(const nsAString& aChar)
 {
   if (!gInitialized) {
     InitGlobals();
--- a/layout/printing/nsPrintData.cpp
+++ b/layout/printing/nsPrintData.cpp
@@ -118,21 +118,16 @@ nsPrintData::~nsPrintData()
       if (NS_FAILED(rv)) {
         // XXX nsPrintData::ShowPrintErrorDialog(rv);
       }
     }
   }
 
   delete mPrintObject;
 
-  if (mPrintDocList != nsnull) {
-    mPrintDocList->Clear();
-    delete mPrintDocList;
-  }
-
   if (mBrandName) {
     NS_Free(mBrandName);
   }
 }
 
 void nsPrintData::OnStartPrinting()
 {
   if (!mOnStartSent) {
--- a/layout/printing/nsPrintData.h
+++ b/layout/printing/nsPrintData.h
@@ -37,17 +37,17 @@
 #ifndef nsPrintData_h___
 #define nsPrintData_h___
 
 // Interfaces
 #include "nsIDOMWindow.h"
 #include "nsIDeviceContext.h"
 #include "nsIPrintProgressParams.h"
 #include "nsIPrintOptions.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCOMArray.h"
 
 // Classes
 class nsPrintObject;
 class nsPrintPreviewListener;
 class nsIWebProgressListener;
 
 //------------------------------------------------------------------------
@@ -97,17 +97,17 @@ public:
   nsPrintObject *                mPrintObject;
   nsPrintObject *                mSelectedPO;
 
   nsCOMArray<nsIWebProgressListener> mPrintProgressListeners;
   nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
 
   nsCOMPtr<nsIDOMWindow> mCurrentFocusWin; // cache a pointer to the currently focused window
 
-  nsVoidArray*                mPrintDocList;
+  nsTArray<nsPrintObject*>    mPrintDocList;
   PRPackedBool                mIsIFrameSelected;
   PRPackedBool                mIsParentAFrameSet;
   PRPackedBool                mOnStartSent;
   PRPackedBool                mIsAborted;           // tells us the document is being aborted
   PRPackedBool                mPreparingForPrint;   // see comments above
   PRPackedBool                mDocWasToBeDestroyed; // see comments above
   PRBool                      mShrinkToFit;
   PRInt16                     mPrintFrameType;
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -196,17 +196,17 @@ static const char * gFrameHowToEnableStr
 static const char * gPrintRangeStr[]       = {"kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection", "kRangeFocusFrame"};
 #else
 #define PRT_YESNO(_p)
 #define PR_PL(_p1)
 #endif
 
 #ifdef EXTENDED_DEBUG_PRINTING
 // Forward Declarations
-static void DumpPrintObjectsListStart(const char * aStr, nsVoidArray * aDocList);
+static void DumpPrintObjectsListStart(const char * aStr, nsTArray<nsPrintObject*> * aDocList);
 static void DumpPrintObjectsTree(nsPrintObject * aPO, int aLevel= 0, FILE* aFD = nsnull);
 static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,nsIDeviceContext * aDC, int aLevel= 0, FILE * aFD = nsnull);
 
 #define DUMP_DOC_LIST(_title) DumpPrintObjectsListStart((_title), mPrt->mPrintDocList);
 #define DUMP_DOC_TREE DumpPrintObjectsTree(mPrt->mPrintObject);
 #define DUMP_DOC_TREELAYOUT DumpPrintObjectsTreeLayout(mPrt->mPrintObject, mPrt->mPrintDC);
 #else
 #define DUMP_DOC_LIST(_title)
@@ -394,17 +394,17 @@ nsresult nsPrintEngine::GetSeqFrameAndCo
 //-- Section: nsIWebBrowserPrint
 //---------------------------------------------------------------------------------
 
 // Foward decl for Debug Helper Functions
 #ifdef EXTENDED_DEBUG_PRINTING
 static int RemoveFilesInDir(const char * aDir);
 static void GetDocTitleAndURL(nsPrintObject* aPO, char *& aDocStr, char *& aURLStr);
 static void DumpPrintObjectsTree(nsPrintObject * aPO, int aLevel, FILE* aFD);
-static void DumpPrintObjectsList(nsVoidArray * aDocList);
+static void DumpPrintObjectsList(nsTArray<nsPrintObject*> * aDocList);
 static void RootFrameList(nsPresContext* aPresContext, FILE* out, PRInt32 aIndent);
 static void DumpViews(nsIDocShell* aDocShell, FILE* out);
 static void DumpLayoutData(char* aTitleStr, char* aURLStr,
                            nsPresContext* aPresContext,
                            nsIDeviceContext * aDC, nsIFrame * aRootFrame,
                            nsIDocShell * aDocShell, FILE* aFD);
 #endif
 
@@ -503,37 +503,34 @@ nsPrintEngine::DoCommonPrint(PRBool     
   // Get the currently focused window and cache it
   // because the Print Dialog will "steal" focus and later when you try
   // to get the currently focused windows it will be NULL
   mPrt->mCurrentFocusWin = FindFocusedDOMWindow();
 
   // Check to see if there is a "regular" selection
   PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);
 
-  mPrt->mPrintDocList = new nsVoidArray();
-  NS_ENSURE_TRUE(mPrt->mPrintDocList, NS_ERROR_OUT_OF_MEMORY);
-
   // Get the docshell for this documentviewer
   nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   mPrt->mPrintObject = new nsPrintObject();
   NS_ENSURE_TRUE(mPrt->mPrintObject, NS_ERROR_OUT_OF_MEMORY);
   rv = mPrt->mPrintObject->Init(webContainer);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_ENSURE_TRUE(mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject),
+  NS_ENSURE_TRUE(mPrt->mPrintDocList.AppendElement(mPrt->mPrintObject),
                  NS_ERROR_OUT_OF_MEMORY);
 
   mPrt->mIsParentAFrameSet = IsParentAFrameSet(webContainer);
   mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet ? eFrameSet : eDoc;
 
   // Build the "tree" of PrintObjects
   nsCOMPtr<nsIDocShellTreeNode>  parentAsNode(do_QueryInterface(webContainer));
-  BuildDocTree(parentAsNode, mPrt->mPrintDocList, mPrt->mPrintObject);
+  BuildDocTree(parentAsNode, &mPrt->mPrintDocList, mPrt->mPrintObject);
 
   // XXX This isn't really correct...
   if (!mPrt->mPrintObject->mDocument->GetRootContent())
     return NS_ERROR_GFX_PRINTER_STARTDOC;
 
   // Create the linkage from the sub-docs back to the content element
   // in the parent document
   MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject);
@@ -822,23 +819,23 @@ nsPrintEngine::EnumerateDocumentNames(PR
                                       PRUnichar*** aResult)
 {
   NS_ENSURE_ARG(aCount);
   NS_ENSURE_ARG_POINTER(aResult);
 
   *aCount = 0;
   *aResult = nsnull;
 
-  PRInt32     numDocs = mPrt->mPrintDocList->Count();
+  PRInt32     numDocs = mPrt->mPrintDocList.Length();
   PRUnichar** array   = (PRUnichar**) nsMemory::Alloc(numDocs * sizeof(PRUnichar*));
   if (!array)
     return NS_ERROR_OUT_OF_MEMORY;
 
   for (PRInt32 i=0;i<numDocs;i++) {
-    nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+    nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     PRUnichar * docTitleStr;
     PRUnichar * docURLStr;
     GetDocumentTitleAndURL(po->mDocument, &docTitleStr, &docURLStr);
 
     // Use the URL if the doc is empty
     if (!docTitleStr || !*docTitleStr) {
       if (docURLStr && *docURLStr) {
@@ -1098,19 +1095,19 @@ nsPrintEngine::IsParentAFrameSet(nsIDocS
   return isFrameSet;
 }
 
 
 //---------------------------------------------------------------------
 // Recursively build a list of sub documents to be printed
 // that mirrors the document tree
 void
-nsPrintEngine::BuildDocTree(nsIDocShellTreeNode * aParentNode,
-                                 nsVoidArray *         aDocList,
-                                 nsPrintObject *         aPO)
+nsPrintEngine::BuildDocTree(nsIDocShellTreeNode *      aParentNode,
+                            nsTArray<nsPrintObject*> * aDocList,
+                            nsPrintObject *            aPO)
 {
   NS_ASSERTION(aParentNode, "Pointer is null!");
   NS_ASSERTION(aDocList, "Pointer is null!");
   NS_ASSERTION(aPO, "Pointer is null!");
 
   PRInt32 childWebshellCount;
   aParentNode->GetChildCount(&childWebshellCount);
   if (childWebshellCount > 0) {
@@ -1195,18 +1192,18 @@ nsPrintEngine::MapContentToWebShells(nsP
   nsIContent *rootContent = aPO->mDocument->GetRootContent();
   if (rootContent) {
     MapContentForPO(aPO, rootContent);
   } else {
     NS_WARNING("Null root content on (sub)document.");
   }
 
   // Continue recursively walking the chilren of this PO
-  for (PRInt32 i=0;i<aPO->mKids.Count();i++) {
-    MapContentToWebShells(aRootPO, (nsPrintObject*)aPO->mKids[i]);
+  for (PRUint32 i=0;i<aPO->mKids.Length();i++) {
+    MapContentToWebShells(aRootPO, aPO->mKids[i]);
   }
 
 }
 
 //-------------------------------------------------------
 // A Frame's sub-doc may contain content or a FrameSet
 // When it contains a FrameSet the mFrameType for the PrintObject
 // is always set to an eFrame. Which is fine when printing "AsIs"
@@ -1222,18 +1219,18 @@ nsPrintEngine::MapContentToWebShells(nsP
 //            when printing "As Is" leave it as an eFrame
 void
 nsPrintEngine::CheckForChildFrameSets(nsPrintObject* aPO)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Continue recursively walking the chilren of this PO
   PRBool hasChildFrames = PR_FALSE;
-  for (PRInt32 i=0;i<aPO->mKids.Count();i++) {
-    nsPrintObject* po = (nsPrintObject*)aPO->mKids[i];
+  for (PRUint32 i=0;i<aPO->mKids.Length();i++) {
+    nsPrintObject* po = aPO->mKids[i];
     if (po->mFrameType == eFrame) {
       hasChildFrames = PR_TRUE;
       CheckForChildFrameSets(po);
     }
   }
 
   if (hasChildFrames && aPO->mFrameType == eFrame) {
     aPO->mFrameType = eFrameSet;
@@ -1268,19 +1265,19 @@ nsPrintEngine::MapContentForPO(nsPrintOb
   nsIDocument* subDoc = doc->GetSubDocumentFor(aContent);
 
   if (subDoc) {
     nsCOMPtr<nsISupports> container = subDoc->GetContainer();
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
 
     if (docShell) {
       nsPrintObject * po = nsnull;
-      PRInt32 cnt = aPO->mKids.Count();
+      PRInt32 cnt = aPO->mKids.Length();
       for (PRInt32 i=0;i<cnt;i++) {
-        nsPrintObject* kid = (nsPrintObject*)aPO->mKids.ElementAt(i);
+        nsPrintObject* kid = aPO->mKids.ElementAt(i);
         if (kid->mDocument == subDoc) {
           po = kid;
           break;
         }
       }
 
       // XXX If a subdocument has no onscreen presentation, there will be no PO
       //     This is even if there should be a print presentation
@@ -1348,18 +1345,18 @@ nsPrintEngine::IsThereAnIFrameSelected(n
 void
 nsPrintEngine::SetPrintPO(nsPrintObject* aPO, PRBool aPrint)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Set whether to print flag
   aPO->mDontPrint = !aPrint;
 
-  for (PRInt32 i=0;i<aPO->mKids.Count();i++) {
-    SetPrintPO((nsPrintObject*)aPO->mKids[i], aPrint);
+  for (PRUint32 i=0;i<aPO->mKids.Length();i++) {
+    SetPrintPO(aPO->mKids[i], aPrint);
   } 
 }
 
 //---------------------------------------------------------------------
 // This will first use a Title and/or URL from the PrintSettings
 // if one isn't set then it uses the one from the document
 // then if not title is there we will make sure we send something back
 // depending on the situation.
@@ -1618,35 +1615,35 @@ nsPrintEngine::SetupToPrintContent()
   if (NS_FAILED(rv)) {
     return NS_ERROR_FAILURE;
   }
 
   // Here is where we do the extra reflow for shrinking the content
   // But skip this step if we are in PrintPreview
   if (mPrt->mShrinkToFit && !ppIsShrinkToFit) {
     // Now look for the PO that has the smallest percent for shrink to fit
-    if (mPrt->mPrintDocList->Count() > 1 && mPrt->mPrintObject->mFrameType == eFrameSet) {
+    if (mPrt->mPrintDocList.Length() > 1 && mPrt->mPrintObject->mFrameType == eFrameSet) {
       nsPrintObject* smallestPO = FindSmallestSTF();
       NS_ASSERTION(smallestPO, "There must always be an XMost PO!");
       if (smallestPO) {
         // Calc the shrinkage based on the entire content area
         mPrt->mShrinkRatio = smallestPO->mShrinkRatio;
       }
     } else {
       // Single document so use the Shrink as calculated for the PO
       mPrt->mShrinkRatio = mPrt->mPrintObject->mShrinkRatio;
     }
 
     // Only Shrink if we are smaller
     if (mPrt->mShrinkRatio < 0.998f) {
       // Clamp Shrink to Fit to 60%
       mPrt->mShrinkRatio = PR_MAX(mPrt->mShrinkRatio, 0.60f);
 
-      for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
-        nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+      for (PRUint32 i=0;i<mPrt->mPrintDocList.Length();i++) {
+        nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
         NS_ASSERTION(po, "nsPrintObject can't be null!");
         // Wipe out the presentation before we reflow
         po->DestroyPresentation();
       }
 
 #if (defined(XP_WIN) || defined(XP_OS2)) && defined(EXTENDED_DEBUG_PRINTING)
       // We need to clear all the output files here
       // because they will be re-created with second reflow of the docs
@@ -1663,17 +1660,17 @@ nsPrintEngine::SetupToPrintContent()
       if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, PR_TRUE))) {
         return NS_ERROR_FAILURE;
       }
     }
 
 #ifdef PR_LOGGING
     {
       float calcRatio = 0.0f;
-      if (mPrt->mPrintDocList->Count() > 1 && mPrt->mPrintObject->mFrameType == eFrameSet) {
+      if (mPrt->mPrintDocList.Length() > 1 && mPrt->mPrintObject->mFrameType == eFrameSet) {
         nsPrintObject* smallestPO = FindSmallestSTF();
         NS_ASSERTION(smallestPO, "There must always be an XMost PO!");
         if (smallestPO) {
           // Calc the shrinkage based on the entire content area
           calcRatio = smallestPO->mShrinkRatio;
         }
       } else {
         // Single document so use the Shrink as calculated for the PO
@@ -1804,19 +1801,19 @@ nsPrintEngine::ReflowDocList(nsPrintObje
     aPO->mZoomRatio = float(scaling);
   }
 
   nsresult rv;
   // Reflow the PO
   rv = ReflowPrintObject(aPO);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  PRInt32 cnt = aPO->mKids.Count();
+  PRInt32 cnt = aPO->mKids.Length();
   for (PRInt32 i=0;i<cnt;i++) {
-    rv = ReflowDocList((nsPrintObject *)aPO->mKids[i], aSetPixelScale);
+    rv = ReflowDocList(aPO->mKids[i], aSetPixelScale);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 //-------------------------------------------------------
 // Reflow a nsPrintObject
 nsresult
@@ -2052,19 +2049,18 @@ nsPrintEngine::ReflowPrintObject(nsPrint
 //-------------------------------------------------------
 // Figure out how many documents and how many total pages we are printing
 void
 nsPrintEngine::CalcNumPrintablePages(PRInt32& aNumPages)
 {
   aNumPages = 0;
   // Count the number of printable documents
   // and printable pages
-  PRInt32 i;
-  for (i=0; i<mPrt->mPrintDocList->Count(); i++) {
-    nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+  for (PRUint32 i=0; i<mPrt->mPrintDocList.Length(); i++) {
+    nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     if (po->mPresContext && po->mPresContext->IsRootPaginatedDocument()) {
       nsIPageSequenceFrame* pageSequence;
       po->mPresShell->GetPageSequenceFrame(&pageSequence);
       nsIFrame * seqFrame = do_QueryFrame(pageSequence);
       if (seqFrame) {
         nsIFrame* frame = seqFrame->GetFirstChild(nsnull);
         while (frame) {
@@ -2094,18 +2090,18 @@ nsPrintEngine::PrintDocContent(nsPrintOb
   if (!aPO->mHasBeenPrinted && aPO->IsPrintable()) {
     aStatus = DoPrint(aPO);
     return PR_TRUE;
   }
 
   // If |aPO->mPrintAsIs| and |aPO->mHasBeenPrinted| are true,
   // the kids frames are already processed in |PrintPage|.
   if (!aPO->mInvisible && !(aPO->mPrintAsIs && aPO->mHasBeenPrinted)) {
-    for (PRInt32 i=0;i<aPO->mKids.Count();i++) {
-      nsPrintObject* po = (nsPrintObject*)aPO->mKids[i];
+    for (PRUint32 i=0;i<aPO->mKids.Length();i++) {
+      nsPrintObject* po = aPO->mKids[i];
       PRBool printed = PrintDocContent(po, aStatus);
       if (printed || NS_FAILED(aStatus)) {
         return PR_TRUE;
       }
     }
   }
   return PR_FALSE;
 }
@@ -2759,18 +2755,18 @@ nsPrintEngine::DonePrintingPages(nsPrint
 // Recursively sets the PO items to be printed "As Is"
 // from the given item down into the tree
 void
 nsPrintEngine::SetPrintAsIs(nsPrintObject* aPO, PRBool aAsIs)
 {
   NS_ASSERTION(aPO, "Pointer is null!");
 
   aPO->mPrintAsIs = aAsIs;
-  for (PRInt32 i=0;i<aPO->mKids.Count();i++) {
-    SetPrintAsIs((nsPrintObject*)aPO->mKids[i], aAsIs);
+  for (PRUint32 i=0;i<aPO->mKids.Length();i++) {
+    SetPrintAsIs(aPO->mKids[i], aAsIs);
   }
 }
 
 //-------------------------------------------------------
 // Given a DOMWindow it recursively finds the PO object that matches
 nsPrintObject*
 nsPrintEngine::FindPrintObjectByDOMWin(nsPrintObject* aPO,
                                        nsIDOMWindow* aDOMWin)
@@ -2783,20 +2779,19 @@ nsPrintEngine::FindPrintObjectByDOMWin(n
     return nsnull;
   }
 
   nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(aPO->mDocShell));
   if (domWin && domWin == aDOMWin) {
     return aPO;
   }
 
-  PRInt32 cnt = aPO->mKids.Count();
+  PRInt32 cnt = aPO->mKids.Length();
   for (PRInt32 i = 0; i < cnt; ++i) {
-    nsPrintObject* po = FindPrintObjectByDOMWin((nsPrintObject*)aPO->mKids[i],
-                                                aDOMWin);
+    nsPrintObject* po = FindPrintObjectByDOMWin(aPO->mKids[i], aDOMWin);
     if (po) {
       return po;
     }
   }
 
   return nsnull;
 }
 
@@ -2845,19 +2840,19 @@ nsPrintEngine::EnablePOsForPrinting()
 
     // Print all the pages or a sub range of pages
     if (printRangeType == nsIPrintSettings::kRangeAllPages ||
         printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) {
       SetPrintPO(mPrt->mPrintObject, PR_TRUE);
 
       // Set the children so they are PrinAsIs
       // In this case, the children are probably IFrames
-      if (mPrt->mPrintObject->mKids.Count() > 0) {
-        for (PRInt32 i=0;i<mPrt->mPrintObject->mKids.Count();i++) {
-          nsPrintObject* po = (nsPrintObject*)mPrt->mPrintObject->mKids[i];
+      if (mPrt->mPrintObject->mKids.Length() > 0) {
+        for (PRUint32 i=0;i<mPrt->mPrintObject->mKids.Length();i++) {
+          nsPrintObject* po = mPrt->mPrintObject->mKids[i];
           NS_ASSERTION(po, "nsPrintObject can't be null!");
           SetPrintAsIs(po);
         }
 
         // ***** Another override *****
         mPrt->mPrintFrameType = nsIPrintSettings::kFramesAsIs;
       }
       PR_PL(("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]));
@@ -2895,18 +2890,18 @@ nsPrintEngine::EnablePOsForPrinting()
             mPrt->mPrintSettings->SetPrintRange(printRangeType);
           }
           PR_PL(("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->mPrintFrameType]));
           PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable]));
           PR_PL(("PrintRange:         %s \n", gPrintRangeStr[printRangeType]));
           return NS_OK;
         }
       } else {
-        for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
-          nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+        for (PRUint32 i=0;i<mPrt->mPrintDocList.Length();i++) {
+          nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
           NS_ASSERTION(po, "nsPrintObject can't be null!");
           nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mDocShell);
           if (IsThereARangeSelection(domWin)) {
             mPrt->mCurrentFocusWin = domWin;
             SetPrintPO(po, PR_TRUE);
             break;
           }
         }
@@ -2963,35 +2958,35 @@ nsPrintEngine::EnablePOsForPrinting()
 
     if ((mPrt->mIsParentAFrameSet && mPrt->mCurrentFocusWin) || mPrt->mIsIFrameSelected) {
       nsPrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCurrentFocusWin);
       if (po != nsnull) {
         mPrt->mSelectedPO = po;
         // NOTE: Calling this sets the "po" and
         // we don't want to do this for documents that have no children,
         // because then the "DoEndPage" gets called and it shouldn't
-        if (po->mKids.Count() > 0) {
+        if (po->mKids.Length() > 0) {
           // Makes sure that itself, and all of its children are printed "AsIs"
           SetPrintAsIs(po);
         }
 
         // Now, only enable this POs (the selected PO) and all of its children
         SetPrintPO(po, PR_TRUE);
       }
     }
     return NS_OK;
   }
 
   // If we are print each subdoc separately,
   // then don't print any of the FraneSet Docs
   if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
     SetPrintPO(mPrt->mPrintObject, PR_TRUE);
-    PRInt32 cnt = mPrt->mPrintDocList->Count();
+    PRInt32 cnt = mPrt->mPrintDocList.Length();
     for (PRInt32 i=0;i<cnt;i++) {
-      nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+      nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
       NS_ASSERTION(po, "nsPrintObject can't be null!");
       if (po->mFrameType == eFrameSet) {
         po->mDontPrint = PR_TRUE;
       }
     }
   }
 
   return NS_OK;
@@ -3001,18 +2996,18 @@ nsPrintEngine::EnablePOsForPrinting()
 // Return the nsPrintObject with that is XMost (The widest frameset frame) AND
 // contains the XMost (widest) layout frame
 nsPrintObject*
 nsPrintEngine::FindSmallestSTF()
 {
   float smallestRatio = 1.0f;
   nsPrintObject* smallestPO = nsnull;
 
-  for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
-    nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
+  for (PRUint32 i=0;i<mPrt->mPrintDocList.Length();i++) {
+    nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     if (po->mFrameType != eFrameSet && po->mFrameType != eIFrame) {
       if (po->mShrinkRatio < smallestRatio) {
         smallestRatio = po->mShrinkRatio;
         smallestPO    = po;
       }
     }
   }
@@ -3035,18 +3030,18 @@ nsPrintEngine::TurnScriptingOn(PRBool aD
 #endif
   if (!prt) {
     return;
   }
 
   NS_ASSERTION(mDocument, "We MUST have a document.");
   // First, get the script global object from the document...
 
-  for (PRInt32 i=0;i<prt->mPrintDocList->Count();i++) {
-    nsPrintObject* po = (nsPrintObject*)prt->mPrintDocList->ElementAt(i);
+  for (PRUint32 i=0;i<prt->mPrintDocList.Length();i++) {
+    nsPrintObject* po = prt->mPrintDocList.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
 
     nsIDocument* doc = po->mDocument;
     
     // get the script global object
     nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject();
 
     if (scriptGlobalObj) {
@@ -3439,28 +3434,28 @@ void DumpLayoutData(char*              a
     }
     if (aFD == nsnull) {
       fclose(fd);
     }
   }
 }
 
 //-------------------------------------------------------------
-static void DumpPrintObjectsList(nsVoidArray * aDocList)
+static void DumpPrintObjectsList(nsTArray<nsPrintObject*> * aDocList)
 {
   if (!kPrintingLogMod || kPrintingLogMod->level != DUMP_LAYOUT_LEVEL) return;
 
   NS_ASSERTION(aDocList, "Pointer is null!");
 
   const char types[][3] = {"DC", "FR", "IF", "FS"};
   PR_PL(("Doc List\n***************************************************\n"));
   PR_PL(("T  P A H    PO    DocShell   Seq     Page      Root     Page#    Rect\n"));
-  PRInt32 cnt = aDocList->Count();
+  PRInt32 cnt = aDocList->Length();
   for (PRInt32 i=0;i<cnt;i++) {
-    nsPrintObject* po = (nsPrintObject*)aDocList->ElementAt(i);
+    nsPrintObject* po = aDocList->ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     nsIFrame* rootFrame = nsnull;
     if (po->mPresShell) {
       rootFrame = po->mPresShell->FrameManager()->GetRootFrame();
       while (rootFrame != nsnull) {
         nsIPageSequenceFrame * sqf = do_QueryFrame(rootFrame);
         if (sqf) {
           break;
@@ -3483,19 +3478,19 @@ static void DumpPrintObjectsTree(nsPrint
   NS_ASSERTION(aPO, "Pointer is null!");
 
   FILE * fd = aFD?aFD:stdout;
   const char types[][3] = {"DC", "FR", "IF", "FS"};
   if (aLevel == 0) {
     fprintf(fd, "DocTree\n***************************************************\n");
     fprintf(fd, "T     PO    DocShell   Seq      Page     Page#    Rect\n");
   }
-  PRInt32 cnt = aPO->mKids.Count();
+  PRInt32 cnt = aPO->mKids.Length();
   for (PRInt32 i=0;i<cnt;i++) {
-    nsPrintObject* po = (nsPrintObject*)aPO->mKids.ElementAt(i);
+    nsPrintObject* po = aPO->mKids.ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     for (PRInt32 k=0;k<aLevel;k++) fprintf(fd, "  ");
     fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po, po->mDocShell.get(), po->mSeqFrame,
            po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height);
   }
 }
 
 //-------------------------------------------------------------
@@ -3556,30 +3551,30 @@ static void DumpPrintObjectsTreeLayout(n
       char * urlStr;
       GetDocTitleAndURL(aPO, docStr, urlStr);
       DumpLayoutData(docStr, urlStr, aPO->mPresContext, aDC, rootFrame, aPO->mDocShell, fd);
       if (docStr) nsMemory::Free(docStr);
       if (urlStr) nsMemory::Free(urlStr);
     }
     fprintf(fd, "<***************************************************>\n");
 
-    PRInt32 cnt = aPO->mKids.Count();
+    PRInt32 cnt = aPO->mKids.Length();
     for (PRInt32 i=0;i<cnt;i++) {
-      nsPrintObject* po = (nsPrintObject*)aPO->mKids.ElementAt(i);
+      nsPrintObject* po = aPO->mKids.ElementAt(i);
       NS_ASSERTION(po, "nsPrintObject can't be null!");
       DumpPrintObjectsTreeLayout(po, aDC, aLevel+1, fd);
     }
   }
   if (aLevel == 0 && fd) {
     fclose(fd);
   }
 }
 
 //-------------------------------------------------------------
-static void DumpPrintObjectsListStart(const char * aStr, nsVoidArray * aDocList)
+static void DumpPrintObjectsListStart(const char * aStr, nsTArray<nsPrintObject*> * aDocList)
 {
   if (!kPrintingLogMod || kPrintingLogMod->level != DUMP_LAYOUT_LEVEL) return;
 
   NS_ASSERTION(aStr, "Pointer is null!");
   NS_ASSERTION(aDocList, "Pointer is null!");
 
   PR_PL(("%s\n", aStr));
   DumpPrintObjectsList(aDocList);
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -130,19 +130,19 @@ public:
   PRBool CheckDocumentForPPCaching();
   void InstallPrintPreviewListener();
 
   // nsIDocumentViewerPrint Printing Methods
   PRBool   PrintPage(nsPrintObject* aPOect, PRBool& aInRange);
   PRBool   DonePrintingPages(nsPrintObject* aPO, nsresult aResult);
 
   //---------------------------------------------------------------------
-  void BuildDocTree(nsIDocShellTreeNode * aParentNode,
-                    nsVoidArray *         aDocList,
-                    nsPrintObject *         aPO);
+  void BuildDocTree(nsIDocShellTreeNode *      aParentNode,
+                    nsTArray<nsPrintObject*> * aDocList,
+                    nsPrintObject *            aPO);
   nsresult ReflowDocList(nsPrintObject * aPO, PRBool aSetPixelScale);
 
   nsresult ReflowPrintObject(nsPrintObject * aPO);
 
   void CheckForChildFrameSets(nsPrintObject* aPO);
 
   void CalcNumPrintablePages(PRInt32& aNumPages);
   void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -48,18 +48,18 @@ nsPrintObject::nsPrintObject() :
   mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE),
   mShrinkRatio(1.0), mZoomRatio(1.0)
 {
 }
 
 
 nsPrintObject::~nsPrintObject()
 {
-  for (PRInt32 i=0;i<mKids.Count();i++) {
-    nsPrintObject* po = (nsPrintObject*)mKids[i];
+  for (PRUint32 i=0;i<mKids.Length();i++) {
+    nsPrintObject* po = mKids[i];
     delete po;
   }
 
   DestroyPresentation();
 }
 
 //------------------------------------------------------------------
 // Resets PO by destroying the presentation
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -74,17 +74,17 @@ public:
   nsCOMPtr<nsPresContext>  mPresContext;
   nsCOMPtr<nsIPresShell>   mPresShell;
   nsCOMPtr<nsIViewManager> mViewManager;
   nsCOMPtr<nsIWidget>      mWindow;
 
   nsIContent*      mContent;
   PrintObjectType  mFrameType;
   
-  nsVoidArray      mKids;
+  nsTArray<nsPrintObject*> mKids;
   nsPrintObject*   mParent;
   PRPackedBool     mHasBeenPrinted;
   PRPackedBool     mDontPrint;
   PRPackedBool     mPrintAsIs;
   PRPackedBool     mSharedPresShell;
   PRPackedBool     mInvisible;        // Indicates PO is set to not visible by CSS
 
   float            mShrinkRatio;
--- a/layout/style/nsCSSLoader.cpp
+++ b/layout/style/nsCSSLoader.cpp
@@ -1519,17 +1519,17 @@ CSSLoaderImpl::ParseSheet(nsIUnicharInpu
   // Push our load data on the stack so any kids can pick it up
   mParsingDatas.AppendElement(aLoadData);
   nsCOMPtr<nsIURI> sheetURI, baseURI;
   aLoadData->mSheet->GetSheetURI(getter_AddRefs(sheetURI));
   aLoadData->mSheet->GetBaseURI(getter_AddRefs(baseURI));
   rv = parser->Parse(aStream, sheetURI, baseURI,
                      aLoadData->mSheet->Principal(), aLoadData->mLineNumber,
                      aLoadData->mAllowUnsafeRules);
-  mParsingDatas.RemoveElementAt(mParsingDatas.Count() - 1);
+  mParsingDatas.RemoveElementAt(mParsingDatas.Length() - 1);
   RecycleParser(parser);
 
   NS_ASSERTION(aLoadData->mPendingChildren == 0 || !aLoadData->mSyncLoad,
                "Sync load has leftover pending children!");
   
   if (aLoadData->mPendingChildren == 0) {
     LOG(("  No pending kids from parse"));
     aCompleted = PR_TRUE;
@@ -1642,17 +1642,17 @@ CSSLoaderImpl::DoSheetComplete(SheetLoad
 
     // If we have a parent, our parent is no longer being parsed, and
     // we are the last pending child, then our load completion
     // completes the parent too.  Note that the parent _can_ still be
     // being parsed (eg if the child (us) failed to open the channel
     // or some such).
     if (data->mParentData &&
         --(data->mParentData->mPendingChildren) == 0 &&
-        mParsingDatas.IndexOf(data->mParentData) == -1) {
+        !mParsingDatas.Contains(data->mParentData)) {
       DoSheetComplete(data->mParentData, aStatus, aDatasToNotify);
     }
     
     data = data->mNext;
   }
 
   // Now that it's marked complete, put the sheet in our cache
   if (NS_SUCCEEDED(aStatus) && aLoadData->mURI) {
@@ -1686,17 +1686,17 @@ CSSLoaderImpl::LoadInlineStyle(nsIConten
                                const nsSubstring& aTitle,
                                const nsSubstring& aMedia,
                                nsICSSLoaderObserver* aObserver,
                                PRBool* aCompleted,
                                PRBool* aIsAlternate)
 {
   LOG(("CSSLoaderImpl::LoadInlineStyle"));
   NS_PRECONDITION(aStream, "Must have a stream to parse!");
-  NS_ASSERTION(mParsingDatas.Count() == 0, "We're in the middle of a parse?");
+  NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
 
   *aCompleted = PR_TRUE;
 
   if (!mEnabled) {
     LOG_WARN(("  Not enabled"));
     return NS_ERROR_NOT_AVAILABLE;
   }
 
@@ -1756,17 +1756,17 @@ CSSLoaderImpl::LoadStyleLink(nsIContent*
                              const nsSubstring& aTitle,
                              const nsSubstring& aMedia,
                              PRBool aHasAlternateRel,
                              nsICSSLoaderObserver* aObserver,
                              PRBool* aIsAlternate)
 {
   LOG(("CSSLoaderImpl::LoadStyleLink"));
   NS_PRECONDITION(aURL, "Must have URL to load");
-  NS_ASSERTION(mParsingDatas.Count() == 0, "We're in the middle of a parse?");
+  NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
 
   LOG_URI("  Link uri: '%s'", aURL);
   LOG(("  Link title: '%s'", NS_ConvertUTF16toUTF8(aTitle).get()));
   LOG(("  Link media: '%s'", NS_ConvertUTF16toUTF8(aMedia).get()));
   LOG(("  Link alternate rel: %d", aHasAlternateRel));
 
   if (!mEnabled) {
     LOG_WARN(("  Not enabled"));
@@ -1893,21 +1893,20 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyl
   rv = CheckLoadAllowed(principal, aURL, context);
   if (NS_FAILED(rv)) return rv;
 
   LOG(("  Passed load check"));
   
   SheetLoadData* parentData = nsnull;
   nsCOMPtr<nsICSSLoaderObserver> observer;
 
-  PRInt32 count = mParsingDatas.Count();
+  PRInt32 count = mParsingDatas.Length();
   if (count > 0) {
     LOG(("  Have a parent load"));
-    parentData = static_cast<SheetLoadData*>
-                            (mParsingDatas.ElementAt(count - 1));
+    parentData = mParsingDatas.ElementAt(count - 1);
     // Check for cycles
     SheetLoadData* data = parentData;
     while (data && data->mURI) {
       PRBool equal;
       if (NS_SUCCEEDED(data->mURI->Equals(aURL, &equal)) && equal) {
         // Houston, we have a loop, blow off this child and pretend this never
         // happened
         LOG_ERROR(("  @import cycle detected, dropping load"));
@@ -2007,17 +2006,17 @@ nsresult
 CSSLoaderImpl::InternalLoadNonDocumentSheet(nsIURI* aURL, 
                                             PRBool aAllowUnsafeRules,
                                             nsIPrincipal* aOriginPrincipal,
                                             nsICSSStyleSheet** aSheet,
                                             nsICSSLoaderObserver* aObserver)
 {
   NS_PRECONDITION(aURL, "Must have a URI to load");
   NS_PRECONDITION(aSheet || aObserver, "Sheet and observer can't both be null");
-  NS_ASSERTION(mParsingDatas.Count() == 0, "We're in the middle of a parse?");
+  NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
 
   LOG_URI("  Non-document sheet uri: '%s'", aURL);
   
   if (aSheet) {
     *aSheet = nsnull;
   }
   
   if (!mEnabled) {
--- a/layout/style/nsCSSLoader.h
+++ b/layout/style/nsCSSLoader.h
@@ -487,17 +487,17 @@ private:
                        nsICSSStyleSheet> mCompleteSheets;
   nsDataHashtable<nsURIAndPrincipalHashKey,
                   SheetLoadData*> mLoadingDatas; // weak refs
   nsDataHashtable<nsURIAndPrincipalHashKey,
                   SheetLoadData*> mPendingDatas; // weak refs
   
   // We're not likely to have many levels of @import...  But likely to have
   // some.  Allocate some storage, what the hell.
-  nsAutoVoidArray   mParsingDatas;
+  nsAutoTArray<SheetLoadData*, 8> mParsingDatas;
 
   // The array of posted stylesheet loaded events (SheetLoadDatas) we have.
   // Note that these are rare.
   LoadDataArray mPostedEvents;
 
   // Number of datas still waiting to be notified on if we're notifying on a
   // whole bunch at once (e.g. in one of the stop methods).  This is used to
   // make sure that HasPendingLoads() won't return false until we're notifying
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -58,17 +58,16 @@
 #include "nsStyleConsts.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIAtom.h"
-#include "nsVoidArray.h"
 #include "nsCOMArray.h"
 #include "nsColor.h"
 #include "nsStyleConsts.h"
 #include "nsCSSPseudoClasses.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsINameSpaceManager.h"
 #include "nsXMLNameSpaceMap.h"
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -60,17 +60,16 @@
 #include "nsICSSStyleRule.h"
 #include "nsICSSGroupRule.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsIEventStateManager.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
-#include "nsVoidArray.h"
 #include "nsDOMError.h"
 #include "nsRuleWalker.h"
 #include "nsCSSPseudoClasses.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsHashKeys.h"
 #include "nsStyleUtil.h"
 #include "nsQuickSort.h"
@@ -657,17 +656,17 @@ void RuleHash::EnumerateTagRules(nsIAtom
   }
 }
 
 //--------------------------------
 
 // Attribute selectors hash table.
 struct AttributeSelectorEntry : public PLDHashEntryHdr {
   nsIAtom *mAttribute;
-  nsVoidArray *mSelectors;
+  nsTArray<nsCSSSelector*> *mSelectors;
 };
 
 static void
 AttributeSelectorClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
 {
   AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>(hdr);
   delete entry->mSelectors;
   memset(entry, 0, table->entrySize);
@@ -697,41 +696,41 @@ struct RuleCascadeData {
     PL_DHashTableInit(&mAttributeSelectors, &AttributeSelectorOps, nsnull,
                       sizeof(AttributeSelectorEntry), 16);
   }
 
   ~RuleCascadeData()
   {
     PL_DHashTableFinish(&mAttributeSelectors);
   }
-  RuleHash          mRuleHash;
-  nsVoidArray       mStateSelectors;
-  nsVoidArray       mClassSelectors;
-  nsVoidArray       mIDSelectors;
-  PLDHashTable      mAttributeSelectors; // nsIAtom* -> nsVoidArray*
+  RuleHash                 mRuleHash;
+  nsTArray<nsCSSSelector*> mStateSelectors;
+  nsTArray<nsCSSSelector*> mClassSelectors;
+  nsTArray<nsCSSSelector*> mIDSelectors;
+  PLDHashTable             mAttributeSelectors;
 
   nsTArray<nsFontFaceRuleContainer> mFontFaceRules;
 
   // Looks up or creates the appropriate list in |mAttributeSelectors|.
   // Returns null only on allocation failure.
-  nsVoidArray* AttributeListFor(nsIAtom* aAttribute);
+  nsTArray<nsCSSSelector*>* AttributeListFor(nsIAtom* aAttribute);
 
   nsMediaQueryResultCacheKey mCacheKey;
   RuleCascadeData*  mNext; // for a different medium
 };
 
-nsVoidArray*
+nsTArray<nsCSSSelector*>*
 RuleCascadeData::AttributeListFor(nsIAtom* aAttribute)
 {
   AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>
                                              (PL_DHashTableOperate(&mAttributeSelectors, aAttribute, PL_DHASH_ADD));
   if (!entry)
     return nsnull;
   if (!entry->mSelectors) {
-    if (!(entry->mSelectors = new nsVoidArray)) {
+    if (!(entry->mSelectors = new nsTArray<nsCSSSelector*>)) {
       PL_DHashTableRawRemove(&mAttributeSelectors, entry);
       return nsnull;
     }
     entry->mAttribute = aAttribute;
   }
   return entry->mSelectors;
 }
 
@@ -1985,45 +1984,16 @@ nsCSSRuleProcessor::RulesMatching(Pseudo
 }
 
 inline PRBool
 IsSiblingOperator(PRUnichar oper)
 {
   return oper == PRUnichar('+') || oper == PRUnichar('~');
 }
 
-struct StateEnumData {
-  StateEnumData(StateRuleProcessorData *aData)
-    : data(aData), change(nsReStyleHint(0)) {}
-
-  StateRuleProcessorData *data;
-  nsReStyleHint change;
-};
-
-static PRBool StateEnumFunc(void* aSelector, void* aData)
-{
-  StateEnumData *enumData = static_cast<StateEnumData*>(aData);
-  StateRuleProcessorData *data = enumData->data;
-  nsCSSSelector* selector = static_cast<nsCSSSelector*>(aSelector);
-
-  nsReStyleHint possibleChange = IsSiblingOperator(selector->mOperator) ?
-    eReStyle_LaterSiblings : eReStyle_Self;
-
-  // If enumData->change already includes all the bits of possibleChange, don't
-  // bother calling SelectorMatches, since even if it returns false
-  // enumData->change won't change.
-  if ((possibleChange & ~(enumData->change)) &&
-      SelectorMatches(*data, selector, data->mStateMask, nsnull, PR_TRUE) &&
-      SelectorMatchesTree(*data, selector->mNext, PR_TRUE)) {
-    enumData->change = nsReStyleHint(enumData->change | possibleChange);
-  }
-
-  return PR_TRUE;
-}
-
 NS_IMETHODIMP
 nsCSSRuleProcessor::HasStateDependentStyle(StateRuleProcessorData* aData,
                                            nsReStyleHint* aResult)
 {
   NS_PRECONDITION(aData->mContent->IsNodeOfType(nsINode::eELEMENT),
                   "content must be element");
 
   RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
@@ -2031,52 +2001,65 @@ nsCSSRuleProcessor::HasStateDependentSty
   // Look up the content node in the state rule list, which points to
   // any (CSS2 definition) simple selector (whether or not it is the
   // subject) that has a state pseudo-class on it.  This means that this
   // code will be matching selectors that aren't real selectors in any
   // stylesheet (e.g., if there is a selector "body > p:hover > a", then
   // "body > p:hover" will be in |cascade->mStateSelectors|).  Note that
   // |IsStateSelector| below determines which selectors are in
   // |cascade->mStateSelectors|.
-  StateEnumData data(aData);
-  if (cascade)
-    cascade->mStateSelectors.EnumerateForwards(StateEnumFunc, &data);
-  *aResult = data.change;
+  if (cascade) {
+    *aResult = nsReStyleHint(0);
+    nsCSSSelector **iter = cascade->mStateSelectors.Elements(),
+                  **end = iter + cascade->mStateSelectors.Length();
+    for(; iter != end; ++iter) {
+      nsCSSSelector* selector = *iter;
+
+      nsReStyleHint possibleChange = IsSiblingOperator(selector->mOperator) ?
+        eReStyle_LaterSiblings : eReStyle_Self;
+
+      // If *aResult already includes all the bits of possibleChange,
+      // don't bother calling SelectorMatches, since even if it returns false
+      // *aResult won't change.
+      if ((possibleChange & ~(*aResult)) &&
+          SelectorMatches(*aData, selector, aData->mStateMask, nsnull, PR_TRUE) &&
+          SelectorMatchesTree(*aData, selector->mNext, PR_TRUE)) {
+        *aResult = nsReStyleHint(*aResult | possibleChange);
+      }
+    }
+  }
   return NS_OK;
 }
 
 struct AttributeEnumData {
   AttributeEnumData(AttributeRuleProcessorData *aData)
     : data(aData), change(nsReStyleHint(0)) {}
 
   AttributeRuleProcessorData *data;
   nsReStyleHint change;
 };
 
 
-static PRBool AttributeEnumFunc(void* aSelector, void* aData)
+static void
+AttributeEnumFunc(nsCSSSelector* aSelector, AttributeEnumData* aData)
 {
-  AttributeEnumData *enumData = static_cast<AttributeEnumData*>(aData);
-  AttributeRuleProcessorData *data = enumData->data;
-  nsCSSSelector* selector = static_cast<nsCSSSelector*>(aSelector);
+  AttributeRuleProcessorData *data = aData->data;
 
-  nsReStyleHint possibleChange = IsSiblingOperator(selector->mOperator) ?
+  nsReStyleHint possibleChange = IsSiblingOperator(aSelector->mOperator) ?
     eReStyle_LaterSiblings : eReStyle_Self;
 
   // If enumData->change already includes all the bits of possibleChange, don't
   // bother calling SelectorMatches, since even if it returns false
   // enumData->change won't change.
-  if ((possibleChange & ~(enumData->change)) &&
-      SelectorMatches(*data, selector, data->mStateMask, data->mAttribute,
+  if ((possibleChange & ~(aData->change)) &&
+      SelectorMatches(*data, aSelector, data->mStateMask, data->mAttribute,
                       PR_TRUE) &&
-      SelectorMatchesTree(*data, selector->mNext, PR_TRUE)) {
-    enumData->change = nsReStyleHint(enumData->change | possibleChange);
+      SelectorMatchesTree(*data, aSelector->mNext, PR_TRUE)) {
+    aData->change = nsReStyleHint(aData->change | possibleChange);
   }
-
-  return PR_TRUE;
 }
 
 NS_IMETHODIMP
 nsCSSRuleProcessor::HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
                                                nsReStyleHint* aResult)
 {
   NS_PRECONDITION(aData->mContent->IsNodeOfType(nsINode::eELEMENT),
                   "content must be element");
@@ -2108,28 +2091,40 @@ nsCSSRuleProcessor::HasAttributeDependen
   RuleCascadeData* cascade = GetRuleCascade(aData->mPresContext);
 
   // We do the same thing for attributes that we do for state selectors
   // (see HasStateDependentStyle), except that instead of one big list
   // we have a hashtable with a per-attribute list.
 
   if (cascade) {
     if (aData->mAttribute == aData->mContent->GetIDAttributeName()) {
-      cascade->mIDSelectors.EnumerateForwards(AttributeEnumFunc, &data);
+      nsCSSSelector **iter = cascade->mIDSelectors.Elements(),
+                    **end = iter + cascade->mIDSelectors.Length();
+      for(; iter != end; ++iter) {
+        AttributeEnumFunc(*iter, &data);
+      }
     }
     
     if (aData->mAttribute == aData->mContent->GetClassAttributeName()) {
-      cascade->mClassSelectors.EnumerateForwards(AttributeEnumFunc, &data);
+      nsCSSSelector **iter = cascade->mClassSelectors.Elements(),
+                    **end = iter + cascade->mClassSelectors.Length();
+      for(; iter != end; ++iter) {
+        AttributeEnumFunc(*iter, &data);
+      }
     }
 
     AttributeSelectorEntry *entry = static_cast<AttributeSelectorEntry*>
                                                (PL_DHashTableOperate(&cascade->mAttributeSelectors, aData->mAttribute,
                              PL_DHASH_LOOKUP));
     if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
-      entry->mSelectors->EnumerateForwards(AttributeEnumFunc, &data);
+      nsCSSSelector **iter = entry->mSelectors->Elements(),
+                    **end = iter + entry->mSelectors->Length();
+      for(; iter != end; ++iter) {
+        AttributeEnumFunc(*iter, &data);
+      }
     }
   }
 
   *aResult = data.change;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -2227,19 +2222,19 @@ PRBool IsStateSelector(nsCSSSelector& aS
 static PRBool
 AddRule(RuleValue* aRuleInfo, void* aCascade)
 {
   RuleCascadeData *cascade = static_cast<RuleCascadeData*>(aCascade);
 
   // Build the rule hash.
   cascade->mRuleHash.PrependRule(aRuleInfo);
 
-  nsVoidArray* stateArray = &cascade->mStateSelectors;
-  nsVoidArray* classArray = &cascade->mClassSelectors;
-  nsVoidArray* idArray = &cascade->mIDSelectors;
+  nsTArray<nsCSSSelector*>* stateArray = &cascade->mStateSelectors;
+  nsTArray<nsCSSSelector*>* classArray = &cascade->mClassSelectors;
+  nsTArray<nsCSSSelector*>* idArray = &cascade->mIDSelectors;
   
   for (nsCSSSelector* selector = aRuleInfo->mSelector;
            selector; selector = selector->mNext) {
     // It's worth noting that this loop over negations isn't quite
     // optimal for two reasons.  One, we could add something to one of
     // these lists twice, which means we'll check it twice, but I don't
     // think that's worth worrying about.   (We do the same for multiple
     // attribute selectors on the same attribute.)  Two, we don't really
@@ -2260,17 +2255,17 @@ AddRule(RuleValue* aRuleInfo, void* aCas
       // Build mClassSelectors
       if (negation->mClassList) {
         classArray->AppendElement(selector);
       }
 
       // Build mAttributeSelectors.
       for (nsAttrSelector *attr = negation->mAttrList; attr;
            attr = attr->mNext) {
-        nsVoidArray *array = cascade->AttributeListFor(attr->mAttr);
+        nsTArray<nsCSSSelector*> *array = cascade->AttributeListFor(attr->mAttr);
         if (!array)
           return PR_FALSE;
         array->AppendElement(selector);
       }
     }
   }
 
   return PR_TRUE;
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -51,17 +51,17 @@
 #include "nsICSSNameSpaceRule.h"
 #include "nsICSSGroupRule.h"
 #include "nsICSSImportRule.h"
 #include "nsIMediaList.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
 #include "nsGkAtoms.h"
 #include "nsString.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsIDOMStyleSheetList.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsIDOMCSSRule.h"
 #include "nsIDOMCSSImportRule.h"
 #include "nsICSSRuleList.h"
 #include "nsIDOMMediaList.h"
 #include "nsIDOMNode.h"
 #include "nsDOMError.h"
@@ -890,26 +890,26 @@ void
 nsCSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aSheet)
 {
   mSheets.AppendElement(aSheet);
 }
 
 void
 nsCSSStyleSheetInner::RemoveSheet(nsICSSStyleSheet* aSheet)
 {
-  if (1 == mSheets.Count()) {
-    NS_ASSERTION(aSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0), "bad parent");
+  if (1 == mSheets.Length()) {
+    NS_ASSERTION(aSheet == mSheets.ElementAt(0), "bad parent");
     delete this;
     return;
   }
-  if (aSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0)) {
+  if (aSheet == mSheets.ElementAt(0)) {
     mSheets.RemoveElementAt(0);
-    NS_ASSERTION(mSheets.Count(), "no parents");
+    NS_ASSERTION(mSheets.Length(), "no parents");
     mOrderedRules.EnumerateForwards(SetStyleSheetReference,
-                                    (nsICSSStyleSheet*)mSheets.ElementAt(0));
+                                    mSheets.ElementAt(0));
   }
   else {
     mSheets.RemoveElement(aSheet);
   }
 }
 
 static void
 AddNamespaceRuleToMap(nsICSSRule* aRule, nsXMLNameSpaceMap* aMap)
@@ -1042,17 +1042,17 @@ nsCSSStyleSheet::~nsCSSStyleSheet()
     mMedia->SetStyleSheet(nsnull);
     mMedia = nsnull;
   }
   mInner->RemoveSheet(this);
   // XXX The document reference is not reference counted and should
   // not be released. The document will let us know when it is going
   // away.
   if (mRuleProcessors) {
-    NS_ASSERTION(mRuleProcessors->Count() == 0, "destructing sheet with rule processor reference");
+    NS_ASSERTION(mRuleProcessors->Length() == 0, "destructing sheet with rule processor reference");
     delete mRuleProcessors; // weak refs, should be empty here anyway
   }
 }
 
 
 // QueryInterface implementation for nsCSSStyleSheet
 NS_INTERFACE_MAP_BEGIN(nsCSSStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet)
@@ -1068,17 +1068,17 @@ NS_INTERFACE_MAP_END
 NS_IMPL_ADDREF(nsCSSStyleSheet)
 NS_IMPL_RELEASE(nsCSSStyleSheet)
 
 
 NS_IMETHODIMP
 nsCSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor)
 {
   if (! mRuleProcessors) {
-    mRuleProcessors = new nsAutoVoidArray();
+    mRuleProcessors = new nsAutoTArray<nsCSSRuleProcessor*, 8>();
     if (!mRuleProcessors)
       return NS_ERROR_OUT_OF_MEMORY;
   }
   NS_ASSERTION(-1 == mRuleProcessors->IndexOf(aProcessor),
                "processor already registered");
   mRuleProcessors->AppendElement(aProcessor); // weak ref
   return NS_OK;
 }
@@ -1458,17 +1458,17 @@ nsCSSStyleSheet::GetStyleSheetAt(PRInt32
   NS_IF_ADDREF(aSheet = child);
 
   return NS_OK;
 }
 
 nsresult  
 nsCSSStyleSheet::EnsureUniqueInner()
 {
-  if (1 < mInner->mSheets.Count()) {
+  if (1 < mInner->mSheets.Length()) {
     nsCSSStyleSheetInner* clone = mInner->CloneFor(this);
     if (clone) {
       mInner->RemoveSheet(this);
       mInner = clone;
     }
     else {
       return NS_ERROR_OUT_OF_MEMORY;
     }
@@ -1544,30 +1544,25 @@ void nsCSSStyleSheet::List(FILE* out, PR
     child->List(out, aIndent + 1);
   }
 
   fputs("Rules in source order:\n", out);
   ListRules(mInner->mOrderedRules, out, aIndent);
 }
 #endif
 
-static PRBool
-EnumClearRuleCascades(void* aProcessor, void* aData)
-{
-  nsCSSRuleProcessor* processor =
-    static_cast<nsCSSRuleProcessor*>(aProcessor);
-  processor->ClearRuleCascades();
-  return PR_TRUE;
-}
-
 void 
 nsCSSStyleSheet::ClearRuleCascades()
 {
   if (mRuleProcessors) {
-    mRuleProcessors->EnumerateForwards(EnumClearRuleCascades, nsnull);
+    nsCSSRuleProcessor **iter = mRuleProcessors->Elements(),
+                       **end = iter + mRuleProcessors->Length();
+    for(; iter != end; ++iter) {
+      (*iter)->ClearRuleCascades();
+    }
   }
   if (mParent) {
     nsCSSStyleSheet* parent = (nsCSSStyleSheet*)mParent;
     parent->ClearRuleCascades();
   }
 }
 
 nsresult
--- a/layout/style/nsCSSStyleSheet.h
+++ b/layout/style/nsCSSStyleSheet.h
@@ -45,17 +45,17 @@
 #define nsCSSStyleSheet_h_
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsICSSStyleSheet.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsICSSLoaderObserver.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsCOMArray.h"
 
 class nsIURI;
 class nsMediaList;
 class nsMediaQueryResultCacheKey;
 class nsCSSStyleSheet;
 
 // -------------------------------
@@ -73,17 +73,17 @@ public:
   void AddSheet(nsICSSStyleSheet* aSheet);
   void RemoveSheet(nsICSSStyleSheet* aSheet);
 
   void RebuildNameSpaces();
 
   // Create a new namespace map
   nsresult CreateNamespaceMap();
 
-  nsAutoVoidArray        mSheets;
+  nsAutoTArray<nsICSSStyleSheet*, 8> mSheets;
   nsCOMPtr<nsIURI>       mSheetURI; // for error reports, etc.
   nsCOMPtr<nsIURI>       mOriginalSheetURI;  // for GetHref.  Can be null.
   nsCOMPtr<nsIURI>       mBaseURI; // for resolving relative URIs
   nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCOMArray<nsICSSRule> mOrderedRules;
   nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
   PRBool                 mComplete;
   // Linked list of child sheets.  This is al fundamentally broken, because
@@ -219,17 +219,17 @@ protected:
   CSSRuleListImpl*      mRuleCollection;
   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
   nsIDOMNode*           mOwningNode; // weak ref
   PRPackedBool          mDisabled;
   PRPackedBool          mDirty; // has been modified 
 
   nsCSSStyleSheetInner* mInner;
 
-  nsAutoVoidArray*      mRuleProcessors;
+  nsAutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
 
   friend class nsMediaList;
   friend class nsCSSRuleProcessor;
   friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
   friend struct ChildSheetListBuilder;
 };
 
 #endif /* !defined(nsCSSStyleSheet_h_) */
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -68,16 +68,17 @@
 #include "nsRuleData.h"
 #include "nsILanguageAtomService.h"
 #include "nsIStyleRule.h"
 #include "nsBidiUtils.h"
 #include "nsStyleStructInlines.h"
 #include "nsStyleTransformMatrix.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSProps.h"
+#include "nsTArray.h"
 
 /*
  * For storage of an |nsRuleNode|'s children in a PLDHashTable.
  */
 
 struct ChildrenHashEntry : public PLDHashEntryHdr {
   // key is |mRuleNode->GetKey()|
   nsRuleNode *mRuleNode;
@@ -2725,17 +2726,17 @@ nsRuleNode::SetFont(nsPresContext* aPres
 //  - re-apply cascading rules from there without caching intermediate values
 /* static */ void
 nsRuleNode::SetGenericFont(nsPresContext* aPresContext,
                            nsStyleContext* aContext,
                            PRUint8 aGenericFontID, nscoord aMinFontSize,
                            nsStyleFont* aFont)
 {
   // walk up the contexts until a context with the desired generic font
-  nsAutoVoidArray contextPath;
+  nsAutoTArray<nsStyleContext*, 8> contextPath;
   contextPath.AppendElement(aContext);
   nsStyleContext* higherContext = aContext->GetParent();
   while (higherContext) {
     if (higherContext->GetStyleFont()->mGenericID == aGenericFontID) {
       // done walking up the higher contexts
       break;
     }
     contextPath.AppendElement(higherContext);
@@ -2753,18 +2754,18 @@ nsRuleNode::SetGenericFont(nsPresContext
     const nsStyleFont* tmpFont = higherContext->GetStyleFont();
     parentFont = *tmpFont;
   }
   *aFont = parentFont;
 
   PRBool dummy;
   PRUint32 fontBit = nsCachedStyleData::GetBitForSID(eStyleStruct_Font);
   
-  for (PRInt32 i = contextPath.Count() - 1; i >= 0; --i) {
-    nsStyleContext* context = (nsStyleContext*)contextPath[i];
+  for (PRInt32 i = contextPath.Length() - 1; i >= 0; --i) {
+    nsStyleContext* context = contextPath[i];
     nsRuleDataFont fontData; // Declare a struct with null CSS values.
     nsRuleData ruleData(NS_STYLE_INHERIT_BIT(Font), aPresContext, context);
     ruleData.mFontData = &fontData;
 
     // Trimmed down version of ::WalkRuleTree() to re-apply the style rules
     // Note that we *do* need to do this for our own data, since what is
     // in |fontData| in ComputeFontData is only for the rules below
     // aStartStruct.
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -46,17 +46,16 @@
 #ifndef nsStyleStruct_h___
 #define nsStyleStruct_h___
 
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsMargin.h"
 #include "nsRect.h"
 #include "nsFont.h"
-#include "nsVoidArray.h"
 #include "nsStyleCoord.h"
 #include "nsStyleConsts.h"
 #include "nsChangeHint.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsIAtom.h"
--- a/layout/xul/base/src/tree/src/nsTreeContentView.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeContentView.cpp
@@ -168,17 +168,17 @@ NS_INTERFACE_MAP_BEGIN(nsTreeContentView
   NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITreeContentView)
   NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(TreeContentView)
 NS_INTERFACE_MAP_END
 
 NS_IMETHODIMP
 nsTreeContentView::GetRowCount(PRInt32* aRowCount)
 {
-  *aRowCount = mRows.Count();
+  *aRowCount = mRows.Length();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetSelection(nsITreeSelection** aSelection)
 {
   NS_IF_ADDREF(*aSelection = mSelection);
@@ -191,18 +191,18 @@ nsTreeContentView::SetSelection(nsITreeS
 {
   mSelection = aSelection;
   if (!mSelection || !mUpdateSelection)
     return NS_OK;
 
   mUpdateSelection = PR_FALSE;
 
   mSelection->SetSelectEventsSuppressed(PR_TRUE);
-  for (PRInt32 i = 0; i < mRows.Count(); ++i) {
-    Row* row = (Row*)mRows[i];
+  for (PRUint32 i = 0; i < mRows.Length(); ++i) {
+    Row* row = mRows[i];
     nsCOMPtr<nsIDOMHTMLOptionElement> optEl = do_QueryInterface(row->mContent);
     if (optEl) {
       PRBool isSelected;
       optEl->GetSelected(&isSelected);
       if (isSelected)
         mSelection->ToggleSelect(i);
     }
   }
@@ -210,21 +210,21 @@ nsTreeContentView::SetSelection(nsITreeS
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetRowProperties(PRInt32 aIndex, nsISupportsArray* aProperties)
 {
   NS_ENSURE_ARG_POINTER(aProperties);
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   nsCOMPtr<nsIContent> realRow;
   if (row->IsSeparator())
     realRow = row->mContent;
   else
     nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
 
   if (realRow) {
     nsAutoString properties;
@@ -236,21 +236,21 @@ nsTreeContentView::GetRowProperties(PRIn
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetCellProperties(PRInt32 aRow, nsITreeColumn* aCol, nsISupportsArray* aProperties)
 {
   NS_ENSURE_ARG_POINTER(aCol);
   NS_ENSURE_ARG_POINTER(aProperties);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell) {
       nsAutoString properties;
       cell->GetAttr(kNameSpaceID_None, nsGkAtoms::properties, properties);
       if (!properties.IsEmpty())
@@ -276,181 +276,183 @@ nsTreeContentView::GetColumnProperties(n
     nsTreeUtils::TokenizeProperties(properties, aProperties);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsContainer(PRInt32 aIndex, PRBool* _retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  *_retval = ((Row*)mRows[aIndex])->IsContainer();
+  *_retval = mRows[aIndex]->IsContainer();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsContainerOpen(PRInt32 aIndex, PRBool* _retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  *_retval = ((Row*)mRows[aIndex])->IsOpen();
+  *_retval = mRows[aIndex]->IsOpen();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsContainerEmpty(PRInt32 aIndex, PRBool* _retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  *_retval = ((Row*)mRows[aIndex])->IsEmpty();
+  *_retval = mRows[aIndex]->IsEmpty();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsSeparator(PRInt32 aIndex, PRBool *_retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  *_retval = ((Row*)mRows[aIndex])->IsSeparator();
+  *_retval = mRows[aIndex]->IsSeparator();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsSorted(PRBool *_retval)
 {
   *_retval = PR_FALSE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::CanDrop(PRInt32 aIndex, PRInt32 aOrientation, PRBool *_retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   *_retval = PR_FALSE;
  
   return NS_OK;
 }
  
 NS_IMETHODIMP
 nsTreeContentView::Drop(PRInt32 aRow, PRInt32 aOrientation)
 {
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetParentIndex(PRInt32 aRowIndex, PRInt32* _retval)
 {
-  NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < mRows.Count(), "bad row index");
-  if (aRowIndex < 0 || aRowIndex >= mRows.Count())
+  NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < PRInt32(mRows.Length()),
+                  "bad row index");
+  if (aRowIndex < 0 || aRowIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  *_retval = ((Row*)mRows[aRowIndex])->mParentIndex;
+  *_retval = mRows[aRowIndex]->mParentIndex;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::HasNextSibling(PRInt32 aRowIndex, PRInt32 aAfterIndex, PRBool* _retval)
 {
-  NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < mRows.Count(), "bad row index");
-  if (aRowIndex < 0 || aRowIndex >= mRows.Count())
+  NS_PRECONDITION(aRowIndex >= 0 && aRowIndex < PRInt32(mRows.Length()),
+                  "bad row index");
+  if (aRowIndex < 0 || aRowIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   // We have a next sibling if the row is not the last in the subtree.
-  PRInt32 parentIndex = ((Row*)mRows[aRowIndex])->mParentIndex;
+  PRInt32 parentIndex = mRows[aRowIndex]->mParentIndex;
   if (parentIndex >= 0) {
     // Compute the last index in this subtree.
-    PRInt32 lastIndex = parentIndex + ((Row*)mRows[parentIndex])->mSubtreeSize;
-    Row* row = (Row*)mRows[lastIndex];
+    PRInt32 lastIndex = parentIndex + (mRows[parentIndex])->mSubtreeSize;
+    Row* row = mRows[lastIndex];
     while (row->mParentIndex != parentIndex) {
       lastIndex = row->mParentIndex;
-      row = (Row*)mRows[lastIndex];
+      row = mRows[lastIndex];
     }
 
     *_retval = aRowIndex < lastIndex;
   }
   else {
-    *_retval = aRowIndex < mRows.Count() - 1;
+    *_retval = PRUint32(aRowIndex) < mRows.Length() - 1;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetLevel(PRInt32 aIndex, PRInt32* _retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   PRInt32 level = 0;
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   while (row->mParentIndex >= 0) {
     level++;
-    row = (Row*)mRows[row->mParentIndex];
+    row = mRows[row->mParentIndex];
   }
   *_retval = level;
 
   return NS_OK;
 }
 
  NS_IMETHODIMP
 nsTreeContentView::GetImageSrc(PRInt32 aRow, nsITreeColumn* aCol, nsAString& _retval)
 {
   _retval.Truncate();
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell)
       cell->GetAttr(kNameSpaceID_None, nsGkAtoms::src, _retval);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetProgressMode(PRInt32 aRow, nsITreeColumn* aCol, PRInt32* _retval)
 {
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   *_retval = nsITreeView::PROGRESS_NONE;
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell) {
       static nsIContent::AttrValuesArray strings[] =
         {&nsGkAtoms::normal, &nsGkAtoms::undetermined, nsnull};
@@ -465,21 +467,21 @@ nsTreeContentView::GetProgressMode(PRInt
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetCellValue(PRInt32 aRow, nsITreeColumn* aCol, nsAString& _retval)
 {
   _retval.Truncate();
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell)
       cell->GetAttr(kNameSpaceID_None, nsGkAtoms::value, _retval);
   }
@@ -487,23 +489,23 @@ nsTreeContentView::GetCellValue(PRInt32 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsAString& _retval)
 {
   _retval.Truncate();
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
   NS_PRECONDITION(aCol, "bad column");
 
-  if (aRow < 0 || aRow >= mRows.Count() || !aCol)
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()) || !aCol)
     return NS_ERROR_INVALID_ARG;
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   // Check for a "label" attribute - this is valid on an <treeitem>
   // or an <option>, with a single implied column.
   if (row->mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, _retval)
       && !_retval.IsEmpty())
     return NS_OK;
 
   nsIAtom *rowTag = row->mContent->Tag();
@@ -565,23 +567,23 @@ nsTreeContentView::SetTree(nsITreeBoxObj
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::ToggleOpenState(PRInt32 aIndex)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   // We don't serialize content right here, since content might be generated
   // lazily.
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
 
   if (row->mContent->Tag() == nsGkAtoms::optgroup &&
       row->mContent->IsNodeOfType(nsINode::eHTML)) {
     // we don't use an attribute for optgroup's open state
     if (row->IsOpen())
       CloseContainer(aIndex);
     else
       OpenContainer(aIndex);
@@ -645,23 +647,23 @@ nsTreeContentView::CycleCell(PRInt32 aRo
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsEditable(PRInt32 aRow, nsITreeColumn* aCol, PRBool* _retval)
 {
   *_retval = PR_FALSE;
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   *_retval = PR_TRUE;
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell && cell->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
                                   nsGkAtoms::_false, eCaseMatters)) {
       *_retval = PR_FALSE;
@@ -669,23 +671,23 @@ nsTreeContentView::IsEditable(PRInt32 aR
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::IsSelectable(PRInt32 aRow, nsITreeColumn* aCol, PRBool* _retval)
 {
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
   *_retval = PR_TRUE;
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell && cell->AttrValueIs(kNameSpaceID_None, nsGkAtoms::selectable,
                                   nsGkAtoms::_false, eCaseMatters)) {
       *_retval = PR_FALSE;
@@ -694,42 +696,42 @@ nsTreeContentView::IsSelectable(PRInt32 
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::SetCellValue(PRInt32 aRow, nsITreeColumn* aCol, const nsAString& aValue)
 {
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell)
       cell->SetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue, PR_TRUE);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::SetCellText(PRInt32 aRow, nsITreeColumn* aCol, const nsAString& aValue)
 {
   NS_ENSURE_ARG_POINTER(aCol);
-  NS_PRECONDITION(aRow >= 0 && aRow < mRows.Count(), "bad row");
-  if (aRow < 0 || aRow >= mRows.Count())
+  NS_PRECONDITION(aRow >= 0 && aRow < PRInt32(mRows.Length()), "bad row");
+  if (aRow < 0 || aRow >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aRow];
+  Row* row = mRows[aRow];
 
   nsCOMPtr<nsIContent> realRow;
   nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treerow, getter_AddRefs(realRow));
   if (realRow) {
     nsIContent* cell = GetCell(realRow, aCol);
     if (cell)
       cell->SetAttr(kNameSpaceID_None, nsGkAtoms::label, aValue, PR_TRUE);
   }
@@ -754,21 +756,21 @@ nsTreeContentView::PerformActionOnCell(c
 {
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsTreeContentView::GetItemAtIndex(PRInt32 aIndex, nsIDOMElement** _retval)
 {
-  NS_PRECONDITION(aIndex >= 0 && aIndex < mRows.Count(), "bad index");
-  if (aIndex < 0 || aIndex >= mRows.Count())
+  NS_PRECONDITION(aIndex >= 0 && aIndex < PRInt32(mRows.Length()), "bad index");
+  if (aIndex < 0 || aIndex >= PRInt32(mRows.Length()))
     return NS_ERROR_INVALID_ARG;   
 
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   row->mContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)_retval);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetIndexOfItem(nsIDOMElement* aItem, PRInt32* _retval)
 {
@@ -875,17 +877,17 @@ nsTreeContentView::AttributeChanged(nsID
           mBoxObject->InvalidateColumn(col);
         }
       }
     }
   }
   else if (tag == nsGkAtoms::treeitem) {
     PRInt32 index = FindContent(aContent);
     if (index >= 0) {
-      Row* row = (Row*)mRows[index];
+      Row* row = mRows[index];
       if (aAttribute == nsGkAtoms::container) {
         PRBool isContainer =
           aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::container,
                                 nsGkAtoms::_true, eCaseMatters);
         row->SetContainer(isContainer);
         if (mBoxObject)
           mBoxObject->InvalidateRow(index);
       }
@@ -1002,17 +1004,17 @@ nsTreeContentView::ContentInserted(nsIDo
     if ((element->IsNodeOfType(nsINode::eXUL) && parentTag == nsGkAtoms::tree) ||
         (element->IsNodeOfType(nsINode::eHTML) && parentTag == nsGkAtoms::select))
       return; // this is not for us
   }
 
   if (childTag == nsGkAtoms::treechildren) {
     PRInt32 index = FindContent(aContainer);
     if (index >= 0) {
-      Row* row = (Row*)mRows[index];
+      Row* row = mRows[index];
       row->SetEmpty(PR_FALSE);
       if (mBoxObject)
         mBoxObject->InvalidateRow(index);
       if (row->IsContainer() && row->IsOpen()) {
         PRInt32 count = EnsureSubtree(index);
         if (mBoxObject)
           mBoxObject->RowCountChanged(index + 1, count);
       }
@@ -1085,17 +1087,17 @@ nsTreeContentView::ContentRemoved(nsIDoc
     if ((element->IsNodeOfType(nsINode::eXUL) && parentTag == nsGkAtoms::tree) ||
         (element->IsNodeOfType(nsINode::eHTML) && parentTag == nsGkAtoms::select))
       return; // this is not for us
   }
 
   if (tag == nsGkAtoms::treechildren) {
     PRInt32 index = FindContent(aContainer);
     if (index >= 0) {
-      Row* row = (Row*)mRows[index];
+      Row* row = mRows[index];
       row->SetEmpty(PR_TRUE);
       PRInt32 count = RemoveSubtree(index);
       // Invalidate also the row to update twisty.
       if (mBoxObject) {
         mBoxObject->InvalidateRow(index);
         mBoxObject->RowCountChanged(index + 1, -count);
       }
     }
@@ -1131,42 +1133,44 @@ void
 nsTreeContentView::NodeWillBeDestroyed(const nsINode* aNode)
 {
   ClearRows();
 }
 
 
 // Recursively serialize content, starting with aContent.
 void
-nsTreeContentView::Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
+nsTreeContentView::Serialize(nsIContent* aContent, PRInt32 aParentIndex,
+                             PRInt32* aIndex, nsTArray<Row*>& aRows)
 {
   ChildIterator iter, last;
   for (ChildIterator::Init(aContent, &iter, &last); iter != last; ++iter) {
     nsCOMPtr<nsIContent> content = *iter;
     nsIAtom *tag = content->Tag();
-    PRInt32 count = aRows.Count();
+    PRInt32 count = aRows.Length();
 
     if (content->IsNodeOfType(nsINode::eXUL)) {
       if (tag == nsGkAtoms::treeitem)
         SerializeItem(content, aParentIndex, aIndex, aRows);
       else if (tag == nsGkAtoms::treeseparator)
         SerializeSeparator(content, aParentIndex, aIndex, aRows);
     }
     else if (content->IsNodeOfType(nsINode::eHTML)) {
       if (tag == nsGkAtoms::option)
         SerializeOption(content, aParentIndex, aIndex, aRows);
       else if (tag == nsGkAtoms::optgroup)
         SerializeOptGroup(content, aParentIndex, aIndex, aRows);
     }
-    *aIndex += aRows.Count() - count;
+    *aIndex += aRows.Length() - count;
   }
 }
 
 void
-nsTreeContentView::SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
+nsTreeContentView::SerializeItem(nsIContent* aContent, PRInt32 aParentIndex,
+                                 PRInt32* aIndex, nsTArray<Row*>& aRows)
 {
   if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
                             nsGkAtoms::_true, eCaseMatters))
     return;
 
   Row* row = Row::Create(mAllocator, aContent, aParentIndex);
   aRows.AppendElement(row);
 
@@ -1175,76 +1179,78 @@ nsTreeContentView::SerializeItem(nsICont
     row->SetContainer(PR_TRUE);
     if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open,
                               nsGkAtoms::_true, eCaseMatters)) {
       row->SetOpen(PR_TRUE);
       nsCOMPtr<nsIContent> child;
       nsTreeUtils::GetImmediateChild(aContent, nsGkAtoms::treechildren, getter_AddRefs(child));
       if (child) {
         // Now, recursively serialize our child.
-        PRInt32 count = aRows.Count();
+        PRInt32 count = aRows.Length();
         PRInt32 index = 0;
         Serialize(child, aParentIndex + *aIndex + 1, &index, aRows);
-        row->mSubtreeSize += aRows.Count() - count;
+        row->mSubtreeSize += aRows.Length() - count;
       }
       else
         row->SetEmpty(PR_TRUE);
     } else if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::empty,
                                      nsGkAtoms::_true, eCaseMatters)) {
       row->SetEmpty(PR_TRUE);
     }
   } 
 }
 
 void
-nsTreeContentView::SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows)
+nsTreeContentView::SerializeSeparator(nsIContent* aContent,
+                                      PRInt32 aParentIndex, PRInt32* aIndex,
+                                      nsTArray<Row*>& aRows)
 {
   if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
                             nsGkAtoms::_true, eCaseMatters))
     return;
 
   Row* row = Row::Create(mAllocator, aContent, aParentIndex);
   row->SetSeparator(PR_TRUE);
   aRows.AppendElement(row);
 }
 
 void
 nsTreeContentView::SerializeOption(nsIContent* aContent, PRInt32 aParentIndex,
-                                   PRInt32* aIndex, nsVoidArray& aRows)
+                                   PRInt32* aIndex, nsTArray<Row*>& aRows)
 {
   Row* row = Row::Create(mAllocator, aContent, aParentIndex);
   aRows.AppendElement(row);
 
   // This will happen before the TreeSelection is hooked up.  So, cache the selected
   // state in the row properties and update the selection when it is attached.
 
   nsCOMPtr<nsIDOMHTMLOptionElement> optEl = do_QueryInterface(aContent);
   PRBool isSelected;
   optEl->GetSelected(&isSelected);
   if (isSelected)
     mUpdateSelection = PR_TRUE;
 }
 
 void
 nsTreeContentView::SerializeOptGroup(nsIContent* aContent, PRInt32 aParentIndex,
-                                     PRInt32* aIndex, nsVoidArray& aRows)
+                                     PRInt32* aIndex, nsTArray<Row*>& aRows)
 {
   Row* row = Row::Create(mAllocator, aContent, aParentIndex);
   aRows.AppendElement(row);
   row->SetContainer(PR_TRUE);
   row->SetOpen(PR_TRUE);
 
   nsCOMPtr<nsIContent> child;
   nsTreeUtils::GetImmediateChild(aContent, nsGkAtoms::option, getter_AddRefs(child));
   if (child) {
     // Now, recursively serialize our child.
-    PRInt32 count = aRows.Count();
+    PRInt32 count = aRows.Length();
     PRInt32 index = 0;
     Serialize(aContent, aParentIndex + *aIndex + 1, &index, aRows);
-    row->mSubtreeSize += aRows.Count() - count;
+    row->mSubtreeSize += aRows.Length() - count;
   }
   else
     row->SetEmpty(PR_TRUE);
 }
 
 void
 nsTreeContentView::GetIndexInSubtree(nsIContent* aContainer,
                                      nsIContent* aContent, PRInt32* aIndex)
@@ -1290,52 +1296,52 @@ nsTreeContentView::GetIndexInSubtree(nsI
         (*aIndex)++;
     }
   }
 }
 
 PRInt32
 nsTreeContentView::EnsureSubtree(PRInt32 aIndex)
 {
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
 
   nsCOMPtr<nsIContent> child;
   if (row->mContent->Tag() == nsGkAtoms::optgroup)
     child = row->mContent;
   else {
     nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treechildren, getter_AddRefs(child));
     if (! child) {
       return 0;
     }
   }
 
-  nsAutoVoidArray rows;
+  nsAutoTArray<Row*, 8> rows;
   PRInt32 index = 0;
   Serialize(child, aIndex, &index, rows);
-  mRows.InsertElementsAt(rows, aIndex + 1);
-  PRInt32 count = rows.Count();
+  mRows.InsertElementsAt(aIndex + 1, rows);
+  PRInt32 count = rows.Length();
 
   row->mSubtreeSize += count;
   UpdateSubtreeSizes(row->mParentIndex, count);
 
   // Update parent indexes, but skip newly added rows.
   // They already have correct values.
   UpdateParentIndexes(aIndex, count + 1, count);
 
   return count;
 }
 
 PRInt32
 nsTreeContentView::RemoveSubtree(PRInt32 aIndex)
 {
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   PRInt32 count = row->mSubtreeSize;
 
   for(PRInt32 i = 0; i < count; i++) {
-    Row* nextRow = (Row*)mRows[aIndex + i + 1];
+    Row* nextRow = mRows[aIndex + i + 1];
     Row::Destroy(mAllocator, nextRow);
   }
   mRows.RemoveElementsAt(aIndex + 1, count);
 
   row->mSubtreeSize -= count;
   UpdateSubtreeSizes(row->mParentIndex, -count);
 
   UpdateParentIndexes(aIndex, 0, -count);
@@ -1361,17 +1367,17 @@ nsTreeContentView::InsertRowFor(nsIConte
   else {
     // Test insertion to an inner container.
 
     // First try to find this parent in our array of rows, if we find one
     // we can be sure that all other parents are open too.
     grandParentIndex = FindContent(grandParent);
     if (grandParentIndex >= 0) {
       // Got it, now test if it is open.
-      if (((Row*)mRows[grandParentIndex])->IsOpen())
+      if (mRows[grandParentIndex]->IsOpen())
         insertRow = PR_TRUE;
     }
   }
 
   if (insertRow) {
     PRInt32 index = 0;
     GetIndexInSubtree(aParent, aChild, &index);
 
@@ -1379,133 +1385,133 @@ nsTreeContentView::InsertRowFor(nsIConte
     if (mBoxObject)
       mBoxObject->RowCountChanged(grandParentIndex + index + 1, count);
   }
 }
 
 PRInt32
 nsTreeContentView::InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent)
 {
-  nsAutoVoidArray rows;
+  nsAutoTArray<Row*, 8> rows;
   nsIAtom *tag = aContent->Tag();
   if (aContent->IsNodeOfType(nsINode::eXUL)) {
     if (tag == nsGkAtoms::treeitem)
       SerializeItem(aContent, aParentIndex, &aIndex, rows);
     else if (tag == nsGkAtoms::treeseparator)
       SerializeSeparator(aContent, aParentIndex, &aIndex, rows);
   }
   else if (aContent->IsNodeOfType(nsINode::eHTML)) {
     if (tag == nsGkAtoms::option)
       SerializeOption(aContent, aParentIndex, &aIndex, rows);
     else if (tag == nsGkAtoms::optgroup)
       SerializeOptGroup(aContent, aParentIndex, &aIndex, rows);
   }
 
-  mRows.InsertElementsAt(rows, aParentIndex + aIndex + 1);
-  PRInt32 count = rows.Count();
+  mRows.InsertElementsAt(aParentIndex + aIndex + 1, rows);
+  PRInt32 count = rows.Length();
 
   UpdateSubtreeSizes(aParentIndex, count);
 
   // Update parent indexes, but skip added rows.
   // They already have correct values.
   UpdateParentIndexes(aParentIndex + aIndex, count + 1, count);
 
   return count;
 }
 
 PRInt32
 nsTreeContentView::RemoveRow(PRInt32 aIndex)
 {
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   PRInt32 count = row->mSubtreeSize + 1;
   PRInt32 parentIndex = row->mParentIndex;
 
   Row::Destroy(mAllocator, row);
   for(PRInt32 i = 1; i < count; i++) {
-    Row* nextRow = (Row*)mRows[aIndex + i];
+    Row* nextRow = mRows[aIndex + i];
     Row::Destroy(mAllocator, nextRow);
   }
   mRows.RemoveElementsAt(aIndex, count);
 
   UpdateSubtreeSizes(parentIndex, -count);
   
   UpdateParentIndexes(aIndex, 0, -count);
 
   return count;
 }
 
 void
 nsTreeContentView::ClearRows()
 {
-  for (PRInt32 i = 0; i < mRows.Count(); i++)
-    Row::Destroy(mAllocator, (Row*)mRows[i]);
+  for (PRUint32 i = 0; i < mRows.Length(); i++)
+    Row::Destroy(mAllocator, mRows[i]);
   mRows.Clear();
   mRoot = nsnull;
   mBody = nsnull;
   // Remove ourselves from mDocument's observers.
   if (mDocument) {
     mDocument->RemoveObserver(this);
     mDocument = nsnull;
   }
 } 
 
 void
 nsTreeContentView::OpenContainer(PRInt32 aIndex)
 {
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   row->SetOpen(PR_TRUE);
 
   PRInt32 count = EnsureSubtree(aIndex);
   if (mBoxObject) {
     mBoxObject->InvalidateRow(aIndex);
     mBoxObject->RowCountChanged(aIndex + 1, count);
   }
 }
 
 void
 nsTreeContentView::CloseContainer(PRInt32 aIndex)
 {
-  Row* row = (Row*)mRows[aIndex];
+  Row* row = mRows[aIndex];
   row->SetOpen(PR_FALSE);
 
   PRInt32 count = RemoveSubtree(aIndex);
   if (mBoxObject) {
     mBoxObject->InvalidateRow(aIndex);
     mBoxObject->RowCountChanged(aIndex + 1, -count);
   }
 }
 
 PRInt32
 nsTreeContentView::FindContent(nsIContent* aContent)
 {
-  for (PRInt32 i = 0; i < mRows.Count(); i++) {
-    if (((Row*)mRows[i])->mContent == aContent) {
+  for (PRUint32 i = 0; i < mRows.Length(); i++) {
+    if (mRows[i]->mContent == aContent) {
       return i;
     }
   }
 
   return -1;
 }
 
 void
 nsTreeContentView::UpdateSubtreeSizes(PRInt32 aParentIndex, PRInt32 count)
 {
   while (aParentIndex >= 0) {
-    Row* row = (Row*)mRows[aParentIndex];
+    Row* row = mRows[aParentIndex];
     row->mSubtreeSize += count;
     aParentIndex = row->mParentIndex;
   }
 }
 
 void
 nsTreeContentView::UpdateParentIndexes(PRInt32 aIndex, PRInt32 aSkip, PRInt32 aCount)
 {
-  PRInt32 count = mRows.Count();
+  PRInt32 count = mRows.Length();
   for (PRInt32 i = aIndex + aSkip; i < count; i++) {
-    Row* row = (Row*)mRows[i];
+    Row* row = mRows[i];
     if (row->mParentIndex > aIndex) {
       row->mParentIndex += aCount;
     }
   }
 }
 
 nsIContent*
 nsTreeContentView::GetCell(nsIContent* aContainer, nsITreeColumn* aCol)
--- a/layout/xul/base/src/tree/src/nsTreeContentView.h
+++ b/layout/xul/base/src/tree/src/nsTreeContentView.h
@@ -34,25 +34,27 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsTreeContentView_h__
 #define nsTreeContentView_h__
 
 #include "nsFixedSizeAllocator.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsIDocument.h"
 #include "nsStubDocumentObserver.h"
 #include "nsITreeBoxObject.h"
 #include "nsITreeColumns.h"
 #include "nsITreeView.h"
 #include "nsITreeContentView.h"
 #include "nsITreeSelection.h"
 
+class Row;
+
 nsresult NS_NewTreeContentView(nsITreeView** aResult);
 
 class nsTreeContentView : public nsINativeTreeView,
                           public nsITreeContentView,
                           public nsStubDocumentObserver
 {
   public:
     nsTreeContentView(void);
@@ -75,27 +77,30 @@ class nsTreeContentView : public nsINati
     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
 
   protected:
     // Recursive methods which deal with serializing of nested content.
-    void Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
+    void Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
+                   nsTArray<Row*>& aRows);
 
-    void SerializeItem(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
+    void SerializeItem(nsIContent* aContent, PRInt32 aParentIndex,
+                       PRInt32* aIndex, nsTArray<Row*>& aRows);
 
-    void SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex, nsVoidArray& aRows);
+    void SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex,
+                            PRInt32* aIndex, nsTArray<Row*>& aRows);
 
     void SerializeOption(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
-                         nsVoidArray& aRows);
+                         nsTArray<Row*>& aRows);
 
     void SerializeOptGroup(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
-                           nsVoidArray& aRows);
+                           nsTArray<Row*>& aRows);
 
     void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, PRInt32* aResult);
     
     // Helper methods which we use to manage our plain array of rows.
     PRInt32 EnsureSubtree(PRInt32 aIndex);
 
     PRInt32 RemoveSubtree(PRInt32 aIndex);
 
@@ -122,14 +127,14 @@ class nsTreeContentView : public nsINati
 
   private:
     nsCOMPtr<nsITreeBoxObject>          mBoxObject;
     nsCOMPtr<nsITreeSelection>          mSelection;
     nsCOMPtr<nsIContent>                mRoot;
     nsCOMPtr<nsIContent>                mBody;
     nsIDocument*                        mDocument;      // WEAK
     nsFixedSizeAllocator                mAllocator;
-    nsVoidArray                         mRows;
+    nsTArray<Row*>                      mRows;
 
     PRPackedBool                        mUpdateSelection;
 };
 
 #endif // nsTreeContentView_h__