style: Improve logging for attribute changes.

And general Element logging. We now print all the attributes for comparison.

If this turns out to be too verbose we can change it to diff them or something.

Differential Revision: https://phabricator.services.mozilla.com/D2471
This commit is contained in:
Emilio Cobos Álvarez 2018-07-27 17:44:48 +02:00
parent 2e3aacdf80
commit c3289ad46e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 47 additions and 34 deletions

View file

@ -156,6 +156,15 @@ impl GeckoElementSnapshot {
} }
impl ElementSnapshot for GeckoElementSnapshot { impl ElementSnapshot for GeckoElementSnapshot {
fn debug_list_attributes(&self) -> String {
use nsstring::nsCString;
let mut string = nsCString::new();
unsafe {
bindings::Gecko_Snapshot_DebugListAttributes(self, &mut string);
}
String::from_utf8_lossy(&*string).into_owned()
}
fn state(&self) -> Option<ElementState> { fn state(&self) -> Option<ElementState> {
if self.has_any(Flags::State) { if self.has_any(Flags::State) {
Some(ElementState::from_bits_truncate(self.mState)) Some(ElementState::from_bits_truncate(self.mState))

View file

@ -562,28 +562,15 @@ pub struct GeckoElement<'le>(pub &'le RawGeckoElement);
impl<'le> fmt::Debug for GeckoElement<'le> { impl<'le> fmt::Debug for GeckoElement<'le> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use nsstring::nsCString;
write!(f, "<{}", self.local_name())?; write!(f, "<{}", self.local_name())?;
if let Some(id) = self.id() {
write!(f, " id={}", id)?;
}
let mut first = true; let mut attrs = nsCString::new();
let mut any = false; unsafe {
self.each_class(|c| { bindings::Gecko_Element_DebugListAttributes(self.0, &mut attrs);
if first {
first = false;
any = true;
let _ = f.write_str(" class=\"");
} else {
let _ = f.write_str(" ");
} }
let _ = write!(f, "{}", c); write!(f, "{}", attrs)?;
});
if any {
f.write_str("\"")?;
}
write!(f, "> ({:#x})", self.as_node().opaque().0) write!(f, "> ({:#x})", self.as_node().opaque().0)
} }
} }

View file

@ -43,6 +43,11 @@ pub trait ElementSnapshot: Sized {
/// If this snapshot contains attribute information. /// If this snapshot contains attribute information.
fn has_attrs(&self) -> bool; fn has_attrs(&self) -> bool;
/// Gets the attribute information of the snapshot as a string.
///
/// Only for debugging purposes.
fn debug_list_attributes(&self) -> String { String::new() }
/// The ID attribute per this snapshot. Should only be called if /// The ID attribute per this snapshot. Should only be called if
/// `has_attrs()` returns true. /// `has_attrs()` returns true.
fn id_attr(&self) -> Option<&WeakAtom>; fn id_attr(&self) -> Option<&WeakAtom>;

View file

@ -208,20 +208,32 @@ where
} }
} }
if log_enabled!(::log::Level::Debug) {
debug!("Collecting changes for: {:?}", element); debug!("Collecting changes for: {:?}", element);
if !state_changes.is_empty() {
debug!(" > state: {:?}", state_changes); debug!(" > state: {:?}", state_changes);
}
if snapshot.id_changed() {
debug!( debug!(
" > id changed: {:?} -> +{:?} -{:?}", " > id changed: +{:?} -{:?}",
snapshot.id_changed(),
id_added, id_added,
id_removed id_removed
); );
}
if snapshot.class_changed() {
debug!( debug!(
" > class changed: {:?} -> +{:?} -{:?}", " > class changed: +{:?} -{:?}",
snapshot.class_changed(),
classes_added, classes_added,
classes_removed classes_removed
); );
}
if snapshot.other_attr_changed() {
debug!(
" > attributes changed, old: {}",
snapshot.debug_list_attributes()
)
}
}
let lookup_element = if element.implemented_pseudo_element().is_some() { let lookup_element = if element.implemented_pseudo_element().is_some() {
element.pseudo_element_originating_element().unwrap() element.pseudo_element_originating_element().unwrap()