aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/utils.rs32
-rw-r--r--components/script/dom/document.rs39
-rw-r--r--components/script/dom/htmlbodyelement.rs28
-rw-r--r--components/script/dom/servohtmlparser.rs3
-rw-r--r--components/script/dom/window.rs2
5 files changed, 87 insertions, 17 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 55933484165..612cba46f35 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -637,19 +637,29 @@ pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
// Step 2.
try!(validate_qualified_name(qualified_name));
- let (prefix, local_name) = if qualified_name.contains(":") {
- // Step 5.
- let mut parts = qualified_name.splitn(2, ':');
- let prefix = parts.next().unwrap();
- debug_assert!(!prefix.is_empty());
- let local_name = parts.next().unwrap();
- debug_assert!(!local_name.contains(":"));
- (Some(prefix), local_name)
- } else {
- (None, qualified_name)
+ let colon = ':';
+
+ // Step 5.
+ let mut parts = qualified_name.splitn(2, colon);
+
+ let (maybe_prefix, local_name) = {
+ let maybe_prefix = parts.next();
+ let maybe_local_name = parts.next();
+
+ debug_assert!(parts.next().is_none());
+
+ if let Some(local_name) = maybe_local_name {
+ debug_assert!(!maybe_prefix.unwrap().is_empty());
+
+ (maybe_prefix, local_name)
+ } else {
+ (None, maybe_prefix.unwrap())
+ }
};
- match (namespace, prefix) {
+ debug_assert!(!local_name.contains(colon));
+
+ match (namespace, maybe_prefix) {
(ns!(""), Some(_)) => {
// Step 6.
Err(Error::Namespace)
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index b81b0f58e4f..3d615df43de 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -148,6 +148,8 @@ pub struct Document {
loader: DOMRefCell<DocumentLoader>,
/// The current active HTML parser, to allow resuming after interruptions.
current_parser: MutNullableHeap<JS<ServoHTMLParser>>,
+ /// When we should kick off a reflow. This happens during parsing.
+ reflow_timeout: Cell<Option<u64>>,
}
impl DocumentDerived for EventTarget {
@@ -226,6 +228,9 @@ pub trait DocumentHelpers<'a> {
fn set_encoding_name(self, name: DOMString);
fn content_changed(self, node: JSRef<Node>, damage: NodeDamage);
fn content_and_heritage_changed(self, node: JSRef<Node>, damage: NodeDamage);
+ fn reflow_if_reflow_timer_expired(self);
+ fn set_reflow_timeout(self, timeout: u64);
+ fn disarm_reflow_timeout(self);
fn unregister_named_element(self, to_unregister: JSRef<Element>, id: Atom);
fn register_named_element(self, element: JSRef<Element>, id: Atom);
fn load_anchor_href(self, href: DOMString);
@@ -343,11 +348,42 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
}
fn content_and_heritage_changed(self, node: JSRef<Node>, damage: NodeDamage) {
- debug!("content_and_heritage_changed on {}", node.debug_str());
node.force_dirty_ancestors(damage);
node.dirty(damage);
}
+ /// Reflows and disarms the timer if the reflow timer has expired.
+ fn reflow_if_reflow_timer_expired(self) {
+ if let Some(reflow_timeout) = self.reflow_timeout.get() {
+ if time::precise_time_ns() < reflow_timeout {
+ return
+ }
+
+ self.reflow_timeout.set(None);
+ let window = self.window.root();
+ window.r().reflow(ReflowGoal::ForDisplay,
+ ReflowQueryType::NoQuery,
+ ReflowReason::RefreshTick);
+ }
+ }
+
+ /// Schedules a reflow to be kicked off at the given `timeout` (in `time::precise_time_ns()`
+ /// units). This reflow happens even if the event loop is busy. This is used to display initial
+ /// page content during parsing.
+ fn set_reflow_timeout(self, timeout: u64) {
+ if let Some(existing_timeout) = self.reflow_timeout.get() {
+ if existing_timeout < timeout {
+ return
+ }
+ }
+ self.reflow_timeout.set(Some(timeout))
+ }
+
+ /// Disables any pending reflow timeouts.
+ fn disarm_reflow_timeout(self) {
+ self.reflow_timeout.set(None)
+ }
+
/// Remove any existing association between the provided id and any elements in this document.
fn unregister_named_element(self,
to_unregister: JSRef<Element>,
@@ -1004,6 +1040,7 @@ impl Document {
animation_frame_list: RefCell::new(HashMap::new()),
loader: DOMRefCell::new(doc_loader),
current_parser: Default::default(),
+ reflow_timeout: Cell::new(None),
}
}
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 8145c2f3866..97cd615f910 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -6,11 +6,11 @@ use dom::attr::{Attr, AttrHelpers};
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
-use dom::bindings::codegen::InheritTypes::EventTargetCast;
+use dom::bindings::codegen::InheritTypes::{EventTargetCast};
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
use dom::bindings::js::{JSRef, Rootable, Temporary};
use dom::bindings::utils::Reflectable;
-use dom::document::Document;
+use dom::document::{Document, DocumentHelpers};
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -23,6 +23,11 @@ use util::str::{self, DOMString};
use std::borrow::ToOwned;
use std::cell::Cell;
+use time;
+
+/// How long we should wait before performing the initial reflow after `<body>` is parsed, in
+/// nanoseconds.
+const INITIAL_REFLOW_DELAY: u64 = 200_000_000;
#[dom_struct]
pub struct HTMLBodyElement {
@@ -32,9 +37,8 @@ pub struct HTMLBodyElement {
impl HTMLBodyElementDerived for EventTarget {
fn is_htmlbodyelement(&self) -> bool {
- *self.type_id() ==
- EventTargetTypeId::Node(
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)))
+ *self.type_id() == EventTargetTypeId::Node(NodeTypeId::Element(ElementTypeId::HTMLElement(
+ HTMLElementTypeId::HTMLBodyElement)))
}
}
@@ -91,6 +95,20 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
Some(element as &VirtualMethods)
}
+ fn bind_to_tree(&self, tree_in_doc: bool) {
+ if let Some(ref s) = self.super_type() {
+ s.bind_to_tree(tree_in_doc);
+ }
+
+ if !tree_in_doc {
+ return
+ }
+
+ let window = window_from_node(*self).root();
+ let document = window.r().Document().root();
+ document.r().set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY);
+ }
+
fn after_set_attr(&self, attr: JSRef<Attr>) {
if let Some(ref s) = self.super_type() {
s.after_set_attr(attr);
diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs
index c4779a5666d..1d69b24c5c8 100644
--- a/components/script/dom/servohtmlparser.rs
+++ b/components/script/dom/servohtmlparser.rs
@@ -303,6 +303,9 @@ impl<'a> PrivateServoHTMLParserHelpers for JSRef<'a, ServoHTMLParser> {
break;
}
+ let document = self.document.root();
+ document.r().reflow_if_reflow_timer_expired();
+
let mut pending_input = self.pending_input.borrow_mut();
if !pending_input.is_empty() {
let chunk = pending_input.remove(0);
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 6ebff11c5f1..21e9bbc28f2 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -81,6 +81,7 @@ enum WindowState {
#[derive(Debug)]
pub enum ReflowReason {
CachedPageNeededReflow,
+ RefreshTick,
FirstLoad,
KeyEvent,
MouseEvent,
@@ -1046,6 +1047,7 @@ fn debug_reflow_events(goal: &ReflowGoal, query_type: &ReflowQueryType, reason:
debug_msg.push_str(match *reason {
ReflowReason::CachedPageNeededReflow => "\tCachedPageNeededReflow",
+ ReflowReason::RefreshTick => "\tRefreshTick",
ReflowReason::FirstLoad => "\tFirstLoad",
ReflowReason::KeyEvent => "\tKeyEvent",
ReflowReason::MouseEvent => "\tMouseEvent",