style: Fix servo build, and appease tidy / fmt.

This commit is contained in:
Emilio Cobos Álvarez 2019-04-11 22:16:56 +02:00
parent 8c004c0858
commit 49842f5031
23 changed files with 165 additions and 53 deletions

45
Cargo.lock generated
View file

@ -942,6 +942,17 @@ dependencies = [
"deny_public_fields 0.0.1", "deny_public_fields 0.0.1",
] ]
[[package]]
name = "derive_common"
version = "0.0.1"
dependencies = [
"darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "0.13.0" version = "0.13.0"
@ -3646,6 +3657,8 @@ dependencies = [
"servo_arc 0.1.1", "servo_arc 0.1.1",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"to_shmem 0.0.1",
"to_shmem_derive 0.0.1",
] ]
[[package]] [[package]]
@ -3992,6 +4005,8 @@ dependencies = [
"malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_rand 0.0.1", "servo_rand 0.0.1",
"to_shmem 0.0.1",
"to_shmem_derive 0.0.1",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4240,6 +4255,8 @@ dependencies = [
"style_traits 0.0.1", "style_traits 0.0.1",
"thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"to_shmem 0.0.1",
"to_shmem_derive 0.0.1",
"toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"uluru 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "uluru 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4253,6 +4270,7 @@ name = "style_derive"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_common 0.0.1",
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4297,6 +4315,8 @@ dependencies = [
"servo_arc 0.1.1", "servo_arc 0.1.1",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"to_shmem 0.0.1",
"to_shmem_derive 0.0.1",
"webrender_api 0.60.0 (git+https://github.com/servo/webrender)", "webrender_api 0.60.0 (git+https://github.com/servo/webrender)",
] ]
@ -4435,6 +4455,31 @@ dependencies = [
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "to_shmem"
version = "0.0.1"
dependencies = [
"cssparser 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_arc 0.1.1",
"smallbitvec 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "to_shmem_derive"
version = "0.0.1"
dependencies = [
"darling 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"derive_common 0.0.1",
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "0.1.8" version = "0.1.8"

View file

@ -26,7 +26,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{font_stretch, font_style, font_variant_caps, font_weight}; use style::computed_values::{font_stretch, font_style, font_variant_caps, font_weight};
use style::properties::style_structs::Font as FontStyleStruct; use style::properties::style_structs::Font as FontStyleStruct;
use style::values::computed::font::SingleFontFamily; use style::values::computed::font::{GenericFontFamily, SingleFontFamily};
use unicode_script::Script; use unicode_script::Script;
macro_rules! ot_tag { macro_rules! ot_tag {
@ -564,9 +564,14 @@ impl<'a> From<&'a SingleFontFamily> for FontFamilyName {
FontFamilyName::Specific(family_name.name.clone()) FontFamilyName::Specific(family_name.name.clone())
}, },
SingleFontFamily::Generic(ref generic_name) => { SingleFontFamily::Generic(generic) => FontFamilyName::Generic(match generic {
FontFamilyName::Generic(generic_name.clone()) GenericFontFamily::None => panic!("Shouldn't appear in style"),
}, GenericFontFamily::Serif => atom!("serif"),
GenericFontFamily::SansSerif => atom!("sans-serif"),
GenericFontFamily::Monospace => atom!("monospace"),
GenericFontFamily::Cursive => atom!("cursive"),
GenericFontFamily::Fantasy => atom!("fantasy"),
}),
} }
} }
} }

View file

@ -19,9 +19,10 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::length::{MaxSize, NonNegativeLengthOrAuto, Size}; use style::values::computed::length::{
MaxSize, NonNegativeLengthOrAuto, NonNegativeLengthPercentageOrNormal, Size,
};
use style::values::generics::column::ColumnCount; use style::values::generics::column::ColumnCount;
use style::values::Either;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe impl crate::flow::HasBaseFlow for MulticolFlow {} unsafe impl crate::flow::HasBaseFlow for MulticolFlow {}
@ -106,8 +107,10 @@ impl Flow for MulticolFlow {
{ {
let style = &self.block_flow.fragment.style; let style = &self.block_flow.fragment.style;
let column_gap = match style.get_position().column_gap { let column_gap = match style.get_position().column_gap {
Either::First(len) => len.0.to_pixel_length(content_inline_size).into(), NonNegativeLengthPercentageOrNormal::LengthPercentage(len) => {
Either::Second(_normal) => { len.0.to_pixel_length(content_inline_size).into()
},
NonNegativeLengthPercentageOrNormal::Normal => {
self.block_flow.fragment.style.get_font().font_size.size() self.block_flow.fragment.style.get_font().font_size.size()
}, },
}; };

View file

@ -643,6 +643,7 @@ impl LayoutElementHelpers for LayoutDom<Element> {
}; };
if let Some(font_family) = font_family { if let Some(font_family) = font_family {
// FIXME(emilio): This in Gecko parses a whole family list.
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values( PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values(

View file

@ -20,7 +20,7 @@ gecko = ["style_traits/gecko", "fallible/known_system_malloc"]
use_bindgen = ["bindgen", "regex", "toml"] use_bindgen = ["bindgen", "regex", "toml"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever", servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union", "cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
"servo_url", "string_cache", "crossbeam-channel"] "servo_url", "string_cache", "crossbeam-channel", "to_shmem/servo", "servo_arc/servo"]
gecko_debug = [] gecko_debug = []
[dependencies] [dependencies]

View file

@ -70,7 +70,7 @@ impl FontMetricsProvider for ServoMetricsProvider {
ServoMetricsProvider ServoMetricsProvider
} }
fn get_size(&self, _font_name: &Atom, _font_family: u8) -> Au { fn get_size(&self, _: &Atom, _: crate::values::computed::font::GenericFontFamily) -> Au {
unreachable!("Dummy provider should never be used to compute font size") unreachable!("Dummy provider should never be used to compute font size")
} }
} }

View file

@ -123,7 +123,7 @@ impl MallocSizeOf for CssUrl {
} }
/// A key type for URL_VALUE_TABLE. /// A key type for URL_VALUE_TABLE.
#[derive(Hash, PartialEq, Eq)] #[derive(Eq, Hash, PartialEq)]
struct CssUrlDataKey(*const CssUrlData); struct CssUrlDataKey(*const CssUrlData);
unsafe impl Sync for CssUrlDataKey {} unsafe impl Sync for CssUrlDataKey {}

View file

@ -25,7 +25,7 @@ use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCs
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData}; use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
use super::*; use super::*;
use crate::values::computed::Context; use crate::values::computed::Context;
use crate::selector_parser::{SelectorImpl}; use crate::selector_parser::SelectorImpl;
use selectors::SelectorList; use selectors::SelectorList;
/// The animation rules. /// The animation rules.

View file

@ -495,8 +495,7 @@ ${helpers.predefined_type(
// a lot of code with `if product == gecko` conditionals, we have a // a lot of code with `if product == gecko` conditionals, we have a
// dummy system font module that does nothing // dummy system font module that does nothing
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)] #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
/// void enum for system font, can never exist /// void enum for system font, can never exist
pub enum SystemFont {} pub enum SystemFont {}
impl SystemFont { impl SystemFont {

View file

@ -29,8 +29,7 @@ use style_traits::{ParseError, StyleParseErrorKind};
/// A pseudo-element, both public and private. /// A pseudo-element, both public and private.
/// ///
/// NB: If you add to this list, be sure to update `each_simple_pseudo_element` too. /// NB: If you add to this list, be sure to update `each_simple_pseudo_element` too.
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[allow(missing_docs)] #[allow(missing_docs)]
#[repr(usize)] #[repr(usize)]
pub enum PseudoElement { pub enum PseudoElement {
@ -265,8 +264,7 @@ pub type Lang = Box<str>;
/// A non tree-structural pseudo-class. /// A non tree-structural pseudo-class.
/// See https://drafts.csswg.org/selectors-4/#structural-pseudos /// See https://drafts.csswg.org/selectors-4/#structural-pseudos
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum NonTSPseudoClass { pub enum NonTSPseudoClass {
Active, Active,

View file

@ -12,7 +12,7 @@ use std::fmt::{self, Write};
// nonzero optimization is important in keeping the size of SpecifiedUrl below // nonzero optimization is important in keeping the size of SpecifiedUrl below
// the threshold. // the threshold.
use crate::values::computed::{Context, ToComputedValue}; use crate::values::computed::{Context, ToComputedValue};
use std::sync::Arc; use servo_arc::Arc;
use style_traits::{CssWriter, ParseError, ToCss}; use style_traits::{CssWriter, ParseError, ToCss};
/// A CSS url() value for servo. /// A CSS url() value for servo.
@ -26,7 +26,7 @@ use style_traits::{CssWriter, ParseError, ToCss};
/// ///
/// TODO(emilio): This should be shrunk by making CssUrl a wrapper type of an /// TODO(emilio): This should be shrunk by making CssUrl a wrapper type of an
/// arc, and keep the serialization in that Arc. See gecko/url.rs for example. /// arc, and keep the serialization in that Arc. See gecko/url.rs for example.
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, SpecifiedValueInfo)] #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, SpecifiedValueInfo, ToShmem)]
pub struct CssUrl { pub struct CssUrl {
/// The original URI. This might be optional since we may insert computed /// The original URI. This might be optional since we may insert computed
/// values of images into the cascade directly, and we don't bother to /// values of images into the cascade directly, and we don't bother to

View file

@ -15,7 +15,6 @@ use std::cell::UnsafeCell;
use std::fmt; use std::fmt;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use std::mem; use std::mem;
#[cfg(feature = "gecko")]
use std::mem::ManuallyDrop; use std::mem::ManuallyDrop;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use std::ptr; use std::ptr;
@ -124,11 +123,7 @@ impl<'a> Drop for SharedRwLockReadGuard<'a> {
fn drop(&mut self) { fn drop(&mut self) {
// Unsafe: self.lock is private to this module, only ever set after `read()`, // Unsafe: self.lock is private to this module, only ever set after `read()`,
// and never copied or cloned (see `compile_time_assert` below). // and never copied or cloned (see `compile_time_assert` below).
if let Some(arc) = self.0.arc { unsafe { self.0.arc.force_unlock_read() }
unsafe {
arc.force_unlock_read();
}
}
} }
} }
@ -166,12 +161,6 @@ impl<T: fmt::Debug> fmt::Debug for Locked<T> {
} }
impl<T> Locked<T> { impl<T> Locked<T> {
#[cfg(feature = "servo")]
#[inline]
fn is_read_only_lock(&self) -> bool {
false
}
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
#[inline] #[inline]
fn is_read_only_lock(&self) -> bool { fn is_read_only_lock(&self) -> bool {
@ -199,10 +188,14 @@ impl<T> Locked<T> {
/// Access the data for reading. /// Access the data for reading.
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T { pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
#[cfg(feature = "gecko")]
assert!( assert!(
self.is_read_only_lock() || self.same_lock_as(guard.0.as_ref().map(|r| &**r)), self.is_read_only_lock() || self.same_lock_as(guard.0.as_ref().map(|r| &**r)),
"Locked::read_with called with a guard from an unrelated SharedRwLock" "Locked::read_with called with a guard from an unrelated SharedRwLock"
); );
#[cfg(not(feature = "gecko"))]
assert!(self.same_lock_as(&guard.0));
let ptr = self.data.get(); let ptr = self.data.get();
// Unsafe: // Unsafe:
@ -223,10 +216,14 @@ impl<T> Locked<T> {
/// Access the data for writing. /// Access the data for writing.
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T { pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
#[cfg(feature = "gecko")]
assert!( assert!(
!self.is_read_only_lock() && self.same_lock_as(Some(&guard.0)), !self.is_read_only_lock() && self.same_lock_as(Some(&guard.0)),
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock" "Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
); );
#[cfg(not(feature = "gecko"))]
assert!(self.same_lock_as(&guard.0));
let ptr = self.data.get(); let ptr = self.data.get();
// Unsafe: // Unsafe:

View file

@ -39,6 +39,7 @@ use std::fmt;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use std::mem::{self, ManuallyDrop}; use std::mem::{self, ManuallyDrop};
use style_traits::ParsingMode; use style_traits::ParsingMode;
#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem}; use to_shmem::{SharedMemoryBuilder, ToShmem};
pub use self::counter_style_rule::CounterStyleRule; pub use self::counter_style_rule::CounterStyleRule;

View file

@ -29,6 +29,7 @@ use std::mem::{self, ManuallyDrop};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use std::slice; use std::slice;
use style_traits::{CssWriter, ParseError, ToCss}; use style_traits::{CssWriter, ParseError, ToCss};
#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem}; use to_shmem::{SharedMemoryBuilder, ToShmem};
pub use crate::values::computed::Length as MozScriptMinSize; pub use crate::values::computed::Length as MozScriptMinSize;
@ -284,7 +285,7 @@ pub enum FontFamilyNameSyntax {
Identifiers, Identifiers,
} }
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)] #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))]
/// A set of faces that vary in weight, width or slope. /// A set of faces that vary in weight, width or slope.
pub enum SingleFontFamily { pub enum SingleFontFamily {
@ -299,7 +300,10 @@ pub enum SingleFontFamily {
/// The order here is important, if you change it make sure that /// The order here is important, if you change it make sure that
/// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s /// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s
/// sSingleGenerics are updated as well. /// sSingleGenerics are updated as well.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToResolvedValue)] #[derive(
Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToResolvedValue, ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(u8)] #[repr(u8)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum GenericFontFamily { pub enum GenericFontFamily {
@ -373,6 +377,35 @@ impl SingleFontFamily {
})) }))
} }
#[cfg(feature = "servo")]
/// Get the corresponding font-family with Atom
pub fn from_atom(input: Atom) -> SingleFontFamily {
match input {
atom!("serif") => return SingleFontFamily::Generic(GenericFontFamily::Serif),
atom!("sans-serif") => return SingleFontFamily::Generic(GenericFontFamily::SansSerif),
atom!("cursive") => return SingleFontFamily::Generic(GenericFontFamily::Cursive),
atom!("fantasy") => return SingleFontFamily::Generic(GenericFontFamily::Fantasy),
atom!("monospace") => return SingleFontFamily::Generic(GenericFontFamily::Monospace),
_ => {},
}
match_ignore_ascii_case! { &input,
"serif" => return SingleFontFamily::Generic(GenericFontFamily::Serif),
"sans-serif" => return SingleFontFamily::Generic(GenericFontFamily::SansSerif),
"cursive" => return SingleFontFamily::Generic(GenericFontFamily::Cursive),
"fantasy" => return SingleFontFamily::Generic(GenericFontFamily::Fantasy),
"monospace" => return SingleFontFamily::Generic(GenericFontFamily::Monospace),
_ => {}
}
// We don't know if it's quoted or not. So we set it to
// quoted by default.
SingleFontFamily::FamilyName(FamilyName {
name: input,
syntax: FontFamilyNameSyntax::Quoted,
})
}
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
/// Get the corresponding font-family with family name /// Get the corresponding font-family with family name
fn from_font_family_name(family: &structs::FontFamilyName) -> SingleFontFamily { fn from_font_family_name(family: &structs::FontFamilyName) -> SingleFontFamily {
@ -389,7 +422,7 @@ impl SingleFontFamily {
} }
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue)] #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
/// A list of SingleFontFamily /// A list of SingleFontFamily
pub struct FontFamilyList(Box<[SingleFontFamily]>); pub struct FontFamilyList(Box<[SingleFontFamily]>);
@ -501,7 +534,7 @@ impl FontFamilyList {
let mut iter = self.iter(); let mut iter = self.iter();
if let Some(SingleFontFamily::Generic(f)) = iter.next() { if let Some(SingleFontFamily::Generic(f)) = iter.next() {
if iter.next().is_none() { if iter.next().is_none() {
return Some(f); return Some(f.clone());
} }
} }
None None

View file

@ -557,7 +557,7 @@ pub enum TrackListType {
/// A grid `<track-list>` type. /// A grid `<track-list>` type.
/// ///
/// <https://drafts.csswg.org/css-grid/#typedef-track-list> /// <https://drafts.csswg.org/css-grid/#typedef-track-list>
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem, ToResolvedValue)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToResolvedValue, ToShmem)]
pub struct TrackList<LengthPercentage, Integer> { pub struct TrackList<LengthPercentage, Integer> {
/// The type of this `<track-list>` (auto, explicit or general). /// The type of this `<track-list>` (auto, explicit or general).
/// ///

View file

@ -157,7 +157,7 @@ pub struct ColorStop<Color, LengthPercentage> {
/// Specified values for a paint worklet. /// Specified values for a paint worklet.
/// <https://drafts.css-houdini.org/css-paint-api/> /// <https://drafts.css-houdini.org/css-paint-api/>
#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Debug, PartialEq, ToComputedValue)] #[derive(Clone, Debug, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
pub struct PaintWorklet { pub struct PaintWorklet {
/// The name the worklet was registered with. /// The name the worklet was registered with.
pub name: Atom, pub name: Atom,

View file

@ -65,15 +65,16 @@ trivial_to_resolved_value!(u8);
trivial_to_resolved_value!(i8); trivial_to_resolved_value!(i8);
trivial_to_resolved_value!(u16); trivial_to_resolved_value!(u16);
trivial_to_resolved_value!(u32); trivial_to_resolved_value!(u32);
#[cfg(feature = "servo")]
trivial_to_resolved_value!(Prefix);
trivial_to_resolved_value!(String); trivial_to_resolved_value!(String);
trivial_to_resolved_value!(Box<str>); trivial_to_resolved_value!(Box<str>);
trivial_to_resolved_value!(cssparser::RGBA); trivial_to_resolved_value!(cssparser::RGBA);
trivial_to_resolved_value!(crate::Atom); trivial_to_resolved_value!(crate::Atom);
trivial_to_resolved_value!(app_units::Au); trivial_to_resolved_value!(app_units::Au);
trivial_to_resolved_value!(computed::url::ComputedUrl); trivial_to_resolved_value!(computed::url::ComputedUrl);
#[cfg(feature = "gecko")]
trivial_to_resolved_value!(computed::url::ComputedImageUrl); trivial_to_resolved_value!(computed::url::ComputedImageUrl);
#[cfg(feature = "servo")]
trivial_to_resolved_value!(html5ever::Prefix);
impl<A, B> ToResolvedValue for (A, B) impl<A, B> ToResolvedValue for (A, B)
where where

View file

@ -1192,7 +1192,7 @@ macro_rules! impl_variant_east_asian {
)+ )+
} => { } => {
bitflags! { bitflags! {
#[derive(MallocSizeOf, ToShmem, ToResolvedValue)] #[derive(MallocSizeOf, ToResolvedValue, ToShmem)]
/// Vairants for east asian variant /// Vairants for east asian variant
pub struct VariantEastAsian: u16 { pub struct VariantEastAsian: u16 {
/// None of the features /// None of the features

View file

@ -10,13 +10,14 @@ name = "to_shmem"
path = "lib.rs" path = "lib.rs"
[features] [features]
servo = ["serde", "cssparser/serde"] servo = ["serde", "cssparser/serde", "string_cache"]
gecko = [] gecko = []
[dependencies] [dependencies]
cssparser = "0.25" cssparser = "0.25"
serde = {version = "1.0", optional = true} serde = { version = "1.0", optional = true }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
smallbitvec = "2.1.1" smallbitvec = "2.1.1"
smallvec = "0.6.6" smallvec = "0.6.6"
string_cache = { version = "0.7", optional = true }
thin-slice = "0.1.0" thin-slice = "0.1.0"

View file

@ -16,6 +16,8 @@ extern crate cssparser;
extern crate servo_arc; extern crate servo_arc;
extern crate smallbitvec; extern crate smallbitvec;
extern crate smallvec; extern crate smallvec;
#[cfg(feature = "string_cache")]
extern crate string_cache;
extern crate thin_slice; extern crate thin_slice;
use servo_arc::{Arc, ThinArc}; use servo_arc::{Arc, ThinArc};
@ -193,16 +195,18 @@ pub trait ToShmem: Sized {
#[macro_export] #[macro_export]
macro_rules! impl_trivial_to_shmem { macro_rules! impl_trivial_to_shmem {
($($ty:ty),*) => {$( ($($ty:ty),*) => {
impl $crate::ToShmem for $ty { $(
fn to_shmem( impl $crate::ToShmem for $ty {
&self, fn to_shmem(
_builder: &mut $crate::SharedMemoryBuilder, &self,
) -> ::std::mem::ManuallyDrop<Self> { _builder: &mut $crate::SharedMemoryBuilder,
::std::mem::ManuallyDrop::new(*self) ) -> ::std::mem::ManuallyDrop<Self> {
::std::mem::ManuallyDrop::new(*self)
}
} }
} )*
)*}; };
} }
impl_trivial_to_shmem!( impl_trivial_to_shmem!(
@ -522,3 +526,17 @@ impl ToShmem for SmallBitVec {
ManuallyDrop::new(unsafe { SmallBitVec::from_storage(storage) }) ManuallyDrop::new(unsafe { SmallBitVec::from_storage(storage) })
} }
} }
#[cfg(feature = "string_cache")]
impl<Static: string_cache::StaticAtomSet> ToShmem for string_cache::Atom<Static> {
fn to_shmem(&self, _: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
// NOTE(emilio): In practice, this can be implemented trivially if
// string_cache could expose the implementation detail of static atoms
// being an index into the static table (and panicking in the
// non-static, non-inline cases).
unimplemented!(
"If servo wants to share stylesheets across processes, \
then ToShmem for Atom needs to be implemented"
)
}
}

View file

@ -40,7 +40,7 @@ pub fn derive(mut input: syn::DeriveInput) -> TokenStream {
quote! { quote! {
impl #impl_generics ::to_shmem::ToShmem for #name #ty_generics #where_clause { impl #impl_generics ::to_shmem::ToShmem for #name #ty_generics #where_clause {
#[allow(unused_variables)] #[allow(unused_variables, unreachable_code)]
fn to_shmem( fn to_shmem(
&self, &self,
builder: &mut ::to_shmem::SharedMemoryBuilder, builder: &mut ::to_shmem::SharedMemoryBuilder,

View file

@ -13,6 +13,8 @@ path = "lib.rs"
[dependencies] [dependencies]
malloc_size_of = { path = "../malloc_size_of", features = ["servo"] } malloc_size_of = { path = "../malloc_size_of", features = ["servo"] }
malloc_size_of_derive = "0.1" malloc_size_of_derive = "0.1"
to_shmem = { path = "../to_shmem" }
to_shmem_derive = { path = "../to_shmem_derive" }
serde = {version = "1.0", features = ["derive"]} serde = {version = "1.0", features = ["derive"]}
servo_rand = {path = "../rand"} servo_rand = {path = "../rand"}
url = "1.2" url = "1.2"

View file

@ -20,10 +20,12 @@ pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin};
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::fmt; use std::fmt;
use std::hash::Hasher; use std::hash::Hasher;
use std::mem::ManuallyDrop;
use std::net::IpAddr; use std::net::IpAddr;
use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo}; use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo};
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use to_shmem::{SharedMemoryBuilder, ToShmem};
use url::{Position, Url}; use url::{Position, Url};
pub use url::Host; pub use url::Host;
@ -31,6 +33,12 @@ pub use url::Host;
#[derive(Clone, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd)] #[derive(Clone, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd)]
pub struct ServoUrl(#[ignore_malloc_size_of = "Arc"] Arc<Url>); pub struct ServoUrl(#[ignore_malloc_size_of = "Arc"] Arc<Url>);
impl ToShmem for ServoUrl {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
unimplemented!("If servo wants to share stylesheets across processes, ToShmem for Url must be implemented")
}
}
impl ServoUrl { impl ServoUrl {
pub fn from_url(url: Url) -> Self { pub fn from_url(url: Url) -> Self {
ServoUrl(Arc::new(url)) ServoUrl(Arc::new(url))