mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Unify the task source and task canceller API
I moved away from the `Window` struct all the logic to handle task sources, into a new struct called `TaskManager`. In a happy world, I'd be able to just have there two functions, of the types: ```rust fn task_source<T: TaskSource>(&self, name: TaskSourceName) -> Box<T> fn task_source_with_canceller<T: TaskSource>(&self, name: TaskSourceName) -> (Box<T>, TaskSourceCanceller) ``` And not so much duplicated code. However, because TaskSource can't be a trait object (because it has generic type parameters), that's not possible. Instead, I decided to reduce duplicated logic through macros. For reasons[1], I have to pass both the name of the function with canceller and the name of the function without, as I'm not able to concatenate them in the macro itself. I could probably use `concat_idents` to create both types already defined and reduce the amount of arguments by one, but that macro is nightly only. At the same time, not being able to declare macros inside `impl` forces me to pass `self` as an argument. All this makes this solution more verbose than it would be ideally. It does reduce duplication, but it doesn't reduce the size of the file. [1](https://github.com/rust-lang/rust/issues/29599)
This commit is contained in:
parent
14bc8ab754
commit
75eb94afca
26 changed files with 362 additions and 252 deletions
|
@ -521,6 +521,7 @@ impl Document {
|
|||
if self.ready_state.get() == DocumentReadyState::Complete {
|
||||
let document = Trusted::new(self);
|
||||
self.window
|
||||
.task_manager()
|
||||
.dom_manipulation_task_source()
|
||||
.queue(
|
||||
task!(fire_pageshow_event: move || {
|
||||
|
@ -1869,6 +1870,7 @@ impl Document {
|
|||
debug!("Document loads are complete.");
|
||||
let document = Trusted::new(self);
|
||||
self.window
|
||||
.task_manager()
|
||||
.dom_manipulation_task_source()
|
||||
.queue(
|
||||
task!(fire_load_event: move || {
|
||||
|
@ -1922,6 +1924,7 @@ impl Document {
|
|||
let document = Trusted::new(self);
|
||||
if document.root().browsing_context().is_some() {
|
||||
self.window
|
||||
.task_manager()
|
||||
.dom_manipulation_task_source()
|
||||
.queue(
|
||||
task!(fire_pageshow_event: move || {
|
||||
|
@ -2104,13 +2107,16 @@ impl Document {
|
|||
|
||||
// Step 4.1.
|
||||
let window = self.window();
|
||||
window.dom_manipulation_task_source().queue_event(
|
||||
self.upcast(),
|
||||
atom!("DOMContentLoaded"),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable,
|
||||
window,
|
||||
);
|
||||
window
|
||||
.task_manager()
|
||||
.dom_manipulation_task_source()
|
||||
.queue_event(
|
||||
self.upcast(),
|
||||
atom!("DOMContentLoaded"),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable,
|
||||
window,
|
||||
);
|
||||
|
||||
window.reflow(ReflowGoal::Full, ReflowReason::DOMContentLoaded);
|
||||
update_with_current_time_ms(&self.dom_content_loaded_event_end);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue