changeset 1558:e0636bb69562

6818787: It is possible to reposition the security icon too far from the border of the window on X11 Summary: The constraints for the position of the icon are moved to the shared code Reviewed-by: art, dcherepanov
author anthony
date Tue, 05 May 2009 17:56:31 +0400
parents 38a0e21f345a
children 4b498e41c1c2
files src/share/classes/java/awt/Window.java src/windows/native/sun/windows/awt_Window.cpp
diffstat 2 files changed, 47 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/Window.java	Tue May 05 17:47:04 2009 +0400
+++ b/src/share/classes/java/awt/Window.java	Tue May 05 17:56:31 2009 +0400
@@ -3593,16 +3593,56 @@
 
     // ****************** END OF MIXING CODE ********************************
 
-    // This method gets the window location/size as reported by the native
-    // system since the locally cached values may represent outdated data.
-    // NOTE: this method is invoked on the toolkit thread, and therefore
-    // is not supposed to become public/user-overridable.
+    /**
+     * Limit the given double value with the given range.
+     */
+    private static double limit(double value, double min, double max) {
+        value = Math.max(value, min);
+        value = Math.min(value, max);
+        return value;
+    }
+
+    /**
+     * Calculate the position of the security warning.
+     *
+     * This method gets the window location/size as reported by the native
+     * system since the locally cached values may represent outdated data.
+     *
+     * The method is used from the native code, or via AWTAccessor.
+     *
+     * NOTE: this method is invoked on the toolkit thread, and therefore is not
+     * supposed to become public/user-overridable.
+     */
     private Point2D calculateSecurityWarningPosition(double x, double y,
             double w, double h)
     {
-        return new Point2D.Double(
-                x + w * securityWarningAlignmentX + securityWarningPointX,
-                y + h * securityWarningAlignmentY + securityWarningPointY);
+        // The position according to the spec of SecurityWarning.setPosition()
+        double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
+        double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
+
+        // First, make sure the warning is not too far from the window bounds
+        wx = Window.limit(wx,
+                x - securityWarningWidth - 2,
+                x + w + 2);
+        wy = Window.limit(wy,
+                y - securityWarningHeight - 2,
+                y + h + 2);
+
+        // Now make sure the warning window is visible on the screen
+        Rectangle screenBounds = graphicsConfig.getBounds();
+        Insets screenInsets =
+            Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
+
+        wx = Window.limit(wx,
+                screenBounds.x + screenInsets.left,
+                screenBounds.x + screenBounds.width - screenInsets.right
+                - securityWarningWidth);
+        wy = Window.limit(wy,
+                screenBounds.y + screenInsets.top,
+                screenBounds.y + screenBounds.height - screenInsets.bottom
+                - securityWarningHeight);
+
+        return new Point2D.Double(wx, wy);
     }
 
     static {
--- a/src/windows/native/sun/windows/awt_Window.cpp	Tue May 05 17:47:04 2009 +0400
+++ b/src/windows/native/sun/windows/awt_Window.cpp	Tue May 05 17:56:31 2009 +0400
@@ -707,31 +707,6 @@
 
     env->DeleteLocalRef(point2D);
 
-    //Make sure the warning is not far from the window bounds
-    x = max(x, windowBounds.left - (int)warningWindowWidth - 2);
-    x = min(x, windowBounds.right + (int)warningWindowWidth + 2);
-
-    y = max(y, windowBounds.top - (int)warningWindowHeight - 2);
-    y = min(y, windowBounds.bottom + (int)warningWindowHeight + 2);
-
-    // Now make sure the warning window is visible on the screen
-    HMONITOR hmon = MonitorFromWindow(GetHWnd(), MONITOR_DEFAULTTOPRIMARY);
-    DASSERT(hmon != NULL);
-
-    RECT monitorBounds;
-    RECT monitorInsets;
-
-    MonitorBounds(hmon, &monitorBounds);
-    if (!AwtToolkit::GetScreenInsets(m_screenNum, &monitorInsets)) {
-        ::ZeroMemory(&monitorInsets, sizeof(monitorInsets));
-    }
-
-    x = max(x, monitorBounds.left + monitorInsets.left);
-    x = min(x, monitorBounds.right - monitorInsets.right - (int)warningWindowWidth);
-
-    y = max(y, monitorBounds.top + monitorInsets.top);
-    y = min(y, monitorBounds.bottom - monitorInsets.bottom - (int)warningWindowHeight);
-
     rect->left = x;
     rect->top = y;
     rect->right = rect->left + warningWindowWidth;