From ede4f5e23b08e9b2cc8fb6a449ee9f667b8da9fa Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 13 Sep 2012 12:14:13 +0300 Subject: Fix mapping to/from global coordinates for child/embedded windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWidget's mapToGlobal() and mapFromGlobal() functions assumed that if the widget reports it's a window or if it has no parent widget, it must be a top level window whose coordinates are in global coordinates. This is not true for child QWindows or embedded native windows (QAxWidgets). Changed the logic for mapping coordinates to use equivalent methods from QWindow if widget has a window handle, and changed QWindow's methods to map coordinates using native methods if window is embedded. Also fixed newly failing accessibility autotest. The geometry related failures there popped up because now the position of the rect returned by accessible interface is actually correct while widget geometry still reports position 0,0 before widget has shown up. Task-number: QTBUG-26436 Change-Id: I658fafd0ce01eb1604ba255efeeba3073ca0189f Reviewed-by: Samuel Rødal --- src/gui/kernel/qplatformwindow.cpp | 24 ++++++++++++++++++++++++ src/gui/kernel/qplatformwindow.h | 2 ++ src/gui/kernel/qwindow.cpp | 12 ++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 748a7825b6..6200ad01bf 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -187,6 +187,30 @@ bool QPlatformWindow::isEmbedded(const QPlatformWindow *parentWindow) const return false; } +/*! + Translates the window coordinate \a pos to global screen + coordinates using native methods. This is required for embedded windows, + where the topmost QWindow coordinates are not global screen coordinates. + + Returns \a pos if there is no platform specific implementation. +*/ +QPoint QPlatformWindow::mapToGlobal(const QPoint &pos) const +{ + return pos; +} + +/*! + Translates the global screen coordinate \a pos to window + coordinates using native methods. This is required for embedded windows, + where the topmost QWindow coordinates are not global screen coordinates. + + Returns \a pos if there is no platform specific implementation. +*/ +QPoint QPlatformWindow::mapFromGlobal(const QPoint &pos) const +{ + return pos; +} + /*! Requests setting the window state of this surface to \a type. Returns the actual state set. diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index e27851830e..7d6bb80df1 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -104,6 +104,8 @@ public: virtual bool isExposed() const; virtual bool isActive() const; virtual bool isEmbedded(const QPlatformWindow *parentWindow) const; + virtual QPoint mapToGlobal(const QPoint &pos) const; + virtual QPoint mapFromGlobal(const QPoint &pos) const; virtual void propagateSizeHints(); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 3b12768678..a2447e282a 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1744,7 +1744,11 @@ bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *resu */ QPoint QWindow::mapToGlobal(const QPoint &pos) const { - return pos + d_func()->globalPosition(); + Q_D(const QWindow); + if (d->platformWindow && d->platformWindow->isEmbedded(0)) + return d->platformWindow->mapToGlobal(pos); + else + return pos + d_func()->globalPosition(); } @@ -1758,7 +1762,11 @@ QPoint QWindow::mapToGlobal(const QPoint &pos) const */ QPoint QWindow::mapFromGlobal(const QPoint &pos) const { - return pos - d_func()->globalPosition(); + Q_D(const QWindow); + if (d->platformWindow && d->platformWindow->isEmbedded(0)) + return d->platformWindow->mapFromGlobal(pos); + else + return pos - d_func()->globalPosition(); } -- cgit v1.2.3