From cf33f00018c7dc44a09086d6bb68b253153635ae Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 20 Nov 2015 09:51:05 -0800 Subject: Generalize the rest of layout to operate on generic Layout*. There wasn't a good way to split this up, unfortunately. With this change, the only remaining usage of the Servo-specific structures is in layout_task, where the root node is received from the script task. \o/ --- components/layout/construct.rs | 87 ++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 38 deletions(-) (limited to 'components/layout/construct.rs') diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 53b2416ee8d..49cc3567d57 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -38,6 +38,7 @@ use script::dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; use script::dom::htmlobjectelement::is_image_data; use std::borrow::ToOwned; use std::collections::LinkedList; +use std::marker::PhantomData; use std::mem; use std::sync::Arc; use std::sync::atomic::Ordering; @@ -57,7 +58,7 @@ use traversal::PostorderNodeMutTraversal; use url::Url; use util::linked_list; use util::opts; -use wrapper::{PseudoElementType, ServoThreadSafeLayoutNode, TextContent, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; +use wrapper::{PseudoElementType, TextContent, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; /// The results of flow construction for a DOM node. #[derive(Clone)] @@ -208,7 +209,8 @@ impl InlineFragmentsAccumulator { } } - fn from_inline_node(node: &ServoThreadSafeLayoutNode) -> InlineFragmentsAccumulator { + fn from_inline_node<'ln, N>(node: &N) -> InlineFragmentsAccumulator + where N: ThreadSafeLayoutNode<'ln> { InlineFragmentsAccumulator { fragments: IntermediateInlineFragments::new(), enclosing_node: Some(InlineFragmentNodeInfo { @@ -265,29 +267,35 @@ impl InlineFragmentsAccumulator { } /// An object that knows how to create flows. -pub struct FlowConstructor<'a> { +pub struct FlowConstructor<'a, 'ln, N: ThreadSafeLayoutNode<'ln>> { /// The layout context. pub layout_context: &'a LayoutContext<'a>, + /// Satisfy the compiler about the unused parameters, which we use to improve the ergonomics of + /// the ensuing impl {} by removing the need to parameterize all the methods individually. + phantom1: PhantomData<&'ln ()>, + phantom2: PhantomData, } -impl<'a> FlowConstructor<'a> { +impl<'a, 'ln, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'ln>> + FlowConstructor<'a, 'ln, ConcreteThreadSafeLayoutNode> { /// Creates a new flow constructor. - pub fn new<'b>(layout_context: &'b LayoutContext<'b>) - -> FlowConstructor<'b> { + pub fn new(layout_context: &'a LayoutContext<'a>) -> Self { FlowConstructor { layout_context: layout_context, + phantom1: PhantomData, + phantom2: PhantomData, } } #[inline] fn set_flow_construction_result(&self, - node: &ServoThreadSafeLayoutNode, + node: &ConcreteThreadSafeLayoutNode, result: ConstructionResult) { node.set_flow_construction_result(result); } /// Builds the fragment for the given block or subclass thereof. - fn build_fragment_for_block(&mut self, node: &ServoThreadSafeLayoutNode) -> Fragment { + fn build_fragment_for_block(&mut self, node: &ConcreteThreadSafeLayoutNode) -> Fragment { let specific_fragment_info = match node.type_id() { Some(NodeTypeId::Element(ElementTypeId::HTMLElement( HTMLElementTypeId::HTMLIFrameElement))) => { @@ -343,7 +351,7 @@ impl<'a> FlowConstructor<'a> { fn generate_anonymous_table_flows_if_necessary(&mut self, flow: &mut FlowRef, child: &mut FlowRef, - child_node: &ServoThreadSafeLayoutNode) { + child_node: &ConcreteThreadSafeLayoutNode) { if !flow.is_block_flow() { return } @@ -401,7 +409,7 @@ impl<'a> FlowConstructor<'a> { flow: &mut FlowRef, flow_list: &mut Vec, absolute_descendants: &mut AbsoluteDescendants, - node: &ServoThreadSafeLayoutNode) { + node: &ConcreteThreadSafeLayoutNode) { let mut fragments = fragment_accumulator.to_intermediate_inline_fragments(); if fragments.is_empty() { return @@ -486,8 +494,8 @@ impl<'a> FlowConstructor<'a> { &mut self, flow: &mut FlowRef, consecutive_siblings: &mut Vec, - node: &ServoThreadSafeLayoutNode, - kid: ServoThreadSafeLayoutNode, + node: &ConcreteThreadSafeLayoutNode, + kid: ConcreteThreadSafeLayoutNode, inline_fragment_accumulator: &mut InlineFragmentsAccumulator, abs_descendants: &mut AbsoluteDescendants) { match kid.swap_out_construction_result() { @@ -595,7 +603,7 @@ impl<'a> FlowConstructor<'a> { fn build_flow_for_block_starting_with_fragments( &mut self, mut flow: FlowRef, - node: &ServoThreadSafeLayoutNode, + node: &ConcreteThreadSafeLayoutNode, initial_fragments: IntermediateInlineFragments) -> ConstructionResult { // Gather up fragments for the inline flows we might need to create. @@ -662,7 +670,7 @@ impl<'a> FlowConstructor<'a> { /// /// FIXME(pcwalton): It is not clear to me that there isn't a cleaner way to handle /// `