Skip to content

Conversation

@beldenfox
Copy link
Contributor

@beldenfox beldenfox commented Jan 26, 2024

In the Mac glass code the presence of "marked" text (which is tracked in the nsAttrBuffer) signals that an IME is active. In this state the current code assumes that when NSTextInputContext handles a keyDown: it will either generate a call to insertText:replacementRange: or one of the routines that manipulates the marked (composed) text. But this bug shows that sometimes the IME acts on the event without generating any calls back into glass at all.

In this PR the logic is simplified: if the NSTextInputContext handles the keyDown: and there's marked (composed) text we don't generate a KeyEvent. Otherwise we do. This PR removes the shouldProcessKeyEvent flag since it no longer assumes we can catch callbacks to update it correctly.

The existing code also assumes that the composition phase ends when the NSTextInputContext calls insertText:replacementRange to commit the text. This is true but if the user tries to use a dead-key sequence to generate a non-existent character (like an accented 'q') the context will call insertText twice while handling one key down event. In that case we can't exit the composition mode upon seeing the first insertText call since it will cause us to mis-handle the second one. This PR defers exiting composition mode until the end of keyDown:.

I also updated a few deprecated constants so this file no longer generates compiler warnings.


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)

Issues

  • JDK-8301900: TextArea: Committing text with ENTER in an IME window inserts newline (Bug - P4)
  • JDK-8088172: Mac: On German keyboard, pressing <+><q> inserts two apostrophes instead of one (Bug - P4)
  • JDK-8089803: [Mac, TextArea] Japanese IME, caret moves to the next line when pressing Return to select a candidate. (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1351

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 26, 2024

👋 Welcome back mfox! 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 openjdk bot added the rfr Ready for review label Jan 26, 2024
@beldenfox
Copy link
Contributor Author

/issue JDK-8088172

@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@beldenfox
Adding additional issue to issue list: 8088172: Mac: On German keyboard, pressing <+><q> inserts two apostrophes instead of one.

@mlbridge
Copy link

mlbridge bot commented Jan 26, 2024

Webrevs

@beldenfox
Copy link
Contributor Author

/issue JDK-8089803

@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@beldenfox
Adding additional issue to issue list: 8089803: [Mac, TextArea] Japanese IME, caret moves to the next line when pressing Return to select a candidate..

@kevinrushforth kevinrushforth self-requested a review January 26, 2024 18:15
@kevinrushforth
Copy link
Member

Reviewers: @andy-goryachev-oracle @kevinrushforth

/reviewers 2

@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@kevinrushforth
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
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

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

Code changes look good. All my testing looks good.

@beldenfox
Copy link
Contributor Author

I need to amend this PR. If the IM is disabled in the middle of composition we don't dismiss the IM window. In the past that was sort of OK because we ignored the enabled stated and kept sending events to the NSTextInputContext. With this PR we honor the state and stop talking to the context so the IM window just freezes and never goes away. I'll be adding a line of code to ensure we get rid of the IM window when the enabled state changes (which we should have been doing all along).

This condition can arise if the user starts composing and then clicks on a control that doesn't accept IM input (like a button). It can also happen with JDK-8087477 which is a bug I'm still investigating.

@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Jan 29, 2024

@beldenfox
are you going to update this PR with a fix for dismissing the IME window you alluded in the previous comment?

I don't know whether it's the side effect of that scenario, or a new issue, but try this:

  • using a simple app with a TextArea with pre-existing text (I am using the MonkeyTester, but any simple app would do)
  • switch to japanese/romaji input
  • type in "ariga". you'll see the IME window with some candidates (for some reason, the IME window disappears on "ari" - I guess it's expected since the native TextEdit app exhibits the same behavior)
  • click elsewhere. the IME window disappears
    PROBLEM 1: the inline candidate remains underlined
  • switch to German input
  • click on some other position in the text
  • type in + q (from JDK-8088172)
    PROBLEM 2: the text gets inserted into a different position, replacing that underlined Japanese candidate created earlier

Screenshot 2024-01-29 at 10 59 45

edit: some of the scenarios are described in https://bugs.openjdk.org/browse/JDK-8320912

@andy-goryachev-oracle
Copy link
Contributor

... and scenarios described in JDK-8088172 and JDK-8089803 seem to have been fixed.

didCommitText = NO;
nsAttrBuffer = [nsAttrBuffer initWithString: @""];
}
else if (!inputContextHandledEvent || (nsAttrBuffer.length == 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

} else if { ?

@beldenfox
Copy link
Contributor Author

@andy-goryachev-oracle

@beldenfox are you going to update this PR with a fix for dismissing the IME window you alluded in the previous comment?

I did that with the most recent commit (Jan 27th).

  • click elsewhere. the IME window disappears

That indicates that you got my most recent commit, otherwise the IME window would not disappear immediately.

I'm really glad you caught this. The old code for disabling the IME just called [self unmarkText]. I added the code for dismissing the IME window but didn't notice that unmarkText doesn't seem to work. Currently it commits a zero-length string (which appears to be a no-op) and leaves the composition buffer untouched. That combination doesn't make much sense and doesn't match Apple's spec. I need to dig around in the code history to see why it's behaving this way. This also explains some of the bad behavior you noticed in JDK-8320912.

@beldenfox
Copy link
Contributor Author

Currently it commits a zero-length string (which appears to be a no-op) and leaves the composition buffer untouched.

Correcting myself: it does clear the composition buffer. But the zero-length commit doesn't seem to be doing what it needs to.

@beldenfox
Copy link
Contributor Author

@andy-goryachev-oracle The behavior you're seeing when clicking on another control is a manifestation of https://bugs.openjdk.org/browse/JDK-8320912. I put together a fix for that bug but decided not to roll it into this PR. If it would help testing I could do that.

The current code to disable the IME happens after focus has already moved to the node that doesn't want IME input. So the commit that's fired off by unmarkText targets the wrong node. The fix is to implement finishInputMethodComposition so we do the cleanup before the focus changes.

@andy-goryachev-oracle
Copy link
Contributor

JDK-8320912. I put together a fix for that bug but decided not to roll it into this PR.

Are these two bugs independent? Should JDK-8320912 be resolved first?

@beldenfox
Copy link
Contributor Author

JDK-8320912. I put together a fix for that bug but decided not to roll it into this PR.

Are these two bugs independent? Should JDK-8320912 be resolved first?

They are independent. This bug has to do with how we divide keystrokes between KeyEvents and InputMethodEvents. JDK-8320912 is about cleaning up during focus changes. The order in which they get resolved doesn't matter.

@andy-goryachev-oracle
Copy link
Contributor

The order in which they get resolved doesn't matter.

would it be possible to get JDK-8320912 integrated first then? It seems the scenario it addresses is narrower, and it will be easier to review this bug.

@beldenfox
Copy link
Contributor Author

@andy-goryachev-oracle I submitted PR #1356.

@andy-goryachev-oracle
Copy link
Contributor

I submitted PR

thank you!

@kevinrushforth kevinrushforth self-requested a review February 2, 2024 13:51
@kevinrushforth
Copy link
Member

Once #1356 is integrated I'll re-review.

@andy-goryachev-oracle
Copy link
Contributor

@beldenfox could you sync up with the latest master branch please?
Eclipse reports a conflict in GlassView3D.m around lines 722, I am surprised there are no conflicts in github...

@andy-goryachev-oracle
Copy link
Contributor

Even though it says "This branch has conflicts that must be resolved" there is a green checkmark next to it in the Pull Requests view:

https://github.com/openjdk/jfx/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+label%3Arfr

@kevinrushforth
Copy link
Member

I'm surprised Skara hasn't noticed that there is a merge conflict -- when it does, it should add a merge-conflict label. Maybe it needs something other than a PR comment to wake it up?

@beldenfox
Copy link
Contributor Author

Skara has noted the merge conflict. I'll get that patched up. I also need to tweak the implementation of setEnabled, it's trying to handle focus moving from node to node but the logic is wrong.

@kevinrushforth
Copy link
Member

Skara hasn't labeled it, so I'm restating the requirement of 2 reviewers to see if that wakes up the bot to check for the merge conflict.

/reviewers 2

@openjdk
Copy link

openjdk bot commented Feb 2, 2024

@kevinrushforth
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).

@openjdk
Copy link

openjdk bot commented Feb 2, 2024

@beldenfox this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout macimefixes
git fetch https://git.openjdk.org/jfx.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Feb 2, 2024
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Feb 2, 2024
@beldenfox
Copy link
Contributor Author

Two additions to the code. I was not handling the case where the keystroke didn't commit text but did clear the marked text (getting us out of composition mode). You can do this by repeatedly pressing ESC.

When the enabled state changes we shouldn't have any marked text but if we do it should just be discarded. The old code was trying to deal with focusOwner changes but that cleanup has to happen before the enabled state changes instead of after (which is why finishInputMethodComposition exists).

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.

As far as I can tell, the new behavior matches the native app one.

有難う

@openjdk
Copy link

openjdk bot commented Feb 23, 2024

@beldenfox This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8301900: TextArea: Committing text with ENTER in an IME window inserts newline
8088172: Mac: On German keyboard, pressing <+><q> inserts two apostrophes instead of one
8089803: [Mac, TextArea] Japanese IME, caret moves to the next line when pressing Return to select a candidate.

Reviewed-by: kcr, angorya

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 14 new commits pushed to the master branch:

  • afa206b: 8321603: Bump minimum JDK version for JavaFX to JDK 21
  • e0b88bc: 8278021: Fix warnings in macOS glass native code and treat warnings as errors
  • 9a06bf9: 8322748: Caret blinking in JavaFX should only stop when caret moves
  • ee8633c: 8089373: Translation from character to key code is not sufficient
  • 1fb56e3: 8323880: Caret rendered at wrong position in case of a click event on RTL text
  • 2754939: 8309374: Accessibility Focus Rectangle on ListItem is not drawn when ListView is shown for first time
  • 48be7d3: 8324182: Deprecate for removal SimpleSelector and CompoundSelector classes
  • 49d7d52: 8325798: Spinner throws uncatchable exception on tab out from garbled text
  • f379eae: 8325873: Update JDK_DOCS property to point to JDK 21 docs
  • e2f42c5: 8325154: resizeColumnToFitContent is slower than it needs to be
  • ... and 4 more: https://git.openjdk.org/jfx/compare/17dfab066b1f5db3d34b130cade3acd09ee21a70...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Ready to be integrated label Feb 23, 2024
@beldenfox
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 23, 2024

Going to push as commit d9263ab.
Since your change was applied there have been 14 commits pushed to the master branch:

  • afa206b: 8321603: Bump minimum JDK version for JavaFX to JDK 21
  • e0b88bc: 8278021: Fix warnings in macOS glass native code and treat warnings as errors
  • 9a06bf9: 8322748: Caret blinking in JavaFX should only stop when caret moves
  • ee8633c: 8089373: Translation from character to key code is not sufficient
  • 1fb56e3: 8323880: Caret rendered at wrong position in case of a click event on RTL text
  • 2754939: 8309374: Accessibility Focus Rectangle on ListItem is not drawn when ListView is shown for first time
  • 48be7d3: 8324182: Deprecate for removal SimpleSelector and CompoundSelector classes
  • 49d7d52: 8325798: Spinner throws uncatchable exception on tab out from garbled text
  • f379eae: 8325873: Update JDK_DOCS property to point to JDK 21 docs
  • e2f42c5: 8325154: resizeColumnToFitContent is slower than it needs to be
  • ... and 4 more: https://git.openjdk.org/jfx/compare/17dfab066b1f5db3d34b130cade3acd09ee21a70...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 23, 2024
@openjdk openjdk bot closed this Feb 23, 2024
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Feb 23, 2024
@openjdk
Copy link

openjdk bot commented Feb 23, 2024

@beldenfox Pushed as commit d9263ab.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@beldenfox beldenfox deleted the macimefixes branch July 23, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants