зеркало из https://github.com/mozilla/pjs.git
added ability to set behavior of scrollbars in scrollable views.
This commit is contained in:
Родитель
e9a44a81e8
Коммит
7dda210d32
|
@ -24,6 +24,13 @@
|
|||
#include "nsIViewManager.h"
|
||||
class nsIView;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
nsScrollPreference_kAuto = 0,
|
||||
nsScrollPreference_kNeverScroll,
|
||||
nsScrollPreference_kAlwaysScroll
|
||||
} nsScrollPreference;
|
||||
|
||||
// IID for the nsIView interface
|
||||
#define NS_ISCROLLABLEVIEW_IID \
|
||||
{ 0xc95f1830, 0xc376, 0x11d1, \
|
||||
|
@ -83,6 +90,20 @@ public:
|
|||
* @param aShow if PR_TRUE, quality level will be displayed, else hidden
|
||||
*/
|
||||
virtual void SetQuality(nsContentQuality aQuality) = 0;
|
||||
|
||||
/**
|
||||
* Select whether scroll bars should be displayed all the time, never or
|
||||
* only when necessary.
|
||||
* @param aPref desired scrollbar selection
|
||||
*/
|
||||
virtual void SetScrollPreference(nsScrollPreference aPref) = 0;
|
||||
|
||||
/**
|
||||
* Query whether scroll bars should be displayed all the time, never or
|
||||
* only when necessary.
|
||||
* @return current scrollbar selection
|
||||
*/
|
||||
virtual nsScrollPreference GetScrollPreference(void) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -238,6 +238,7 @@ nsScrollingView :: nsScrollingView()
|
|||
mVScrollBarView = nsnull;
|
||||
mHScrollBarView = nsnull;
|
||||
mCornerView = nsnull;
|
||||
mScrollPref = nsScrollPreference_kAuto;
|
||||
}
|
||||
|
||||
nsScrollingView :: ~nsScrollingView()
|
||||
|
@ -690,7 +691,9 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
|
||||
if (NS_OK == win->QueryInterface(kscroller, (void **)&scrollh))
|
||||
{
|
||||
if (mSizeX > mBounds.width)
|
||||
if (((mSizeX > mBounds.width) &&
|
||||
(mScrollPref != nsScrollPreference_kNeverScroll)) ||
|
||||
(mScrollPref == nsScrollPreference_kAlwaysScroll))
|
||||
scrollh->Release(); //DO NOT USE NS_RELEASE()! MMP
|
||||
else
|
||||
NS_RELEASE(scrollh); //MUST USE NS_RELEASE()! MMP
|
||||
|
@ -708,11 +711,12 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
|
||||
if (NS_OK == win->QueryInterface(kscroller, (void **)&scrollv))
|
||||
{
|
||||
if (mSizeY > mBounds.height)
|
||||
if ((mSizeY > mBounds.height) && (mScrollPref != nsScrollPreference_kNeverScroll))
|
||||
{
|
||||
//we need to be able to scroll
|
||||
|
||||
mVScrollBarView->SetVisibility(nsViewVisibility_kShow);
|
||||
win->Enable(PR_TRUE);
|
||||
|
||||
//now update the scroller position for the new size
|
||||
|
||||
|
@ -729,8 +733,18 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
{
|
||||
mOffsetY = 0;
|
||||
dy = NS_TO_INT_ROUND(scale * offy);
|
||||
mVScrollBarView->SetVisibility(nsViewVisibility_kHide);
|
||||
NS_RELEASE(scrollv);
|
||||
|
||||
if (mScrollPref == nsScrollPreference_kAlwaysScroll)
|
||||
{
|
||||
mVScrollBarView->SetVisibility(nsViewVisibility_kShow);
|
||||
win->Enable(PR_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
mVScrollBarView->SetVisibility(nsViewVisibility_kHide);
|
||||
win->Enable(PR_TRUE);
|
||||
NS_RELEASE(scrollv);
|
||||
}
|
||||
}
|
||||
|
||||
//don't release the vertical scroller here because if we need to
|
||||
|
@ -749,11 +763,12 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
|
||||
if (NS_OK == win->QueryInterface(kscroller, (void **)&scrollh))
|
||||
{
|
||||
if (mSizeX > mBounds.width)
|
||||
if ((mSizeX > mBounds.width) && (mScrollPref != nsScrollPreference_kNeverScroll))
|
||||
{
|
||||
//we need to be able to scroll
|
||||
|
||||
mHScrollBarView->SetVisibility(nsViewVisibility_kShow);
|
||||
win->Enable(PR_TRUE);
|
||||
|
||||
//now update the scroller position for the new size
|
||||
|
||||
|
@ -775,7 +790,17 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
{
|
||||
mOffsetX = 0;
|
||||
dx = NS_TO_INT_ROUND(scale * offx);
|
||||
mHScrollBarView->SetVisibility(nsViewVisibility_kHide);
|
||||
|
||||
if (mScrollPref == nsScrollPreference_kAlwaysScroll)
|
||||
{
|
||||
mHScrollBarView->SetVisibility(nsViewVisibility_kShow);
|
||||
win->Enable(PR_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
mHScrollBarView->SetVisibility(nsViewVisibility_kHide);
|
||||
win->Enable(PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(scrollh);
|
||||
|
@ -876,6 +901,17 @@ void nsScrollingView :: SetQuality(nsContentQuality aQuality)
|
|||
((CornerView *)mCornerView)->SetQuality(aQuality);
|
||||
}
|
||||
|
||||
void nsScrollingView :: SetScrollPreference(nsScrollPreference aPref)
|
||||
{
|
||||
mScrollPref = aPref;
|
||||
ComputeContainerSize();
|
||||
}
|
||||
|
||||
nsScrollPreference nsScrollingView :: GetScrollPreference(void)
|
||||
{
|
||||
return mScrollPref;
|
||||
}
|
||||
|
||||
void nsScrollingView :: AdjustChildWidgets(nsScrollingView *aScrolling, nsIView *aView, nscoord aDx, nscoord aDy, float scale)
|
||||
{
|
||||
PRInt32 numkids = aView->GetChildCount();
|
||||
|
|
|
@ -66,15 +66,19 @@ public:
|
|||
virtual PRBool GetShowQuality(void);
|
||||
virtual void SetQuality(nsContentQuality aQuality);
|
||||
|
||||
virtual void SetScrollPreference(nsScrollPreference aPref);
|
||||
virtual nsScrollPreference GetScrollPreference(void);
|
||||
|
||||
//private
|
||||
void ComputeScrollArea(nsIView *aView, nsRect &aRect, nscoord aOffX, nscoord aOffY);
|
||||
|
||||
protected:
|
||||
nscoord mSizeX, mSizeY;
|
||||
nscoord mOffsetX, mOffsetY;
|
||||
nsIView *mVScrollBarView;
|
||||
nsIView *mHScrollBarView;
|
||||
nsIView *mCornerView;
|
||||
nscoord mSizeX, mSizeY;
|
||||
nscoord mOffsetX, mOffsetY;
|
||||
nsIView *mVScrollBarView;
|
||||
nsIView *mHScrollBarView;
|
||||
nsIView *mCornerView;
|
||||
nsScrollPreference mScrollPref;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче