0003-QPlatformWindow-Extract-static-method-for-closestAcc.patch 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 42c6ea4f6c29845d68e865b19a73a09cc6d0bdbe Mon Sep 17 00:00:00 2001
  2. From: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
  3. Date: Tue, 15 Sep 2015 12:12:51 +0200
  4. Subject: [PATCH] QPlatformWindow: Extract static method for
  5. closestAcceptableGeometry().
  6. On Windows, some messages occur before a QPlatformWindow is actually
  7. created, for example WM_WINDOWPOSCHANGING, which is handled in
  8. QWindowsWindow::handleGeometryChangingMessage().
  9. Extract a static function QPlatformWindow::closestAcceptableGeometry()
  10. from QPlatformWindow::windowClosestAcceptableGeometry() and use
  11. that in QWindowsWindow::handleGeometryChangingMessage().
  12. This fixes a regression crash occurring in Qt 5.6 when running
  13. the example from QTBUG-48201.
  14. Task-number: QTBUG-36220
  15. Task-number: QTBUG-48201
  16. Task-number: QTBUG-46615
  17. Change-Id: I86b8f923447c8e447382427cf5795628ef1c9717
  18. Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
  19. ---
  20. src/gui/kernel/qplatformwindow.cpp | 11 ++++++++---
  21. src/gui/kernel/qplatformwindow.h | 1 +
  22. src/plugins/platforms/windows/qwindowswindow.cpp | 2 +-
  23. 3 files changed, 10 insertions(+), 4 deletions(-)
  24. diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
  25. index 0430d5a..ea3b75c 100644
  26. --- a/src/gui/kernel/qplatformwindow.cpp
  27. +++ b/src/gui/kernel/qplatformwindow.cpp
  28. @@ -702,15 +702,20 @@ QRect QPlatformWindow::windowFrameGeometry() const
  29. a resize/move event for platforms that support it, for example to
  30. implement heightForWidth().
  31. */
  32. -QRectF QPlatformWindow::windowClosestAcceptableGeometry(const QRectF &nativeRect) const
  33. +
  34. +QRectF QPlatformWindow::closestAcceptableGeometry(const QWindow *qWindow, const QRectF &nativeRect)
  35. {
  36. - QWindow *qWindow = window();
  37. const QRectF rectF = QHighDpi::fromNativePixels(nativeRect, qWindow);
  38. - const QRectF correctedGeometryF = qt_window_private(qWindow)->closestAcceptableGeometry(rectF);
  39. + const QRectF correctedGeometryF = qt_window_private(const_cast<QWindow *>(qWindow))->closestAcceptableGeometry(rectF);
  40. return !correctedGeometryF.isEmpty() && rectF != correctedGeometryF
  41. ? QHighDpi::toNativePixels(correctedGeometryF, qWindow) : nativeRect;
  42. }
  43. +QRectF QPlatformWindow::windowClosestAcceptableGeometry(const QRectF &nativeRect) const
  44. +{
  45. + return QPlatformWindow::closestAcceptableGeometry(window(), nativeRect);
  46. +}
  47. +
  48. /*!
  49. \class QPlatformWindow
  50. \since 4.8
  51. diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h
  52. index 1b283db..9c28179 100644
  53. --- a/src/gui/kernel/qplatformwindow.h
  54. +++ b/src/gui/kernel/qplatformwindow.h
  55. @@ -140,6 +140,7 @@ public:
  56. QRect windowGeometry() const;
  57. QRect windowFrameGeometry() const;
  58. QRectF windowClosestAcceptableGeometry(const QRectF &nativeRect) const;
  59. + static QRectF closestAcceptableGeometry(const QWindow *w, const QRectF &nativeRect);
  60. protected:
  61. static QString formatWindowTitle(const QString &title, const QString &separator);
  62. diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
  63. index f9b3433..5318360 100644
  64. --- a/src/plugins/platforms/windows/qwindowswindow.cpp
  65. +++ b/src/plugins/platforms/windows/qwindowswindow.cpp
  66. @@ -1825,7 +1825,7 @@ bool QWindowsWindow::handleGeometryChangingMessage(MSG *message, const QWindow *
  67. const QRect suggestedFrameGeometry(windowPos->x, windowPos->y,
  68. windowPos->cx, windowPos->cy);
  69. const QRect suggestedGeometry = suggestedFrameGeometry - margins;
  70. - const QRectF correctedGeometryF = qWindow->handle()->windowClosestAcceptableGeometry(suggestedGeometry);
  71. + const QRectF correctedGeometryF = QPlatformWindow::closestAcceptableGeometry(qWindow, suggestedGeometry);
  72. if (!correctedGeometryF.isValid())
  73. return false;
  74. const QRect correctedFrameGeometry = correctedGeometryF.toRect() + margins;
  75. --
  76. 2.5.1