/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/// A function that, given an element of type `T`, allows you to get a single /// class or a class list. enum Class<'a> {
None,
One(*const nsAtom),
More(&'a [structs::RefPtr<nsAtom>]),
}
/// Returns the attribute name as an atom pointer. #[inline] pubfn name(&self) -> *const nsAtom { ifself.is_nodeinfo() { unsafe { self.as_nodeinfo() }.mInner.mName
} else { self.mBits as *const nsAtom
}
}
}
/// Find an attribute value with a given name and no namespace. #[inline(always)] pubfn find_attr<'a>(
attrs: &'a [structs::AttrArray_InternalAttr],
name: &Atom,
) -> Option<&'a structs::nsAttrValue> {
attrs
.iter()
.find(|attr| attr.mName.mBits == name.as_ptr() as usize)
.map(|attr| &attr.mValue)
}
/// Finds the id attribute from a list of attributes. #[inline(always)] pubfn get_id(attrs: &[structs::AttrArray_InternalAttr]) -> Option<&WeakAtom> {
Some(unsafe { get_id_from_attr(find_attr(attrs, &atom!("id"))?) })
}
unsafe { for atom in std::slice::from_raw_parts(atoms, length) {
AtomIdent::with(*atom, &mut callback)
}
}
}
#[inline(always)] pub(super) fn imported_part(
attrs: &[structs::AttrArray_InternalAttr],
name: &AtomIdent,
) -> Option<AtomIdent> { let attr = find_attr(attrs, &atom!("exportparts"))?; let atom = unsafe { bindings::Gecko_Element_ImportedPart(attr, name.as_ptr()) }; if atom.is_null() { return None;
}
Some(AtomIdent(unsafe { Atom::from_raw(atom) }))
}
/// Given a class or part name, a case sensitivity, and an array of attributes, /// returns whether the attribute has that name. #[inline(always)] pubfn has_class_or_part(
name: &AtomIdent,
case_sensitivity: CaseSensitivity,
attr: &structs::nsAttrValue,
) -> bool { matchunsafe { get_class_or_part_from_attr(attr) } {
Class::None => false,
Class::One(atom) => unsafe { case_sensitivity.eq_atom(name, WeakAtom::new(atom)) },
Class::More(atoms) => match case_sensitivity {
CaseSensitivity::CaseSensitive => { let name_ptr = name.as_ptr();
atoms.iter().any(|atom| atom.mRawPtr == name_ptr)
},
CaseSensitivity::AsciiCaseInsensitive => unsafe {
atoms
.iter()
.any(|atom| WeakAtom::new(atom.mRawPtr).eq_ignore_ascii_case(name))
},
},
}
}
/// Given an item, a callback, and a getter, execute `callback` for each class /// or part name this `item` has. #[inline(always)] pubfn each_class_or_part<F>(attr: &structs::nsAttrValue, mut callback: F) where
F: FnMut(&AtomIdent),
{ unsafe { match get_class_or_part_from_attr(attr) {
Class::None => {},
Class::One(atom) => AtomIdent::with(atom, callback),
Class::More(atoms) => { for atom in atoms {
AtomIdent::with(atom.mRawPtr, &mut callback)
}
},
}
}
}
/// Returns a list of classes that were either added to or removed from the /// element since the snapshot. pubfn classes_changed<E: TElement>(element: &E, snapshots: &SnapshotMap) -> SmallVec<[Atom; 8]> {
debug_assert!(element.has_snapshot(), "Why bothering?"); let snapshot = snapshots.get(element).expect("has_snapshot lied"); if !snapshot.class_changed() { return SmallVec::new();
}
/// Returns whether a given attribute selector matches given the internal attrs. #[inline(always)] pub(crate) fn attr_matches(
attrs: &[structs::AttrArray_InternalAttr],
ns: &NamespaceConstraint<&Namespace>,
local_name: &LocalName,
operation: &AttrSelectorOperation<&AttrValue>,
) -> bool { let name_ptr = local_name.as_ptr(); for attr in attrs { if attr.mName.name() != name_ptr { continue;
}
if attr_matches_checked_name(attr, ns, operation) { returntrue;
}
// The name matched but the value or namespace didn't. The only reason to check the other // attributes now would be to find one with the same name but a different namespace. if *ns != NamespaceConstraint::Any { // We don't want to look for other namespaces, so we're done. returnfalse;
}
} false
}
/// Returns whether a given attribute selector matches given a single attribute, /// for the case where the caller has already found an attribute with the right name. fn attr_matches_checked_name(
attr: &structs::AttrArray_InternalAttr,
ns: &NamespaceConstraint<&Namespace>,
operation: &AttrSelectorOperation<&AttrValue>,
) -> bool { let ns_matches = match *ns {
NamespaceConstraint::Any => true,
NamespaceConstraint::Specific(ns) => { if *ns == ns!() {
!attr.mName.is_nodeinfo()
} else {
ns.as_ptr() == unsafe { namespace_id_to_atom(attr.mName.namespace_id()) }
}
},
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.