From ed7d78f9fd54cc5dc4861dcfe55b888c0410d3e4 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Tue, 9 Jul 2002 04:30:28 +0000 Subject: [PATCH] Ensure that scroll position listeners are properly unregistered. b=114221 sr=waterson r=attinasi git-svn-id: svn://10.0.0.236/trunk@124828 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsGfxScrollFrame.cpp | 4 ++ mozilla/layout/generic/nsHTMLFrame.cpp | 42 ++++++++++--------- .../layout/html/base/src/nsGfxScrollFrame.cpp | 4 ++ mozilla/layout/html/base/src/nsHTMLFrame.cpp | 42 ++++++++++--------- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/mozilla/layout/generic/nsGfxScrollFrame.cpp b/mozilla/layout/generic/nsGfxScrollFrame.cpp index c31ef5e3efb..27f973b6d43 100644 --- a/mozilla/layout/generic/nsGfxScrollFrame.cpp +++ b/mozilla/layout/generic/nsGfxScrollFrame.cpp @@ -460,6 +460,10 @@ NS_IMETHODIMP nsGfxScrollFrame::Destroy(nsIPresContext* aPresContext) { + nsIScrollableView *view = mInner->GetScrollableView(aPresContext); + NS_ASSERTION(view, "unexpected null pointer"); + if (view) + view->RemoveScrollPositionListener(mInner); return nsBoxFrame::Destroy(aPresContext); } diff --git a/mozilla/layout/generic/nsHTMLFrame.cpp b/mozilla/layout/generic/nsHTMLFrame.cpp index 87538fcc00d..9207d8d5be1 100644 --- a/mozilla/layout/generic/nsHTMLFrame.cpp +++ b/mozilla/layout/generic/nsHTMLFrame.cpp @@ -97,6 +97,7 @@ public: nsIFrame* aParent, nsIStyleContext* aContext, nsIFrame* aPrevInFlow); + NS_IMETHOD Destroy(nsIPresContext* aPresContext); NS_IMETHOD AppendFrames(nsIPresContext* aPresContext, nsIPresShell& aPresShell, @@ -168,7 +169,7 @@ protected: // Data members PRPackedBool mDoPaintFocus; - nsCOMPtr mPresContext; + nsCOMPtr mViewManager; private: @@ -227,22 +228,29 @@ CanvasFrame::Init(nsIPresContext* aPresContext, { nsresult rv = nsHTMLContainerFrame::Init(aPresContext,aContent,aParent,aContext,aPrevInFlow); - mPresContext = aPresContext; - nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - nsCOMPtr vm; - presShell->GetViewManager(getter_AddRefs(vm)); + presShell->GetViewManager(getter_AddRefs(mViewManager)); nsIScrollableView* scrollingView = nsnull; - vm->GetRootScrollableView(&scrollingView); - + mViewManager->GetRootScrollableView(&scrollingView); if (scrollingView) { - scrollingView->AddScrollPositionListener((nsIScrollPositionListener *)this); + scrollingView->AddScrollPositionListener(this); } return rv; +} +NS_IMETHODIMP +CanvasFrame::Destroy(nsIPresContext* aPresContext) +{ + nsIScrollableView* scrollingView = nsnull; + mViewManager->GetRootScrollableView(&scrollingView); + if (scrollingView) { + scrollingView->RemoveScrollPositionListener(this); + } + + return nsHTMLContainerFrame::Destroy(aPresContext); } NS_IMETHODIMP @@ -251,8 +259,13 @@ CanvasFrame::ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX #ifdef DEBUG_CANVAS_FOCUS { PRBool hasFocus = PR_FALSE; + nsCOMPtr observer; + mViewManager->GetViewObserver(*getter_AddRefs(observer)); + nsCOMPtr shell = do_QueryInterface(observer); + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); nsCOMPtr container; - mPresContext->GetContainer(getter_AddRefs(container)); + context->GetContainer(getter_AddRefs(container)); nsCOMPtr docShell(do_QueryInterface(container)); if (docShell) { docShell->GetHasFocus(&hasFocus); @@ -263,16 +276,7 @@ CanvasFrame::ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX if (mDoPaintFocus) { mDoPaintFocus = PR_FALSE; - - nsCOMPtr presShell; - mPresContext->GetShell(getter_AddRefs(presShell)); - if (presShell) { - nsCOMPtr vm; - presShell->GetViewManager(getter_AddRefs(vm)); - if (vm) { - vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC); - } - } + mViewManager->UpdateAllViews(NS_VMREFRESH_NO_SYNC); } return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp index c31ef5e3efb..27f973b6d43 100644 --- a/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/mozilla/layout/html/base/src/nsGfxScrollFrame.cpp @@ -460,6 +460,10 @@ NS_IMETHODIMP nsGfxScrollFrame::Destroy(nsIPresContext* aPresContext) { + nsIScrollableView *view = mInner->GetScrollableView(aPresContext); + NS_ASSERTION(view, "unexpected null pointer"); + if (view) + view->RemoveScrollPositionListener(mInner); return nsBoxFrame::Destroy(aPresContext); } diff --git a/mozilla/layout/html/base/src/nsHTMLFrame.cpp b/mozilla/layout/html/base/src/nsHTMLFrame.cpp index 87538fcc00d..9207d8d5be1 100644 --- a/mozilla/layout/html/base/src/nsHTMLFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLFrame.cpp @@ -97,6 +97,7 @@ public: nsIFrame* aParent, nsIStyleContext* aContext, nsIFrame* aPrevInFlow); + NS_IMETHOD Destroy(nsIPresContext* aPresContext); NS_IMETHOD AppendFrames(nsIPresContext* aPresContext, nsIPresShell& aPresShell, @@ -168,7 +169,7 @@ protected: // Data members PRPackedBool mDoPaintFocus; - nsCOMPtr mPresContext; + nsCOMPtr mViewManager; private: @@ -227,22 +228,29 @@ CanvasFrame::Init(nsIPresContext* aPresContext, { nsresult rv = nsHTMLContainerFrame::Init(aPresContext,aContent,aParent,aContext,aPrevInFlow); - mPresContext = aPresContext; - nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - nsCOMPtr vm; - presShell->GetViewManager(getter_AddRefs(vm)); + presShell->GetViewManager(getter_AddRefs(mViewManager)); nsIScrollableView* scrollingView = nsnull; - vm->GetRootScrollableView(&scrollingView); - + mViewManager->GetRootScrollableView(&scrollingView); if (scrollingView) { - scrollingView->AddScrollPositionListener((nsIScrollPositionListener *)this); + scrollingView->AddScrollPositionListener(this); } return rv; +} +NS_IMETHODIMP +CanvasFrame::Destroy(nsIPresContext* aPresContext) +{ + nsIScrollableView* scrollingView = nsnull; + mViewManager->GetRootScrollableView(&scrollingView); + if (scrollingView) { + scrollingView->RemoveScrollPositionListener(this); + } + + return nsHTMLContainerFrame::Destroy(aPresContext); } NS_IMETHODIMP @@ -251,8 +259,13 @@ CanvasFrame::ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX #ifdef DEBUG_CANVAS_FOCUS { PRBool hasFocus = PR_FALSE; + nsCOMPtr observer; + mViewManager->GetViewObserver(*getter_AddRefs(observer)); + nsCOMPtr shell = do_QueryInterface(observer); + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context)); nsCOMPtr container; - mPresContext->GetContainer(getter_AddRefs(container)); + context->GetContainer(getter_AddRefs(container)); nsCOMPtr docShell(do_QueryInterface(container)); if (docShell) { docShell->GetHasFocus(&hasFocus); @@ -263,16 +276,7 @@ CanvasFrame::ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX if (mDoPaintFocus) { mDoPaintFocus = PR_FALSE; - - nsCOMPtr presShell; - mPresContext->GetShell(getter_AddRefs(presShell)); - if (presShell) { - nsCOMPtr vm; - presShell->GetViewManager(getter_AddRefs(vm)); - if (vm) { - vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC); - } - } + mViewManager->UpdateAllViews(NS_VMREFRESH_NO_SYNC); } return NS_OK; }