Commit 01da4d86 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Remove NullValue() from CalculateDirectedProgress

NullValue() is represented as a NaN in a double. We could better return
a base::Optional<double> and use the undefined base::Optional as null
value. Also there is no need for the IsNull() call as we could just use
the returned value as a boolean.

Bug: 994811
Change-Id: I2c5eb88ba563486f4864480b8f842ce349c610f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760965
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689144}
parent 126276b8
......@@ -175,7 +175,7 @@ Timing::CalculatedTiming Timing::CalculateTimings(
overall_progress, simple_iteration_progress);
const bool current_direction_is_forwards =
IsCurrentDirectionForwards(current_iteration, direction);
const double directed_progress = CalculateDirectedProgress(
const base::Optional<double> directed_progress = CalculateDirectedProgress(
simple_iteration_progress, current_iteration, direction);
progress = CalculateTransformedProgress(
......
......@@ -242,13 +242,13 @@ static inline bool IsCurrentDirectionForwards(
}
// https://drafts.csswg.org/web-animations/#calculating-the-directed-progress
static inline double CalculateDirectedProgress(
static inline base::Optional<double> CalculateDirectedProgress(
double simple_iteration_progress,
double current_iteration,
Timing::PlaybackDirection direction) {
// 1. If the simple progress is unresolved, return unresolved.
if (IsNull(simple_iteration_progress))
return NullValue();
return base::nullopt;
// 2. Calculate the current direction.
bool current_direction_is_forwards =
......@@ -263,11 +263,11 @@ static inline double CalculateDirectedProgress(
// https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress
static inline base::Optional<double> CalculateTransformedProgress(
Timing::Phase phase,
double directed_progress,
base::Optional<double> directed_progress,
double iteration_duration,
bool is_current_direction_forward,
scoped_refptr<TimingFunction> timing_function) {
if (IsNull(directed_progress))
if (!directed_progress)
return base::nullopt;
// Set the before flag to indicate if at the leading edge of an iteration.
......@@ -282,17 +282,18 @@ static inline base::Optional<double> CalculateTransformedProgress(
// Snap boundaries to correctly render step timing functions at 0 and 1.
// (crbug.com/949373)
if (phase == Timing::kPhaseAfter) {
if (is_current_direction_forward && IsWithinEpsilon(directed_progress, 1)) {
if (is_current_direction_forward &&
IsWithinEpsilon(directed_progress.value(), 1)) {
directed_progress = 1;
} else if (!is_current_direction_forward &&
IsWithinEpsilon(directed_progress, 0)) {
IsWithinEpsilon(directed_progress.value(), 0)) {
directed_progress = 0;
}
}
// Return the result of evaluating the animation effect’s timing function
// passing directed progress as the input progress value.
return timing_function->Evaluate(directed_progress, limit_direction);
return timing_function->Evaluate(directed_progress.value(), limit_direction);
}
// Offsets the active time by how far into the animation we start (i.e. the
......
......@@ -275,8 +275,8 @@ TEST(AnimationTimingCalculationsTest, CalculateDirectedProgress) {
// direction);
// if the simple iteration progress is null
EXPECT_TRUE(IsNull(CalculateDirectedProgress(
NullValue(), NullValue(), Timing::PlaybackDirection::NORMAL)));
EXPECT_FALSE(CalculateDirectedProgress(NullValue(), NullValue(),
Timing::PlaybackDirection::NORMAL));
// forwards
EXPECT_EQ(0,
......@@ -324,7 +324,7 @@ TEST(AnimationTimingCalculationsTest, TransformedProgress) {
StepsTimingFunction::Create(4, StepsTimingFunction::StepPosition::END);
// directed_progress is null.
EXPECT_FALSE(CalculateTransformedProgress(Timing::kPhaseActive, NullValue(),
EXPECT_FALSE(CalculateTransformedProgress(Timing::kPhaseActive, base::nullopt,
1, true, timing_function));
// At step boundaries.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment