Skip to content
Permalink
Browse files

Derive HeapSizeOf on more Stylesheet-related types

In preparation of storing `Stylesheet`s on nodes.
  • Loading branch information...
tschneidereit committed Oct 6, 2015
1 parent f1b6c7c commit 068e6a8e9f926fa6e8649b934ee9ffe2ef7b78de
@@ -9,20 +9,21 @@ use properties::longhands::font_family::parse_one_family;
use std::ascii::AsciiExt;
use string_cache::Atom;
use url::{Url, UrlParser};
use util::mem::HeapSizeOf;

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Debug, HeapSizeOf, PartialEq, Eq, Deserialize, Serialize)]
pub enum Source {
Url(UrlSource),
Local(Atom),
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Debug, HeapSizeOf, PartialEq, Eq, Deserialize, Serialize)]
pub struct UrlSource {
pub url: Url,
pub format_hints: Vec<String>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, HeapSizeOf, PartialEq, Eq)]
pub struct FontFaceRule {
pub family: Atom,
pub sources: Vec<Source>,
@@ -8,15 +8,16 @@ use euclid::size::{Size2D, TypedSize2D};
use properties::longhands;
use std::ascii::AsciiExt;
use util::geometry::ViewportPx;
use util::mem::HeapSizeOf;
use values::specified;


#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct MediaQueryList {
pub media_queries: Vec<MediaQuery>
}

#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)]
pub enum Range<T> {
Min(T),
Max(T),
@@ -59,20 +60,20 @@ impl<T: Ord> Range<T> {
}

/// http://dev.w3.org/csswg/mediaqueries-3/#media1
#[derive(PartialEq, Copy, Clone, Debug)]
#[derive(PartialEq, Copy, Clone, Debug, HeapSizeOf)]
pub enum Expression {
/// http://dev.w3.org/csswg/mediaqueries-3/#width
Width(Range<specified::Length>),
}

/// http://dev.w3.org/csswg/mediaqueries-3/#media0
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)]
pub enum Qualifier {
Only,
Not,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct MediaQuery {
pub qualifier: Option<Qualifier>,
pub media_type: MediaQueryType,
@@ -91,20 +92,20 @@ impl MediaQuery {
}

/// http://dev.w3.org/csswg/mediaqueries-3/#media0
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)]
pub enum MediaQueryType {
All, // Always true
MediaType(MediaType),
}

#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)]
pub enum MediaType {
Screen,
Print,
Unknown,
}

#[derive(Debug)]
#[derive(Debug, HeapSizeOf)]
pub struct Device {
pub media_type: MediaType,
pub viewport_size: TypedSize2D<ViewportPx, f32>,
@@ -17,12 +17,13 @@ use std::iter::Iterator;
use std::slice;
use string_cache::{Atom, Namespace};
use url::Url;
use util::mem::HeapSizeOf;
use viewport::ViewportRule;

/// Each style rule has an origin, which determines where it enters the cascade.
///
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
#[derive(Clone, PartialEq, Eq, Copy, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Debug, HeapSizeOf)]
pub enum Origin {
/// http://dev.w3.org/csswg/css-cascade/#cascade-origin-ua
UserAgent,
@@ -35,7 +36,7 @@ pub enum Origin {
}


#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct Stylesheet {
/// List of rules in the order they were found (important for
/// cascading order)
@@ -44,7 +45,7 @@ pub struct Stylesheet {
}


#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub enum CSSRule {
Charset(String),
Namespace(Option<String>, Namespace),
@@ -54,7 +55,7 @@ pub enum CSSRule {
Viewport(ViewportRule),
}

#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct MediaRule {
pub media_queries: MediaQueryList,
pub rules: Vec<CSSRule>,
@@ -67,7 +68,7 @@ impl MediaRule {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct StyleRule {
pub selectors: Vec<Selector>,
pub declarations: PropertyDeclarationBlock,
@@ -18,10 +18,11 @@ use std::str::Chars;
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
use stylesheets::Origin;
use util::geometry::ViewportPx;
use util::mem::HeapSizeOf;
use values::computed::{Context, ToComputedValue};
use values::specified::{Length, LengthOrPercentageOrAuto, ViewportPercentageLength};

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, HeapSizeOf, PartialEq)]
pub enum ViewportDescriptor {
MinWidth(ViewportLength),
MaxWidth(ViewportLength),
@@ -133,7 +134,7 @@ struct ViewportRuleParser<'a, 'b: 'a> {
context: &'a ParserContext<'b>
}

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, HeapSizeOf, PartialEq)]
pub struct ViewportDescriptorDeclaration {
pub origin: Origin,
pub descriptor: ViewportDescriptor,
@@ -228,7 +229,7 @@ impl<'a, 'b> DeclarationParser for ViewportRuleParser<'a, 'b> {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, HeapSizeOf, PartialEq)]
pub struct ViewportRule {
pub declarations: Vec<ViewportDescriptorDeclaration>
}
@@ -20,7 +20,7 @@ define_css_keyword_enum!(Orientation:
"landscape" => Landscape);


#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, HeapSizeOf, PartialEq, Deserialize, Serialize)]
pub struct ViewportConstraints {
pub size: TypedSize2D<ViewportPx, f32>,

@@ -54,7 +54,7 @@ impl ToCss for ViewportConstraints {

/// Zoom is a number | percentage | auto
/// See http://dev.w3.org/csswg/css-device-adapt/#descdef-viewport-zoom
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, HeapSizeOf, PartialEq)]
pub enum Zoom {
Number(f32),
Percentage(f32),

0 comments on commit 068e6a8

Please sign in to comment.
You can’t perform that action at this time.