views-unmanaged
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 160 fd41ae75c7983b0c8aeff594c5c4cb25cde2ce5e
permissions -rw-r--r--
State as of now

diff --git a/view/public/nsIView.h b/view/public/nsIView.h
--- a/view/public/nsIView.h
+++ b/view/public/nsIView.h
@@ -335,9 +335,9 @@ public:
   void SetDeletionObserver(nsWeakView* aDeletionObserver);
 protected:
   friend class nsWeakView;
-  nsViewManager     *mViewManager;
+  nsViewManager     *mViewManager NS_UNMANAGED;
   nsView            *mParent;
-  nsIWidget         *mWindow;
+  nsIWidget         *mWindow NS_UNMANAGED;
   nsView            *mNextSibling;
   nsView            *mFirstChild;
   void              *mClientData;
diff --git a/view/src/nsScrollPortView.cpp b/view/src/nsScrollPortView.cpp
--- a/view/src/nsScrollPortView.cpp
+++ b/view/src/nsScrollPortView.cpp
@@ -44,7 +44,6 @@
 #include "nsViewsCID.h"
 #include "nsIScrollableView.h"
 #include "nsILookAndFeel.h"
-#include "nsISupportsArray.h"
 #include "nsIScrollPositionListener.h"
 #include "nsIRegion.h"
 #include "nsViewManager.h"
@@ -84,17 +83,11 @@ nsScrollPortView::nsScrollPortView(nsVie
   mViewManager->GetDeviceContext(*&dev);
   mLineHeight = dev->AppUnitsPerInch() / 6; // 12 pt
 
-  mListeners = nsnull;
   mSmoothScroll = nsnull;
 }
 
 nsScrollPortView::~nsScrollPortView()
 {    
-  if (nsnull != mListeners) {
-    mListeners->Clear();
-    NS_RELEASE(mListeners);
-  }
-
   if (nsnull != mViewManager) {
      nsIScrollableView* scrollingView;
      mViewManager->GetRootScrollableView(&scrollingView);
@@ -127,19 +120,13 @@ NS_IMETHODIMP_(nsIView*) nsScrollPortVie
 
 NS_IMETHODIMP nsScrollPortView::AddScrollPositionListener(nsIScrollPositionListener* aListener)
 {
-  if (nsnull == mListeners) {
-    nsresult rv = NS_NewISupportsArray(&mListeners);
-    if (NS_FAILED(rv))
-      return rv;
-  }
-  return mListeners->AppendElement(aListener);
+  mListeners.AppendElement(aListener);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsScrollPortView::RemoveScrollPositionListener(nsIScrollPositionListener* aListener)
 {
-  if (nsnull != mListeners) {
-    return mListeners->RemoveElement(aListener);
-  }
+  return mListeners.RemoveElement(aListener);
   return NS_ERROR_FAILURE;
 }
 
@@ -633,19 +620,8 @@ NS_IMETHODIMP nsScrollPortView::ScrollTo
   dyPx = NSAppUnitsToIntPixels(mOffsetY, p2a) - yPixels;
 
   // notify the listeners.
-  PRUint32 listenerCount;
-  const nsIID& kScrollPositionListenerIID = NS_GET_IID(nsIScrollPositionListener);
-  nsIScrollPositionListener* listener;
-  if (nsnull != mListeners) {
-    if (NS_SUCCEEDED(mListeners->Count(&listenerCount))) {
-      for (PRUint32 i = 0; i < listenerCount; i++) {
-        if (NS_SUCCEEDED(mListeners->QueryElementAt(i, kScrollPositionListenerIID, (void**)&listener))) {
-          listener->ScrollPositionWillChange(this, aX, aY);
-          NS_RELEASE(listener);
-        }
-      }
-    }
-  }
+  for (PRUint32 i = 0; i < mListeners.Length(); ++i)
+    mListeners[i]->ScrollPositionWillChange(this, aX, aY);
   
   nsView* scrolledView = GetScrolledView();
   if (!scrolledView) return NS_ERROR_FAILURE;
@@ -666,16 +642,8 @@ NS_IMETHODIMP nsScrollPortView::ScrollTo
   mViewManager->SynthesizeMouseMove(PR_TRUE);
   
   // notify the listeners.
-  if (nsnull != mListeners) {
-    if (NS_SUCCEEDED(mListeners->Count(&listenerCount))) {
-      for (PRUint32 i = 0; i < listenerCount; i++) {
-        if (NS_SUCCEEDED(mListeners->QueryElementAt(i, kScrollPositionListenerIID, (void**)&listener))) {
-          listener->ScrollPositionDidChange(this, aX, aY);
-          NS_RELEASE(listener);
-        }
-      }
-    }
-  }
+  for (PRUint32 i = 0; i < mListeners.Length(); ++i)
+    mListeners[i]->ScrollPositionDidChange(this, aX, aY);
  
   return NS_OK;
 }
diff --git a/view/src/nsScrollPortView.h b/view/src/nsScrollPortView.h
--- a/view/src/nsScrollPortView.h
+++ b/view/src/nsScrollPortView.h
@@ -42,8 +42,8 @@
 #include "nsIScrollableView.h"
 #include "nsCOMPtr.h"
 #include "nsITimer.h"
+#include "nsTArray.h"
 
-class nsISupportsArray;
 class SmoothScroll;
 
 //this is a class that acts as a container for other views and provides
@@ -108,7 +108,7 @@ protected:
   nscoord             mOffsetX, mOffsetY;
   PRUint32            mScrollProperties;
   nscoord             mLineHeight;
-  nsISupportsArray   *mListeners;
+  nsTArray<nsIScrollPositionListener*> mListeners;
 };
 
 #endif