mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Fix clamping on animations for fort-style.
Bug: 1455358 Reviewed-by: xidorn MozReview-Commit-ID: Awyub0dMOmq
This commit is contained in:
parent
737501153b
commit
0a8518b452
5 changed files with 37 additions and 10 deletions
|
@ -20,8 +20,7 @@ ${helpers.predefined_type(
|
||||||
"FontStyle",
|
"FontStyle",
|
||||||
initial_value="computed::FontStyle::normal()",
|
initial_value="computed::FontStyle::normal()",
|
||||||
initial_specified_value="specified::FontStyle::normal()",
|
initial_specified_value="specified::FontStyle::normal()",
|
||||||
# FIXME(emilio): This won't handle clamping correctly.
|
animation_value_type="FontStyle",
|
||||||
animation_value_type="ComputedValue",
|
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
|
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
|
||||||
servo_restyle_damage="rebuild_and_reflow",
|
servo_restyle_damage="rebuild_and_reflow",
|
||||||
|
|
|
@ -64,6 +64,12 @@ impl Angle {
|
||||||
radians.min(f64::MAX).max(f64::MIN)
|
radians.min(f64::MAX).max(f64::MIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the value in degrees.
|
||||||
|
pub fn degrees(&self) -> f32 {
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
self.radians() * 360. / (2. * PI)
|
||||||
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-transitions/#animtype-number>
|
/// <https://drafts.csswg.org/css-transitions/#animtype-number>
|
||||||
#[inline]
|
#[inline]
|
||||||
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
|
|
|
@ -838,11 +838,34 @@ impl ToComputedValue for specified::MozScriptLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper over an `Angle`, that handles clamping to the appropriate range
|
||||||
|
/// for `font-style` animation.
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
pub struct FontStyleAngle(pub Angle);
|
||||||
|
|
||||||
|
impl ToAnimatedValue for FontStyleAngle {
|
||||||
|
type AnimatedValue = Angle;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||||
|
FontStyleAngle(Angle::Deg(
|
||||||
|
animated.degrees()
|
||||||
|
.min(specified::FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES)
|
||||||
|
.max(specified::FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The computed value of `font-style`.
|
/// The computed value of `font-style`.
|
||||||
///
|
///
|
||||||
/// FIXME(emilio): Angle should be a custom type to handle clamping during
|
/// FIXME(emilio): Angle should be a custom type to handle clamping during
|
||||||
/// animation.
|
/// animation.
|
||||||
pub type FontStyle = generics::FontStyle<Angle>;
|
pub type FontStyle = generics::FontStyle<FontStyleAngle>;
|
||||||
|
|
||||||
impl FontStyle {
|
impl FontStyle {
|
||||||
/// The `normal` value.
|
/// The `normal` value.
|
||||||
|
@ -855,8 +878,8 @@ impl FontStyle {
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
|
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn default_angle() -> Angle {
|
fn default_angle() -> FontStyleAngle {
|
||||||
Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES)
|
FontStyleAngle(Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -110,8 +110,7 @@ impl Angle {
|
||||||
/// Returns the amount of degrees this angle represents.
|
/// Returns the amount of degrees this angle represents.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn degrees(self) -> f32 {
|
pub fn degrees(self) -> f32 {
|
||||||
use std::f32::consts::PI;
|
self.value.degrees()
|
||||||
self.radians() * 360. / (2. * PI)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `0deg`.
|
/// Returns `0deg`.
|
||||||
|
|
|
@ -19,7 +19,7 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
use values::computed::{Angle as ComputedAngle, Percentage as ComputedPercentage};
|
use values::computed::{Angle as ComputedAngle, Percentage as ComputedPercentage};
|
||||||
use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue};
|
use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue};
|
||||||
use values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily};
|
use values::computed::font::{FamilyName, FontFamilyList, FontStyleAngle, SingleFontFamily};
|
||||||
use values::generics::NonNegative;
|
use values::generics::NonNegative;
|
||||||
use values::generics::font::{self as generics, FeatureTagValue, FontSettings, FontTag};
|
use values::generics::font::{self as generics, FeatureTagValue, FontSettings, FontTag};
|
||||||
use values::generics::font::{KeywordInfo as GenericKeywordInfo, KeywordSize, VariationValue};
|
use values::generics::font::{KeywordInfo as GenericKeywordInfo, KeywordSize, VariationValue};
|
||||||
|
@ -241,7 +241,7 @@ impl ToComputedValue for SpecifiedFontStyle {
|
||||||
generics::FontStyle::Normal => generics::FontStyle::Normal,
|
generics::FontStyle::Normal => generics::FontStyle::Normal,
|
||||||
generics::FontStyle::Italic => generics::FontStyle::Italic,
|
generics::FontStyle::Italic => generics::FontStyle::Italic,
|
||||||
generics::FontStyle::Oblique(ref angle) => {
|
generics::FontStyle::Oblique(ref angle) => {
|
||||||
generics::FontStyle::Oblique(Self::compute_angle(angle))
|
generics::FontStyle::Oblique(FontStyleAngle(Self::compute_angle(angle)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ impl ToComputedValue for SpecifiedFontStyle {
|
||||||
generics::FontStyle::Normal => generics::FontStyle::Normal,
|
generics::FontStyle::Normal => generics::FontStyle::Normal,
|
||||||
generics::FontStyle::Italic => generics::FontStyle::Italic,
|
generics::FontStyle::Italic => generics::FontStyle::Italic,
|
||||||
generics::FontStyle::Oblique(ref angle) => {
|
generics::FontStyle::Oblique(ref angle) => {
|
||||||
generics::FontStyle::Oblique(Angle::from_computed_value(angle))
|
generics::FontStyle::Oblique(Angle::from_computed_value(&angle.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue