changeset 1271:188ee39990fe

Fix for RT-22015: workaround for incorrect fullscreen visual bounds
author Lubomir Nerad <lubomir.nerad@oracle.com>
date Wed, 06 Jun 2012 12:14:18 +0200
parents 7eb62ef86e4f
children a4bd88439e22
files javafx-ui-common/src/com/sun/javafx/Utils.java javafx-ui-common/src/javafx/stage/PopupWindow.java javafx-ui-common/test/unit/javafx/stage/PopupTest.java
diffstat 3 files changed, 69 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/Utils.java	Tue Jun 05 18:58:25 2012 -0700
+++ b/javafx-ui-common/src/com/sun/javafx/Utils.java	Wed Jun 06 12:14:18 2012 +0200
@@ -27,7 +27,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Locale;
 
 import javafx.geometry.BoundingBox;
 import javafx.geometry.Bounds;
@@ -40,8 +39,10 @@
 import javafx.scene.paint.Color;
 import javafx.scene.paint.Stop;
 import javafx.stage.Screen;
+import javafx.stage.Stage;
 import javafx.stage.Window;
-import com.sun.javafx.PlatformUtil;
+
+import com.sun.javafx.stage.StageHelper;
 
 /**
  * Some basic utilities which need to be in java (for shifting operations or
@@ -597,7 +598,10 @@
 
         // ...and then we get the bounds of this screen
         final Screen currentScreen = getScreen(parent);
-        final Rectangle2D screenBounds = currentScreen.getVisualBounds();
+        final Rectangle2D screenBounds =
+                hasFullScreenStage(currentScreen)
+                        ? currentScreen.getBounds()
+                        : currentScreen.getVisualBounds();
 
         // test if this layout will force the node to appear outside
         // of the screens bounds. If so, we must reposition the item to a better position.
@@ -797,6 +801,18 @@
         }
     }
 
+    public static boolean hasFullScreenStage(final Screen screen) {
+        final List<Stage> allStages = StageHelper.getStages();
+
+        for (final Stage stage: allStages) {
+            if (stage.isFullScreen() && (getScreen(stage) == screen)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /*
      * Returns true if the primary Screen has VGA dimensions, in landscape or portrait mode.
      */
--- a/javafx-ui-common/src/javafx/stage/PopupWindow.java	Tue Jun 05 18:58:25 2012 -0700
+++ b/javafx-ui-common/src/javafx/stage/PopupWindow.java	Wed Jun 06 12:14:18 2012 +0200
@@ -339,6 +339,9 @@
 
     private void showImpl(final Window owner) {
         if (isShowing()) {
+            if (autofixHandler != null) {
+                autofixHandler.adjustPosition();
+            }
             return;
         }
 
@@ -349,8 +352,7 @@
         }
 
         // It is required that the root window exist and be visible to show the popup.
-        Window rootWindow = getRootWindow(getOwnerWindow());
-        if (rootWindow != null && rootWindow.isShowing()) {
+        if (getRootWindow(owner).isShowing()) {
             // We do show() first so that the width and height of the
             // popup window are initialized. This way the x,y location of the
             // popup calculated below uses the right width and height values for
@@ -397,7 +399,7 @@
         }
     }
 
-    private Window focusGrabWindow;
+    private Window rootWindow;
 
     /**
      * @treatAsPrivate implementation detail
@@ -413,6 +415,8 @@
 
         final Window ownerWindowValue = getOwnerWindow();
         if (visible) {
+            rootWindow = getRootWindow(ownerWindowValue);
+
             startMonitorOwnerEvents(ownerWindowValue);
             // currently we consider popup window to be focused when it is
             // visible and its owner window is focused (we need to track
@@ -421,17 +425,15 @@
             // track focus state across multiple windows
             bindOwnerFocusedProperty(ownerWindowValue);
             setFocused(ownerWindowValue.isFocused());
-            focusGrabWindow = increaseFocusGrabInRootWindow(ownerWindowValue);
             handleAutofixActivation(true, isAutoFix());
+            rootWindow.impl_increaseFocusGrabCounter();
         } else {
             stopMonitorOwnerEvents(ownerWindowValue);
             unbindOwnerFocusedProperty(ownerWindowValue);
             setFocused(false);
-            if (focusGrabWindow != null) {
-                focusGrabWindow.impl_decreaseFocusGrabCounter();
-                focusGrabWindow = null;
-            }
             handleAutofixActivation(false, isAutoFix());
+            rootWindow.impl_decreaseFocusGrabCounter();
+            rootWindow = null;
         }
 
         PerformanceTracker.logEvent("PopupWindow.storeVisible for [PopupWindow] finished");
@@ -506,15 +508,6 @@
         parentEventRedirector.removeEventDispatcher(getEventDispatcher());
     }
 
-    private Window increaseFocusGrabInRootWindow(final Window ownerWindow) {
-        final Window rootWindow = getRootWindow(ownerWindow);
-        if (rootWindow != null) {
-            rootWindow.impl_increaseFocusGrabCounter();
-        }
-
-        return rootWindow;
-    }
-
     private ChangeListener<Boolean> ownerFocusedListener;
 
     private void bindOwnerFocusedProperty(final Window ownerWindowValue) {
@@ -607,7 +600,10 @@
         public void adjustPosition() {
             final Screen currentScreen =
                     Utils.getScreenForPoint(getX(), getY());
-            final Rectangle2D screenBounds = currentScreen.getVisualBounds();
+            final Rectangle2D screenBounds =
+                    Utils.hasFullScreenStage(currentScreen)
+                            ? currentScreen.getBounds()
+                            : currentScreen.getVisualBounds();
             double _x = Math.min(getX(), screenBounds.getMaxX() - getWidth());
             double _y = Math.min(getY(), screenBounds.getMaxY() - getHeight());
             _x = Math.max(_x, screenBounds.getMinX());
--- a/javafx-ui-common/test/unit/javafx/stage/PopupTest.java	Tue Jun 05 18:58:25 2012 -0700
+++ b/javafx-ui-common/test/unit/javafx/stage/PopupTest.java	Wed Jun 06 12:14:18 2012 +0200
@@ -312,6 +312,25 @@
     }
 
     @Test
+    public void testDoubleShowAutofix() {
+        toolkit.setScreens(
+                new ScreenConfiguration(0, 0, 1920, 1200,
+                                        0, 200, 1920, 1000,
+                                        96));
+
+        final Popup popup = new Popup();
+        popup.getContent().add(new Rectangle(0, 0, 50, 50));
+
+        popup.show(stage, 1900, 100);
+        assertEquals(1920, popup.getX() + popup.getWidth(), 1e-100);
+        assertEquals(200, popup.getY(), 1e-100);
+
+        popup.show(stage, 1900, 100);
+        assertEquals(1920, popup.getX() + popup.getWidth(), 1e-100);
+        assertEquals(200, popup.getY(), 1e-100);
+    }
+
+    @Test
     public void testAutofixActivationAfterShow() {
         toolkit.setScreens(
                 new ScreenConfiguration(0, 0, 1920, 1200,
@@ -372,6 +391,23 @@
     }
 
     @Test
+    public void testAutofixWithFullScreen() {
+        toolkit.setScreens(
+                new ScreenConfiguration(0, 0, 1920, 1200,
+                                        0, 0, 1920, 1172,
+                                        96));
+
+        final Popup popup = new Popup();
+        popup.getContent().add(new Rectangle(0, 0, 50, 50));
+
+        stage.setFullScreen(true);
+        popup.show(stage, 100, 1160);
+
+        assertEquals(100, popup.getX(), 1e-100);
+        assertEquals(1150, popup.getY(), 1e-100);
+    }
+
+    @Test
     public void testSetPopupContentByChangingRootNode() {
         final Popup popup = new Popup();