changeset 7916:4c3674e9ab57

RT-38483: [CSS] add indefinite as a value for duration type
author David Grieve<david.grieve@oracle.com>
date Fri, 29 Aug 2014 09:37:30 -0400
parents fd2937307d22
children c157e2f9a534
files modules/graphics/src/main/docs/javafx/scene/doc-files/cssref.html modules/graphics/src/main/java/com/sun/javafx/css/converters/DurationConverter.java modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSParser.java modules/graphics/src/test/java/com/sun/javafx/css/parser/CSSParserTest.java
diffstat 4 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/docs/javafx/scene/doc-files/cssref.html	Fri Aug 29 15:41:00 2014 +0200
+++ b/modules/graphics/src/main/docs/javafx/scene/doc-files/cssref.html	Fri Aug 29 09:37:30 2014 -0400
@@ -817,12 +817,13 @@
     </ul>
     <h3><a name="typeduration" id="typeduration">&lt;duration&gt;</a></h3>
     <p>A duration is a <a href="#typenumber" class="typeref">&lt;number&gt;</a>
-        with one of the following units.</p>
+        with second or millisecond units, or the value <span class="grammar">indefinite</span>.</p>
     <p> </p>
-    <p class="grammar"><a href="#typenumber">&lt;number&gt;</a>[ s | ms ]</p>
+    <p class="grammar">[<a href="#typenumber">&lt;number&gt;</a>[ s | ms ]] | indefinite</p>
     <ul>
         <li><strong>s</strong>: duration in seconds</li>
         <li><strong>ms</strong>: duration in milliseconds. One second is 1000 milliseconds.</li>
+        <li><strong>indefinite</strong>: See <a href="../../util/Duration.html#INDEFINITE" class="typelink">Duration.INDEFINITE</a></li>
     </ul>
     <p>See also <a href="http://www.w3.org/TR/css3-values/#time" class="typelink">W3C time units</a>.</p>
     <h3><a name="typepoint" id="typepoint">&lt;point&gt;</a></h3>
--- a/modules/graphics/src/main/java/com/sun/javafx/css/converters/DurationConverter.java	Fri Aug 29 15:41:00 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/converters/DurationConverter.java	Fri Aug 29 09:37:30 2014 -0400
@@ -54,10 +54,14 @@
         Size size = parsedValue.convert(font);
         double time = size.getValue();
         Duration duration = null;
-        switch (size.getUnits()) {
-            case S: duration = Duration.seconds(time); break;
-            case MS: duration = Duration.millis(time); break;
-            default: duration = Duration.UNKNOWN;
+        if (time < Double.POSITIVE_INFINITY) {
+            switch (size.getUnits()) {
+                case S:  duration = Duration.seconds(time); break;
+                case MS: duration = Duration.millis(time);  break;
+                default: duration = Duration.UNKNOWN;
+            }
+        } else {
+            duration = Duration.INDEFINITE;
         }
         return duration;
     }
--- a/modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSParser.java	Fri Aug 29 15:41:00 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSParser.java	Fri Aug 29 09:37:30 2014 -0400
@@ -885,6 +885,10 @@
                 Size size = new Size(Double.MAX_VALUE, SizeUnits.PX);
                 ParsedValueImpl sizeValue = new ParsedValueImpl<Size,Number>(size, null);
                 value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(sizeValue, SizeConverter.getInstance());
+            } else if ("indefinite".equals(text)) {
+                Size size = new Size(Double.POSITIVE_INFINITY, SizeUnits.PX);
+                ParsedValueImpl<Size,Size> sizeValue = new ParsedValueImpl<>(size, null);
+                value = new ParsedValueImpl<ParsedValue<?,Size>,Duration>(sizeValue, DurationConverter.getInstance());
             } else if ("true".equals(text)) {
                 // TODO: handling of boolean is really bogus
                 value = new ParsedValueImpl<String,Boolean>("true",BooleanConverter.getInstance());
--- a/modules/graphics/src/test/java/com/sun/javafx/css/parser/CSSParserTest.java	Fri Aug 29 15:41:00 2014 +0200
+++ b/modules/graphics/src/test/java/com/sun/javafx/css/parser/CSSParserTest.java	Fri Aug 29 09:37:30 2014 -0400
@@ -42,6 +42,7 @@
 import javafx.scene.paint.Paint;
 import javafx.scene.paint.Stop;
 import javafx.scene.text.Font;
+import javafx.util.Duration;
 import org.junit.Test;
 import static org.junit.Assert.*;
 
@@ -293,4 +294,16 @@
         assertEquals(1d, (Number)obj);
 
     }
+
+    @Test public void testRT_38483() {
+
+        Duration expected = Duration.millis(42);
+        ParsedValue value = CSSParser.getInstance().parseExpr("foo", "42ms;");
+        Object observed = value.convert(null);
+        assertEquals(expected, observed);
+
+        value = CSSParser.getInstance().parseExpr("foo", "indefinite;");
+        observed = value.convert(null);
+        assertEquals(Duration.INDEFINITE, observed);
+    }
 }