macOS: Don't assume NSSlider is never flipped

We need to take into account the possibility that the slider is flipped,
otherwise we end up with inverted rects, as noticed in Big Sur.

The logic to use the ticks as input to whether the bar rect should be
inverted didn't make sense.  If the graphics context has been flipped,
then we should reflect that through the slider.

Change-Id: I3574027c14807460affb42a9763211981c4ed528
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit e4f647e2720612d030e4a2240a00500054bbda99)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2020-09-22 18:14:04 +02:00 committed by Qt Cherry-pick Bot
parent 92fe1eba0a
commit 1c4e727c52

View File

@ -530,7 +530,7 @@ static void fixStaleGeometry(NSSlider *slider)
return; return;
NSSliderCell *cell = slider.cell; NSSliderCell *cell = slider.cell;
const NSRect barRect = [cell barRectFlipped:NO]; const NSRect barRect = [cell barRectFlipped:slider.isFlipped];
const NSSize sliderSize = slider.frame.size; const NSSize sliderSize = slider.frame.size;
CGFloat difference = 0.; CGFloat difference = 0.;
if (slider.vertical) if (slider.vertical)
@ -5310,7 +5310,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
CGPoint pressPoint; CGPoint pressPoint;
if (isPressed) { if (isPressed) {
const CGRect knobRect = [slider.cell knobRectFlipped:NO]; const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
pressPoint.x = CGRectGetMidX(knobRect); pressPoint.x = CGRectGetMidX(knobRect);
pressPoint.y = CGRectGetMidY(knobRect); pressPoint.y = CGRectGetMidY(knobRect);
[slider.cell startTrackingAt:pressPoint inView:slider]; [slider.cell startTrackingAt:pressPoint inView:slider];
@ -5361,7 +5361,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
if (hasDoubleTicks) if (hasDoubleTicks)
slider.numberOfTickMarks = 0; slider.numberOfTickMarks = 0;
const CGRect barRect = [cell barRectFlipped:hasTicks]; const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
if (drawBar) { if (drawBar) {
[cell drawBarInside:barRect flipped:!verticalFlip]; [cell drawBarInside:barRect flipped:!verticalFlip];
// This ain't HIG kosher: force unfilled bar look. // This ain't HIG kosher: force unfilled bar look.
@ -5742,8 +5742,8 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc,
[slider calcSize]; [slider calcSize];
NSSliderCell *cell = slider.cell; NSSliderCell *cell = slider.cell;
const auto barRect = QRectF::fromCGRect([cell barRectFlipped:hasTicks]); const auto barRect = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]);
const auto knobRect = QRectF::fromCGRect([cell knobRectFlipped:NO]); const auto knobRect = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]);
if (knobRect.contains(pt)) { if (knobRect.contains(pt)) {
sc = SC_SliderHandle; sc = SC_SliderHandle;
} else if (barRect.contains(pt)) { } else if (barRect.contains(pt)) {
@ -5848,7 +5848,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
[slider calcSize]; [slider calcSize];
NSSliderCell *cell = slider.cell; NSSliderCell *cell = slider.cell;
if (sc == SC_SliderHandle) { if (sc == SC_SliderHandle) {
ret = QRectF::fromCGRect([cell knobRectFlipped:NO]).toRect(); ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
if (isHorizontal) { if (isHorizontal) {
ret.setTop(sl->rect.top()); ret.setTop(sl->rect.top());
ret.setBottom(sl->rect.bottom()); ret.setBottom(sl->rect.bottom());
@ -5857,7 +5857,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
ret.setRight(sl->rect.right()); ret.setRight(sl->rect.right());
} }
} else if (sc == SC_SliderGroove) { } else if (sc == SC_SliderGroove) {
ret = QRectF::fromCGRect([cell barRectFlipped:hasTicks]).toRect(); ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
} else if (hasTicks && sc == SC_SliderTickmarks) { } else if (hasTicks && sc == SC_SliderTickmarks) {
const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]); const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
if (isHorizontal) if (isHorizontal)