Skip to main content

ScrollManager

Struct ScrollManager 

Source
pub struct ScrollManager {
    pub scroll_input_queue: ScrollInputQueue,
    /* private fields */
}
Expand description

Manages all scroll state and animations for a window

Fields§

§scroll_input_queue: ScrollInputQueue

Thread-safe queue for scroll inputs (shared with timer callbacks)

Implementations§

Source§

impl ScrollManager

Source

pub fn new() -> Self

Creates a new empty ScrollManager

Source

pub fn record_scroll_input(&mut self, input: ScrollInput) -> bool

Records a scroll input event into the shared queue.

This is the primary entry point for platform event handlers. Instead of directly modifying scroll positions, the input is queued for the scroll physics timer to process. This decouples input from physics simulation.

Returns true if the physics timer should be started (i.e., there are now pending inputs and no timer is running yet).

Source

pub fn record_scroll_from_hit_test( &mut self, delta_x: f32, delta_y: f32, source: ScrollInputSource, hover_manager: &HoverManager, input_point_id: &InputPointId, now: Instant, ) -> Option<(DomId, NodeId, bool)>

High-level entry point for platform event handlers: performs hit-test lookup and queues the input for the physics timer, instead of directly modifying offsets.

Returns Some((dom_id, node_id, should_start_timer)) if a scrollable node was found. The caller should start SCROLL_MOMENTUM_TIMER_ID when should_start_timer is true.

Source

pub fn get_input_queue(&self) -> ScrollInputQueue

Get a clone of the scroll input queue (for sharing with timer callbacks).

The timer callback stores this in its RefAny data and calls take_all() each tick to consume pending inputs.

Source

pub fn tick(&mut self, now: Instant) -> ScrollTickResult

Advances scroll animations by one tick, returns repaint info

Source

pub fn find_scroll_parent( &self, dom_id: DomId, node_id: NodeId, node_hierarchy: &[NodeHierarchyItem], ) -> Option<NodeId>

Finds the closest scroll-container ancestor for a given node.

Walks up the node hierarchy to find a node that is registered as a scrollable node in this ScrollManager. Returns None if no scrollable ancestor is found.

Source

pub fn set_scroll_position( &mut self, dom_id: DomId, node_id: NodeId, position: LogicalPosition, now: Instant, )

Sets scroll position immediately (no animation)

Source

pub fn scroll_by( &mut self, dom_id: DomId, node_id: NodeId, delta: LogicalPosition, duration: Duration, easing: EasingFunction, now: Instant, )

Scrolls by a delta amount with animation

Source

pub fn scroll_to( &mut self, dom_id: DomId, node_id: NodeId, target: LogicalPosition, duration: Duration, easing: EasingFunction, now: Instant, )

Scrolls to an absolute position with animation

If duration is zero, the position is set immediately without animation.

Source

pub fn update_node_bounds( &mut self, dom_id: DomId, node_id: NodeId, container_rect: LogicalRect, content_rect: LogicalRect, now: Instant, )

Updates the container and content bounds for a scrollable node

Source

pub fn update_virtual_scroll_bounds( &mut self, dom_id: DomId, node_id: NodeId, virtual_scroll_size: LogicalSize, virtual_scroll_offset: Option<LogicalPosition>, )

Updates virtual scroll bounds for an IFrame node.

Called after IFrame callback returns to propagate the virtual content size to the ScrollManager. Clamp logic then uses virtual_scroll_size (when set) instead of content_rect for max scroll bounds.

Source

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

Returns the current scroll offset for a node

Source

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

Returns the timestamp of last scroll activity for a node

Source

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

Returns the internal scroll state for a node

Source

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

Returns a read-only snapshot of a scroll node’s state.

This is the preferred way for timer callbacks to query scroll state, since they only have &CallbackInfo (read-only access).

When virtual_scroll_size is set (for IFrame nodes), the max scroll bounds are computed from the virtual size instead of content_rect.

Source

pub fn get_scroll_states_for_dom( &self, dom_id: DomId, ) -> BTreeMap<NodeId, ScrollPosition>

Returns all scroll positions for nodes in a specific DOM

Source

pub fn register_or_update_scroll_node( &mut self, dom_id: DomId, node_id: NodeId, container_rect: LogicalRect, content_size: LogicalSize, now: Instant, )

Registers or updates a scrollable node with its container and content sizes. This should be called after layout for each node that has overflow:scroll or overflow:auto with overflowing content.

If the node already exists, updates container/content rects without changing scroll offset. If the node is new, initializes with zero scroll offset.

Source

pub fn register_scroll_node( &mut self, dom_id: DomId, node_id: NodeId, ) -> ExternalScrollId

Register a scroll node and get its ExternalScrollId for WebRender. If the node already has an ID, returns the existing one.

Source

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

Get the ExternalScrollId for a node (returns None if not registered)

Source

pub fn iter_external_scroll_ids( &self, ) -> impl Iterator<Item = ((DomId, NodeId), ExternalScrollId)> + '_

Iterate over all registered external scroll IDs

Source

pub fn calculate_scrollbar_states(&mut self)

Calculate scrollbar states for all visible scrollbars. This should be called once per frame after layout is complete.

Source

pub fn get_scrollbar_state( &self, dom_id: DomId, node_id: NodeId, orientation: ScrollbarOrientation, ) -> Option<&ScrollbarState>

Get scrollbar state for hit-testing

Source

pub fn iter_scrollbar_states( &self, ) -> impl Iterator<Item = ((DomId, NodeId, ScrollbarOrientation), &ScrollbarState)> + '_

Iterate over all visible scrollbar states

Source

pub fn hit_test_scrollbar( &self, dom_id: DomId, node_id: NodeId, global_pos: LogicalPosition, ) -> Option<ScrollbarHit>

Hit-test scrollbars for a specific node at the given position. Returns Some if the position is inside a scrollbar for this node.

Source

pub fn hit_test_scrollbars( &self, global_pos: LogicalPosition, ) -> Option<ScrollbarHit>

Perform hit-testing for all scrollbars at the given global position.

This iterates through all visible scrollbars in reverse z-order (top to bottom) and returns the first hit. Use this when you don’t know which node to check.

For better performance, use hit_test_scrollbar() when you already have a hit-tested node from WebRender.

Source§

impl ScrollManager

Source

pub fn remap_node_ids( &mut self, dom_id: DomId, node_id_map: &BTreeMap<NodeId, NodeId>, )

Remap NodeIds after DOM reconciliation

When the DOM is regenerated, NodeIds can change. This method updates all internal state to use the new NodeIds based on the provided mapping.

Trait Implementations§

Source§

impl Clone for ScrollManager

Source§

fn clone(&self) -> ScrollManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScrollManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ScrollManager

Source§

fn default() -> ScrollManager

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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