JBR-1752 Floating windows overlap modal dialogs

(cherry picked from commit 0161050077)

with fix for JBR-5300 Change source code and test files to use GPL license

(cherry picked from commit 8b2f0315d1)
This commit is contained in:
Dmitry Batrak
2021-01-29 14:42:06 +03:00
committed by jbrbot
parent e31a2dda14
commit 16d518cd92
3 changed files with 104 additions and 44 deletions

View File

@@ -1231,11 +1231,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
return !peer.isSimpleWindow() && target.getFocusableWindowState();
}
private boolean isBlocked() {
LWWindowPeer blocker = (peer != null) ? peer.getBlocker() : null;
return (blocker != null);
}
/*
* An utility method for the support of the auto request focus.
* Updates the focusable state of the window under certain

View File

@@ -493,23 +493,6 @@ AWT_ASSERT_APPKIT_THREAD;
[super dealloc];
}
// Tests whether window is blocked by modal dialog/window
- (BOOL) isBlocked {
BOOL isBlocked = NO;
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(isBlocked);
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z", isBlocked);
isBlocked = (*env)->CallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO;
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, platformWindow);
}
return isBlocked;
}
// Test whether window is simple window and owned by embedded frame
- (BOOL) isSimpleWindowOwnedByEmbeddedFrame {
BOOL isSimpleWindowOwnedByEmbeddedFrame = NO;
@@ -553,9 +536,8 @@ AWT_ASSERT_APPKIT_THREAD;
- (void) orderChildWindows:(BOOL)focus {
AWT_ASSERT_APPKIT_THREAD;
if (self.isMinimizing || [self isBlocked]) {
if (self.isMinimizing) {
// Do not perform any ordering, if iconify is in progress
// or the window is blocked by a modal window
return;
}
@@ -999,26 +981,9 @@ AWT_ASSERT_APPKIT_THREAD;
}
- (void)sendEvent:(NSEvent *)event {
if ([event type] == NSEventTypeLeftMouseDown ||
[event type] == NSEventTypeRightMouseDown ||
[event type] == NSEventTypeOtherMouseDown) {
if ([self isBlocked]) {
// Move parent windows to front and make sure that a child window is displayed
// in front of its nearest parent.
if (self.ownerWindow != nil) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
(*env)->CallVoidMethod(env,platformWindow, jm_orderAboveSiblings);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, platformWindow);
}
}
[self orderChildWindows:YES];
}
if ([event type] == NSLeftMouseDown ||
[event type] == NSRightMouseDown ||
[event type] == NSOtherMouseDown) {
NSPoint p = [NSEvent mouseLocation];
NSRect frame = [self.nsWindow frame];
NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame];

View File

@@ -0,0 +1,100 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* 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 javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.concurrent.*;
/**
* @test
* @summary Regression test for JBR-1752 Floating windows overlap modal dialogs
* @key headful
*/
public class ModalDialogOverSiblingTest {
private static final CompletableFuture<Boolean> modalDialogButtonClicked = new CompletableFuture<>();
private static Robot robot;
private static JFrame frame;
private static JButton button1;
private static JButton button2;
private static JButton button3;
public static void main(String[] args) throws Exception {
robot = new Robot();
try {
SwingUtilities.invokeAndWait(ModalDialogOverSiblingTest::initUI);
robot.delay(2000);
clickOn(button1);
robot.delay(2000);
clickOn(button2);
robot.delay(2000);
clickOn(button3);
modalDialogButtonClicked.get(5, TimeUnit.SECONDS);
} finally {
SwingUtilities.invokeAndWait(ModalDialogOverSiblingTest::disposeUI);
}
}
private static void initUI() {
frame = new JFrame("ModalDialogOverSiblingTest");
frame.setLayout(new FlowLayout());
button1 = new JButton("Open non-modal dialog");
button1.addActionListener(e -> {
JDialog dialog = new JDialog(frame, "Non-modal", false);
dialog.setSize(200, 200);
dialog.setLocation(200, 400);
dialog.setVisible(true);
});
frame.add(button1);
button2 = new JButton("Open modal dialog");
button2.addActionListener(e -> {
JDialog dialog = new JDialog(frame, "Modal", true);
button3 = new JButton("Button");
button3.addActionListener(event -> modalDialogButtonClicked.complete(true));
dialog.add(button3);
dialog.setSize(150, 150);
dialog.setLocation(220, 420);
dialog.setVisible(true);
});
frame.add(button2);
frame.pack();
frame.setLocation(200, 200);
frame.setVisible(true);
}
private static void disposeUI() {
if (frame != null) frame.dispose();
}
private static void clickAt(int x, int y) {
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
private static void clickOn(Component component) {
Point location = component.getLocationOnScreen();
clickAt(location.x + component.getWidth() / 2, location.y + component.getHeight() / 2);
}
}