Ensure compatibility with OS X 10.7's arrowless scrollbar. r=mstange

This commit is contained in:
Steven Michaud 2011-05-16 12:56:03 -05:00
Родитель c4246ec726
Коммит 0134af60ca
5 изменённых файлов: 50 добавлений и 33 удалений

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

@ -43,10 +43,10 @@
// for |#ifdef NS_DEBUG|
struct nsSize;
// 2e89c566-0a31-4c93-bdff-222651df45a0
// 89401022-94b3-413e-a6b8-2203dab824f3
#define NS_ILOOKANDFEEL_IID \
{ 0x2e89c566, 0x0a31, 0x4c93, \
{ 0xbd, 0xff, 0x22, 0x26, 0x51, 0xdf, 0x45, 0xa0 } }
{ 0x89401022, 0x94b3, 0x413e, \
{ 0xa6, 0xb8, 0x22, 0x03, 0xda, 0xb8, 0x24, 0xf3 } }
class nsILookAndFeel: public nsISupports {
public:
@ -326,6 +326,7 @@ public:
};
enum {
eMetric_ScrollArrowNone = 0,
eMetric_ScrollArrowStartBackward = 0x1000,
eMetric_ScrollArrowStartForward = 0x0100,
eMetric_ScrollArrowEndBackward = 0x0010,

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

@ -343,22 +343,25 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
aMetric = 4;
break;
case eMetric_ScrollArrowStyle:
{
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
if ([buttonPlacement isEqualToString:@"Single"]) {
aMetric = eMetric_ScrollArrowStyleSingle;
} else if ([buttonPlacement isEqualToString:@"DoubleMin"]) {
aMetric = eMetric_ScrollArrowStyleBothAtTop;
} else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) {
aMetric = eMetric_ScrollArrowStyleBothAtEachEnd;
if (nsToolkit::OnLionOrLater()) {
// OS X Lion's scrollbars have no arrows
aMetric = eMetric_ScrollArrowNone;
} else {
aMetric = eMetric_ScrollArrowStyleBothAtBottom; // The default is BothAtBottom.
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
if ([buttonPlacement isEqualToString:@"Single"]) {
aMetric = eMetric_ScrollArrowStyleSingle;
} else if ([buttonPlacement isEqualToString:@"DoubleMin"]) {
aMetric = eMetric_ScrollArrowStyleBothAtTop;
} else if ([buttonPlacement isEqualToString:@"DoubleBoth"]) {
aMetric = eMetric_ScrollArrowStyleBothAtEachEnd;
} else {
aMetric = eMetric_ScrollArrowStyleBothAtBottom; // The default is BothAtBottom.
}
}
}
break;
break;
case eMetric_ScrollSliderStyle:
aMetric = eMetric_ScrollThumbStyleProportional;
break;
aMetric = eMetric_ScrollThumbStyleProportional;
break;
case eMetric_TreeOpenDelay:
aMetric = 1000;
break;

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

@ -1428,9 +1428,12 @@ nsNativeThemeCocoa::GetScrollbarDrawInfo(HIThemeTrackDrawInfo& aTdi, nsIFrame *a
aTdi.trackInfo.scrollbar.pressState = 0;
// Only go get these scrollbar button states if we need it. For example, there's no reaon to look up scrollbar button
// states when we're only creating a TrackDrawInfo to determine the size of the thumb.
if (aShouldGetButtonStates) {
// Only go get these scrollbar button states if we need it. For example,
// there's no reason to look up scrollbar button states when we're only
// creating a TrackDrawInfo to determine the size of the thumb. There's
// also no reason to do this on Lion or later, whose scrollbars have no
// arrow buttons.
if (aShouldGetButtonStates && !nsToolkit::OnLionOrLater()) {
nsEventStates buttonStates[4];
GetScrollbarPressStates(aFrame, buttonStates);
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
@ -2155,23 +2158,26 @@ nsNativeThemeCocoa::GetWidgetBorder(nsDeviceContext* aContext,
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
{
// There's only an endcap to worry about when both arrows are on the bottom
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
if (!buttonPlacement || [buttonPlacement isEqualToString:@"DoubleMax"]) {
PRBool isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
// On Lion and later, scrollbars have no arrows.
if (!nsToolkit::OnLionOrLater()) {
// There's only an endcap to worry about when both arrows are on the bottom
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
if (!buttonPlacement || [buttonPlacement isEqualToString:@"DoubleMax"]) {
PRBool isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame) return NS_ERROR_FAILURE;
PRBool isSmall = (scrollbarFrame->GetStyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
if (!scrollbarFrame) return NS_ERROR_FAILURE;
PRBool isSmall = (scrollbarFrame->GetStyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
// There isn't a metric for this, so just hardcode a best guess at the value.
// This value is even less exact due to the fact that the endcap is partially concave.
PRInt32 endcapSize = isSmall ? 5 : 6;
// There isn't a metric for this, so just hardcode a best guess at the value.
// This value is even less exact due to the fact that the endcap is partially concave.
PRInt32 endcapSize = isSmall ? 5 : 6;
if (isHorizontal)
aResult->SizeTo(endcapSize, 0, 0, 0);
else
aResult->SizeTo(0, endcapSize, 0, 0);
if (isHorizontal)
aResult->SizeTo(endcapSize, 0, 0, 0);
else
aResult->SizeTo(0, endcapSize, 0, 0);
}
}
break;
}

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

@ -48,6 +48,7 @@
#define MAC_OS_X_VERSION_10_5_HEX 0x00001050
#define MAC_OS_X_VERSION_10_6_HEX 0x00001060
#define MAC_OS_X_VERSION_10_7_HEX 0x00001070
class nsToolkit : public nsIToolkit
{
@ -60,6 +61,7 @@ public:
static PRInt32 OSXVersion();
static PRBool OnSnowLeopardOrLater();
static PRBool OnLionOrLater();
static void PostSleepWakeNotification(const char* aNotification);

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

@ -407,6 +407,11 @@ PRBool nsToolkit::OnSnowLeopardOrLater()
return (OSXVersion() >= MAC_OS_X_VERSION_10_6_HEX);
}
PRBool nsToolkit::OnLionOrLater()
{
return (OSXVersion() >= MAC_OS_X_VERSION_10_7_HEX);
}
// An alternative to [NSObject poseAsClass:] that isn't deprecated on OS X
// Leopard and is available to 64-bit binaries on Leopard and above. Based on
// ideas and code from http://www.cocoadev.com/index.pl?MethodSwizzling.