mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
stylo: Add sugar over the bitfield accessors in nsIAtom.
This commit is contained in:
parent
24168f87eb
commit
2b3c684b37
2 changed files with 25 additions and 6 deletions
|
@ -264,7 +264,7 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *
|
|||
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
|
||||
data.flush_stylesheets();
|
||||
|
||||
let atom = unsafe { Atom::from_static(pseudo_tag) };
|
||||
let atom = Atom::from(pseudo_tag);
|
||||
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);
|
||||
|
||||
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
|
||||
|
@ -293,7 +293,7 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
|
|||
}
|
||||
};
|
||||
|
||||
let atom = unsafe { Atom::from_static(pseudo_tag) };
|
||||
let atom = Atom::from(pseudo_tag);
|
||||
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);
|
||||
|
||||
// The stylist consumes stylesheets lazily.
|
||||
|
|
|
@ -128,6 +128,20 @@ impl WeakAtom {
|
|||
String::from_utf16(self.as_slice()).unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_static(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).mIsStatic() != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).mLength()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_ptr(&self) -> *mut nsIAtom {
|
||||
let const_ptr: *const nsIAtom = &self.0;
|
||||
|
@ -158,7 +172,7 @@ impl Atom {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
|
||||
unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
|
||||
Atom(ptr as *mut WeakAtom)
|
||||
}
|
||||
}
|
||||
|
@ -199,8 +213,10 @@ impl Clone for Atom {
|
|||
impl Drop for Atom {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
Gecko_ReleaseAtom(self.as_ptr());
|
||||
if !self.is_static() {
|
||||
unsafe {
|
||||
Gecko_ReleaseAtom(self.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,8 +297,11 @@ impl From<String> for Atom {
|
|||
impl From<*mut nsIAtom> for Atom {
|
||||
#[inline]
|
||||
fn from(ptr: *mut nsIAtom) -> Atom {
|
||||
debug_assert!(!ptr.is_null());
|
||||
unsafe {
|
||||
Gecko_AddRefAtom(ptr);
|
||||
if (*ptr).mIsStatic() == 0 {
|
||||
Gecko_AddRefAtom(ptr);
|
||||
}
|
||||
Atom(WeakAtom::new(ptr))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue