Bug 232913. Let nsIScrollbarMediator support multiple scrollbars. Patch by Nate Nielsen, r+sr=roc.

This commit is contained in:
roc+%cs.cmu.edu 2004-05-29 00:09:05 +00:00
Родитель 98e604dbdf
Коммит 27375e9b38
15 изменённых файлов: 55 добавлений и 42 удалений

Просмотреть файл

@ -1615,7 +1615,7 @@ nsGfxScrollFrameInner::SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisibl
scrollbar->GetScrollbarMediator(getter_AddRefs(mediator));
if (mediator) {
// Inform the mediator of the visibility change.
mediator->VisibilityChanged(aVisible);
mediator->VisibilityChanged(scrollbar, aVisible);
}
}
}

Просмотреть файл

@ -1615,7 +1615,7 @@ nsGfxScrollFrameInner::SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisibl
scrollbar->GetScrollbarMediator(getter_AddRefs(mediator));
if (mediator) {
// Inform the mediator of the visibility change.
mediator->VisibilityChanged(aVisible);
mediator->VisibilityChanged(scrollbar, aVisible);
}
}
}

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Original Author: David W. Hyatt (hyatt@netscape.com)
* Nate Nielsen (nielsen@memberwebs.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -39,21 +40,25 @@
#ifndef nsIScrollbarMediator_h___
#define nsIScrollbarMediator_h___
// {351C003A-E8F7-4d10-8BFA-635C9860D650}
// {b589027f-271b-4c68-91df-04f139885e9a}
#define NS_ISCROLLBARMEDIATOR_IID \
{ 0x351c003a, 0xe8f7, 0x4d10, { 0x8b, 0xfa, 0x63, 0x5c, 0x98, 0x60, 0xd6, 0x50 } }
{ 0xb589027f, 0x271b, 0x4c68, { 0x91, 0xdf, 0x04, 0xf1, 0x39, 0x88, 0x5e, 0x9a } }
static NS_DEFINE_IID(kIScrollbarMediatorIID, NS_ISCROLLBARMEDIATOR_IID);
static NS_DEFINE_IID(kIScrollbarMediatorIID, NS_ISCROLLBARMEDIATOR_IID);
class nsIScrollbarMediator : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCROLLBARMEDIATOR_IID)
NS_IMETHOD PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex) = 0;
NS_IMETHOD ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex) = 0;
NS_IMETHOD VisibilityChanged(PRBool aVisible) = 0;
// The nsISupports aScrollbar argument below denotes the
// scrollbar that's firing the notification. It should be
// where the same object as where nsIScrollbarFrame is implemented
NS_IMETHOD PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex) = 0;
NS_IMETHOD ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex) = 0;
NS_IMETHOD VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible) = 0;
};
#endif

Просмотреть файл

@ -373,7 +373,7 @@ nsListBoxBodyFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState)
///////////// nsIScrollbarMediator ///////////////
NS_IMETHODIMP
nsListBoxBodyFrame::PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex)
nsListBoxBodyFrame::PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex)
{
if (mScrolling)
return NS_OK;
@ -428,7 +428,7 @@ nsListBoxBodyFrame::PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex)
}
NS_IMETHODIMP
nsListBoxBodyFrame::VisibilityChanged(PRBool aVisible)
nsListBoxBodyFrame::VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible)
{
PRInt32 lastPageTopRow = GetRowCount() - (GetAvailableHeight() / mRowHeight);
if (lastPageTopRow < 0)
@ -443,7 +443,7 @@ nsListBoxBodyFrame::VisibilityChanged(PRBool aVisible)
}
NS_IMETHODIMP
nsListBoxBodyFrame::ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex)
nsListBoxBodyFrame::ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex)
{
if (aOldIndex == aNewIndex)
return NS_OK;

Просмотреть файл

@ -82,9 +82,9 @@ public:
PRInt32 aModType);
// nsIScrollbarMediator
NS_IMETHOD PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex);
NS_IMETHOD ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex);
NS_IMETHOD VisibilityChanged(PRBool aVisible);
NS_IMETHOD PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex);
NS_IMETHOD ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex);
NS_IMETHOD VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible);
// nsIReflowCallback
NS_IMETHOD ReflowFinished(nsIPresShell* aPresShell, PRBool* aFlushFlag);

Просмотреть файл

@ -90,7 +90,7 @@ nsNativeScrollbarFrame::~nsNativeScrollbarFrame ( )
// the content node just to be safe about lifetime issues
nsCOMPtr<nsINativeScrollbar> scrollbar ( do_QueryInterface(mScrollbar) );
if ( scrollbar )
scrollbar->SetContent(nsnull, nsnull);
scrollbar->SetContent(nsnull, nsnull, nsnull);
}
@ -240,7 +240,7 @@ nsNativeScrollbarFrame::AttributeChanged(nsIPresContext* aPresContext,
nsCOMPtr<nsIScrollbarMediator> mediator;
scrollbarFrame->GetScrollbarMediator(getter_AddRefs(mediator));
if (mediator)
mediator->PositionChanged(oldPosition, /* inout */ curPosition);
mediator->PositionChanged(scrollbarFrame, oldPosition, /* inout */ curPosition);
}
nsAutoString currentStr;
@ -327,7 +327,7 @@ nsNativeScrollbarFrame::Hookup()
return;
}
scrollbar->SetContent(scrollbarContent, mediator);
scrollbar->SetContent(scrollbarContent, sb, mediator);
mScrollbarNeedsContent = PR_FALSE;
if (!scrollbarContent)

Просмотреть файл

@ -195,7 +195,7 @@ nsScrollbarButtonFrame::MouseClicked()
nsCOMPtr<nsIScrollbarMediator> m;
sb->GetScrollbarMediator(getter_AddRefs(m));
if (m) {
m->ScrollbarButtonPressed(oldpos, curpos);
m->ScrollbarButtonPressed(sb, oldpos, curpos);
return;
}
}

Просмотреть файл

@ -267,7 +267,7 @@ nsSliderFrame::AttributeChanged(nsIPresContext* aPresContext,
nsCOMPtr<nsIScrollbarMediator> mediator;
scrollbarFrame->GetScrollbarMediator(getter_AddRefs(mediator));
if (mediator) {
mediator->PositionChanged(GetCurrentPosition(scrollbar), current);
mediator->PositionChanged(scrollbarFrame, GetCurrentPosition(scrollbar), current);
}
}
@ -833,7 +833,7 @@ nsSliderFrame::SetCurrentPosition(nsIContent* scrollbar, nsIFrame* aThumbFrame,
nsCOMPtr<nsIScrollbarMediator> mediator;
scrollbarFrame->GetScrollbarMediator(getter_AddRefs(mediator));
if (mediator) {
mediator->PositionChanged(GetCurrentPosition(scrollbar), newpos);
mediator->PositionChanged(scrollbarFrame, GetCurrentPosition(scrollbar), newpos);
UpdateAttribute(scrollbar, newpos, PR_FALSE, aIsSmooth);
CurrentPositionChanged(GetPresContext());
return;

Просмотреть файл

@ -3269,7 +3269,7 @@ nsTreeBodyFrame::ScrollInternal(PRInt32 aRow)
}
NS_IMETHODIMP
nsTreeBodyFrame::ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex)
nsTreeBodyFrame::ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex)
{
if (aNewIndex > aOldIndex)
ScrollToRow(mTopRowIndex+1);
@ -3279,7 +3279,7 @@ nsTreeBodyFrame::ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex)
}
NS_IMETHODIMP
nsTreeBodyFrame::PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex)
nsTreeBodyFrame::PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex)
{
if (!EnsureScrollbar())
return NS_ERROR_UNEXPECTED;

Просмотреть файл

@ -79,9 +79,9 @@ public:
NS_IMETHOD PseudoMatches(nsIAtom* aTag, nsCSSSelector* aSelector, PRBool* aResult);
// nsIScrollbarMediator
NS_IMETHOD PositionChanged(PRInt32 aOldIndex, PRInt32& aNewIndex);
NS_IMETHOD ScrollbarButtonPressed(PRInt32 aOldIndex, PRInt32 aNewIndex);
NS_IMETHOD VisibilityChanged(PRBool aVisible) { Invalidate(); return NS_OK; };
NS_IMETHOD PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex);
NS_IMETHOD ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex);
NS_IMETHOD VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible) { Invalidate(); return NS_OK; };
// Overridden from nsIFrame to cache our pres context.
NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent,

Просмотреть файл

@ -53,10 +53,10 @@ interface nsIContent;
interface nsIScrollbarMediator;
[uuid(dd1cb116-1dd1-11b2-9e67-abac4e09d533)]
[uuid(b77380bc-610b-49e3-8df7-18cc946285c5)]
interface nsINativeScrollbar : nsISupports
{
void setContent ( in nsIContent content, in nsIScrollbarMediator mediator);
void setContent ( in nsIContent content, in nsISupports scrollbar, in nsIScrollbarMediator mediator);
readonly attribute long narrowSize; // the width of a vertical scrollbar, height of horizontal

Просмотреть файл

@ -93,7 +93,8 @@ private:
nsIContent* mContent; // the content node that affects the scrollbar's value
nsIScrollbarMediator* mMediator; // for scrolling with outliners
nsISupports* mScrollbar; // for calling into the mediator
PRUint32 mValue;
PRUint32 mMaxValue;
PRUint32 mVisibleImageSize;

Просмотреть файл

@ -63,6 +63,7 @@ nsNativeScrollbar::nsNativeScrollbar()
: nsChildView()
, mContent(nsnull)
, mMediator(nsnull)
, mScrollbar(nsnull)
, mValue(0)
, mMaxValue(0)
, mVisibleImageSize(0)
@ -143,7 +144,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
newPos = oldPos - (mLineIncrement ? mLineIncrement : 1);
if ( mMediator ) {
BoundsCheck(0, newPos, mMaxValue);
mMediator->ScrollbarButtonPressed(oldPos, newPos);
mMediator->ScrollbarButtonPressed(mScrollbar, oldPos, newPos);
} else {
UpdateContentPosition(newPos);
}
@ -153,7 +154,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
newPos = oldPos + (mLineIncrement ? mLineIncrement : 1);
if ( mMediator ) {
BoundsCheck(0, newPos, mMaxValue);
mMediator->ScrollbarButtonPressed(oldPos, newPos);
mMediator->ScrollbarButtonPressed(mScrollbar, oldPos, newPos);
} else {
UpdateContentPosition(newPos);
}
@ -174,7 +175,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
@ -185,7 +186,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
@ -202,7 +203,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
@ -414,10 +415,12 @@ nsNativeScrollbar::GetNarrowSize(PRInt32* outSize)
// care about the mediator for <outliner> so we can do row-based scrolling.
//
NS_IMETHODIMP
nsNativeScrollbar::SetContent(nsIContent* inContent, nsIScrollbarMediator* inMediator)
nsNativeScrollbar::SetContent(nsIContent* inContent, nsISupports* inScrollbar,
nsIScrollbarMediator* inMediator)
{
mContent = inContent;
mMediator = inMediator;
mScrollbar = inScrollbar;
if ( mContent ) {
// we may have to re-create the scrollbar view as horizontal. Check the

Просмотреть файл

@ -101,6 +101,7 @@ nsNativeScrollbar::nsNativeScrollbar()
: nsMacControl()
, mContent(nsnull)
, mMediator(nsnull)
, mScrollbar(nsnull)
, mLineIncrement(0)
, mMaxValue(0)
, mVisibleImageSize(0)
@ -157,7 +158,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
// update the attributes on the content node (the scroll frame listens
// for these attributes and will scroll accordingly). However,
// if we have a mediator, we're in an outliner and we have to scroll by
// lines. Outliner ignores the params to ScrollbarButtonPressed() except
// lines. Outliner ignores the indexes in ScrollbarButtonPressed() except
// to check if one is greater than the other to indicate direction.
//
@ -165,7 +166,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
newPos = oldPos - (mLineIncrement ? mLineIncrement : 1);
if ( mMediator ) {
BoundsCheck(0, newPos, mMaxValue);
mMediator->ScrollbarButtonPressed(oldPos, newPos);
mMediator->ScrollbarButtonPressed(mScrollbar, oldPos, newPos);
} else {
UpdateContentPosition(newPos);
}
@ -175,7 +176,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
newPos = oldPos + (mLineIncrement ? mLineIncrement : 1);
if ( mMediator ) {
BoundsCheck(0, newPos, mMaxValue);
mMediator->ScrollbarButtonPressed(oldPos, newPos);
mMediator->ScrollbarButtonPressed(mScrollbar, oldPos, newPos);
} else {
UpdateContentPosition(newPos);
}
@ -197,7 +198,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
@ -208,7 +209,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
@ -219,7 +220,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
PRInt32 op = oldPos, np = mValue;
if ( np < 0 )
np = 0;
mMediator->PositionChanged(op, np);
mMediator->PositionChanged(mScrollbar, op, np);
}
break;
}
@ -512,9 +513,11 @@ nsNativeScrollbar::GetNarrowSize(PRInt32* outSize)
// care about the mediator for <outliner> so we can do row-based scrolling.
//
NS_IMETHODIMP
nsNativeScrollbar::SetContent(nsIContent* inContent, nsIScrollbarMediator* inMediator)
nsNativeScrollbar::SetContent(nsIContent* inContent, nsISupports* inScrollbar,
nsIScrollbarMediator* inMediator)
{
mContent = inContent;
mMediator = inMediator;
mScrollbar = inScrollbar;
return NS_OK;
}

Просмотреть файл

@ -89,6 +89,7 @@ private:
nsIContent* mContent; // the content node that affects the scrollbar's value
nsIScrollbarMediator* mMediator; // for scrolling with outliners
nsISupports* mScrollbar; // for calling into the mediator
PRUint32 mMaxValue;
PRUint32 mVisibleImageSize;