On 18/08/2023 18:35, Michael Strauß wrote:
Scene graph nodes have three focus-related properties:
1. focused
2. focus-within
3. focus-visible

What might be a bit surprising is that multiple nodes can be focused
at the same time, but only one of those focused nodes can be the
scene's focus owner. The `Scene.focusOwner` property indicates which
of the focused nodes is the current focus owner.

Even more surprisingly, a node can be _unfocused_  and be the focus
owner at the same time (this can happen when the window is
deactivated).

 From the perspective of `Node`, there's currently no API to easily
determine whether it is the focus owner, and there's no CSS
pseudo-class that matches a node that is the focus owner.

Wouldn't `node.getScene().getFocusOwner() == node` do this?  Not for CSS, I agree.

I think it may be of benefit for my application. Focus for me is pretty useless as my application rarely has its Window focused -- the focus however is still visible and used (the application reacts to external commands given by remote control, no need for Window focus).  Using the `focused` pseudo class in stylesheets is pretty useless for me as whatever has focus won't show up when the main window doesn't have focus.  I've resorted to track the focus owner, and adding/removing a focused style class to the current focused node (and use the styleclass instead of the pseudo class in my stylesheets) -- this was before I knew you can also easily add a new pseudo class to a node, but a styleclass works fine for this purpose.

This potential new pseudo class (focus-owner) would have been a good alternative for me, although I will immediately admit that it probably is of very limited use for other applications.

There is also the internal-focus and external-focus pseudo classes for those of us using the TwoLevelFocusBehavior (especially useful for apps controlled by remote with limited keys to interact with controls).  I believe it may be removed in the future though, at least there is a ticket for that (unresolved).

--John


We could add two more properties to the `Node` class to support this use case:
4. focus-owner
5. focus-owner-within

Note that `focus-visible` only matches nodes that are also focus
owners, so there's no need to have a `focus-owner-visible` property.

The two additional properties would suffice to match any possible
focus state, but it might also be not useful enough to warrant the
additional API surface. What do you think?

Reply via email to