提交 8f9460fa 编写于 作者: L leonidr

7124376: [macosx] Modal dialog lost focus

Reviewed-by: anthony
上级 4120c120
...@@ -409,6 +409,8 @@ public class LWWindowPeer ...@@ -409,6 +409,8 @@ public class LWWindowPeer
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null; this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
} }
platformWindow.setModalBlocked(blocked);
} }
@Override @Override
......
...@@ -108,6 +108,8 @@ public interface PlatformWindow { ...@@ -108,6 +108,8 @@ public interface PlatformWindow {
public void flip(int x1, int y1, int x2, int y2, public void flip(int x1, int y1, int x2, int y2,
BufferCapabilities.FlipContents flipAction); BufferCapabilities.FlipContents flipAction);
public void setModalBlocked(boolean blocked);
public void toFront(); public void toFront();
public void toBack(); public void toBack();
......
...@@ -205,4 +205,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { ...@@ -205,4 +205,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
@Override @Override
public void setWindowState(int windowState) {} public void setWindowState(int windowState) {}
@Override
public void setModalBlocked(boolean blocked) {}
} }
...@@ -61,6 +61,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -61,6 +61,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage); private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename); private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY); private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr); private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr); private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
...@@ -800,6 +801,15 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -800,6 +801,15 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// value when the native notification comes to us // value when the native notification comes to us
} }
@Override
public void setModalBlocked(boolean blocked) {
if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
return;
}
nativeSetEnabled(getNSWindowPtr(), !blocked);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// UTILITY METHODS // UTILITY METHODS
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
......
...@@ -81,7 +81,7 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -81,7 +81,7 @@ AWT_ASSERT_APPKIT_THREAD;
fEnablePressAndHold = shouldUsePressAndHold(); fEnablePressAndHold = shouldUsePressAndHold();
fInPressAndHold = NO; fInPressAndHold = NO;
fPAHNeedsToSelect = NO; fPAHNeedsToSelect = NO;
mouseIsOver = NO; mouseIsOver = NO;
if (windowLayer != nil) { if (windowLayer != nil) {
...@@ -302,16 +302,25 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -302,16 +302,25 @@ AWT_ASSERT_APPKIT_THREAD;
*/ */
-(void) deliverJavaMouseEvent: (NSEvent *) event { -(void) deliverJavaMouseEvent: (NSEvent *) event {
BOOL isEnabled = YES;
NSEventType type = [event type]; NSWindow* window = [self window];
if ([window isKindOfClass: [AWTWindow class]]) {
isEnabled = [(AWTWindow*)window isEnabled];
}
if (!isEnabled) {
return;
}
NSEventType type = [event type];
// check synthesized mouse entered/exited events // check synthesized mouse entered/exited events
if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) { if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
return; return;
}else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) { }else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
mouseIsOver = !mouseIsOver; mouseIsOver = !mouseIsOver;
} }
[AWTToolkit eventCountPlusPlus]; [AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv]; JNIEnv *env = [ThreadUtilities getJNIEnv];
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
NSSize javaMinSize; NSSize javaMinSize;
NSSize javaMaxSize; NSSize javaMaxSize;
jint styleBits; jint styleBits;
BOOL isEnabled;
} }
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow; @property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
...@@ -49,6 +50,7 @@ ...@@ -49,6 +50,7 @@
@property (nonatomic) NSSize javaMinSize; @property (nonatomic) NSSize javaMinSize;
@property (nonatomic) NSSize javaMaxSize; @property (nonatomic) NSSize javaMaxSize;
@property (nonatomic) jint styleBits; @property (nonatomic) jint styleBits;
@property (nonatomic) BOOL isEnabled;
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
styleBits:(jint)styleBits styleBits:(jint)styleBits
......
...@@ -58,6 +58,7 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); ...@@ -58,6 +58,7 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
@synthesize javaMinSize; @synthesize javaMinSize;
@synthesize javaMaxSize; @synthesize javaMaxSize;
@synthesize styleBits; @synthesize styleBits;
@synthesize isEnabled;
- (void) updateMinMaxSize:(BOOL)resizable { - (void) updateMinMaxSize:(BOOL)resizable {
if (resizable) { if (resizable) {
...@@ -157,6 +158,7 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -157,6 +158,7 @@ AWT_ASSERT_APPKIT_THREAD;
if (self == nil) return nil; // no hope if (self == nil) return nil; // no hope
self.isEnabled = YES;
self.javaPlatformWindow = platformWindow; self.javaPlatformWindow = platformWindow;
self.styleBits = bits; self.styleBits = bits;
[self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)]; [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
...@@ -170,22 +172,22 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -170,22 +172,22 @@ AWT_ASSERT_APPKIT_THREAD;
return self; return self;
} }
// checks that this window is under the mouse cursor and this point is not overlapped by others windows // checks that this window is under the mouse cursor and this point is not overlapped by others windows
- (BOOL) isTopmostWindowUnderMouse { - (BOOL) isTopmostWindowUnderMouse {
int currentWinID = [self windowNumber]; int currentWinID = [self windowNumber];
NSRect screenRect = [[NSScreen mainScreen] frame]; NSRect screenRect = [[NSScreen mainScreen] frame];
NSPoint nsMouseLocation = [NSEvent mouseLocation]; NSPoint nsMouseLocation = [NSEvent mouseLocation];
CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y); CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID); NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
for (NSDictionary *window in windows) { for (NSDictionary *window in windows) {
int layer = [[window objectForKey:(id)kCGWindowLayer] intValue]; int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
if (layer == 0) { if (layer == 0) {
int winID = [[window objectForKey:(id)kCGWindowNumber] intValue]; int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];
CGRect rect; CGRect rect;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect); CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
if (CGRectContainsPoint(rect, cgMouseLocation)) { if (CGRectContainsPoint(rect, cgMouseLocation)) {
...@@ -199,23 +201,23 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -199,23 +201,23 @@ AWT_ASSERT_APPKIT_THREAD;
} }
- (void) synthesizeMouseEnteredExitedEvents { - (void) synthesizeMouseEnteredExitedEvents {
int eventType = 0; int eventType = 0;
BOOL isUnderMouse = [self isTopmostWindowUnderMouse]; BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
BOOL mouseIsOver = [[self contentView] mouseIsOver]; BOOL mouseIsOver = [[self contentView] mouseIsOver];
if (isUnderMouse && !mouseIsOver) { if (isUnderMouse && !mouseIsOver) {
eventType = NSMouseEntered; eventType = NSMouseEntered;
} else if (!isUnderMouse && mouseIsOver) { } else if (!isUnderMouse && mouseIsOver) {
eventType = NSMouseExited; eventType = NSMouseExited;
} else { } else {
return; return;
} }
NSPoint screenLocation = [NSEvent mouseLocation]; NSPoint screenLocation = [NSEvent mouseLocation];
NSPoint windowLocation = [self convertScreenToBase: screenLocation]; NSPoint windowLocation = [self convertScreenToBase: screenLocation];
int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask; int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
location: windowLocation location: windowLocation
modifierFlags: modifierFlags modifierFlags: modifierFlags
...@@ -226,7 +228,7 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -226,7 +228,7 @@ AWT_ASSERT_APPKIT_THREAD;
trackingNumber: 0 trackingNumber: 0
userData: nil userData: nil
]; ];
[[self contentView] deliverJavaMouseEvent: mouseEvent]; [[self contentView] deliverJavaMouseEvent: mouseEvent];
} }
...@@ -239,16 +241,15 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -239,16 +241,15 @@ AWT_ASSERT_APPKIT_THREAD;
[super dealloc]; [super dealloc];
} }
// NSWindow overrides // NSWindow overrides
- (BOOL) canBecomeKeyWindow { - (BOOL) canBecomeKeyWindow {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
return IS(self.styleBits, SHOULD_BECOME_KEY); return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
} }
- (BOOL) canBecomeMainWindow { - (BOOL) canBecomeMainWindow {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
return IS(self.styleBits, SHOULD_BECOME_MAIN); return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
} }
- (BOOL) worksWhenModal { - (BOOL) worksWhenModal {
...@@ -562,6 +563,27 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -562,6 +563,27 @@ AWT_ASSERT_APPKIT_THREAD;
size->height = MAX(size->height, minHeight); size->height = MAX(size->height, minHeight);
} }
- (void) setEnabled: (BOOL)flag {
self.isEnabled = flag;
if (IS(self.styleBits, CLOSEABLE)) {
[[self standardWindowButton:NSWindowCloseButton] setEnabled: flag];
}
if (IS(self.styleBits, MINIMIZABLE)) {
[[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
}
if (IS(self.styleBits, ZOOMABLE)) {
[[self standardWindowButton:NSWindowZoomButton] setEnabled: flag];
}
if (IS(self.styleBits, RESIZABLE)) {
[self updateMinMaxSize:flag];
[self setShowsResizeIndicator:flag];
}
}
@end // AWTWindow @end // AWTWindow
...@@ -729,7 +751,7 @@ AWT_ASSERT_NOT_APPKIT_THREAD; ...@@ -729,7 +751,7 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
// ensure we repaint the whole window after the resize operation // ensure we repaint the whole window after the resize operation
// (this will also re-enable screen updates, which were disabled above) // (this will also re-enable screen updates, which were disabled above)
// TODO: send PaintEvent // TODO: send PaintEvent
[window synthesizeMouseEnteredExitedEvents]; [window synthesizeMouseEnteredExitedEvents];
}]; }];
...@@ -969,14 +991,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMou ...@@ -969,14 +991,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMou
{ {
JNF_COCOA_ENTER(env); JNF_COCOA_ENTER(env);
AWT_ASSERT_NOT_APPKIT_THREAD; AWT_ASSERT_NOT_APPKIT_THREAD;
AWTWindow *window = OBJC(windowPtr); AWTWindow *window = OBJC(windowPtr);
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
[window synthesizeMouseEnteredExitedEvents]; [window synthesizeMouseEnteredExitedEvents];
}]; }];
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
} }
...@@ -1056,3 +1078,17 @@ JNF_COCOA_EXIT(env); ...@@ -1056,3 +1078,17 @@ JNF_COCOA_EXIT(env);
return underMouse; return underMouse;
} }
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
{
JNF_COCOA_ENTER(env);
AWTWindow *window = OBJC(windowPtr);
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
[window setEnabled: isEnabled];
}];
JNF_COCOA_EXIT(env);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册