jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
changeset 39511 a7ad23d3d161
parent 38987 ffe8b158dd6a
child 40446 cf666940a804
--- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m	Thu Jun 09 13:54:48 2016 +0300
+++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m	Thu Jun 09 14:21:42 2016 +0300
@@ -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
@@ -55,6 +55,11 @@
 // window or the app currently has no key window.
 static AWTWindow* lastKeyWindow = nil;
 
+// This variable contains coordinates of a window's top left
+// which was positioned via java.awt.Window.setLocationByPlatform.
+// It would be NSZeroPoint if 'Location by Platform' is not used.
+static NSPoint lastTopLeftPoint;
+
 // --------------------------------------------------------------
 // NSWindow/NSPanel descendants implementation
 #define AWT_NS_WINDOW_IMPLEMENTATION                            \
@@ -1084,6 +1089,31 @@
 
 /*
  * Class:     sun_lwawt_macosx_CPlatformWindow
+ * Method:    nativeSetNSWindowLocationByPlatform
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform
+(JNIEnv *env, jclass clazz, jlong windowPtr)
+{
+    JNF_COCOA_ENTER(env);
+
+    NSWindow *nsWindow = OBJC(windowPtr);
+    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+
+        if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
+            // This is the first usage of lastTopLeftPoint. So invoke cascadeTopLeftFromPoint
+            // twice to avoid positioning the window's top left to zero-point, since it may
+            // cause negative user experience.
+            lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
+        }
+        lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
+    }];
+
+    JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CPlatformWindow
  * Method:    nativeSetNSWindowMinMax
  * Signature: (JDDDD)V
  */