Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions style/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "lib.rs"
doctest = false

[features]
default = ["servo"]
default = ["servo", "malloc_size_of", "to_shmem", "specified_value_info", "typed_om"]
gecko = [
"bindgen",
"malloc_size_of/gecko",
Expand All @@ -29,8 +29,11 @@ gecko = [
"serde",
"style_traits/gecko",
"toml",
"selectors/to_shmem",
"to_shmem",
"to_shmem/gecko",
"malloc_size_of",
"specified_value_info",
"typed_om",
]
servo = [
"cssparser/serde",
Expand All @@ -44,9 +47,16 @@ servo = [
"string_cache",
"style_traits/servo",
"url",
"selectors/to_shmem",
"to_shmem/servo",
]
# Optional heavy derives. These are enabled by default (and by the "gecko"
# feature), but can be disabled (with default-features = false) to
# significantly reduce compile times when the corresponding functionality
# is not needed.
malloc_size_of = []
to_shmem = ["selectors/to_shmem"]
specified_value_info = []
typed_om = []
gecko_debug = []
gecko_refcount_logging = []
nsstring = []
Expand Down
1 change: 1 addition & 0 deletions style/counter_style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl CounterStyle {
}
}

#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for CounterStyle {
fn collect_completion_keywords(f: KeywordsCollectFn) {
// XXX The best approach for implementing this is probably
Expand Down
4 changes: 4 additions & 0 deletions style/custom_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::properties_and_values::{
};
use crate::stylesheets::UrlExtraData;
use crate::stylist::Stylist;
#[cfg(feature = "typed_om")]
use crate::typed_om::{
ToTyped, TypedValue, UnparsedSegment, UnparsedValue, VariableReferenceValue,
};
Expand Down Expand Up @@ -312,6 +313,7 @@ impl ToCss for SpecifiedValue {
}
}

#[cfg(feature = "typed_om")]
impl ToTyped for SpecifiedValue {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
let unparsed_value = reify_variable_value(self)?;
Expand All @@ -320,6 +322,7 @@ impl ToTyped for SpecifiedValue {
}
}

#[cfg(feature = "typed_om")]
fn reify_variable_value(value: &VariableValue) -> Result<UnparsedValue, ()> {
let mut reference_index = 0;
reify_variable_value_range(
Expand All @@ -337,6 +340,7 @@ fn reify_variable_value(value: &VariableValue) -> Result<UnparsedValue, ()> {
/// inserted before references in their fallback. The shared `reference_index`
/// relies on this ordering to recurse into fallbacks without reprocessing
/// nested referecences.
#[cfg(feature = "typed_om")]
fn reify_variable_value_range(
css: &str,
references: &[SubstitutionFunctionReference],
Expand Down
2 changes: 1 addition & 1 deletion style/device/servo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::color::AbsoluteColor;
use crate::context::QuirksMode;
use crate::custom_properties::CssEnvironment;
use crate::derives::MallocSizeOf;
use crate::font_metrics::FontMetrics;
use crate::logical_geometry::WritingMode;
use crate::media_queries::MediaType;
Expand All @@ -28,7 +29,6 @@ use crate::values::KeyframesName;
use app_units::{Au, AU_PER_PX};
use euclid::default::Size2D as UntypedSize2D;
use euclid::{Scale, SideOffsets2D, Size2D};
use malloc_size_of_derive::MallocSizeOf;
use mime::Mime;
use parking_lot::RwLock;
use servo_arc::Arc;
Expand Down
1 change: 1 addition & 0 deletions style/gecko_string_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,5 @@ impl From<String> for Atom {

malloc_size_of::malloc_size_of_is_0!(Atom);

#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for Atom {}
36 changes: 33 additions & 3 deletions style/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
//! [selectors]: ../selectors/index.html

#![deny(missing_docs)]
// When the optional derive features are disabled, some imports and helpers
// that only exist to support those derives become unused.
#![cfg_attr(
not(all(
feature = "malloc_size_of",
feature = "to_shmem",
feature = "specified_value_info",
feature = "typed_om"
)),
allow(unused_imports, dead_code)
)]

pub(crate) use cssparser;

Expand Down Expand Up @@ -53,13 +64,31 @@ mod macros;

mod derives {
pub(crate) use derive_more::{Add, AddAssign, Deref, DerefMut, From};
pub(crate) use malloc_size_of_derive::MallocSizeOf;
pub(crate) use num_derive::FromPrimitive;
pub(crate) use style_derive::{
Animate, ComputeSquaredDistance, Parse, SpecifiedValueInfo, ToAnimatedValue,
ToAnimatedZero, ToComputedValue, ToCss, ToResolvedValue, ToTyped,
Animate, ComputeSquaredDistance, Parse, ToAnimatedValue, ToAnimatedZero, ToComputedValue,
ToCss, ToResolvedValue,
};

#[cfg(feature = "malloc_size_of")]
pub(crate) use malloc_size_of_derive::MallocSizeOf;
#[cfg(not(feature = "malloc_size_of"))]
pub(crate) use style_derive::NoopMallocSizeOf as MallocSizeOf;

#[cfg(not(feature = "to_shmem"))]
pub(crate) use style_derive::NoopToShmem as ToShmem;
#[cfg(feature = "to_shmem")]
pub(crate) use to_shmem_derive::ToShmem;

#[cfg(not(feature = "specified_value_info"))]
pub(crate) use style_derive::NoopSpecifiedValueInfo as SpecifiedValueInfo;
#[cfg(feature = "specified_value_info")]
pub(crate) use style_derive::SpecifiedValueInfo;

#[cfg(not(feature = "typed_om"))]
pub(crate) use style_derive::NoopToTyped as ToTyped;
#[cfg(feature = "typed_om")]
pub(crate) use style_derive::ToTyped;
}

pub mod applicable_declarations;
Expand Down Expand Up @@ -114,6 +143,7 @@ pub mod stylist;
pub mod thread_state;
pub mod traversal;
pub mod traversal_flags;
#[cfg(feature = "typed_om")]
pub mod typed_om;
pub mod url;
pub mod use_counters;
Expand Down
3 changes: 3 additions & 0 deletions style/properties/declaration_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::shared_lock::Locked;
use crate::stylesheets::container_rule::ContainerSizeQuery;
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
use crate::stylist::Stylist;
#[cfg(feature = "typed_om")]
use crate::typed_om::TypedValueList;
use crate::values::computed::Context;
use cssparser::{
Expand Down Expand Up @@ -250,6 +251,7 @@ pub struct PropertyDeclarationBlock {
pub immutable: AtomicBool,
}

#[cfg(feature = "to_shmem")]
impl to_shmem::ToShmem for PropertyDeclarationBlock {
fn to_shmem(&self, builder: &mut to_shmem::SharedMemoryBuilder) -> to_shmem::Result<Self> {
use std::mem::ManuallyDrop;
Expand Down Expand Up @@ -633,6 +635,7 @@ impl PropertyDeclarationBlock {
/// Find the value of the given property in this block and reify it.
/// Returns `Err(())` if the property is not present in this declaration
/// block.
#[cfg(feature = "typed_om")]
pub fn property_value_to_typed_value_list(
&self,
property: &PropertyId,
Expand Down
7 changes: 6 additions & 1 deletion style/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::parser::ParserContext;
use crate::stylesheets::CssRuleType;
use crate::stylesheets::Origin;
use crate::stylist::Stylist;
#[cfg(feature = "typed_om")]
use crate::typed_om::{ToTyped, TypedValue};
use crate::values::{computed, serialize_atom_name};
use arrayvec::{ArrayVec, Drain as ArrayVecDrain};
Expand Down Expand Up @@ -159,6 +160,7 @@ pub struct WideKeywordDeclaration {

// XXX Switch back to ToTyped derive once it can automatically handle structs
// Tracking in bug 1991631
#[cfg(feature = "typed_om")]
impl ToTyped for WideKeywordDeclaration {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
self.keyword.to_typed(dest)
Expand Down Expand Up @@ -333,7 +335,7 @@ impl NonCustomPropertyId {

#[cfg(feature = "servo")]
/// Iterate over all non-custom properties in arbitrary order.
pub fn iter() -> impl Iterator<Item=Self> {
pub fn iter() -> impl Iterator<Item = Self> {
(0..property_counts::NON_CUSTOM as u16).map(|index| Self(index))
}
}
Expand Down Expand Up @@ -550,6 +552,7 @@ impl PropertyId {

/// Whether the property supports the given CSS type.
/// `ty` should a bitflags of constants in style_traits::CssType.
#[cfg(feature = "specified_value_info")]
pub fn supports_type(&self, ty: u8) -> bool {
let id = self.non_custom_non_alias_id();
id.map_or(0, |id| id.supported_types()) & ty != 0
Expand All @@ -559,6 +562,7 @@ impl PropertyId {
///
/// See style_traits::SpecifiedValueInfo::collect_completion_keywords for more
/// details.
#[cfg(feature = "specified_value_info")]
pub fn collect_property_completion_keywords(&self, f: KeywordsCollectFn) {
if let Some(id) = self.non_custom_non_alias_id() {
id.collect_property_completion_keywords(f);
Expand Down Expand Up @@ -1544,6 +1548,7 @@ impl ToCss for UnparsedValue {
}
}

#[cfg(feature = "typed_om")]
impl ToTyped for UnparsedValue {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
if self.from_shorthand.is_none() {
Expand Down
11 changes: 10 additions & 1 deletion style/properties/properties.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ use std::{ops, ptr, fmt, mem};
#[cfg(feature = "servo")] use crate::logical_geometry::LogicalMargin;
#[cfg(feature = "servo")] use crate::dom::AttributeReferences;
use crate::logical_geometry::WritingMode;
#[cfg(feature = "malloc_size_of")]
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use crate::computed_value_flags::*;
use cssparser::Parser;
use crate::device::Device;
use crate::parser::ParserContext;
use crate::selector_parser::PseudoElement;
use crate::stylist::Stylist;
use style_traits::{CssStringWriter, CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
use style_traits::{CssStringWriter, CssWriter, KeywordsCollectFn, ParseError, StyleParseErrorKind, ToCss};
#[cfg(feature = "specified_value_info")]
use style_traits::SpecifiedValueInfo;
use crate::derives::*;
use crate::stylesheets::{CssRuleType, CssRuleTypes, Origin};
use crate::logical_geometry::{LogicalAxis, LogicalCorner, LogicalSide};
#[cfg(feature = "typed_om")]
use crate::typed_om::{ToTyped, TypedValueList};
use crate::use_counters::UseCounters;
use crate::rule_tree::StrongRuleNode;
Expand Down Expand Up @@ -211,6 +215,7 @@ impl PartialEq for PropertyDeclaration {
}
}

#[cfg(feature = "malloc_size_of")]
impl MallocSizeOf for PropertyDeclaration {
#[inline]
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
Expand Down Expand Up @@ -273,6 +278,7 @@ impl PropertyDeclaration {
}

/// Like the method on ToTyped.
#[cfg(feature = "typed_om")]
pub fn to_typed_value_list(&self) -> Option<TypedValueList> {
use self::PropertyDeclaration::*;

Expand Down Expand Up @@ -472,6 +478,7 @@ impl NonCustomPropertyId {

/// The supported types of this property. The return value should be
/// style_traits::CssType when it can become a bitflags type.
#[cfg(feature = "specified_value_info")]
pub(super) fn supported_types(&self) -> u8 {
const SUPPORTED_TYPES: [u8; property_counts::LONGHANDS_AND_SHORTHANDS] = [
% for prop in data.longhands:
Expand All @@ -489,6 +496,7 @@ impl NonCustomPropertyId {
}

/// See PropertyId::collect_property_completion_keywords.
#[cfg(feature = "specified_value_info")]
pub(super) fn collect_property_completion_keywords(&self, f: KeywordsCollectFn) {
fn do_nothing(_: KeywordsCollectFn) {}
const COLLECT_FUNCTIONS: [fn(KeywordsCollectFn);
Expand Down Expand Up @@ -1729,6 +1737,7 @@ impl ComputedValues {

/// Returns the computed value of the given longhand as a
/// [`TypedValueList`], if supported.
#[cfg(feature = "typed_om")]
pub fn property_value_to_typed_value_list(
&self,
property_id: LonghandId,
Expand Down
4 changes: 4 additions & 0 deletions style/properties/shorthands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ pub mod border {

// We need to implement this by hand because deriving this would also derive border-image,
// which this property only resets. Just use the same as border-left for simplicity.
#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for Longhands {
const SUPPORTED_TYPES: u8 = border_left::Longhands::SUPPORTED_TYPES;

Expand Down Expand Up @@ -1115,6 +1116,7 @@ pub mod white_space {
}
}

#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for Longhands {
fn collect_completion_keywords(f: KeywordsCollectFn) {
// Collect keywords from our longhands.
Expand Down Expand Up @@ -2845,6 +2847,7 @@ pub mod font {
}
}

#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for Longhands {
const SUPPORTED_TYPES: u8 = FontStyle::SUPPORTED_TYPES
| FontWeight::SUPPORTED_TYPES
Expand Down Expand Up @@ -3121,6 +3124,7 @@ pub mod font_synthesis {

// The shorthand takes the sub-property names of the longhands, and not the
// 'auto' keyword like they do, so we can't automatically derive this.
#[cfg(feature = "specified_value_info")]
impl SpecifiedValueInfo for Longhands {
fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&[
Expand Down
1 change: 1 addition & 0 deletions style/properties_and_values/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub enum PropertyRegistrationError {

impl PropertyRegistration {
/// Measure heap usage.
#[cfg(feature = "malloc_size_of")]
pub fn size_of(&self, _: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
MallocSizeOf::size_of(self, ops)
}
Expand Down
6 changes: 4 additions & 2 deletions style/stylist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,7 @@ struct GenericElementAndPseudoRules<Map> {
pseudos_map: PerPseudoElementMap<Self>,
}

impl<Map: Default + MallocSizeOf> GenericElementAndPseudoRules<Map> {
impl<Map: Default> GenericElementAndPseudoRules<Map> {
#[inline(always)]
fn for_insertion<'a>(&mut self, pseudo_elements: &[&'a PseudoElement]) -> &mut Map {
let mut current = self;
Expand Down Expand Up @@ -2806,9 +2806,11 @@ impl<Map: Default + MallocSizeOf> GenericElementAndPseudoRules<Map> {
}
Some(&current.element_map)
}
}

#[cfg(feature = "gecko")]
impl<Map: Default + MallocSizeOf> GenericElementAndPseudoRules<Map> {
/// Measures heap usage.
#[cfg(feature = "gecko")]
fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) {
sizes.mElementAndPseudosMaps += self.element_map.size_of(ops);

Expand Down
2 changes: 2 additions & 0 deletions style/values/computed/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Computed angles.

use crate::derives::*;
#[cfg(feature = "typed_om")]
use crate::typed_om::{NumericType, NumericValue, ToTyped, TypedValue, UnitValue};
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
use crate::values::CSSFloat;
Expand Down Expand Up @@ -44,6 +45,7 @@ impl ToCss for Angle {
}
}

#[cfg(feature = "typed_om")]
impl ToTyped for Angle {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
dest.push(TypedValue::Numeric(NumericValue::Unit(UnitValue {
Expand Down
2 changes: 2 additions & 0 deletions style/values/computed/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Computed values for properties related to animations and transitions

use crate::derives::*;
#[cfg(feature = "typed_om")]
use crate::typed_om::{KeywordValue, ToTyped, TypedValue};
use crate::values::computed::{Context, LengthPercentage, Time, ToComputedValue};
use crate::values::generics::animation as generics;
Expand Down Expand Up @@ -82,6 +83,7 @@ impl ToCss for AnimationIterationCount {
}
}

#[cfg(feature = "typed_om")]
impl ToTyped for AnimationIterationCount {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
if self.0.is_infinite() {
Expand Down
Loading