jfx icon indicating copy to clipboard operation
jfx copied to clipboard

8331464: ChangeListener for TableView.focusWithinProperty( ) is not always called

Open faneeshh opened this issue 6 months ago • 9 comments

The virtual cells (like List Cell and Table Cell) call setFocused( ) in their updateFocus( ) method to kind of replicate the control's focus model state. This call goes through the focused.set( ) override in Node, which adjusts the focusWithin reference count on all ancestor nodes.

Since the owning control ( like TableView) is already the Scene focus owner contributing a count of 1, so I believe the cell's setFocused(true) increments it to 2. When the Scene later moves focus away, it decrements the count back to 1 (still positive) and so focusWithinProperty never fires.

The fix I've used is a focusModelUpdate flag on Node. When setFocusedViaFocusModel( ) is called, this flag suppresses the focusWithin reference count adjustment inside focused.set( ) and all normal change notifications and CSS pseudo class updates are firing as usual too.

I've updated the 6 cell types to use setFocusedViaFocusModel( ) in their updateFocus( ) methods too.


Progress

  • [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue

Error

 ⚠️ OCA signatory status must be verified

Integration blocker

 ⚠️ Title mismatch between PR and JBS for issue JDK-8331464

Issue

  • JDK-8331464: ChangeListener for TableView.focusWithinProperty() is not always called (Bug - P4) ⚠️ Title mismatch between PR and JBS.

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2178

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

Using diff file

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

faneeshh avatar May 29 '26 06:05 faneeshh

Hi @faneeshh, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user faneeshh" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

bridgekeeper[bot] avatar May 29 '26 06:05 bridgekeeper[bot]

/signed

faneeshh avatar May 29 '26 06:05 faneeshh

Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

bridgekeeper[bot] avatar May 29 '26 06:05 bridgekeeper[bot]

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

openjdk[bot] avatar May 29 '26 06:05 openjdk[bot]

image

That's weird...

faneeshh avatar May 29 '26 06:05 faneeshh

You've hit on a sharp edge in the way focus handling is implemented. This is a known issue, but we can't solve it in the way you propose. You assume that TableView.focusWithin should always be false when another control outside of the table is focused. This is a sensible assumption, but it would mean incorrectly reporting that no node within a subtree is focused, even if it actually is.

The problem is not with focusWithin, it's with setFocused: cells use the input-focus flag on Node to track their internal "focus" state, which is different from the input-focus state that is tracked by Node. Superficially, both concepts look similar, but they are very clearly not. The existence of the public setFocused method allows subclasses to break the focus model, and cells unfortunately do that. We need to fix that at some point, and it probably means deprecating setFocused and making it ineffective.

mstr2 avatar May 29 '26 10:05 mstr2

Okay thank u for the feedback! @Maran23 told me the same but I just needed second opinions on my approach but yeah I agree with you both. You can close the PR then if u need to.

faneeshh avatar May 29 '26 21:05 faneeshh

I was also thinking if it be acceptable to address this at the Cell level instead? The idea would be to override setFocused( ) in Cell to be deprecated and introduce a package private setFocusedByFocusModel(boolean) on Cell that updates the :focused pseudo-class directlyy without going through Node's focus machinery or affecting focusWithin

This would also keep the existing CSS working and fix the focusWithin bug and scope all changes to controls.

faneeshh avatar May 29 '26 21:05 faneeshh

As mentioned in the ticket, this one is tricky indeed.

We know that:

  • We should deprecate setFocused - it is a defect, working around requestFocus and will not play nice with focusWithin
  • We somehow need a way to kind of (fake) focus a node. I think in TableCell we could get around faking it completely as it really is there for CSS - the commit on focus loss can also work without that
  • FakeFocusTextField is more ticky as all the focusListener registered in the skin need to run still while we do not steal the focus with requestFocus

Maran23 avatar Jun 01 '26 21:06 Maran23

@faneeshh This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

bridgekeeper[bot] avatar Jun 30 '26 02:06 bridgekeeper[bot]