--- old/src/solaris/classes/sun/awt/X11/XBaseWindow.java 2014-10-30 19:49:09.000000000 +0300 +++ new/src/solaris/classes/sun/awt/X11/XBaseWindow.java 2014-10-30 19:49:08.000000000 +0300 @@ -1001,6 +1001,13 @@ switch (xev.get_type()) { case XConstants.ButtonPress: if (buttonState == 0) { + XWindowPeer parent = getToplevelXWindow(); + // See 6385277, 6981400. + if (parent != null && parent.isFocusableWindow()) { + // A click in a client area drops the actual focused window retaining. + parent.setActualFocusedWindow(null); + parent.requestWindowFocus(xbe.get_time(), true); + } XAwtState.setAutoGrabWindow(this); } break; --- old/src/solaris/classes/sun/awt/X11/XComponentPeer.java 2014-10-30 19:49:09.000000000 +0300 +++ new/src/solaris/classes/sun/awt/X11/XComponentPeer.java 2014-10-30 19:49:09.000000000 +0300 @@ -605,33 +605,6 @@ } - public void handleButtonPressRelease(XEvent xev) { - /* - * Fix for 6385277. - * We request focus on simple Window by click in order - * to make it behave like Frame/Dialog in this case and also to unify - * the behaviour with what we have on MS Windows. - * handleJavaMouseEvent() would be more suitable place to do this - * but we want Swing to have this functionality also. - */ - if (xev.get_type() == XConstants.ButtonPress) { - final XWindowPeer parentXWindow = getParentTopLevel(); - Window parentWindow = (Window)parentXWindow.getTarget(); - if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() && - XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() != parentWindow) - { - postEvent(new InvocationEvent(parentWindow, new Runnable() { - public void run() { - // Request focus on the EDT of 'parentWindow' because - // XDecoratedPeer.requestWindowFocus() calls client code. - parentXWindow.requestXFocus(); - } - })); - } - } - super.handleButtonPressRelease(xev); - } - public Dimension getMinimumSize() { return target.getSize(); } --- old/src/solaris/classes/sun/awt/X11/XContentWindow.java 2014-10-30 19:49:10.000000000 +0300 +++ new/src/solaris/classes/sun/awt/X11/XContentWindow.java 2014-10-30 19:49:10.000000000 +0300 @@ -24,7 +24,9 @@ */ package sun.awt.X11; -import java.awt.*; +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.Insets; import java.awt.event.ComponentEvent; @@ -160,23 +162,6 @@ } } - public void handleButtonPressRelease(XEvent xev) { - if (xev.get_type() == XConstants.ButtonPress) { - Window parentWindow = (Window)parentFrame.getTarget(); - /* - * In case the decorated frame is active but not focused - * (that is an owned window is currently focused) - * it should be made a focused window. - * This is needed to focus the frame when it's clicked - * in an empty spot of its content area. See 6886678. - */ - if (parentWindow != null && parentWindow.isActive() && !parentWindow.isFocused()) { - parentFrame.requestWindowFocus(); - } - } - super.handleButtonPressRelease(xev); - } - void purgeIconifiedExposeEvents() { for (SavedExposeEvent evt : iconifiedExposeEvents) { super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h); --- /dev/null 2009-04-14 14:16:08.000000000 +0400 +++ new/test/java/awt/Focus/NPEInKFMOnButtonClickInDialogTest/NPEInKFMOnButtonClickInDialogTest.java 2014-10-30 19:49:10.000000000 +0300 @@ -0,0 +1,135 @@ +/* + * 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 8061954 + @summary Button does not get the focus on a mouse click, and NPE is thrown in KFM + @author Anton Litvinov +*/ + +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.InputEvent; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.SwingUtilities; + +import sun.awt.OSInfo; +import sun.awt.SunToolkit; + +public class NPEInKFMOnButtonClickInDialogTest { + private static Frame frame = null; + private static JDialog dialog = null; + private static JButton cancelBtn = null; + private static Point clickPoint = null; + private static volatile Boolean cancelBtnIsFocused = null; + + public static void main(String[] args) { + OSInfo.OSType osType = OSInfo.getOSType(); + if ((osType != OSInfo.OSType.LINUX) && (osType != OSInfo.OSType.SOLARIS)) { + System.out.println("This test is only for Linux OS and Solaris OS."); + return; + } + + ThreadGroup mainThreadGroup = Thread.currentThread().getThreadGroup(); + Thread t = new Thread(new ThreadGroup(mainThreadGroup, "TestThreadGroup"), new Runnable() { + public void run() { + try { + SunToolkit.createNewAppContext(); + doTest(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + t.start(); + + try { + t.join(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + + if (cancelBtnIsFocused == null) { + throw new RuntimeException("Test failed for an unknown reason, look at error log."); + } else if (cancelBtnIsFocused.booleanValue() == false) { + throw new RuntimeException("'Cancel' button did not become a focus owner."); + } + } + + private static void doTest() throws Exception { + final SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); + final Robot robot = new Robot(); + robot.setAutoDelay(50); + + try { + frame = new Frame("Frame of NPEInKFMOnButtonClickInDialogTest"); + frame.setSize(100, 100); + frame.setVisible(true); + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + dialog = new JDialog(frame, + "Dialog of NPEInKFMOnButtonClickInDialogTest", false); + Container content = dialog.getContentPane(); + content.setLayout(new FlowLayout()); + content.add(new JButton("Run")); + content.add(cancelBtn = new JButton("Cancel")); + dialog.pack(); + dialog.setVisible(true); + } + }); + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + Point p = cancelBtn.getLocationOnScreen(); + clickPoint = new Point(p.x + cancelBtn.getWidth() / 2, + p.y + cancelBtn.getHeight() / 2); + } + }); + robot.mouseMove(clickPoint.x, clickPoint.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + cancelBtnIsFocused = cancelBtn.isFocusOwner(); + } + }); + } finally { + if (dialog != null) { + dialog.dispose(); + } + if (frame != null) { + frame.dispose(); + } + } + } +}