From 511d2b11d4ba0cd11409ef96ae4354cc28ea462c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 11 Dec 2013 17:46:36 -0800 Subject: [PATCH] layout: If the border style is "none", treat its width as 0. Closes #1383. --- src/components/main/layout/block.rs | 20 ++++----- src/components/main/layout/box.rs | 54 ++++++++++++++++++----- src/components/main/layout/layout_task.rs | 6 +-- src/test/ref/basic.list | 1 + src/test/ref/border_style_none_a.html | 20 +++++++++ src/test/ref/border_style_none_b.html | 19 ++++++++ 6 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 src/test/ref/border_style_none_a.html create mode 100644 src/test/ref/border_style_none_b.html diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index f32d1ebff38..61cfcfac313 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -763,17 +763,17 @@ impl Flow for BlockFlow { } fn debug_str(&self) -> ~str { - if self.is_root { - ~"BlockFlow(root)" + let txt = if self.is_float() { + ~"FloatFlow: " + } else if self.is_root { + ~"RootFlow: " } else { - let txt = if self.is_float() { ~"FloatFlow: " } else { ~"BlockFlow: " }; - txt.append(match self.box { - Some(ref rb) => { - rb.debug_str() - } - None => { ~"" } - }) - } + ~"BlockFlow: " + }; + txt.append(match self.box { + Some(ref rb) => rb.debug_str(), + None => ~"", + }) } } diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 47797a5a4da..0280b646e58 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -281,10 +281,23 @@ impl Box { /// /// FIXME(pcwalton): This should not be necessary. Just go to the style. pub fn compute_borders(&self, style: &ComputedValues) { - self.border.set(SideOffsets2D::new(style.Border.border_top_width, - style.Border.border_right_width, - style.Border.border_bottom_width, - style.Border.border_left_width)) + #[inline] + fn width(width: Au, style: border_style::T) -> Au { + if style == border_style::none { + Au(0) + } else { + width + } + } + + self.border.set(SideOffsets2D::new(width(style.Border.border_top_width, + style.Border.border_top_style), + width(style.Border.border_right_width, + style.Border.border_right_style), + width(style.Border.border_bottom_width, + style.Border.border_bottom_style), + width(style.Border.border_left_width, + style.Border.border_left_style))) } /// Populates the box model padding parameters from the given computed style. @@ -983,12 +996,33 @@ impl Box { /// Returns a debugging string describing this box. pub fn debug_str(&self) -> ~str { - match self.specific { - GenericBox => "(GenericBox)", - ImageBox(_) => "(ImageBox)", - ScannedTextBox(_) => "(ScannedTextBox)", - UnscannedTextBox(_) => "(UnscannedTextBox)", - }.to_str() + let class_name = match self.specific { + GenericBox => "GenericBox", + ImageBox(_) => "ImageBox", + ScannedTextBox(_) => "ScannedTextBox", + UnscannedTextBox(_) => "UnscannedTextBox", + }; + + format!("({}{}{}{})", + class_name, + self.side_offsets_debug_string("b", self.border.get()), + self.side_offsets_debug_string("p", self.padding.get()), + self.side_offsets_debug_string("m", self.margin.get())) } + + /// A helper function to return a debug string describing the side offsets for one of the rect + /// box model properties (border, padding, or margin). + fn side_offsets_debug_string(&self, name: &str, value: SideOffsets2D) -> ~str { + let zero: SideOffsets2D = Zero::zero(); + if value == zero { + return "".to_str() + } + format!(" {}{},{},{},{}", + name, + *value.top, + *value.right, + *value.bottom, + *value.left) + } } diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index fdface606fd..0ccdcfd5db0 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -448,15 +448,15 @@ impl LayoutTask { }); layout_root.traverse_postorder(&mut ComputeDamageTraversal.clone()); - debug!("layout: constructed Flow tree"); - debug!("{:?}", layout_root.dump()); - // Perform the primary layout passes over the flow tree to compute the locations of all // the boxes. do profile(time::LayoutMainCategory, self.profiler_chan.clone()) { self.solve_constraints(layout_root, &mut layout_ctx) } + debug!("layout: constraint solving done:"); + debug!("{:?}", layout_root.dump()); + // Build the display list if necessary, and send it to the renderer. if data.goal == ReflowForDisplay { do profile(time::LayoutDispListBuildCategory, self.profiler_chan.clone()) { diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list index bad42e54c30..613d832fa08 100644 --- a/src/test/ref/basic.list +++ b/src/test/ref/basic.list @@ -15,3 +15,4 @@ == visibility_hidden.html visibility_hidden_ref.html == root_height_a.html root_height_b.html == png_rgba_colorspace_a.html png_rgba_colorspace_b.html +== border_style_none_a.html border_style_none_b.html diff --git a/src/test/ref/border_style_none_a.html b/src/test/ref/border_style_none_a.html new file mode 100644 index 00000000000..d0389a8b803 --- /dev/null +++ b/src/test/ref/border_style_none_a.html @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/src/test/ref/border_style_none_b.html b/src/test/ref/border_style_none_b.html new file mode 100644 index 00000000000..185dc03cd89 --- /dev/null +++ b/src/test/ref/border_style_none_b.html @@ -0,0 +1,19 @@ + + + + + + + +