mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Ensure that derived types are right for optimized-away implementations.
We have this optimization where, for non-generic structs, we generate just a clone / move as the ToComputedValue / ToResolvedValue implementation. This moves the optimization a bit further down, and refines it so that we still generate all the relevant where clauses that make it sound, that is, that all the ToComputedValue implementations of the fields return the same type. Otherwise this wouldn't be sound and the type would need to become generic. We add an escape hatch (no_field_bound) for fields that need to be cloned but which don't implement the trait. This is right now only for the RefPtr<> in the shared font-family list, and a piece of code in PaintWorklet which looks kinda fishy, and probably should be fixed (but we don't ship it in Firefox and there's a pre-existing FIXME for servo, so I punted on it for now). The other thing this patch does is adding a bunch of ToComputedValue / ToResolvedValue implementations that are trivial and were missing. Differential Revision: https://phabricator.services.mozilla.com/D67913
This commit is contained in:
parent
0514059618
commit
7d438cd816
18 changed files with 295 additions and 146 deletions
|
@ -556,7 +556,7 @@ impl SpecifiedValueInfo for AlignItems {
|
|||
/// Value of the `justify-items` property
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-align/#justify-items-property>
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToShmem)]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
|
||||
#[repr(C)]
|
||||
pub struct JustifyItems(pub AlignFlags);
|
||||
|
||||
|
|
|
@ -234,7 +234,18 @@ impl Parse for BorderSpacing {
|
|||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum BorderImageRepeatKeyword {
|
||||
Stretch,
|
||||
|
|
|
@ -492,7 +492,9 @@ impl ToComputedValue for FontStretch {
|
|||
SpecifiedValueInfo,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[allow(missing_docs)]
|
||||
|
@ -534,7 +536,9 @@ impl Default for KeywordSize {
|
|||
PartialEq,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
/// Additional information for keyword-derived font sizes.
|
||||
|
@ -567,7 +571,7 @@ impl KeywordInfo {
|
|||
/// Computes the final size for this font-size keyword, accounting for
|
||||
/// text-zoom.
|
||||
fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
|
||||
let base = context.maybe_zoom_text(self.kw.to_computed_value(context).0);
|
||||
let base = context.maybe_zoom_text(self.kw.to_length(context).0);
|
||||
base * self.factor + context.maybe_zoom_text(self.offset)
|
||||
}
|
||||
|
||||
|
@ -760,11 +764,10 @@ const LARGER_FONT_SIZE_RATIO: f32 = 1.2;
|
|||
/// The default font size.
|
||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ToComputedValue for KeywordSize {
|
||||
type ComputedValue = NonNegativeLength;
|
||||
impl KeywordSize {
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _: &Context) -> NonNegativeLength {
|
||||
#[cfg(feature = "servo")]
|
||||
fn to_length(&self, _: &Context) -> NonNegativeLength {
|
||||
let medium = Length::new(FONT_MEDIUM_PX as f32);
|
||||
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
|
||||
NonNegative(match *self {
|
||||
|
@ -779,17 +782,9 @@ impl ToComputedValue for KeywordSize {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn from_computed_value(_: &NonNegativeLength) -> Self {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToComputedValue for KeywordSize {
|
||||
type ComputedValue = NonNegativeLength;
|
||||
#[inline]
|
||||
fn to_computed_value(&self, cx: &Context) -> NonNegativeLength {
|
||||
fn to_length(&self, cx: &Context) -> NonNegativeLength {
|
||||
use crate::context::QuirksMode;
|
||||
|
||||
// The tables in this function are originally from
|
||||
|
@ -857,11 +852,6 @@ impl ToComputedValue for KeywordSize {
|
|||
base_size * FONT_SIZE_FACTORS[html_size] as f32 / 100.0
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(_: &NonNegativeLength) -> Self {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl FontSize {
|
||||
|
|
|
@ -539,7 +539,7 @@ impl TemplateAreas {
|
|||
Ok(TemplateAreas {
|
||||
areas: areas.into(),
|
||||
strings: strings.into(),
|
||||
width: width,
|
||||
width,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -589,7 +589,16 @@ impl Parse for TemplateAreasArc {
|
|||
/// A range of rows or columns. Using this instead of std::ops::Range for FFI
|
||||
/// purposes.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub struct UnsignedRange {
|
||||
/// The start of the range.
|
||||
pub start: u32,
|
||||
|
@ -597,7 +606,16 @@ pub struct UnsignedRange {
|
|||
pub end: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
/// Not associated with any particular grid item, but can be referenced from the
|
||||
/// grid-placement properties.
|
||||
|
|
|
@ -35,7 +35,8 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|||
pub struct SVGPathData(
|
||||
// TODO(emilio): Should probably measure this somehow only from the
|
||||
// specified values.
|
||||
#[ignore_malloc_size_of = "Arc"] pub crate::ArcSlice<PathCommand>,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
pub crate::ArcSlice<PathCommand>,
|
||||
);
|
||||
|
||||
impl SVGPathData {
|
||||
|
@ -159,6 +160,8 @@ impl ComputeSquaredDistance for SVGPathData {
|
|||
Serialize,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[allow(missing_docs)]
|
||||
|
@ -488,6 +491,8 @@ impl ToCss for PathCommand {
|
|||
Serialize,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
|
@ -518,7 +523,9 @@ impl IsAbsolute {
|
|||
Serialize,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
|
@ -534,7 +541,7 @@ impl CoordPair {
|
|||
|
||||
/// The EllipticalArc flag type.
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, SpecifiedValueInfo, ToShmem,
|
||||
Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct ArcFlag(bool);
|
||||
|
|
|
@ -122,7 +122,7 @@ impl ToComputedValue for LineHeight {
|
|||
}
|
||||
|
||||
/// A generic value for the `text-overflow` property.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
|
||||
#[repr(C, u8)]
|
||||
pub enum TextOverflowSide {
|
||||
/// Clip inline content.
|
||||
|
@ -687,7 +687,7 @@ pub enum TextEmphasisStyle {
|
|||
}
|
||||
|
||||
/// Fill mode for the text-emphasis-style property
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[repr(u8)]
|
||||
pub enum TextEmphasisFillMode {
|
||||
/// `filled`
|
||||
|
@ -706,7 +706,18 @@ impl TextEmphasisFillMode {
|
|||
|
||||
/// Shape keyword for the text-emphasis-style property
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToCss,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum TextEmphasisShapeKeyword {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue