提交 c61e4550 编写于 作者: A alexsch

8080137: Dragged events for extra mouse buttons (4, 5, 6) are not generated on JSplitPane

Reviewed-by: serb, azvegint
上级 6ba65cf1
...@@ -4401,6 +4401,18 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4401,6 +4401,18 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher"); private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher");
private static final int BUTTONS_DOWN_MASK;
static {
int[] buttonsDownMask = AWTAccessor.getInputEventAccessor().
getButtonDownMasks();
int mask = 0;
for (int buttonDownMask : buttonsDownMask) {
mask |= buttonDownMask;
}
BUTTONS_DOWN_MASK = mask;
}
LightweightDispatcher(Container nativeContainer) { LightweightDispatcher(Container nativeContainer) {
this.nativeContainer = nativeContainer; this.nativeContainer = nativeContainer;
mouseEventTarget = new WeakReference<>(null); mouseEventTarget = new WeakReference<>(null);
...@@ -4469,25 +4481,12 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { ...@@ -4469,25 +4481,12 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener {
private boolean isMouseGrab(MouseEvent e) { private boolean isMouseGrab(MouseEvent e) {
int modifiers = e.getModifiersEx(); int modifiers = e.getModifiersEx();
if(e.getID() == MouseEvent.MOUSE_PRESSED if (e.getID() == MouseEvent.MOUSE_PRESSED
|| e.getID() == MouseEvent.MOUSE_RELEASED) || e.getID() == MouseEvent.MOUSE_RELEASED) {
{ modifiers ^= InputEvent.getMaskForButton(e.getButton());
switch (e.getButton()) {
case MouseEvent.BUTTON1:
modifiers ^= InputEvent.BUTTON1_DOWN_MASK;
break;
case MouseEvent.BUTTON2:
modifiers ^= InputEvent.BUTTON2_DOWN_MASK;
break;
case MouseEvent.BUTTON3:
modifiers ^= InputEvent.BUTTON3_DOWN_MASK;
break;
}
} }
/* modifiers now as just before event */ /* modifiers now as just before event */
return ((modifiers & (InputEvent.BUTTON1_DOWN_MASK return ((modifiers & BUTTONS_DOWN_MASK) != 0);
| InputEvent.BUTTON2_DOWN_MASK
| InputEvent.BUTTON3_DOWN_MASK)) != 0);
} }
/** /**
......
/*
* Copyright (c) 2015, 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.*;
import java.awt.event.*;
import javax.swing.*;
/*
* @test
* @bug 8080137
* @summary Dragged events for extra mouse buttons (4,5,6) are not generated
* on JSplitPane
* @author alexandr.scherbatiy area=awt.event
* @run main MouseDraggedTest
*/
public class MouseDraggedTest {
private static JFrame frame;
private static Rectangle frameBounds;
private static volatile boolean mouseDragged;
public static void main(String[] args) throws Exception {
try {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(MouseDraggedTest::createAndShowGUI);
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> frameBounds = frame.getBounds());
robot.waitForIdle();
for (int i = 1; i <= MouseInfo.getNumberOfButtons(); i++) {
testMouseDrag(i, robot);
}
} finally {
SwingUtilities.invokeLater(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
private static void testMouseDrag(int button, Robot robot) {
mouseDragged = false;
int x1 = frameBounds.x + frameBounds.width / 4;
int y1 = frameBounds.y + frameBounds.height / 4;
int x2 = frameBounds.x + frameBounds.width / 2;
int y2 = frameBounds.y + frameBounds.height / 2;
robot.mouseMove(x1, y1);
robot.waitForIdle();
int buttonMask = InputEvent.getMaskForButton(button);
robot.mousePress(buttonMask);
robot.mouseMove(x2, y2);
robot.mouseRelease(buttonMask);
robot.waitForIdle();
if (!mouseDragged) {
throw new RuntimeException("Mouse button " + button
+ " is not dragged");
}
}
static void createAndShowGUI() {
frame = new JFrame();
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new BorderLayout());
panel.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
mouseDragged = true;
}
});
frame.add(panel, BorderLayout.CENTER);
frame.setVisible(true);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册