Skip to content
Permalink
Browse files

Auto merge of #16829 - hiikezoe:disallow-negative-duration, r=emilio

Disallow negative duration for animation and transition

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15343

<!-- Either: -->
- [X] There are tests for these changes written by @simon-whitehead . Thank you!

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16829)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 13, 2017
2 parents c5e31de + 2e3f45b commit 4613c0382ab76263fb8202ccf52f4c0520e44809
@@ -444,7 +444,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
}

pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
Time::parse(context, input)
Time::parse_non_negative(context, input)
}
</%helpers:vector_longhand>

@@ -824,7 +824,11 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
pub use properties::longhands::transition_duration::single_value::computed_value;
pub use properties::longhands::transition_duration::single_value::{get_initial_value, get_initial_specified_value};
pub use properties::longhands::transition_duration::single_value::parse;

pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
use values::specified::Time;
Time::parse(context, input)
}
</%helpers:vector_longhand>

<%helpers:vector_longhand name="animation-name"
@@ -1031,10 +1035,10 @@ ${helpers.single_keyword("animation-fill-mode",
extra_prefixes="moz webkit",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
allowed_in_keyframe_block="False">
pub use properties::longhands::transition_duration::single_value::computed_value;
pub use properties::longhands::transition_duration::single_value::get_initial_specified_value;
pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse};
pub use properties::longhands::transition_duration::single_value::SpecifiedValue;
pub use properties::longhands::transition_delay::single_value::computed_value;
pub use properties::longhands::transition_delay::single_value::get_initial_specified_value;
pub use properties::longhands::transition_delay::single_value::{get_initial_value, parse};
pub use properties::longhands::transition_delay::single_value::SpecifiedValue;
</%helpers:vector_longhand>

<%helpers:longhand products="gecko" name="scroll-snap-points-y" animation_value_type="none"
@@ -539,6 +539,28 @@ impl Time {
was_calc: true,
}
}

fn parse_with_clamping_mode(context: &ParserContext,
input: &mut Parser,
clamping_mode: AllowedNumericType) -> Result<Self, ()> {
match input.next() {
Ok(Token::Dimension(ref value, ref unit)) if clamping_mode.is_ok(value.value) => {
Time::parse_dimension(value.value, &unit, /* from_calc = */ false)
}
Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {
match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) {
Ok(time) if clamping_mode.is_ok(time.seconds) => Ok(time),
_ => Err(()),
}
}
_ => Err(())
}
}

/// Parse <time> that values are non-negative.
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
}
}

impl ToComputedValue for Time {
@@ -558,15 +580,7 @@ impl ToComputedValue for Time {

impl Parse for Time {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
match input.next() {
Ok(Token::Dimension(ref value, ref unit)) => {
Time::parse_dimension(value.value, &unit, /* from_calc = */ false)
}
Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {
input.parse_nested_block(|i| CalcNode::parse_time(context, i))
}
_ => Err(())
}
Self::parse_with_clamping_mode(context, input, AllowedNumericType::All)
}
}

@@ -105,6 +105,7 @@ mod selectors;
mod supports;
mod text;
mod text_overflow;
mod transition_duration;
mod transition_property;
mod transition_timing_function;
mod ui;
@@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use parsing::parse;
use style::properties::longhands::transition_duration;

#[test]
fn test_positive_transition_duration() {
assert!(parse(transition_duration::parse, "5s").is_ok());
assert!(parse(transition_duration::parse, "0s").is_ok());
}

#[test]
fn test_negative_transition_duration() {
assert!(parse(transition_duration::parse, "-5s").is_err());
}

This file was deleted.

This file was deleted.

0 comments on commit 4613c03

Please sign in to comment.
You can’t perform that action at this time.