mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Add computed value ZeroToOneNumber.
Correctly handle clamping to 1 behavior of grayscale(), invert(), opacity() and sepia(). Differential Revision: https://phabricator.services.mozilla.com/D35509
This commit is contained in:
parent
9939c1ee07
commit
2fba62aba9
6 changed files with 132 additions and 73 deletions
|
@ -10,7 +10,7 @@ use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent
|
|||
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
|
||||
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
|
||||
use super::generics::transform::IsParallelTo;
|
||||
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative};
|
||||
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative, ZeroToOne};
|
||||
use super::specified;
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
use crate::context::QuirksMode;
|
||||
|
@ -519,6 +519,30 @@ impl From<NonNegativeNumber> for CSSFloat {
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Number, but the value between 0 and 1
|
||||
pub type ZeroToOneNumber = ZeroToOne<CSSFloat>;
|
||||
|
||||
impl ToAnimatedValue for ZeroToOneNumber {
|
||||
type AnimatedValue = CSSFloat;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
Self(animated.max(0.).min(1.))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CSSFloat> for ZeroToOneNumber {
|
||||
#[inline]
|
||||
fn from(number: CSSFloat) -> Self {
|
||||
Self(number)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Number, but the value >= 1.
|
||||
pub type GreaterThanOrEqualToOneNumber = GreaterThanOrEqualToOne<CSSFloat>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue