diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 43438438a40..44dbc1bb04b 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -13,9 +13,9 @@ use crate::gecko::values::GeckoStyleCoordConvertible; use crate::gecko_bindings::bindings; use crate::gecko_bindings::structs::{self, nsStyleCoord_CalcValue, Matrix4x4Components}; -use crate::gecko_bindings::structs::{nsStyleImage, nsresult, SheetType}; +use crate::gecko_bindings::structs::{nsStyleImage, nsresult}; use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue}; -use crate::stylesheets::{Origin, RulesMutateError}; +use crate::stylesheets::RulesMutateError; use crate::values::computed::image::LineDirection; use crate::values::computed::transform::Matrix3D; use crate::values::computed::url::ComputedImageUrl; @@ -818,16 +818,6 @@ impl From for nsresult { } } -impl From for SheetType { - fn from(other: Origin) -> Self { - match other { - Origin::UserAgent => SheetType::Agent, - Origin::Author => SheetType::Doc, - Origin::User => SheetType::User, - } - } -} - impl TrackSize { /// Return TrackSize from given two nsStyleCoord pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { diff --git a/components/style/stylesheet_set.rs b/components/style/stylesheet_set.rs index d2c3ad0f88e..5e72f7a219f 100644 --- a/components/style/stylesheet_set.rs +++ b/components/style/stylesheet_set.rs @@ -468,7 +468,14 @@ where .fold(0, |s, (item, _)| s + item.len()) } + /// Returns the count of stylesheets for a given origin. + #[inline] + pub fn sheet_count(&self, origin: Origin) -> usize { + self.collections.borrow_for_origin(&origin).len() + } + /// Returns the `index`th stylesheet in the set for the given origin. + #[inline] pub fn get(&self, origin: Origin, index: usize) -> Option<&S> { self.collections.borrow_for_origin(&origin).get(index) } diff --git a/components/style/stylesheets/origin.rs b/components/style/stylesheets/origin.rs index 783b8f26a8b..a65b61fca13 100644 --- a/components/style/stylesheets/origin.rs +++ b/components/style/stylesheets/origin.rs @@ -10,18 +10,17 @@ use std::ops::BitOrAssign; /// Each style rule has an origin, which determines where it enters the cascade. /// /// -#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)] #[repr(u8)] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] pub enum Origin { /// - UserAgent = 1 << 0, + UserAgent = 0x1, /// - User = 1 << 1, + User = 0x2, /// - Author = 1 << 2, + Author = 0x4, } impl Origin { @@ -59,7 +58,7 @@ impl Origin { bitflags! { /// A set of origins. This is equivalent to Gecko's OriginFlags. - #[cfg_attr(feature = "servo", derive(MallocSizeOf))] + #[derive(MallocSizeOf)] pub struct OriginSet: u8 { /// const ORIGIN_USER_AGENT = Origin::UserAgent as u8; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index ece14e9896f..ad7f9fd8585 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -591,6 +591,18 @@ impl Stylist { .remove_stylesheet(Some(&self.device), sheet, guard) } + /// Appends a new stylesheet to the current set. + #[inline] + pub fn sheet_count(&self, origin: Origin) -> usize { + self.stylesheets.sheet_count(origin) + } + + /// Appends a new stylesheet to the current set. + #[inline] + pub fn sheet_at(&self, origin: Origin, index: usize) -> Option<&StylistSheet> { + self.stylesheets.get(origin, index) + } + /// Returns whether for any of the applicable style rule data a given /// condition is true. pub fn any_applicable_rule_data(&self, element: E, mut f: F) -> bool