style: Don't keep two list of stylesheets in ServoStyleSet.

Just one set of stylesheets is enough. While at it, unify SheetType and Origin.

Differential Revision: https://phabricator.services.mozilla.com/D27564
This commit is contained in:
Emilio Cobos Álvarez 2019-04-19 04:20:31 +00:00
parent 098eb300ac
commit c0b17cc844
4 changed files with 26 additions and 18 deletions

View file

@ -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<RulesMutateError> for nsresult {
}
}
impl From<Origin> for SheetType {
fn from(other: Origin) -> Self {
match other {
Origin::UserAgent => SheetType::Agent,
Origin::Author => SheetType::Doc,
Origin::User => SheetType::User,
}
}
}
impl TrackSize<LengthPercentage> {
/// Return TrackSize from given two nsStyleCoord
pub fn from_gecko_style_coords<T: CoordData>(gecko_min: &T, gecko_max: &T) -> Self {

View file

@ -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)
}

View file

@ -10,18 +10,17 @@ use std::ops::BitOrAssign;
/// Each style rule has an origin, which determines where it enters the cascade.
///
/// <https://drafts.csswg.org/css-cascade/#cascading-origins>
#[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 {
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-user-agent>
UserAgent = 1 << 0,
UserAgent = 0x1,
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-user>
User = 1 << 1,
User = 0x2,
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-author>
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 {
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-user-agent>
const ORIGIN_USER_AGENT = Origin::UserAgent as u8;

View file

@ -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<E, F>(&self, element: E, mut f: F) -> bool