pub struct FocusManager {
pub focused_node: Option<DomNodeId>,
pub pending_focus_request: Option<FocusTarget>,
pub cursor_needs_initialization: bool,
pub pending_contenteditable_focus: Option<PendingContentEditableFocus>,
}Expand description
Manager for keyboard focus and tab navigation
Note: Text cursor management is now handled by the separate CursorManager.
The FocusManager only tracks which node has focus, while CursorManager
tracks the cursor position within that node (if it’s contenteditable).
§W3C Focus/Selection Model
The W3C model maintains a strict separation between keyboard focus and selection:
- Focus lands on the contenteditable container (
document.activeElement) - Selection/Cursor is placed in a descendant text node (
Selection.focusNode)
This separation requires a “flag and defer” pattern:
- During focus event: Set
cursor_needs_initialization = true - After layout pass: Call
finalize_pending_focus_changes()to actually initialize the cursor
This is necessary because cursor positioning requires text layout information, which isn’t available during the focus event handling phase.
Fields§
§focused_node: Option<DomNodeId>Currently focused node (if any)
pending_focus_request: Option<FocusTarget>Pending focus request from callback
cursor_needs_initialization: boolFlag indicating that cursor initialization is pending (set during focus, consumed after layout)
pending_contenteditable_focus: Option<PendingContentEditableFocus>Information about the pending contenteditable focus
Implementations§
Source§impl FocusManager
impl FocusManager
Sourcepub fn get_focused_node(&self) -> Option<&DomNodeId>
pub fn get_focused_node(&self) -> Option<&DomNodeId>
Get the currently focused node
Sourcepub fn set_focused_node(&mut self, node: Option<DomNodeId>)
pub fn set_focused_node(&mut self, node: Option<DomNodeId>)
Set the focused node directly (used by event system)
Note: Cursor initialization/clearing is now handled by CursorManager.
The event system should check if the newly focused node is contenteditable
and call CursorManager::initialize_cursor_at_end() if needed.
Sourcepub fn request_focus_change(&mut self, target: FocusTarget)
pub fn request_focus_change(&mut self, target: FocusTarget)
Request a focus change (to be processed by event system)
Sourcepub fn take_focus_request(&mut self) -> Option<FocusTarget>
pub fn take_focus_request(&mut self) -> Option<FocusTarget>
Take the pending focus request (one-shot)
Sourcepub fn clear_focus(&mut self)
pub fn clear_focus(&mut self)
Clear focus
Sourcepub fn set_pending_contenteditable_focus(
&mut self,
dom_id: DomId,
container_node_id: NodeId,
text_node_id: NodeId,
)
pub fn set_pending_contenteditable_focus( &mut self, dom_id: DomId, container_node_id: NodeId, text_node_id: NodeId, )
Mark that cursor initialization is needed for a contenteditable element.
This is called during focus event handling. The actual cursor initialization
happens later in finalize_pending_focus_changes() after layout is complete.
§W3C Conformance
In the W3C model, when focus lands on a contenteditable element:
- The focus event fires on the container element
- The browser’s editing engine modifies the Selection to place a caret
- The Selection’s anchorNode/focusNode point to the child text node
Since we need layout information to position the cursor, we defer step 2+3.
Sourcepub fn clear_pending_contenteditable_focus(&mut self)
pub fn clear_pending_contenteditable_focus(&mut self)
Clear the pending contenteditable focus (when focus moves away or is cleared).
Sourcepub fn take_pending_contenteditable_focus(
&mut self,
) -> Option<PendingContentEditableFocus>
pub fn take_pending_contenteditable_focus( &mut self, ) -> Option<PendingContentEditableFocus>
Take the pending contenteditable focus (consumes the flag).
Returns Some(info) if cursor initialization is pending, None otherwise.
After calling this, cursor_needs_initialization is set to false.
Sourcepub fn needs_cursor_initialization(&self) -> bool
pub fn needs_cursor_initialization(&self) -> bool
Check if cursor initialization is pending.
Trait Implementations§
Source§impl Clone for FocusManager
impl Clone for FocusManager
Source§fn clone(&self) -> FocusManager
fn clone(&self) -> FocusManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FocusManager
impl Debug for FocusManager
Source§impl Default for FocusManager
impl Default for FocusManager
Source§impl FocusManagerQuery for FocusManager
impl FocusManagerQuery for FocusManager
Source§fn get_focused_node_id(&self) -> Option<DomNodeId>
fn get_focused_node_id(&self) -> Option<DomNodeId>
Source§impl PartialEq for FocusManager
impl PartialEq for FocusManager
impl StructuralPartialEq for FocusManager
Auto Trait Implementations§
impl Freeze for FocusManager
impl RefUnwindSafe for FocusManager
impl Send for FocusManager
impl Sync for FocusManager
impl Unpin for FocusManager
impl UnwindSafe for FocusManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more