The FocusScope class holds the attributes of a focus scope: More...
#include <kanzi/core.ui/input/focus_scope.hpp>
Classes | |
class | FocusChain |
The FocusChain contains the snapshot of the focus chain of a focus scope. More... | |
Public Types | |
using | FocusChainSharedPtr = shared_ptr< FocusChain > |
The focus chain pointer type. More... | |
Public Member Functions | |
bool | canFocusEnter () const |
Returns whether the focus can enter the focus scope. More... | |
bool | canFocusLeave () const |
Returns whether the focus can leave the focus scope. More... | |
bool | canGetLastFocused () const |
Returns whether the focus scope node can be the last-focused node of its owning focus scope. More... | |
NodeSharedPtr | findNodeToRecoverFocusWhenScopeChangeTo (FocusScopePtr &newScopeInfo) const |
Finds a node to which Kanzi tries to set the focus after this focus scope changes to newScopeInfo and the scope type change itself did not restore focus to any node. More... | |
FocusChainNode | findNodeToRestoreFocusOn () |
Finds a focusable node to which tryRestoreScopeFocusedNode() restores the focus when called with Direction set to Next and Reason set to Force. More... | |
FocusChainNode | getFocus () const |
Returns the focus node of a focus scope. More... | |
FocusChainSharedPtr | getFocusChainSnapshot () |
Returns a snapshot of the focus chain of a focus scope. More... | |
FocusChainSharedPtr | getFocusChainSnapshot (bool onlyEffectivelyVisible) |
Returns a snapshot of the focus chain of a focus scope. More... | |
FocusNavigationManipulatorSharedPtr | getFocusNavigationManipulator () const |
Returns the focus navigation manipulator of a focus scope. More... | |
virtual OverlayScope * | getOverlayScope () const |
Returns the overlay scope that owns the focus scope. More... | |
virtual FocusScope * | getParent () const |
If a focus scope has a parent focus scope, returns the parent focus scope. More... | |
Node & | getRoot () const |
Returns the focus scope node. More... | |
virtual FocusScopeType | getType () const =0 |
Returns the type of the focus scope. More... | |
bool | isAttached () const |
Returns whether a focus scope node is attached. More... | |
bool | isFocusChainEmpty () const |
Returns whether the focus chain of a focus scope is empty. More... | |
bool | isFocusChainEmpty (bool onlyEffectivelyVisible) const |
Returns whether the focus chain of a focus scope is empty. More... | |
virtual bool | isNodeInScope (const Node &node) const |
Returns whether a node is in a focus scope. More... | |
void | setFocusNavigationManipulator (FocusNavigationManipulatorSharedPtr newManipulator) |
Sets the focus navigation manipulator of the focus scope. More... | |
FocusChainNode | tryMoveFocusInScope (FocusChainDirection direction) |
Tries to set the focus to a node relative to the current focus node of the focus scope using the focus chain navigation. More... | |
FocusChainNode | tryRestoreScopeFocusedNode (Node *currentFocus, FocusReason reason, FocusChainDirection direction) |
Tries to restore the focus to the last-focused node of a focus scope. More... | |
Node::VisitorResult | visitFocusChain (FocusScopeVisitor &visitor) |
Visits the focus chain of the focus scope, and calls the visitor on each node. More... | |
Node::VisitorResult | visitFocusScope (FocusScopeVisitor &visitor) |
Visits the focusable nodes of the focus scope, including nested focus scope nodes. More... | |
virtual | ~FocusScope () |
Destructor. More... | |
The last-focused node | |
FocusChainIndex | getLastFocused () const |
Returns the focus chain index of the last-focused node of a focus scope. More... | |
void | setLastFocused (const FocusChainIndex &lastFocus) |
Sets the focus chain index of the last-focused node of the focus scope. More... | |
void | clearLastFocused () |
Clears the focus chain index of the last-focused node of a focus scope. More... | |
FocusChainNode | getLastFocusedNode () const |
Returns the last-focused node of a focus scope. More... | |
FocusChainNode | setLastFocusedNode (const Node &lastFocused) |
Sets the last-focused node of a focus scope. More... | |
void | clearLastFocusedNode () |
Set the Node::FocusedProperty value to false, Node::FocusStateProperty to FocusState::NoFocus, and clears the last-focused node of a focus scope. More... | |
Static Public Member Functions | |
static FocusScopePtr | create (FocusScopeType type, Node &rootNode) |
Creates an instance of a focus scope type, with the rootNode as the focus scope node. More... | |
static FocusScopePtr | create (Node &rootNode) |
Creates a focus scope type instance with the rootNode as the root of the focus scope. More... | |
static void | swapScope (FocusScopePtr &newScopeInfo, FocusScopePtr &nodeScopeInfo) |
Safely swaps the focus scope info nodeScopeInfo of a node with the newScopeInfo. More... | |
Protected Member Functions | |
void | focusNavigationHandler (FocusManager::MoveFocusMessageArguments &args) |
Navigates the focus in a scope. More... | |
FocusScope (Node &scopeNode, ScopeFlag flags) | |
Constructor. More... | |
void | invalidateFocusChain () |
Invalidates the focus chain of the focus scope, including the focus chain snapshots of its nested focus scopes. More... | |
virtual void | joinScope (FocusScope &target) |
Joins the last-focused node of this scope with the target focus scope, if the last-focused node of the target scope is the scope node of this focus scope. More... | |
void | notifyInvalidateFocusChain () override |
Kanzi calls this method to invalidate the focus chain snapshots of the focus scope. More... | |
void | notifyNodeAttached (Node &node) override |
FocusManager calls this method when a node is attached to the node tree. More... | |
void | notifyNodeDetached (Node &node) override |
FocusManager calls this method to notify that a node from the scope is detached. More... | |
virtual void | notifyScopeTypeChange (FocusScope &oldScopeData) |
Notifies that the focus scope type of this scope changed from oldScopeData. More... | |
virtual void | splitScope (FocusScope *target, FocusChainNode targetLastFocusedNode) |
Splits the last-focused node of a target scope with this focus scope. More... | |
void | swapScopeData (FocusScope &other) |
Swaps the focus scope data of this scope with the focus scope data of the source scope. More... | |
The FocusScope class holds the attributes of a focus scope:
The root node of a focus scope is called the focus scope node.
The Node class creates the focus scope information when you set the FocusManager::FocusScopeTypeProperty on a node. When you attach an overlay focus scope node to the node tree, Kanzi registers the scope to the FocusManager.
The class provides the interface for FocusManager on testing focusable node candidates. When testing a node, or querying the focus scope for the next focus candidate, FocusScope checks that:
using kanzi::FocusScope::FocusChainSharedPtr = shared_ptr<FocusChain> |
The focus chain pointer type.
|
virtual |
Destructor.
|
explicitprotected |
Constructor.
scopeNode | The focus scope node. |
flags | The focus scope flags. |
|
static |
Creates an instance of a focus scope type, with the rootNode as the focus scope node.
type | The focus scope type to create. |
rootNode | The focus scope node. |
|
static |
Creates a focus scope type instance with the rootNode as the root of the focus scope.
The FocusManager::FocusScopeTypeProperty attached to the rootNode defines the type of the focus scope instance.
rootNode | The focus scope node. |
|
static |
Safely swaps the focus scope info nodeScopeInfo of a node with the newScopeInfo.
Joins, splits or updates the new nodeScopeInfo based on the new scope info passed as argument. The function asserts if the two focus scope types have different root node.
newScopeInfo | The new focus scope info to swap with the scope info. |
nodeScopeInfo | The address of the focus scope info structure to swap. |
bool kanzi::FocusScope::isAttached | ( | ) | const |
Returns whether a focus scope node is attached.
Node& kanzi::FocusScope::getRoot | ( | ) | const |
Returns the focus scope node.
|
virtual |
If a focus scope has a parent focus scope, returns the parent focus scope.
Reimplemented in kanzi::OverlayScope.
|
virtual |
Returns the overlay scope that owns the focus scope.
Reimplemented in kanzi::OverlayScope.
|
pure virtual |
Returns the type of the focus scope.
Implemented in kanzi::AutoClosingModelessScope, kanzi::ModelessScope, kanzi::AutoClosingModalScope, kanzi::ModalScope, kanzi::FocusFence, and kanzi::FocusGroup.
|
virtual |
Returns whether a node is in a focus scope.
node | The node to check whether it is in the current focus scope. Skips nested overlay focus scopes. |
Reimplemented in kanzi::OverlayScope.
FocusChainNode kanzi::FocusScope::getFocus | ( | ) | const |
Returns the focus node of a focus scope.
FocusChainIndex kanzi::FocusScope::getLastFocused | ( | ) | const |
Returns the focus chain index of the last-focused node of a focus scope.
void kanzi::FocusScope::setLastFocused | ( | const FocusChainIndex & | lastFocus | ) |
Sets the focus chain index of the last-focused node of the focus scope.
lastFocus | The focus chain index of the last-focused node. |
void kanzi::FocusScope::clearLastFocused | ( | ) |
Clears the focus chain index of the last-focused node of a focus scope.
FocusChainNode kanzi::FocusScope::getLastFocusedNode | ( | ) | const |
Returns the last-focused node of a focus scope.
FocusChainNode kanzi::FocusScope::setLastFocusedNode | ( | const Node & | lastFocused | ) |
Sets the last-focused node of a focus scope.
lastFocused | The node to set as the last-focused node of the focus scope. |
void kanzi::FocusScope::clearLastFocusedNode | ( | ) |
Set the Node::FocusedProperty value to false, Node::FocusStateProperty to FocusState::NoFocus, and clears the last-focused node of a focus scope.
Node::VisitorResult kanzi::FocusScope::visitFocusScope | ( | FocusScopeVisitor & | visitor | ) |
Visits the focusable nodes of the focus scope, including nested focus scope nodes.
Generates the focus order offset for each node of the focus scope, and calls the visitor on each focusable node.
visitor | The focus scope visitor. |
Node::VisitorResult kanzi::FocusScope::visitFocusChain | ( | FocusScopeVisitor & | visitor | ) |
Visits the focus chain of the focus scope, and calls the visitor on each node.
visitor | The focus chain visitor. |
FocusChainSharedPtr kanzi::FocusScope::getFocusChainSnapshot | ( | ) |
Returns a snapshot of the focus chain of a focus scope.
FocusChainSharedPtr kanzi::FocusScope::getFocusChainSnapshot | ( | bool | onlyEffectivelyVisible | ) |
Returns a snapshot of the focus chain of a focus scope.
The snapshot contains either:
onlyEffectivelyVisible | If you pass true, Kanzi returns a focus chain snapshot which contains the effectively visible nodes. If you pass false, Kanzi returns a focus chain snapshot which contains the visible, but effectively invisible nodes. |
bool kanzi::FocusScope::isFocusChainEmpty | ( | ) | const |
Returns whether the focus chain of a focus scope is empty.
The focus chain of a focus scope is empty if the focus scope does not contain any focusable nodes.
bool kanzi::FocusScope::isFocusChainEmpty | ( | bool | onlyEffectivelyVisible | ) | const |
Returns whether the focus chain of a focus scope is empty.
The focus chain of a focus scope is empty if the focus scope does not contain any focusable nodes.
onlyEffectivelyVisible | To include in the check only effectively visible nodes, pass true. To include also nodes that have the Node::VisibleProperty set to true but are effectively invisible, pass false. |
FocusNavigationManipulatorSharedPtr kanzi::FocusScope::getFocusNavigationManipulator | ( | ) | const |
Returns the focus navigation manipulator of a focus scope.
void kanzi::FocusScope::setFocusNavigationManipulator | ( | FocusNavigationManipulatorSharedPtr | newManipulator | ) |
Sets the focus navigation manipulator of the focus scope.
To remove the focus navigation manipulator from an attached node, pass a nullptr as argument.
newManipulator | The pointer to the focus navigation manipulator to set. To remove the focus manipulator from the focus scope, use nullptr. |
bool kanzi::FocusScope::canFocusEnter | ( | ) | const |
Returns whether the focus can enter the focus scope.
bool kanzi::FocusScope::canFocusLeave | ( | ) | const |
Returns whether the focus can leave the focus scope.
bool kanzi::FocusScope::canGetLastFocused | ( | ) | const |
Returns whether the focus scope node can be the last-focused node of its owning focus scope.
FocusChainNode kanzi::FocusScope::tryRestoreScopeFocusedNode | ( | Node * | currentFocus, |
FocusReason | reason, | ||
FocusChainDirection | direction | ||
) |
Tries to restore the focus to the last-focused node of a focus scope.
If the focus scope has no last-focused node, sets the focus to the first or last focusable node of the focus scope. If the root node of the focus scope has no focusable children, but the root node can hold focus, sets focus to the root node of the focus scope.
currentFocus | The node from which to remove the focus. |
reason | The reason to move the focus. |
direction | The direction based on which Kanzi moves the focus to the first or last focusable node of the focus chain. |
FocusChainNode kanzi::FocusScope::tryMoveFocusInScope | ( | FocusChainDirection | direction | ) |
Tries to set the focus to a node relative to the current focus node of the focus scope using the focus chain navigation.
The method takes the next focus candidate from the focus chain of the focus scope and its nested focus scopes in the given direction.
If the focus scope has no last-focused node set, the method sets the focus to:
The method fails if the focus scope has no focusable descendant node, or if there is no existing application focus.
direction | The direction in which to query for the next focusable node. |
FocusChainNode kanzi::FocusScope::findNodeToRestoreFocusOn | ( | ) |
Finds a focusable node to which tryRestoreScopeFocusedNode() restores the focus when called with Direction set to Next and Reason set to Force.
NodeSharedPtr kanzi::FocusScope::findNodeToRecoverFocusWhenScopeChangeTo | ( | FocusScopePtr & | newScopeInfo | ) | const |
Finds a node to which Kanzi tries to set the focus after this focus scope changes to newScopeInfo and the scope type change itself did not restore focus to any node.
|
protected |
Invalidates the focus chain of the focus scope, including the focus chain snapshots of its nested focus scopes.
|
protectedvirtual |
Splits the last-focused node of a target scope with this focus scope.
Kanzi assumes that the target scope is the parent focus scope of this scope. If the target focus scope holds the focus node, the last-focused node of target is set to the last-focused node of this scope.
target | The target focus scope to split. |
targetLastFocusedNode | The last-focused node of the target focus scope. |
Reimplemented in kanzi::OverlayScope.
|
protectedvirtual |
Joins the last-focused node of this scope with the target focus scope, if the last-focused node of the target scope is the scope node of this focus scope.
Prepares this scope for destruction.
target | The focus scope to which you want to merge this focus scope. |
Reimplemented in kanzi::OverlayScope.
|
protectedvirtual |
Notifies that the focus scope type of this scope changed from oldScopeData.
oldScopeData | The previous scope data of the focus scope that changed. |
Reimplemented in kanzi::OverlayScope.
|
overrideprotected |
FocusManager calls this method when a node is attached to the node tree.
node | The node attached to the node tree. |
|
overrideprotected |
FocusManager calls this method to notify that a node from the scope is detached.
node | The detached node. |
|
inlineoverrideprotected |
Kanzi calls this method to invalidate the focus chain snapshots of the focus scope.
When Kanzi invalidates a focus chain snapshot, all its nested focus chain snapshots are also invalidated.
|
protected |
Swaps the focus scope data of this scope with the focus scope data of the source scope.
other | The focus scope with which the scope data is to switch. |
|
protected |
Navigates the focus in a scope.
args | The navigation message arguments received from the FocusNavigationManipulator. |