diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-08-10 11:10:04 -0700 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-08-10 18:26:27 -0700 |
commit | 477c3c8c5b5a85f787d72bee56f489d820b65400 (patch) | |
tree | c0098691b5b8a93836fb189cd99d07a79aa75c4a | |
parent | 2c321015e9b6c53a72f8461af8d75064b087cb26 (diff) | |
download | servo-477c3c8c5b5a85f787d72bee56f489d820b65400.tar.gz servo-477c3c8c5b5a85f787d72bee56f489d820b65400.zip |
layout: Factor out the code to ensure a node data is initialized.
-rw-r--r-- | components/layout/query.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/components/layout/query.rs b/components/layout/query.rs index 5b7d2ad6625..d6defa8bd2d 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -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(); |