提交 87452bfe 编写于 作者: S serb

8221823: Requested JDialog width is ignored

Reviewed-by: aivanov
上级 764187ea
/*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, 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
......@@ -22,13 +22,19 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.windows;
import java.awt.*;
import java.awt.peer.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.SystemColor;
import java.awt.Window;
import java.awt.peer.DialogPeer;
import sun.awt.*;
import sun.awt.im.*;
import sun.awt.AWTAccessor;
import sun.awt.im.InputMethodManager;
final class WDialogPeer extends WWindowPeer implements DialogPeer {
// Toolkit & peer internals
......@@ -110,9 +116,9 @@ final class WDialogPeer extends WWindowPeer implements DialogPeer {
public Dimension getMinimumSize() {
if (((Dialog)target).isUndecorated()) {
return super.getMinimumSize();
} else {
return new Dimension(getSysMinWidth(), getSysMinHeight());
}
return new Dimension(scaleDownX(getSysMinWidth()),
scaleDownY(getSysMinHeight()));
}
@Override
......
......@@ -147,13 +147,14 @@ class WFramePeer extends WWindowPeer implements FramePeer {
}
@Override
public Dimension getMinimumSize() {
public final Dimension getMinimumSize() {
Dimension d = new Dimension();
if (!((Frame)target).isUndecorated()) {
d.setSize(getSysMinWidth(), getSysMinHeight());
d.setSize(scaleDownX(getSysMinWidth()),
scaleDownY(getSysMinHeight()));
}
if (((Frame)target).getMenuBar() != null) {
d.height += getSysMenuHeight();
d.height += scaleDownY(getSysMenuHeight());
}
return d;
}
......
/*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, 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
......@@ -402,10 +402,8 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
minimumSize = ((Component)target).getMinimumSize();
}
if (minimumSize != null) {
int msw = getSysMinWidth();
int msh = getSysMinHeight();
int w = (minimumSize.width >= msw) ? minimumSize.width : msw;
int h = (minimumSize.height >= msh) ? minimumSize.height : msh;
int w = Math.max(minimumSize.width, scaleDownX(getSysMinWidth()));
int h = Math.max(minimumSize.height, scaleDownY(getSysMinHeight()));
setMinSize(w, h);
} else {
setMinSize(0, 0);
......@@ -687,6 +685,22 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
}
}
final int scaleUpX(int x) {
return Region.clipRound(x * scaleX);
}
final int scaleUpY(int y) {
return Region.clipRound(y * scaleY);
}
final int scaleDownX(int x) {
return Region.clipRound(x / scaleX);
}
final int scaleDownY(int y) {
return Region.clipRound(y / scaleY);
}
@Override
public void print(Graphics g) {
// We assume we print the whole frame,
......
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, 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
......@@ -2565,8 +2565,8 @@ void AwtWindow::_ReshapeFrame(void *param)
if (!p->IsEmbeddedFrame())
{
jobject peer = p->GetPeer(env);
int minWidth = ::GetSystemMetrics(SM_CXMIN);
int minHeight = ::GetSystemMetrics(SM_CYMIN);
int minWidth = p->ScaleDownX(::GetSystemMetrics(SM_CXMIN));
int minHeight = p->ScaleDownY(::GetSystemMetrics(SM_CYMIN));
if (w < minWidth)
{
env->SetIntField(target, AwtComponent::widthID,
......@@ -3857,7 +3857,7 @@ Java_sun_awt_windows_WWindowPeer_setOpacity(JNIEnv *env, jobject self,
os->iOpacity = iOpacity;
AwtToolkit::GetInstance().SyncCall(AwtWindow::_SetOpacity, os);
// global refs and mds are deleted in _SetMinSize
// global refs and mds are deleted in _SetOpacity
CATCH_BAD_ALLOC;
}
......@@ -3878,7 +3878,7 @@ Java_sun_awt_windows_WWindowPeer_setOpaqueImpl(JNIEnv *env, jobject self,
os->isOpaque = isOpaque;
AwtToolkit::GetInstance().SyncCall(AwtWindow::_SetOpaque, os);
// global refs and mds are deleted in _SetMinSize
// global refs and mds are deleted in _SetOpaque
CATCH_BAD_ALLOC;
}
......
......@@ -517,8 +517,6 @@ com/apple/eawt/DefaultMenuBar/DefaultMenuBarTest.java 8233648 macosx-all
java/awt/Choice/ChoiceKeyEventReaction/ChoiceKeyEventReaction.java 7185258 macosx-all
java/awt/TrayIcon/RightClickWhenBalloonDisplayed/RightClickWhenBalloonDisplayed.java 8238720 windows-all
java/awt/PopupMenu/PopupMenuLocation.java 8238720 windows-all
java/awt/Mixing/AWT_Mixing/MixingFrameResizing.java 8238720 windows-all
java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java 8238720 windows-all
java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java 8238720 windows-all
java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java 8238720 windows-all
java/awt/event/MouseEvent/FrameMouseEventAbsoluteCoordsTest/FrameMouseEventAbsoluteCoordsTest.java
......
......@@ -35,7 +35,7 @@ import java.io.*;
/*
* @test
* @key headful
* @bug 6768230
* @bug 6768230 8221823
* @summary Mixing test for HierarchyBoundsListener ancestors
* @build FrameBorderCounter
* @run main HierarchyBoundsListenerMixingTest
......
......@@ -39,7 +39,7 @@ import test.java.awt.regtesthelpers.Util;
/*
* @test
* @key headful
* @bug 6777370
* @bug 6777370 8221823
* @summary Issues when resizing the JFrame with HW components
* @author sergey.grinev@oracle.com: area=awt.mixing
* @library /java/awt/patchlib ../../regtesthelpers
......
......@@ -35,7 +35,7 @@ import test.java.awt.regtesthelpers.Util;
/*
* @test
* @key headful
* @bug 6786219
* @bug 6786219 8221823
* @summary Issues when resizing the frame after mixing of heavy weight & light weight components
* @author sergey.grinev@oracle.com: area=awt.mixing
* @library ../../regtesthelpers
......
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Window;
import java.util.List;
import java.util.concurrent.TimeUnit;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/**
* @test
* @bug 8221823
* @key headful
* @summary Verifies TOP level component's minimumSize using different DPI
* @library /test/lib
* @run main/othervm -Dsun.java2d.uiScale=1 MinimumSizeDPIVariation
*/
public final class MinimumSizeDPIVariation {
public static void main(String[] args) throws Exception {
if (args.length == 0) {
Dimension minimumSize = test(new Frame());
checkAllDPI("frame", minimumSize.width, minimumSize.height);
minimumSize = test(new Window(null));
checkAllDPI("window", minimumSize.width, minimumSize.height);
minimumSize = test(new Dialog((Frame) null));
checkAllDPI("dialog", minimumSize.width, minimumSize.height);
} else {
String comp = args[0];
int w = Integer.parseInt(args[1]);
int h = Integer.parseInt(args[2]);
double scale = Double.parseDouble(args[3]);
System.err.println("comp = " + comp);
System.err.println("scale = " + scale);
Dimension minimumSize = null;
switch (comp) {
case "frame": minimumSize = test(new Frame()); break;
case "window": minimumSize = test(new Window(null)); break;
case "dialog": minimumSize = test(new Dialog((Frame) null)); break;
default: throw new java.lang.IllegalStateException(
"Unexpected value: " + comp);
};
check(minimumSize.width, Math.max(w / scale, 1));
check(minimumSize.height, Math.max(h / scale, 1));
}
}
private static Dimension test(Window window) {
try {
window.setLayout(null); // trigger use the minimum size of the peer
window.setSize(new Dimension(1, 1));
window.pack();
Dimension minimumSize = window.getMinimumSize();
Dimension size = window.getSize();
if (!minimumSize.equals(size)) {
System.err.println(window);
System.err.println("Expected: " + minimumSize);
System.err.println("Actual: " + size);
throw new RuntimeException("Wrong size");
}
return minimumSize;
} finally {
window.dispose();
}
}
private static void check(int actual, double expected) {
double i = 100 * (actual - expected) / expected;
if (Math.abs(i) > 10) { // no more than 10% variation
System.err.println("Expected: " + expected);
System.err.println("Actual: " + actual);
throw new RuntimeException("Difference is too big: " + i);
}
}
private static void checkAllDPI(String comp, int w, int h)
throws Exception {
if (!Platform.isOSX()) {
for (String dpi : List.of("1.5", "1.75", "2", "2.5")) {
runPocess(dpi, comp, w, h);
}
}
}
private static void runPocess(String dpi, String comp, int w, int h)
throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Dsun.java2d.uiScale=" + dpi,
MinimumSizeDPIVariation.class.getSimpleName(), comp,
String.valueOf(w), String.valueOf(h), dpi);
Process worker = ProcessTools.startProcess("Worker", pb, null, 20,
TimeUnit.SECONDS);
new OutputAnalyzer(worker).shouldHaveExitValue(0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册