mirror of
https://github.com/servo/servo.git
synced 2025-09-07 05:28:21 +01:00
Further changes required by Servo
This commit is contained in:
parent
8c1c4073e2
commit
b6db94bdf5
9 changed files with 94 additions and 66 deletions
|
@ -2,13 +2,13 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::RGBA;
|
||||
use style::color::AbsoluteColor;
|
||||
use style::values::animated::{Animate, Procedure, ToAnimatedValue};
|
||||
|
||||
fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA {
|
||||
fn interpolate_color(from: AbsoluteColor, to: AbsoluteColor, progress: f64) -> AbsoluteColor {
|
||||
let from = from.to_animated_value();
|
||||
let to = to.to_animated_value();
|
||||
RGBA::from_animated_value(
|
||||
AbsoluteColor::from_animated_value(
|
||||
from.animate(&to, Procedure::Interpolate { progress })
|
||||
.unwrap(),
|
||||
)
|
||||
|
@ -18,16 +18,24 @@ fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA {
|
|||
#[test]
|
||||
fn test_rgba_color_interepolation_preserves_transparent() {
|
||||
assert_eq!(
|
||||
interpolate_rgba(RGBA::transparent(), RGBA::transparent(), 0.5),
|
||||
RGBA::transparent()
|
||||
interpolate_color(
|
||||
AbsoluteColor::transparent(),
|
||||
AbsoluteColor::transparent(),
|
||||
0.5
|
||||
),
|
||||
AbsoluteColor::transparent()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_alpha() {
|
||||
assert_eq!(
|
||||
interpolate_rgba(RGBA::new(200, 0, 0, 0.4), RGBA::new(0, 200, 0, 0.8), 0.5),
|
||||
RGBA::new(67, 133, 0, 0.6)
|
||||
interpolate_color(
|
||||
AbsoluteColor::srgb(0.6, 0.0, 0.0, 0.4),
|
||||
AbsoluteColor::srgb(0.0, 0.6, 0.0, 0.8),
|
||||
0.5
|
||||
),
|
||||
AbsoluteColor::srgb(0.2, 0.4, 0.0, 0.6)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -36,47 +44,47 @@ fn test_rgba_color_interepolation_out_of_range_1() {
|
|||
// Some cubic-bezier functions produce values that are out of range [0, 1].
|
||||
// Unclamped cases.
|
||||
assert_eq!(
|
||||
interpolate_rgba(
|
||||
RGBA::from_floats(0.3, 0.0, 0.0, 0.4),
|
||||
RGBA::from_floats(0.0, 1.0, 0.0, 0.6),
|
||||
interpolate_color(
|
||||
AbsoluteColor::srgb(0.3, 0.0, 0.0, 0.4),
|
||||
AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.6),
|
||||
-0.5
|
||||
),
|
||||
RGBA::new(154, 0, 0, 0.3)
|
||||
AbsoluteColor::srgb(0.6, -1.0, 0.0, 0.3)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_2() {
|
||||
assert_eq!(
|
||||
interpolate_rgba(
|
||||
RGBA::from_floats(1.0, 0.0, 0.0, 0.6),
|
||||
RGBA::from_floats(0.0, 0.3, 0.0, 0.4),
|
||||
interpolate_color(
|
||||
AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.6),
|
||||
AbsoluteColor::srgb(0.0, 0.3, 0.0, 0.4),
|
||||
1.5
|
||||
),
|
||||
RGBA::new(0, 154, 0, 0.3)
|
||||
AbsoluteColor::srgb(-1.0, 0.6, 0.0, 0.3)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_clamped_1() {
|
||||
assert_eq!(
|
||||
interpolate_rgba(
|
||||
RGBA::from_floats(1.0, 0.0, 0.0, 0.8),
|
||||
RGBA::from_floats(0.0, 1.0, 0.0, 0.2),
|
||||
interpolate_color(
|
||||
AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.8),
|
||||
AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.2),
|
||||
-0.5
|
||||
),
|
||||
RGBA::from_floats(1.0, 0.0, 0.0, 1.0)
|
||||
AbsoluteColor::srgb(1.2, -0.1, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_clamped_2() {
|
||||
assert_eq!(
|
||||
interpolate_rgba(
|
||||
RGBA::from_floats(1.0, 0.0, 0.0, 0.8),
|
||||
RGBA::from_floats(0.0, 1.0, 0.0, 0.2),
|
||||
interpolate_color(
|
||||
AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.8),
|
||||
AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.2),
|
||||
1.5
|
||||
),
|
||||
RGBA::from_floats(0.0, 0.0, 0.0, 0.0)
|
||||
AbsoluteColor::srgb(0.0, 0.0, 0.0, 0.0)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue