diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c
index 601e4064ca..c1b10c7efd 100644
--- a/gtk/gtkcssanimation.c
+++ b/gtk/gtkcssanimation.c
@@ -68,37 +68,35 @@ static double
gtk_css_animation_get_progress_from_iteration (GtkCssAnimation *animation,
double iteration)
{
- double d;
+ gboolean reverse;
+ double completed;
- iteration = CLAMP (iteration, 0, animation->iteration_count);
+ iteration = CLAMP (iteration, 0.0, animation->iteration_count);
+ completed = floor (iteration);
switch (animation->direction)
{
case GTK_CSS_DIRECTION_NORMAL:
- if (iteration == animation->iteration_count)
- return 1;
- else
- return iteration - floor (iteration);
+ reverse = completed == iteration && iteration > 0;
+ break;
case GTK_CSS_DIRECTION_REVERSE:
- if (iteration == animation->iteration_count)
- return 1;
- else
- return ceil (iteration) - iteration;
+ reverse = !(completed == iteration && iteration > 0);
+ break;
case GTK_CSS_DIRECTION_ALTERNATE:
- d = floor (iteration);
- if (fmod (d, 2))
- return 1 + d - iteration;
- else
- return iteration - d;
+ reverse = fmod (iteration, 2) >= 1.0;
+ break;
case GTK_CSS_DIRECTION_ALTERNATE_REVERSE:
- d = floor (iteration);
- if (fmod (d, 2))
- return iteration - d;
- else
- return 1 + d - iteration;
+ reverse = !(fmod (iteration, 2) >= 1.0);
+ break;
default:
- g_return_val_if_reached (0);
+ g_return_val_if_reached (0.0);
}
+
+ iteration -= completed;
+ if (reverse)
+ iteration = 1.0 - iteration;
+
+ return iteration;
}
static void
diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am
index cd005233cc..0183508cb1 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -83,6 +83,9 @@ testdata = \
animation-direction.css \
animation-direction.ref.ui \
animation-direction.ui \
+ animation-fill-mode-iteration-count.css \
+ animation-fill-mode-iteration-count.ref.ui \
+ animation-fill-mode-iteration-count.ui \
background-area.css \
background-area.ref.ui \
background-area.ui \
diff --git a/testsuite/reftests/animation-fill-mode-iteration-count.css b/testsuite/reftests/animation-fill-mode-iteration-count.css
new file mode 100644
index 0000000000..db65050bb4
--- /dev/null
+++ b/testsuite/reftests/animation-fill-mode-iteration-count.css
@@ -0,0 +1,83 @@
+@keyframes cssrocks {
+ from { background-color: yellow; }
+ to { background-color: red; }
+}
+
+box {
+ background-color: blue;
+ animation-fill-mode: both;
+ animation-duration: 100s;
+ padding: 1px;
+ background-clip: content-box;
+ animation-timing-function: linear;
+}
+
+.after {
+ animation-name: cssrocks;
+ animation-delay: -10000s;
+}
+
+.before {
+ animation-name: cssrocks;
+ animation-delay: 10000s;
+}
+
+.normal {
+ animation-direction: normal;
+}
+
+.reverse {
+ animation-direction: reverse;
+}
+
+.alternate {
+ animation-direction: alternate;
+}
+
+.alternate-reverse {
+ animation-direction: alternate-reverse;
+}
+
+.x0 {
+ animation-iteration-count: 0;
+}
+
+.x02 {
+ animation-iteration-count: 0.2;
+}
+
+.x1 {
+ animation-iteration-count: 1;
+}
+
+.x12 {
+ animation-iteration-count: 1.2;
+}
+
+.x2 {
+ animation-iteration-count: 2;
+}
+
+.x22 {
+ animation-iteration-count: 2.2;
+}
+
+.yellow {
+ animation: none;
+ background-color: yellow;
+}
+
+.red {
+ animation: none;
+ background-color: red;
+}
+
+.darkorange {
+ animation: none;
+ background-color: rgb(255,51,0);
+}
+
+.lightorange {
+ animation: none;
+ background-color: rgb(255,204,0);
+}
diff --git a/testsuite/reftests/animation-fill-mode-iteration-count.ref.ui b/testsuite/reftests/animation-fill-mode-iteration-count.ref.ui
new file mode 100644
index 0000000000..914e4e8cbc
--- /dev/null
+++ b/testsuite/reftests/animation-fill-mode-iteration-count.ref.ui
@@ -0,0 +1,1117 @@
+
+
+
+
+
+
diff --git a/testsuite/reftests/animation-fill-mode-iteration-count.ui b/testsuite/reftests/animation-fill-mode-iteration-count.ui
new file mode 100644
index 0000000000..cfb64c74fa
--- /dev/null
+++ b/testsuite/reftests/animation-fill-mode-iteration-count.ui
@@ -0,0 +1,1213 @@
+
+
+
+
+
+ False
+
+
+ True
+ False
+
+
+ True
+ False
+ normal
+
+
+ 0
+ 1
+
+
+
+
+ True
+ False
+ reverse
+
+
+ 0
+ 2
+
+
+
+
+ True
+ False
+ alternate
+
+
+ 0
+ 3
+
+
+
+
+ True
+ False
+ alternate-reverse
+
+
+ 0
+ 4
+
+
+
+
+ True
+ False
+ -->
+2⅕x
+
+
+ 12
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 12
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 12
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 12
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 12
+ 4
+
+
+
+
+ True
+ False
+ <--
+2⅕x
+
+
+ 11
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 11
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 11
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 11
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 11
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 10
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 10
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 10
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 10
+ 1
+
+
+
+
+ True
+ False
+ -->
+2x
+
+
+ 10
+ 0
+
+
+
+
+ True
+ False
+ <--
+2x
+
+
+ 9
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 9
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 9
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 9
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 9
+ 4
+
+
+
+
+ True
+ False
+ -->
+1⅕x
+
+
+ 8
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 8
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 8
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 8
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 8
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 7
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 7
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 7
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 7
+ 1
+
+
+
+
+ True
+ False
+ <--
+1⅕x
+
+
+ 7
+ 0
+
+
+
+
+ True
+ False
+ -->
+1x
+
+
+ 6
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 6
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 6
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 6
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 6
+ 4
+
+
+
+
+ True
+ False
+ <--
+1x
+
+
+ 5
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 5
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 5
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 5
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 5
+ 4
+
+
+
+
+ True
+ False
+ <--
+⅕x
+
+
+ 3
+ 0
+
+
+
+
+ True
+ False
+ -->
+⅕x
+
+
+ 4
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 3
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 4
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 4
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 3
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 3
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 4
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 3
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 4
+ 4
+
+
+
+
+ True
+ False
+ <--
+0x
+
+
+ 1
+ 0
+
+
+
+
+ True
+ False
+ -->
+0x
+
+
+ 2
+ 0
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 1
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 2
+ 1
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 2
+ 2
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 2
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 2
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 1
+ 4
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 1
+ 3
+
+
+
+
+ 50
+ 50
+ True
+ False
+ vertical
+
+
+
+
+
+
+ 1
+ 2
+
+
+
+
+
+
+
+
+