Bug 1016569 - For 10.7 non-overlay scrollbars, draw the scrollbar track and the scrollbar thumb separately. r=smichaud

This commit is contained in:
Markus Stange 2014-05-28 15:22:16 +02:00
parent f8ea5472ea
commit c6f0165d4f
3 changed files with 53 additions and 35 deletions

View File

@ -17,7 +17,7 @@ random-if(d2d) == element-paint-transform-02.html element-paint-transform-02-ref
== element-paint-background-size-02.html element-paint-background-size-02-ref.html
== element-paint-transform-repeated.html element-paint-transform-repeated-ref.html
fuzzy-if(d2d,255,24) == element-paint-transform-03.html element-paint-transform-03-ref.html
fuzzy-if(gtk2Widget,1,32) == element-paint-native-widget.html element-paint-native-widget-ref.html
fuzzy-if(gtk2Widget,1,32) fuzzy-if(cocoaWidget,1,106) == element-paint-native-widget.html element-paint-native-widget-ref.html
== element-paint-subimage-sampling-restriction.html about:blank
== element-paint-clippath.html element-paint-clippath-ref.html
== element-paint-sharpness-01a.html element-paint-sharpness-01b.html

View File

@ -129,6 +129,7 @@ protected:
void GetScrollbarDrawInfo (HIThemeTrackDrawInfo& aTdi, nsIFrame *aFrame,
const CGSize& aSize, bool aShouldGetButtonStates);
nsIFrame* GetParentScrollbarFrame(nsIFrame *aFrame);
bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
private:
NSButtonCell* mHelpButtonCell;

View File

@ -2068,6 +2068,21 @@ nsNativeThemeCocoa::DrawResizer(CGContextRef cgContext, const HIRect& aRect,
NS_OBJC_END_TRY_ABORT_BLOCK;
}
static bool
ScrollbarTrackAndThumbDrawSeparately()
{
return nsLookAndFeel::UseOverlayScrollbars() || nsCocoaFeatures::OnLionOrLater();
}
bool
nsNativeThemeCocoa::IsParentScrollbarRolledOver(nsIFrame* aFrame)
{
nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
return nsLookAndFeel::UseOverlayScrollbars()
? CheckBooleanAttr(scrollbarFrame, nsGkAtoms::hover)
: GetContentState(scrollbarFrame, NS_THEME_NONE).HasState(NS_EVENT_STATE_HOVER);
}
static bool
IsHiDPIContext(nsDeviceContext* aContext)
{
@ -2507,17 +2522,17 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
case NS_THEME_SCROLLBAR_SMALL:
case NS_THEME_SCROLLBAR:
if (!nsLookAndFeel::UseOverlayScrollbars()) {
if (!ScrollbarTrackAndThumbDrawSeparately()) {
DrawScrollbar(cgContext, macRect, aFrame);
}
break;
case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
if (nsLookAndFeel::UseOverlayScrollbars()) {
if (ScrollbarTrackAndThumbDrawSeparately()) {
BOOL isOverlay = nsLookAndFeel::UseOverlayScrollbars();
BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_THUMB_HORIZONTAL);
BOOL isRolledOver = CheckBooleanAttr(GetParentScrollbarFrame(aFrame),
nsGkAtoms::hover);
if (!nsCocoaFeatures::OnMountainLionOrLater() || !isRolledOver) {
BOOL isRolledOver = IsParentScrollbarRolledOver(aFrame);
if (isOverlay && (!nsCocoaFeatures::OnMountainLionOrLater() || !isRolledOver)) {
if (isHorizontal) {
macRect.origin.y += 4;
macRect.size.height -= 4;
@ -2532,9 +2547,9 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
CUIDraw([NSWindow coreUIRenderer], macRect, cgContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
@"kCUIWidgetOverlayScrollBar", @"widget",
(isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
@"regular", @"size",
(isRolledOver ? @"rollover" : @""), @"state",
(isRolledOver ? @"rollover" : @"normal"), @"state",
(isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
(isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
[NSNumber numberWithBool:YES], @"indiconly",
@ -2560,35 +2575,37 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
break;
case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
if (nsLookAndFeel::UseOverlayScrollbars() &&
CheckBooleanAttr(GetParentScrollbarFrame(aFrame), nsGkAtoms::hover)) {
BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
if (!nsCocoaFeatures::OnMountainLionOrLater()) {
// On OSX 10.7, scrollbars don't grow when hovered. The adjustments
// below were obtained by trial and error.
if (isHorizontal) {
macRect.origin.y += 2.0;
} else {
if (aFrame->StyleVisibility()->mDirection !=
NS_STYLE_DIRECTION_RTL) {
macRect.origin.x += 3.0;
if (ScrollbarTrackAndThumbDrawSeparately()) {
BOOL isOverlay = nsLookAndFeel::UseOverlayScrollbars();
if (!isOverlay || IsParentScrollbarRolledOver(aFrame)) {
BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL);
if (isOverlay && !nsCocoaFeatures::OnMountainLionOrLater()) {
// On OSX 10.7, scrollbars don't grow when hovered.
// The adjustments below were obtained by trial and error.
if (isHorizontal) {
macRect.origin.y += 2.0;
} else {
macRect.origin.x -= 1.0;
if (aFrame->StyleVisibility()->mDirection !=
NS_STYLE_DIRECTION_RTL) {
macRect.origin.x += 3.0;
} else {
macRect.origin.x -= 1.0;
}
}
}
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
CUIDraw([NSWindow coreUIRenderer], macRect, cgContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
(isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
@"regular", @"size",
(isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
(isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
[NSNumber numberWithBool:YES], @"noindicator",
[NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
[NSNumber numberWithBool:YES], @"is.flipped",
nil],
nil);
}
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
CUIDraw([NSWindow coreUIRenderer], macRect, cgContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
@"kCUIWidgetOverlayScrollBar", @"widget",
@"regular", @"size",
(isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
(isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
[NSNumber numberWithBool:YES], @"noindicator",
[NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
[NSNumber numberWithBool:YES], @"is.flipped",
nil],
nil);
}
break;
@ -3235,12 +3252,12 @@ nsNativeThemeCocoa::WidgetStateChanged(nsIFrame* aFrame, uint8_t aWidgetType,
if ((aWidgetType == NS_THEME_SCROLLBAR ||
aWidgetType == NS_THEME_SCROLLBAR_SMALL) &&
!nsLookAndFeel::UseOverlayScrollbars() &&
!ScrollbarTrackAndThumbDrawSeparately() &&
(aAttribute == nsGkAtoms::curpos ||
aAttribute == nsGkAtoms::minpos ||
aAttribute == nsGkAtoms::maxpos ||
aAttribute == nsGkAtoms::pageincrement)) {
// Non-overlay scrollbars paint the thumb as part of the scrollbar,
// 10.6-style scrollbars paint the thumb as part of the scrollbar,
// so we need to invalidate the scrollbar when the thumb moves.
*aShouldRepaint = true;
}