pub struct LayoutWindow {Show 30 fields
pub layout_cache: LayoutCache,
pub text_cache: LayoutCache,
pub font_manager: FontManager<FontRef>,
pub image_cache: ImageCache,
pub layout_results: BTreeMap<DomId, DomLayoutResult>,
pub scroll_manager: ScrollManager,
pub gesture_drag_manager: GestureAndDragManager,
pub focus_manager: FocusManager,
pub cursor_manager: CursorManager,
pub file_drop_manager: FileDropManager,
pub selection_manager: SelectionManager,
pub clipboard_manager: ClipboardManager,
pub drag_drop_manager: DragDropManager,
pub hover_manager: HoverManager,
pub iframe_manager: IFrameManager,
pub gpu_state_manager: GpuStateManager,
pub a11y_manager: A11yManager,
pub timers: BTreeMap<TimerId, Timer>,
pub threads: BTreeMap<ThreadId, Thread>,
pub renderer_resources: RendererResources,
pub renderer_type: Option<RendererType>,
pub previous_window_state: Option<FullWindowState>,
pub current_window_state: FullWindowState,
pub document_id: DocumentId,
pub id_namespace: IdNamespace,
pub epoch: Epoch,
pub gl_texture_cache: GlTextureCache,
pub text_input_manager: TextInputManager,
pub undo_redo_manager: UndoRedoManager,
pub pending_iframe_updates: BTreeMap<DomId, FastBTreeSet<NodeId>>,
/* private fields */
}Expand description
A window-level layout manager that encapsulates all layout state and caching.
This struct owns the layout and text caches, and provides methods dir_to:
- Perform initial layout
- Incrementally update layout on DOM changes
- Generate display lists for rendering
- Handle window resizes efficiently
- Manage multiple DOMs (for IFrames)
Fields§
§layout_cache: LayoutCacheLayout cache for solver3 (incremental layout tree) - for the root DOM
text_cache: LayoutCacheText layout cache for text3 (shaped glyphs, line breaks, etc.)
font_manager: FontManager<FontRef>Font manager for loading and caching fonts
image_cache: ImageCacheCache to store decoded images
layout_results: BTreeMap<DomId, DomLayoutResult>Cached layout results for all DOMs (root + iframes)
scroll_manager: ScrollManagerScroll state manager for all nodes across all DOMs
gesture_drag_manager: GestureAndDragManagerGesture and drag manager for multi-frame interactions (moved from FullWindowState)
focus_manager: FocusManagerFocus manager for keyboard focus and tab navigation
cursor_manager: CursorManagerCursor manager for text cursor position and rendering
file_drop_manager: FileDropManagerFile drop manager for cursor state and file drag-drop
selection_manager: SelectionManagerSelection manager for text selections across all DOMs
clipboard_manager: ClipboardManagerClipboard manager for system clipboard integration
drag_drop_manager: DragDropManagerDrag-drop manager for node and file dragging operations
hover_manager: HoverManagerHover manager for tracking hit test history over multiple frames
iframe_manager: IFrameManagerIFrame manager for all nodes across all DOMs
gpu_state_manager: GpuStateManagerGPU state manager for all nodes across all DOMs
a11y_manager: A11yManagerAccessibility manager for screen reader support
timers: BTreeMap<TimerId, Timer>Timers associated with this window
threads: BTreeMap<ThreadId, Thread>Threads running in the background for this window
renderer_resources: RendererResourcesCurrently loaded fonts and images present in this renderer (window)
renderer_type: Option<RendererType>Renderer type: Hardware-with-software-fallback, pure software or pure hardware renderer?
previous_window_state: Option<FullWindowState>Windows state of the window of (current frame - 1): initialized to None on startup
current_window_state: FullWindowStateWindow state of this current window (current frame): initialized to the state of WindowCreateOptions
document_id: DocumentIdA “document” in WebRender usually corresponds to one tab (i.e. in Azuls case, the whole window).
id_namespace: IdNamespaceID namespace under which every font / image for this window is registered
epoch: EpochThe “epoch” is a frame counter, to remove outdated images, fonts and OpenGL textures when they’re not in use anymore.
gl_texture_cache: GlTextureCacheCurrently GL textures inside the active CachedDisplayList
text_input_manager: TextInputManagerText input manager - centralizes all text editing logic
undo_redo_manager: UndoRedoManagerUndo/Redo manager for text editing operations
pending_iframe_updates: BTreeMap<DomId, FastBTreeSet<NodeId>>Pending IFrame updates from callbacks (processed in next frame) Map of DomId -> Set of NodeIds that need re-rendering
Implementations§
Source§impl LayoutWindow
impl LayoutWindow
Sourcepub fn new(fc_cache: FcFontCache) -> Result<Self, LayoutError>
pub fn new(fc_cache: FcFontCache) -> Result<Self, LayoutError>
Create a new layout window with empty caches.
For full initialization with WindowInternal compatibility, use new_full().
Sourcepub fn layout_and_generate_display_list(
&mut self,
root_dom: StyledDom,
window_state: &FullWindowState,
renderer_resources: &RendererResources,
system_callbacks: &ExternalSystemCallbacks,
debug_messages: &mut Option<Vec<LayoutDebugMessage>>,
) -> Result<(), LayoutError>
pub fn layout_and_generate_display_list( &mut self, root_dom: StyledDom, window_state: &FullWindowState, renderer_resources: &RendererResources, system_callbacks: &ExternalSystemCallbacks, debug_messages: &mut Option<Vec<LayoutDebugMessage>>, ) -> Result<(), LayoutError>
Perform layout on a styled DOM and generate a display list.
This is the main entry point for layout. It handles:
- Incremental layout updates using the cached layout tree
- Text shaping and line breaking
- IFrame callback invocation and recursive layout
- Display list generation for rendering
- Accessibility tree synchronization
§Arguments
styled_dom: The styled DOM to layoutwindow_state: Current window dimensions and staterenderer_resources: Resources for image sizing etc.debug_messages: Optional vector to collect debug/warning messages
§Returns
The display list ready for rendering, or an error if layout fails.
Sourcepub fn resize_window(
&mut self,
styled_dom: StyledDom,
new_size: LogicalSize,
renderer_resources: &RendererResources,
system_callbacks: &ExternalSystemCallbacks,
debug_messages: &mut Option<Vec<LayoutDebugMessage>>,
) -> Result<DisplayList, LayoutError>
pub fn resize_window( &mut self, styled_dom: StyledDom, new_size: LogicalSize, renderer_resources: &RendererResources, system_callbacks: &ExternalSystemCallbacks, debug_messages: &mut Option<Vec<LayoutDebugMessage>>, ) -> Result<DisplayList, LayoutError>
Handle a window resize by updating the cached layout.
This method leverages solver3’s incremental layout system to efficiently relayout only the affected parts of the tree when the window size changes.
Returns the new display list after the resize.
Sourcepub fn clear_caches(&mut self)
pub fn clear_caches(&mut self)
Clear all caches (useful for testing or when switching documents).
Sourcepub fn set_scroll_position(
&mut self,
dom_id: DomId,
node_id: NodeId,
scroll: ScrollPosition,
)
pub fn set_scroll_position( &mut self, dom_id: DomId, node_id: NodeId, scroll: ScrollPosition, )
Set scroll position for a node
Sourcepub fn get_scroll_position(
&self,
dom_id: DomId,
node_id: NodeId,
) -> Option<ScrollPosition>
pub fn get_scroll_position( &self, dom_id: DomId, node_id: NodeId, ) -> Option<ScrollPosition>
Get scroll position for a node
Sourcepub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)
pub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)
Set selection state for a DOM
Sourcepub fn get_selection(&self, dom_id: DomId) -> Option<&SelectionState>
pub fn get_selection(&self, dom_id: DomId) -> Option<&SelectionState>
Get selection state for a DOM
Sourcepub fn get_node_size(&self, node_id: DomNodeId) -> Option<LogicalSize>
pub fn get_node_size(&self, node_id: DomNodeId) -> Option<LogicalSize>
Get the size of a laid-out node
Sourcepub fn get_node_position(&self, node_id: DomNodeId) -> Option<LogicalPosition>
pub fn get_node_position(&self, node_id: DomNodeId) -> Option<LogicalPosition>
Get the position of a laid-out node
Sourcepub fn get_node_hit_test_bounds(
&self,
node_id: DomNodeId,
) -> Option<LogicalRect>
pub fn get_node_hit_test_bounds( &self, node_id: DomNodeId, ) -> Option<LogicalRect>
Get the hit test bounds of a node from the display list
This is more reliable than get_node_position + get_node_size because the display list always contains the correct final rendered positions, including for nodes that may not have entries in calculated_positions.
Sourcepub fn get_parent(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn get_parent(&self, node_id: DomNodeId) -> Option<DomNodeId>
Get the parent of a node
Sourcepub fn get_first_child(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn get_first_child(&self, node_id: DomNodeId) -> Option<DomNodeId>
Get the first child of a node
Sourcepub fn get_next_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn get_next_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>
Get the next sibling of a node
Sourcepub fn get_previous_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn get_previous_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>
Get the previous sibling of a node
Sourcepub fn get_last_child(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn get_last_child(&self, node_id: DomNodeId) -> Option<DomNodeId>
Get the last child of a node
Sourcepub fn scan_used_fonts(&self) -> BTreeSet<FontKey>
pub fn scan_used_fonts(&self) -> BTreeSet<FontKey>
Scan all fonts used in this LayoutWindow (for resource GC)
Sourcepub fn scan_used_images(
&self,
_css_image_cache: &ImageCache,
) -> BTreeSet<ImageRefHash>
pub fn scan_used_images( &self, _css_image_cache: &ImageCache, ) -> BTreeSet<ImageRefHash>
Scan all images used in this LayoutWindow (for resource GC)
Sourcepub fn scroll_node_into_view(
&mut self,
node_id: DomNodeId,
options: ScrollIntoViewOptions,
now: Instant,
) -> Vec<ScrollAdjustment>
pub fn scroll_node_into_view( &mut self, node_id: DomNodeId, options: ScrollIntoViewOptions, now: Instant, ) -> Vec<ScrollAdjustment>
Scroll a DOM node into view
This is the main API for scrolling elements into view. It handles:
- Finding scroll ancestors
- Calculating scroll deltas
- Applying scroll animations
§Arguments
node_id- The DOM node to scroll into viewoptions- Scroll alignment and animation optionsnow- Current timestamp for animations
§Returns
A vector of scroll adjustments that were applied
Sourcepub fn scroll_cursor_into_view(
&mut self,
cursor_rect: LogicalRect,
node_id: DomNodeId,
options: ScrollIntoViewOptions,
now: Instant,
) -> Vec<ScrollAdjustment>
pub fn scroll_cursor_into_view( &mut self, cursor_rect: LogicalRect, node_id: DomNodeId, options: ScrollIntoViewOptions, now: Instant, ) -> Vec<ScrollAdjustment>
Scroll a text cursor into view
Used when the cursor moves within a contenteditable element. The cursor rect should be in node-local coordinates.
Sourcepub fn remove_timer(&mut self, timer_id: &TimerId) -> Option<Timer>
pub fn remove_timer(&mut self, timer_id: &TimerId) -> Option<Timer>
Remove a timer from this window
Sourcepub fn get_timer_mut(&mut self, timer_id: &TimerId) -> Option<&mut Timer>
pub fn get_timer_mut(&mut self, timer_id: &TimerId) -> Option<&mut Timer>
Get a mutable reference to a timer
Sourcepub fn get_timer_ids(&self) -> TimerIdVec
pub fn get_timer_ids(&self) -> TimerIdVec
Get all timer IDs
Sourcepub fn tick_timers(&mut self, current_time: Instant) -> Vec<TimerId>
pub fn tick_timers(&mut self, current_time: Instant) -> Vec<TimerId>
Tick all timers (called once per frame) Returns a list of timer IDs that are ready to run
Sourcepub fn time_until_next_timer_ms(
&self,
get_system_time_fn: &GetSystemTimeCallback,
) -> Option<u64>
pub fn time_until_next_timer_ms( &self, get_system_time_fn: &GetSystemTimeCallback, ) -> Option<u64>
Calculate milliseconds until the next timer needs to fire.
Returns None if there are no timers, meaning the caller can block indefinitely.
Returns Some(0) if a timer is already overdue.
Otherwise returns the minimum time in milliseconds until any timer fires.
This is used by Linux (X11/Wayland) to set an efficient poll/select timeout instead of always polling every 16ms.
Sourcepub fn add_thread(&mut self, thread_id: ThreadId, thread: Thread)
pub fn add_thread(&mut self, thread_id: ThreadId, thread: Thread)
Add a thread to this window
Sourcepub fn remove_thread(&mut self, thread_id: &ThreadId) -> Option<Thread>
pub fn remove_thread(&mut self, thread_id: &ThreadId) -> Option<Thread>
Remove a thread from this window
Sourcepub fn get_thread(&self, thread_id: &ThreadId) -> Option<&Thread>
pub fn get_thread(&self, thread_id: &ThreadId) -> Option<&Thread>
Get a reference to a thread
Sourcepub fn get_thread_mut(&mut self, thread_id: &ThreadId) -> Option<&mut Thread>
pub fn get_thread_mut(&mut self, thread_id: &ThreadId) -> Option<&mut Thread>
Get a mutable reference to a thread
Sourcepub fn get_thread_ids(&self) -> ThreadIdVec
pub fn get_thread_ids(&self) -> ThreadIdVec
Get all thread IDs
Sourcepub fn create_cursor_blink_timer(
&self,
_window_state: &FullWindowState,
) -> Timer
pub fn create_cursor_blink_timer( &self, _window_state: &FullWindowState, ) -> Timer
Create the cursor blink timer
This timer toggles cursor visibility at ~530ms intervals. It checks if enough time has passed since the last user input before blinking, to avoid blinking while the user is actively typing.
Sourcepub fn scroll_active_cursor_into_view(
&mut self,
result: &mut CallbackChangeResult,
)
pub fn scroll_active_cursor_into_view( &mut self, result: &mut CallbackChangeResult, )
Scroll the active text cursor into view within its scrollable container
This finds the focused contenteditable node, gets the cursor rectangle, and scrolls any scrollable ancestor to ensure the cursor is visible.
Sourcepub fn handle_focus_change_for_cursor_blink(
&mut self,
new_focus: Option<DomNodeId>,
current_window_state: &FullWindowState,
) -> CursorBlinkTimerAction
pub fn handle_focus_change_for_cursor_blink( &mut self, new_focus: Option<DomNodeId>, current_window_state: &FullWindowState, ) -> CursorBlinkTimerAction
Handle focus change for cursor blink timer management (W3C “flag and defer” pattern)
This method implements the W3C focus/selection model:
- Focus change is handled immediately (timer start/stop)
- Cursor initialization is DEFERRED until after layout (via flag)
The cursor is NOT initialized here because text layout may not be available
during focus event handling. Instead, we set a flag that is consumed by
finalize_pending_focus_changes() after the layout pass.
§Parameters
new_focus- The newly focused node (None if focus is being cleared)current_window_state- Current window state for timer creation
§Returns
A CursorBlinkTimerAction indicating what timer action the platform
layer should take.
Sourcepub fn finalize_pending_focus_changes(&mut self) -> bool
pub fn finalize_pending_focus_changes(&mut self) -> bool
Finalize pending focus changes after layout pass (W3C “flag and defer” pattern)
This method should be called AFTER the layout pass completes. It checks if there’s a pending contenteditable focus and initializes the cursor now that text layout information is available.
§W3C Conformance
In the W3C model:
- Focus event fires during event handling (layout may not be ready)
- Selection/cursor placement happens after layout is computed
- The cursor is drawn at the position specified by the Selection
This function implements step 2+3 by:
- Checking the
cursor_needs_initializationflag - Getting the (now available) text layout
- Initializing the cursor at the correct position
§Returns
true if cursor was initialized, false if no pending focus or initialization failed.
Sourcepub fn apply_callback_changes(
&mut self,
changes: Vec<CallbackChange>,
current_window_state: &FullWindowState,
image_cache: &mut ImageCache,
system_fonts: &mut FcFontCache,
) -> CallbackChangeResult
pub fn apply_callback_changes( &mut self, changes: Vec<CallbackChange>, current_window_state: &FullWindowState, image_cache: &mut ImageCache, system_fonts: &mut FcFontCache, ) -> CallbackChangeResult
Apply callback changes that were collected during callback execution
This method processes all changes accumulated in the CallbackChange vector and applies them to the appropriate state. This is called after a callback returns to ensure atomic application of all changes.
Returns a CallbackChangeResult containing all the changes to be applied.
Sourcepub fn get_gpu_cache(&self, dom_id: &DomId) -> Option<&GpuValueCache>
pub fn get_gpu_cache(&self, dom_id: &DomId) -> Option<&GpuValueCache>
Get the GPU value cache for a specific DOM
Sourcepub fn get_gpu_cache_mut(
&mut self,
dom_id: &DomId,
) -> Option<&mut GpuValueCache>
pub fn get_gpu_cache_mut( &mut self, dom_id: &DomId, ) -> Option<&mut GpuValueCache>
Get a mutable reference to the GPU value cache for a specific DOM
Sourcepub fn get_or_create_gpu_cache(&mut self, dom_id: DomId) -> &mut GpuValueCache
pub fn get_or_create_gpu_cache(&mut self, dom_id: DomId) -> &mut GpuValueCache
Get or create a GPU value cache for a specific DOM
Sourcepub fn get_layout_result(&self, dom_id: &DomId) -> Option<&DomLayoutResult>
pub fn get_layout_result(&self, dom_id: &DomId) -> Option<&DomLayoutResult>
Get a layout result for a specific DOM
Sourcepub fn get_layout_result_mut(
&mut self,
dom_id: &DomId,
) -> Option<&mut DomLayoutResult>
pub fn get_layout_result_mut( &mut self, dom_id: &DomId, ) -> Option<&mut DomLayoutResult>
Get a mutable layout result for a specific DOM
Sourcepub fn get_dom_ids(&self) -> DomIdVec
pub fn get_dom_ids(&self) -> DomIdVec
Get all DOM IDs that have layout results
Sourcepub fn compute_cursor_type_hit_test(
&self,
hit_test: &FullHitTest,
) -> CursorTypeHitTest
pub fn compute_cursor_type_hit_test( &self, hit_test: &FullHitTest, ) -> CursorTypeHitTest
Compute the cursor type hit-test from a full hit-test
This determines which mouse cursor to display based on the CSS cursor properties of the hovered nodes.
Sourcepub fn synchronize_scrollbar_opacity(
gpu_state_manager: &mut GpuStateManager,
scroll_manager: &ScrollManager,
dom_id: DomId,
layout_tree: &LayoutTree,
system_callbacks: &ExternalSystemCallbacks,
fade_delay: Duration,
fade_duration: Duration,
) -> Vec<GpuScrollbarOpacityEvent>
pub fn synchronize_scrollbar_opacity( gpu_state_manager: &mut GpuStateManager, scroll_manager: &ScrollManager, dom_id: DomId, layout_tree: &LayoutTree, system_callbacks: &ExternalSystemCallbacks, fade_delay: Duration, fade_duration: Duration, ) -> Vec<GpuScrollbarOpacityEvent>
Synchronize scrollbar opacity values with the GPU value cache.
Static method that takes individual components instead of &mut self to avoid borrow conflicts.
Sourcepub fn compute_scroll_ids(
layout_tree: &LayoutTree,
styled_dom: &StyledDom,
) -> (BTreeMap<usize, u64>, BTreeMap<u64, NodeId>)
pub fn compute_scroll_ids( layout_tree: &LayoutTree, styled_dom: &StyledDom, ) -> (BTreeMap<usize, u64>, BTreeMap<u64, NodeId>)
Compute stable scroll IDs for all scrollable nodes in a layout tree
This should be called after layout but before display list generation. It creates stable IDs based on node_data_hash that persist across frames.
Returns:
- scroll_ids: Map from layout node index -> external scroll ID
- scroll_id_to_node_id: Map from scroll ID -> DOM NodeId (for hit testing)
Sourcepub fn get_node_layout_rect(&self, node_id: DomNodeId) -> Option<LogicalRect>
pub fn get_node_layout_rect(&self, node_id: DomNodeId) -> Option<LogicalRect>
Get the layout rectangle for a specific DOM node in logical coordinates
This is useful in callbacks to get the position and size of the hit node for positioning menus, tooltips, or other overlays.
Returns None if the node is not currently laid out (e.g., display:none)
Sourcepub fn get_focused_cursor_rect(&self) -> Option<LogicalRect>
pub fn get_focused_cursor_rect(&self) -> Option<LogicalRect>
Get the cursor rect for the currently focused text input node in ABSOLUTE coordinates.
This returns the cursor position in absolute window coordinates (not accounting for scroll offsets). This is used for scroll-into-view calculations where you need to compare the cursor position with the scrollable container’s bounds.
Returns None if:
- No node is focused
- Focused node has no text cursor
- Focused node has no layout
- Text cache cannot find cursor position
For IME positioning (viewport-relative coordinates), use
get_focused_cursor_rect_viewport().
Sourcepub fn get_focused_cursor_rect_viewport(&self) -> Option<LogicalRect>
pub fn get_focused_cursor_rect_viewport(&self) -> Option<LogicalRect>
Get the cursor rect for the currently focused text input node in VIEWPORT coordinates.
This returns the cursor position accounting for:
- Scroll offsets from all scrollable ancestors
- GPU transforms (CSS transforms, animations) from all transformed ancestors
The returned position is viewport-relative (what the user actually sees on screen). This is used for IME window positioning, where the IME popup needs to appear at the visible cursor location, not the absolute layout position.
Returns None if:
- No node is focused
- Focused node has no text cursor
- Focused node has no layout
- Text cache cannot find cursor position
For scroll-into-view calculations (absolute coordinates), use get_focused_cursor_rect().
Sourcepub fn find_scrollable_ancestor(&self, node_id: DomNodeId) -> Option<DomNodeId>
pub fn find_scrollable_ancestor(&self, node_id: DomNodeId) -> Option<DomNodeId>
Find the nearest scrollable ancestor for a given node Returns (DomId, NodeId) of the scrollable container, or None if no scrollable ancestor exists
Sourcepub fn scroll_selection_into_view(
&mut self,
scroll_type: SelectionScrollType,
scroll_mode: ScrollMode,
) -> bool
pub fn scroll_selection_into_view( &mut self, scroll_type: SelectionScrollType, scroll_mode: ScrollMode, ) -> bool
Scroll selection or cursor into view with distance-based acceleration.
Unified Scroll System: This method handles both cursor (0-size selection) and full selection scrolling with a single implementation. For drag-to-scroll, scroll speed increases with distance from container edge.
§Algorithm
- Get bounds to scroll (cursor rect, selection rect, or mouse position)
- Find scrollable ancestor container
- Calculate distance from bounds to container edges
- Compute scroll delta (instant with padding, or accelerated with zones)
- Apply scroll with appropriate animation
§Distance-Based Acceleration (ScrollMode::Accelerated)
Distance from edge: Scroll speed per frame:
0-20px Dead zone (no scroll)
20-50px Slow (2px/frame)
50-100px Medium (4px/frame)
100-200px Fast (8px/frame)
200+px Very fast (16px/frame)§Returns
true if scrolling was applied, false if already visible
Source§impl LayoutWindow
impl LayoutWindow
Sourcepub fn run_single_timer(
&mut self,
timer_id: usize,
frame_start: Instant,
current_window_handle: &RawWindowHandle,
gl_context: &OptionGlContextPtr,
image_cache: &mut ImageCache,
system_fonts: &mut FcFontCache,
system_style: Arc<SystemStyle>,
system_callbacks: &ExternalSystemCallbacks,
previous_window_state: &Option<FullWindowState>,
current_window_state: &FullWindowState,
renderer_resources: &RendererResources,
) -> CallCallbacksResult
pub fn run_single_timer( &mut self, timer_id: usize, frame_start: Instant, current_window_handle: &RawWindowHandle, gl_context: &OptionGlContextPtr, image_cache: &mut ImageCache, system_fonts: &mut FcFontCache, system_style: Arc<SystemStyle>, system_callbacks: &ExternalSystemCallbacks, previous_window_state: &Option<FullWindowState>, current_window_state: &FullWindowState, renderer_resources: &RendererResources, ) -> CallCallbacksResult
Runs a single timer, similar to CallbacksOfHitTest.call()
NOTE: The timer has to be selected first by the calling code and verified that it is ready to run
pub fn run_all_threads( &mut self, data: &mut RefAny, current_window_handle: &RawWindowHandle, gl_context: &OptionGlContextPtr, image_cache: &mut ImageCache, system_fonts: &mut FcFontCache, system_style: Arc<SystemStyle>, system_callbacks: &ExternalSystemCallbacks, previous_window_state: &Option<FullWindowState>, current_window_state: &FullWindowState, renderer_resources: &RendererResources, ) -> CallCallbacksResult
Sourcepub fn invoke_single_callback(
&mut self,
callback: &mut Callback,
data: &mut RefAny,
current_window_handle: &RawWindowHandle,
gl_context: &OptionGlContextPtr,
image_cache: &mut ImageCache,
system_fonts: &mut FcFontCache,
system_style: Arc<SystemStyle>,
system_callbacks: &ExternalSystemCallbacks,
previous_window_state: &Option<FullWindowState>,
current_window_state: &FullWindowState,
renderer_resources: &RendererResources,
) -> CallCallbacksResult
pub fn invoke_single_callback( &mut self, callback: &mut Callback, data: &mut RefAny, current_window_handle: &RawWindowHandle, gl_context: &OptionGlContextPtr, image_cache: &mut ImageCache, system_fonts: &mut FcFontCache, system_style: Arc<SystemStyle>, system_callbacks: &ExternalSystemCallbacks, previous_window_state: &Option<FullWindowState>, current_window_state: &FullWindowState, renderer_resources: &RendererResources, ) -> CallCallbacksResult
Invokes a single callback (used for on_window_create, on_window_shutdown, etc.)
Invokes a menu callback
Source§impl LayoutWindow
impl LayoutWindow
Sourcepub fn find_next_text_node(
&self,
dom_id: &DomId,
current_node: NodeId,
) -> Option<(DomId, NodeId)>
pub fn find_next_text_node( &self, dom_id: &DomId, current_node: NodeId, ) -> Option<(DomId, NodeId)>
Finds the next text node in the DOM tree after the given node.
This function performs a depth-first traversal to find the next node that contains text content and is selectable (user-select != none).
§Arguments
dom_id- The ID of the DOM containing the current nodecurrent_node- The current node ID to start searching from
§Returns
Some((DomId, NodeId))- The next text node if foundNone- If no next text node exists
Sourcepub fn find_prev_text_node(
&self,
dom_id: &DomId,
current_node: NodeId,
) -> Option<(DomId, NodeId)>
pub fn find_prev_text_node( &self, dom_id: &DomId, current_node: NodeId, ) -> Option<(DomId, NodeId)>
Finds the previous text node in the DOM tree before the given node.
This function performs a reverse depth-first traversal to find the previous node that contains text content and is selectable.
§Arguments
dom_id- The ID of the DOM containing the current nodecurrent_node- The current node ID to start searching from
§Returns
Some((DomId, NodeId))- The previous text node if foundNone- If no previous text node exists
Sourcepub fn process_accessibility_action(
&mut self,
dom_id: DomId,
node_id: NodeId,
action: AccessibilityAction,
now: Instant,
) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
pub fn process_accessibility_action( &mut self, dom_id: DomId, node_id: NodeId, action: AccessibilityAction, now: Instant, ) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
Process an accessibility action from an assistive technology.
This method dispatches actions to the appropriate managers (scroll, focus, etc.) and returns information about which nodes were affected and how.
§Arguments
dom_id- The DOM containing the target nodenode_id- The target node for the actionaction- The accessibility action to performnow- Current timestamp for animations
§Returns
A BTreeMap of affected nodes with:
- Key: DomNodeId that was affected
- Value: (Vec
synthetic events to dispatch, bool indicating if node needs re-layout)
Empty map = action was not applicable or nothing changed
Sourcepub fn record_text_input(
&mut self,
text_input: &str,
) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
pub fn record_text_input( &mut self, text_input: &str, ) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
Process text input from keyboard using cursor/selection/focus managers.
This is the new unified text input handling. The framework manages text editing internally using managers, then fires callbacks (On::TextInput, On::Changed) after the internal state is already updated.
§Workflow
- Check if focus manager has a focused contenteditable node
- Get cursor/selection from managers
- Call edit_text_node to apply the edit and update cache
- Collect affected nodes that need dirty marking
- Return map for re-layout triggering
§Parameters
text_input- The text that was typed (can be multiple chars for IME)
§Returns
BTreeMap of affected nodes with:
- Key: DomNodeId that was affected
- Value: (Vec
synthetic events, bool needs_relayout) - Empty map = no focused contenteditable node
Sourcepub fn apply_text_changeset(&mut self) -> Vec<DomNodeId>
pub fn apply_text_changeset(&mut self) -> Vec<DomNodeId>
Apply the recorded text changeset to the text cache
This is called AFTER user callbacks, if preventDefault was not set. This is where we actually compute the new text and update the cache.
Also updates the cursor position to reflect the edit.
Returns the nodes that need to be marked dirty for re-layout.
Sourcepub fn process_text_input(
&mut self,
text_input: &str,
) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
pub fn process_text_input( &mut self, text_input: &str, ) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>
Legacy name for backward compatibility
Sourcepub fn get_last_text_changeset(&self) -> Option<&PendingTextEdit>
pub fn get_last_text_changeset(&self) -> Option<&PendingTextEdit>
Get the last text changeset (what was changed in the last text input)
Sourcepub fn get_text_before_textinput(
&self,
dom_id: DomId,
node_id: NodeId,
) -> Vec<InlineContent>
pub fn get_text_before_textinput( &self, dom_id: DomId, node_id: NodeId, ) -> Vec<InlineContent>
Get the current inline content (text before text input is applied)
This is a query function that retrieves the current text state from the node. Returns InlineContent vector if the node has text.
§Implementation Note
This function FIRST checks dirty_text_nodes for optimistic state (edits not yet
committed to StyledDom), then falls back to the StyledDom. This is critical for
correct text input handling - without this, each keystroke would read stale state.
Sourcepub fn extract_text_from_inline_content(
&self,
content: &[InlineContent],
) -> String
pub fn extract_text_from_inline_content( &self, content: &[InlineContent], ) -> String
Extract plain text string from inline content
This is a helper for building the changeset’s resulting_text field.
Sourcepub fn update_text_cache_after_edit(
&mut self,
dom_id: DomId,
node_id: NodeId,
new_inline_content: Vec<InlineContent>,
)
pub fn update_text_cache_after_edit( &mut self, dom_id: DomId, node_id: NodeId, new_inline_content: Vec<InlineContent>, )
Update the text cache after a text edit
This is the ONLY place where we mutate the text cache. All other functions are pure queries or transformations.
This function:
- Stores the new content in
dirty_text_nodesfor tracking - Re-runs the text3 layout pipeline (create_logical_items -> reorder -> shape -> fragment)
- Updates the inline_layout_result on the IFC root node in the layout tree
Sourcepub fn sync_cursor_to_selection_manager(&mut self)
pub fn sync_cursor_to_selection_manager(&mut self)
Sync cursor from CursorManager to SelectionManager for rendering
The renderer expects cursor and selection data from the SelectionManager, but we manage the cursor separately in the CursorManager for better separation of concerns. This function syncs the cursor state so it can be rendered.
This should be called whenever the cursor changes.
Sourcepub fn edit_text_node(
&mut self,
dom_id: DomId,
node_id: NodeId,
edit_type: TextEditType,
) -> Vec<DomNodeId>
pub fn edit_text_node( &mut self, dom_id: DomId, node_id: NodeId, edit_type: TextEditType, ) -> Vec<DomNodeId>
Edit the text content of a node (used for text input actions)
This function applies text edits to nodes that contain text content. The DOM node itself is NOT modified - instead, the text cache is updated with the new shaped text that reflects the edit, cursor, and selection.
It handles:
- ReplaceSelectedText: Replaces the current selection with new text
- SetValue: Sets the entire text value
- SetNumericValue: Converts number to string and sets value
§Returns
Returns a Vec of DomNodeIds (node + parent) that need to be marked dirty for re-layout. The caller MUST use this return value to trigger layout.
Sourcepub fn process_mouse_click_for_selection(
&mut self,
position: LogicalPosition,
time_ms: u64,
) -> Option<Vec<DomNodeId>>
pub fn process_mouse_click_for_selection( &mut self, position: LogicalPosition, time_ms: u64, ) -> Option<Vec<DomNodeId>>
Process mouse click for text selection.
This method handles:
- Single click: Place cursor at click position
- Double click: Select word at click position
- Triple click: Select paragraph (line) at click position
§Workflow
- Use HoverManager’s hit test to find hit nodes
- Find the IFC layout via
inline_layout_result(IFC root) orifc_membership(text node) - Use point_relative_to_item for local cursor position
- Hit-test the text layout to get logical cursor
- Apply appropriate selection based on click count
- Update SelectionManager with new selection
§IFC Architecture
Text nodes don’t store inline_layout_result directly. Instead:
- IFC root nodes (e.g.,
<p>) haveinline_layout_resultwith the complete text layout - Text nodes have
ifc_membershippointing back to their IFC root - This allows efficient lookup without iterating all nodes
§Parameters
position- Click position in logical coordinates (for click count tracking)time_ms- Current time in milliseconds (for multi-click detection)
§Returns
Option<Vec<DomNodeId>>- Affected nodes that need re-rendering, None if click didn’t hit text
Sourcepub fn process_mouse_drag_for_selection(
&mut self,
_start_position: LogicalPosition,
current_position: LogicalPosition,
) -> Option<Vec<DomNodeId>>
pub fn process_mouse_drag_for_selection( &mut self, _start_position: LogicalPosition, current_position: LogicalPosition, ) -> Option<Vec<DomNodeId>>
Process mouse drag for text selection extension.
This method handles drag-to-select by extending the selection from the anchor (mousedown position) to the current focus (drag position).
Uses the anchor/focus model:
- Anchor is fixed at the initial click position (set by process_mouse_click_for_selection)
- Focus moves with the mouse during drag
- Affected nodes between anchor and focus are computed in DOM order
§Parameters
start_position- Initial click position in logical coordinates (unused, anchor is stored)current_position- Current mouse position in logical coordinates
§Returns
Option<Vec<DomNodeId>>- Affected nodes that need re-rendering
Sourcepub fn delete_selection(
&mut self,
target: DomNodeId,
forward: bool,
) -> Option<Vec<DomNodeId>>
pub fn delete_selection( &mut self, target: DomNodeId, forward: bool, ) -> Option<Vec<DomNodeId>>
Delete the currently selected text
Handles Backspace/Delete key when a selection exists. The selection is deleted and replaced with a single cursor at the deletion point.
§Arguments
target- The target node (focused contenteditable element)forward- true for Delete key (forward), false for Backspace (backward)
§Returns
Some(Vec<DomNodeId>)- Affected nodes if selection was deletedNone- If no selection exists or deletion failed
Sourcepub fn get_selected_content_for_clipboard(
&self,
dom_id: &DomId,
) -> Option<ClipboardContent>
pub fn get_selected_content_for_clipboard( &self, dom_id: &DomId, ) -> Option<ClipboardContent>
Extract clipboard content from the current selection
This method extracts both plain text and styled text from the selection ranges. It iterates through all selected text, extracts the actual characters, and preserves styling information from the ShapedGlyph’s StyleProperties.
This is NOT reading from the system clipboard - use clipboard_manager.get_paste_content()
for that. This extracts content FROM the selection TO be copied.
§Arguments
dom_id- The DOM to extract selection from
§Returns
Some(ClipboardContent)- If there is a selection with textNone- If no selection or no text layouts found
Sourcepub fn process_image_callback_updates(
&mut self,
image_callbacks_changed: &BTreeMap<DomId, FastBTreeSet<NodeId>>,
gl_context: &OptionGlContextPtr,
) -> Vec<(DomId, NodeId, Texture)>
pub fn process_image_callback_updates( &mut self, image_callbacks_changed: &BTreeMap<DomId, FastBTreeSet<NodeId>>, gl_context: &OptionGlContextPtr, ) -> Vec<(DomId, NodeId, Texture)>
Process image callback updates from CallbackChangeResult
This function re-invokes image callbacks for nodes that requested updates (typically from timer callbacks or resize events). It returns the updated textures along with their metadata for the rendering pipeline to process.
§Arguments
image_callbacks_changed- Map of DomId -> Set of NodeIds that need re-renderinggl_context- OpenGL context pointer for rendering
§Returns
Vector of (DomId, NodeId, Texture) tuples for textures that were updated
Sourcepub fn process_iframe_updates(
&mut self,
iframes_to_update: &BTreeMap<DomId, FastBTreeSet<NodeId>>,
window_state: &FullWindowState,
renderer_resources: &RendererResources,
system_callbacks: &ExternalSystemCallbacks,
) -> Vec<(DomId, NodeId)>
pub fn process_iframe_updates( &mut self, iframes_to_update: &BTreeMap<DomId, FastBTreeSet<NodeId>>, window_state: &FullWindowState, renderer_resources: &RendererResources, system_callbacks: &ExternalSystemCallbacks, ) -> Vec<(DomId, NodeId)>
Process IFrame updates requested by callbacks
This method handles manual IFrame re-rendering triggered by trigger_iframe_rerender().
It invokes the IFrame callback with DomRecreated reason and performs layout on the
returned DOM, then submits a new display list to WebRender for that pipeline.
§Arguments
iframes_to_update- Map of DomId -> Set of NodeIds that need re-renderingwindow_state- Current window staterenderer_resources- Renderer resourcessystem_callbacks- External system callbacks
§Returns
Vector of (DomId, NodeId) tuples for IFrames that were successfully updated
Sourcepub fn queue_iframe_updates(
&mut self,
iframes_to_update: BTreeMap<DomId, FastBTreeSet<NodeId>>,
)
pub fn queue_iframe_updates( &mut self, iframes_to_update: BTreeMap<DomId, FastBTreeSet<NodeId>>, )
Queue IFrame updates to be processed in the next frame
This is called after callbacks to store the iframes_to_update from CallbackChangeResult
Sourcepub fn process_pending_iframe_updates(
&mut self,
window_state: &FullWindowState,
renderer_resources: &RendererResources,
system_callbacks: &ExternalSystemCallbacks,
) -> Vec<(DomId, NodeId)>
pub fn process_pending_iframe_updates( &mut self, window_state: &FullWindowState, renderer_resources: &RendererResources, system_callbacks: &ExternalSystemCallbacks, ) -> Vec<(DomId, NodeId)>
Process and clear pending IFrame updates
This is called during frame generation to re-render updated IFrames
Auto Trait Implementations§
impl !Freeze for LayoutWindow
impl !RefUnwindSafe for LayoutWindow
impl Send for LayoutWindow
impl Sync for LayoutWindow
impl Unpin for LayoutWindow
impl !UnwindSafe for LayoutWindow
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> 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