changeset 47730:9b702b6608f9

8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors Reviewed-by: dmarkov, ssadetsky
author serb
date Fri, 20 Oct 2017 20:08:09 -0700
parents b3ea71b70f7b
children 187b92b2e32d
files src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m
diffstat 2 files changed, 167 insertions(+), 168 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Fri Oct 20 19:08:25 2017 -0700
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Fri Oct 20 20:08:09 2017 -0700
@@ -74,20 +74,20 @@
     // Initialize ourselves
     self = [super initWithFrame: rect];
     if (self == nil) return self;
-    
+
     m_cPlatformView = cPlatformView;
     fInputMethodLOCKABLE = NULL;
     fKeyEventsNeeded = NO;
     fProcessingKeystroke = NO;
-    
+
     fEnablePressAndHold = shouldUsePressAndHold();
     fInPressAndHold = NO;
     fPAHNeedsToSelect = NO;
-    
+
     mouseIsOver = NO;
     [self resetTrackingArea];
     [self setAutoresizesSubviews:NO];
-    
+
     if (windowLayer != nil) {
         self.cglLayer = windowLayer;
         //Layer hosting view
@@ -98,7 +98,7 @@
         //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
         //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
         //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
-        
+
 #ifdef REMOTELAYER
         CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
         parentLayer.parentLayer = NULL;
@@ -120,36 +120,36 @@
         }
 #endif /* REMOTELAYER */
     }
-    
+
     return self;
 }
 
 - (void) dealloc {
     AWT_ASSERT_APPKIT_THREAD;
-    
+
     self.cglLayer = nil;
-    
+
     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
     (*env)->DeleteWeakGlobalRef(env, m_cPlatformView);
     m_cPlatformView = NULL;
-    
+
     if (fInputMethodLOCKABLE != NULL)
     {
         JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
-        
+
         JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
         fInputMethodLOCKABLE = NULL;
     }
-    
-    
+
+
     [super dealloc];
 }
 
 - (void) viewDidMoveToWindow {
     AWT_ASSERT_APPKIT_THREAD;
-    
+
     [AWTToolkit eventCountPlusPlus];
-    
+
     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
         [[self window] makeFirstResponder: self];
     }];
@@ -230,10 +230,10 @@
 
 - (void) mouseMoved: (NSEvent *)event {
     // TODO: better way to redirect move events to the "under" view
-    
+
     NSPoint eventLocation = [event locationInWindow];
     NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
-    
+
     if  ([self mouse: localPoint inRect: [self bounds]]) {
         [self deliverJavaMouseEvent: event];
     } else {
@@ -277,10 +277,10 @@
 - (void) keyDown: (NSEvent *)event {
     fProcessingKeystroke = YES;
     fKeyEventsNeeded = YES;
-    
+
     // Allow TSM to look at the event and potentially send back NSTextInputClient messages.
     [self interpretKeyEvents:[NSArray arrayWithObject:event]];
-    
+
     if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod] && fInputMethodLOCKABLE) {
         fProcessingKeystroke = NO;
         if (!fInPressAndHold) {
@@ -289,14 +289,14 @@
         }
         return;
     }
-    
+
     NSString *eventCharacters = [event characters];
     BOOL isDeadKey = (eventCharacters != nil && [eventCharacters length] == 0);
-    
+
     if ((![self hasMarkedText] && fKeyEventsNeeded) || isDeadKey) {
         [self deliverJavaKeyEventHelper: event];
     }
-    
+
     fProcessingKeystroke = NO;
 }
 
@@ -313,7 +313,7 @@
     if (![self hasMarkedText] && !fInPressAndHold) {
         [self deliverJavaKeyEventHelper: event];
     }
-    
+
     // Workaround for 8020209: special case for "Cmd =" and "Cmd ."
     // because Cocoa calls performKeyEquivalent twice for these keystrokes
     NSUInteger modFlags = [event modifierFlags] &
@@ -327,9 +327,9 @@
                 return YES;
             }
         }
-        
+
     }
-    
+
     return NO;
 }
 
@@ -343,36 +343,36 @@
     if ([window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]]) {
         isEnabled = [(AWTWindow*)[window delegate] isEnabled];
     }
-    
+
     if (!isEnabled) {
         return;
     }
-    
+
     NSEventType type = [event type];
-    
+
     // check synthesized mouse entered/exited events
     if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
         return;
     }else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
         mouseIsOver = !mouseIsOver;
     }
-    
+
     [AWTToolkit eventCountPlusPlus];
-    
+
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     NSPoint eventLocation = [event locationInWindow];
     NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
     NSPoint absP = [NSEvent mouseLocation];
-    
+
     // Convert global numbers between Cocoa's coordinate system and Java.
     // TODO: need consitent way for doing that both with global as well as with local coordinates.
     // The reason to do it here is one more native method for getting screen dimension otherwise.
-    
+
     NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame];
     absP.y = screenRect.size.height - absP.y;
     jint clickCount;
-    
+
     if (type == NSMouseEntered ||
         type == NSMouseExited ||
         type == NSScrollWheel ||
@@ -388,7 +388,7 @@
         deltaX = [event scrollingDeltaX] * 0.1;
         deltaY = [event scrollingDeltaY] * 0.1;
     }
-    
+
     static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
     static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
     jobject jEvent = JNFNewObject(env, jctor_NSEvent,
@@ -402,7 +402,7 @@
                                   deltaX,
                                   [AWTToolkit scrollStateWithEvent: event]);
     CHECK_NULL(jEvent);
-    
+
     static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
     static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
     jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);
@@ -418,10 +418,10 @@
         [self removeTrackingArea:rolloverTrackingArea];
         [rolloverTrackingArea release];
     }
-    
+
     int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |
                    NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
-    
+
     rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]
                                                         options: options
                                                           owner:self
@@ -448,17 +448,17 @@
     }
     [sLastKeyEvent release];
     sLastKeyEvent = [event retain];
-    
+
     [AWTToolkit eventCountPlusPlus];
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     jstring characters = NULL;
     jstring charactersIgnoringModifiers = NULL;
     if ([event type] != NSFlagsChanged) {
         characters = JNFNSToJavaString(env, [event characters]);
         charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]);
     }
-    
+
     static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
     static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V");
     jobject jEvent = JNFNewObject(env, jctor_NSEvent,
@@ -468,7 +468,7 @@
                                   characters,
                                   charactersIgnoringModifiers);
     CHECK_NULL(jEvent);
-    
+
     static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
     static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
                             "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
@@ -502,7 +502,7 @@
 
 - (void) drawRect:(NSRect)dirtyRect {
     AWT_ASSERT_APPKIT_THREAD;
-    
+
     [super drawRect:dirtyRect];
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     if (env != NULL) {
@@ -615,17 +615,17 @@
 - (id)accessibilityAttributeValue:(NSString *)attribute
 {
     AWT_ASSERT_APPKIT_THREAD;
-    
+
     if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
     {
         JNIEnv *env = [ThreadUtilities getJNIEnv];
-        
+
         (*env)->PushLocalFrame(env, 4);
-        
+
         id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);
-        
+
         (*env)->PopLocalFrame(env, NULL);
-        
+
         return result;
     }
     else
@@ -642,28 +642,28 @@
 {
     AWT_ASSERT_APPKIT_THREAD;
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     (*env)->PushLocalFrame(env, 4);
-    
+
     id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];
-    
+
     (*env)->PopLocalFrame(env, NULL);
-    
+
     return result;
 }
 
 - (id)accessibilityFocusedUIElement
 {
     AWT_ASSERT_APPKIT_THREAD;
-    
+
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     (*env)->PushLocalFrame(env, 4);
-    
+
     id result = [[self getAxData:env] accessibilityFocusedUIElement];
-    
+
     (*env)->PopLocalFrame(env, NULL);
-    
+
     return result;
 }
 
@@ -702,12 +702,12 @@
 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
 {
     if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
-    
+
     if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
         NSString *selectedText = [self accessibleSelectedText];
         if (selectedText) return self;
     }
-    
+
     return nil;
 }
 
@@ -719,13 +719,13 @@
         [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
         return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];
     }
-    
+
     if ([types containsObject:NSRTFDPboardType])
     {
         [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
         return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
     }
-    
+
     return NO;
 }
 
@@ -737,17 +737,17 @@
         NSString *text = [pboard stringForType:NSStringPboardType];
         return [self replaceAccessibleTextSelection:text];
     }
-    
+
     if ([[pboard types] containsObject:NSRTFDPboardType])
     {
         NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
         NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];
         NSString *text = [styledText string];
         [styledText release];
-        
+
         return [self replaceAccessibleTextSelection:text];
     }
-    
+
     return NO;
 }
 
@@ -769,7 +769,7 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     NSDragOperation dragOp = NSDragOperationNone;
-    
+
     if (dragSource != nil) {
         dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
     }
@@ -781,7 +781,7 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     NSArray* array = nil;
-    
+
     if (dragSource != nil) {
         array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
     }
@@ -792,7 +792,7 @@
 {
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
-    
+
     if (dragSource != nil) {
         [dragSource draggedImage:image beganAt:screenPoint];
     }
@@ -802,7 +802,7 @@
 {
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
-    
+
     if (dragSource != nil) {
         [dragSource draggedImage:image endedAt:screenPoint operation:operation];
     }
@@ -812,7 +812,7 @@
 {
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
-    
+
     if (dragSource != nil) {
         [dragSource draggedImage:image movedTo:screenPoint];
     }
@@ -823,7 +823,7 @@
     // If draggingSource is nil route the message to the superclass (if responding to the selector):
     CDragSource *dragSource = self._dragSource;
     BOOL result = FALSE;
-    
+
     if (dragSource != nil) {
         result = [dragSource ignoreModifierKeysWhileDragging];
     }
@@ -839,7 +839,7 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     NSDragOperation dragOp = NSDragOperationNone;
-    
+
     if (dropTarget != nil) {
         dragOp = [dropTarget draggingEntered:sender];
     }
@@ -851,7 +851,7 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     NSDragOperation dragOp = NSDragOperationNone;
-    
+
     if (dropTarget != nil) {
         dragOp = [dropTarget draggingUpdated:sender];
     }
@@ -862,7 +862,7 @@
 {
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
-    
+
     if (dropTarget != nil) {
         [dropTarget draggingExited:sender];
     }
@@ -873,7 +873,7 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     BOOL result = FALSE;
-    
+
     if (dropTarget != nil) {
         result = [dropTarget prepareForDragOperation:sender];
     }
@@ -885,7 +885,7 @@
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
     BOOL result = FALSE;
-    
+
     if (dropTarget != nil) {
         result = [dropTarget performDragOperation:sender];
     }
@@ -896,7 +896,7 @@
 {
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
-    
+
     if (dropTarget != nil) {
         [dropTarget concludeDragOperation:sender];
     }
@@ -906,7 +906,7 @@
 {
     // If draggingDestination is nil route the message to the superclass:
     CDropTarget *dropTarget = self._dropTarget;
-    
+
     if (dropTarget != nil) {
         [dropTarget draggingEnded:sender];
     }
@@ -924,20 +924,20 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
 #endif // IM_DEBUG
-    
+
     if (fInputMethodLOCKABLE == NULL) {
         return;
     }
-    
+
     // Insert happens at the end of PAH
     fInPressAndHold = NO;
-    
+
     // insertText gets called when the user commits text generated from an input method.  It also gets
     // called during ordinary input as well.  We only need to send an input method event when we have marked
     // text, or 'text in progress'.  We also need to send the event if we get an insert text out of the blue!
     // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
     // Unicode value.
-    
+
     NSMutableString * useString = [self parseString:aString];
     NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
     NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
@@ -946,22 +946,22 @@
         ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
         aStringIsComplex = YES;
     }
-    
+
     if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {
         JNIEnv *env = [ThreadUtilities getJNIEnv];
-        
+
         static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
         // We need to select the previous glyph so that it is overwritten.
         if (fPAHNeedsToSelect) {
             JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
             fPAHNeedsToSelect = NO;
         }
-        
+
         static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
         jstring insertedText =  JNFNSToJavaString(env, useString);
         JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
         (*env)->DeleteLocalRef(env, insertedText);
-        
+
         // The input method event will create psuedo-key events for each character in the committed string.
         // We also don't want to send the character that triggered the insertText, usually a return. [3337563]
         fKeyEventsNeeded = NO;
@@ -993,7 +993,7 @@
 {
     if (!fInputMethodLOCKABLE)
         return;
-    
+
     BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
     NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);
     NSString *incomingString = (isAttributedString ? [aString string] : aString);
@@ -1004,14 +1004,14 @@
     static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");
     static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     // NSInputContext already did the analysis of the TSM event and created attributes indicating
     // the underlining and color that should be done to the string.  We need to look at the underline
     // style and color to determine what kind of Java hilighting needs to be done.
     jstring inProcessText = JNFNSToJavaString(env, incomingString);
     JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
     (*env)->DeleteLocalRef(env, inProcessText);
-    
+
     if (isAttributedString) {
         NSUInteger length;
         NSRange effectiveRange;
@@ -1027,25 +1027,25 @@
                 (NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];
                 NSInteger underlineSize = [underlineSizeObj integerValue];
                 isThickUnderline = (underlineSize > 1);
-                
+
                 NSColor *underlineColorObj =
                 (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];
                 isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);
-                
+
                 JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
             }
         }
     }
-    
+
     static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
     // We need to select the previous glyph so that it is overwritten.
     if (fPAHNeedsToSelect) {
         JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
         fPAHNeedsToSelect = NO;
     }
-    
+
     JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
     // If the marked text is being cleared (zero-length string) don't handle the key event.
     if ([incomingString length] == 0) {
         fKeyEventsNeeded = NO;
@@ -1057,16 +1057,16 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
 #endif // IM_DEBUG
-    
+
     if (!fInputMethodLOCKABLE) {
         return;
     }
-    
+
     // unmarkText cancels any input in progress and commits it to the text field.
     static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
 }
 
 - (BOOL) hasMarkedText
@@ -1074,24 +1074,24 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");
 #endif // IM_DEBUG
-    
+
     if (!fInputMethodLOCKABLE) {
         return NO;
     }
-    
+
     static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");
     static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);
-    
+
     jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);
-    
+
     BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);
-    
+
     if (currentText != NULL) {
         (*env)->DeleteLocalRef(env, currentText);
     }
-    
+
     return hasMarkedText;
 }
 
@@ -1100,7 +1100,7 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");
 #endif // IM_DEBUG
-    
+
     return (NSInteger) self;
 }
 
@@ -1112,16 +1112,16 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
 #endif // IM_DEBUG
-    
+
     static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
     id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];
 #ifdef IM_DEBUG
     NSLog(@"attributedSubstringFromRange returning \"%@\"", result);
 #endif // IM_DEBUG
-    
+
     (*env)->DeleteLocalRef(env, theString);
     return result;
 }
@@ -1131,24 +1131,24 @@
  */
 - (NSRange) markedRange
 {
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");
 #endif // IM_DEBUG
-    
+
     if (!fInputMethodLOCKABLE) {
         return NSMakeRange(NSNotFound, 0);
     }
-    
+
     static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     jarray array;
     jboolean isCopy;
     jint *_array;
     NSRange range = NSMakeRange(NSNotFound, 0);
-    
+
     array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
     if (array) {
         _array = (*env)->GetIntArrayElements(env, array, &isCopy);
         if (_array != NULL) {
@@ -1162,7 +1162,7 @@
         }
         (*env)->DeleteLocalRef(env, array);
     }
-    
+
     return range;
 }
 
@@ -1174,18 +1174,18 @@
     if (!fInputMethodLOCKABLE) {
         return NSMakeRange(NSNotFound, 0);
     }
-    
+
     static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
     jarray array;
     jboolean isCopy;
     jint *_array;
     NSRange range = NSMakeRange(NSNotFound, 0);
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
 #endif // IM_DEBUG
-    
+
     array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
     if (array) {
         _array = (*env)->GetIntArrayElements(env, array, &isCopy);
@@ -1196,7 +1196,7 @@
         }
         (*env)->DeleteLocalRef(env, array);
     }
-    
+
     return range;
 }
 
@@ -1207,7 +1207,7 @@
     if (!fInputMethodLOCKABLE) {
         return NSZeroRect;
     }
-    
+
     static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,
                             "firstRectForCharacterRange", "(I)[I");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
@@ -1215,16 +1215,16 @@
     jboolean isCopy;
     jint *_array;
     NSRect rect;
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr,
             "AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",
             (unsigned long)theRange.location, (unsigned long)theRange.length);
 #endif // IM_DEBUG
-    
+
     array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,
                                 theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
     _array = (*env)->GetIntArrayElements(env, array, &isCopy);
     if (_array) {
         rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));
@@ -1233,7 +1233,7 @@
         rect = NSZeroRect;
     }
     (*env)->DeleteLocalRef(env, array);
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr,
             "firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",
@@ -1250,23 +1250,23 @@
     if (!fInputMethodLOCKABLE) {
         return NSNotFound;
     }
-    
+
     static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,
                             "characterIndexForPoint", "(II)I");
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);
 #endif // IM_DEBUG
-    
+
     jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
-    
+
 #ifdef IM_DEBUG
     fprintf(stderr, "characterIndexForPoint returning %ld\n", index);
 #endif // IM_DEBUG
-    
+
     if (index == -1) {
         return NSNotFound;
     } else {
@@ -1279,7 +1279,7 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");
 #endif // IM_DEBUG
-    
+
     return [NSArray array];
 }
 
@@ -1288,14 +1288,14 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");
 #endif // IM_DEBUG
-    
+
     JNIEnv *env = [ThreadUtilities getJNIEnv];
-    
+
     // Get rid of the old one
     if (fInputMethodLOCKABLE) {
         JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
     }
-    
+
     // Save a global ref to the new input method.
     if (inputMethod != NULL)
         fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
@@ -1308,7 +1308,7 @@
 #ifdef IM_DEBUG
     fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
 #endif // IM_DEBUG
-    
+
     [ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];
     [self unmarkText];
 }
@@ -1330,22 +1330,22 @@
 (JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
 {
     __block AWTView *newView = nil;
-    
+
     JNF_COCOA_ENTER(env);
-    
+
     NSRect rect = NSMakeRect(originX, originY, width, height);
     jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
-    
+
     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-        
+
         CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
         newView = [[AWTView alloc] initWithRect:rect
                                    platformView:cPlatformView
                                     windowLayer:windowLayer];
     }];
-    
+
     JNF_COCOA_EXIT(env);
-    
+
     return ptr_to_jlong(newView);
 }
 
@@ -1360,21 +1360,21 @@
 (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)
 {
     JNF_COCOA_ENTER(env);
-    
+
     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
-    
+
     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
-        
+
         if (toResize) {
             [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
         } else {
             [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
         }
-        
+
         if ([view superview] != nil) {
             [[view superview] setAutoresizesSubviews:(BOOL)toResize];
         }
-        
+
     }];
     JNF_COCOA_EXIT(env);
 }
@@ -1390,19 +1390,19 @@
 (JNIEnv *env, jclass cls, jlong viewPtr)
 {
     __block jint ret; //CGDirectDisplayID
-    
+
     JNF_COCOA_ENTER(env);
-    
+
     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
     NSWindow *window = [view window];
-    
+
     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-        
+
         ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
     }];
-    
+
     JNF_COCOA_EXIT(env);
-    
+
     return ret;
 }
 
@@ -1417,25 +1417,25 @@
 (JNIEnv *env, jclass cls, jlong viewPtr)
 {
     jobject jRect = NULL;
-    
+
     JNF_COCOA_ENTER(env);
-    
+
     __block NSRect rect = NSZeroRect;
-    
+
     NSView *view = (NSView *)jlong_to_ptr(viewPtr);
     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-        
+
         NSRect viewBounds = [view bounds];
         NSRect frameInWindow = [view convertRect:viewBounds toView:nil];
         rect = [[view window] convertRectToScreen:frameInWindow];
-        NSRect screenRect = [[NSScreen mainScreen] frame];
         //Convert coordinates to top-left corner origin
-        rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height;
+        rect = ConvertNSScreenRect(NULL, rect);
+
     }];
     jRect = NSToJavaRect(env, rect);
-    
+
     JNF_COCOA_EXIT(env);
-    
+
     return jRect;
 }
 
@@ -1449,17 +1449,17 @@
 (JNIEnv *env, jclass clazz, jlong viewPtr)
 {
     __block jboolean underMouse = JNI_FALSE;
-    
+
     JNF_COCOA_ENTER(env);
-    
+
     NSView *nsView = OBJC(viewPtr);
-    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){       
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
         NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
         NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
         underMouse = [nsView hitTest:ptViewCoords] != nil;
     }];
-    
+
     JNF_COCOA_EXIT(env);
-    
+
     return underMouse;
 }
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m	Fri Oct 20 19:08:25 2017 -0700
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m	Fri Oct 20 20:08:09 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -134,8 +134,7 @@
     NSPoint absP = [NSEvent mouseLocation];
     NSEventType type = [event type];
 
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    absP.y = screenRect.size.height - absP.y;
+    absP = ConvertNSScreenPoint(NULL, absP);
     jint clickCount;
 
     clickCount = [event clickCount];
@@ -179,15 +178,15 @@
     isHighlighted = NO;
     image = nil;
     trackingArea = nil;
-	
+
     [self addTrackingArea];
-	
+
     return self;
 }
 
 - (void)addTrackingArea {
-    NSTrackingAreaOptions options = NSTrackingMouseMoved | 
-                                    NSTrackingInVisibleRect | 
+    NSTrackingAreaOptions options = NSTrackingMouseMoved |
+                                    NSTrackingInVisibleRect |
                                     NSTrackingActiveAlways;
     trackingArea = [[NSTrackingArea alloc] initWithRect: CGRectZero
                                                 options: options