提交 0b575cf4 编写于 作者: D dmarkov

8044614: [macosx] Focus issue with 2 applets in firefox

Reviewed-by: alexsch, pchelko
上级 ea755d1b
......@@ -37,7 +37,8 @@ public class CEmbeddedFrame extends EmbeddedFrame {
private CPlatformResponder responder;
private static final Object classLock = new Object();
private static volatile CEmbeddedFrame focusedWindow;
private static volatile CEmbeddedFrame globalFocusedWindow;
private CEmbeddedFrame browserWindowFocusedApplet;
private boolean parentWindowActive = true;
public CEmbeddedFrame() {
......@@ -110,10 +111,10 @@ public class CEmbeddedFrame extends EmbeddedFrame {
synchronized (classLock) {
// In some cases an applet may not receive the focus lost event
// from the parent window (see 8012330)
focusedWindow = (focused) ? this
: ((focusedWindow == this) ? null : focusedWindow);
globalFocusedWindow = (focused) ? this
: ((globalFocusedWindow == this) ? null : globalFocusedWindow);
}
if (focusedWindow == this) {
if (globalFocusedWindow == this) {
// see bug 8010925
// we can't put this to handleWindowFocusEvent because
// it won't be invoced if focuse is moved to a html element
......@@ -144,9 +145,23 @@ public class CEmbeddedFrame extends EmbeddedFrame {
// non-focused applet. This method can be called from different threads.
public void handleWindowFocusEvent(boolean parentWindowActive) {
this.parentWindowActive = parentWindowActive;
// If several applets are running in different browser's windows, it is necessary to
// detect the switching between the parent windows and update globalFocusedWindow accordingly.
synchronized (classLock) {
if (!parentWindowActive) {
this.browserWindowFocusedApplet = globalFocusedWindow;
}
if (parentWindowActive && globalFocusedWindow != this && isParentWindowChanged()) {
// It looks like we have switched to another browser window, let's restore focus to
// the previously focused applet in this window. If no applets were focused in the
// window, we will set focus to the first applet in the window.
globalFocusedWindow = (this.browserWindowFocusedApplet != null) ? this.browserWindowFocusedApplet
: this;
}
}
// ignore focus "lost" native request as it may mistakenly
// deactivate active window (see 8001161)
if (focusedWindow == this && parentWindowActive) {
if (globalFocusedWindow == this && parentWindowActive) {
responder.handleWindowFocusEvent(parentWindowActive, null);
}
}
......@@ -154,4 +169,10 @@ public class CEmbeddedFrame extends EmbeddedFrame {
public boolean isParentWindowActive() {
return parentWindowActive;
}
private boolean isParentWindowChanged() {
// If globalFocusedWindow is located at inactive parent window or null, we have swithed to
// another window.
return globalFocusedWindow != null ? !globalFocusedWindow.isParentWindowActive() : true;
}
}
/*
* Copyright (c) 2014, 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.applet.Applet;
import java.awt.TextField;
public class TestApplet extends Applet {
TextField textField = null;
public void init() {
textField = new TextField(25);
add(textField);
}
}
<!--
Copyright (c) 2014, 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.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>First Applet</title>
</head>
<body>
<applet
code="TestApplet.class"
width="400"
height="200"/>
</applet>
</body>
</html>
<!--
Copyright (c) 2014, 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.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Second Applet</title>
</head>
<body>
<applet
code="TestApplet.class"
width="400"
height="200"/>
</applet>
</body>
</html>
<!--
Copyright (c) 2014, 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.
-->
<html>
<head>
<title>bug8044614</title>
</head>
<body>
<h1>bug8044614</h1>
<p> See the dialog box (usually in upper left corner) for instructions</p>
<APPLET CODE="bug8044614.class" WIDTH=200 HEIGHT=200></APPLET>
</body>
</html>
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @bug 8044614
* @summary Tests focus transfer between applets in different browser windows
* @author Dmitry Markov
* @library ../../regtesthelpers
* @build Sysout
* @run applet/manual=yesno bug8044614.html
*/
import javax.swing.JApplet;
import test.java.awt.regtesthelpers.Sysout;
public class bug8044614 extends JApplet {
public void init() {
String[] instructions = {
"(1) Go to the test directory test/java/awt/Focus/8044614",
"(2) Compile source file: javac TestApplet.java",
"(3) Open the \"main.html\" file in the browser",
"(4) Click the \"Start First Applet\" link to open the first applet window",
"(5) Wait for the applet to start (press \"Run\" to any security alerts that appears)",
"(6) Enter \"Hello\" to the text field",
"(7) Click the \"Start Second Applet)\" link to open the second applet window",
"(8) Wait for the applet to start (press \"Run\" to any security alerts that appears)",
"(9) Enter \"World\" to the text field",
"(10) Go back to the first applet and make sure you can enter some text to the text field"
};
Sysout.createDialogWithInstructions(instructions);
}
}
<!--
Copyright (c) 2014, 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.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Applet Focus Bug main window</title>
<script language="JavaScript">
function openWindow(strURL, strWindowName, strWindowFeatures) {
var win = window.open(strURL, strWindowName, strWindowFeatures);
}
</script>
</head>
<body>
<table>
<tr>
<td><a href="javascript:openWindow('applet1.html', '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=400, top=0, left=0, hide=no')">Start First Applet</a></td>
</tr>
<tr>
<td><a href="javascript:openWindow('applet2.html', '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=400, top=0, left=350, hide=no')">Start Second Applet</a></td>
</tr>
</table>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册