changeset 11248:58afdd563c0d

8222222: Gradients defined in CSS always use "reflect" even when "repeat" is specified Reviewed-by: kcr, aghaisas
author arapte
date Wed, 17 Apr 2019 10:22:34 +0530
parents 01da8b583966
children 3f29f685f4e1
files modules/javafx.graphics/src/main/java/javafx/css/CssParser.java modules/javafx.graphics/src/test/java/test/javafx/scene/paint/LinearGradientTest.java modules/javafx.graphics/src/test/java/test/javafx/scene/paint/RadialGradientTest.java
diffstat 3 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/javafx/css/CssParser.java	Tue Apr 16 15:25:29 2019 -0700
+++ b/modules/javafx.graphics/src/main/java/javafx/css/CssParser.java	Wed Apr 17 10:22:34 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1875,7 +1875,7 @@
             prev = arg;
             arg = arg.nextArg;
         } else if ("repeat".equalsIgnoreCase(arg.token.getText())) {
-            cycleMethod = CycleMethod.REFLECT;
+            cycleMethod = CycleMethod.REPEAT;
             prev = arg;
             arg = arg.nextArg;
         }
@@ -2175,7 +2175,7 @@
             prev = arg;
             arg = arg.nextArg;
         } else if ("repeat".equalsIgnoreCase(arg.token.getText())) {
-            cycleMethod = CycleMethod.REFLECT;
+            cycleMethod = CycleMethod.REPEAT;
             prev = arg;
             arg = arg.nextArg;
         }
--- a/modules/javafx.graphics/src/test/java/test/javafx/scene/paint/LinearGradientTest.java	Tue Apr 16 15:25:29 2019 -0700
+++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/paint/LinearGradientTest.java	Wed Apr 17 10:22:34 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,12 @@
 import java.util.Arrays;
 import java.util.List;
 import com.sun.javafx.tk.Toolkit;
+import javafx.scene.layout.Region;
 import javafx.scene.paint.Color;
 import javafx.scene.paint.CycleMethod;
 import javafx.scene.paint.LinearGradient;
 import javafx.scene.paint.Stop;
+import javafx.scene.Scene;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -438,4 +440,23 @@
                 new Stop(1.0, Color.BLACK));
         assertEquals(expected, actual);
     }
+
+    @Test
+    public void testCycleMethodCSSStyle() {
+        Region region = new Region();
+        Scene scene = new Scene(region);
+        LinearGradient lGradient;
+
+        region.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 10% 10%,"
+            + " reflect, red 30%, black 70%);");
+        region.applyCss();
+        lGradient = (LinearGradient) region.backgroundProperty().get().getFills().get(0).getFill();
+        assertEquals(CycleMethod.REFLECT, lGradient.getCycleMethod());
+
+        region.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 10% 10%,"
+            + " repeat, red 30%, black 70%);");
+        region.applyCss();
+        lGradient = (LinearGradient) region.backgroundProperty().get().getFills().get(0).getFill();
+        assertEquals(CycleMethod.REPEAT, lGradient.getCycleMethod());
+    }
 }
--- a/modules/javafx.graphics/src/test/java/test/javafx/scene/paint/RadialGradientTest.java	Tue Apr 16 15:25:29 2019 -0700
+++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/paint/RadialGradientTest.java	Wed Apr 17 10:22:34 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,10 +28,12 @@
 import java.util.Arrays;
 import java.util.List;
 import com.sun.javafx.tk.Toolkit;
+import javafx.scene.layout.Region;
 import javafx.scene.paint.Color;
 import javafx.scene.paint.CycleMethod;
 import javafx.scene.paint.RadialGradient;
 import javafx.scene.paint.Stop;
+import javafx.scene.Scene;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -466,4 +468,23 @@
                 new Stop(1.0, Color.RED));
         assertEquals(expected, actual);
     }
+
+    @Test
+    public void testCycleMethodCSSStyle() {
+        Region region = new Region();
+        Scene scene = new Scene(region);
+        RadialGradient rGradient;
+
+        region.setStyle("-fx-background-color: radial-gradient(focus-angle 45deg,"
+            + " focus-distance 20%, center 25% 25%, radius 50%, reflect, red 25%, black 75%);");
+        region.applyCss();
+        rGradient = (RadialGradient) region.backgroundProperty().get().getFills().get(0).getFill();
+        assertEquals(CycleMethod.REFLECT, rGradient.getCycleMethod());
+
+        region.setStyle("-fx-background-color: radial-gradient(focus-angle 45deg,"
+            + " focus-distance 20%, center 25% 25%, radius 50%, repeat, red 25%, black 75%);");
+        region.applyCss();
+        rGradient = (RadialGradient) region.backgroundProperty().get().getFills().get(0).getFill();
+        assertEquals(CycleMethod.REPEAT, rGradient.getCycleMethod());
+    }
 }