From 477c3c8c5b5a85f787d72bee56f489d820b65400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 10 Aug 2016 11:10:04 -0700 Subject: [PATCH] layout: Factor out the code to ensure a node data is initialized. --- components/layout/query.rs | 27 ++++++++++++++++----------- 1 file 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(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();