layout: Factor out the code to ensure a node data is initialized.

This commit is contained in:
Emilio Cobos Álvarez 2016-08-10 11:10:04 -07:00
parent 2c321015e9
commit 477c3c8c5b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -615,6 +615,20 @@ pub fn process_node_scroll_area_request< N: LayoutNode>(requested_node: N, layou
}
}
/// Ensures that a node's data, and all its parents' is initialized. This is
/// needed to resolve style lazily.
fn ensure_node_data_initialized<N: LayoutNode>(node: &N) {
let mut cur = Some(node.clone());
while let Some(current) = cur {
if current.borrow_data().is_some() {
break;
}
current.initialize_data();
cur = current.parent_node();
}
}
/// Return the resolved value of property for a given (pseudo)element.
/// https://drafts.csswg.org/cssom/#resolved-value
pub fn process_resolved_style_request<'a, N, C>(requested_node: N,
@ -630,17 +644,8 @@ pub fn process_resolved_style_request<'a, N, C>(requested_node: N,
// This node might have display: none, or it's style might be not up to
// date, so we might need to do style recalc.
//
// XXX: Is a bit shame we have to do this instead of in style :/
let mut cur = Some(requested_node);
while let Some(current) = cur {
if current.borrow_data().is_some() {
break;
}
current.initialize_data();
cur = current.parent_node();
}
// FIXME(emilio): Is a bit shame we have to do this instead of in style.
ensure_node_data_initialized(&requested_node);
ensure_node_styled(requested_node, style_context);
let layout_node = requested_node.to_threadsafe();