From 3474a2f9e135e1c1027d1023b97d51ab22772d80 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 11 Oct 2016 12:18:23 +0200 Subject: [PATCH] Add a custom Debug formatter for ClippingRegion This will make display list dumps more likely to fit on a single line. --- components/gfx/display_list/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 1b7195fa201e..be4aecd3a458 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -897,7 +897,7 @@ impl BaseDisplayItem { /// A clipping region for a display item. Currently, this can describe rectangles, rounded /// rectangles (for `border-radius`), or arbitrary intersections of the two. Arbitrary transforms /// are not supported because those are handled by the higher-level `StackingContext` abstraction. -#[derive(Clone, PartialEq, Debug, HeapSizeOf, Deserialize, Serialize)] +#[derive(Clone, PartialEq, HeapSizeOf, Deserialize, Serialize)] pub struct ClippingRegion { /// The main rectangular region. This does not include any corners. pub main: Rect, @@ -1043,6 +1043,20 @@ impl ClippingRegion { } } +impl fmt::Debug for ClippingRegion { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if *self == ClippingRegion::max() { + write!(f, "ClippingRegion::Max") + } else if *self == ClippingRegion::empty() { + write!(f, "ClippingRegion::Empty") + } else if self.main == max_rect() { + write!(f, "ClippingRegion(Complex={:?})", self.complex) + } else { + write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex) + } + } +} + impl ComplexClippingRegion { // TODO(pcwalton): This could be more aggressive by considering points that touch the inside of // the border radius ellipse.