Android: Delete parent window in QtView instead of just the child view

Since the parent window wraps the QtView, it should always be destroyed
when the QtView is, and live inside QtView rather than the delegate.

Destroying the parent window will always destroy the child window, so
do not destroy the child window separately.

Move createRootWindow and deleteWindow native functions to QtView.

Fixes: QTBUG-124908
Change-Id: Ib6b3c6388a9dd3f74d16fa09a442b0a6f8ccb336
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Petri Virkkunen 2024-04-30 13:09:59 +03:00
parent 6d2db42f7c
commit 9ef4435fbf
3 changed files with 15 additions and 32 deletions

View File

@ -24,13 +24,9 @@ import java.util.HashMap;
class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppStateDetailsListener {
// TODO simplistic implementation with one QtView, expand to support multiple views QTBUG-117649
private QtView m_view;
private long m_rootWindowRef = 0L;
private QtNative.ApplicationStateDetails m_stateDetails;
private boolean m_windowLoaded = false;
private static native void createRootWindow(View rootView, int x, int y, int width, int height);
static native void deleteWindow(long windowReference);
public QtEmbeddedDelegate(Activity context) {
super(context);
@ -82,7 +78,6 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
QtNative.terminateQt();
QtNative.setActivity(null);
QtNative.getQtThread().exit();
onDestroy();
}
}
});
@ -154,20 +149,10 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS
m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view));
}
public void setRootWindowRef(long ref) {
m_rootWindowRef = ref;
}
public void onDestroy() {
if (m_rootWindowRef != 0L)
deleteWindow(m_rootWindowRef);
m_rootWindowRef = 0L;
}
private void createRootWindow() {
if (m_view != null && !m_windowLoaded) {
createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(), m_view.getHeight());
QtView.createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(),
m_view.getHeight());
m_windowLoaded = true;
}
}

View File

@ -29,6 +29,7 @@ abstract class QtView extends ViewGroup {
protected QtWindow m_window;
protected long m_windowReference;
protected long m_parentWindowReference;
protected QtWindowListener m_windowListener;
protected QtEmbeddedDelegate m_delegate;
// Implement in subclass to handle the creation of the QWindow and its parent container.
@ -37,6 +38,8 @@ abstract class QtView extends ViewGroup {
// too much JNI back and forth. Related to parent window creation, so handle with QTBUG-121511.
abstract protected void createWindow(long parentWindowRef);
static native void createRootWindow(View rootView, int x, int y, int width, int height);
static native void deleteWindow(long windowReference);
private static native void setWindowVisible(long windowReference, boolean visible);
private static native void resizeWindow(long windowReference,
int x, int y, int width, int height);
@ -156,7 +159,7 @@ abstract class QtView extends ViewGroup {
// viewReference - the reference to the created QQuickView
void addQtWindow(QtWindow window, long viewReference, long parentWindowRef) {
setWindowReference(viewReference);
m_delegate.setRootWindowRef(parentWindowRef);
m_parentWindowReference = parentWindowRef;
final Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
@ -176,9 +179,9 @@ abstract class QtView extends ViewGroup {
// Destroy the underlying QWindow
void destroyWindow() {
if (m_windowReference != 0L)
QtEmbeddedDelegate.deleteWindow(m_windowReference);
m_windowReference = 0L;
if (m_parentWindowReference != 0L)
deleteWindow(m_parentWindowReference);
m_parentWindowReference = 0L;
}
QtWindow getQtWindow() {

View File

@ -12,7 +12,6 @@
QT_BEGIN_NAMESPACE
Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate");
namespace QtAndroidWindowEmbedding {
void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView,
@ -59,16 +58,12 @@ namespace QtAndroidWindowEmbedding {
}
bool registerNatives(QJniEnvironment& env) {
using namespace QtJniTypes;
bool success = env.registerNativeMethods(Traits<QtEmbeddedDelegate>::className(),
{Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding)});
success &= env.registerNativeMethods(Traits<QtView>::className(),
{Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding)});
return success;
return env.registerNativeMethods(
QtJniTypes::Traits<QtJniTypes::QtView>::className(),
{ Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding),
Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) });
}
}