From cbfb8c143d4744d38f684a6adfc2021801d0ffa9 Mon Sep 17 00:00:00 2001 From: michaelp Date: Thu, 23 Apr 1998 21:51:43 +0000 Subject: [PATCH] view no longer shows a scrollbar when we can't scroll. added GetScrolledView(). --- view/public/nsIScrollableView.h | 7 ++++ view/src/nsScrollingView.cpp | 69 ++++++++++++++++++++------------- view/src/nsScrollingView.h | 2 + view/src/nsView.cpp | 33 +++++++--------- 4 files changed, 66 insertions(+), 45 deletions(-) diff --git a/view/public/nsIScrollableView.h b/view/public/nsIScrollableView.h index 5a67dd5d9740..8f9bc6d96ec8 100644 --- a/view/public/nsIScrollableView.h +++ b/view/public/nsIScrollableView.h @@ -53,6 +53,13 @@ public: * @result coordinate in twips */ virtual PRInt32 GetVisibleOffset(void) = 0; + + /** + * Get the view that we are scrolling within the + * scrolling view. + * @result child view + */ + virtual nsIView * GetScrolledView(void) = 0; }; #endif diff --git a/view/src/nsScrollingView.cpp b/view/src/nsScrollingView.cpp index 3036b954a441..1c2218573954 100644 --- a/view/src/nsScrollingView.cpp +++ b/view/src/nsScrollingView.cpp @@ -47,6 +47,16 @@ ScrollBarView :: ~ScrollBarView() void ScrollBarView :: SetDimensions(nscoord width, nscoord height) { mBounds.SizeTo(width, height); + + if (nsnull != mWindow) + { + nsIPresContext *px = mViewManager->GetPresContext(); + float t2p = px->GetTwipsToPixels(); + + mWindow->Resize(NS_TO_INT_ROUND(t2p * width), NS_TO_INT_ROUND(t2p * height)); + + NS_RELEASE(px); + } } static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); @@ -140,8 +150,6 @@ void nsScrollingView :: SetPosition(nscoord x, nscoord y) void nsScrollingView :: SetDimensions(nscoord width, nscoord height) { - PRInt32 owidth, oheight; - nsIWidget *win; nsRect trect; nsIPresContext *cx; nsIDeviceContext *dx; @@ -153,32 +161,19 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height) cx = mViewManager->GetPresContext(); dx = cx->GetDeviceContext(); - mScrollBarView->GetDimensions(&owidth, &oheight); - mScrollBarView->SetDimensions(owidth, height); + mScrollBarView->GetDimensions(&trect.width, &trect.height); - mScrollBarView->SetPosition(width - NS_TO_INT_ROUND(dx->GetScrollBarWidth()), 0); + trect.height = height; + trect.x = width - NS_TO_INT_ROUND(dx->GetScrollBarWidth()); + trect.y = 0; - win = mScrollBarView->GetWidget(); + mScrollBarView->SetBounds(trect); - if (nsnull != win) - { - nsRect trect; - win->GetBounds(trect); - - //compute new bounds - - trect.x = NS_TO_INT_ROUND((width - NS_TO_INT_ROUND(dx->GetScrollBarWidth())) * cx->GetTwipsToPixels()); - trect.y = 0; - trect.height = NS_TO_INT_ROUND(height * cx->GetTwipsToPixels()); - - win->Resize(trect.x, trect.y, trect.width, trect.height); - - NS_RELEASE(win); - } - - //this will fix the size of the thumb when we resize the root window - - SetContainerSize(mSize); + //this will fix the size of the thumb when we resize the root window, + //but unfortunately it will also cause scrollbar flashing. so long as + //all resize operations happen through the viewmanager, this is not + //an issue. we'll see. MMP +// SetContainerSize(mSize); NS_RELEASE(dx); NS_RELEASE(cx); @@ -281,7 +276,7 @@ void nsScrollingView :: SetContainerSize(nscoord aSize) //we need to be able to scroll - scroll->Enable(PR_TRUE); + mScrollBarView->SetVisibility(nsViewVisibility_kShow); //now update the scroller position for the new size @@ -298,7 +293,7 @@ void nsScrollingView :: SetContainerSize(nscoord aSize) NS_RELEASE(px); } else - scroll->Enable(PR_FALSE); + mScrollBarView->SetVisibility(nsViewVisibility_kHide); scroll->Release(); } @@ -348,3 +343,23 @@ void nsScrollingView :: AdjustChildWidgets(nscoord aDx, nscoord aDy) } } } + +nsIView * nsScrollingView :: GetScrolledView(void) +{ + PRInt32 numkids; + nsIView *retview = nsnull; + + numkids = GetChildCount(); + + for (PRInt32 cnt = 0; cnt < numkids; cnt++) + { + retview = GetChild(cnt); + + if (retview != mScrollBarView) + break; + else + retview = nsnull; + } + + return retview; +} diff --git a/view/src/nsScrollingView.h b/view/src/nsScrollingView.h index b8d4e77e6c5b..c584a593fb28 100644 --- a/view/src/nsScrollingView.h +++ b/view/src/nsScrollingView.h @@ -59,6 +59,8 @@ public: virtual void SetVisibleOffset(PRInt32 aOffset); virtual PRInt32 GetVisibleOffset(); + virtual nsIView * GetScrolledView(void); + protected: PRInt32 mSize; PRInt32 mOffset; diff --git a/view/src/nsView.cpp b/view/src/nsView.cpp index aa99e0e1abf3..93188142b3ce 100644 --- a/view/src/nsView.cpp +++ b/view/src/nsView.cpp @@ -30,6 +30,7 @@ #include "nsRepository.h" #include "nsIRenderingContext.h" #include "nsTransform2D.h" +#include "nsIScrollableView.h" static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); @@ -478,35 +479,31 @@ void nsView :: GetPosition(nscoord *x, nscoord *y) *y = mBounds.y; } -#include "nsScrollingView.h" - void nsView :: SetDimensions(nscoord width, nscoord height) { mBounds.SizeTo(width, height); - //XXX this is a hack. pretend you don't see it. - //it will go away soon, i promise. MMP - if (nsnull != mParent) { - nsScrollingView *root = (nsScrollingView *)mViewManager->GetRootView(); + nsIScrollableView *scroller; - if (mParent == root) + static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID); + + if (NS_OK == mParent->QueryInterface(kscroller, (void **)&scroller)) { - root->SetContainerSize(mBounds.height); + scroller->SetContainerSize(mBounds.height); + NS_RELEASE(scroller); } + } - if (nsnull != mWindow) - { - nsIPresContext *px = mViewManager->GetPresContext(); - float t2p = px->GetTwipsToPixels(); - - mWindow->Resize(NS_TO_INT_ROUND(t2p * width), NS_TO_INT_ROUND(t2p * height)); + if (nsnull != mWindow) + { + nsIPresContext *px = mViewManager->GetPresContext(); + float t2p = px->GetTwipsToPixels(); + + mWindow->Resize(NS_TO_INT_ROUND(t2p * width), NS_TO_INT_ROUND(t2p * height)); - NS_RELEASE(px); - } - - NS_RELEASE(root); + NS_RELEASE(px); } }