Skip to content
Permalink
Browse files

style: Add derived ToShmem implementations.

  • Loading branch information...
heycam authored and emilio committed Mar 30, 2019
1 parent 128c6ae commit 40248ae5fdc2e768862a1865b43e0a23e588b303
Showing with 649 additions and 267 deletions.
  1. +2 −0 components/selectors/Cargo.toml
  2. +9 −5 components/selectors/attr.rs
  3. +1 −1 components/selectors/builder.rs
  4. +3 −0 components/selectors/lib.rs
  5. +20 −13 components/selectors/parser.rs
  6. +12 −12 components/style/counter_style/mod.rs
  7. +1 −1 components/style/custom_properties.rs
  8. +9 −7 components/style/font_face.rs
  9. +1 −1 components/style/gecko/pseudo_element_definition.mako.rs
  10. +1 −1 components/style/gecko/selector_parser.rs
  11. +4 −4 components/style/gecko/url.rs
  12. +1 −1 components/style/gecko_string_cache/namespace.rs
  13. +1 −0 components/style/lib.rs
  14. +1 −0 components/style/macros.rs
  15. +2 −2 components/style/media_queries/media_condition.rs
  16. +6 −6 components/style/media_queries/media_feature_expression.rs
  17. +1 −1 components/style/media_queries/media_list.rs
  18. +4 −4 components/style/media_queries/media_query.rs
  19. +1 −1 components/style/properties/declaration_block.rs
  20. +5 −5 components/style/properties/helpers.mako.rs
  21. +1 −1 components/style/properties/longhands/font.mako.rs
  22. +9 −8 components/style/properties/properties.mako.rs
  23. +1 −1 components/style/selector_parser.rs
  24. +4 −4 components/style/stylesheets/document_rule.rs
  25. +5 −5 components/style/stylesheets/font_feature_values_rule.rs
  26. +4 −4 components/style/stylesheets/keyframes_rule.rs
  27. +1 −1 components/style/stylesheets/media_rule.rs
  28. +1 −1 components/style/stylesheets/mod.rs
  29. +1 −1 components/style/stylesheets/namespace_rule.rs
  30. +1 −1 components/style/stylesheets/origin.rs
  31. +1 −1 components/style/stylesheets/page_rule.rs
  32. +1 −1 components/style/stylesheets/rule_list.rs
  33. +1 −1 components/style/stylesheets/rule_parser.rs
  34. +1 −1 components/style/stylesheets/style_rule.rs
  35. +4 −4 components/style/stylesheets/supports_rule.rs
  36. +4 −4 components/style/stylesheets/viewport_rule.rs
  37. +2 −2 components/style/values/computed/font.rs
  38. +2 −0 components/style/values/computed/length.rs
  39. +1 −0 components/style/values/computed/percentage.rs
  40. +1 −0 components/style/values/generics/background.rs
  41. +28 −3 components/style/values/generics/basic_shape.rs
  42. +24 −4 components/style/values/generics/border.rs
  43. +5 −1 components/style/values/generics/box.rs
  44. +3 −2 components/style/values/generics/color.rs
  45. +1 −0 components/style/values/generics/column.rs
  46. +30 −6 components/style/values/generics/counters.rs
  47. +13 −2 components/style/values/generics/easing.rs
  48. +3 −0 components/style/values/generics/effects.rs
  49. +1 −0 components/style/values/generics/flex.rs
  50. +13 −3 components/style/values/generics/font.rs
  51. +1 −1 components/style/values/generics/gecko.rs
  52. +40 −10 components/style/values/generics/grid.rs
  53. +15 −11 components/style/values/generics/image.rs
  54. +4 −0 components/style/values/generics/length.rs
  55. +7 −2 components/style/values/generics/mod.rs
  56. +2 −0 components/style/values/generics/position.rs
  57. +1 −0 components/style/values/generics/rect.rs
  58. +1 −0 components/style/values/generics/size.rs
  59. +5 −0 components/style/values/generics/svg.rs
  60. +13 −2 components/style/values/generics/text.rs
  61. +46 −7 components/style/values/generics/transform.rs
  62. +3 −2 components/style/values/generics/ui.rs
  63. +1 −0 components/style/values/generics/url.rs
  64. +5 −2 components/style/values/mod.rs
  65. +9 −9 components/style/values/specified/align.rs
  66. +2 −2 components/style/values/specified/angle.rs
  67. +2 −1 components/style/values/specified/background.rs
  68. +8 −3 components/style/values/specified/border.rs
  69. +57 −10 components/style/values/specified/box.rs
  70. +1 −1 components/style/values/specified/calc.rs
  71. +4 −4 components/style/values/specified/color.rs
  72. +1 −1 components/style/values/specified/effects.rs
  73. +40 −26 components/style/values/specified/font.rs
  74. +2 −2 components/style/values/specified/image.rs
  75. +7 −7 components/style/values/specified/length.rs
  76. +10 −3 components/style/values/specified/list.rs
  77. +9 −5 components/style/values/specified/mod.rs
  78. +1 −0 components/style/values/specified/motion.rs
  79. +1 −0 components/style/values/specified/outline.rs
  80. +1 −1 components/style/values/specified/percentage.rs
  81. +28 −6 components/style/values/specified/position.rs
  82. +1 −1 components/style/values/specified/resolution.rs
  83. +6 −2 components/style/values/specified/svg.rs
  84. +12 −2 components/style/values/specified/svg_path.rs
  85. +9 −1 components/style/values/specified/table.rs
  86. +26 −9 components/style/values/specified/text.rs
  87. +2 −2 components/style/values/specified/time.rs
  88. +1 −1 components/style/values/specified/transform.rs
  89. +5 −1 components/style/values/specified/ui.rs
  90. +2 −0 components/style_traits/Cargo.toml
  91. +3 −0 components/style_traits/lib.rs
  92. +2 −2 components/style_traits/values.rs
  93. +1 −1 components/style_traits/viewport.rs
@@ -31,6 +31,8 @@ precomputed-hash = "0.1"
servo_arc = { version = "0.1", path = "../servo_arc" }
smallvec = "0.6"
thin-slice = "0.1.0"
to_shmem = { path = "../to_shmem" }
to_shmem_derive = { path = "../to_shmem_derive" }

[build-dependencies]
phf_codegen = "0.7.18"
@@ -6,11 +6,15 @@ use crate::parser::SelectorImpl;
use cssparser::ToCss;
use std::fmt;

#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, ToShmem)]
#[shmem(no_bounds)]
pub struct AttrSelectorWithOptionalNamespace<Impl: SelectorImpl> {
#[shmem(field_bound)]
pub namespace: Option<NamespaceConstraint<(Impl::NamespacePrefix, Impl::NamespaceUrl)>>,
#[shmem(field_bound)]
pub local_name: Impl::LocalName,
pub local_name_lower: Impl::LocalName,
#[shmem(field_bound)]
pub operation: ParsedAttrSelectorOperation<Impl::AttrValue>,
pub never_matches: bool,
}
@@ -24,15 +28,15 @@ impl<Impl: SelectorImpl> AttrSelectorWithOptionalNamespace<Impl> {
}
}

#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, ToShmem)]
pub enum NamespaceConstraint<NamespaceUrl> {
Any,

/// Empty string for no namespace
Specific(NamespaceUrl),
}

#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, ToShmem)]
pub enum ParsedAttrSelectorOperation<AttrValue> {
Exists,
WithValue {
@@ -72,7 +76,7 @@ impl<AttrValue> AttrSelectorOperation<AttrValue> {
}
}

#[derive(Clone, Copy, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, PartialEq, ToShmem)]
pub enum AttrSelectorOperator {
Equal,
Includes,
@@ -132,7 +136,7 @@ impl AttrSelectorOperator {
/// The definition of whitespace per CSS Selectors Level 3 § 4.
pub static SELECTOR_WHITESPACE: &'static [char] = &[' ', '\t', '\n', '\r', '\x0C'];

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)]
pub enum ParsedCaseSensitivity {
// 's' was specified.
ExplicitCaseSensitive,
@@ -199,7 +199,7 @@ pub const HAS_SLOTTED_BIT: u32 = 1 << 31;

/// We use ten bits for each specificity kind (id, class, element), and the two
/// high bits for the pseudo and slotted flags.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)]
pub struct SpecificityAndFlags(pub u32);

impl SpecificityAndFlags {
@@ -21,6 +21,9 @@ extern crate precomputed_hash;
extern crate servo_arc;
extern crate smallvec;
extern crate thin_slice;
extern crate to_shmem;
#[macro_use]
extern crate to_shmem_derive;

pub mod attr;
pub mod bloom;
@@ -221,8 +221,9 @@ pub trait Parser<'i> {
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SelectorList<Impl: SelectorImpl>(pub SmallVec<[Selector<Impl>; 1]>);
#[derive(Clone, Debug, Eq, PartialEq, ToShmem)]
#[shmem(no_bounds)]
pub struct SelectorList<Impl: SelectorImpl>(#[shmem(field_bound)] pub SmallVec<[Selector<Impl>; 1]>);

impl<Impl: SelectorImpl> SelectorList<Impl> {
/// Parse a comma-separated list of Selectors.
@@ -507,8 +508,9 @@ pub fn namespace_empty_string<Impl: SelectorImpl>() -> Impl::NamespaceUrl {
///
/// This reordering doesn't change the semantics of selector matching, and we
/// handle it in to_css to make it invisible to serialization.
#[derive(Clone, Eq, PartialEq)]
pub struct Selector<Impl: SelectorImpl>(ThinArc<SpecificityAndFlags, Component<Impl>>);
#[derive(Clone, Eq, PartialEq, ToShmem)]
#[shmem(no_bounds)]
pub struct Selector<Impl: SelectorImpl>(#[shmem(field_bound)] ThinArc<SpecificityAndFlags, Component<Impl>>);

impl<Impl: SelectorImpl> Selector<Impl> {
#[inline]
@@ -776,7 +778,7 @@ impl<'a, Impl: SelectorImpl> Iterator for AncestorIter<'a, Impl> {
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)]
pub enum Combinator {
Child, // >
Descendant, // space
@@ -824,29 +826,32 @@ impl Combinator {
/// optimal packing and cache performance, see [1].
///
/// [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, ToShmem)]
#[shmem(no_bounds)]
pub enum Component<Impl: SelectorImpl> {
Combinator(Combinator),

ExplicitAnyNamespace,
ExplicitNoNamespace,
DefaultNamespace(Impl::NamespaceUrl),
Namespace(Impl::NamespacePrefix, Impl::NamespaceUrl),
DefaultNamespace(#[shmem(field_bound)] Impl::NamespaceUrl),
Namespace(#[shmem(field_bound)] Impl::NamespacePrefix, #[shmem(field_bound)] Impl::NamespaceUrl),

ExplicitUniversalType,
LocalName(LocalName<Impl>),

ID(Impl::Identifier),
Class(Impl::ClassName),
ID(#[shmem(field_bound)] Impl::Identifier),
Class(#[shmem(field_bound)] Impl::ClassName),

AttributeInNoNamespaceExists {
#[shmem(field_bound)]
local_name: Impl::LocalName,
local_name_lower: Impl::LocalName,
},
// Used only when local_name is already lowercase.
AttributeInNoNamespace {
local_name: Impl::LocalName,
operator: AttrSelectorOperator,
#[shmem(field_bound)]
value: Impl::AttrValue,
case_sensitivity: ParsedCaseSensitivity,
never_matches: bool,
@@ -878,7 +883,7 @@ pub enum Component<Impl: SelectorImpl> {
FirstOfType,
LastOfType,
OnlyOfType,
NonTSPseudoClass(Impl::NonTSPseudoClass),
NonTSPseudoClass(#[shmem(field_bound)] Impl::NonTSPseudoClass),
/// The ::slotted() pseudo-element (which isn't actually a pseudo-element,
/// and probably should be a pseudo-class):
///
@@ -902,7 +907,7 @@ pub enum Component<Impl: SelectorImpl> {
///
/// See https://github.com/w3c/csswg-drafts/issues/2158
Host(Option<Selector<Impl>>),
PseudoElement(Impl::PseudoElement),
PseudoElement(#[shmem(field_bound)] Impl::PseudoElement),
}

impl<Impl: SelectorImpl> Component<Impl> {
@@ -957,8 +962,10 @@ impl<Impl: SelectorImpl> Component<Impl> {
}
}

#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, ToShmem)]
#[shmem(no_bounds)]
pub struct LocalName<Impl: SelectorImpl> {
#[shmem(field_bound)]
pub name: Impl::LocalName,
pub lower_name: Impl::LocalName,
}
@@ -164,7 +164,7 @@ macro_rules! counter_style_descriptors {
$( #[$doc: meta] $name: tt $ident: ident / $setter: ident [$checker: tt]: $ty: ty, )+
) => {
/// An @counter-style rule
#[derive(Clone, Debug)]
#[derive(Clone, Debug, ToShmem)]
pub struct CounterStyleRuleData {
name: CustomIdent,
generation: Wrapping<u32>,
@@ -337,7 +337,7 @@ impl CounterStyleRuleData {
}

/// <https://drafts.csswg.org/css-counter-styles/#counter-style-system>
#[derive(Clone, Debug)]
#[derive(Clone, Debug, ToShmem)]
pub enum System {
/// 'cyclic'
Cyclic,
@@ -410,7 +410,7 @@ impl ToCss for System {

/// <https://drafts.csswg.org/css-counter-styles/#typedef-symbol>
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss, ToShmem)]
pub enum Symbol {
/// <string>
String(String),
@@ -447,7 +447,7 @@ impl Symbol {
}

/// <https://drafts.csswg.org/css-counter-styles/#counter-style-negative>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub struct Negative(pub Symbol, pub Option<Symbol>);

impl Parse for Negative {
@@ -465,11 +465,11 @@ impl Parse for Negative {
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-range>
///
/// Empty Vec represents 'auto'
#[derive(Clone, Debug)]
#[derive(Clone, Debug, ToShmem)]
pub struct Ranges(pub Vec<Range<CounterBound>>);

/// A bound found in `Ranges`.
#[derive(Clone, Copy, Debug, ToCss)]
#[derive(Clone, Copy, Debug, ToCss, ToShmem)]
pub enum CounterBound {
/// An integer bound.
Integer(Integer),
@@ -548,7 +548,7 @@ where
}

/// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub struct Pad(pub Integer, pub Symbol);

impl Parse for Pad {
@@ -564,7 +564,7 @@ impl Parse for Pad {
}

/// <https://drafts.csswg.org/css-counter-styles/#counter-style-fallback>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub struct Fallback(pub CustomIdent);

impl Parse for Fallback {
@@ -578,7 +578,7 @@ impl Parse for Fallback {

/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss, ToShmem)]
pub struct Symbols(#[css(iterable)] pub Vec<Symbol>);

impl Parse for Symbols {
@@ -602,7 +602,7 @@ impl Parse for Symbols {
}

/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub struct AdditiveSymbols(pub Vec<AdditiveTuple>);

impl Parse for AdditiveSymbols {
@@ -623,7 +623,7 @@ impl Parse for AdditiveSymbols {
}

/// <integer> && <symbol>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub struct AdditiveTuple {
/// <integer>
pub weight: Integer,
@@ -651,7 +651,7 @@ impl Parse for AdditiveTuple {
}

/// <https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as>
#[derive(Clone, Debug, ToCss)]
#[derive(Clone, Debug, ToCss, ToShmem)]
pub enum SpeakAs {
/// auto
Auto,
@@ -96,7 +96,7 @@ pub fn parse_name(s: &str) -> Result<&str, ()> {
///
/// We preserve the original CSS for serialization, and also the variable
/// references to other custom property names.
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
pub struct VariableValue {
css: String,

@@ -34,7 +34,7 @@ use style_traits::{StyleParseErrorKind, ToCss};

/// A source for a font-face rule.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
pub enum Source {
/// A `url()` source.
Url(UrlSource),
@@ -68,7 +68,7 @@ pub enum FontFaceSourceListComponent {
///
/// <https://drafts.csswg.org/css-fonts/#src-desc>
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, ToShmem)]
pub struct UrlSource {
/// The specified url.
pub url: SpecifiedUrl,
@@ -101,7 +101,9 @@ impl ToCss for UrlSource {
/// on whether and when it is downloaded and ready to use.
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[derive(
Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss, ToShmem,
)]
#[repr(u8)]
pub enum FontDisplay {
Auto,
@@ -144,7 +146,7 @@ macro_rules! impl_range {
/// The font-weight descriptor:
///
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-weight
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToShmem)]
pub struct FontWeightRange(pub AbsoluteFontWeight, pub AbsoluteFontWeight);
impl_range!(FontWeightRange, AbsoluteFontWeight);

@@ -176,7 +178,7 @@ impl FontWeightRange {
/// The font-stretch descriptor:
///
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-stretch
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToShmem)]
pub struct FontStretchRange(pub FontStretch, pub FontStretch);
impl_range!(FontStretchRange, FontStretch);

@@ -205,7 +207,7 @@ impl FontStretchRange {
/// The font-style descriptor:
///
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-style
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToShmem)]
#[allow(missing_docs)]
pub enum FontStyle {
Normal,
@@ -435,7 +437,7 @@ macro_rules! font_face_descriptors_common {
/// Data inside a `@font-face` rule.
///
/// <https://drafts.csswg.org/css-fonts/#font-face-rule>
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, ToShmem)]
pub struct FontFaceRuleData {
$(
#[$doc]
@@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/// Gecko's pseudo-element definition.
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
pub enum PseudoElement {
% for pseudo in PSEUDOS:
/// ${pseudo.value}
@@ -44,7 +44,7 @@ pub type Lang = Atom;
macro_rules! pseudo_class_name {
([$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*]) => {
/// Our representation of a non tree-structural pseudo-class.
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
pub enum NonTSPseudoClass {
$(
#[doc = $css]
Oops, something went wrong.

0 comments on commit 40248ae

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