diff options
-rw-r--r-- | components/layout/animation.rs | 4 | ||||
-rw-r--r-- | components/layout/block.rs | 76 | ||||
-rw-r--r-- | components/layout/construct.rs | 32 | ||||
-rw-r--r-- | components/layout/flex.rs | 11 | ||||
-rw-r--r-- | components/layout/floats.rs | 8 | ||||
-rw-r--r-- | components/layout/flow.rs | 113 | ||||
-rw-r--r-- | components/layout/fragment.rs | 8 | ||||
-rw-r--r-- | components/layout/generated_content.rs | 6 | ||||
-rw-r--r-- | components/layout/incremental.rs | 18 | ||||
-rw-r--r-- | components/layout/inline.rs | 14 | ||||
-rw-r--r-- | components/layout/layout_debug.rs | 10 | ||||
-rw-r--r-- | components/layout/multicol.rs | 4 | ||||
-rw-r--r-- | components/layout/parallel.rs | 10 | ||||
-rw-r--r-- | components/layout/query.rs | 4 | ||||
-rw-r--r-- | components/layout/sequential.rs | 28 | ||||
-rw-r--r-- | components/layout/table.rs | 11 | ||||
-rw-r--r-- | components/layout/table_cell.rs | 12 | ||||
-rw-r--r-- | components/layout/table_row.rs | 8 | ||||
-rw-r--r-- | components/layout/traversal.rs | 28 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 18 |
20 files changed, 211 insertions, 212 deletions
diff --git a/components/layout/animation.rs b/components/layout/animation.rs index 19f621f7fdc..a3c364a7851 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -5,7 +5,7 @@ //! CSS transitions and animations. use context::LayoutContext; -use flow::{self, Flow}; +use flow::{Flow, GetBaseFlow}; use fnv::FnvHashMap; use gfx::display_list::OpaqueNode; use ipc_channel::ipc::IpcSender; @@ -170,7 +170,7 @@ pub fn recalc_style_for_animations(context: &LayoutContext, } }); - let base = flow::mut_base(flow); + let base = flow.mut_base(); base.restyle_damage.insert(damage); for kid in base.children.iter_mut() { recalc_style_for_animations(context, kid, animations) diff --git a/components/layout/block.rs b/components/layout/block.rs index 2a539031195..f615c5aa469 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -34,7 +34,7 @@ use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Rect, SideOffsets2D, Size2D}; use floats::{ClearType, FloatKind, Floats, PlacementInfo}; -use flow::{self, BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ForceNonfloatedFlag}; +use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ForceNonfloatedFlag, GetBaseFlow}; use flow::{ImmutableFlowUtils, LateAbsolutePositionInfo, OpaqueFlow, FragmentationContext, FlowFlags}; use flow_list::FlowList; use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow, FragmentFlags}; @@ -708,7 +708,7 @@ impl BlockFlow { // Shift all kids down (or up, if margins are negative) if necessary. if block_start_margin_value != Au(0) { for kid in self.base.child_iter_mut() { - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); kid_base.position.start.b = kid_base.position.start.b + block_start_margin_value } } @@ -744,7 +744,7 @@ impl BlockFlow { /// is also needed to handle RTL.) fn propagate_early_absolute_position_info_to_children(&mut self) { for kid in self.base.child_iter_mut() { - flow::mut_base(kid).early_absolute_position_info = EarlyAbsolutePositionInfo { + kid.mut_base().early_absolute_position_info = EarlyAbsolutePositionInfo { relative_containing_block_size: self.fragment.content_box().size, relative_containing_block_mode: self.fragment.style().writing_mode, } @@ -816,19 +816,19 @@ impl BlockFlow { let thread_id = self.base.thread_id; let (mut had_floated_children, mut had_children_with_clearance) = (false, false); for (child_index, kid) in self.base.child_iter_mut().enumerate() { - if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Assume that the *hypothetical box* for an absolute flow starts immediately // after the margin-end border edge of the previous flow. - if flow::base(kid).flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { + if kid.base().flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { let previous_bottom_margin = margin_collapse_info.current_float_ceiling(); - flow::mut_base(kid).position.start.b = cur_b + - flow::base(kid).collapsible_margins + kid.mut_base().position.start.b = cur_b + + kid.base().collapsible_margins .block_start_margin_for_noncollapsible_context() + previous_bottom_margin } kid.place_float_if_applicable(); - if !flow::base(kid).flags.is_float() { + if !kid.base().flags.is_float() { kid.assign_block_size_for_inorder_child_if_necessary(layout_context, thread_id, content_box); @@ -852,10 +852,10 @@ impl BlockFlow { // Assign block-size now for the child if it might have floats in and we couldn't // before. - flow::mut_base(kid).floats = floats.clone(); - if flow::base(kid).flags.is_float() { + kid.mut_base().floats = floats.clone(); + if kid.base().flags.is_float() { had_floated_children = true; - flow::mut_base(kid).position.start.b = cur_b; + kid.mut_base().position.start.b = cur_b; { let kid_block = kid.as_mut_block(); let float_ceiling = margin_collapse_info.current_float_ceiling(); @@ -863,7 +863,7 @@ impl BlockFlow { } kid.place_float_if_applicable(); - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); floats = kid_base.floats.clone(); continue } @@ -875,8 +875,8 @@ impl BlockFlow { // complicated with margin collapse. Possibly the right thing to do is to lay out // the block again in this rare case. (Note that WebKit can lay blocks out twice; // this may be related, although I haven't looked into it closely.) - if flow::base(kid).flags.clears_floats() { - flow::mut_base(kid).floats = Floats::new(self.fragment.style.writing_mode) + if kid.base().flags.clears_floats() { + kid.mut_base().floats = Floats::new(self.fragment.style.writing_mode) } // Lay the child out if this was an in-order traversal. @@ -887,26 +887,26 @@ impl BlockFlow { if !had_children_with_clearance && floats.is_present() && - (flow::base(kid).flags.contains(FlowFlags::CLEARS_LEFT) || - flow::base(kid).flags.contains(FlowFlags::CLEARS_RIGHT)) { + (kid.base().flags.contains(FlowFlags::CLEARS_LEFT) || + kid.base().flags.contains(FlowFlags::CLEARS_RIGHT)) { had_children_with_clearance = true } // Handle any (possibly collapsed) top margin. let delta = margin_collapse_info.advance_block_start_margin( - &flow::base(kid).collapsible_margins, + &kid.base().collapsible_margins, !had_children_with_clearance); translate_including_floats(&mut cur_b, delta, &mut floats); // Collapse-through margins should be placed at the top edge, // so we'll handle the delta after the bottom margin is processed - if let CollapsibleMargins::CollapseThrough(_) = flow::base(kid).collapsible_margins { + if let CollapsibleMargins::CollapseThrough(_) = kid.base().collapsible_margins { cur_b = cur_b - delta; } // Clear past the floats that came in, if necessary. - let clearance = match (flow::base(kid).flags.contains(FlowFlags::CLEARS_LEFT), - flow::base(kid).flags.contains(FlowFlags::CLEARS_RIGHT)) { + let clearance = match (kid.base().flags.contains(FlowFlags::CLEARS_LEFT), + kid.base().flags.contains(FlowFlags::CLEARS_RIGHT)) { (false, false) => Au(0), (true, false) => floats.clearance(ClearType::Left), (false, true) => floats.clearance(ClearType::Right), @@ -915,19 +915,19 @@ impl BlockFlow { translate_including_floats(&mut cur_b, clearance, &mut floats); // At this point, `cur_b` is at the border edge of the child. - flow::mut_base(kid).position.start.b = cur_b; + kid.mut_base().position.start.b = cur_b; // Now pull out the child's outgoing floats. We didn't do this immediately after // the `assign_block_size_for_inorder_child_if_necessary` call because clearance on // a block operates on the floats that come *in*, not the floats that go *out*. if need_to_process_child_floats { - floats = flow::mut_base(kid).floats.clone() + floats = kid.mut_base().floats.clone() } // Move past the child's border box. Do not use the `translate_including_floats` // function here because the child has already translated floats past its border // box. - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); cur_b = cur_b + kid_base.position.size.block; // Handle any (possibly collapsed) block-end margin. @@ -1371,11 +1371,11 @@ impl BlockFlow { let mut iterator = self.base.child_iter_mut().enumerate().peekable(); while let Some((i, kid)) = iterator.next() { - flow::mut_base(kid).block_container_explicit_block_size = explicit_content_size; + kid.mut_base().block_container_explicit_block_size = explicit_content_size; // The inline-start margin edge of the child flow is at our inline-start content edge, // and its inline-size is our content inline-size. - let kid_mode = flow::base(kid).writing_mode; + let kid_mode = kid.base().writing_mode; { // Don't assign positions to children unless they're going to be reflowed. // Otherwise, the position we assign might be incorrect and never fixed up. (Issue @@ -1385,7 +1385,7 @@ impl BlockFlow { // `assign_block_size()`, which won't do anything unless `REFLOW` is set. So, if a // float child does not have `REFLOW` set, we must be careful to avoid touching its // inline position, as no logic will run afterward to set its true value. - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); let reflow_damage = if kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { ServoRestyleDamage::REFLOW_OUT_OF_FLOW } else { @@ -1418,7 +1418,7 @@ impl BlockFlow { // // TODO(#2265, pcwalton): Do this in the cascade instead. let containing_block_text_align = self.fragment.style().get_inheritedtext().text_align; - flow::mut_base(kid).flags.set_text_align(containing_block_text_align); + kid.mut_base().flags.set_text_align(containing_block_text_align); // Handle `text-indent` on behalf of any inline children that we have. This is // necessary because any percentages are relative to the containing block, which only @@ -1554,7 +1554,7 @@ impl BlockFlow { // Assign final-final inline sizes on all our children. self.assign_inline_sizes(layout_context); // Re-run layout on our children. - for child in flow::mut_base(self).children.iter_mut() { + for child in self.base.child_iter_mut() { sequential::reflow(child, layout_context, RelayoutMode::Force); } // Assign our final-final block size. @@ -1597,7 +1597,7 @@ impl BlockFlow { } else { flags.remove(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); for kid in self.base.children.iter() { - if flow::base(kid).flags.contains(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS) { + if kid.base().flags.contains(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS) { flags.insert(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); break } @@ -1615,11 +1615,11 @@ impl BlockFlow { let (mut left_float_width_accumulator, mut right_float_width_accumulator) = (Au(0), Au(0)); let mut preferred_inline_size_of_children_without_text_or_replaced_fragments = Au(0); for kid in self.base.child_iter_mut() { - if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) || !consult_children { + if kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) || !consult_children { continue } - let child_base = flow::mut_base(kid); + let child_base = kid.mut_base(); let float_kind = child_base.flags.float_kind(); computation.content_intrinsic_sizes.minimum_inline_size = max(computation.content_intrinsic_sizes.minimum_inline_size, @@ -1935,14 +1935,14 @@ impl Flow for BlockFlow { self.base.flags.contains(FlowFlags::MARGINS_CANNOT_COLLAPSE) { // Root element margins should never be collapsed according to CSS § 8.3.1. debug!("assign_block_size: assigning block_size for root flow {:?}", - flow::base(self).debug_id()); + self.base().debug_id()); self.assign_block_size_block_base( layout_context, fragmentation_context, MarginsMayCollapseFlag::MarginsMayNotCollapse) } else { debug!("assign_block_size: assigning block_size for block {:?}", - flow::base(self).debug_id()); + self.base().debug_id()); self.assign_block_size_block_base( layout_context, fragmentation_context, @@ -2060,9 +2060,9 @@ impl Flow for BlockFlow { // Process children. for kid in self.base.child_iter_mut() { - if flow::base(kid).flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) || - flow::base(kid).flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { - let kid_base = flow::mut_base(kid); + if kid.base().flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) || + kid.base().flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { + let kid_base = kid.mut_base(); let physical_position = kid_base.position.to_physical(kid_base.writing_mode, container_size_for_children); @@ -2088,7 +2088,7 @@ impl Flow for BlockFlow { } } - flow::mut_base(kid).late_absolute_position_info = + kid.mut_base().late_absolute_position_info = late_absolute_position_info_for_children; } } @@ -2377,7 +2377,7 @@ pub trait ISizeAndMarginsComputer { // We also resize the block itself, to ensure that overflow is not calculated // as the inline-size of our parent. We might be smaller and we might be larger if we // overflow. - flow::mut_base(block).position.size.inline = inline_size + extra_inline_size_from_margin; + block.mut_base().position.size.inline = inline_size + extra_inline_size_from_margin; } /// Set the inline coordinate of the given flow if it is absolutely positioned. diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 07e4b783b2a..67e61b7dfcb 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -19,7 +19,7 @@ use context::{LayoutContext, with_thread_local_font_context}; use data::{LayoutDataFlags, LayoutData}; use flex::FlexFlow; use floats::FloatKind; -use flow::{self, AbsoluteDescendants, Flow, FlowClass, ImmutableFlowUtils}; +use flow::{AbsoluteDescendants, Flow, FlowClass, GetBaseFlow, ImmutableFlowUtils}; use flow::{FlowFlags, MutableFlowUtils, MutableOwnedFlowUtils}; use flow_ref::FlowRef; use fragment::{CanvasFragmentInfo, ImageFragmentInfo, InlineAbsoluteFragmentInfo, SvgFragmentInfo}; @@ -96,7 +96,7 @@ impl ConstructionResult { match *self { ConstructionResult::None => 0, ConstructionResult::ConstructionItem(_) => 0, - ConstructionResult::Flow(ref flow_ref, _) => flow::base(&**flow_ref).debug_id(), + ConstructionResult::Flow(ref flow_ref, _) => flow_ref.base().debug_id(), } } } @@ -497,7 +497,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> ConstructionResult::Flow(kid_flow, AbsoluteDescendants::new()); self.set_flow_construction_result(&kid, construction_result) } else { - if !flow::base(&*kid_flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if !kid_flow.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Flush any inline fragments that we were gathering up. This allows us to // handle {ib} splits. let old_inline_fragment_accumulator = @@ -625,7 +625,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> flow.set_absolute_descendants(abs_descendants); abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if flow.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its CB. abs_descendants.push(flow.clone()); @@ -780,7 +780,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> match kid.get_construction_result() { ConstructionResult::None => {} ConstructionResult::Flow(flow, kid_abs_descendants) => { - if !flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if !flow.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { opt_inline_block_splits.push_back(InlineBlockSplit::new( &mut fragment_accumulator, node, self.style_context(), flow)); abs_descendants.push_descendants(kid_abs_descendants); @@ -1073,7 +1073,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if flow.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its containing block. abs_descendants.push(flow.clone()); @@ -1144,7 +1144,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*wrapper_flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if wrapper_flow.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its containing block. abs_descendants.push(wrapper_flow.clone()); @@ -1373,7 +1373,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } let flow = FlowRef::deref_mut(flow); - flow::mut_base(flow).restyle_damage.insert(damage); + flow.mut_base().restyle_damage.insert(damage); flow.repair_style_and_bubble_inline_sizes(&style); true } @@ -1398,7 +1398,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> match fragment.specific { SpecificFragmentInfo::InlineBlock(ref mut inline_block_fragment) => { let flow_ref = FlowRef::deref_mut(&mut inline_block_fragment.flow_ref); - flow::mut_base(flow_ref).restyle_damage.insert(damage); + flow_ref.mut_base().restyle_damage.insert(damage); // FIXME(pcwalton): Fragment restyle damage too? flow_ref.repair_style_and_bubble_inline_sizes(&style); } @@ -1406,14 +1406,14 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> ref mut inline_absolute_hypothetical_fragment) => { let flow_ref = FlowRef::deref_mut( &mut inline_absolute_hypothetical_fragment.flow_ref); - flow::mut_base(flow_ref).restyle_damage.insert(damage); + flow_ref.mut_base().restyle_damage.insert(damage); // FIXME(pcwalton): Fragment restyle damage too? flow_ref.repair_style_and_bubble_inline_sizes(&style); } SpecificFragmentInfo::InlineAbsolute(ref mut inline_absolute_fragment) => { let flow_ref = FlowRef::deref_mut( &mut inline_absolute_fragment.flow_ref); - flow::mut_base(flow_ref).restyle_damage.insert(damage); + flow_ref.mut_base().restyle_damage.insert(damage); // FIXME(pcwalton): Fragment restyle damage too? flow_ref.repair_style_and_bubble_inline_sizes(&style); } @@ -1660,7 +1660,7 @@ impl<ConcreteThreadSafeLayoutNode> NodeUtils for ConcreteThreadSafeLayoutNode fn set_flow_construction_result(self, mut result: ConstructionResult) { if self.can_be_fragmented() { if let ConstructionResult::Flow(ref mut flow, _) = result { - flow::mut_base(FlowRef::deref_mut(flow)).flags.insert(FlowFlags::CAN_BE_FRAGMENTED); + FlowRef::deref_mut(flow).mut_base().flags.insert(FlowFlags::CAN_BE_FRAGMENTED); } } @@ -1732,11 +1732,11 @@ impl FlowConstructionUtils for FlowRef { /// Adds a new flow as a child of this flow. Fails if this flow is marked as a leaf. fn add_new_child(&mut self, mut new_child: FlowRef) { { - let kid_base = flow::mut_base(FlowRef::deref_mut(&mut new_child)); + let kid_base = FlowRef::deref_mut(&mut new_child).mut_base(); kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self); } - let base = flow::mut_base(FlowRef::deref_mut(self)); + let base = FlowRef::deref_mut(self).mut_base(); base.children.push_back(new_child); let _ = base.parallel.children_count.fetch_add(1, Ordering::Relaxed); } @@ -1750,7 +1750,7 @@ impl FlowConstructionUtils for FlowRef { fn finish(&mut self) { if !opts::get().bubble_inline_sizes_separately { FlowRef::deref_mut(self).bubble_inline_sizes(); - flow::mut_base(FlowRef::deref_mut(self)).restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); + FlowRef::deref_mut(self).mut_base().restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); } } } @@ -1951,7 +1951,7 @@ impl Legalizer { } (FlowClass::Flex, FlowClass::Inline) => { - flow::mut_base(FlowRef::deref_mut(child)).flags.insert(FlowFlags::MARGINS_CANNOT_COLLAPSE); + FlowRef::deref_mut(child).mut_base().flags.insert(FlowFlags::MARGINS_CANNOT_COLLAPSE); let mut block_wrapper = Legalizer::create_anonymous_flow(context, parent, diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 564f8ed9a5e..5cbb80263ac 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -13,8 +13,7 @@ use display_list_builder::{DisplayListBuildState, FlexFlowDisplayListBuilding}; use display_list_builder::StackingContextCollectionState; use euclid::Point2D; use floats::FloatKind; -use flow; -use flow::{Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow, FlowFlags}; +use flow::{Flow, FlowClass, GetBaseFlow, ImmutableFlowUtils, OpaqueFlow, FlowFlags}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use layout_debug; use model::{AdjoiningMargins, CollapsibleMargins}; @@ -451,7 +450,7 @@ impl FlexFlow { let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { for kid in self.block_flow.base.children.iter_mut() { - let base = flow::mut_base(kid); + let base = kid.mut_base(); let is_absolutely_positioned = base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); if !is_absolutely_positioned { let flex_item_inline_sizes = IntrinsicISizes { @@ -477,7 +476,7 @@ impl FlexFlow { let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { for kid in self.block_flow.base.children.iter_mut() { - let base = flow::mut_base(kid); + let base = kid.mut_base(); let is_absolutely_positioned = base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); if !is_absolutely_positioned { computation.content_intrinsic_sizes.minimum_inline_size = @@ -519,7 +518,7 @@ impl FlexFlow { let mut children = self.block_flow.base.children.random_access_mut(); for kid in &mut self.items { - let kid_base = flow::mut_base(children.get(kid.index)); + let kid_base = children.get(kid.index).mut_base(); kid_base.block_container_explicit_block_size = container_block_size; if kid_base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { // The inline-start margin edge of the child flow is at our inline-start content @@ -667,7 +666,7 @@ impl FlexFlow { let mut children = self.block_flow.base.children.random_access_mut(); for item in &mut self.items { - let base = flow::mut_base(children.get(item.index)); + let base = children.get(item.index).mut_base(); if !self.main_reverse { base.position.start.b = cur_b; cur_b = cur_b + base.position.size.block; diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 0feb6699987..4c4d6f21f36 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -4,7 +4,7 @@ use app_units::{Au, MAX_AU}; use block::FormattingContextType; -use flow::{self, Flow, FlowFlags, ImmutableFlowUtils}; +use flow::{Flow, FlowFlags, GetBaseFlow, ImmutableFlowUtils}; use persistent_list::PersistentList; use std::cmp::{max, min}; use std::fmt; @@ -458,7 +458,7 @@ impl SpeculatedFloatPlacement { /// Given the speculated inline size of the floats out for the inorder predecessor of this /// flow, computes the speculated inline size of the floats flowing in. pub fn compute_floats_in(&mut self, flow: &mut Flow) { - let base_flow = flow::base(flow); + let base_flow = flow.base(); if base_flow.flags.contains(FlowFlags::CLEARS_LEFT) { self.left = Au(0) } @@ -491,7 +491,7 @@ impl SpeculatedFloatPlacement { } } - let base_flow = flow::base(flow); + let base_flow = flow.base(); if !base_flow.flags.is_float() { return } @@ -522,7 +522,7 @@ impl SpeculatedFloatPlacement { /// Given a flow, computes the speculated inline size of the floats in of its first child. pub fn compute_floats_in_for_first_child(parent_flow: &mut Flow) -> SpeculatedFloatPlacement { if !parent_flow.is_block_like() { - return flow::base(parent_flow).speculated_float_placement_in + return parent_flow.base().speculated_float_placement_in } let parent_block_flow = parent_flow.as_block(); diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 943ddcb71b7..e4841bd2e0f 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -76,6 +76,30 @@ use table_wrapper::TableWrapperFlow; #[allow(unsafe_code)] pub unsafe trait HasBaseFlow {} +/// Methods to get the `BaseFlow` from any `HasBaseFlow` type. +pub trait GetBaseFlow { + fn base(&self) -> &BaseFlow; + fn mut_base(&mut self) -> &mut BaseFlow; +} + +impl<T: HasBaseFlow + ?Sized> GetBaseFlow for T { + #[inline(always)] + #[allow(unsafe_code)] + fn base(&self) -> &BaseFlow { + let ptr: *const Self = self; + let ptr = ptr as *const BaseFlow; + unsafe { &*ptr } + } + + #[inline(always)] + #[allow(unsafe_code)] + fn mut_base(&mut self) -> &mut BaseFlow { + let ptr: *mut Self = self; + let ptr = ptr as *mut BaseFlow; + unsafe { &mut *ptr } + } +} + /// Virtual methods that make up a float context. /// /// Note that virtual methods have a cost; we should not overuse them in Servo. Consider adding @@ -224,8 +248,8 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { layout_context: &LayoutContext, _fragmentation_context: Option<FragmentationContext>) -> Option<Arc<Flow>> { - fn recursive_assign_block_size<F: ?Sized + Flow>(flow: &mut F, ctx: &LayoutContext) { - for child in mut_base(flow).children.iter_mut() { + fn recursive_assign_block_size<F: ?Sized + Flow + GetBaseFlow>(flow: &mut F, ctx: &LayoutContext) { + for child in flow.mut_base().child_iter_mut() { recursive_assign_block_size(child, ctx) } flow.assign_block_size(ctx); @@ -251,12 +275,12 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { parent_thread_id: u8, _content_box: LogicalRect<Au>) -> bool { - let might_have_floats_in_or_out = base(self).might_have_floats_in() || - base(self).might_have_floats_out(); + let might_have_floats_in_or_out = self.base().might_have_floats_in() || + self.base().might_have_floats_out(); if might_have_floats_in_or_out { - mut_base(self).thread_id = parent_thread_id; + self.mut_base().thread_id = parent_thread_id; self.assign_block_size(layout_context); - mut_base(self).restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); + self.mut_base().restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } might_have_floats_in_or_out } @@ -264,9 +288,9 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { fn get_overflow_in_parent_coordinates(&self) -> Overflow { // FIXME(#2795): Get the real container size. let container_size = Size2D::zero(); - let position = base(self).position.to_physical(base(self).writing_mode, container_size); + let position = self.base().position.to_physical(self.base().writing_mode, container_size); - let mut overflow = base(self).overflow; + let mut overflow = self.base().overflow; match self.class() { FlowClass::Block | FlowClass::TableCaption | FlowClass::TableCell => {} @@ -277,9 +301,9 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { } let border_box = self.as_block().fragment.stacking_relative_border_box( - &base(self).stacking_relative_position, - &base(self).early_absolute_position_info.relative_containing_block_size, - base(self).early_absolute_position_info.relative_containing_block_mode, + &self.base().stacking_relative_position, + &self.base().early_absolute_position_info.relative_containing_block_size, + self.base().early_absolute_position_info.relative_containing_block_mode, CoordinateSystem::Own); if StyleOverflow::Visible != self.as_block().fragment.style.get_box().overflow_x { overflow.paint.origin.x = Au(0); @@ -341,13 +365,13 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { FlowClass::Block | FlowClass::TableCaption | FlowClass::TableCell => { - for kid in mut_base(self).children.iter_mut() { + for kid in self.mut_base().children.iter_mut() { overflow.union(&kid.get_overflow_in_parent_coordinates()); } } _ => {} } - mut_base(self).overflow = overflow + self.mut_base().overflow = overflow } /// Phase 4 of reflow: Compute the stacking-relative position (origin of the content box, @@ -406,7 +430,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { fn contains_positioned_fragments(&self) -> bool { self.contains_relatively_positioned_fragments() || - base(self).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) + self.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) } fn contains_relatively_positioned_fragments(&self) -> bool { @@ -448,41 +472,13 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { fn print_extra_flow_children(&self, _: &mut PrintTree) { } fn clipping_and_scrolling(&self) -> ClippingAndScrolling { - match base(self).clipping_and_scrolling { + match self.base().clipping_and_scrolling { Some(info) => info, None => unreachable!("Tried to access scroll root id on Flow before assignment"), } } } -// Base access - -#[inline(always)] -#[allow(unsafe_code)] -pub fn base<T: ?Sized + HasBaseFlow>(this: &T) -> &BaseFlow { - let ptr: *const T = this; - let ptr = ptr as *const BaseFlow; - unsafe { &*ptr } -} - -/// Iterates over the children of this immutable flow. -pub fn child_iter<'a>(flow: &'a Flow) -> FlowListIterator { - base(flow).children.iter() -} - -#[inline(always)] -#[allow(unsafe_code)] -pub fn mut_base<T: ?Sized + HasBaseFlow>(this: &mut T) -> &mut BaseFlow { - let ptr: *mut T = this; - let ptr = ptr as *mut BaseFlow; - unsafe { &mut *ptr } -} - -/// Iterates over the children of this flow. -pub fn child_iter_mut<'a>(flow: &'a mut Flow) -> MutFlowListIterator<'a> { - mut_base(flow).children.iter_mut() -} - pub trait ImmutableFlowUtils { // Convenience functions @@ -1106,6 +1102,11 @@ impl BaseFlow { } } + /// Iterates over the children of this immutable flow. + pub fn child_iter(&self) -> FlowListIterator { + self.children.iter() + } + pub fn child_iter_mut(&mut self) -> MutFlowListIterator { self.children.iter_mut() } @@ -1216,12 +1217,12 @@ impl<'a> ImmutableFlowUtils for &'a Flow { /// Returns true if this flow has no children. fn is_leaf(self) -> bool { - base(self).children.is_empty() + self.base().children.is_empty() } /// Returns the number of children that this flow possesses. fn child_count(self) -> usize { - base(self).children.len() + self.base().children.len() } /// Return true if this flow is a Block Container. @@ -1267,14 +1268,14 @@ impl<'a> ImmutableFlowUtils for &'a Flow { fn print_with_tree(self, print_tree: &mut PrintTree) { print_tree.new_level(format!("{:?}", self)); self.print_extra_flow_children(print_tree); - for kid in child_iter(self) { + for kid in self.base().child_iter() { kid.print_with_tree(print_tree); } print_tree.end_level(); } fn floats_might_flow_through(self) -> bool { - if !base(self).might_have_floats_in() && !base(self).might_have_floats_out() { + if !self.base().might_have_floats_in() && !self.base().might_have_floats_out() { return false } if self.is_root() { @@ -1287,15 +1288,15 @@ impl<'a> ImmutableFlowUtils for &'a Flow { } fn baseline_offset_of_last_line_box_in_flow(self) -> Option<Au> { - for kid in base(self).children.iter().rev() { + for kid in self.base().children.iter().rev() { if kid.is_inline_flow() { if let Some(baseline_offset) = kid.as_inline().baseline_offset_of_last_line() { - return Some(base(kid).position.start.b + baseline_offset) + return Some(kid.base().position.start.b + baseline_offset) } } - if kid.is_block_like() && !base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + if kid.is_block_like() && !kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { if let Some(baseline_offset) = kid.baseline_offset_of_last_line_box_in_flow() { - return Some(base(kid).position.start.b + baseline_offset) + return Some(kid.base().position.start.b + baseline_offset) } } } @@ -1308,7 +1309,7 @@ impl<'a> MutableFlowUtils for &'a mut Flow { /// calling them individually, since there is no reason not to perform both operations. fn repair_style_and_bubble_inline_sizes(self, style: &::ServoArc<ComputedValues>) { self.repair_style(style); - mut_base(self).update_flags_if_needed(style); + self.mut_base().update_flags_if_needed(style); self.bubble_inline_sizes(); } } @@ -1323,11 +1324,11 @@ impl MutableOwnedFlowUtils for FlowRef { /// construction is allowed to possess. fn set_absolute_descendants(&mut self, abs_descendants: AbsoluteDescendants) { let this = self.clone(); - let base = mut_base(FlowRef::deref_mut(self)); + let base = FlowRef::deref_mut(self).mut_base(); base.abs_descendants = abs_descendants; for descendant_link in base.abs_descendants.descendant_links.iter_mut() { debug_assert!(!descendant_link.has_reached_containing_block); - let descendant_base = mut_base(FlowRef::deref_mut(&mut descendant_link.flow)); + let descendant_base = FlowRef::deref_mut(&mut descendant_link.flow).mut_base(); descendant_base.absolute_cb.set(this.clone()); } } @@ -1353,10 +1354,10 @@ impl MutableOwnedFlowUtils for FlowRef { }); let this = self.clone(); - let base = mut_base(FlowRef::deref_mut(self)); + let base = FlowRef::deref_mut(self).mut_base(); base.abs_descendants = applicable_absolute_descendants; for descendant_link in base.abs_descendants.iter() { - let descendant_base = mut_base(descendant_link); + let descendant_base = descendant_link.mut_base(); descendant_base.absolute_cb.set(this.clone()); } } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 548c1636e86..b2a627347da 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -12,7 +12,7 @@ use canvas_traits::canvas::CanvasMsg; use context::{LayoutContext, with_thread_local_font_context}; use euclid::{Transform3D, Point2D, Vector2D, Rect, Size2D}; use floats::ClearType; -use flow::{self, ImmutableFlowUtils}; +use flow::{GetBaseFlow, ImmutableFlowUtils}; use flow_ref::FlowRef; use gfx; use gfx::display_list::{BLUR_INFLATION_FACTOR, OpaqueNode}; @@ -232,7 +232,7 @@ impl SpecificFragmentInfo { SpecificFragmentInfo::InlineBlock(ref info) => &info.flow_ref, }; - flow::base(&**flow).restyle_damage + flow.base().restyle_damage } pub fn get_type(&self) -> &'static str { @@ -2612,11 +2612,11 @@ impl Fragment { match self.specific { SpecificFragmentInfo::InlineBlock(ref info) => { let block_flow = info.flow_ref.as_block(); - overflow.union(&flow::base(block_flow).overflow); + overflow.union(&block_flow.base().overflow); } SpecificFragmentInfo::InlineAbsolute(ref info) => { let block_flow = info.flow_ref.as_block(); - overflow.union(&flow::base(block_flow).overflow); + overflow.union(&block_flow.base().overflow); } _ => (), } diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index e838bde6b95..fd11b996872 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -9,7 +9,7 @@ //! as possible. use context::{LayoutContext, with_thread_local_font_context}; -use flow::{self, Flow, FlowFlags, ImmutableFlowUtils}; +use flow::{Flow, FlowFlags, GetBaseFlow, ImmutableFlowUtils}; use fragment::{Fragment, GeneratedContentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; use gfx::display_list::OpaqueNode; use script_layout_interface::wrapper_traits::PseudoElementType; @@ -132,8 +132,8 @@ impl<'a> InorderFlowTraversal for ResolveGeneratedContent<'a> { #[inline] fn should_process_subtree(&mut self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::RESOLVE_GENERATED_CONTENT) || - flow::base(flow).flags.intersects(FlowFlags::AFFECTS_COUNTERS | FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN) + flow.base().restyle_damage.intersects(ServoRestyleDamage::RESOLVE_GENERATED_CONTENT) || + flow.base().flags.intersects(FlowFlags::AFFECTS_COUNTERS | FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN) } } diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index bbb2c89f55f..ff1e0813ccd 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use flow::{self, FlowFlags, Flow}; +use flow::{FlowFlags, Flow, GetBaseFlow}; use style::computed_values::float::T as Float; use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; @@ -30,20 +30,20 @@ pub trait LayoutDamageComputation { impl<'a> LayoutDamageComputation for &'a mut Flow { fn compute_layout_damage(self) -> SpecialRestyleDamage { let mut special_damage = SpecialRestyleDamage::empty(); - let is_absolutely_positioned = flow::base(self).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); + let is_absolutely_positioned = self.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); // In addition to damage, we use this phase to compute whether nodes affect CSS counters. let mut has_counter_affecting_children = false; { - let self_base = flow::mut_base(self); + let self_base = self.mut_base(); // Take a snapshot of the parent damage before updating it with damage from children. let parent_damage = self_base.restyle_damage; for kid in self_base.children.iter_mut() { let child_is_absolutely_positioned = - flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); - flow::mut_base(kid).restyle_damage.insert( + kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); + kid.mut_base().restyle_damage.insert( parent_damage.damage_for_child(is_absolutely_positioned, child_is_absolutely_positioned)); { @@ -51,16 +51,16 @@ impl<'a> LayoutDamageComputation for &'a mut Flow { special_damage.insert(kid.compute_layout_damage()); } self_base.restyle_damage - .insert(flow::base(kid).restyle_damage.damage_for_parent( + .insert(kid.base().restyle_damage.damage_for_parent( child_is_absolutely_positioned)); has_counter_affecting_children = has_counter_affecting_children || - flow::base(kid).flags.intersects(FlowFlags::AFFECTS_COUNTERS | + kid.base().flags.intersects(FlowFlags::AFFECTS_COUNTERS | FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN); } } - let self_base = flow::mut_base(self); + let self_base = self.mut_base(); if self_base.flags.float_kind() != Float::None && self_base.restyle_damage.intersects(ServoRestyleDamage::REFLOW) { special_damage.insert(SpecialRestyleDamage::REFLOW_ENTIRE_DOCUMENT); @@ -76,7 +76,7 @@ impl<'a> LayoutDamageComputation for &'a mut Flow { } fn reflow_entire_document(self) { - let self_base = flow::mut_base(self); + let self_base = self.mut_base(); self_base.restyle_damage.insert(RestyleDamage::rebuild_and_reflow()); self_base.restyle_damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); for kid in self_base.children.iter_mut() { diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 9d4bfbc7ae4..b52b2f7fe45 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -12,8 +12,8 @@ use display_list_builder::{DisplayListBuildState, InlineFlowDisplayListBuilding} use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Size2D}; use floats::{FloatKind, Floats, PlacementInfo}; -use flow::{self, BaseFlow, Flow, FlowClass, ForceNonfloatedFlag}; -use flow::{FlowFlags, EarlyAbsolutePositionInfo, OpaqueFlow}; +use flow::{BaseFlow, Flow, FlowClass, ForceNonfloatedFlag}; +use flow::{FlowFlags, EarlyAbsolutePositionInfo, GetBaseFlow, OpaqueFlow}; use flow_ref::FlowRef; use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; use fragment::FragmentFlags; @@ -1315,7 +1315,7 @@ impl Flow for InlineFlow { let writing_mode = self.base.writing_mode; for kid in self.base.child_iter_mut() { - flow::mut_base(kid).floats = Floats::new(writing_mode); + kid.mut_base().floats = Floats::new(writing_mode); } self.base.flags.remove(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); @@ -1423,7 +1423,7 @@ impl Flow for InlineFlow { // sizes down to them. let block_container_explicit_block_size = self.base.block_container_explicit_block_size; for kid in self.base.child_iter_mut() { - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); kid_base.block_container_inline_size = inline_size; kid_base.block_container_writing_mode = container_mode; @@ -1524,14 +1524,14 @@ impl Flow for InlineFlow { match f.specific { SpecificFragmentInfo::InlineBlock(ref mut info) => { let block = FlowRef::deref_mut(&mut info.flow_ref); - flow::mut_base(block).early_absolute_position_info = EarlyAbsolutePositionInfo { + block.mut_base().early_absolute_position_info = EarlyAbsolutePositionInfo { relative_containing_block_size: containing_block_size, relative_containing_block_mode: writing_mode, }; } SpecificFragmentInfo::InlineAbsolute(ref mut info) => { let block = FlowRef::deref_mut(&mut info.flow_ref); - flow::mut_base(block).early_absolute_position_info = EarlyAbsolutePositionInfo { + block.mut_base().early_absolute_position_info = EarlyAbsolutePositionInfo { relative_containing_block_size: containing_block_size, relative_containing_block_mode: writing_mode, }; @@ -1757,7 +1757,7 @@ impl fmt::Debug for InlineFlow { "{:?}({:x}) {:?}", self.class(), self.base.debug_id(), - flow::base(self)) + self.base()) } } diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index 1c9869c2165..466399ca8f0 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -5,7 +5,7 @@ //! Supports writing a trace file created during each layout scope //! that can be viewed by an external tool to make layout debugging easier. -use flow; +use flow::GetBaseFlow; use flow_ref::FlowRef; use serde_json::{to_string, to_value, Value}; use std::borrow::ToOwned; @@ -63,7 +63,7 @@ impl Scope { pub fn new(name: String) -> Scope { STATE_KEY.with(|ref r| { if let Some(ref mut state) = *r.borrow_mut() { - let flow_trace = to_value(&flow::base(&*state.flow_root)).unwrap(); + let flow_trace = to_value(&state.flow_root.base()).unwrap(); let data = Box::new(ScopeData::new(name.clone(), flow_trace)); state.scope_stack.push(data); } @@ -78,7 +78,7 @@ impl Drop for Scope { STATE_KEY.with(|ref r| { if let Some(ref mut state) = *r.borrow_mut() { let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = to_value(&flow::base(&*state.flow_root)).unwrap(); + current_scope.post = to_value(&state.flow_root.base()).unwrap(); let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope); } @@ -100,7 +100,7 @@ pub fn begin_trace(flow_root: FlowRef) { assert!(STATE_KEY.with(|ref r| r.borrow().is_none())); STATE_KEY.with(|ref r| { - let flow_trace = to_value(&flow::base(&*flow_root)).unwrap(); + let flow_trace = to_value(&flow_root.base()).unwrap(); let state = State { scope_stack: vec![Box::new(ScopeData::new("root".to_owned(), flow_trace))], flow_root: flow_root.clone(), @@ -116,7 +116,7 @@ pub fn end_trace(generation: u32) { let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap()); assert!(thread_state.scope_stack.len() == 1); let mut root_scope = thread_state.scope_stack.pop().unwrap(); - root_scope.post = to_value(&flow::base(&*thread_state.flow_root)).unwrap(); + root_scope.post = to_value(&thread_state.flow_root.base()).unwrap(); let result = to_string(&root_scope).unwrap(); let mut file = File::create(format!("layout_trace-{}.json", generation)).unwrap(); diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 7b811e38772..327c475fefe 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -13,7 +13,7 @@ use context::LayoutContext; use display_list_builder::{DisplayListBuildState, StackingContextCollectionState}; use euclid::{Point2D, Vector2D}; use floats::FloatKind; -use flow::{Flow, FlowClass, OpaqueFlow, mut_base, FragmentationContext}; +use flow::{Flow, FlowClass, OpaqueFlow, FragmentationContext, GetBaseFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; use std::cmp::{min, max}; @@ -180,7 +180,7 @@ impl Flow for MulticolFlow { let pitch = LogicalSize::new(self.block_flow.base.writing_mode, self.column_pitch, Au(0)); let pitch = pitch.to_physical(self.block_flow.base.writing_mode); for (i, child) in self.block_flow.base.children.iter_mut().enumerate() { - let point = &mut mut_base(child).stacking_relative_position; + let point = &mut child.mut_base().stacking_relative_position; *point = *point + Vector2D::new(pitch.width * i as i32, pitch.height * i as i32); } } diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index 3793ad648a6..b555a9f51dc 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -10,7 +10,7 @@ use block::BlockFlow; use context::LayoutContext; -use flow::{self, Flow}; +use flow::{Flow, GetBaseFlow}; use flow_ref::FlowRef; use profile_traits::time::{self, TimerMetadata, profile}; use rayon; @@ -84,7 +84,7 @@ fn bottom_up_flow(mut unsafe_flow: UnsafeFlow, } - let base = flow::mut_base(flow); + let base = flow.mut_base(); // Reset the count of children for the next layout traversal. base.parallel.children_count.store(base.children.len() as isize, @@ -103,7 +103,7 @@ fn bottom_up_flow(mut unsafe_flow: UnsafeFlow, let parent: &mut Flow = unsafe { &mut *(unsafe_parent.0 as *mut Flow) }; - let parent_base = flow::mut_base(parent); + let parent_base = parent.mut_base(); if parent_base.parallel.children_count.fetch_sub(1, Ordering::Relaxed) == 1 { // We were the last child of our parent. Reflow our parent. unsafe_flow = unsafe_parent @@ -127,7 +127,7 @@ fn top_down_flow<'scope>(unsafe_flows: &[UnsafeFlow], unsafe { // Get a real flow. let flow: &mut Flow = mem::transmute(*unsafe_flow); - flow::mut_base(flow).thread_id = + flow.mut_base().thread_id = pool.current_thread_index().unwrap() as u8; if assign_isize_traversal.should_process(flow) { @@ -136,7 +136,7 @@ fn top_down_flow<'scope>(unsafe_flows: &[UnsafeFlow], } // Possibly enqueue the children. - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { had_children = true; discovered_child_flows.push(UnsafeFlow(kid)); } diff --git a/components/layout/query.rs b/components/layout/query.rs index 2fb199f4e45..36e4a9b04d3 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -8,7 +8,7 @@ use app_units::Au; use construct::ConstructionResult; use context::LayoutContext; use euclid::{Point2D, Vector2D, Rect, Size2D}; -use flow::{self, Flow}; +use flow::{Flow, GetBaseFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo}; use gfx::display_list::{DisplayList, OpaqueNode, ScrollOffsetMap}; use inline::InlineFragmentNodeFlags; @@ -774,7 +774,7 @@ where let position = maybe_data.map_or(Point2D::zero(), |data| { match (*data).flow_construction_result { ConstructionResult::Flow(ref flow_ref, _) => - flow::base(flow_ref.deref()).stacking_relative_position.to_point(), + flow_ref.deref().base().stacking_relative_position.to_point(), // TODO(dzbarsky) search parents until we find node with a flow ref. // https://github.com/servo/servo/issues/8307 _ => Point2D::zero() diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index 57785fceee7..02f876c35ae 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -9,7 +9,7 @@ use context::LayoutContext; use display_list_builder::{DisplayListBuildState, StackingContextCollectionState}; use euclid::{Point2D, Vector2D}; use floats::SpeculatedFloatPlacement; -use flow::{self, Flow, ImmutableFlowUtils, FlowFlags}; +use flow::{Flow, ImmutableFlowUtils, FlowFlags, GetBaseFlow}; use fragment::{FragmentBorderBoxIterator, CoordinateSystem}; use generated_content::ResolveGeneratedContent; use incremental::RelayoutMode; @@ -31,7 +31,7 @@ pub fn reflow(root: &mut Flow, layout_context: &LayoutContext, relayout_mode: Re // Force reflow children during this traversal. This is needed when we failed // the float speculation of a block formatting context and need to fix it. if relayout_mode == RelayoutMode::Force { - flow::mut_base(flow) + flow.mut_base() .restyle_damage .insert(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } @@ -40,7 +40,7 @@ pub fn reflow(root: &mut Flow, layout_context: &LayoutContext, relayout_mode: Re assign_inline_sizes.process(flow); } - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { doit(kid, assign_inline_sizes, assign_block_sizes, relayout_mode); } @@ -87,11 +87,11 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut Flow, iterator stacking_context_position: &Point2D<Au>) { flow.iterate_through_fragment_border_boxes(iterator, level, stacking_context_position); - for kid in flow::mut_base(flow).child_iter_mut() { + for kid in flow.mut_base().child_iter_mut() { let mut stacking_context_position = *stacking_context_position; if kid.is_block_flow() && kid.as_block().fragment.establishes_stacking_context() { stacking_context_position = Point2D::new(kid.as_block().fragment.margin.inline_start, Au(0)) + - flow::base(kid).stacking_relative_position + + kid.base().stacking_relative_position + stacking_context_position.to_vector(); let relative_position = kid.as_block() .stacking_relative_border_box(CoordinateSystem::Own); @@ -112,17 +112,17 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut Flow, iterator } pub fn store_overflow(layout_context: &LayoutContext, flow: &mut Flow) { - if !flow::base(flow).restyle_damage.contains(ServoRestyleDamage::STORE_OVERFLOW) { + if !flow.base().restyle_damage.contains(ServoRestyleDamage::STORE_OVERFLOW) { return; } - for kid in flow::mut_base(flow).child_iter_mut() { + for kid in flow.mut_base().child_iter_mut() { store_overflow(layout_context, kid); } flow.store_overflow(layout_context); - flow::mut_base(flow) + flow.mut_base() .restyle_damage .remove(ServoRestyleDamage::STORE_OVERFLOW); } @@ -131,22 +131,22 @@ pub fn store_overflow(layout_context: &LayoutContext, flow: &mut Flow) { /// given flow. This is needed to speculatively calculate the inline sizes of block formatting /// contexts. The speculation typically succeeds, but if it doesn't we have to lay it out again. pub fn guess_float_placement(flow: &mut Flow) { - if !flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW) { + if !flow.base().restyle_damage.intersects(ServoRestyleDamage::REFLOW) { return; } let mut floats_in = SpeculatedFloatPlacement::compute_floats_in_for_first_child(flow); - for kid in flow::mut_base(flow).child_iter_mut() { - if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + for kid in flow.mut_base().child_iter_mut() { + if kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Do not propagate floats in or out, but do propogate between kids. guess_float_placement(kid); } else { floats_in.compute_floats_in(kid); - flow::mut_base(kid).speculated_float_placement_in = floats_in; + kid.mut_base().speculated_float_placement_in = floats_in; guess_float_placement(kid); - floats_in = flow::base(kid).speculated_float_placement_out; + floats_in = kid.base().speculated_float_placement_out; } } floats_in.compute_floats_out(flow); - flow::mut_base(flow).speculated_float_placement_out = floats_in + flow.mut_base().speculated_float_placement_out = floats_in } diff --git a/components/layout/table.rs b/components/layout/table.rs index 37e92be32be..512db136b0c 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -13,8 +13,7 @@ use context::LayoutContext; use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags, StackingContextCollectionState}; use euclid::Point2D; -use flow; -use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow}; +use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, GetBaseFlow, OpaqueFlow}; use flow_list::MutFlowListIterator; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; @@ -752,12 +751,12 @@ impl TableLikeFlow for BlockFlow { } // At this point, `current_block_offset` is at the border edge of the child. - flow::mut_base(kid).position.start.b = current_block_offset; + kid.mut_base().position.start.b = current_block_offset; // Move past the child's border box. Do not use the `translate_including_floats` // function here because the child has already translated floats past its border // box. - let kid_base = flow::mut_base(kid); + let kid_base = kid.mut_base(); current_block_offset = current_block_offset + kid_base.position.size.block; } @@ -796,7 +795,7 @@ impl TableLikeFlow for BlockFlow { // Write in the size of the relative containing block for children. (This information // is also needed to handle RTL.) for kid in self.base.child_iter_mut() { - flow::mut_base(kid).early_absolute_position_info = EarlyAbsolutePositionInfo { + kid.mut_base().early_absolute_position_info = EarlyAbsolutePositionInfo { relative_containing_block_size: self.fragment.content_box().size, relative_containing_block_mode: self.fragment.style().writing_mode, }; @@ -856,7 +855,7 @@ impl<'a> Iterator for TableRowIterator<'a> { match self.kids.next() { Some(kid) => { if kid.is_table_rowgroup() { - self.grandkids = Some(flow::mut_base(kid).child_iter_mut()); + self.grandkids = Some(kid.mut_base().child_iter_mut()); self.next() } else if kid.is_table_row() { Some(kid.as_mut_table_row()) diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index cbde1a2be83..81f9e32661a 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -13,7 +13,7 @@ use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags}; use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Rect, SideOffsets2D, Size2D}; -use flow::{self, Flow, FlowClass, FlowFlags, OpaqueFlow}; +use flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; use layout_debug; @@ -101,8 +101,8 @@ impl TableCellFlow { // Note to the reader: this code has been tested with negative margins. // We end up with a "end" that's before the "start," but the math still works out. let mut extents = None; - for kid in flow::base(self).children.iter() { - let kid_base = flow::base(kid); + for kid in self.base().children.iter() { + let kid_base = kid.base(); if kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { continue } @@ -128,7 +128,7 @@ impl TableCellFlow { }; let kids_size = last_end - first_start; - let self_size = flow::base(self).position.size.block - + let self_size = self.base().position.size.block - self.block_flow.fragment.border_padding.block_start_end(); let kids_self_gap = self_size - kids_size; @@ -143,8 +143,8 @@ impl TableCellFlow { return } - for kid in flow::mut_base(self).children.iter_mut() { - let kid_base = flow::mut_base(kid); + for kid in self.mut_base().children.iter_mut() { + let kid_base = kid.mut_base(); if !kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { kid_base.position.start.b += offset } diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 8135e9b51a2..6f2212176f7 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -13,7 +13,7 @@ use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags}; use display_list_builder::StackingContextCollectionState; use euclid::Point2D; -use flow::{self, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow}; +use flow::{EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, GetBaseFlow, OpaqueFlow}; use flow_list::MutFlowListIterator; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; @@ -126,7 +126,7 @@ impl TableRowFlow { - self.block_flow.fragment.margin; for kid in self.block_flow.base.child_iter_mut() { kid.place_float_if_applicable(); - if !flow::base(kid).flags.is_float() { + if !kid.base().flags.is_float() { kid.assign_block_size_for_inorder_child_if_necessary(layout_context, thread_id, content_box); @@ -143,7 +143,7 @@ impl TableRowFlow { child_specified_block_size + child_fragment.border_padding.block_start_end()); } - let child_node = flow::mut_base(kid); + let child_node = kid.mut_base(); child_node.position.start.b = Au(0); max_block_size = max(max_block_size, child_node.position.size.block); } @@ -301,7 +301,7 @@ impl Flow for TableRowFlow { // Collect minimum and preferred inline-sizes of the cell for automatic table layout // calculation. - let child_base = flow::mut_base(kid); + let child_base = kid.mut_base(); let child_column_inline_size = ColumnIntrinsicInlineSize { minimum_length: match child_specified_inline_size { LengthOrPercentageOrAuto::Auto | diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index b69d6926816..8dac0180171 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -7,7 +7,7 @@ use construct::FlowConstructor; use context::LayoutContext; use display_list_builder::DisplayListBuildState; -use flow::{self, FlowFlags, Flow, ImmutableFlowUtils}; +use flow::{FlowFlags, Flow, GetBaseFlow, ImmutableFlowUtils}; use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use servo_config::opts; use style::context::{SharedStyleContext, StyleContext}; @@ -110,7 +110,7 @@ pub trait PreorderFlowTraversal { if self.should_process(flow) { self.process(flow); } - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { self.traverse(kid); } } @@ -125,7 +125,7 @@ pub trait PreorderFlowTraversal { if self.should_process(flow) { self.process(flow); } - for descendant_link in flow::mut_base(flow).abs_descendants.iter() { + for descendant_link in flow.mut_base().abs_descendants.iter() { self.traverse_absolute_flows(descendant_link) } } @@ -145,7 +145,7 @@ pub trait PostorderFlowTraversal { /// Traverses the tree in postorder. fn traverse(&self, flow: &mut Flow) { - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { self.traverse(kid); } if self.should_process(flow) { @@ -171,7 +171,7 @@ pub trait InorderFlowTraversal { return; } self.process(flow, level); - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { self.traverse(kid, level + 1); } } @@ -226,12 +226,12 @@ impl<'a> PostorderFlowTraversal for BubbleISizes<'a> { #[inline] fn process(&self, flow: &mut Flow) { flow.bubble_inline_sizes(); - flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); + flow.mut_base().restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); } #[inline] fn should_process(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.contains(ServoRestyleDamage::BUBBLE_ISIZES) + flow.base().restyle_damage.contains(ServoRestyleDamage::BUBBLE_ISIZES) } } @@ -249,7 +249,7 @@ impl<'a> PreorderFlowTraversal for AssignISizes<'a> { #[inline] fn should_process(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) + flow.base().restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) } } @@ -278,7 +278,7 @@ impl<'a> PostorderFlowTraversal for AssignBSizes<'a> { #[inline] fn should_process(&self, flow: &mut Flow) -> bool { - let base = flow::base(flow); + let base = flow.base(); base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) && // The fragmentation countainer is responsible for calling Flow::fragment recursively !base.flags.contains(FlowFlags::CAN_BE_FRAGMENTED) @@ -292,13 +292,13 @@ pub struct ComputeStackingRelativePositions<'a> { impl<'a> PreorderFlowTraversal for ComputeStackingRelativePositions<'a> { #[inline] fn should_process_subtree(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.contains(ServoRestyleDamage::REPOSITION) + flow.base().restyle_damage.contains(ServoRestyleDamage::REPOSITION) } #[inline] fn process(&self, flow: &mut Flow) { flow.compute_stacking_relative_position(self.layout_context); - flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::REPOSITION) + flow.mut_base().restyle_damage.remove(ServoRestyleDamage::REPOSITION) } } @@ -310,15 +310,15 @@ impl<'a> BuildDisplayList<'a> { #[inline] pub fn traverse(&mut self, flow: &mut Flow) { let parent_stacking_context_id = self.state.current_stacking_context_id; - self.state.current_stacking_context_id = flow::base(flow).stacking_context_id; + self.state.current_stacking_context_id = flow.base().stacking_context_id; let parent_clipping_and_scrolling = self.state.current_clipping_and_scrolling; self.state.current_clipping_and_scrolling = flow.clipping_and_scrolling(); flow.build_display_list(&mut self.state); - flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::REPAINT); + flow.mut_base().restyle_damage.remove(ServoRestyleDamage::REPAINT); - for kid in flow::child_iter_mut(flow) { + for kid in flow.mut_base().child_iter_mut() { self.traverse(kid); } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 6ed68abcb80..8401305036f 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -70,7 +70,7 @@ use layout::context::RegisteredPainter; use layout::context::RegisteredPainters; use layout::context::malloc_size_of_persistent_local_context; use layout::display_list_builder::ToGfxColor; -use layout::flow::{self, Flow, ImmutableFlowUtils, MutableOwnedFlowUtils}; +use layout::flow::{Flow, GetBaseFlow, ImmutableFlowUtils, MutableOwnedFlowUtils}; use layout::flow_ref::FlowRef; use layout::incremental::{LayoutDamageComputation, RelayoutMode, SpecialRestyleDamage}; use layout::layout_debug; @@ -956,22 +956,22 @@ impl LayoutThread { layout_root: &mut Flow, layout_context: &mut LayoutContext, rw_data: &mut LayoutThreadData) { - let writing_mode = flow::base(layout_root).writing_mode; + let writing_mode = layout_root.base().writing_mode; let (metadata, sender) = (self.profiler_metadata(), self.time_profiler_chan.clone()); profile(time::ProfilerCategory::LayoutDispListBuild, metadata.clone(), sender.clone(), || { - flow::mut_base(layout_root).stacking_relative_position = + layout_root.mut_base().stacking_relative_position = LogicalPoint::zero(writing_mode).to_physical(writing_mode, self.viewport_size).to_vector(); - flow::mut_base(layout_root).clip = data.page_clip_rect; + layout_root.mut_base().clip = data.page_clip_rect; let traversal = ComputeStackingRelativePositions { layout_context: layout_context }; traversal.traverse(layout_root); - if flow::base(layout_root).restyle_damage.contains(ServoRestyleDamage::REPAINT) || + if layout_root.base().restyle_damage.contains(ServoRestyleDamage::REPAINT) || rw_data.display_list.is_none() { if reflow_goal.needs_display_list() { let mut build_state = @@ -980,7 +980,7 @@ impl LayoutThread { debug!("Done building display list."); let root_size = { - let root_flow = flow::base(layout_root); + let root_flow = layout_root.base(); if self.stylist.viewport_constraints().is_some() { root_flow.position.size.to_physical(root_flow.writing_mode) } else { @@ -1564,7 +1564,7 @@ impl LayoutThread { // Perform the primary layout passes over the flow tree to compute the locations of all // the boxes. - if flow::base(&**root_flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW | + if root_flow.base().restyle_damage.intersects(ServoRestyleDamage::REFLOW | ServoRestyleDamage::REFLOW_OUT_OF_FLOW) { profile(time::ProfilerCategory::LayoutMain, self.profiler_metadata(), @@ -1630,12 +1630,12 @@ impl LayoutThread { fn reflow_all_nodes(flow: &mut Flow) { debug!("reflowing all nodes!"); - flow::mut_base(flow) + flow.mut_base() .restyle_damage .insert(ServoRestyleDamage::REPAINT | ServoRestyleDamage::STORE_OVERFLOW | ServoRestyleDamage::REFLOW | ServoRestyleDamage::REPOSITION); - for child in flow::child_iter_mut(flow) { + for child in flow.mut_base().child_iter_mut() { LayoutThread::reflow_all_nodes(child); } } |