From 1996c7ecd8f00aba856c5cc2d3c8ab0b33bf2379 Mon Sep 17 00:00:00 2001 From: "kmcclusk%netscape.com" Date: Thu, 27 Jan 2000 02:23:34 +0000 Subject: [PATCH] Added missing nsIViewManager methods to nsViewManager2.h and nsViewManger2.cpp. bug=22069; r=attinasi@netscape.com --- view/public/nsIViewManager.h | 1 - view/src/nsViewManager2.cpp | 72 +++++++++++++++++++++++++++++++++++- view/src/nsViewManager2.h | 6 ++- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/view/public/nsIViewManager.h b/view/public/nsIViewManager.h index 922ca025f033..e3b74cc324ec 100644 --- a/view/public/nsIViewManager.h +++ b/view/public/nsIViewManager.h @@ -454,7 +454,6 @@ public: /** * Force update of view manager widget * Callers should use UpdateView(view, NS_VMREFRESH_IMMEDIATE) in most cases instead - * @param aWidget the widget that aView renders into. * @result error status */ diff --git a/view/src/nsViewManager2.cpp b/view/src/nsViewManager2.cpp index 5179feccf31a..6d70815fa68f 100755 --- a/view/src/nsViewManager2.cpp +++ b/view/src/nsViewManager2.cpp @@ -287,7 +287,7 @@ NS_IMETHODIMP nsViewManager2::GetRootView(nsIView *&aView) return NS_OK; } -NS_IMETHODIMP nsViewManager2::SetRootView(nsIView *aView) +NS_IMETHODIMP nsViewManager2 :: SetRootView(nsIView *aView, nsIWidget* aWidget) { UpdateTransCnt(mRootView, aView); // Do NOT destroy the current root view. It's the caller's responsibility @@ -297,8 +297,27 @@ NS_IMETHODIMP nsViewManager2::SetRootView(nsIView *aView) //now get the window too. NS_IF_RELEASE(mRootWindow); - if (nsnull != mRootView) + // The window must be specified through one of the following: + //* a) The aView has a nsIWidget instance or + //* b) the aWidget parameter is an nsIWidget instance to render into + //* that is not owned by a view. + //* c) aView has a parent view managed by a different view manager or + + if (nsnull != aWidget) { + mRootWindow = aWidget; + NS_ADDREF(mRootWindow); + return NS_OK; + } + + // case b) The aView has a nsIWidget instance + if (nsnull != mRootView) { mRootView->GetWidget(mRootWindow); + if (nsnull != mRootWindow) { + return NS_OK; + } + } + + // case c) aView has a parent view managed by a different view manager return NS_OK; } @@ -1775,6 +1794,55 @@ NS_IMETHODIMP nsViewManager2::RemoveCompositeListener(nsICompositeListener* aLis return NS_ERROR_FAILURE; } +NS_IMETHODIMP nsViewManager2::GetWidgetForView(nsIView *aView, nsIWidget **aWidget) +{ + *aWidget = nsnull; + nsIView *view = aView; + PRBool hasWidget = PR_FALSE; + while (!hasWidget && view) + { + view->HasWidget(&hasWidget); + if (!hasWidget) + view->GetParent(view); + } + + if (hasWidget) { + // Widget was found in the view hierarchy + view->GetWidget(*aWidget); + } else { + // No widget was found in the view hierachy, so use try to use the mRootWindow + if (nsnull != mRootWindow) { +#ifdef NS_DEBUG + nsCOMPtr vm; + nsCOMPtr thisInstance(this); + aView->GetViewManager(*getter_AddRefs(vm)); + NS_ASSERTION(thisInstance == vm, "Must use the view instances view manager when calling GetWidgetForView"); +#endif + *aWidget = mRootWindow; + NS_ADDREF(mRootWindow); + } + } + + return NS_OK; +} + + +NS_IMETHODIMP nsViewManager2::GetWidget(nsIWidget **aWidget) +{ + NS_IF_ADDREF(mRootWindow); + *aWidget = mRootWindow; + return NS_OK; +} + +NS_IMETHODIMP nsViewManager2::ForceUpdate() +{ + if (mRootWindow) { + mRootWindow->Update(); + } + return NS_OK; +} + + PRBool nsViewManager2::CreateDisplayList(nsIView *aView, PRInt32 *aIndex, nscoord aOriginX, nscoord aOriginY, nsIView *aRealView, const nsRect *aDamageRect, nsIView *aTopView, diff --git a/view/src/nsViewManager2.h b/view/src/nsViewManager2.h index f7455f11ee97..6f651d267c33 100755 --- a/view/src/nsViewManager2.h +++ b/view/src/nsViewManager2.h @@ -48,7 +48,7 @@ public: NS_IMETHOD Init(nsIDeviceContext* aContext); NS_IMETHOD GetRootView(nsIView *&aView); - NS_IMETHOD SetRootView(nsIView *aView); + NS_IMETHOD SetRootView(nsIView *aView, nsIWidget* aWidget=nsnull); NS_IMETHOD GetFrameRate(PRUint32 &aRate); NS_IMETHOD SetFrameRate(PRUint32 frameRate); @@ -129,6 +129,10 @@ public: NS_IMETHOD AddCompositeListener(nsICompositeListener *aListener); NS_IMETHOD RemoveCompositeListener(nsICompositeListener *aListener); + NS_IMETHOD GetWidgetForView(nsIView *aView, nsIWidget **aWidget); + NS_IMETHOD GetWidget(nsIWidget **aWidget); + NS_IMETHOD ForceUpdate(); + protected: virtual ~nsViewManager2();