Skip to main content

Module scroll_state

Module scroll_state 

Source
Expand description

Pure scroll state management — the single source of truth for scroll offsets.

§Architecture

ScrollManager is the exclusive owner of all scroll state. Other modules interact with scrolling only through its public API:

  • Platform shell (macos/events.rs, etc.): Calls record_scroll_from_hit_test() to queue trackpad/mouse wheel input for the physics timer.
  • Scroll physics timer (scroll_timer.rs): Consumes inputs via ScrollInputQueue, applies physics, and pushes CallbackChange::ScrollTo for each updated node.
  • Event processing (event_v2.rs): Processes ScrollTo changes, sets scroll positions, and checks VirtualView re-invocation transparently.
  • Gesture manager (gesture.rs): Tracks drag state and emits AutoScrollDirection — does NOT modify scroll offsets directly.
  • Render loop: Calls tick() every frame to advance easing animations.
  • WebRender sync (wr_translate2.rs): Reads offsets via get_scroll_states_for_dom() to synchronize scroll frames.
  • Layout (cache.rs): Registers scroll nodes via register_or_update_scroll_node() after layout completes.

§Scroll Flow

Platform Event Handler
  → record_scroll_from_hit_test() → ScrollInputQueue
  → starts SCROLL_MOMENTUM_TIMER_ID if not running

Timer fires (every ~16ms):
  → queue.take_all() → physics integration
  → push_change(CallbackChange::ScrollTo)

ScrollTo processing (event_v2.rs):
  → scroll_manager.set_scroll_position()
  → virtual_view_manager.check_reinvoke() (transparent VirtualView support)
  → repaint

This module provides:

  • Smooth scroll animations with easing
  • Event source classification for scroll events
  • Scrollbar geometry and hit-testing
  • Virtual scroll bounds for VirtualView nodes

Structs§

AnimatedScrollState
The complete scroll state for a single node (with animation support)
ScrollAnimation
Details of an in-progress smooth scroll animation.
ScrollInput
A single scroll input event to be processed by the physics timer.
ScrollInputQueue
Thread-safe queue for scroll inputs, shared between event handlers and timer callbacks.
ScrollManager
Manages all scroll state and animations for a window
ScrollNodeInfo
Read-only snapshot of a scroll node’s state, returned by CallbackInfo queries.
ScrollTickResult
Result of a scroll tick, indicating what actions are needed
ScrollbarHit
Result of a scrollbar hit-test
ScrollbarState
Scrollbar geometry state (calculated per frame, used for hit-testing and rendering)

Enums§

ScrollInputSource
Classifies the source of a scroll input event.
ScrollbarComponent
Which component of a scrollbar was hit during hit-testing