Skip to content

stylo: Bug 1374233 - Clamp interpolated values for properties which need to be restricted - #17783

Merged
bors-servo merged 13 commits into
servo:masterfrom
BorisChiou:stylo/animation/restrictions
Aug 7, 2017
Merged

bors-servo merged 13 commits into
servo:masterfrom
BorisChiou:stylo/animation/restrictions

Conversation

@BorisChiou

@BorisChiou BorisChiou commented Jul 19, 2017 •

Copy link
Copy Markdown
Contributor

Some properties only accept non-negative values, or values greater than or equal to one. It is possible to produce an negative interpolated values while using negative timing functions, so we have to apply a restriction to these values to avoid getting invalid values.

For example, line-height must be non-negative, but the output progress of some timing functions (e,g. cubic-bezier(0.25, -2, 0.75, 1)) may be a negative value, so the interpolated result of line-height is also negative.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix Bug 1374233.
  • These changes do not require tests because we have tests in Gecko side already.

This change is Reviewable

@highfive highfive assigned ghost Jul 19, 2017
@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/longhand/inherited_text.mako.rs, components/style/values/computed/text.rs, components/style/properties/longhand/padding.mako.rs, components/style/properties/longhand/position.mako.rs, components/style/properties/data.py and 13 more
  • @canaltinova: components/style/properties/longhand/inherited_text.mako.rs, components/style/values/computed/text.rs, components/style/properties/longhand/padding.mako.rs, components/style/properties/longhand/position.mako.rs, components/style/properties/data.py and 13 more
  • @emilio: components/style/properties/longhand/inherited_text.mako.rs, components/style/values/computed/text.rs, components/style/properties/longhand/padding.mako.rs, components/style/properties/longhand/position.mako.rs, components/style/properties/data.py and 13 more

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 19, 2017
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!

@BorisChiou

Copy link
Copy Markdown
Contributor Author

r? @nox

@highfive highfive assigned nox and unassigned ghost Jul 19, 2017
@nox

nox commented Jul 19, 2017

Copy link
Copy Markdown
Contributor

So my first issue with this is: even if we clamp at conversion-time, what about the result of interpolation? When does that get clamped?

@BorisChiou

Copy link
Copy Markdown
Contributor Author

cc @hiikezoe

@BorisChiou

BorisChiou commented Jul 19, 2017 •

Copy link
Copy Markdown
Contributor Author

We don't change the result of interpolation. All we need to do is make sure we put the correct non-negative result into ServoComputedValues (by uncompute() and then cascade it to ServoComputedValues), with Animation/Transition cascade level, so we can see the correct animation on the screen.

The out of range interpolated values are still needed to be preserved during calculating AnimationValue in the case for additive or accumulative animations.

nox
nox previously requested changes Jul 19, 2017

impl AnimatedValueAsComputed for T {
#[inline]
fn restrict_value(self, restriction_type: Restriction) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK there is never a need for such a method given Animatable methods can clamp directly.

Comment thread components/style/values/animated/mod.rs Outdated
/// Restriction types.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Restriction {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a type for that, please replace by AllowedNumericType.

}}
}

impl<Angle, Factor, Length, DropShadow> ToAnimatedValue for Filter<Angle, Factor, Length, DropShadow>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, define the Factor impl yourself instead of clamping from here.

color: ToAnimatedValue::from_animated_value(animated.color),
horizontal: ToAnimatedValue::from_animated_value(animated.horizontal),
vertical: ToAnimatedValue::from_animated_value(animated.vertical),
blur: convert_and_clamp_nonnegative_animated_value!(animated.blur)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the blur value its own wrapper type that clamps correctly.

}
}

impl AnimatedValueAsComputed for LineHeight {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the computed type clamp itself during animation?

}
}

impl AnimatedValueAsComputed for BackgroundSize {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't the computed type clamp itself during animation?

use app_units::Au;
use std::cmp;
use values::computed::Angle as ComputedAngle;
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no, make a submodule border just like there is one in computed and specified.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't addressed, I think.

@nox

nox commented Jul 19, 2017

Copy link
Copy Markdown
Contributor

We don't change the result of interpolation. All we need to do is make sure we put the correct non-negative result into ServoComputedValues (by uncompute() function), with Animation/Transition cascade level, so we can see the correct animation on the screen.

Why wasn't the computed value clamped itself, then?

@BorisChiou

Copy link
Copy Markdown
Contributor Author

Per our talk on irc, I will try to add new types for those non-negative or greater-than-or-equal-to-one, to avoid additional conditional clamping.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #17774) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 19, 2017
@BorisChiou

BorisChiou commented Jul 25, 2017 •

Copy link
Copy Markdown
Contributor Author

I've finished re-writing my patches locally (by introducing some non-negative types and greater-than-or-equal-to-one types, and updating some existing types, e.g. LineHeight), so will update this PR soon.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@BorisChiou
BorisChiou force-pushed the stylo/animation/restrictions branch 2 times, most recently from 4f0f67d to e066336 Compare July 26, 2017 07:23
@BorisChiou

Copy link
Copy Markdown
Contributor Author

r? @nox again. Thanks.
I add some types for NonNegtaive and Greater-than-Or-Equal-To-One values, and then use these types as the specified/computed values of these properties which need to be clamped.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit e066336 with merge 6a757dd...

bors-servo pushed a commit that referenced this pull request Jul 26, 2017
stylo: Bug 1374233 - Clamp interpolated values for properties which need to be restricted

Some properties only accept non-negative values, or values greater than or equal to one. It is possible to produce an negative interpolated values while using negative timing functions, so we have to apply a restriction to these values to avoid getting invalid values.

For example, line-height must be non-negative, but the output progress of some timing functions (e,g. cubic-bezier(0.25, -2, 0.75, 1)) may be a negative value, so the interpolated result of line-height is also negative.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix Bug 1374233.
- [X] These changes do not require tests because we have tests in Gecko side already.

<!-- 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/17783)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@BorisChiou

Copy link
Copy Markdown
Contributor Author

There are some conflicts now, but I'd like to rebase my patches after making sure the design is accepted or knowing what should I fix.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@emilio, nox is still on PTO, so do you feel comfortable with reviewing these patches?

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine over all. There's a fair amount of boilerplate (disclaimer: I don't know how previous versions of the patch were). Most of it could go away with derive, I think.

I wonder if some kind of NonNegative<T>, etc would be doable.

This also needs a rebase.

@nox does this patch address your comments properly? I'm not aware of the full discussion. I know you're on PTO, but it'd be nice if you could take a quick look. Thanks!

<%def name="impl_simple_wrapper_setter(ident, gecko_ffi_name)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
${set_gecko_property(gecko_ffi_name, "v.0")}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have something to implement stuff with conversions. Perhaps we should implement From and remove this mako code instead, wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great, I can try it.


#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
GreaterThanOrEqualToOneNumber(Number::from_computed_value(&computed.0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ick, that's a decent amount of boilerplate...

/// https://drafts.csswg.org/css-transitions/#animtype-number
impl Animatable for NonNegativeNumber {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we're not clamping here, and I think that's the intention, right? If so, some comments about it would be nice.

no_viewport_percentage!(GreaterThanOrEqualToOneNumber);

impl Parse for GreaterThanOrEqualToOneNumber {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove Number::parse_at_least_one and Number::parse_non_negative now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all non-negative properties are animated, so I didn't replace the type of all non-negative properties with NonNegativeNumber. I will try to check it.

@BorisChiou BorisChiou Aug 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I can do it, but if you don't mind, I'd like to remove Number::parse_at_least_one() and Number::parse_non_negative() in a follow-up PR to keep this not too complicated because it seems I have to update more types from Number to NonNegativeNumber.


#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
T { horizontal: NonNegativeAu::from_animated_value(animated.horizontal),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation here is weird.

T {
    horizontal: ...,
    vertical: ...,
}

use app_units::Au;
use std::cmp;
use values::computed::Angle as ComputedAngle;
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't addressed, I think.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

NonNegative<T> might be a good way to refactor these patches (in the same PR or others). I'd like to know what nox think.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

I just tried to use NonNegative<T> as the type of NonNegativeXXX, and it looks much better because lots of code could be written as template. I'd like to update a newer version by this way. Thanks for the suggestion, Emilio.

…neNumber.

NonNegativeNumber: for -moz-box-flex, flex-grow, and flex-shrink.
GreaterThanOrEqualToOneNumber: for stroke-miterlimit.

MozReview-Commit-ID: Kgbt99BPdVA
@BorisChiou

Copy link
Copy Markdown
Contributor Author

gecko try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=a2db4c2a8d83bd0d837350505cb5046edb029f0c

The test failures on the try is not related to these patches, so the overall status looks good now.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 8651acd with merge d1f22c0...

bors-servo pushed a commit that referenced this pull request Aug 4, 2017
stylo: Bug 1374233 - Clamp interpolated values for properties which need to be restricted

Some properties only accept non-negative values, or values greater than or equal to one. It is possible to produce an negative interpolated values while using negative timing functions, so we have to apply a restriction to these values to avoid getting invalid values.

For example, line-height must be non-negative, but the output progress of some timing functions (e,g. cubic-bezier(0.25, -2, 0.75, 1)) may be a negative value, so the interpolated result of line-height is also negative.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix Bug 1374233.
- [X] These changes do not require tests because we have tests in Gecko side already.

<!-- 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/17783)
<!-- Reviewable:end -->
@BorisChiou

Copy link
Copy Markdown
Contributor Author

I rebased the patches and use NonNegative<T> as the boilerplate to remove lots of redundant code.

@bors-servo

Copy link
Copy Markdown
Contributor

@nox

nox commented Aug 7, 2017

Copy link
Copy Markdown
Contributor

r=me if geckotry is green.

@emilio
emilio dismissed nox’s stale review August 7, 2017 13:11

(Comments addressed)

@BorisChiou

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I just push these commits to gecko try again. (Gecko try tree is closed now, so I will put the try link later.)

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@bors-servo r=nox

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 8651acd has been approved by nox

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors. labels Aug 7, 2017
@BorisChiou

Copy link
Copy Markdown
Contributor Author

@bors-servo p=1

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 8651acd with merge 016ea11...

bors-servo pushed a commit that referenced this pull request Aug 7, 2017
stylo: Bug 1374233 - Clamp interpolated values for properties which need to be restricted

Some properties only accept non-negative values, or values greater than or equal to one. It is possible to produce an negative interpolated values while using negative timing functions, so we have to apply a restriction to these values to avoid getting invalid values.

For example, line-height must be non-negative, but the output progress of some timing functions (e,g. cubic-bezier(0.25, -2, 0.75, 1)) may be a negative value, so the interpolated result of line-height is also negative.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix Bug 1374233.
- [X] These changes do not require tests because we have tests in Gecko side already.

<!-- 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/17783)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Aug 7, 2017
@jdm

jdm commented Aug 7, 2017

Copy link
Copy Markdown
Member

That's #17168; you can retry.

@BorisChiou

Copy link
Copy Markdown
Contributor Author

@bors-servo retry

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, mac-dev-unit, mac-rel-css1, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt4, windows-msvc-dev are reusable. Rebuilding only linux-rel-wpt, mac-rel-css2, mac-rel-wpt3...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: nox
Pushing 016ea11 to master...

@bors-servo
bors-servo merged commit 8651acd into servo:master Aug 7, 2017
@emilio emilio mentioned this pull request Dec 3, 2017
4 tasks done
@BorisChiou
BorisChiou deleted the stylo/animation/restrictions branch June 24, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-tests-failed The changes caused existing tests to fail.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants