/* 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/. */
impl Origin { /// Returns an origin that goes in order for `index`. /// /// This is used for iterating across origins. fn from_index(index: i8) -> Option<Self> {
Some(match index { 0 => Origin::Author, 1 => Origin::User, 2 => Origin::UserAgent,
_ => return None,
})
}
/// Returns an iterator from this origin, towards all the less specific /// origins. So for `UserAgent`, it'd iterate through all origins. #[inline] pubfn following_including(self) -> OriginSetIterator {
OriginSetIterator {
set: OriginSet::ORIGIN_USER | OriginSet::ORIGIN_AUTHOR | OriginSet::ORIGIN_USER_AGENT,
cur: self.to_index(),
rev: true,
}
}
}
impl OriginSet { /// Returns an iterator over the origins present in this `OriginSet`. /// /// See the `OriginSet` documentation for information about the order /// origins are iterated. pubfn iter_origins(&self) -> OriginSetIterator {
OriginSetIterator {
set: *self,
cur: 0,
rev: false,
}
}
}
impl From<Origin> for OriginSet { fn from(origin: Origin) -> Self { Self::from_bits_retain(origin as u8)
}
}
/// Iterates over the origins present in an `OriginSet`, in order from /// highest priority (author) to lower (user agent). #[derive(Clone)] pubstruct OriginSetIterator {
set: OriginSet,
cur: i8,
rev: bool,
}
impl Iterator for OriginSetIterator { type Item = Origin;
/// An object that stores a `T` for each origin of the CSS cascade. #[derive(Debug, Default, MallocSizeOf)] pubstruct PerOrigin<T> { /// Data for `Origin::UserAgent`. pub user_agent: T,
/// Data for `Origin::User`. pub user: T,
/// Data for `Origin::Author`. pub author: T,
}
impl<T> PerOrigin<T> { /// Returns a reference to the per-origin data for the specified origin. #[inline] pubfn borrow_for_origin(&self, origin: &Origin) -> &T { match *origin {
Origin::UserAgent => &self.user_agent,
Origin::User => &self.user,
Origin::Author => &self.author,
}
}
/// Returns a mutable reference to the per-origin data for the specified /// origin. #[inline] pubfn borrow_mut_for_origin(&mutself, origin: &Origin) -> &e='color:red'>mut T { match *origin {
Origin::UserAgent => &mutself.user_agent,
Origin::User => &mutself.user,
Origin::Author => &mutself.author,
}
}
/// Iterates over references to per-origin extra style data, from highest /// level (author) to lowest (user agent). pubfn iter_origins(&self) -> PerOriginIter<T> {
PerOriginIter {
data: &self,
cur: 0,
rev: false,
}
}
/// Iterates over references to per-origin extra style data, from lowest /// level (user agent) to highest (author). pubfn iter_origins_rev(&self) -> PerOriginIter<T> {
PerOriginIter {
data: &self,
cur: 2,
rev: true,
}
}
/// Iterates over mutable references to per-origin extra style data, from /// highest level (author) to lowest (user agent). pubfn iter_mut_origins(&mutself) -> PerOriginIterMut<T> {
PerOriginIterMut {
data: self,
cur: 0,
_marker: PhantomData,
}
}
}
/// Iterator over `PerOrigin<T>`, from highest level (author) to lowest /// (user agent). /// /// We rely on this specific order for correctly looking up @font-face, /// @counter-style and @keyframes rules. pubstruct PerOriginIter<'a, T: 'a> {
data: &'a PerOrigin<T>,
cur: i8,
rev: bool,
}
impl<'a, T> Iterator for PerOriginIter<'a, T> where
T: 'a,
{ type Item = (&'a T, Origin);
fn next(&mutself) -> Option<Self::Item> { let origin = Origin::from_index(self.cur)?;
/// Like `PerOriginIter<T>`, but iterates over mutable references to the /// per-origin data. /// /// We must use unsafe code here since it's not possible for the borrow /// checker to know that we are safely returning a different reference /// each time from `next()`. pubstruct PerOriginIterMut<'a, T: 'a> {
data: *mut PerOrigin<T>,
cur: i8,
_marker: PhantomData<&'a mut PerOrigin<T>>,
}
impl<'a, T> Iterator for PerOriginIterMut<'a, T> where
T: 'a,
{ type Item = (&'a mut T, Origin);
fn next(&mutself) -> Option<Self::Item> { let origin = Origin::from_index(self.cur)?;
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.