macOS: Reduce usage of m_nsWindow in favor of isContentView()
The m_nsWindow member both indicates whether or not the QCocoaWindow represents the content view of a NSWindow, and provides access to that NSWindow. The former is better expressed through isContentView(), which allows us to then replace m_nsWindow entirely in a followup with access though m_view.window, removing the need to cache the NSWindow. Change-Id: I6e7de4b6d64b29fc9023222be045254f18be28cd Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>bb10
parent
4a5a4245b7
commit
7124096f2b
|
|
@ -279,9 +279,6 @@ public:
|
|||
Q_FLAG(RecreationReasons)
|
||||
|
||||
protected:
|
||||
bool isChildNSWindow() const;
|
||||
bool isContentView() const;
|
||||
|
||||
void foreachChildNSWindow(void (^block)(QCocoaWindow *));
|
||||
|
||||
void recreateWindowIfNeeded();
|
||||
|
|
@ -302,6 +299,9 @@ public: // for QNSView
|
|||
friend class QCocoaBackingStore;
|
||||
friend class QCocoaNativeInterface;
|
||||
|
||||
bool isContentView() const;
|
||||
bool isChildNSWindow() const;
|
||||
|
||||
void removeMonitor();
|
||||
|
||||
NSView *m_view;
|
||||
|
|
|
|||
|
|
@ -612,7 +612,7 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect)
|
|||
// call this here: updateGeometry in qnsview.mm is a no-op for this case
|
||||
QWindowSystemInterface::handleGeometryChange(window(), rect);
|
||||
QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), rect.size()));
|
||||
} else if (m_nsWindow) {
|
||||
} else if (isContentView()) {
|
||||
NSRect bounds = qt_mac_flipRect(rect);
|
||||
[m_nsWindow setFrame:[m_nsWindow frameRectForContentRect:bounds] display:YES animate:NO];
|
||||
} else {
|
||||
|
|
@ -761,7 +761,7 @@ void QCocoaWindow::setVisible(bool visible)
|
|||
// viewDidUnhide message.
|
||||
exposeWindow();
|
||||
|
||||
if (m_nsWindow) {
|
||||
if (isContentView()) {
|
||||
QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
|
||||
// setWindowState might have been called while the window was hidden and
|
||||
|
|
@ -829,7 +829,7 @@ void QCocoaWindow::setVisible(bool visible)
|
|||
QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = 0;
|
||||
if (cocoaEventDispatcher)
|
||||
cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
|
||||
if (m_nsWindow) {
|
||||
if (isContentView()) {
|
||||
if (m_hasModalSession) {
|
||||
if (cocoaEventDispatcherPrivate)
|
||||
cocoaEventDispatcherPrivate->endModalSession(window());
|
||||
|
|
@ -979,7 +979,7 @@ void QCocoaWindow::setWindowZoomButton(Qt::WindowFlags flags)
|
|||
|
||||
void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
|
||||
{
|
||||
if (m_nsWindow && !isChildNSWindow()) {
|
||||
if (isContentView() && !isChildNSWindow()) {
|
||||
NSUInteger styleMask = windowStyleMask(flags);
|
||||
NSInteger level = this->windowLevel(flags);
|
||||
// While setting style mask we can have -updateGeometry calls on a content
|
||||
|
|
@ -1008,7 +1008,7 @@ void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags)
|
|||
setWindowZoomButton(flags);
|
||||
}
|
||||
|
||||
if (m_nsWindow)
|
||||
if (isContentView())
|
||||
m_nsWindow.ignoresMouseEvents = flags & Qt::WindowTransparentForInput;
|
||||
|
||||
m_windowFlags = flags;
|
||||
|
|
@ -1023,7 +1023,7 @@ void QCocoaWindow::setWindowState(Qt::WindowStates state)
|
|||
void QCocoaWindow::setWindowTitle(const QString &title)
|
||||
{
|
||||
QMacAutoReleasePool pool;
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
CFStringRef windowTitle = title.toCFString();
|
||||
|
|
@ -1034,7 +1034,7 @@ void QCocoaWindow::setWindowTitle(const QString &title)
|
|||
void QCocoaWindow::setWindowFilePath(const QString &filePath)
|
||||
{
|
||||
QMacAutoReleasePool pool;
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
QFileInfo fi(filePath);
|
||||
|
|
@ -1084,12 +1084,12 @@ void QCocoaWindow::raise()
|
|||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::raise" << window();
|
||||
|
||||
// ### handle spaces (see Qt 4 raise_sys in qwidget_mac.mm)
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
if (isChildNSWindow()) {
|
||||
if (m_hiddenByClipping)
|
||||
return;
|
||||
}
|
||||
|
||||
if (isChildNSWindow() && m_hiddenByClipping)
|
||||
return;
|
||||
|
||||
if ([m_nsWindow isVisible]) {
|
||||
if (isChildNSWindow()) {
|
||||
// -[NSWindow orderFront:] doesn't work with attached windows.
|
||||
|
|
@ -1119,12 +1119,12 @@ void QCocoaWindow::raise()
|
|||
void QCocoaWindow::lower()
|
||||
{
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::lower" << window();
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
if (isChildNSWindow()) {
|
||||
if (m_hiddenByClipping)
|
||||
return;
|
||||
}
|
||||
|
||||
if (isChildNSWindow() && m_hiddenByClipping)
|
||||
return;
|
||||
|
||||
if ([m_nsWindow isVisible]) {
|
||||
if (isChildNSWindow()) {
|
||||
// -[NSWindow orderBack:] doesn't work with attached windows.
|
||||
|
|
@ -1165,7 +1165,7 @@ bool QCocoaWindow::isOpaque() const
|
|||
void QCocoaWindow::propagateSizeHints()
|
||||
{
|
||||
QMacAutoReleasePool pool;
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::propagateSizeHints" << window() << "\n"
|
||||
|
|
@ -1204,16 +1204,17 @@ void QCocoaWindow::propagateSizeHints()
|
|||
void QCocoaWindow::setOpacity(qreal level)
|
||||
{
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setOpacity" << level;
|
||||
if (m_nsWindow) {
|
||||
[m_nsWindow setAlphaValue:level];
|
||||
[m_nsWindow setOpaque: isOpaque()];
|
||||
}
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
[m_nsWindow setAlphaValue:level];
|
||||
[m_nsWindow setOpaque:isOpaque()];
|
||||
}
|
||||
|
||||
void QCocoaWindow::setMask(const QRegion ®ion)
|
||||
{
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setMask" << window() << region;
|
||||
if (m_nsWindow)
|
||||
if (isContentView())
|
||||
[m_nsWindow setBackgroundColor:[NSColor clearColor]];
|
||||
|
||||
[qnsview_cast(m_view) setMaskRegion:®ion];
|
||||
|
|
@ -1223,7 +1224,7 @@ void QCocoaWindow::setMask(const QRegion ®ion)
|
|||
bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
|
||||
{
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setKeyboardGrabEnabled" << window() << grab;
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return false;
|
||||
|
||||
if (grab && ![m_nsWindow isKeyWindow])
|
||||
|
|
@ -1235,7 +1236,7 @@ bool QCocoaWindow::setKeyboardGrabEnabled(bool grab)
|
|||
bool QCocoaWindow::setMouseGrabEnabled(bool grab)
|
||||
{
|
||||
qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::setMouseGrabEnabled" << window() << grab;
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return false;
|
||||
|
||||
if (grab && ![m_nsWindow isKeyWindow])
|
||||
|
|
@ -1300,7 +1301,7 @@ void QCocoaWindow::windowDidMove()
|
|||
|
||||
void QCocoaWindow::windowDidResize()
|
||||
{
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
if (isChildNSWindow())
|
||||
|
|
@ -1808,7 +1809,7 @@ void QCocoaWindow::removeMonitor()
|
|||
// Returns the current global screen geometry for the nswindow associated with this window.
|
||||
QRect QCocoaWindow::nativeWindowGeometry() const
|
||||
{
|
||||
if (!m_nsWindow || isChildNSWindow())
|
||||
if (!isContentView() || isChildNSWindow())
|
||||
return geometry();
|
||||
|
||||
NSRect rect = [m_nsWindow frame];
|
||||
|
|
@ -1833,7 +1834,7 @@ void QCocoaWindow::applyWindowState(Qt::WindowStates requestedState)
|
|||
if (newState == currentState)
|
||||
return;
|
||||
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
const NSSize contentSize = m_view.frame.size;
|
||||
|
|
@ -1957,8 +1958,9 @@ void QCocoaWindow::reportCurrentWindowState(bool unconditionally)
|
|||
|
||||
bool QCocoaWindow::setWindowModified(bool modified)
|
||||
{
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return false;
|
||||
|
||||
[m_nsWindow setDocumentEdited:(modified?YES:NO)];
|
||||
return true;
|
||||
}
|
||||
|
|
@ -2101,7 +2103,7 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
|
|||
|
||||
void QCocoaWindow::updateNSToolbar()
|
||||
{
|
||||
if (!m_nsWindow)
|
||||
if (!isContentView())
|
||||
return;
|
||||
|
||||
NSToolbar *toolbar = QCocoaIntegration::instance()->toolbar(window());
|
||||
|
|
@ -2115,7 +2117,7 @@ void QCocoaWindow::updateNSToolbar()
|
|||
|
||||
bool QCocoaWindow::testContentBorderAreaPosition(int position) const
|
||||
{
|
||||
return m_nsWindow && m_drawContentBorderGradient &&
|
||||
return isContentView() && m_drawContentBorderGradient &&
|
||||
0 <= position && position < [m_nsWindow contentBorderThicknessForEdge: NSMaxYEdge];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
qDebug() << "geometry" << geometry;
|
||||
#endif
|
||||
//geometry = QRect(screenRect.origin.x, qt_mac_flipYCoordinate(screenRect.origin.y + screenRect.size.height), screenRect.size.width, screenRect.size.height);
|
||||
} else if (m_platformWindow->m_nsWindow) {
|
||||
} else if (m_platformWindow->isContentView()) {
|
||||
// top level window, get window rect and flip y.
|
||||
NSRect rect = [self frame];
|
||||
NSRect windowRect = [[self window] frame];
|
||||
|
|
@ -309,7 +309,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
geometry = QRectF::fromCGRect(NSRectToCGRect([self frame])).toRect();
|
||||
}
|
||||
|
||||
if (m_platformWindow->m_nsWindow && geometry == m_platformWindow->geometry())
|
||||
if (m_platformWindow->isContentView() && geometry == m_platformWindow->geometry())
|
||||
return;
|
||||
|
||||
const bool isResize = geometry.size() != m_platformWindow->geometry().size();
|
||||
|
|
@ -431,8 +431,8 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
|
||||
- (void)invalidateWindowShadowIfNeeded
|
||||
{
|
||||
if (m_shouldInvalidateWindowShadow && m_platformWindow->m_nsWindow) {
|
||||
[m_platformWindow->m_nsWindow invalidateShadow];
|
||||
if (m_shouldInvalidateWindowShadow && m_platformWindow->isContentView()) {
|
||||
[m_platformWindow->nativeWindow() invalidateShadow];
|
||||
m_shouldInvalidateWindowShadow = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -507,7 +507,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
// Optimization: Copy frame buffer content instead of blending for
|
||||
// top-level windows where Qt fills the entire window content area.
|
||||
// (But don't overpaint the title-bar gradient)
|
||||
if (m_platformWindow->m_nsWindow && !m_platformWindow->m_drawContentBorderGradient)
|
||||
if (m_platformWindow->isContentView() && !m_platformWindow->m_drawContentBorderGradient)
|
||||
CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
|
||||
|
||||
CGContextDrawImage(cgContext, dirtyWindowRect, cleanImg);
|
||||
|
|
@ -971,7 +971,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
// the time of the leave. This is dificult to accomplish by
|
||||
// handling mouseEnter and mouseLeave envents, since they are sent
|
||||
// individually to different views.
|
||||
if (m_platformWindow->m_nsWindow && childWindow) {
|
||||
if (m_platformWindow->isContentView() && childWindow) {
|
||||
if (childWindow != m_platformWindow->m_enterLeaveTargetWindow) {
|
||||
QWindowSystemInterface::handleEnterLeaveEvent(childWindow, m_platformWindow->m_enterLeaveTargetWindow, windowPoint, screenPoint);
|
||||
m_platformWindow->m_enterLeaveTargetWindow = childWindow;
|
||||
|
|
@ -998,7 +998,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
return;
|
||||
|
||||
// Top-level windows generate enter events for sub-windows.
|
||||
if (!m_platformWindow->m_nsWindow)
|
||||
if (!m_platformWindow->isContentView())
|
||||
return;
|
||||
|
||||
QPointF windowPoint;
|
||||
|
|
@ -1020,7 +1020,7 @@ static bool _q_dontOverrideCtrlLMB = false;
|
|||
return;
|
||||
|
||||
// Top-level windows generate leave events for sub-windows.
|
||||
if (!m_platformWindow->m_nsWindow)
|
||||
if (!m_platformWindow->isContentView())
|
||||
return;
|
||||
|
||||
QWindowSystemInterface::handleLeaveEvent(m_platformWindow->m_enterLeaveTargetWindow);
|
||||
|
|
|
|||
Loading…
Reference in New Issue