Android: Handle embedding container windows better
Initialize surface container type to TextureView to make sure it's set also for embedding containers. Additional checks for embedding containers when setting parent or changing visibility. Change-Id: Iba07bfbb9e8f16804627efbdfe78559ac2580e41 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 46b86410a9730b099fa350516c3902db0ee01291) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ccd624eacc
commit
e47180b46d
@ -48,12 +48,16 @@ void QAndroidPlatformForeignWindow::setGeometry(const QRect &rect)
|
||||
|
||||
void QAndroidPlatformForeignWindow::setVisible(bool visible)
|
||||
{
|
||||
if (!m_view.isValid() || isEmbeddingContainer())
|
||||
if (isEmbeddingContainer()) {
|
||||
QAndroidPlatformWindow::setVisible(visible);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_view.isValid())
|
||||
return;
|
||||
|
||||
QtAndroid::setViewVisibility(m_view.object(), visible);
|
||||
|
||||
QAndroidPlatformWindow::setVisible(visible);
|
||||
if (!visible && m_nativeViewInserted) {
|
||||
m_nativeQtWindow.callMethod<void>("removeNativeView");
|
||||
m_nativeViewInserted = false;
|
||||
|
@ -17,7 +17,8 @@ QT_BEGIN_NAMESPACE
|
||||
Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window")
|
||||
|
||||
QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window)
|
||||
: QPlatformWindow(window), m_nativeQtWindow(nullptr), m_nativeParentQtWindow(nullptr),
|
||||
: QPlatformWindow(window), m_nativeQtWindow(nullptr),
|
||||
m_surfaceContainerType(SurfaceContainer::TextureView), m_nativeParentQtWindow(nullptr),
|
||||
m_androidSurfaceObject(nullptr)
|
||||
{
|
||||
m_windowFlags = Qt::Widget;
|
||||
@ -48,8 +49,11 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window)
|
||||
if (isEmbeddingContainer())
|
||||
return;
|
||||
|
||||
if (parent())
|
||||
m_nativeParentQtWindow = static_cast<QAndroidPlatformWindow*>(parent())->nativeWindow();
|
||||
if (parent()) {
|
||||
QAndroidPlatformWindow *androidParent = static_cast<QAndroidPlatformWindow*>(parent());
|
||||
if (!androidParent->isEmbeddingContainer())
|
||||
m_nativeParentQtWindow = androidParent->nativeWindow();
|
||||
}
|
||||
|
||||
m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>(
|
||||
QNativeInterface::QAndroidApplication::context(),
|
||||
@ -62,9 +66,7 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window)
|
||||
// TODO should handle case where this changes at runtime -> need to change existing window
|
||||
// into TextureView (or perhaps not, if the parent window would be SurfaceView, as long as
|
||||
// onTop was false it would stay below the children)
|
||||
if (platformScreen()->windows().size() > 1)
|
||||
m_surfaceContainerType = SurfaceContainer::TextureView;
|
||||
else
|
||||
if (platformScreen()->windows().size() <= 1)
|
||||
m_surfaceContainerType = SurfaceContainer::SurfaceView;
|
||||
}
|
||||
|
||||
@ -114,6 +116,8 @@ void QAndroidPlatformWindow::setGeometry(const QRect &rect)
|
||||
|
||||
void QAndroidPlatformWindow::setVisible(bool visible)
|
||||
{
|
||||
if (isEmbeddingContainer())
|
||||
return;
|
||||
m_nativeQtWindow.callMethod<void>("setVisible", visible);
|
||||
|
||||
if (visible) {
|
||||
@ -164,20 +168,22 @@ Qt::WindowFlags QAndroidPlatformWindow::windowFlags() const
|
||||
void QAndroidPlatformWindow::setParent(const QPlatformWindow *window)
|
||||
{
|
||||
using namespace QtJniTypes;
|
||||
|
||||
if (window) {
|
||||
auto androidWindow = static_cast<const QAndroidPlatformWindow*>(window);
|
||||
if (androidWindow->isEmbeddingContainer())
|
||||
return;
|
||||
// If we were a top level window, remove from screen
|
||||
if (!m_nativeParentQtWindow.isValid())
|
||||
platformScreen()->removeWindow(this);
|
||||
|
||||
const QAndroidPlatformWindow *androidWindow =
|
||||
static_cast<const QAndroidPlatformWindow*>(window);
|
||||
const QtWindow parentWindow = androidWindow->nativeWindow();
|
||||
// If this was a child window of another window, the java method takes care of that
|
||||
m_nativeQtWindow.callMethod<void, QtWindow>("setParent", parentWindow.object());
|
||||
m_nativeParentQtWindow = parentWindow;
|
||||
} else {
|
||||
m_nativeQtWindow.callMethod<void, QtWindow>("setParent", nullptr);
|
||||
} else if (QtAndroid::isQtApplication()) {
|
||||
platformScreen()->addWindow(this);
|
||||
m_nativeQtWindow.callMethod<void, QtWindow>("setParent", nullptr);
|
||||
m_nativeParentQtWindow = QJniObject();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user