diff --git a/components/layout/block.rs b/components/layout/block.rs index 5f89cf7f825..f3ec9e0f373 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1842,15 +1842,7 @@ impl Flow for BlockFlow { impl fmt::Show for BlockFlow { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "BlockFlow")); - if self.is_float() { - try!(write!(f, "(Float)")); - } else if self.is_root() { - try!(write!(f, "(Root)")); - } else if self.is_absolutely_positioned() { - try!(write!(f, "(Absolute)")); - } - write!(f, ": {} ({})", self.fragment, self.base) + write!(f, "{} - {:x}: frag={} ({})", self.class(), self.base.debug_id(), self.fragment, self.base) } } @@ -2010,6 +2002,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; } diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 3698fe65974..49a182d54aa 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -299,10 +299,6 @@ pub trait Flow: fmt::Show + ToString + Sync { LayerId(pointer, fragment_id) } } - - fn debug_print(&self) -> String { - format!("{} - {:x}", self.class(), base(self).debug_id()) - } } impl<'a, E, S: Encoder> Encodable for &'a Flow + 'a { @@ -1025,7 +1021,9 @@ impl<'a> ImmutableFlowUtils for &'a Flow + 'a { for _ in range(0, level) { indent.push_str("| ") } - debug!("{}+ {}", indent, self.debug_print()); + + error!("{}+ {}", indent, self.to_string()); + for kid in imm_child_iter(self) { kid.dump_with_level(level + 1) } @@ -1222,7 +1220,6 @@ impl<'a> MutableFlowUtils for &'a mut Flow + 'a { doit(self, RestyleDamage::empty(), &mut DirtyFloats { left: false, right: false }); } - fn nonincremental_reset(self) { fn reset_flow(flow: &mut Flow) { let base = mut_base(flow); diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index e3d63e348e6..56b14754ca6 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -379,15 +379,19 @@ pub struct ScannedTextFragmentInfo { /// The new_line_pos is eaten during line breaking. If we need to re-merge /// fragments, it will have to be restored. pub original_new_line_pos: Option>, + + /// The inline-size of the text fragment. + pub content_inline_size: Au, } impl ScannedTextFragmentInfo { /// Creates the information specific to a scanned text fragment from a range and a text run. - pub fn new(run: Arc>, range: Range) -> ScannedTextFragmentInfo { + pub fn new(run: Arc>, range: Range, content_inline_size: Au) -> ScannedTextFragmentInfo { ScannedTextFragmentInfo { run: run, range: range, original_new_line_pos: None, + content_inline_size: content_inline_size, } } } @@ -552,6 +556,11 @@ impl Fragment { } } + pub fn reset_inline_sizes(&mut self) { + self.border_padding = LogicalMargin::zero(self.style.writing_mode); + self.margin = LogicalMargin::zero(self.style.writing_mode); + } + /// Saves the new_line_pos vector into a `ScannedTextFragment`. This will fail /// if called on any other type of fragment. pub fn save_new_line_pos(&mut self) { @@ -584,22 +593,22 @@ impl Fragment { self.debug_id } - pub fn debug_show(&self) -> String { - format!("{:x} {}", self.debug_id(), self.specific.get_type()) - } - /// Transforms this fragment into another fragment of the given type, with the given size, preserving all /// the other data. - pub fn transform(&self, size: LogicalSize, specific: SpecificFragmentInfo) -> Fragment { + pub fn transform(&self, size: LogicalSize, mut info: ScannedTextFragmentInfo) -> Fragment { + let new_border_box = + LogicalRect::from_point_size(self.style.writing_mode, self.border_box.start, size); + + info.content_inline_size = size.inline; + Fragment { node: self.node, style: self.style.clone(), restyle_damage: RestyleDamage::all(), - border_box: LogicalRect::from_point_size( - self.style.writing_mode, self.border_box.start, size), + border_box: new_border_box, border_padding: self.border_padding, margin: self.margin, - specific: specific, + specific: ScannedTextFragment(info), new_line_pos: self.new_line_pos.clone(), inline_context: self.inline_context.clone(), debug_id: self.debug_id, @@ -1689,10 +1698,10 @@ impl Fragment { block_flow.base.intrinsic_inline_sizes.preferred_inline_size; block_flow.base.block_container_inline_size = self.border_box.size.inline; } - ScannedTextFragment(_) => { + ScannedTextFragment(ref info) => { // Scanned text fragments will have already had their content inline-sizes assigned // by this point. - self.border_box.size.inline = self.border_box.size.inline + noncontent_inline_size + self.border_box.size.inline = info.content_inline_size + noncontent_inline_size } ImageFragment(ref mut image_fragment_info) => { // TODO(ksh8281): compute border,margin @@ -1964,24 +1973,8 @@ impl Fragment { } impl fmt::Show for Fragment { - /// Outputs a debugging string describing this fragment. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "({} ", - match self.specific { - GenericFragment => "GenericFragment", - IframeFragment(_) => "IframeFragment", - ImageFragment(_) => "ImageFragment", - InlineAbsoluteHypotheticalFragment(_) => "InlineAbsoluteHypotheticalFragment", - InlineBlockFragment(_) => "InlineBlockFragment", - InputFragment => "InputFragment", - ScannedTextFragment(_) => "ScannedTextFragment", - TableFragment => "TableFragment", - TableCellFragment => "TableCellFragment", - TableColumnFragment(_) => "TableColumnFragment", - TableRowFragment => "TableRowFragment", - TableWrapperFragment => "TableWrapperFragment", - UnscannedTextFragment(_) => "UnscannedTextFragment", - })); + try!(write!(f, "({} {} ", self.debug_id(), self.specific.get_type())); try!(write!(f, "bp {}", self.border_padding)); try!(write!(f, " ")); try!(write!(f, "m {}", self.margin)); diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 4625a0dd9df..0babaa46234 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -405,11 +405,14 @@ impl LineBreaker { let writing_mode = self.floats.writing_mode; let split_fragment = |split: SplitInfo| { - let info = ScannedTextFragmentInfo::new(run.clone(), split.range); - let specific = ScannedTextFragment(info); + let info = + ScannedTextFragmentInfo::new( + run.clone(), + split.range, + in_fragment.border_box.size.inline); let size = LogicalSize::new( writing_mode, split.inline_size, in_fragment.border_box.size.block); - in_fragment.transform(size, specific) + in_fragment.transform(size, info) }; debug!("LineBreaker: Pushing the fragment to the inline_start of the new-line character \ @@ -493,12 +496,15 @@ impl LineBreaker { line_is_empty); match split.map(|(inline_start, inline_end, run)| { let split_fragment = |split: SplitInfo| { - let info = ScannedTextFragmentInfo::new(run.clone(), split.range); - let specific = ScannedTextFragment(info); + let info = + ScannedTextFragmentInfo::new( + run.clone(), + split.range, + in_fragment.border_box.size.inline); let size = LogicalSize::new(self.floats.writing_mode, split.inline_size, in_fragment.border_box.size.block); - in_fragment.transform(size, specific) + in_fragment.transform(size, info) }; (inline_start.map(|x| { @@ -568,6 +574,13 @@ pub struct InlineFragments { pub fragments: Vec, } +impl fmt::Show for InlineFragments { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.fragments) + } +} + + impl InlineFragments { /// Creates an empty set of inline fragments. pub fn new() -> InlineFragments { @@ -576,26 +589,6 @@ impl InlineFragments { } } - pub fn debug_show(&self) -> String { - let mut ret = String::new(); - ret.push_str("[ "); - for (i, fragment) in self.fragments.iter().enumerate() { - if i != 0 { - ret.push_str(", "); - } - - ret.push_str(fragment.debug_show().as_slice()); - } - - if self.is_empty() { - ret.push_str("]"); - } else { - ret.push_str(" ]"); - } - - ret - } - /// Returns the number of inline fragments. pub fn len(&self) -> uint { self.fragments.len() @@ -998,10 +991,6 @@ impl Flow for InlineFlow { InlineFlowClass } - fn debug_print(&self) -> String { - format!("{} - {:x} - {}", self.class(), self.base.debug_id(), self.fragments.debug_show()) - } - fn as_immutable_inline<'a>(&'a self) -> &'a InlineFlow { self } @@ -1268,15 +1257,7 @@ impl Flow for InlineFlow { impl fmt::Show for InlineFlow { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "InlineFlow")); - for (i, fragment) in self.fragments.fragments.iter().enumerate() { - if i == 0 { - try!(write!(f, ": {}", fragment)) - } else { - try!(write!(f, ", {}", fragment)) - } - } - write!(f, " ({})", self.base) + write!(f, "{} - {:x} - {}", self.class(), self.base.debug_id(), self.fragments) } } diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 31c3b99094e..60b2a53938a 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -676,6 +676,10 @@ impl LayoutTask { } }); + if self.opts.dump_flow_tree { + layout_root.dump(); + } + // Build the display list if necessary, and send it to the renderer. if data.goal == ReflowForDisplay { let writing_mode = flow::base(layout_root.deref()).writing_mode; diff --git a/components/layout/text.rs b/components/layout/text.rs index be79be0c06d..19338d4c021 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -7,7 +7,7 @@ #![deny(unsafe_block)] use flow::Flow; -use fragment::{Fragment, ScannedTextFragment, ScannedTextFragmentInfo, UnscannedTextFragment}; +use fragment::{Fragment, ScannedTextFragmentInfo, UnscannedTextFragment}; use gfx::font::{FontMetrics,RunMetrics}; use gfx::font_context::FontContext; @@ -154,9 +154,9 @@ impl TextRunScanner { let new_metrics = run.metrics_for_range(&range); let bounding_box_size = bounding_box_for_run_metrics( &new_metrics, old_fragment.style.writing_mode); - let new_text_fragment_info = ScannedTextFragmentInfo::new(Arc::new(run), range); - let mut new_fragment = old_fragment.transform( - bounding_box_size, ScannedTextFragment(new_text_fragment_info)); + let new_text_fragment_info = + ScannedTextFragmentInfo::new(Arc::new(run), range, old_fragment.border_box.size.inline); + let mut new_fragment = old_fragment.transform(bounding_box_size, new_text_fragment_info); new_fragment.new_line_pos = new_line_pos; out_fragments.push(new_fragment) } @@ -235,13 +235,16 @@ impl TextRunScanner { continue } - let new_text_fragment_info = ScannedTextFragmentInfo::new(run.as_ref().unwrap().clone(), range); let old_fragment = &in_fragments[i.to_uint()]; + let new_text_fragment_info = + ScannedTextFragmentInfo::new( + run.as_ref().unwrap().clone(), + range, + old_fragment.border_box.size.inline); let new_metrics = new_text_fragment_info.run.metrics_for_range(&range); let bounding_box_size = bounding_box_for_run_metrics( &new_metrics, old_fragment.style.writing_mode); - let mut new_fragment = old_fragment.transform( - bounding_box_size, ScannedTextFragment(new_text_fragment_info)); + let mut new_fragment = old_fragment.transform(bounding_box_size, new_text_fragment_info); new_fragment.new_line_pos = new_line_positions[logical_offset.to_uint()].new_line_pos.clone(); out_fragments.push(new_fragment) }