On Wed, 9 Jul 2025 17:21:06 GMT, Martin Fox <m...@openjdk.org> wrote:
>> Implementation of [focus >> delegation](https://gist.github.com/mstr2/44d94f0bd5b5c030e26a47103063aa29). > > modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 8654: > >> 8652: * @since 26 >> 8653: */ >> 8654: Node getFocusDelegate(Node hoistingNode) { > > I tried to tweak the InputMethodStateManager to deal with delegates and > discovered there’s no easy way to get a node’s delegate. Shouldn’t there be a > public way of retrieving the current delegate? > > I don’t think getFocusDelegate should take a parameter. If I was creating a > node with multiple focus delegates I would probably want to track the current > one in some simple way. But getFocusDelegate doesn’t allow me to do that, I > always have to respect the hoisting node parameter being passed in and dig > through my descendant nodes to figure out which delegate is being requested. > And it implies the only way to change the delegate is to requestFocus on the > new delegate and take it through the hoisting process. That seems overly > restrictive. I can see why a focus scope node would need to know which node > hoisted focus but only at the time the hoist happens. > > We’re spending a lot of time thinking about controls that may have more than > one delegate. I really doubt anyone will ever create one. If they do it > raises a bunch of questions related to accessibility and keyboard traversal > that we’re not even discussing. Does `resolveFocusDelegate` do what you need? Perhaps that method should be public (and maybe renamed) and the version taking the parameter can be kept internal. I think it would be unwise to assume there can only be one delegate as this mechanism is there primarily for skins, which are public API and would be used to construct advanced controls that would benefit from multiple delegates. While FX itself is unlikely to have need of this as its focus is (and must be) on basic, composable controls, there is an infinite amount of useful composed controls that would benefit from having multiple focus delegates. Examples that would work well with multiple delegates: - The Date/Time entry control I mentioned with separated TextFields - Similar to the above but for credit card entry, ip addresses, or any other field with fixed separators; of course this can be done with a single TextField as well, but that's much harder (and you get less context for each field for accessibility -- ie. for a date field it can specifically mention you are in the "month" part instead of just asking for a full date where it may need to explain the order of the individual parts). - Spreadsheet cells can have controls embedded while the cell retains focus - Tag editor (where you type something, which is autocompleted from a list of options, and when selected becomes a removable/editable tag -- the address fields of an email client are such an example) At a minimum IMHO we should ensure this design doesn't prevent the possibility of multiple focus delegates, but preferably it should support it immediately. I'm less well versed in the accessibility points you raised, could you elaborate? For example, for keyboard traversal, I don't see why this wouldn't work with multiple delegates (as its similar to having a Skin that has multiple focusable controls)? ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1632#discussion_r2200312566