stylo: Convert pseudo-elements to an Atom wrapper.

This commit is contained in:
Emilio Cobos Álvarez 2016-08-09 19:43:44 -07:00
parent b1091dff58
commit d612d9f5ef
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 129 additions and 280 deletions

View file

@ -42,3 +42,28 @@ fn assert_restyle_hints_match() {
check_enum_value_non_static!(nsRestyleHint::eRestyle_SomeDescendants, RESTYLE_DESCENDANTS.bits());
check_enum_value_non_static!(nsRestyleHint::eRestyle_LaterSiblings, RESTYLE_LATER_SIBLINGS.bits());
}
// Note that we can't call each_pseudo_element, parse_pseudo_element, or
// similar, because we'd need the foreign atom symbols to link.
#[test]
fn assert_basic_pseudo_elements() {
let mut saw_before = false;
let mut saw_after = false;
macro_rules! pseudo_element {
(":before", $atom:expr, false) => {
saw_before = true;
};
(":after", $atom:expr, false) => {
saw_after = true;
};
($pseudo_str_with_colon:expr, $atom:expr, $is_anon_box:expr) => {
// Do nothing
};
}
include!("../../components/style/generated/gecko_pseudo_element_helper.rs");
assert!(saw_before);
assert!(saw_after);
}

View file

@ -134,6 +134,21 @@ impl WeakAtom {
}
}
impl fmt::Debug for WeakAtom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "Gecko WeakAtom({:p}, {})", self, self)
}
}
impl fmt::Display for WeakAtom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in self.chars() {
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
}
Ok(())
}
}
impl Atom {
pub unsafe fn with<F>(ptr: *mut nsIAtom, callback: &mut F) where F: FnMut(&Atom) {
let atom = Atom(WeakAtom::new(ptr));
@ -217,16 +232,15 @@ impl Deserialize for Atom {
impl fmt::Debug for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "Gecko Atom {:p}", self.0)
write!(w, "Gecko Atom({:p}, {})", self.0, self)
}
}
impl fmt::Display for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in self.chars() {
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
unsafe {
(&*self.0).fmt(w)
}
Ok(())
}
}