mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-15 04:45:25 +00:00
8288325: [windows] Actual and Preferred Size of AWT Non-resizable frame are different
Reviewed-by: kizune, aivanov, tr
This commit is contained in:
parent
2e20e7ec0f
commit
eca9749da0
@ -1388,7 +1388,6 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
|
||||
*/
|
||||
RECT outside;
|
||||
RECT inside;
|
||||
int extraBottomInsets = 0;
|
||||
|
||||
// extra padded border for captioned windows
|
||||
int extraPaddedBorderInsets = ::GetSystemMetrics(SM_CXPADDEDBORDER);
|
||||
@ -1400,12 +1399,13 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
|
||||
if (outside.right - outside.left > 0 && outside.bottom - outside.top > 0) {
|
||||
::MapWindowPoints(GetHWnd(), 0, (LPPOINT)&inside, 2);
|
||||
m_insets.top = inside.top - outside.top;
|
||||
m_insets.bottom = outside.bottom - inside.bottom + extraBottomInsets;
|
||||
m_insets.bottom = outside.bottom - inside.bottom;
|
||||
m_insets.left = inside.left - outside.left;
|
||||
m_insets.right = outside.right - inside.right;
|
||||
} else {
|
||||
m_insets.top = -1;
|
||||
}
|
||||
|
||||
if (m_insets.left < 0 || m_insets.top < 0 ||
|
||||
m_insets.right < 0 || m_insets.bottom < 0)
|
||||
{
|
||||
@ -1413,18 +1413,11 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
|
||||
jobject target = GetTarget(env);
|
||||
if (IsUndecorated() == FALSE) {
|
||||
/* Get outer frame sizes. */
|
||||
LONG style = GetStyle();
|
||||
if (style & WS_THICKFRAME) {
|
||||
m_insets.left = m_insets.right =
|
||||
::GetSystemMetrics(SM_CXSIZEFRAME) + extraPaddedBorderInsets;
|
||||
m_insets.top = m_insets.bottom =
|
||||
::GetSystemMetrics(SM_CYSIZEFRAME) + extraPaddedBorderInsets;
|
||||
} else {
|
||||
m_insets.left = m_insets.right =
|
||||
::GetSystemMetrics(SM_CXDLGFRAME) + extraPaddedBorderInsets;
|
||||
m_insets.top = m_insets.bottom =
|
||||
::GetSystemMetrics(SM_CYDLGFRAME) + extraPaddedBorderInsets;
|
||||
}
|
||||
// System metrics are same for resizable & non-resizable frame.
|
||||
m_insets.left = m_insets.right =
|
||||
::GetSystemMetrics(SM_CXFRAME) + extraPaddedBorderInsets;
|
||||
m_insets.top = m_insets.bottom =
|
||||
::GetSystemMetrics(SM_CYFRAME) + extraPaddedBorderInsets;
|
||||
/* Add in title. */
|
||||
m_insets.top += ::GetSystemMetrics(SM_CYCAPTION);
|
||||
}
|
||||
@ -1432,7 +1425,7 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
|
||||
/* fix for 4418125: Undecorated frames are off by one */
|
||||
/* undo the -1 set above */
|
||||
/* Additional fix for 5059656 */
|
||||
/* Also, 5089312: Window insets should be 0. */
|
||||
/* Also, 5089312: Window insets should be 0. */
|
||||
::memset(&m_insets, 0, sizeof(m_insets));
|
||||
}
|
||||
|
||||
@ -1445,7 +1438,6 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
|
||||
env->DeleteLocalRef(target);
|
||||
return FALSE;
|
||||
}
|
||||
m_insets.bottom += extraBottomInsets;
|
||||
env->DeleteLocalRef(target);
|
||||
}
|
||||
|
||||
|
||||
@ -39,21 +39,37 @@ import javax.imageio.ImageIO;
|
||||
* @test
|
||||
* @bug 8265586
|
||||
* @key headful
|
||||
* @summary Tests whether insets are calculated correctly on Windows
|
||||
* for AWT Frame by checking the actual and expected/preferred frame sizes.
|
||||
* @summary Tests whether correct native frame insets are obtained
|
||||
* for Resizable & Non-Resizable AWT Frame by checking the actual
|
||||
* and expected/preferred frame sizes.
|
||||
* @run main AwtFramePackTest
|
||||
*/
|
||||
|
||||
public class AwtFramePackTest {
|
||||
|
||||
private static Frame frame;
|
||||
private static Robot robot;
|
||||
private static StringBuffer errorLog = new StringBuffer();
|
||||
|
||||
public static void main(String[] args) throws AWTException {
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(300);
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(300);
|
||||
|
||||
// Resizable frame
|
||||
createAWTFrame(true);
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
|
||||
// Non-Resizable frame
|
||||
createAWTFrame(false);
|
||||
|
||||
if (!errorLog.isEmpty()) {
|
||||
throw new RuntimeException("Test failed due to the following" +
|
||||
" one or more errors: \n" + errorLog);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAWTFrame(boolean isResizable) {
|
||||
try {
|
||||
frame = new Frame();
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
@ -67,32 +83,36 @@ public class AwtFramePackTest {
|
||||
mb.add(m);
|
||||
frame.setMenuBar(mb);
|
||||
|
||||
frame.setResizable(isResizable);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
robot.delay(500);
|
||||
robot.waitForIdle();
|
||||
robot.delay(500);
|
||||
|
||||
Dimension actualFrameSize = frame.getSize();
|
||||
Dimension expectedFrameSize = frame.getPreferredSize();
|
||||
|
||||
if (!actualFrameSize.equals(expectedFrameSize)) {
|
||||
System.out.println("Expected frame size: "+ expectedFrameSize);
|
||||
System.out.println("Actual frame size: "+ actualFrameSize);
|
||||
saveScreenCapture();
|
||||
throw new RuntimeException("Expected and Actual frame size" +
|
||||
" are different. frame.pack() does not work!!");
|
||||
String frameType = isResizable ? "ResizableFrame" : "NonResizableFrame";
|
||||
System.out.println("Expected frame size: " + expectedFrameSize);
|
||||
System.out.println("Actual frame size: " + actualFrameSize);
|
||||
saveScreenCapture(frameType + ".png");
|
||||
errorLog.append(frameType + ": Expected and Actual frame size" +
|
||||
" are different. frame.pack() does not work!! \n");
|
||||
}
|
||||
} finally {
|
||||
frame.dispose();
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for debugging purpose, saves screen capture when test fails.
|
||||
private static void saveScreenCapture() {
|
||||
private static void saveScreenCapture(String filename) {
|
||||
BufferedImage image = robot.createScreenCapture(frame.getBounds());
|
||||
try {
|
||||
ImageIO.write(image,"png", new File("Frame.png"));
|
||||
ImageIO.write(image,"png", new File(filename));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user