Repository navigation
DropTargetContext: get the target actions from the peer - #72
Conversation
7748bbf to
8e33200
Compare
|
Thanks, this looks good. One issue: the
I suggest removing the What do you think? |
|
One more thing I noticed: Removing the masking from |
getTargetActions() returned a field that only setTargetActions() set, and nothing calls setTargetActions() during a drag. Thus the field was 0, and DropTargetDragEvent.getDropAction(), which masks the drop action with the target actions, always returned ACTION_NONE. As in the JDK, remove the field and keep the actions in the DropTarget. getTargetActions() asks the peer, or returns the default actions of the drop target when there is no peer. setTargetActions() gives the actions to the peer, if there is one, and to the drop target. Also, as in the JDK, DropTargetDragEvent.getDropAction() now returns the drop action as given. The peer must limit the drop action to the target actions. DropTargetDropEvent.getDropAction() already did this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: duncanmcqueen <dwmcqueen@gmail.com>
8e33200 to
67e1ed4
Compare
|
Thank you. You are correct on all points. I changed the commit as you suggest:
You are also correct about I added your two edge cases to the test ( Because the event does not mask the drop action now, the Haiku peer in #61 must limit the drop action to the target actions. I changed the peer to do this, as the JDK peers do. |
Split from #57.
Problem and fix
DropTargetContext.getTargetActions()returns a field that onlysetTargetActions()sets, and nothing callssetTargetActions()during a drag. Thus the field is 0.DropTargetDragEvent.getDropAction()masks the drop action withgetTargetActions(), so it always returnsACTION_NONE. (DropTargetDropEvent.getDropAction()returns the drop action as given, so the problem does not occur there.)The fix, as in the JDK:
targetActionsfield and keep the actions in theDropTarget.getTargetActions()asks the peer, or returnsdropTarget.getDefaultActions()when there is no peer.setTargetActions()gives the actions to the peer, if there is one, and always callsdropTarget.setDefaultActions(). ThussetTargetActions(ACTION_NONE)works, and a laterDropTarget.setDefaultActions()is not ignored.DropTargetDragEvent.getDropAction()returns the drop action as given, asDropTargetDropEvent.getDropAction()does. The peer must limit the drop action to the target actions, as the JDK peers do.I found this bug when I wrote an AWT toolkit for Haiku, which supplies drag and drop peers.
How to reproduce
The methods are not public, so the test calls them with reflection. It tests the context without a peer, and then with a peer that has the target action
ACTION_COPY(StubDropPeer, below). TheDropTargetDragEventcheck also needs #70: without #70, the constructor rejects the source actionsACTION_COPY_OR_MOVE.DropContextActions.javaStubDropPeer.javaResults
Haiku R1/beta6 x86_64 (hrev60228), JamVM with the Haiku port (#25 in ingelabs/jamvm), and ingelabs/classpath built on Haiku. I compiled each version of the changed classes with
javacfrom OpenJDK 8 and put them first on the boot class path (-Xbootclasspath/p). All three versions also have the constructor fix of #70. "Before" ismaster. "Previous" is the first version of this pull request. "After" is this version.OpenJDK 27 on Linux gives the "After" result for the four checks without a peer. (Its
addNotify()takes an internal peer type, so the checks with a peer cannot run there. JDK 8 gave the "After" result for them with the first version of the test.)Platforms
Not specific to Haiku. The problem is in
java.awt.dndand occurs with all toolkits. I reproduced it on Linux.AI assistance
An AI model (Claude Code, by Anthropic) wrote this change, the test and this text. The repository owner directed the work and checked the results. Please review it as you review other contributions.
🤖 Generated with Claude Code