Skip to content

8207333: [Linux, macOS] Column sorting is triggered always after context menu request on table header #1754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jperedadnr
Copy link
Collaborator

@jperedadnr jperedadnr commented Apr 1, 2025

Note: The JBS issue JDK-8207333 refers to Linux, but it happens on macOS too.

When a TableColumn has a ContextMenu, if the user right clicks on the tableColumnHeader, the ContextMenu shows up, but, as described on the issue, on macOS and Linux, the table gets sorted as well.

Currently, TableColumnHeader#mouseReleasedHandler checks for MouseEvent::isPopupTriggered, but it doesn't have a check on mousePressed. However, it can be seen that a right click on the header has the following values for MouseEvent:: isPopupTriggered on the different platforms and mouse pressed and released events:

isPopupTriggered on: Windows macOS Linux
mousePressed false true true
mouseReleased true false false 

Also, the JavaDoc for MouseEvent::isPopupTriggered clearly states that:

Note: Popup menus are triggered differently on different systems. Therefore, popupTrigger should be checked in both onMousePressed and mouseReleased for proper cross-platform functionality.

Therefore, this PR adds a check to MouseEvent::isPopupTrigger in the mouse pressed event, that can be used later on to cancel the header sorting when the mouse released event happens.

Also a system test has been added. It fails on macOS and Linux, and passes on Windows before this PR, and passes on the three platforms with this PR.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8207333: [Linux, macOS] Column sorting is triggered always after context menu request on table header (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1754/head:pull/1754
$ git checkout pull/1754

Update a local copy of the PR:
$ git checkout pull/1754
$ git pull https://git.openjdk.org/jfx.git pull/1754/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1754

View PR using the GUI difftool:
$ git pr show -t 1754

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1754.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 1, 2025

👋 Welcome back jpereda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 1, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Ready for review label Apr 1, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 1, 2025

Webrevs

@andy-goryachev-oracle
Copy link
Contributor

I'll take a look.
Should we update the JBS and this PR title to remove [linux] as it applies to both platforms?

@andy-goryachev-oracle
Copy link
Contributor

I can only test it on macOS and Windows. Could someone with a linux system help please?
/reviewers 2

@openjdk
Copy link

openjdk bot commented Apr 1, 2025

@andy-goryachev-oracle
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for fixing this bug, @jperedadnr !

testing with the monkey tester looks good on macOS 15.3.2 and windows 11.

@jperedadnr jperedadnr changed the title 8207333: [linux] Column sorting is triggered always after context menu request on table header 8207333: [Linux, macOS] Column sorting is triggered always after context menu request on table header Apr 1, 2025
@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Apr 7, 2025

@Ziad-Mid could you be the second reviewer?

@Ziad-Mid
Copy link
Contributor

Ziad-Mid commented Apr 8, 2025

@Ziad-Mid could you be the second reviewer?

I can't test on Linux , I will check same for macOS

@@ -243,6 +245,7 @@ public TableColumnHeader(final TableColumnBase tc) {
}

if (me.isConsumed()) return;
popupTriggeredOnMousePressed = me.isPopupTrigger();
me.consume();

header.getTableHeaderRow().columnDragLock = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Mac a context menu can be invoked using the right button or the left button in conjunction with the Control key. In the second case the pop trigger flag will be set and the primary button will be down. If I'm reading the code correctly this could get the header stuck in column re-ordering mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing on macOS 15.3.2, it does not get stuck when using control+left-click, works as expected.

There is one (existing and unrelated) problem - if the user tries to dismiss the popup menu by clicking on the header, it dismisses the popup (correctly), but then proceeds to re-sort the table (unexpected).

One can say it works as designed, since the click falls on a header cell and the expected operation is to toggle the sorting, with the side effect of dismissing the popup.

On the other hand, Excel (both mac and windows) behaves differently - a click on the spreadsheet header dismisses the popup and does not select the column, as it normally does when no popup is present.

What do you guys think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

control+left-click works as expected for me too.

When the context menu is showing, clicking anywhere outside of it, closes the popup (because of the autohide property), but doesn't consume the event. If you click on a button, for instance, it will be fired. In any case, this is the same before and after this PR, so maybe an issue for a later discussion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely an unrelated issue, I just wanted to ask whether you guys think it crosses the threshold for a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

control+left-click works as expected for me too.

For control+left-click it looks like the code will call columnReordingStarted but on the released event it won't call columnReorderingComplete. I have no idea if this will lead to problems or not.

@@ -271,7 +274,10 @@ public TableColumnHeader(final TableColumnBase tc) {
TableColumnHeader header = (TableColumnHeader) me.getSource();
header.getTableHeaderRow().columnDragLock = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Ubuntu 22.04 the table column header is not receiving a mouse released event if a context menu is shown. Not sure where the released event is going but it's not to any node on the primary stage. The docs are vague on this but this looks like a separate bug that's making it hard to test this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens in the master branch (without this PR's changes)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble reproducing the original bug on the master branch; the sorting is done when the mouse is released and most of the time that event never arrives (I think it does every now and then).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is strange - the bug is immediately apparent. which macOS version do you have? although I don't think the version matters.

I am testing with an external mouse, with control-left-click, and with the double-finger-click gesture on the trackpad.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having problems reproducing on Linux. No problem reproducing on macOS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux I have some issues too: the test that I attached to the JBS issue doesn't fail for me on Linux, but the test that I added to this PR does fail without the fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try the monkey tester? it allows setting properties on the table view / table column at runtime...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just verified that on Linux the released event usually goes to the popup window. Basically it's whatever window is under the cursor at the time; if I move the mouse fast enough it may go to a node on the primary stage. I don't think this is our doing, it's how GTK is delivering the event.

On the JavaFX side I'm not sure this counts as a bug. The docs state that entered and released events should arrive in pairs during drag and drop operations but doesn't address this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Monkey tester app works for me on Linux (Ubuntu 22.04, either mouse or pad), before and after this PR (so I can't reproduce the issue there, as I mentioned, though the test added to the PR fails without the patch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
Development

Successfully merging this pull request may close these issues.

4 participants