mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Bug 1374233 - Part 11: Implement ToAnimatedValue for background-size.
MozReview-Commit-ID: DMcvpaqHdy9
This commit is contained in:
parent
1e79e5fe1b
commit
ebedea5860
6 changed files with 78 additions and 6 deletions
|
@ -157,7 +157,7 @@ class Longhand(object):
|
|||
allowed_in_keyframe_block=True, cast_type='u8',
|
||||
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False,
|
||||
flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False,
|
||||
gecko_pref_ident=None, vector=False):
|
||||
gecko_pref_ident=None, vector=False, need_animatable=False):
|
||||
self.name = name
|
||||
if not spec:
|
||||
raise TypeError("Spec should be specified for %s" % name)
|
||||
|
|
|
@ -76,8 +76,10 @@
|
|||
We assume that the default/initial value is an empty vector for these.
|
||||
`initial_value` need not be defined for these.
|
||||
</%doc>
|
||||
<%def name="vector_longhand(name, animation_value_type=None, allow_empty=False, separator='Comma', **kwargs)">
|
||||
<%call expr="longhand(name, animation_value_type=animation_value_type, vector=True, **kwargs)">
|
||||
<%def name="vector_longhand(name, animation_value_type=None, allow_empty=False, separator='Comma',
|
||||
need_animatable=False, **kwargs)">
|
||||
<%call expr="longhand(name, animation_value_type=animation_value_type, vector=True,
|
||||
need_animatable=need_animatable, **kwargs)">
|
||||
#[allow(unused_imports)]
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
|
@ -127,7 +129,7 @@
|
|||
% endif
|
||||
);
|
||||
|
||||
% if animation_value_type == "ComputedValue":
|
||||
% if need_animatable or animation_value_type == "ComputedValue":
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use euclid::{Point2D, Size2D};
|
|||
#[cfg(feature = "gecko")] use gecko_string_cache::Atom;
|
||||
use properties::{CSSWideKeyword, PropertyDeclaration};
|
||||
use properties::longhands;
|
||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use properties::longhands::border_spacing::computed_value::T as BorderSpacing;
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
|
|
|
@ -167,7 +167,8 @@ ${helpers.predefined_type("background-size", "BackgroundSize",
|
|||
initial_specified_value="specified::LengthOrPercentageOrAuto::Auto.into()",
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-size",
|
||||
vector=True,
|
||||
animation_value_type="ComputedValue",
|
||||
animation_value_type="BackgroundSizeList",
|
||||
need_animatable=True,
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
extra_prefixes="webkit")}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
//! module's raison d'être is to ultimately contain all these types.
|
||||
|
||||
use app_units::Au;
|
||||
use smallvec::SmallVec;
|
||||
use std::cmp::max;
|
||||
use values::computed::Angle as ComputedAngle;
|
||||
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
|
||||
|
@ -71,6 +72,23 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> ToAnimatedValue for SmallVec<[T; 1]>
|
||||
where
|
||||
T: ToAnimatedValue,
|
||||
{
|
||||
type AnimatedValue = SmallVec<[T::AnimatedValue; 1]>;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
self.into_iter().map(T::to_animated_value).collect()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
animated.into_iter().map(T::from_animated_value).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Marker trait for computed values with the same representation during animations.
|
||||
pub trait AnimatedValueAsComputed {}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
//! Computed types for CSS values related to backgrounds.
|
||||
|
||||
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||
use values::animated::ToAnimatedZero;
|
||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::length::LengthOrPercentageOrAuto;
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
|
||||
|
@ -56,3 +57,52 @@ impl ToAnimatedZero for BackgroundSize {
|
|||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for BackgroundSize {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
use app_units::Au;
|
||||
use values::computed::Percentage;
|
||||
let clamp_animated_value = |value: LengthOrPercentageOrAuto| -> LengthOrPercentageOrAuto {
|
||||
match value {
|
||||
LengthOrPercentageOrAuto::Length(len) => {
|
||||
LengthOrPercentageOrAuto::Length(Au(::std::cmp::max(len.0, 0)))
|
||||
},
|
||||
LengthOrPercentageOrAuto::Percentage(percent) => {
|
||||
LengthOrPercentageOrAuto::Percentage(Percentage(percent.0.max(0.)))
|
||||
},
|
||||
_ => value
|
||||
}
|
||||
};
|
||||
match animated {
|
||||
GenericBackgroundSize::Explicit { width, height } => {
|
||||
GenericBackgroundSize::Explicit {
|
||||
width: clamp_animated_value(width),
|
||||
height: clamp_animated_value(height)
|
||||
}
|
||||
},
|
||||
_ => animated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for BackgroundSizeList {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue