aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-04-11 22:16:56 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-04-12 12:20:15 +0200
commit49842f50312787fc4f89c88536d7fc9e87583b06 (patch)
tree0f0c196c4d49f612ac8934fd145f6c35a7786d32
parent8c004c08580287172585169807ed36933ad674f8 (diff)
downloadservo-49842f50312787fc4f89c88536d7fc9e87583b06.tar.gz
servo-49842f50312787fc4f89c88536d7fc9e87583b06.zip
style: Fix servo build, and appease tidy / fmt.
-rw-r--r--Cargo.lock45
-rw-r--r--components/gfx/font.rs13
-rw-r--r--components/layout/multicol.rs11
-rw-r--r--components/script/dom/element.rs1
-rw-r--r--components/style/Cargo.toml2
-rw-r--r--components/style/font_metrics.rs2
-rw-r--r--components/style/gecko/url.rs2
-rw-r--r--components/style/properties/declaration_block.rs2
-rw-r--r--components/style/properties/longhands/font.mako.rs3
-rw-r--r--components/style/servo/selector_parser.rs6
-rw-r--r--components/style/servo/url.rs4
-rw-r--r--components/style/shared_lock.rs21
-rw-r--r--components/style/stylesheets/mod.rs1
-rw-r--r--components/style/values/computed/font.rs41
-rw-r--r--components/style/values/generics/grid.rs2
-rw-r--r--components/style/values/generics/image.rs2
-rw-r--r--components/style/values/resolved/mod.rs5
-rw-r--r--components/style/values/specified/font.rs2
-rw-r--r--components/to_shmem/Cargo.toml5
-rw-r--r--components/to_shmem/lib.rs36
-rw-r--r--components/to_shmem_derive/to_shmem.rs2
-rw-r--r--components/url/Cargo.toml2
-rw-r--r--components/url/lib.rs8
23 files changed, 165 insertions, 53 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ea625f81909..8164783500d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -943,6 +943,17 @@ dependencies = [
]
[[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]]
name = "derive_more"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3646,6 +3657,8 @@ dependencies = [
"servo_arc 0.1.1",
"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)",
+ "to_shmem 0.0.1",
+ "to_shmem_derive 0.0.1",
]
[[package]]
@@ -3992,6 +4005,8 @@ dependencies = [
"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)",
"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_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)",
@@ -4240,6 +4255,8 @@ dependencies = [
"style_traits 0.0.1",
"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)",
+ "to_shmem 0.0.1",
+ "to_shmem_derive 0.0.1",
"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)",
"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"
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)",
@@ -4297,6 +4315,8 @@ dependencies = [
"servo_arc 0.1.1",
"servo_atoms 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)",
]
@@ -4436,6 +4456,31 @@ dependencies = [
]
[[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]]
name = "tokio"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/components/gfx/font.rs b/components/gfx/font.rs
index cd9513a3f43..35ce19621ac 100644
--- a/components/gfx/font.rs
+++ b/components/gfx/font.rs
@@ -26,7 +26,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use style::computed_values::{font_stretch, font_style, font_variant_caps, font_weight};
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;
macro_rules! ot_tag {
@@ -564,9 +564,14 @@ impl<'a> From<&'a SingleFontFamily> for FontFamilyName {
FontFamilyName::Specific(family_name.name.clone())
},
- SingleFontFamily::Generic(ref generic_name) => {
- FontFamilyName::Generic(generic_name.clone())
- },
+ SingleFontFamily::Generic(generic) => FontFamilyName::Generic(match generic {
+ 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"),
+ }),
}
}
}
diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs
index f8ddfa8200c..46ccbc64653 100644
--- a/components/layout/multicol.rs
+++ b/components/layout/multicol.rs
@@ -19,9 +19,10 @@ use std::fmt;
use std::sync::Arc;
use style::logical_geometry::LogicalSize;
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::Either;
#[allow(unsafe_code)]
unsafe impl crate::flow::HasBaseFlow for MulticolFlow {}
@@ -106,8 +107,10 @@ impl Flow for MulticolFlow {
{
let style = &self.block_flow.fragment.style;
let column_gap = match style.get_position().column_gap {
- Either::First(len) => len.0.to_pixel_length(content_inline_size).into(),
- Either::Second(_normal) => {
+ NonNegativeLengthPercentageOrNormal::LengthPercentage(len) => {
+ len.0.to_pixel_length(content_inline_size).into()
+ },
+ NonNegativeLengthPercentageOrNormal::Normal => {
self.block_flow.fragment.style.get_font().font_size.size()
},
};
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index eb48c22865b..6da5d92fdb1 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -643,6 +643,7 @@ impl LayoutElementHelpers for LayoutDom<Element> {
};
if let Some(font_family) = font_family {
+ // FIXME(emilio): This in Gecko parses a whole family list.
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values(
diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml
index 005924cec21..0bc745015fd 100644
--- a/components/style/Cargo.toml
+++ b/components/style/Cargo.toml
@@ -20,7 +20,7 @@ gecko = ["style_traits/gecko", "fallible/known_system_malloc"]
use_bindgen = ["bindgen", "regex", "toml"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"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 = []
[dependencies]
diff --git a/components/style/font_metrics.rs b/components/style/font_metrics.rs
index a45ebc297d9..8e69118ade4 100644
--- a/components/style/font_metrics.rs
+++ b/components/style/font_metrics.rs
@@ -70,7 +70,7 @@ impl FontMetricsProvider for 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")
}
}
diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs
index 2c61ab4db0b..2da16043779 100644
--- a/components/style/gecko/url.rs
+++ b/components/style/gecko/url.rs
@@ -123,7 +123,7 @@ impl MallocSizeOf for CssUrl {
}
/// A key type for URL_VALUE_TABLE.
-#[derive(Hash, PartialEq, Eq)]
+#[derive(Eq, Hash, PartialEq)]
struct CssUrlDataKey(*const CssUrlData);
unsafe impl Sync for CssUrlDataKey {}
diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs
index c86f5bac9ee..42fc833e4b9 100644
--- a/components/style/properties/declaration_block.rs
+++ b/components/style/properties/declaration_block.rs
@@ -25,7 +25,7 @@ use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCs
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
use super::*;
use crate::values::computed::Context;
-use crate::selector_parser::{SelectorImpl};
+use crate::selector_parser::SelectorImpl;
use selectors::SelectorList;
/// The animation rules.
diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs
index 7f7b66c3572..c1d3d8fcc6c 100644
--- a/components/style/properties/longhands/font.mako.rs
+++ b/components/style/properties/longhands/font.mako.rs
@@ -495,8 +495,7 @@ ${helpers.predefined_type(
// a lot of code with `if product == gecko` conditionals, we have a
// dummy system font module that does nothing
- #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)]
- #[cfg_attr(feature = "servo", derive(MallocSizeOf))]
+ #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// void enum for system font, can never exist
pub enum SystemFont {}
impl SystemFont {
diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs
index 229f7dccdd2..d839654a65a 100644
--- a/components/style/servo/selector_parser.rs
+++ b/components/style/servo/selector_parser.rs
@@ -29,8 +29,7 @@ use style_traits::{ParseError, StyleParseErrorKind};
/// A pseudo-element, both public and private.
///
/// NB: If you add to this list, be sure to update `each_simple_pseudo_element` too.
-#[derive(Clone, Debug, Eq, Hash, PartialEq)]
-#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
+#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[allow(missing_docs)]
#[repr(usize)]
pub enum PseudoElement {
@@ -265,8 +264,7 @@ pub type Lang = Box<str>;
/// A non tree-structural pseudo-class.
/// See https://drafts.csswg.org/selectors-4/#structural-pseudos
-#[derive(Clone, Debug, Eq, Hash, PartialEq)]
-#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
+#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
#[allow(missing_docs)]
pub enum NonTSPseudoClass {
Active,
diff --git a/components/style/servo/url.rs b/components/style/servo/url.rs
index 26608de2e29..fd7726289be 100644
--- a/components/style/servo/url.rs
+++ b/components/style/servo/url.rs
@@ -12,7 +12,7 @@ use std::fmt::{self, Write};
// nonzero optimization is important in keeping the size of SpecifiedUrl below
// the threshold.
use crate::values::computed::{Context, ToComputedValue};
-use std::sync::Arc;
+use servo_arc::Arc;
use style_traits::{CssWriter, ParseError, ToCss};
/// 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
/// 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 {
/// 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
diff --git a/components/style/shared_lock.rs b/components/style/shared_lock.rs
index f5019326ee0..073c696fa3d 100644
--- a/components/style/shared_lock.rs
+++ b/components/style/shared_lock.rs
@@ -15,7 +15,6 @@ use std::cell::UnsafeCell;
use std::fmt;
#[cfg(feature = "servo")]
use std::mem;
-#[cfg(feature = "gecko")]
use std::mem::ManuallyDrop;
#[cfg(feature = "gecko")]
use std::ptr;
@@ -124,11 +123,7 @@ impl<'a> Drop for SharedRwLockReadGuard<'a> {
fn drop(&mut self) {
// Unsafe: self.lock is private to this module, only ever set after `read()`,
// and never copied or cloned (see `compile_time_assert` below).
- if let Some(arc) = self.0.arc {
- unsafe {
- arc.force_unlock_read();
- }
- }
+ unsafe { self.0.arc.force_unlock_read() }
}
}
@@ -166,12 +161,6 @@ impl<T: fmt::Debug> fmt::Debug for Locked<T> {
}
impl<T> Locked<T> {
- #[cfg(feature = "servo")]
- #[inline]
- fn is_read_only_lock(&self) -> bool {
- false
- }
-
#[cfg(feature = "gecko")]
#[inline]
fn is_read_only_lock(&self) -> bool {
@@ -199,10 +188,14 @@ impl<T> Locked<T> {
/// Access the data for reading.
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
+ #[cfg(feature = "gecko")]
assert!(
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"
);
+ #[cfg(not(feature = "gecko"))]
+ assert!(self.same_lock_as(&guard.0));
+
let ptr = self.data.get();
// Unsafe:
@@ -223,10 +216,14 @@ impl<T> Locked<T> {
/// Access the data for writing.
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
+ #[cfg(feature = "gecko")]
assert!(
!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"
);
+ #[cfg(not(feature = "gecko"))]
+ assert!(self.same_lock_as(&guard.0));
+
let ptr = self.data.get();
// Unsafe:
diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs
index 133b84fa52f..16842021e8d 100644
--- a/components/style/stylesheets/mod.rs
+++ b/components/style/stylesheets/mod.rs
@@ -39,6 +39,7 @@ use std::fmt;
#[cfg(feature = "gecko")]
use std::mem::{self, ManuallyDrop};
use style_traits::ParsingMode;
+#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem};
pub use self::counter_style_rule::CounterStyleRule;
diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs
index 001b8444a30..407a547013f 100644
--- a/components/style/values/computed/font.rs
+++ b/components/style/values/computed/font.rs
@@ -29,6 +29,7 @@ use std::mem::{self, ManuallyDrop};
#[cfg(feature = "servo")]
use std::slice;
use style_traits::{CssWriter, ParseError, ToCss};
+#[cfg(feature = "gecko")]
use to_shmem::{SharedMemoryBuilder, ToShmem};
pub use crate::values::computed::Length as MozScriptMinSize;
@@ -284,7 +285,7 @@ pub enum FontFamilyNameSyntax {
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))]
/// A set of faces that vary in weight, width or slope.
pub enum SingleFontFamily {
@@ -299,7 +300,10 @@ pub enum SingleFontFamily {
/// The order here is important, if you change it make sure that
/// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s
/// 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)]
#[allow(missing_docs)]
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")]
/// Get the corresponding font-family with family name
fn from_font_family_name(family: &structs::FontFamilyName) -> SingleFontFamily {
@@ -389,7 +422,7 @@ impl SingleFontFamily {
}
#[cfg(feature = "servo")]
-#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue)]
+#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
/// A list of SingleFontFamily
pub struct FontFamilyList(Box<[SingleFontFamily]>);
@@ -501,7 +534,7 @@ impl FontFamilyList {
let mut iter = self.iter();
if let Some(SingleFontFamily::Generic(f)) = iter.next() {
if iter.next().is_none() {
- return Some(f);
+ return Some(f.clone());
}
}
None
diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs
index 393e570f066..d20ba265ab2 100644
--- a/components/style/values/generics/grid.rs
+++ b/components/style/values/generics/grid.rs
@@ -557,7 +557,7 @@ pub enum TrackListType {
/// A grid `<track-list>` type.
///
/// <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> {
/// The type of this `<track-list>` (auto, explicit or general).
///
diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs
index a7fa6da9337..71d6a1b3849 100644
--- a/components/style/values/generics/image.rs
+++ b/components/style/values/generics/image.rs
@@ -157,7 +157,7 @@ pub struct ColorStop<Color, LengthPercentage> {
/// Specified values for a paint worklet.
/// <https://drafts.css-houdini.org/css-paint-api/>
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
-#[derive(Clone, Debug, PartialEq, ToComputedValue)]
+#[derive(Clone, Debug, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
pub struct PaintWorklet {
/// The name the worklet was registered with.
pub name: Atom,
diff --git a/components/style/values/resolved/mod.rs b/components/style/values/resolved/mod.rs
index 7877ed71a0b..4003060148c 100644
--- a/components/style/values/resolved/mod.rs
+++ b/components/style/values/resolved/mod.rs
@@ -65,15 +65,16 @@ trivial_to_resolved_value!(u8);
trivial_to_resolved_value!(i8);
trivial_to_resolved_value!(u16);
trivial_to_resolved_value!(u32);
-#[cfg(feature = "servo")]
-trivial_to_resolved_value!(Prefix);
trivial_to_resolved_value!(String);
trivial_to_resolved_value!(Box<str>);
trivial_to_resolved_value!(cssparser::RGBA);
trivial_to_resolved_value!(crate::Atom);
trivial_to_resolved_value!(app_units::Au);
trivial_to_resolved_value!(computed::url::ComputedUrl);
+#[cfg(feature = "gecko")]
trivial_to_resolved_value!(computed::url::ComputedImageUrl);
+#[cfg(feature = "servo")]
+trivial_to_resolved_value!(html5ever::Prefix);
impl<A, B> ToResolvedValue for (A, B)
where
diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs
index f02d44124a2..127b1bfc2fb 100644
--- a/components/style/values/specified/font.rs
+++ b/components/style/values/specified/font.rs
@@ -1192,7 +1192,7 @@ macro_rules! impl_variant_east_asian {
)+
} => {
bitflags! {
- #[derive(MallocSizeOf, ToShmem, ToResolvedValue)]
+ #[derive(MallocSizeOf, ToResolvedValue, ToShmem)]
/// Vairants for east asian variant
pub struct VariantEastAsian: u16 {
/// None of the features
diff --git a/components/to_shmem/Cargo.toml b/components/to_shmem/Cargo.toml
index bebc45e821d..2e7b06eaaca 100644
--- a/components/to_shmem/Cargo.toml
+++ b/components/to_shmem/Cargo.toml
@@ -10,13 +10,14 @@ name = "to_shmem"
path = "lib.rs"
[features]
-servo = ["serde", "cssparser/serde"]
+servo = ["serde", "cssparser/serde", "string_cache"]
gecko = []
[dependencies]
cssparser = "0.25"
-serde = {version = "1.0", optional = true}
+serde = { version = "1.0", optional = true }
servo_arc = { path = "../servo_arc" }
smallbitvec = "2.1.1"
smallvec = "0.6.6"
+string_cache = { version = "0.7", optional = true }
thin-slice = "0.1.0"
diff --git a/components/to_shmem/lib.rs b/components/to_shmem/lib.rs
index 59fc2afb546..96dfbb3a5e9 100644
--- a/components/to_shmem/lib.rs
+++ b/components/to_shmem/lib.rs
@@ -16,6 +16,8 @@ extern crate cssparser;
extern crate servo_arc;
extern crate smallbitvec;
extern crate smallvec;
+#[cfg(feature = "string_cache")]
+extern crate string_cache;
extern crate thin_slice;
use servo_arc::{Arc, ThinArc};
@@ -193,16 +195,18 @@ pub trait ToShmem: Sized {
#[macro_export]
macro_rules! impl_trivial_to_shmem {
- ($($ty:ty),*) => {$(
- impl $crate::ToShmem for $ty {
- fn to_shmem(
- &self,
- _builder: &mut $crate::SharedMemoryBuilder,
- ) -> ::std::mem::ManuallyDrop<Self> {
- ::std::mem::ManuallyDrop::new(*self)
+ ($($ty:ty),*) => {
+ $(
+ impl $crate::ToShmem for $ty {
+ fn to_shmem(
+ &self,
+ _builder: &mut $crate::SharedMemoryBuilder,
+ ) -> ::std::mem::ManuallyDrop<Self> {
+ ::std::mem::ManuallyDrop::new(*self)
+ }
}
- }
- )*};
+ )*
+ };
}
impl_trivial_to_shmem!(
@@ -522,3 +526,17 @@ impl ToShmem for SmallBitVec {
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"
+ )
+ }
+}
diff --git a/components/to_shmem_derive/to_shmem.rs b/components/to_shmem_derive/to_shmem.rs
index 1335ef4eea6..e7ff8c29b8c 100644
--- a/components/to_shmem_derive/to_shmem.rs
+++ b/components/to_shmem_derive/to_shmem.rs
@@ -40,7 +40,7 @@ pub fn derive(mut input: syn::DeriveInput) -> TokenStream {
quote! {
impl #impl_generics ::to_shmem::ToShmem for #name #ty_generics #where_clause {
- #[allow(unused_variables)]
+ #[allow(unused_variables, unreachable_code)]
fn to_shmem(
&self,
builder: &mut ::to_shmem::SharedMemoryBuilder,
diff --git a/components/url/Cargo.toml b/components/url/Cargo.toml
index dbbed4f58db..1a59812e071 100644
--- a/components/url/Cargo.toml
+++ b/components/url/Cargo.toml
@@ -13,6 +13,8 @@ path = "lib.rs"
[dependencies]
malloc_size_of = { path = "../malloc_size_of", features = ["servo"] }
malloc_size_of_derive = "0.1"
+to_shmem = { path = "../to_shmem" }
+to_shmem_derive = { path = "../to_shmem_derive" }
serde = {version = "1.0", features = ["derive"]}
servo_rand = {path = "../rand"}
url = "1.2"
diff --git a/components/url/lib.rs b/components/url/lib.rs
index dccd27a8b00..bb7c1fa4e35 100644
--- a/components/url/lib.rs
+++ b/components/url/lib.rs
@@ -20,10 +20,12 @@ pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin};
use std::collections::hash_map::DefaultHasher;
use std::fmt;
use std::hash::Hasher;
+use std::mem::ManuallyDrop;
use std::net::IpAddr;
use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo};
use std::path::Path;
use std::sync::Arc;
+use to_shmem::{SharedMemoryBuilder, ToShmem};
use url::{Position, Url};
pub use url::Host;
@@ -31,6 +33,12 @@ pub use url::Host;
#[derive(Clone, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd)]
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 {
pub fn from_url(url: Url) -> Self {
ServoUrl(Arc::new(url))