aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlstyleelement.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2016-12-16 12:16:41 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2016-12-16 16:57:20 +0100
commit21bf91c38676900fa2f1ef5a67ac05507466abfb (patch)
tree1cf92344611f5cca2f6622f62c85ef83220b7d86 /components/script/dom/htmlstyleelement.rs
parentb86aa41568463ed8454037dbd4247dd939c3f114 (diff)
downloadservo-21bf91c38676900fa2f1ef5a67ac05507466abfb.tar.gz
servo-21bf91c38676900fa2f1ef5a67ac05507466abfb.zip
script: Add infrastructure to track subresource loads in <link> and <style> elements.
Diffstat (limited to 'components/script/dom/htmlstyleelement.rs')
-rw-r--r--components/script/dom/htmlstyleelement.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs
index 8576a282052..5dbbd338199 100644
--- a/components/script/dom/htmlstyleelement.rs
+++ b/components/script/dom/htmlstyleelement.rs
@@ -12,17 +12,20 @@ use dom::bindings::js::{MutNullableJS, Root};
use dom::bindings::str::DOMString;
use dom::cssstylesheet::CSSStyleSheet;
use dom::document::Document;
-use dom::element::Element;
+use dom::element::{Element, ElementCreator};
+use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{ChildrenMutation, Node, document_from_node, window_from_node};
use dom::stylesheet::StyleSheet as DOMStyleSheet;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
use script_layout_interface::message::Msg;
+use std::cell::Cell;
use std::sync::Arc;
use style::media_queries::parse_media_query_list;
use style::parser::ParserContextExtraData;
use style::stylesheets::{Stylesheet, Origin};
+use stylesheet_loader::StylesheetLoader;
#[dom_struct]
pub struct HTMLStyleElement {
@@ -30,28 +33,59 @@ pub struct HTMLStyleElement {
#[ignore_heap_size_of = "Arc"]
stylesheet: DOMRefCell<Option<Arc<Stylesheet>>>,
cssom_stylesheet: MutNullableJS<CSSStyleSheet>,
+ /// https://html.spec.whatwg.org/multipage/#a-style-sheet-that-is-blocking-scripts
+ parser_inserted: Cell<bool>,
+ pending_loads: Cell<u32>,
+ any_failed_load: Cell<bool>,
}
impl HTMLStyleElement {
fn new_inherited(local_name: LocalName,
prefix: Option<DOMString>,
- document: &Document) -> HTMLStyleElement {
+ document: &Document,
+ creator: ElementCreator) -> HTMLStyleElement {
HTMLStyleElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
stylesheet: DOMRefCell::new(None),
cssom_stylesheet: MutNullableJS::new(None),
+ parser_inserted: Cell::new(creator == ElementCreator::ParserCreated),
+ pending_loads: Cell::new(0),
+ any_failed_load: Cell::new(false),
}
}
#[allow(unrooted_must_root)]
pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
- document: &Document) -> Root<HTMLStyleElement> {
- Node::reflect_node(box HTMLStyleElement::new_inherited(local_name, prefix, document),
+ document: &Document,
+ creator: ElementCreator) -> Root<HTMLStyleElement> {
+ Node::reflect_node(box HTMLStyleElement::new_inherited(local_name, prefix, document, creator),
document,
HTMLStyleElementBinding::Wrap)
}
+ pub fn increment_pending_loads_count(&self) {
+ self.pending_loads.set(self.pending_loads.get() + 1)
+ }
+
+ /// Returns None if there are still pending loads, or whether any load has
+ /// failed since the loads started.
+ pub fn load_finished(&self, succeeded: bool) -> Option<bool> {
+ assert!(self.pending_loads.get() > 0, "What finished?");
+ if !succeeded {
+ self.any_failed_load.set(true);
+ }
+
+ self.pending_loads.set(self.pending_loads.get() - 1);
+ if self.pending_loads.get() != 0 {
+ return None;
+ }
+
+ let any_failed = self.any_failed_load.get();
+ self.any_failed_load.set(false);
+ Some(any_failed)
+ }
+
pub fn parse_own_css(&self) {
let node = self.upcast::<Node>();
let element = self.upcast::<Element>();
@@ -94,6 +128,10 @@ impl HTMLStyleElement {
})
})
}
+
+ pub fn parser_inserted(&self) -> bool {
+ self.parser_inserted.get()
+ }
}
impl VirtualMethods for HTMLStyleElement {