Fix bug 274036: makes sure Mac native controls (Carbon & Cocoa) look disabled when there is nowhere to scroll by removing arbitrary hardcoded limits. r=josh, sr=bryner, a=chofmann.
git-svn-id: svn://10.0.0.236/trunk@175189 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -88,9 +88,11 @@ protected:
|
||||
|
||||
void RecreateHorizontalScrollbar();
|
||||
|
||||
virtual NSView* CreateCocoaView() ;
|
||||
virtual GrafPtr GetQuickDrawPort() ;
|
||||
virtual NSView* CreateCocoaView();
|
||||
virtual GrafPtr GetQuickDrawPort();
|
||||
|
||||
void UpdateScroller();
|
||||
|
||||
// DATA
|
||||
private:
|
||||
|
||||
@@ -101,7 +103,8 @@ private:
|
||||
PRUint32 mValue;
|
||||
PRUint32 mMaxValue;
|
||||
PRUint32 mVisibleImageSize;
|
||||
PRUint32 mLineIncrement;
|
||||
PRUint32 mLineIncrement;
|
||||
PRBool mIsEnabled;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ nsNativeScrollbar::nsNativeScrollbar()
|
||||
, mMaxValue(0)
|
||||
, mVisibleImageSize(0)
|
||||
, mLineIncrement(0)
|
||||
, mIsEnabled(PR_TRUE)
|
||||
{
|
||||
WIDGET_SET_CLASSNAME("nsNativeScrollbar");
|
||||
}
|
||||
@@ -145,7 +146,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
|
||||
// to check if one is greater than the other to indicate direction.
|
||||
//
|
||||
|
||||
case NSScrollerDecrementLine: // scroll up/left
|
||||
case NSScrollerDecrementLine: // scroll up/left
|
||||
newPos = oldPos - (mLineIncrement ? mLineIncrement : 1);
|
||||
if ( mMediator ) {
|
||||
BoundsCheck(0, newPos, mMaxValue);
|
||||
@@ -155,7 +156,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
|
||||
}
|
||||
break;
|
||||
|
||||
case NSScrollerIncrementLine: // scroll down/right
|
||||
case NSScrollerIncrementLine: // scroll down/right
|
||||
newPos = oldPos + (mLineIncrement ? mLineIncrement : 1);
|
||||
if ( mMediator ) {
|
||||
BoundsCheck(0, newPos, mMaxValue);
|
||||
@@ -173,7 +174,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
|
||||
// signed values first.
|
||||
//
|
||||
|
||||
case NSScrollerDecrementPage: // scroll up a page
|
||||
case NSScrollerDecrementPage: // scroll up a page
|
||||
newPos = oldPos - visibleImageSize;
|
||||
UpdateContentPosition(newPos);
|
||||
if ( mMediator ) {
|
||||
@@ -184,7 +185,7 @@ nsNativeScrollbar::DoScroll(NSScrollerPart inPart)
|
||||
}
|
||||
break;
|
||||
|
||||
case NSScrollerIncrementPage: // scroll down a page
|
||||
case NSScrollerIncrementPage: // scroll down a page
|
||||
newPos = oldPos + visibleImageSize;
|
||||
UpdateContentPosition(newPos);
|
||||
if ( mMediator ) {
|
||||
@@ -265,14 +266,11 @@ nsNativeScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent)
|
||||
NS_IMETHODIMP
|
||||
nsNativeScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||
{
|
||||
mMaxValue = ((int)aEndRange) > 0 ? aEndRange : 10;
|
||||
if ( GetControl() ) {
|
||||
// Update the current value based on the new range. We need to recompute the
|
||||
// float value in case we had to set the value to 0 because gecko cheated
|
||||
// and set the position before it set the max value.
|
||||
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
|
||||
[mView setFloatValue:(mValue / (float)mMaxValue) knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
|
||||
}
|
||||
if ((PRInt32)aEndRange < 0)
|
||||
aEndRange = 0;
|
||||
|
||||
mMaxValue = aEndRange;
|
||||
UpdateScroller();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -343,13 +341,12 @@ nsNativeScrollbar::GetPosition(PRUint32* aPos)
|
||||
NS_IMETHODIMP
|
||||
nsNativeScrollbar::SetViewSize(PRUint32 aSize)
|
||||
{
|
||||
mVisibleImageSize = ((int)aSize) > 0 ? aSize : 1;
|
||||
if ((PRInt32)aSize < 0)
|
||||
aSize = 0;
|
||||
|
||||
mVisibleImageSize = aSize;
|
||||
|
||||
// Update the current value based on the new range. We need to recompute the
|
||||
// float value in case we had to set the value to 0 because gecko cheated
|
||||
// and set the position before it set the max value.
|
||||
PRInt32 fullVisibleArea = mVisibleImageSize + mMaxValue;
|
||||
[mView setFloatValue:(mValue / (float)mMaxValue) knobProportion:(mVisibleImageSize / (float)fullVisibleArea)];
|
||||
UpdateScroller();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -461,7 +458,7 @@ nsNativeScrollbar::RecreateHorizontalScrollbar()
|
||||
NSRect oldBounds = [mView bounds];
|
||||
float oldValue = [mView floatValue];
|
||||
float oldProportion = [mView knobProportion];
|
||||
mVisible = PR_TRUE; // ensure that hide does the work
|
||||
mVisible = PR_TRUE; // ensure that hide does the work
|
||||
Show(PR_FALSE);
|
||||
[mView release];
|
||||
|
||||
@@ -509,7 +506,8 @@ nsNativeScrollbar::Show(PRBool bState)
|
||||
NS_IMETHODIMP
|
||||
nsNativeScrollbar::Enable(PRBool bState)
|
||||
{
|
||||
[mView setEnabled:(bState ? YES : NO)];
|
||||
mIsEnabled = bState;
|
||||
UpdateScroller();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -518,11 +516,27 @@ NS_IMETHODIMP
|
||||
nsNativeScrollbar::IsEnabled(PRBool *aState)
|
||||
{
|
||||
if (aState)
|
||||
*aState = [mView isEnabled] ? PR_TRUE : PR_FALSE;
|
||||
*aState = mIsEnabled;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsNativeScrollbar::UpdateScroller()
|
||||
{
|
||||
// Update the current value based on the new range. We need to recompute the
|
||||
// float value in case we had to set the value to 0 because gecko cheated
|
||||
// and set the position before it set the max value.
|
||||
float knobProp = 1.0f;
|
||||
if ((mVisibleImageSize + mMaxValue) > 0)
|
||||
knobProp = (float)mVisibleImageSize / (float)(mVisibleImageSize + mMaxValue);
|
||||
[mView setFloatValue:(mValue / (float)mMaxValue) knobProportion:knobProp];
|
||||
|
||||
BOOL enableScrollbar = (mIsEnabled && (mMaxValue > 0));
|
||||
[mView setEnabled:enableScrollbar];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -174,15 +174,11 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
|
||||
}
|
||||
|
||||
// update hilite
|
||||
PRInt16 hilite;
|
||||
if (mEnabled)
|
||||
hilite = (mWidgetArmed && mMouseInButton ? 1 : 0);
|
||||
else
|
||||
hilite = kControlInactivePart;
|
||||
if (hilite != mLastHilite)
|
||||
PRInt16 curHilite = GetControlHiliteState();
|
||||
if (curHilite != mLastHilite)
|
||||
{
|
||||
mLastHilite = hilite;
|
||||
::HiliteControl(mControl, hilite);
|
||||
mLastHilite = curHilite;
|
||||
::HiliteControl(mControl, curHilite);
|
||||
}
|
||||
|
||||
::SetControlVisibility(mControl, isVisible, false);
|
||||
@@ -321,6 +317,23 @@ void nsMacControl::GetRectForMacControl(nsRect &outRect)
|
||||
outRect.x = outRect.y = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get the current hilite state of the control
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
ControlPartCode nsMacControl::GetControlHiliteState()
|
||||
{
|
||||
// update hilite
|
||||
PRInt16 curHilite;
|
||||
if (mEnabled)
|
||||
curHilite = (mWidgetArmed && mMouseInButton ? 1 : 0);
|
||||
else
|
||||
curHilite = kControlInactivePart;
|
||||
|
||||
return curHilite;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
|
||||
@@ -81,6 +81,8 @@ protected:
|
||||
|
||||
NS_METHOD CreateOrReplaceMacControl(short inControlType);
|
||||
virtual void GetRectForMacControl(nsRect &outRect);
|
||||
virtual ControlPartCode GetControlHiliteState();
|
||||
|
||||
void SetupMacControlFont();
|
||||
void ControlChanged(PRInt32 aNewValue);
|
||||
void NSStringSetControlTitle(ControlHandle theControl, nsString title);
|
||||
|
||||
@@ -84,10 +84,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
static ControlActionUPP ScrollbarActionProc ( );
|
||||
|
||||
static ControlActionUPP
|
||||
ScrollbarActionProc ( )
|
||||
ScrollbarActionProc( )
|
||||
{
|
||||
static StNativeControlActionProcOwner sActionProcOwner;
|
||||
return sActionProcOwner.ActionProc();
|
||||
@@ -107,6 +105,8 @@ nsNativeScrollbar::nsNativeScrollbar()
|
||||
, mMouseDownInScroll(PR_FALSE)
|
||||
, mClickedPartCode(0)
|
||||
{
|
||||
mMax = 0; // override the base class default
|
||||
|
||||
WIDGET_SET_CLASSNAME("nsNativeScrollbar");
|
||||
SetControlType(kControlScrollBarLiveProc);
|
||||
}
|
||||
@@ -224,13 +224,13 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part)
|
||||
}
|
||||
EndDraw();
|
||||
|
||||
// update the area of the parent uncovered by the scrolling. Since
|
||||
// we may be in a tight loop, we need to manually validate the area
|
||||
// we just updated so the update rect doesn't continue to get bigger
|
||||
// and bigger the more we scroll.
|
||||
nsCOMPtr<nsIWidget> parent ( dont_AddRef(GetParent()) );
|
||||
parent->Update();
|
||||
parent->Validate();
|
||||
// update the area of the parent uncovered by the scrolling. Since
|
||||
// we may be in a tight loop, we need to manually validate the area
|
||||
// we just updated so the update rect doesn't continue to get bigger
|
||||
// and bigger the more we scroll.
|
||||
nsCOMPtr<nsIWidget> parent ( dont_AddRef(GetParent()) );
|
||||
parent->Update();
|
||||
parent->Validate();
|
||||
|
||||
StartDraw();
|
||||
}
|
||||
@@ -259,6 +259,20 @@ nsNativeScrollbar::UpdateContentPosition(PRUint32 inNewPos)
|
||||
SetPosition(inNewPos);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get the current hilite state of the control (disables the scrollbar
|
||||
// if there is nowhere to scroll)
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
ControlPartCode
|
||||
nsNativeScrollbar::GetControlHiliteState()
|
||||
{
|
||||
if (mMaxValue == 0)
|
||||
return kControlInactivePart;
|
||||
|
||||
return Inherited::GetControlHiliteState();
|
||||
}
|
||||
|
||||
/**-------------------------------------------------------------------------------
|
||||
* DispatchMouseEvent handle an event for this scrollbar
|
||||
@@ -352,7 +366,11 @@ nsNativeScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent)
|
||||
NS_IMETHODIMP
|
||||
nsNativeScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||
{
|
||||
mMaxValue = ((int)aEndRange) > 0 ? aEndRange : 10;
|
||||
if ((PRInt32)aEndRange < 0)
|
||||
aEndRange = 0;
|
||||
|
||||
mMaxValue = aEndRange;
|
||||
|
||||
if ( GetControl() ) {
|
||||
StartDraw();
|
||||
::SetControl32BitMaximum(GetControl(), mMaxValue);
|
||||
@@ -430,8 +448,11 @@ nsNativeScrollbar::GetPosition(PRUint32* aPos)
|
||||
NS_IMETHODIMP
|
||||
nsNativeScrollbar::SetViewSize(PRUint32 aSize)
|
||||
{
|
||||
mVisibleImageSize = ((int)aSize) > 0 ? aSize : 1;
|
||||
|
||||
if ((PRInt32)aSize < 0)
|
||||
aSize = 0;
|
||||
|
||||
mVisibleImageSize = aSize;
|
||||
|
||||
if ( GetControl() ) {
|
||||
StartDraw();
|
||||
SetControlViewSize(GetControl(), mVisibleImageSize);
|
||||
|
||||
@@ -72,8 +72,10 @@ protected:
|
||||
// nsWindow Interface
|
||||
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
|
||||
|
||||
ControlHandle GetControl() { return mControl; }
|
||||
virtual ControlPartCode GetControlHiliteState();
|
||||
|
||||
ControlHandle GetControl() { return mControl; }
|
||||
|
||||
void UpdateContentPosition(PRUint32 inNewPos);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user