mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
script: Start rework to better match the specification HTML event loop (#31505)
* Fix the HTML event-loop: add a update the rendering task add rendering task source sketch structure to update the rendering resize steps composition events fix warnings in rendering task source refactor handling of composition events: put window and doc for pipeline on top set script as user interacting in update the rendering task fmt add todos for other steps, put all compositor handling logic in one place update the rendering: evaluate media queries and report changes update the rendering: update animations and send events update the rendering: run animation frames update the rendering: order docs put rendering related info on documents map tidy update the rendering: add issue numbers to todos update the rendering: reflow as last step update the rendering: add todo for top layer removals note rendering opportunity when ticking animations for testing fix double borrow crash in css/basic-transition fix faster reversing of transitions test undo ordering of docs bypass not fully-active pipeline task throttling for rendering tasks ensure tasks are dequed from task queue prioritize update the rendering task remove servo media stuff from set activity tidy debug update the rendering: perform microtask checkpoint after task tidy-up only run evaluate media queries if resized re-add evaluation of media queries for each rendering task, re-prioritize rendering tasks, re-add microtask checkpoint for all sequential messages re-structure resize steps, and their interaction with evaluating media queries and reacting to environment changes update the rendering: remove reflow call at the end update webmessaging expectations update to FAIL /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html update to FAIL load-pageshow-events-window-open.html add issue number for ordering of docs nits move batching of mouse move event to document info nits add doc for mouse move event index reset mouse move event index when taking pending compositor events fix replacing mouse move event nits * move update the rendering related data to document * move re-taking of tasks to try_recv * address nits * change task queue try_recv into take_tasks_and_recv, with nits * refactor process_pending_compositor_events * when updating the rendering, return early if script cannot continue running * use an instant for the last render opportunity time * nits * remove handle_tick_all_animations * use a vec for pending resize and compositor events * fix spec links * Fix a few other nits before landing --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
77c50ad356
commit
1d66ea2b27
11 changed files with 528 additions and 283 deletions
|
@ -46,8 +46,9 @@ use profile_traits::ipc as profile_ipc;
|
|||
use profile_traits::time::{TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType};
|
||||
use script_layout_interface::{PendingRestyle, ReflowGoal, TrustedNodeAddress};
|
||||
use script_traits::{
|
||||
AnimationState, DocumentActivity, MouseButton, MouseEventType, MsDuration, ScriptMsg,
|
||||
TouchEventType, TouchId, UntrustedNodeAddress, WheelDelta,
|
||||
AnimationState, AnimationTickType, CompositorEvent, DocumentActivity, MouseButton,
|
||||
MouseEventType, MsDuration, ScriptMsg, TouchEventType, TouchId, UntrustedNodeAddress,
|
||||
WheelDelta,
|
||||
};
|
||||
use servo_arc::Arc;
|
||||
use servo_atoms::Atom;
|
||||
|
@ -446,6 +447,16 @@ pub struct Document {
|
|||
dirty_root: MutNullableDom<Element>,
|
||||
/// <https://html.spec.whatwg.org/multipage/#will-declaratively-refresh>
|
||||
declarative_refresh: DomRefCell<Option<DeclarativeRefresh>>,
|
||||
/// Pending composition events, to be handled at the next rendering opportunity.
|
||||
#[no_trace]
|
||||
#[ignore_malloc_size_of = "CompositorEvent contains data from outside crates"]
|
||||
pending_compositor_events: DomRefCell<Vec<CompositorEvent>>,
|
||||
/// The index of the last mouse move event in the pending compositor events queue.
|
||||
mouse_move_event_index: DomRefCell<Option<usize>>,
|
||||
/// Pending animation ticks, to be handled at the next rendering opportunity.
|
||||
#[no_trace]
|
||||
#[ignore_malloc_size_of = "AnimationTickType contains data from an outside crate"]
|
||||
pending_animation_ticks: DomRefCell<AnimationTickType>,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
|
@ -1217,7 +1228,7 @@ impl Document {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub unsafe fn handle_mouse_event(
|
||||
pub unsafe fn handle_mouse_button_event(
|
||||
&self,
|
||||
button: MouseButton,
|
||||
client_point: Point2D<f32>,
|
||||
|
@ -3211,9 +3222,56 @@ impl Document {
|
|||
animations: DomRefCell::new(Animations::new()),
|
||||
dirty_root: Default::default(),
|
||||
declarative_refresh: Default::default(),
|
||||
pending_animation_ticks: Default::default(),
|
||||
pending_compositor_events: Default::default(),
|
||||
mouse_move_event_index: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Note a pending animation tick, to be processed at the next `update_the_rendering` task.
|
||||
pub fn note_pending_animation_tick(&self, tick_type: AnimationTickType) {
|
||||
self.pending_animation_ticks.borrow_mut().extend(tick_type);
|
||||
}
|
||||
|
||||
/// As part of a `update_the_rendering` task, tick all pending animations.
|
||||
pub fn tick_all_animations(&self) {
|
||||
let tick_type = mem::take(&mut *self.pending_animation_ticks.borrow_mut());
|
||||
if tick_type.contains(AnimationTickType::REQUEST_ANIMATION_FRAME) {
|
||||
self.run_the_animation_frame_callbacks();
|
||||
}
|
||||
if tick_type.contains(AnimationTickType::CSS_ANIMATIONS_AND_TRANSITIONS) {
|
||||
self.maybe_mark_animating_nodes_as_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// Note a pending compositor event, to be processed at the next `update_the_rendering` task.
|
||||
pub fn note_pending_compositor_event(&self, event: CompositorEvent) {
|
||||
let mut pending_compositor_events = self.pending_compositor_events.borrow_mut();
|
||||
if matches!(event, CompositorEvent::MouseMoveEvent { .. }) {
|
||||
// First try to replace any existing mouse move event.
|
||||
if let Some(mouse_move_event) = self
|
||||
.mouse_move_event_index
|
||||
.borrow()
|
||||
.and_then(|index| pending_compositor_events.get_mut(index))
|
||||
{
|
||||
*mouse_move_event = event;
|
||||
return;
|
||||
}
|
||||
|
||||
*self.mouse_move_event_index.borrow_mut() =
|
||||
Some(self.pending_compositor_events.borrow().len());
|
||||
}
|
||||
|
||||
self.pending_compositor_events.borrow_mut().push(event);
|
||||
}
|
||||
|
||||
/// Get pending compositor events, for processing within an `update_the_rendering` task.
|
||||
pub fn take_pending_compositor_events(&self) -> Vec<CompositorEvent> {
|
||||
// Reset the mouse event index.
|
||||
*self.mouse_move_event_index.borrow_mut() = None;
|
||||
mem::take(&mut *self.pending_compositor_events.borrow_mut())
|
||||
}
|
||||
|
||||
pub fn set_csp_list(&self, csp_list: Option<CspList>) {
|
||||
*self.csp_list.borrow_mut() = csp_list;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue