diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index f09a2dc6b34..2972a9465f4 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -79,6 +79,7 @@ use std::borrow::Cow; use std::cell::{Cell, Ref}; use std::convert::TryFrom; use std::default::Default; +use std::fmt; use std::mem; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -115,6 +116,16 @@ pub struct Element { atomic_flags: AtomicElementFlags, } +impl fmt::Debug for Element { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "<{}", self.local_name)); + if let Some(ref id) = *self.id_attribute.borrow() { + try!(write!(f, " id={}", id)); + } + write!(f, ">") + } +} + #[derive(PartialEq, HeapSizeOf)] pub enum ElementCreator { ParserCreated, diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index cbf04b48e5b..431fe55f9b0 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -49,6 +49,7 @@ use script_layout_interface::{HTMLCanvasData, LayoutNodeType, TrustedNodeAddress use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData}; use selectors::matching::{DeclarationBlock, ElementFlags}; use selectors::parser::{AttrSelector, NamespaceConstraint}; +use std::fmt; use std::marker::PhantomData; use std::mem::{transmute, transmute_copy}; use std::sync::Arc; @@ -405,6 +406,16 @@ pub struct ServoLayoutElement<'le> { chain: PhantomData<&'le ()>, } +impl<'le> fmt::Debug for ServoLayoutElement<'le> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "<{}", self.element.local_name())); + if let &Some(ref id) = unsafe { &*self.element.id_attribute() } { + try!(write!(f, " id={}", id)); + } + write!(f, ">") + } +} + impl<'le> PresentationalHintsSynthetizer for ServoLayoutElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes(&self, hints: &mut V) where V: Push>> @@ -926,7 +937,7 @@ impl Iterator for ThreadSafeLayoutNodeChildrenIterator { element: &'le Element, } diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 17d948cc8ca..bc64480b424 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -10,6 +10,7 @@ use gfx_traits::{ByteIndex, LayerId, LayerType}; use msg::constellation_msg::PipelineId; use range::Range; use restyle_damage::RestyleDamage; +use std::fmt::Debug; use std::sync::Arc; use string_cache::{Atom, Namespace}; use style::computed_values::display; @@ -350,7 +351,7 @@ pub trait DangerousThreadSafeLayoutNode: ThreadSafeLayoutNode { unsafe fn dangerous_next_sibling(&self) -> Option; } -pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + +pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + ::selectors::Element + PresentationalHintsSynthetizer { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode; diff --git a/components/style/dom.rs b/components/style/dom.rs index 184e926ef40..bb96b45e9fd 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -201,7 +201,7 @@ pub trait PresentationalHintsSynthetizer { where V: Push>>; } -pub trait TElement : PartialEq + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { +pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { type ConcreteNode: TNode; type ConcreteDocument: TDocument; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index d971b1c6eab..e42f6ce09d8 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -803,7 +803,7 @@ impl ToCss for DeclaredValue { } } -#[derive(PartialEq, Clone, Debug)] +#[derive(PartialEq, Clone)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum PropertyDeclaration { % for property in data.longhands: @@ -867,6 +867,24 @@ impl fmt::Display for PropertyDeclarationName { } } } + +impl fmt::Debug for PropertyDeclaration { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "{}: ", self.name())); + match *self { + % for property in data.longhands: + % if not property.derived_from: + PropertyDeclaration::${property.camel_case}(ref value) => value.to_css(f), + % endif + % endfor + PropertyDeclaration::Custom(_, ref value) => value.to_css(f), + % if any(property.derived_from for property in data.longhands): + _ => Err(fmt::Error), + % endif + } + } +} + impl ToCss for PropertyDeclaration { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index a793fec1ff4..e4b1f3cdc52 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -21,6 +21,7 @@ use selectors::parser::Selector; use sink::Push; use smallvec::VecLike; use std::collections::HashMap; +use std::fmt; use std::hash::BuildHasherDefault; use std::sync::Arc; use string_cache::Atom; @@ -275,6 +276,7 @@ impl Stylist { parent: &Arc) -> Option> where E: Element + + Debug + PresentationalHintsSynthetizer { debug_assert!(TheSelectorImpl::pseudo_element_cascade_type(pseudo).is_lazy()); @@ -343,6 +345,7 @@ impl Stylist { pseudo_element: Option<&PseudoElement>, applicable_declarations: &mut V) -> StyleRelations where E: Element + + fmt::Debug + PresentationalHintsSynthetizer, V: Push + VecLike { diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index 860173820d6..ab0d27a5d85 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -34,6 +34,7 @@ use selectors::matching::DeclarationBlock; use selectors::parser::{AttrSelector, NamespaceConstraint}; use snapshot::GeckoElementSnapshot; use snapshot_helpers; +use std::fmt; use std::marker::PhantomData; use std::ops::BitOr; use std::ptr; @@ -382,6 +383,16 @@ pub struct GeckoElement<'le> { chain: PhantomData<&'le ()>, } +impl<'le> fmt::Debug for GeckoElement<'le> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(write!(f, "<{}", self.get_local_name())); + if let Some(id) = self.get_id() { + try!(write!(f, " id={}", id)); + } + write!(f, ">") + } +} + impl<'le> GeckoElement<'le> { pub unsafe fn from_raw(el: *mut RawGeckoElement) -> GeckoElement<'le> { GeckoElement {