Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs #177

Closed
Changes from all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -121,7 +121,7 @@ - (void) dealloc {
{
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];

JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
fInputMethodLOCKABLE = NULL;
}

@@ -1363,14 +1363,10 @@ - (void)setInputMethod:(jobject)inputMethod

// Get rid of the old one
if (fInputMethodLOCKABLE) {
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
}

// Save a global ref to the new input method.
if (inputMethod != NULL)
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
else
fInputMethodLOCKABLE = NULL;
fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef

NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
kbdLayout = curContxt.selectedKeyboardInputSource;
@@ -1412,6 +1408,7 @@ - (void)abandonInput

NSRect rect = NSMakeRect(originX, originY, width, height);
jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
CHECK_EXCEPTION();

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){

@@ -32,11 +32,10 @@
#import "LWCToolkit.h"

@class AWTView;
@class JNFWeakJObjectWrapper;

@interface AWTWindow : NSObject <NSWindowDelegate> {
@private
JNFWeakJObjectWrapper *javaPlatformWindow;
jobject javaPlatformWindow; /* This is a weak ref. Always copy to a local ref before using */
CMenuBar *javaMenuBar;
NSSize javaMinSize;
NSSize javaMaxSize;
@@ -53,7 +52,7 @@
// An instance of either AWTWindow_Normal or AWTWindow_Panel
@property (nonatomic, retain) NSWindow *nsWindow;

@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@property (nonatomic) jobject javaPlatformWindow;
@property (nonatomic, retain) CMenuBar *javaMenuBar;
@property (nonatomic, retain) AWTWindow *ownerWindow;
@property (nonatomic) NSSize javaMinSize;
@@ -65,7 +64,7 @@
@property (nonatomic) BOOL isMinimizing;
@property (nonatomic) BOOL keyNotificationRecd;

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
- (id) initWithPlatformWindow:(jobject)javaPlatformWindow
ownerWindow:owner
styleBits:(jint)styleBits
frameRect:(NSRect)frameRect
@@ -116,7 +116,7 @@ - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
AWT_ASSERT_APPKIT_THREAD;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, ((AWTWindow *)self.delegate).javaPlatformWindow);
if (platformWindow != NULL) {
// extract the target AWT Window object out of the CPlatformWindow
GET_CPLATFORM_WINDOW_CLASS();
@@ -281,7 +281,7 @@ - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
}
}

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
- (id) initWithPlatformWindow:(jobject)platformWindow
ownerWindow:owner
styleBits:(jint)bits
frameRect:(NSRect)rect
@@ -482,7 +482,7 @@ - (void) dealloc {
AWT_ASSERT_APPKIT_THREAD;

JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
[self.javaPlatformWindow setJObject:nil withEnv:env];
(*env)->DeleteWeakGlobalRef(env, self.javaPlatformWindow);
self.javaPlatformWindow = nil;
self.nsWindow = nil;
self.ownerWindow = nil;
@@ -494,7 +494,7 @@ - (BOOL) isBlocked {
BOOL isBlocked = NO;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(isBlocked);
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z", isBlocked);
@@ -511,7 +511,7 @@ - (BOOL) isSimpleWindowOwnedByEmbeddedFrame {
BOOL isSimpleWindowOwnedByEmbeddedFrame = NO;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z", NO);
@@ -532,7 +532,7 @@ + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
[AWTToolkit eventCountPlusPlus];

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, awtWindow.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(isVisible);
DECLARE_METHOD_RETURN(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z", isVisible)
@@ -603,7 +603,7 @@ - (BOOL) canBecomeMainWindow {
[AWTToolkit eventCountPlusPlus];

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_checkBlockingAndOrder, jc_CPlatformWindow, "checkBlockingAndOrder", "()Z", NO);
@@ -632,7 +632,7 @@ - (void) _deliverMoveResizeEvent {
// the bounds of the window to avoid the Dock or remain on screen.
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow == NULL) {
// TODO: create generic AWT assert
}
@@ -710,7 +710,7 @@ - (void) _deliverIconify:(BOOL)iconify {

[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
@@ -726,7 +726,7 @@ - (void)windowWillMiniaturize:(NSNotification *)notification {
self.isMinimizing = YES;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
@@ -757,9 +757,9 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
//AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
jobject oppositeWindow = (*env)->NewLocalRef(env, opposite.javaPlatformWindow);
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
(*env)->CallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
@@ -788,7 +788,7 @@ - (void) windowDidBecomeMain: (NSNotification *) notification {
}

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
@@ -904,7 +904,7 @@ - (BOOL)windowShouldClose:(id)sender {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V", NO);
@@ -922,7 +922,7 @@ - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
"handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_FIELD(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target);
if (awtWindow != NULL) {
@@ -939,7 +939,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
CHECK_EXCEPTION();
@@ -952,7 +952,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
CHECK_EXCEPTION();
@@ -971,7 +971,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {
jm_windowWillExitFullScreen = (*env)->GetMethodID(env, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
}
CHECK_NULL(jm_windowWillExitFullScreen);
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
CHECK_EXCEPTION();
@@ -982,7 +982,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {

- (void)windowDidExitFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
@@ -1001,7 +1001,7 @@ - (void)sendEvent:(NSEvent *)event {
// in front of its nearest parent.
if (self.ownerWindow != nil) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
@@ -1020,7 +1020,7 @@ - (void)sendEvent:(NSEvent *)event {
// Check if the click happened in the non-client area (title bar)
if (p.y >= (frame.origin.y + contentRect.size.height)) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
// Currently, no need to deliver the whole NSEvent.
GET_CPLATFORM_WINDOW_CLASS();
@@ -1103,7 +1103,7 @@ + (AWTWindow *) lastKeyWindow {

JNI_COCOA_ENTER(env);

JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
jobject platformWindow = (*env)->NewWeakGlobalRef(env, obj);
NSView *contentView = OBJC(contentViewPtr);
NSRect frameRect = NSMakeRect(x, y, w, h);
AWTWindow *owner = [OBJC(ownerPtr) delegate];
@@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow {
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
if (awtWindow != nil) {
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
topmostWindowUnderMouse = awtWindow.javaPlatformWindow;
}
}];

@@ -66,9 +66,9 @@ - (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)en
@synchronized(self) {
if (owner != NULL) {
if (self.clipboardOwner != NULL) {
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
}
self.clipboardOwner = JNFNewGlobalRef(env, owner);
self.clipboardOwner = (*env)->NewGlobalRef(env, owner);
}
}
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
@@ -101,7 +101,7 @@ - (void)checkPasteboard:(id)sender {
if (self.clipboardOwner) {
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
CHECK_EXCEPTION();
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
self.clipboardOwner = NULL;
}
}
@@ -169,32 +169,32 @@ - (void)removeFromView:(JNIEnv *)env

// Clean up JNI refs
if (fComponent != NULL) {
JNFDeleteGlobalRef(env, fComponent);
(*env)->DeleteGlobalRef(env, fComponent);
fComponent = NULL;
}

if (fDragSourceContextPeer != NULL) {
JNFDeleteGlobalRef(env, fDragSourceContextPeer);
(*env)->DeleteGlobalRef(env, fDragSourceContextPeer);
fDragSourceContextPeer = NULL;
}

if (fTransferable != NULL) {
JNFDeleteGlobalRef(env, fTransferable);
(*env)->DeleteGlobalRef(env, fTransferable);
fTransferable = NULL;
}

if (fTriggerEvent != NULL) {
JNFDeleteGlobalRef(env, fTriggerEvent);
(*env)->DeleteGlobalRef(env, fTriggerEvent);
fTriggerEvent = NULL;
}

if (fFormats != NULL) {
JNFDeleteGlobalRef(env, fFormats);
(*env)->DeleteGlobalRef(env, fFormats);
fFormats = NULL;
}

if (fFormatMap != NULL) {
JNFDeleteGlobalRef(env, fFormatMap);
(*env)->DeleteGlobalRef(env, fFormatMap);
fFormatMap = NULL;
}

@@ -50,12 +50,12 @@
JNI_COCOA_ENTER(env);

// Global references are disposed when the DragSource is removed
jobject gComponent = JNFNewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = JNFNewGlobalRef(env, jthis);
jobject gTransferable = JNFNewGlobalRef(env, jtransferable);
jobject gTriggerEvent = JNFNewGlobalRef(env, jtrigger);
jlongArray gFormats = JNFNewGlobalRef(env, jformats);
jobject gFormatMap = JNFNewGlobalRef(env, jformatmap);
jobject gComponent = (*env)->NewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis);
jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable);
jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);
jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);
jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
dragSource = [[CDragSource alloc] init:gDragSourceContextPeer
ProTip! Use n and p to navigate between commits in a pull request.