mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34: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.
|
||||
*
|
||||
* 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
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.awt.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.peer.*;
|
||||
import java.awt.Choice;
|
||||
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.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.peer.ChoicePeer;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
::GetClientRect(c->GetHWnd(), &rc);
|
||||
env->SetIntField(target, AwtComponent::widthID, (jint) rc.right);
|
||||
env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom);
|
||||
env->SetIntField(target, AwtComponent::widthID, c->ScaleDownX(rc.right));
|
||||
env->SetIntField(target, AwtComponent::heightID, c->ScaleDownY(rc.bottom));
|
||||
|
||||
if (IS_WINXP) {
|
||||
::SendMessage(c->GetHWnd(), CB_SETMINVISIBLE, (WPARAM) MINIMUM_NUMBER_OF_VISIBLE_ITEMS, 0);
|
||||
|
@ -228,13 +228,11 @@ int AwtChoice::GetTotalHeight()
|
|||
{
|
||||
int dropHeight = GetDropDownHeight();
|
||||
int fieldHeight = GetFieldHeight();
|
||||
int totalHeight;
|
||||
|
||||
// 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
|
||||
totalHeight = dropHeight + fieldHeight +borderHeight*2;
|
||||
return totalHeight;
|
||||
return dropHeight + fieldHeight + borderHeight * 2;
|
||||
}
|
||||
|
||||
// Recalculate and set the drop-down height for the Choice.
|
||||
|
@ -244,7 +242,7 @@ void AwtChoice::ResetDropDownHeight()
|
|||
|
||||
::GetWindowRect(GetHWnd(), &rcWindow);
|
||||
// resize the drop down to accommodate added/removed items
|
||||
int totalHeight = GetTotalHeight();
|
||||
int totalHeight = ScaleUpY(GetTotalHeight());
|
||||
::SetWindowPos(GetHWnd(), NULL,
|
||||
0, 0, rcWindow.right - rcWindow.left, totalHeight,
|
||||
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
|
||||
|
@ -305,11 +303,11 @@ void AwtChoice::Reshape(int x, int y, int w, int h)
|
|||
BOOL bReshape = true;
|
||||
if (awtParent != NULL) {
|
||||
::GetWindowRect(GetHWnd(), &rc);
|
||||
int oldW = rc.right - rc.left;
|
||||
int oldW = ScaleDownX(rc.right - rc.left);
|
||||
RECT parentRc;
|
||||
::GetWindowRect(awtParent->GetHWnd(), &parentRc);
|
||||
int oldX = rc.left - parentRc.left;
|
||||
int oldY = rc.top - parentRc.top;
|
||||
int oldX = ScaleDownX(rc.left - parentRc.left);
|
||||
int oldY = ScaleDownY(rc.top - parentRc.top);
|
||||
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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -24,19 +24,25 @@
|
|||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 4851798 8041896
|
||||
@bug 4851798 8041896 8225126
|
||||
@summary Tests Choice List shrinks after removeAll
|
||||
@run main RemoveAllShrinkTest
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
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 static void main(String[] args) {
|
||||
Frame f = new Frame();
|
||||
try {
|
||||
Choice choice = new Choice();
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
@ -49,6 +55,7 @@ public class RemoveAllShrinkTest {
|
|||
f.add(panel);
|
||||
|
||||
f.setSize(200, 200);
|
||||
f.setLocationRelativeTo(null);
|
||||
f.setVisible(true);
|
||||
f.toFront();
|
||||
|
||||
|
@ -81,6 +88,9 @@ public class RemoveAllShrinkTest {
|
|||
} 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