From a5e760b81c90c3e73072c3936496fb59e44623e7 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Sat, 20 Aug 2016 18:35:37 +0300 Subject: [PATCH] 8148109: [SWT] Provide a supported mechanism to use EmbeddedFrame Reviewed-by: alanb, prr --- jdk/make/mapfiles/libawt/mapfile-mawt-vers | 6 ++- jdk/make/mapfiles/libawt/mapfile-vers-linux | 6 ++- jdk/make/mapfiles/libawt_xawt/mapfile-vers | 3 ++ .../libawt_lwawt/awt/awt_DrawingSurface.m | 48 +++++++++++++++++- .../java.desktop/macosx/native/libjawt/jawt.m | 12 +++-- .../java.desktop/share/native/include/jawt.h | 49 ++++++++++++++++++- .../native/common/awt/awt_DrawingSurface.h | 13 ++++- .../libawt_xawt/awt/awt_DrawingSurface.c | 47 +++++++++++++++++- .../java.desktop/unix/native/libjawt/jawt.c | 8 ++- .../libawt/windows/awt_DrawingSurface.cpp | 46 ++++++++++++++++- .../libawt/windows/awt_DrawingSurface.h | 12 ++++- .../windows/native/libjawt/jawt.cpp | 11 ++++- 12 files changed, 245 insertions(+), 16 deletions(-) diff --git a/jdk/make/mapfiles/libawt/mapfile-mawt-vers b/jdk/make/mapfiles/libawt/mapfile-mawt-vers index 247e29698e2..32eb88df678 100644 --- a/jdk/make/mapfiles/libawt/mapfile-mawt-vers +++ b/jdk/make/mapfiles/libawt/mapfile-mawt-vers @@ -1,5 +1,5 @@ # -# Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -238,6 +238,10 @@ SUNWprivate_1.1 { awt_GetDrawingSurface; awt_FreeDrawingSurface; awt_GetComponent; + awt_CreateEmbeddedFrame; + awt_SetBounds; + awt_SynthesizeWindowActivation; + X11SurfaceData_GetOps; getDefaultConfig; diff --git a/jdk/make/mapfiles/libawt/mapfile-vers-linux b/jdk/make/mapfiles/libawt/mapfile-vers-linux index 5645cbd18d9..a1f8d9b6e0e 100644 --- a/jdk/make/mapfiles/libawt/mapfile-vers-linux +++ b/jdk/make/mapfiles/libawt/mapfile-vers-linux @@ -1,5 +1,5 @@ # -# Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -264,6 +264,10 @@ SUNWprivate_1.1 { awt_GetDrawingSurface; awt_FreeDrawingSurface; awt_GetComponent; + awt_CreateEmbeddedFrame; + awt_SetBounds; + awt_SynthesizeWindowActivation; + X11SurfaceData_GetOps; getDefaultConfig; diff --git a/jdk/make/mapfiles/libawt_xawt/mapfile-vers b/jdk/make/mapfiles/libawt_xawt/mapfile-vers index 461c1ba9f48..04113dcf031 100644 --- a/jdk/make/mapfiles/libawt_xawt/mapfile-vers +++ b/jdk/make/mapfiles/libawt_xawt/mapfile-vers @@ -458,6 +458,9 @@ SUNWprivate_1.1 { awt_Unlock; awt_Lock; awt_GetComponent; + awt_CreateEmbeddedFrame; + awt_SetBounds; + awt_SynthesizeWindowActivation; #XAWT entry point for CDE Java_sun_awt_motif_XsessionWMcommand; diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m index f444bc9b693..fb2cb86a617 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,8 @@ #import "AWTSurfaceLayers.h" +#import "jni_util.h" + JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL awt_DrawingSurface_GetDrawingSurfaceInfo (JAWT_DrawingSurface* ds) { @@ -130,3 +132,47 @@ JNIEXPORT jobject JNICALL awt_GetComponent // TODO: implement return NULL; } + +// EmbeddedFrame support + +static char *const embeddedClassName = "sun/lwawt/macosx/CViewEmbeddedFrame"; + +JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame +(JNIEnv* env, void* platformInfo) +{ + static jmethodID mid = NULL; + static jclass cls; + if (mid == NULL) { + cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL_RETURN(cls, NULL); + mid = (*env)->GetMethodID(env, cls, "", "(J)V"); + CHECK_NULL_RETURN(mid, NULL); + } + return (*env)->NewObject(env, cls, mid, platformInfo); +} + +JNIEXPORT void JNICALL awt_SetBounds +(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL(cls); + mid = (*env)->GetMethodID(env, cls, "setBoundsPrivate", "(IIII)V"); + CHECK_NULL(mid); + } + (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h); +} + +JNIEXPORT void JNICALL awt_SynthesizeWindowActivation +(JNIEnv *env, jobject embeddedFrame, jboolean doActivate) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL(cls); + mid = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V"); + CHECK_NULL(mid); + } + (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate); +} diff --git a/jdk/src/java.desktop/macosx/native/libjawt/jawt.m b/jdk/src/java.desktop/macosx/native/libjawt/jawt.m index cd9f52a8e5e..773c6482caa 100644 --- a/jdk/src/java.desktop/macosx/native/libjawt/jawt.m +++ b/jdk/src/java.desktop/macosx/native/libjawt/jawt.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,8 +46,9 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT return JNI_FALSE; } - if (awt->version != (JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER) && - awt->version != JAWT_VERSION_1_7) + if (awt->version != (JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER) + && awt->version != JAWT_VERSION_1_7 + && awt->version != JAWT_VERSION_9) { return JNI_FALSE; } @@ -58,6 +59,11 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT awt->Lock = awt_Lock; awt->Unlock = awt_Unlock; awt->GetComponent = awt_GetComponent; + if (awt->version >= JAWT_VERSION_9) { + awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame; + awt->SetBounds = awt_SetBounds; + awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation; + } } return JNI_TRUE; diff --git a/jdk/src/java.desktop/share/native/include/jawt.h b/jdk/src/java.desktop/share/native/include/jawt.h index e0f682f4305..8cb2cb8564d 100644 --- a/jdk/src/java.desktop/share/native/include/jawt.h +++ b/jdk/src/java.desktop/share/native/include/jawt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,7 +33,7 @@ extern "C" { #endif /* - * AWT native interface (new in JDK 1.3) + * AWT native interface. * * The AWT native interface allows a native C or C++ application a means * by which to access native structures in AWT. This is to facilitate moving @@ -279,6 +279,50 @@ typedef struct jawt { */ jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo); + /** + * Since 9 + * Creates a java.awt.Frame placed in a native container. Container is + * referenced by the native platform handle. For example on Windows this + * corresponds to an HWND. For other platforms, see the appropriate + * machine-dependent header file for a description. The reference returned + * by this function is a local reference that is only valid in this + * environment. This function returns a NULL reference if no frame could be + * created with matching platform information. + */ + jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo); + + /** + * Since 9 + * Moves and resizes the embedded frame. The new location of the top-left + * corner is specified by x and y parameters relative to the native parent + * component. The new size is specified by width and height. + * + * The embedded frame should be created by CreateEmbeddedFrame() method, or + * this function will not have any effect. + * + * java.awt.Component.setLocation() and java.awt.Component.setBounds() for + * EmbeddedFrame really don't move it within the native parent. These + * methods always locate the embedded frame at (0, 0) for backward + * compatibility. To allow moving embedded frames this method was + * introduced, and it works just the same way as setLocation() and + * setBounds() for usual, non-embedded components. + * + * Using usual get/setLocation() and get/setBounds() together with this new + * method is not recommended. + */ + void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame, + jint x, jint y, jint w, jint h); + /** + * Since 9 + * Synthesize a native message to activate or deactivate an EmbeddedFrame + * window depending on the value of parameter doActivate, if "true" + * activates the window; otherwise, deactivates the window. + * + * The embedded frame should be created by CreateEmbeddedFrame() method, or + * this function will not have any effect. + */ + void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env, + jobject embeddedFrame, jboolean doActivate); } JAWT; /* @@ -291,6 +335,7 @@ jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt); #define JAWT_VERSION_1_3 0x00010003 #define JAWT_VERSION_1_4 0x00010004 #define JAWT_VERSION_1_7 0x00010007 +#define JAWT_VERSION_9 0x00090000 #ifdef __cplusplus } /* extern "C" */ diff --git a/jdk/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h b/jdk/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h index bb59b4658c7..bdc9830b07b 100644 --- a/jdk/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h +++ b/jdk/src/java.desktop/unix/native/common/awt/awt_DrawingSurface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,6 @@ #include #include -#include _JNI_IMPORT_OR_EXPORT_ JAWT_DrawingSurface* JNICALL awt_GetDrawingSurface(JNIEnv* env, jobject target); @@ -45,4 +44,14 @@ _JNI_IMPORT_OR_EXPORT_ void JNICALL _JNI_IMPORT_OR_EXPORT_ jobject JNICALL awt_GetComponent(JNIEnv* env, void* platformInfo); +_JNI_IMPORT_OR_EXPORT_ jobject JNICALL + awt_CreateEmbeddedFrame(JNIEnv* env, void* platformInfo); + +_JNI_IMPORT_OR_EXPORT_ void JNICALL + awt_SetBounds(JNIEnv *env, jobject embeddedFrame, jint x, jint y, + jint w, jint h); + +_JNI_IMPORT_OR_EXPORT_ void JNICALL + awt_SynthesizeWindowActivation(JNIEnv *env, jobject embeddedFrame, + jboolean doActivate); #endif /* !_AWT_DRAWING_SURFACE_H_ */ diff --git a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c index de7e8488985..1cc09c9acac 100644 --- a/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_DrawingSurface.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -383,3 +383,48 @@ JNIEXPORT jobject JNICALL return target; } + +// EmbeddedFrame support + +static char *const embeddedClassName = "sun/awt/X11/XEmbeddedFrame"; + +JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame +(JNIEnv* env, void* platformInfo) +{ + static jmethodID mid = NULL; + static jclass cls; + if (mid == NULL) { + cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL_RETURN(cls, NULL); + mid = (*env)->GetMethodID(env, cls, "", "(JZ)V"); + CHECK_NULL_RETURN(mid, NULL); + } + return (*env)->NewObject(env, cls, mid, platformInfo, JNI_TRUE); +} + + +JNIEXPORT void JNICALL awt_SetBounds +(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL(cls); + mid = (*env)->GetMethodID(env, cls, "setBoundsPrivate", "(IIII)V"); + CHECK_NULL(mid); + } + (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h); +} + +JNIEXPORT void JNICALL awt_SynthesizeWindowActivation +(JNIEnv *env, jobject embeddedFrame, jboolean doActivate) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = (*env)->FindClass(env, embeddedClassName); + CHECK_NULL(cls); + mid = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V"); + CHECK_NULL(mid); + } + (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate); +} diff --git a/jdk/src/java.desktop/unix/native/libjawt/jawt.c b/jdk/src/java.desktop/unix/native/libjawt/jawt.c index b6a5240a7c1..59e9a55cff2 100644 --- a/jdk/src/java.desktop/unix/native/libjawt/jawt.c +++ b/jdk/src/java.desktop/unix/native/libjawt/jawt.c @@ -45,7 +45,8 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) if (awt->version != JAWT_VERSION_1_3 && awt->version != JAWT_VERSION_1_4 - && awt->version != JAWT_VERSION_1_7) { + && awt->version != JAWT_VERSION_1_7 + && awt->version != JAWT_VERSION_9) { return JNI_FALSE; } @@ -55,6 +56,11 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) awt->Lock = awt_Lock; awt->Unlock = awt_Unlock; awt->GetComponent = awt_GetComponent; + if (awt->version >= JAWT_VERSION_9) { + awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame; + awt->SetBounds = awt_SetBounds; + awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation; + } } return JNI_TRUE; diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp b/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp index 05549673564..019295ac2b5 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -272,3 +272,47 @@ extern "C" JNIEXPORT void JNICALL DSUnlockAWT(JNIEnv* env) { // Do nothing on Windows } + +// EmbeddedFrame support + +static char *const embeddedClassName = "sun/awt/windows/WEmbeddedFrame"; + +JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame +(JNIEnv* env, void* platformInfo) +{ + static jmethodID mid = NULL; + static jclass cls; + if (mid == NULL) { + cls = env->FindClass(embeddedClassName); + CHECK_NULL_RETURN(cls, NULL); + mid = env->GetMethodID(cls, "", "(J)V"); + CHECK_NULL_RETURN(mid, NULL); + } + return env->NewObject(cls, mid, platformInfo); +} + +JNIEXPORT void JNICALL awt_SetBounds +(JNIEnv *env, jobject embeddedFrame, jint x, jint y, jint w, jint h) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = env->FindClass(embeddedClassName); + CHECK_NULL(cls); + mid = env->GetMethodID(cls, "setBoundsPrivate", "(IIII)V"); + CHECK_NULL(mid); + } + env->CallVoidMethod(embeddedFrame, mid, x, y, w, h); +} + +JNIEXPORT void JNICALL awt_SynthesizeWindowActivation +(JNIEnv *env, jobject embeddedFrame, jboolean doActivate) +{ + static jmethodID mid = NULL; + if (mid == NULL) { + jclass cls = env->FindClass(embeddedClassName); + CHECK_NULL(cls); + mid = env->GetMethodID(cls, "synthesizeWindowActivation", "(Z)V"); + CHECK_NULL(mid); + } + env->CallVoidMethod(embeddedFrame, mid, doActivate); +} diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h b/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h index cd135b947e2..a2a510797e9 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -162,6 +162,16 @@ extern "C" { jobject JNICALL DSGetComponent( JNIEnv* env, void* platformInfo); + _JNI_IMPORT_OR_EXPORT_ jobject JNICALL + awt_CreateEmbeddedFrame(JNIEnv* env, void* platformInfo); + + _JNI_IMPORT_OR_EXPORT_ void JNICALL + awt_SetBounds(JNIEnv *env, jobject embeddedFrame, jint x, + jint y, jint w, jint h); + + _JNI_IMPORT_OR_EXPORT_ void JNICALL + awt_SynthesizeWindowActivation(JNIEnv *env, jobject embeddedFrame, + jboolean doActivate); #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/jdk/src/java.desktop/windows/native/libjawt/jawt.cpp b/jdk/src/java.desktop/windows/native/libjawt/jawt.cpp index 218b7dd0864..1393dfcf8f6 100644 --- a/jdk/src/java.desktop/windows/native/libjawt/jawt.cpp +++ b/jdk/src/java.desktop/windows/native/libjawt/jawt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,7 +46,9 @@ extern "C" JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) } if (awt->version != JAWT_VERSION_1_3 - && awt->version != JAWT_VERSION_1_4) { + && awt->version != JAWT_VERSION_1_4 + && awt->version != JAWT_VERSION_1_7 + && awt->version != JAWT_VERSION_9) { return JNI_FALSE; } @@ -56,6 +58,11 @@ extern "C" JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) awt->Lock = DSLockAWT; awt->Unlock = DSUnlockAWT; awt->GetComponent = DSGetComponent; + if (awt->version >= JAWT_VERSION_9) { + awt->CreateEmbeddedFrame = awt_CreateEmbeddedFrame; + awt->SetBounds = awt_SetBounds; + awt->SynthesizeWindowActivation = awt_SynthesizeWindowActivation; + } } return JNI_TRUE;