Skip to main content

ScrollManager

Struct ScrollManager 

Source
pub struct ScrollManager {
    pub scroll_input_queue: ScrollInputQueue,
    pub pending_wheel_event: Option<LogicalPosition>,
    /* 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)

§pending_wheel_event: Option<LogicalPosition>

Raw wheel/trackpad delta recorded this input pass, regardless of whether a scrollable node was under the cursor. The scroll input queue only carries deltas destined for scrollable containers (consumed by the physics timer); this field additionally lets determine_all_events synthesize a Scroll event aimed at the hovered node so non-scroll-container widgets (e.g. the map, which treats wheel = zoom) can react via a HoverEventFilter::Scroll callback + CallbackInfo::get_scroll_delta. Set in Self::record_scroll_from_hit_test; read during event determination and callback dispatch, then cleared at the end of the pass.

Implementations§

Source§

impl ScrollManager

Source

pub fn new() -> Self

Creates a new empty ScrollManager

Source

pub const fn set_natural_scroll(&mut self, natural: bool)

Set the scroll-direction preference. true = natural (content follows the gesture / inverted from the traditional wheel). Platform shells call this from the detected OS preference. See the natural_scroll field docs for the macOS/libinput pre-application caveat.

Source

pub const fn is_natural_scroll(&self) -> bool

Current scroll-direction preference (true = natural/inverted).

Source

pub fn debug_counts(&self) -> (usize, usize)

Sizes of the internal maps — used by AZ_E2E_TEST to watch for unbounded growth across resize/tick iterations.

Source

pub const fn clear_scroll_dirty(&mut self)

Clear the dirty flag after the display list has been regenerated.

Source

pub fn build_scroll_offset_map( &self, dom_id: DomId, scroll_ids: &HashMap<usize, u64>, ) -> HashMap<u64, (f32, f32)>

Build a map from scroll_id (LocalScrollId) to current scroll offset.

Used by the CPU renderer to look up scroll positions at render time without embedding them in the display list.

scroll_ids maps layout-tree node index → scroll_id. We need to convert our (DomId, NodeId) keys to scroll_ids.

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.

The scroll-direction sign (Self::scroll_sign) is applied HERE — the single chokepoint every wheel/axis event flows through — so platform shells pass the RAW delta and no longer hardcode -delta at each call site.

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 a11y_scroll_info( &self, dom_id: DomId, node_id: NodeId, ) -> Option<(LogicalPosition, f32, f32)>

MWA-B10: the a11y tree’s scroll surface for a node — current offset plus max travel per axis, or None when the node isn’t scrollable. Screen readers use this (with the ScrollUp/Down/… actions) to drive the same inbound handler mouse users exercise.

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 has_active_animations(&self) -> bool

Returns true if any scroll node has an active easing animation.

Used by GPU render paths to skip rendering when the UI is completely static (no scroll animations, no layout changes).

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), clamped to valid bounds.

Source

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

Sets scroll position immediately without clamping.

Used by the scroll physics timer which does its own rubber-band clamping. Allows the offset to go outside [0, max_scroll] for overscroll/rubber-banding.

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 a VirtualView node.

Called after VirtualView 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.

If no scroll state exists yet for this node (because register_or_update_scroll_node hasn’t been called yet), this creates a default state so the virtual size is preserved.

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 VirtualView 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, scrollbar_thickness: f32, visual_width_px: f32, has_horizontal_scrollbar: bool, has_vertical_scrollbar: bool, )

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 calculate_scrollbar_states(&mut self)

Calculate scrollbar states for all visible scrollbars. This should be called once per frame after layout is complete. Uses the shared compute_scrollbar_geometry() for consistent geometry.

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

Trait Implementations§

Source§

impl Clone for ScrollManager

Source§

fn clone(&self) -> ScrollManager

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl NodeIdRemap for ScrollManager

Source§

fn remap_node_ids(&mut self, dom: DomId, map: &NodeIdMap)

Rewrite every (DomId, NodeId) key for dom and DROP the scroll state of nodes that were unmounted.

The previous implementation only rewrote keys whose id actually changed and kept everything else “conservatively” — which silently re-attached the scroll offset of a deleted node to whatever node inherited its index. node_moves contains an entry for every matched node, so “absent from the map” unambiguously means “unmounted”.

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.