Skip to main content

LayoutWindow

Struct LayoutWindow 

Source
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: LayoutCache

Layout cache for solver3 (incremental layout tree) - for the root DOM

§text_cache: LayoutCache

Text layout cache for text3 (shaped glyphs, line breaks, etc.)

§font_manager: FontManager<FontRef>

Font manager for loading and caching fonts

§image_cache: ImageCache

Cache to store decoded images

§layout_results: BTreeMap<DomId, DomLayoutResult>

Cached layout results for all DOMs (root + iframes)

§scroll_manager: ScrollManager

Scroll state manager for all nodes across all DOMs

§gesture_drag_manager: GestureAndDragManager

Gesture and drag manager for multi-frame interactions (moved from FullWindowState)

§focus_manager: FocusManager

Focus manager for keyboard focus and tab navigation

§cursor_manager: CursorManager

Cursor manager for text cursor position and rendering

§file_drop_manager: FileDropManager

File drop manager for cursor state and file drag-drop

§selection_manager: SelectionManager

Selection manager for text selections across all DOMs

§clipboard_manager: ClipboardManager

Clipboard manager for system clipboard integration

§drag_drop_manager: DragDropManager

Drag-drop manager for node and file dragging operations

§hover_manager: HoverManager

Hover manager for tracking hit test history over multiple frames

§iframe_manager: IFrameManager

IFrame manager for all nodes across all DOMs

§gpu_state_manager: GpuStateManager

GPU state manager for all nodes across all DOMs

§a11y_manager: A11yManager

Accessibility 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: RendererResources

Currently 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: FullWindowState

Window state of this current window (current frame): initialized to the state of WindowCreateOptions

§document_id: DocumentId

A “document” in WebRender usually corresponds to one tab (i.e. in Azuls case, the whole window).

§id_namespace: IdNamespace

ID namespace under which every font / image for this window is registered

§epoch: Epoch

The “epoch” is a frame counter, to remove outdated images, fonts and OpenGL textures when they’re not in use anymore.

§gl_texture_cache: GlTextureCache

Currently GL textures inside the active CachedDisplayList

§text_input_manager: TextInputManager

Text input manager - centralizes all text editing logic

§undo_redo_manager: UndoRedoManager

Undo/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

Source

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().

Source

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 layout
  • window_state: Current window dimensions and state
  • renderer_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.

Source

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.

Source

pub fn clear_caches(&mut self)

Clear all caches (useful for testing or when switching documents).

Source

pub fn set_scroll_position( &mut self, dom_id: DomId, node_id: NodeId, scroll: ScrollPosition, )

Set scroll position for a node

Source

pub fn get_scroll_position( &self, dom_id: DomId, node_id: NodeId, ) -> Option<ScrollPosition>

Get scroll position for a node

Source

pub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)

Set selection state for a DOM

Source

pub fn get_selection(&self, dom_id: DomId) -> Option<&SelectionState>

Get selection state for a DOM

Source

pub fn get_node_size(&self, node_id: DomNodeId) -> Option<LogicalSize>

Get the size of a laid-out node

Source

pub fn get_node_position(&self, node_id: DomNodeId) -> Option<LogicalPosition>

Get the position of a laid-out node

Source

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.

Source

pub fn get_parent(&self, node_id: DomNodeId) -> Option<DomNodeId>

Get the parent of a node

Source

pub fn get_first_child(&self, node_id: DomNodeId) -> Option<DomNodeId>

Get the first child of a node

Source

pub fn get_next_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>

Get the next sibling of a node

Source

pub fn get_previous_sibling(&self, node_id: DomNodeId) -> Option<DomNodeId>

Get the previous sibling of a node

Source

pub fn get_last_child(&self, node_id: DomNodeId) -> Option<DomNodeId>

Get the last child of a node

Source

pub fn scan_used_fonts(&self) -> BTreeSet<FontKey>

Scan all fonts used in this LayoutWindow (for resource GC)

Source

pub fn scan_used_images( &self, _css_image_cache: &ImageCache, ) -> BTreeSet<ImageRefHash>

Scan all images used in this LayoutWindow (for resource GC)

Source

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 view
  • options - Scroll alignment and animation options
  • now - Current timestamp for animations
§Returns

A vector of scroll adjustments that were applied

Source

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.

Source

pub fn add_timer(&mut self, timer_id: TimerId, timer: Timer)

Add a timer to this window

Source

pub fn remove_timer(&mut self, timer_id: &TimerId) -> Option<Timer>

Remove a timer from this window

Source

pub fn get_timer(&self, timer_id: &TimerId) -> Option<&Timer>

Get a reference to a timer

Source

pub fn get_timer_mut(&mut self, timer_id: &TimerId) -> Option<&mut Timer>

Get a mutable reference to a timer

Source

pub fn get_timer_ids(&self) -> TimerIdVec

Get all timer IDs

Source

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

Source

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.

Source

pub fn add_thread(&mut self, thread_id: ThreadId, thread: Thread)

Add a thread to this window

Source

pub fn remove_thread(&mut self, thread_id: &ThreadId) -> Option<Thread>

Remove a thread from this window

Source

pub fn get_thread(&self, thread_id: &ThreadId) -> Option<&Thread>

Get a reference to a thread

Source

pub fn get_thread_mut(&mut self, thread_id: &ThreadId) -> Option<&mut Thread>

Get a mutable reference to a thread

Source

pub fn get_thread_ids(&self) -> ThreadIdVec

Get all thread IDs

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.

Source

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.

Handle focus change for cursor blink timer management (W3C “flag and defer” pattern)

This method implements the W3C focus/selection model:

  1. Focus change is handled immediately (timer start/stop)
  2. 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.

Source

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:

  1. Focus event fires during event handling (layout may not be ready)
  2. Selection/cursor placement happens after layout is computed
  3. The cursor is drawn at the position specified by the Selection

This function implements step 2+3 by:

  • Checking the cursor_needs_initialization flag
  • 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.

Source

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.

Source

pub fn get_gpu_cache(&self, dom_id: &DomId) -> Option<&GpuValueCache>

Get the GPU value cache for a specific DOM

Source

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

Source

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

Source

pub fn get_layout_result(&self, dom_id: &DomId) -> Option<&DomLayoutResult>

Get a layout result for a specific DOM

Source

pub fn get_layout_result_mut( &mut self, dom_id: &DomId, ) -> Option<&mut DomLayoutResult>

Get a mutable layout result for a specific DOM

Source

pub fn get_dom_ids(&self) -> DomIdVec

Get all DOM IDs that have layout results

Source

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.

Source

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.

Source

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)
Source

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)

Source

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().

Source

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:

  1. Scroll offsets from all scrollable ancestors
  2. 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().

Source

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

Source

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
  1. Get bounds to scroll (cursor rect, selection rect, or mouse position)
  2. Find scrollable ancestor container
  3. Calculate distance from bounds to container edges
  4. Compute scroll delta (instant with padding, or accelerated with zones)
  5. 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

Source

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

Source

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

Source

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.)

Source

pub fn invoke_menu_callback( &mut self, menu_callback: &mut MenuCallback, hit_dom_node: DomNodeId, 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 menu callback

Source§

impl LayoutWindow

Source

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 node
  • current_node - The current node ID to start searching from
§Returns
  • Some((DomId, NodeId)) - The next text node if found
  • None - If no next text node exists
Source

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 node
  • current_node - The current node ID to start searching from
§Returns
  • Some((DomId, NodeId)) - The previous text node if found
  • None - If no previous text node exists
Source

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 node
  • node_id - The target node for the action
  • action - The accessibility action to perform
  • now - 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

Source

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
  1. Check if focus manager has a focused contenteditable node
  2. Get cursor/selection from managers
  3. Call edit_text_node to apply the edit and update cache
  4. Collect affected nodes that need dirty marking
  5. 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
Source

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.

Source

pub fn process_text_input( &mut self, text_input: &str, ) -> BTreeMap<DomNodeId, (Vec<EventFilter>, bool)>

Legacy name for backward compatibility

Source

pub fn get_last_text_changeset(&self) -> Option<&PendingTextEdit>

Get the last text changeset (what was changed in the last text input)

Source

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.

Source

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.

Source

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:

  1. Stores the new content in dirty_text_nodes for tracking
  2. Re-runs the text3 layout pipeline (create_logical_items -> reorder -> shape -> fragment)
  3. Updates the inline_layout_result on the IFC root node in the layout tree
Source

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.

Source

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.

Source

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
  1. Use HoverManager’s hit test to find hit nodes
  2. Find the IFC layout via inline_layout_result (IFC root) or ifc_membership (text node)
  3. Use point_relative_to_item for local cursor position
  4. Hit-test the text layout to get logical cursor
  5. Apply appropriate selection based on click count
  6. Update SelectionManager with new selection
§IFC Architecture

Text nodes don’t store inline_layout_result directly. Instead:

  • IFC root nodes (e.g., <p>) have inline_layout_result with the complete text layout
  • Text nodes have ifc_membership pointing 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
Source

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
Source

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 deleted
  • None - If no selection exists or deletion failed
Source

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 text
  • None - If no selection or no text layouts found
Source

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-rendering
  • gl_context - OpenGL context pointer for rendering
§Returns

Vector of (DomId, NodeId, Texture) tuples for textures that were updated

Source

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-rendering
  • window_state - Current window state
  • renderer_resources - Renderer resources
  • system_callbacks - External system callbacks
§Returns

Vector of (DomId, NodeId) tuples for IFrames that were successfully updated

Source

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

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool