mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8225126: Test SetBoundsPaintTest.html faild on Windows when desktop is scaled
Reviewed-by: jdv
This commit is contained in:
parent
060e4ec305
commit
080c16d36d
4 changed files with 138 additions and 67 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -22,14 +22,19 @@
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sun.awt.windows;
|
package sun.awt.windows;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Choice;
|
||||||
import java.awt.peer.*;
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Window;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.event.WindowListener;
|
import java.awt.event.WindowListener;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.peer.ChoicePeer;
|
||||||
|
|
||||||
import sun.awt.AWTAccessor;
|
import sun.awt.AWTAccessor;
|
||||||
import sun.awt.SunToolkit;
|
import sun.awt.SunToolkit;
|
||||||
|
@ -154,12 +159,5 @@ final class WChoicePeer extends WComponentPeer implements ChoicePeer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDropDownHeight() {
|
|
||||||
Choice c = (Choice)target;
|
|
||||||
FontMetrics fm = getFontMetrics(c.getFont());
|
|
||||||
int maxItems = Math.min(c.getItemCount(), 8);
|
|
||||||
return fm.getHeight() * maxItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
native void closeList();
|
native void closeList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -177,8 +177,8 @@ AwtChoice* AwtChoice::Create(jobject peer, jobject parent) {
|
||||||
* Fix: Set the Choice to its actual size in the component.
|
* Fix: Set the Choice to its actual size in the component.
|
||||||
*/
|
*/
|
||||||
::GetClientRect(c->GetHWnd(), &rc);
|
::GetClientRect(c->GetHWnd(), &rc);
|
||||||
env->SetIntField(target, AwtComponent::widthID, (jint) rc.right);
|
env->SetIntField(target, AwtComponent::widthID, c->ScaleDownX(rc.right));
|
||||||
env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom);
|
env->SetIntField(target, AwtComponent::heightID, c->ScaleDownY(rc.bottom));
|
||||||
|
|
||||||
if (IS_WINXP) {
|
if (IS_WINXP) {
|
||||||
::SendMessage(c->GetHWnd(), CB_SETMINVISIBLE, (WPARAM) MINIMUM_NUMBER_OF_VISIBLE_ITEMS, 0);
|
::SendMessage(c->GetHWnd(), CB_SETMINVISIBLE, (WPARAM) MINIMUM_NUMBER_OF_VISIBLE_ITEMS, 0);
|
||||||
|
@ -228,13 +228,11 @@ int AwtChoice::GetTotalHeight()
|
||||||
{
|
{
|
||||||
int dropHeight = GetDropDownHeight();
|
int dropHeight = GetDropDownHeight();
|
||||||
int fieldHeight = GetFieldHeight();
|
int fieldHeight = GetFieldHeight();
|
||||||
int totalHeight;
|
|
||||||
|
|
||||||
// border on drop-down portion is always non-3d (so don't use SM_CYEDGE)
|
// border on drop-down portion is always non-3d (so don't use SM_CYEDGE)
|
||||||
int borderHeight = ::GetSystemMetrics(SM_CYBORDER);
|
int borderHeight = ScaleDownY(::GetSystemMetrics(SM_CYBORDER));
|
||||||
// total height = drop down height + field height + top+bottom drop down border lines
|
// total height = drop down height + field height + top+bottom drop down border lines
|
||||||
totalHeight = dropHeight + fieldHeight +borderHeight*2;
|
return dropHeight + fieldHeight + borderHeight * 2;
|
||||||
return totalHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate and set the drop-down height for the Choice.
|
// Recalculate and set the drop-down height for the Choice.
|
||||||
|
@ -244,7 +242,7 @@ void AwtChoice::ResetDropDownHeight()
|
||||||
|
|
||||||
::GetWindowRect(GetHWnd(), &rcWindow);
|
::GetWindowRect(GetHWnd(), &rcWindow);
|
||||||
// resize the drop down to accommodate added/removed items
|
// resize the drop down to accommodate added/removed items
|
||||||
int totalHeight = GetTotalHeight();
|
int totalHeight = ScaleUpY(GetTotalHeight());
|
||||||
::SetWindowPos(GetHWnd(), NULL,
|
::SetWindowPos(GetHWnd(), NULL,
|
||||||
0, 0, rcWindow.right - rcWindow.left, totalHeight,
|
0, 0, rcWindow.right - rcWindow.left, totalHeight,
|
||||||
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
||||||
|
@ -305,11 +303,11 @@ void AwtChoice::Reshape(int x, int y, int w, int h)
|
||||||
BOOL bReshape = true;
|
BOOL bReshape = true;
|
||||||
if (awtParent != NULL) {
|
if (awtParent != NULL) {
|
||||||
::GetWindowRect(GetHWnd(), &rc);
|
::GetWindowRect(GetHWnd(), &rc);
|
||||||
int oldW = rc.right - rc.left;
|
int oldW = ScaleDownX(rc.right - rc.left);
|
||||||
RECT parentRc;
|
RECT parentRc;
|
||||||
::GetWindowRect(awtParent->GetHWnd(), &parentRc);
|
::GetWindowRect(awtParent->GetHWnd(), &parentRc);
|
||||||
int oldX = rc.left - parentRc.left;
|
int oldX = ScaleDownX(rc.left - parentRc.left);
|
||||||
int oldY = rc.top - parentRc.top;
|
int oldY = ScaleDownY(rc.top - parentRc.top);
|
||||||
bReshape = (x != oldX || y != oldY || w != oldW);
|
bReshape = (x != oldX || y != oldY || w != oldW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -24,62 +24,72 @@
|
||||||
/*
|
/*
|
||||||
@test
|
@test
|
||||||
@key headful
|
@key headful
|
||||||
@bug 4851798 8041896
|
@bug 4851798 8041896 8225126
|
||||||
@summary Tests Choice List shrinks after removeAll
|
@summary Tests Choice List shrinks after removeAll
|
||||||
@run main RemoveAllShrinkTest
|
@run main RemoveAllShrinkTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import java.awt.Choice;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.Panel;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
|
||||||
public class RemoveAllShrinkTest {
|
public class RemoveAllShrinkTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Frame f = new Frame();
|
Frame f = new Frame();
|
||||||
Choice choice = new Choice();
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
|
||||||
choice.addItem("Item " + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
f.add(choice, BorderLayout.NORTH);
|
|
||||||
Panel panel = new Panel();
|
|
||||||
panel.setBackground(Color.RED);
|
|
||||||
f.add(panel);
|
|
||||||
|
|
||||||
f.setSize(200, 200);
|
|
||||||
f.setVisible(true);
|
|
||||||
f.toFront();
|
|
||||||
|
|
||||||
choice.removeAll();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Robot robot = new Robot();
|
Choice choice = new Choice();
|
||||||
robot.setAutoWaitForIdle(true);
|
|
||||||
robot.setAutoDelay(50);
|
|
||||||
|
|
||||||
robot.waitForIdle();
|
for (int i = 0; i < 10; ++i) {
|
||||||
Thread.sleep(200);
|
choice.addItem("Item " + i);
|
||||||
|
|
||||||
Point pt = choice.getLocationOnScreen();
|
|
||||||
robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight() / 2,
|
|
||||||
pt.y + choice.getHeight() / 2);
|
|
||||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
|
||||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
|
||||||
|
|
||||||
Thread.sleep(400);
|
|
||||||
|
|
||||||
Point pt1 = panel.getLocationOnScreen();
|
|
||||||
|
|
||||||
Color color = robot.getPixelColor(pt1.x + panel.getWidth() / 2,
|
|
||||||
pt1.y + panel.getHeight() / 2);
|
|
||||||
|
|
||||||
if (!color.equals(Color.RED)) {
|
|
||||||
throw new RuntimeException("RemoveAllShrinkTest failed. " + color);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("The test was not completed.\n\n" + e);
|
f.add(choice, BorderLayout.NORTH);
|
||||||
|
Panel panel = new Panel();
|
||||||
|
panel.setBackground(Color.RED);
|
||||||
|
f.add(panel);
|
||||||
|
|
||||||
|
f.setSize(200, 200);
|
||||||
|
f.setLocationRelativeTo(null);
|
||||||
|
f.setVisible(true);
|
||||||
|
f.toFront();
|
||||||
|
|
||||||
|
choice.removeAll();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
robot.setAutoWaitForIdle(true);
|
||||||
|
robot.setAutoDelay(50);
|
||||||
|
|
||||||
|
robot.waitForIdle();
|
||||||
|
Thread.sleep(200);
|
||||||
|
|
||||||
|
Point pt = choice.getLocationOnScreen();
|
||||||
|
robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight() / 2,
|
||||||
|
pt.y + choice.getHeight() / 2);
|
||||||
|
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||||
|
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||||
|
|
||||||
|
Thread.sleep(400);
|
||||||
|
|
||||||
|
Point pt1 = panel.getLocationOnScreen();
|
||||||
|
|
||||||
|
Color color = robot.getPixelColor(pt1.x + panel.getWidth() / 2,
|
||||||
|
pt1.y + panel.getHeight() / 2);
|
||||||
|
|
||||||
|
if (!color.equals(Color.RED)) {
|
||||||
|
throw new RuntimeException("RemoveAllShrinkTest failed. " + color);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("The test was not completed.\n\n" + e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
f.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003, 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.Choice;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 4790927 4783342 4930678 8225126
|
||||||
|
* @key headful
|
||||||
|
* @summary Tests Choice doesn't flash
|
||||||
|
*/
|
||||||
|
public final class SetBoundsPaintTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
CountDownLatch go = new CountDownLatch(10);
|
||||||
|
Choice choice = new Choice();
|
||||||
|
choice.addItem("first");
|
||||||
|
choice.addItem("second");
|
||||||
|
Frame frame = new Frame() {
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
g.fillRect(0, 0, 200, 200);
|
||||||
|
choice.setBounds(50, 50, 180, 30);
|
||||||
|
go.countDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
frame.setLayout(null);
|
||||||
|
frame.add(choice);
|
||||||
|
frame.setSize(300, 300);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
if (go.await(5, TimeUnit.SECONDS)) {
|
||||||
|
throw new RuntimeException("recursive setBounds paint");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue