auto merge of #2336 : bjz/servo/debug_str, r=pcwalton

This commit is contained in:
bors-servo 2014-05-06 23:37:35 -04:00
commit 38bf7fd098
13 changed files with 134 additions and 109 deletions

View file

@ -26,6 +26,7 @@ use libc::uintptr_t;
use servo_net::image::base::Image;
use servo_util::geometry::Au;
use servo_util::range::Range;
use std::fmt;
use std::mem;
use std::slice::Items;
use style::computed_values::border_style;
@ -633,23 +634,27 @@ impl DisplayItem {
for _ in range(0, level) {
indent.push_str("| ")
}
debug!("{}+ {}", indent, self.debug_str());
debug!("{}+ {}", indent, self);
for child in self.children() {
child.debug_with_level(level + 1);
}
}
pub fn debug_str(&self) -> ~str {
let class = match *self {
SolidColorDisplayItemClass(_) => "SolidColor",
TextDisplayItemClass(_) => "Text",
ImageDisplayItemClass(_) => "Image",
BorderDisplayItemClass(_) => "Border",
LineDisplayItemClass(_) => "Line",
ClipDisplayItemClass(_) => "Clip",
PseudoDisplayItemClass(_) => "Pseudo",
};
format!("{} @ {} ({:x})", class, self.base().bounds, self.base().node.id())
}
}
impl fmt::Show for DisplayItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "{} @ {} ({:x})",
match *self {
SolidColorDisplayItemClass(_) => "SolidColor",
TextDisplayItemClass(_) => "Text",
ImageDisplayItemClass(_) => "Image",
BorderDisplayItemClass(_) => "Border",
LineDisplayItemClass(_) => "Line",
ClipDisplayItemClass(_) => "Clip",
PseudoDisplayItemClass(_) => "Pseudo",
},
self.base().bounds,
self.base().node.id(),
)
}
}

View file

@ -38,6 +38,7 @@ use gfx::render_task::RenderLayer;
use servo_msg::compositor_msg::{FixedPosition, LayerId, Scrollable};
use servo_util::geometry::Au;
use servo_util::geometry;
use std::fmt;
use std::mem;
use std::num::Zero;
use style::computed_values::{LPA_Auto, LPA_Length, LPA_Percentage, LPN_Length, LPN_None};
@ -1690,22 +1691,23 @@ impl Flow for BlockFlow {
LayerId(self.box_.node.id(), fragment_index)
}
fn debug_str(&self) -> ~str {
let txt = if self.is_float() {
"FloatFlow: ".to_owned()
} else if self.is_root() {
"RootFlow: ".to_owned()
} else {
"BlockFlow: ".to_owned()
};
txt.append(self.box_.debug_str())
}
fn is_absolute_containing_block(&self) -> bool {
self.is_positioned()
}
}
impl fmt::Show for BlockFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.is_float() {
write!(f.buf, "FloatFlow: {}", self.box_)
} else if self.is_root() {
write!(f.buf, "RootFlow: {}", self.box_)
} else {
write!(f.buf, "BlockFlow: {}", self.box_)
}
}
}
/// The inputs for the widths-and-margins constraint equation.
pub struct WidthConstraintInput {
pub computed_width: MaybeAuto,

View file

@ -38,6 +38,7 @@ use servo_util::namespace;
use servo_util::smallvec::SmallVec;
use servo_util::str::is_whitespace;
use std::cast;
use std::fmt;
use std::from_str::FromStr;
use std::iter::AdditiveIterator;
use std::mem;
@ -838,10 +839,10 @@ impl Box {
// Box position wrt to the owning flow.
let box_bounds = self.border_box;
let absolute_box_bounds = box_bounds.translate(&flow_origin);
debug!("Box::build_display_list at rel={}, abs={}: {:s}",
debug!("Box::build_display_list at rel={}, abs={}: {}",
box_bounds,
absolute_box_bounds,
self.debug_str());
self);
debug!("Box::build_display_list: dirty={}, flow_origin={}",
layout_context.dirty,
flow_origin);
@ -1396,40 +1397,21 @@ impl Box {
self.style().Box.get().overflow == overflow::hidden
}
/// Returns a debugging string describing this box.
pub fn debug_str(&self) -> ~str {
let class_name = match self.specific {
GenericBox => "GenericBox",
IframeBox(_) => "IframeBox",
ImageBox(_) => "ImageBox",
ScannedTextBox(_) => "ScannedTextBox",
TableBox => "TableBox",
TableCellBox => "TableCellBox",
TableColumnBox(_) => "TableColumnBox",
TableRowBox => "TableRowBox",
TableWrapperBox => "TableWrapperBox",
UnscannedTextBox(_) => "UnscannedTextBox",
};
format!("({}{}{})",
class_name,
self.side_offsets_debug_string("bp", self.border_padding),
self.side_offsets_debug_string("m", self.margin))
}
/// 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<Au>) -> ~str {
let zero: SideOffsets2D<Au> = Zero::zero();
if value == zero {
return "".to_str()
}
format!(" {}{},{},{},{}",
fn side_offsets_debug_fmt(&self, name: &str,
value: SideOffsets2D<Au>,
f: &mut fmt::Formatter) -> fmt::Result {
if value.is_zero() {
Ok(())
} else {
write!(f.buf, "{}{},{},{},{}",
name,
value.top,
value.right,
value.bottom,
value.left)
}
}
/// Sends the size and position of this iframe box to the constellation. This is out of line to
@ -1456,6 +1438,29 @@ impl Box {
}
}
impl fmt::Show for Box {
/// Outputs a debugging string describing this box.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f.buf, "({} ",
match self.specific {
GenericBox => "GenericBox",
IframeBox(_) => "IframeBox",
ImageBox(_) => "ImageBox",
ScannedTextBox(_) => "ScannedTextBox",
TableBox => "TableBox",
TableCellBox => "TableCellBox",
TableColumnBox(_) => "TableColumnBox",
TableRowBox => "TableRowBox",
TableWrapperBox => "TableWrapperBox",
UnscannedTextBox(_) => "UnscannedTextBox",
}));
try!(self.side_offsets_debug_fmt("bp", self.border_padding, f));
try!(write!(f.buf, " "));
try!(self.side_offsets_debug_fmt("m", self.margin, f));
write!(f.buf, ")")
}
}
/// An object that accumulates display lists of child flows, applying a clipping rect if necessary.
pub struct ChildDisplayListAccumulator {
clip_display_item: Option<~ClipDisplayItem>,

View file

@ -55,6 +55,7 @@ use gfx::render_task::RenderLayer;
use servo_msg::compositor_msg::LayerId;
use servo_util::geometry::Au;
use std::cast;
use std::fmt;
use std::iter::Zip;
use std::num::Zero;
use std::sync::atomics::Relaxed;
@ -65,7 +66,7 @@ use style::computed_values::{clear, position, text_align};
///
/// Note that virtual methods have a cost; we should not overuse them in Servo. Consider adding
/// methods to `ImmutableFlowUtils` or `MutableFlowUtils` before adding more methods here.
pub trait Flow {
pub trait Flow: fmt::Show + ToStr {
// RTTI
//
// TODO(pcwalton): Use Rust's RTTI, once that works.
@ -267,11 +268,6 @@ pub trait Flow {
LayerId(pointer, fragment_id)
}
}
/// Returns a debugging string describing this flow.
fn debug_str(&self) -> ~str {
"???".to_owned()
}
}
// Base access
@ -915,7 +911,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow {
for _ in range(0, level) {
indent.push_str("| ")
}
debug!("{}+ {}", indent, self.debug_str());
debug!("{}+ {}", indent, self.to_str());
for kid in imm_child_iter(self) {
kid.dump_with_level(level + 1)
}

View file

@ -22,6 +22,7 @@ use servo_util::geometry::Au;
use servo_util::geometry;
use servo_util::range::Range;
use std::iter::Enumerate;
use std::fmt;
use std::mem;
use std::slice::{Items, MutItems};
use std::u16;
@ -235,8 +236,8 @@ impl LineboxScanner {
// try_append_to_line.
match first_box.split_to_width(line_bounds.size.width, line_is_empty) {
CannotSplit => {
error!("LineboxScanner: Tried to split unsplittable render box! {:s}",
first_box.debug_str());
error!("LineboxScanner: Tried to split unsplittable render box! {}",
first_box);
return (line_bounds, first_box_size.width);
}
SplitDidFit(left, right) => {
@ -356,11 +357,11 @@ impl LineboxScanner {
}
debug!("LineboxScanner: Trying to append box to line {:u} (box size: {}, green zone: \
{}): {:s}",
{}): {}",
self.lines.len(),
in_box.border_box.size,
self.pending_line.green_zone,
in_box.debug_str());
in_box);
let green_zone = self.pending_line.green_zone;
@ -400,8 +401,8 @@ impl LineboxScanner {
let split = in_box.split_to_width(available_width, line_is_empty);
let (left, right) = match (split, line_is_empty) {
(CannotSplit, _) => {
debug!("LineboxScanner: Tried to split unsplittable render box! {:s}",
in_box.debug_str());
debug!("LineboxScanner: Tried to split unsplittable render box! {}",
in_box);
self.work_list.push_front(in_box);
return false
}
@ -756,7 +757,7 @@ impl Flow for InlineFlow {
let mut intrinsic_widths = IntrinsicWidths::new();
for (fragment, context) in self.boxes.mut_iter() {
debug!("Flow: measuring {:s}", fragment.debug_str());
debug!("Flow: measuring {}", *fragment);
let box_intrinsic_widths = fragment.intrinsic_widths(Some(context));
intrinsic_widths.minimum_width = geometry::max(intrinsic_widths.minimum_width,
@ -954,16 +955,19 @@ impl Flow for InlineFlow {
self.base.floats = scanner.floats();
self.base.floats.translate(Point2D(Au::new(0), -self.base.position.size.height));
}
}
fn debug_str(&self) -> ~str {
let mut string = "InlineFlow: ".to_str();
impl fmt::Show for InlineFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f.buf, "InlineFlow"));
for (i, (fragment, _)) in self.boxes.iter().enumerate() {
if i != 0 {
string.push_str(", ")
if i == 0 {
try!(write!(f.buf, ": {}", fragment))
} else {
try!(write!(f.buf, ", {}", fragment))
}
string.push_str(fragment.debug_str())
}
string
Ok(())
}
}

View file

@ -16,6 +16,7 @@ use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use servo_util::geometry;
use std::fmt;
use style::computed_values::table_layout;
/// A table flow corresponded to the table's internal table box under a table wrapper flow.
@ -287,10 +288,12 @@ impl Flow for TableFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
}
fn debug_str(&self) -> ~str {
let txt = "TableFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
impl fmt::Show for TableFlow {
/// Outputs a debugging string describing this table flow.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "TableFlow: {}", self.block_flow)
}
}

View file

@ -10,6 +10,8 @@ use layout::context::LayoutContext;
use layout::flow::{TableCaptionFlowClass, FlowClass, Flow};
use layout::wrapper::ThreadSafeLayoutNode;
use std::fmt;
/// A table formatting context.
pub struct TableCaptionFlow {
pub block_flow: BlockFlow,
@ -60,9 +62,10 @@ impl Flow for TableCaptionFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
}
fn debug_str(&self) -> ~str {
let txt = "TableCaptionFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
impl fmt::Show for TableCaptionFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "TableCaptionFlow: {}", self.block_flow)
}
}

View file

@ -13,6 +13,7 @@ use layout::table::InternalTable;
use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use std::fmt;
/// A table formatting context.
pub struct TableCellFlow {
@ -109,10 +110,10 @@ impl Flow for TableCellFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
fn debug_str(&self) -> ~str {
let txt = "TableCellFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
}
}
impl fmt::Show for TableCellFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "TableCellFlow: {}", self.block_flow)
}
}

View file

@ -9,7 +9,9 @@ use layout::context::LayoutContext;
use layout::flow::{BaseFlow, TableColGroupFlowClass, FlowClass, Flow};
use layout::model::{MaybeAuto};
use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use std::fmt;
/// A table formatting context.
pub struct TableColGroupFlow {
@ -72,12 +74,13 @@ impl Flow for TableColGroupFlow {
/// Table column do not have height.
fn assign_height(&mut self, _ctx: &mut LayoutContext) {
}
}
fn debug_str(&self) -> ~str {
let txt = "TableColGroupFlow: ".to_owned();
txt.append(match self.box_ {
Some(ref rb) => rb.debug_str(),
None => "".to_owned(),
})
impl fmt::Show for TableColGroupFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.box_ {
Some(ref rb) => write!(f.buf, "TableColGroupFlow: {}", rb),
None => write!(f.buf, "TableColGroupFlow"),
}
}
}

View file

@ -17,6 +17,7 @@ use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use servo_util::geometry;
use std::fmt;
/// A table formatting context.
pub struct TableRowFlow {
@ -213,10 +214,10 @@ impl Flow for TableRowFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
fn debug_str(&self) -> ~str {
let txt = "TableRowFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
}
}
impl fmt::Show for TableRowFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "TableRowFlow: {}", self.block_flow.box_)
}
}

View file

@ -16,6 +16,7 @@ use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use servo_util::geometry;
use std::fmt;
/// A table formatting context.
pub struct TableRowGroupFlow {
@ -195,10 +196,10 @@ impl Flow for TableRowGroupFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
fn debug_str(&self) -> ~str {
let txt = "TableRowGroupFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
}
}
impl fmt::Show for TableRowGroupFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "TableRowGroupFlow: {}", self.block_flow.box_)
}
}

View file

@ -16,6 +16,7 @@ use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use servo_util::geometry;
use std::fmt;
use style::computed_values::table_layout;
pub enum TableLayout {
@ -188,14 +189,15 @@ impl Flow for TableWrapperFlow {
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
}
fn debug_str(&self) -> ~str {
let txt = if self.is_float() {
"TableWrapperFlow(Float): ".to_owned()
impl fmt::Show for TableWrapperFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.is_float() {
write!(f.buf, "TableWrapperFlow(Float): {}", self.block_flow.box_)
} else {
"TableWrapperFlow: ".to_owned()
};
txt.append(self.block_flow.box_.debug_str())
write!(f.buf, "TableWrapperFlow: {}", self.block_flow.box_)
}
}
}

View file

@ -237,8 +237,7 @@ impl TextRunScanner {
let range = new_ranges.get(logical_offset);
if range.length() == 0 {
debug!("Elided an `UnscannedTextbox` because it was zero-length after \
compression; {:s}",
in_boxes[i].debug_str());
compression; {}", in_boxes[i]);
continue
}