Skip to content

Commit 0049ced

Browse files
author
bors-servo
authored
Auto merge of #12404 - ConnorGBrewster:task_source_cleanup, r=nox
Clean up task sources and make all tasks cancellable <!-- Please describe your changes on the following line: --> This makes it so each task is a thin wrapper over a runnable and whenever a task is queued, it is automatically wrapped by the window's `runnable_wrapper`. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12404) <!-- Reviewable:end -->
2 parents f0c3543 + 6b0ce8e commit 0049ced

15 files changed

+125
-102
lines changed

components/script/dom/document.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,12 @@ impl Document {
14881488

14891489
update_with_current_time_ms(&self.dom_content_loaded_event_start);
14901490

1491-
self.window().dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"),
1492-
EventBubbles::Bubbles, EventCancelable::NotCancelable);
1493-
self.window().reflow(ReflowGoal::ForDisplay,
1494-
ReflowQueryType::NoQuery,
1495-
ReflowReason::DOMContentLoaded);
1491+
let window = self.window();
1492+
window.dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"),
1493+
EventBubbles::Bubbles, EventCancelable::NotCancelable, window);
1494+
window.reflow(ReflowGoal::ForDisplay,
1495+
ReflowQueryType::NoQuery,
1496+
ReflowReason::DOMContentLoaded);
14961497

14971498
update_with_current_time_ms(&self.dom_content_loaded_event_end);
14981499
}

components/script/dom/event.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethod
88
use dom::bindings::error::Fallible;
99
use dom::bindings::global::GlobalRef;
1010
use dom::bindings::js::{JS, MutNullableHeap, Root};
11+
use dom::bindings::refcounted::Trusted;
1112
use dom::bindings::reflector::{Reflector, reflect_dom_object};
1213
use dom::bindings::str::DOMString;
1314
use dom::eventtarget::EventTarget;
15+
use script_thread::Runnable;
1416
use std::cell::Cell;
1517
use std::default::Default;
1618
use string_cache::Atom;
@@ -26,7 +28,7 @@ pub enum EventPhase {
2628
Bubbling = EventConstants::BUBBLING_PHASE,
2729
}
2830

29-
#[derive(PartialEq, HeapSizeOf)]
31+
#[derive(PartialEq, HeapSizeOf, Copy, Clone)]
3032
pub enum EventBubbles {
3133
Bubbles,
3234
DoesNotBubble
@@ -50,7 +52,7 @@ impl From<bool> for EventBubbles {
5052
}
5153
}
5254

53-
#[derive(PartialEq, HeapSizeOf)]
55+
#[derive(PartialEq, HeapSizeOf, Copy, Clone)]
5456
pub enum EventCancelable {
5557
Cancelable,
5658
NotCancelable
@@ -297,3 +299,35 @@ impl Event {
297299
target.dispatch_event(self)
298300
}
299301
}
302+
303+
// https://dom.spec.whatwg.org/#concept-event-fire
304+
pub struct EventRunnable {
305+
pub target: Trusted<EventTarget>,
306+
pub name: Atom,
307+
pub bubbles: EventBubbles,
308+
pub cancelable: EventCancelable,
309+
}
310+
311+
impl Runnable for EventRunnable {
312+
fn name(&self) -> &'static str { "EventRunnable" }
313+
314+
fn handler(self: Box<EventRunnable>) {
315+
let target = self.target.root();
316+
target.fire_event(&*self.name, self.bubbles, self.cancelable);
317+
}
318+
}
319+
320+
// https://html.spec.whatwg.org/multipage/#fire-a-simple-event
321+
pub struct SimpleEventRunnable {
322+
pub target: Trusted<EventTarget>,
323+
pub name: Atom,
324+
}
325+
326+
impl Runnable for SimpleEventRunnable {
327+
fn name(&self) -> &'static str { "SimpleEventRunnable" }
328+
329+
fn handler(self: Box<SimpleEventRunnable>) {
330+
let target = self.target.root();
331+
target.fire_simple_event(&*self.name);
332+
}
333+
}

components/script/dom/htmldetailselement.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use script_thread::Runnable;
1919
use std::cell::Cell;
2020
use string_cache::Atom;
2121
use task_source::TaskSource;
22-
use task_source::dom_manipulation::DOMManipulationTask;
2322

2423
#[dom_struct]
2524
pub struct HTMLDetailsElement {
@@ -72,14 +71,13 @@ impl VirtualMethods for HTMLDetailsElement {
7271
self.toggle_counter.set(counter);
7372

7473
let window = window_from_node(self);
75-
let window = window.r();
7674
let task_source = window.dom_manipulation_task_source();
7775
let details = Trusted::new(self);
7876
let runnable = box DetailsNotificationRunnable {
7977
element: details,
8078
toggle_number: counter
8179
};
82-
let _ = task_source.queue(DOMManipulationTask::Runnable(runnable));
80+
let _ = task_source.queue(runnable, window.r());
8381
}
8482
}
8583
}

components/script/dom/htmlformelement.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use string_cache::Atom;
5353
use style::attr::AttrValue;
5454
use style::str::split_html_space_chars;
5555
use task_source::TaskSource;
56-
use task_source::dom_manipulation::DOMManipulationTask;
5756
use url::form_urlencoded;
5857

5958
#[derive(JSTraceable, PartialEq, Clone, Copy, HeapSizeOf)]
@@ -484,7 +483,7 @@ impl HTMLFormElement {
484483
};
485484

486485
// Step 3
487-
window.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(nav)).unwrap();
486+
window.dom_manipulation_task_source().queue(nav, window).unwrap();
488487
}
489488

490489
/// Interactively validate the constraints of form elements

components/script/dom/htmlimageelement.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use std::sync::Arc;
3232
use string_cache::Atom;
3333
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
3434
use task_source::TaskSource;
35-
use task_source::dom_manipulation::DOMManipulationTask;
3635
use url::Url;
3736

3837
#[derive(JSTraceable, HeapSizeOf)]
@@ -141,7 +140,7 @@ impl HTMLImageElement {
141140
// Return the image via a message to the script thread, which marks the element
142141
// as dirty and triggers a reflow.
143142
let image_response = message.to().unwrap();
144-
let runnable = ImageResponseHandlerRunnable::new(
143+
let runnable = box ImageResponseHandlerRunnable::new(
145144
trusted_node.clone(), image_response);
146145
let runnable = wrapper.wrap_runnable(runnable);
147146
let _ = script_chan.send(CommonScriptMsg::RunnableMsg(
@@ -185,7 +184,7 @@ impl HTMLImageElement {
185184
src: src.into(),
186185
});
187186
let task = window.dom_manipulation_task_source();
188-
let _ = task.queue(DOMManipulationTask::Runnable(runnable));
187+
let _ = task.queue(runnable, window);
189188
}
190189
}
191190
}

components/script/dom/htmlinputelement.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ impl HTMLInputElementMethods for HTMLInputElement {
576576
&self.upcast(),
577577
atom!("select"),
578578
EventBubbles::Bubbles,
579-
EventCancelable::NotCancelable);
579+
EventCancelable::NotCancelable,
580+
window.r());
580581
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
581582
}
582583

@@ -1061,7 +1062,8 @@ impl VirtualMethods for HTMLInputElement {
10611062
&self.upcast(),
10621063
atom!("input"),
10631064
EventBubbles::Bubbles,
1064-
EventCancelable::NotCancelable);
1065+
EventCancelable::NotCancelable,
1066+
window.r());
10651067
}
10661068

10671069
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);

components/script/dom/htmlmediaelement.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::cell::Cell;
3333
use std::sync::{Arc, Mutex};
3434
use string_cache::Atom;
3535
use task_source::TaskSource;
36-
use task_source::dom_manipulation::DOMManipulationTask;
3736
use time::{self, Timespec, Duration};
3837
use url::Url;
3938

@@ -242,7 +241,7 @@ impl HTMLMediaElement {
242241
elem: Trusted::new(self),
243242
};
244243
let win = window_from_node(self);
245-
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
244+
let _ = win.dom_manipulation_task_source().queue(box task, win.r());
246245
}
247246

248247
// https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2
@@ -266,13 +265,13 @@ impl HTMLMediaElement {
266265
elem: Trusted::new(self),
267266
};
268267
let win = window_from_node(self);
269-
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
268+
let _ = win.dom_manipulation_task_source().queue(box task, win.r());
270269
}
271270

272271
fn queue_fire_simple_event(&self, type_: &'static str) {
273272
let win = window_from_node(self);
274273
let task = FireSimpleEventTask::new(self, type_);
275-
let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task));
274+
let _ = win.dom_manipulation_task_source().queue(box task, win.r());
276275
}
277276

278277
fn fire_simple_event(&self, type_: &str) {
@@ -498,8 +497,8 @@ impl HTMLMediaElement {
498497
}
499498

500499
fn queue_dedicated_media_source_failure_steps(&self) {
501-
let _ = window_from_node(self).dom_manipulation_task_source().queue(
502-
DOMManipulationTask::Runnable(box DedicatedMediaSourceFailureTask::new(self)));
500+
let window = window_from_node(self);
501+
let _ = window.dom_manipulation_task_source().queue(box DedicatedMediaSourceFailureTask::new(self), window.r());
503502
}
504503

505504
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps

components/script/dom/htmlscriptelement.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,13 @@ impl HTMLScriptElement {
460460
if external {
461461
self.dispatch_load_event();
462462
} else {
463-
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"));
463+
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"), window.r());
464464
}
465465
}
466466

467467
pub fn queue_error_event(&self) {
468-
window_from_node(self).dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"));
468+
let window = window_from_node(self);
469+
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"), window.r());
469470
}
470471

471472
pub fn dispatch_before_script_execute_event(&self) -> bool {

components/script/dom/htmltextareaelement.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
260260
&self.upcast(),
261261
atom!("select"),
262262
EventBubbles::Bubbles,
263-
EventCancelable::NotCancelable);
263+
EventCancelable::NotCancelable,
264+
window.r());
264265
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
265266
}
266267
}
@@ -383,7 +384,8 @@ impl VirtualMethods for HTMLTextAreaElement {
383384
&self.upcast(),
384385
atom!("input"),
385386
EventBubbles::Bubbles,
386-
EventCancelable::NotCancelable);
387+
EventCancelable::NotCancelable,
388+
window.r());
387389
}
388390

389391
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);

components/script/dom/storage.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use net_traits::IpcSend;
1919
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
2020
use script_thread::{Runnable, ScriptThread};
2121
use task_source::TaskSource;
22-
use task_source::dom_manipulation::DOMManipulationTask;
2322
use url::Url;
2423

2524
#[dom_struct]
@@ -159,10 +158,10 @@ impl Storage {
159158
new_value: Option<String>) {
160159
let global_root = self.global();
161160
let global_ref = global_root.r();
162-
let task_source = global_ref.as_window().dom_manipulation_task_source();
161+
let window = global_ref.as_window();
162+
let task_source = window.dom_manipulation_task_source();
163163
let trusted_storage = Trusted::new(self);
164-
task_source.queue(DOMManipulationTask::Runnable(
165-
box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap();
164+
task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap();
166165
}
167166
}
168167

0 commit comments

Comments
 (0)