summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles/mac/qmacstyle_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/styles/mac/qmacstyle_mac.mm')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm89
1 files changed, 46 insertions, 43 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 45da5fbd84..dd7959f3cf 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -143,22 +143,12 @@ static QWindow *qt_getWindow(const QWidget *widget)
return widget ? widget->window()->windowHandle() : 0;
}
-@interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject {
-QMacStylePrivate *mPrivate;
-}
-- (id)initWithPrivate:(QMacStylePrivate *)priv;
-- (void)scrollBarStyleDidChange:(NSNotification *)notification;
+@interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject
@end
QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver);
@implementation NotificationReceiver
-- (id)initWithPrivate:(QMacStylePrivate *)priv
-{
- self = [super init];
- mPrivate = priv;
- return self;
-}
- (void)scrollBarStyleDidChange:(NSNotification *)notification
{
@@ -1880,20 +1870,46 @@ NSCell *QMacStylePrivate::cocoaCell(CocoaControl widget) const
return cell;
}
-void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &qtRect, QPainter *p,
+void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p,
__attribute__((noescape)) DrawRectBlock drawRectBlock) const
{
QMacCGContext ctx(p);
setupNSGraphicsContext(ctx, YES);
- const CGRect rect = qtRect.toCGRect();
+ // FIXME: The rect that we get in is relative to the widget that we're drawing
+ // style on behalf of, and doesn't take into account the offset of that widget
+ // to the widget that owns the backingstore, which we are placing the native
+ // view into below. This means most of the views are placed in the upper left
+ // corner of backingStoreNSView, which does not map to where the actual widget
+ // is, and which may cause problems such as triggering a setNeedsDisplay of the
+ // backingStoreNSView for the wrong rect. We work around this by making the view
+ // layer-backed, which prevents triggering display of the backingStoreNSView, but
+ // but there may be other issues lurking here due to the wrong position. QTBUG-68023
+ view.wantsLayer = YES;
+
+ // FIXME: We are also setting the frame of the incoming view a lot at the call
+ // sites of this function, making it unclear who's actually responsible for
+ // maintaining the size and position of the view. In theory the call sites
+ // should ensure the _size_ of the view is correct, and then let this code
+ // take care of _positioning_ the view at the right place inside backingStoreNSView.
+ // For now we pass on the rect as is, to prevent any regressions until this
+ // can be investigated properly.
+ view.frame = rect.toCGRect();
[backingStoreNSView addSubview:view];
- view.frame = rect;
+
+ // FIXME: Based on the code below, this method isn't drawing an NSView into
+ // a rect, it's drawing _part of the NSView_, defined by the incoming clip
+ // or dirty rect, into the current graphics context. We're doing some manual
+ // translations at the call sites that would indicate that this relationship
+ // is a bit fuzzy.
+ const CGRect dirtyRect = rect.toCGRect();
+
if (drawRectBlock)
- drawRectBlock(ctx, rect);
+ drawRectBlock(ctx, dirtyRect);
else
- [view drawRect:rect];
+ [view drawRect:dirtyRect];
+
[view removeFromSuperviewWithoutNeedingDisplay];
restoreNSGraphicsContext(ctx);
@@ -1910,7 +1926,7 @@ QMacStyle::QMacStyle()
Q_D(QMacStyle);
QMacAutoReleasePool pool;
- d->receiver = [[NotificationReceiver alloc] initWithPrivate:d];
+ d->receiver = [[NotificationReceiver alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:d->receiver
selector:@selector(scrollBarStyleDidChange:)
name:NSPreferredScrollerStyleDidChangeNotification
@@ -2794,8 +2810,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
{
Q_D(const QMacStyle);
QMacCGContext cg(p);
- QWindow *window = w && w->window() ? w->window()->windowHandle() :
- QStyleHelper::styleObjectWindow(opt->styleObject);
+ QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);
switch (pe) {
case PE_IndicatorArrowUp:
@@ -3110,8 +3125,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
tf.bezeled = YES;
static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
tf.frame = opt->rect.toCGRect();
- d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
- Q_UNUSED(ctx);
+ d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef, const CGRect &rect) {
[tf.cell drawWithFrame:rect inView:tf];
});
} else {
@@ -3240,8 +3254,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
{
Q_D(const QMacStyle);
QMacCGContext cg(p);
- QWindow *window = w && w->window() ? w->window()->windowHandle() :
- QStyleHelper::styleObjectWindow(opt->styleObject);
+ QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);
switch (ce) {
case CE_HeaderSection:
@@ -3442,7 +3455,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
pb.enabled = isEnabled;
[pb highlight:isPressed];
pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState;
- d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) {
+ d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) {
[pb.cell drawBezelWithFrame:r inView:pb.superview];
});
[pb highlight:NO];
@@ -4184,7 +4197,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
auto *sv = static_cast<NSSplitView *>(d->cocoaControl(cw));
sv.frame = opt->rect.toCGRect();
- d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef __unused ctx, const CGRect &rect) {
+ d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef, const CGRect &rect) {
[sv drawDividerInRect:rect];
});
} else {
@@ -4815,8 +4828,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
{
Q_D(const QMacStyle);
QMacCGContext cg(p);
- QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
- QStyleHelper::styleObjectWindow(opt->styleObject);
+ QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);
switch (cc) {
case CC_ScrollBar:
@@ -5191,7 +5203,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
}
pb.frame = frameRect.toCGRect();
[pb highlight:isPressed];
- d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) {
+ d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) {
[pb.cell drawBezelWithFrame:r inView:pb.superview];
});
} else if (cw.type == QMacStylePrivate::ComboBox) {
@@ -5207,7 +5219,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
// TODO Render to pixmap and darken the button manually
}
- d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef __unused ctx, const CGRect &r) {
+ d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef, const CGRect &r) {
// FIXME This is usually drawn in the control's superview, but we wouldn't get inactive look in this case
[cb.cell drawWithFrame:r inView:cb];
});
@@ -5279,13 +5291,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
Q_UNUSED(isHovered); // FIXME No public API for this
const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
- const auto drawBlock = ^ (CGContextRef ctx, const CGRect &rect) {
- Q_UNUSED(ctx);
- Q_UNUSED(rect);
+ d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef, const CGRect &rect) {
auto *wbCell = static_cast<NSButtonCell *>(wb.cell);
[wbCell drawWithFrame:rect inView:wb];
- };
- d->drawNSViewInRect(wb, buttonRect, p, drawBlock);
+ });
}
}
@@ -5350,12 +5359,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
d->drawToolbarButtonArrow(tb, p);
}
if (tb->state & State_On) {
- QWindow *window = 0;
- if (widget && widget->window())
- window = widget->window()->windowHandle();
- else if (opt->styleObject)
- window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>();
-
NSView *view = window ? (NSView *)window->winId() : nil;
bool isKey = false;
if (view)
@@ -5394,8 +5397,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
pb.enabled = isEnabled;
[pb highlight:isPressed];
pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState;
- const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
- d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef __unused ctx, const CGRect &rect) {
+ const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
+ d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef, const CGRect &rect) {
[pb.cell drawBezelWithFrame:rect inView:pb];
});
}
@@ -5878,7 +5881,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
switch (ct) {
#if QT_CONFIG(spinbox)
case CT_SpinBox:
- if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
+ if (qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
const int buttonWidth = 20; // FIXME Use subControlRect()
sz += QSize(buttonWidth, 0);
}