changeset 3981:1ec38d2759eb

[UNIT TEST] resolve unit test failures related to RT-30892
author David Grieve<david.grieve@oracle.com>
date Wed, 12 Jun 2013 16:30:02 -0400
parents 07be64d67626
children eaea57901d09
files javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java javafx-ui-common/src/com/sun/javafx/css/StyleManager.java javafx-ui-common/src/javafx/scene/CssStyleHelper.java javafx-ui-common/test/unit/com/sun/javafx/css/HonorDeveloperSettingsTest.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledText.java javafx-ui-controls/test/com/sun/javafx/scene/control/skin/LabeledTextTest.java
diffstat 6 files changed, 107 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-common/src/com/sun/javafx/css/CompoundSelector.java	Wed Jun 12 16:30:02 2013 -0400
@@ -241,7 +241,7 @@
             while (parent != null) {
                 if (selectors.get(index-1).applies(parent)) { 
                     Set<PseudoClass> parentStates = parent.getPseudoClassStates();
-                    return stateMatches(parent, states, index - 1);
+                    return stateMatches(parent, parentStates, index - 1);
                 }
                 // Otherwise we need to get the next parent and try again
                 parent = parent.getStyleableParent();
--- a/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Wed Jun 12 16:30:02 2013 -0400
@@ -1470,7 +1470,7 @@
         //
         // Create a style helper for this node from the styles that match.
         //
-        StyleMap smap = cache.getStyleMap(cacheContainer, node, triggerStates);
+        StyleMap smap = cache.getStyleMap(cacheContainer, node, triggerStates, hasInlineStyles);
 
         return smap;
     }
@@ -1737,9 +1737,9 @@
             this.cache = new HashMap<Key, Integer>();
         }
 
-        private StyleMap getStyleMap(CacheContainer cacheContainer, Node node, Set<PseudoClass>[] triggerStates) {
+        private StyleMap getStyleMap(CacheContainer cacheContainer, Node node, Set<PseudoClass>[] triggerStates, boolean hasInlineStyle) {
 
-            if (selectors == null || selectors.isEmpty()) {
+            if ((selectors == null || selectors.isEmpty()) && !hasInlineStyle) {
                 return StyleMap.EMPTY_MAP;
             }
 
@@ -1789,14 +1789,12 @@
                 }
             }
 
-            String inlineStyle = node.getStyle();
-            boolean hasInlineStyle = inlineStyle != null && inlineStyle.trim().isEmpty() == false;
-
             // nothing matched!
             if (nothingMatched && hasInlineStyle == false) {
                 return StyleMap.EMPTY_MAP;
             }
 
+            final String inlineStyle = node.getStyle();
             final Key keyObj = new Key(key, inlineStyle);
 
             if (cache.containsKey(keyObj)) {
--- a/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Wed Jun 12 16:30:02 2013 -0400
@@ -1475,6 +1475,7 @@
     {
 
         StyleOrigin origin = null;
+        int distance = 0;
 
         // Each time a sub-property is encountered, cvFont is passed along to
         // calculateValue and the resulting font becomes cvFont. In the end
@@ -1506,7 +1507,35 @@
         //
         CascadingStyle fontShorthand = getStyle(styleable, property, states);
         if (fontShorthand == null && lookupForFontCache == false) {
-            fontShorthand = getInheritedStyle(styleable, property);
+
+            Node parent = styleable != null ? styleable.getParent() : null;
+
+            while (parent != null) {
+
+                CssStyleHelper parentStyleHelper = parent.styleHelper;
+                if (parentStyleHelper != null) {
+
+                    distance += 1;
+
+                    Set<PseudoClass> transitionStates = parent.pseudoClassStates;
+                    CascadingStyle cascadingStyle = parentStyleHelper.getStyle(parent, property, transitionStates);
+
+                    if (cascadingStyle != null) {
+
+                        final ParsedValueImpl cssValue = cascadingStyle.getParsedValueImpl();
+
+                        if ("inherit".equals(cssValue.getValue()) == false) {
+                            fontShorthand = cascadingStyle;
+                            break;
+                        }
+                    }
+
+                }
+
+                parent = parent.getParent();
+
+            }
+
         }
 
         // if user set the font, then fontShorthand must be at zero
@@ -1535,9 +1564,8 @@
         }
 
         CascadingStyle fontSize = getStyle(styleable, property.concat("-size"), states);
-        // only inherit if font-shorthand is null
-        if (fontSize == null && fontShorthand == null && lookupForFontCache == false) {
-            fontSize = getInheritedStyle(styleable, property.concat("-size"));
+        if (fontSize == null && lookupForFontCache == false) {
+            fontSize = lookupInheritedFont(styleable, property.concat("-size"), distance);
         }
 
         // font-size must be closer and more specific than font shorthand
@@ -1570,7 +1598,7 @@
 
             CascadingStyle fontWeight = getStyle(styleable, property.concat("-weight"), states);
             if (fontWeight == null) {
-                fontWeight = getInheritedStyle(styleable,property.concat("-weight"));
+                fontWeight = lookupInheritedFont(styleable,property.concat("-weight"), distance);
             }
 
             if (fontWeight != null) {
@@ -1599,7 +1627,7 @@
 
             CascadingStyle fontStyle = getStyle(styleable, property.concat("-style"), states);
             if (fontStyle == null) {
-                fontStyle = getInheritedStyle(styleable, property.concat("-style"));
+                fontStyle = lookupInheritedFont(styleable, property.concat("-style"), distance);
             }
 
             if (fontStyle != null) {
@@ -1629,7 +1657,7 @@
 
             CascadingStyle fontFamily = getStyle(styleable, property.concat("-family"), states);
             if (fontFamily == null) {
-                fontFamily = getInheritedStyle(styleable,property.concat("-family"));
+                fontFamily = lookupInheritedFont(styleable,property.concat("-family"), distance);
             }
 
             if (fontFamily != null) {
@@ -1666,6 +1694,46 @@
     }
 
     /**
+     * Called when we must getInheritedStyle a value from a parent node in the scenegraph.
+     */
+    private CascadingStyle lookupInheritedFont(
+            Node styleable,
+            String property,
+            int distance) {
+
+        Node parent = styleable != null ? styleable.getParent() : null;
+
+        int nlooks = distance;
+        while (parent != null && nlooks >= 0) {
+
+            CssStyleHelper parentStyleHelper = parent.styleHelper;
+            if (parentStyleHelper != null) {
+
+                nlooks -= 1;
+
+                Set<PseudoClass> transitionStates = parent.pseudoClassStates;
+                CascadingStyle cascadingStyle = parentStyleHelper.getStyle(parent, property, transitionStates);
+
+                if (cascadingStyle != null) {
+
+                    final ParsedValueImpl cssValue = cascadingStyle.getParsedValueImpl();
+
+                    if ("inherit".equals(cssValue.getValue()) == false) {
+                        return cascadingStyle;
+                    }
+                }
+
+            }
+
+            parent = parent.getParent();
+
+        }
+
+        return null;
+    }
+
+
+    /**
      * Called from CssMetaData getMatchingStyles
      * @param node
      * @param styleableProperty
--- a/javafx-ui-common/test/unit/com/sun/javafx/css/HonorDeveloperSettingsTest.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-common/test/unit/com/sun/javafx/css/HonorDeveloperSettingsTest.java	Wed Jun 12 16:30:02 2013 -0400
@@ -26,6 +26,9 @@
 package com.sun.javafx.css;
 
 import static org.junit.Assert.*;
+
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.scene.Cursor;
 import javafx.scene.Group;
 import javafx.scene.Scene;
@@ -36,8 +39,10 @@
 import javafx.stage.Stage;
 import javafx.stage.Window;
 
+import com.sun.javafx.Logging;
 import org.junit.Before;
 import org.junit.Test;
+import sun.util.logging.PlatformLogger;
 
 /**
  * AKA: RT-7401. Tests that the pattern used works by testing opacity
@@ -116,7 +121,7 @@
         assertEquals(.873, rect.getOpacity(), 0.01);
     }
 
-    @Test @org.junit.Ignore("fails, but works from an application")
+    @Test
     public void testOpacityWithManuallyChangedValueAndInlineStyleIsSetToInlineStyle() {
         rect.impl_processCSS(true);
         assertEquals(.76, rect.getOpacity(), 0.01);
@@ -257,7 +262,7 @@
         
     }
     
-    @Test @org.junit.Ignore("fails, but works from an application")
+    @Test
     public void testInlineStyleInheritedFromParentApplies() {
 
         // Must remove the id so we don't match on the ua style.
@@ -354,7 +359,7 @@
 
         // want text to get font style from .root
         // assuming here that test_FontInheritsFromDotRootStyle passed
-        text.setId(null);        
+        text.setId(null);
         text.setStyle("-fx-font-size: 24;");
 
         scene.getRoot().impl_processCSS(true);
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledText.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledText.java	Wed Jun 12 16:30:02 2013 -0400
@@ -273,8 +273,8 @@
             //    not override
             //
             if (propOrigin == null ||
-                    newOrigin == null ||
-                    propOrigin.compareTo(newOrigin) <= 0) {
+                   (newOrigin != null &&
+                    propOrigin.compareTo(newOrigin) <= 0)) {
                 super.applyStyle(newOrigin, value);
             }
         }
--- a/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/LabeledTextTest.java	Wed Jun 12 10:26:26 2013 -0400
+++ b/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/LabeledTextTest.java	Wed Jun 12 16:30:02 2013 -0400
@@ -73,7 +73,7 @@
     public void testLabeledTextAlignmentStyleAffectsLabeledText() {
         
         label.setStyle("-fx-text-alignment: right;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(TextAlignment.RIGHT, label.getTextAlignment());
         assertEquals(TextAlignment.RIGHT, labeledText.getTextAlignment());
     
@@ -93,7 +93,7 @@
     public void testLabeledFontStyleAffectsLabeledText() {
         
         label.setStyle("-fx-font: 10px Amble;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         Font expected = Font.font("Amble", 10);
         assertEquals(expected, label.getFont());
         assertEquals(expected, labeledText.getFont());
@@ -114,7 +114,7 @@
     public void testLabeledTextFillStyleAffectsLabeledText() {
         
         label.setStyle("-fx-text-fill: rgb(255,0,0);");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         Color expected = Color.rgb(255, 0, 0);
         assertEquals(expected, label.getTextFill());
         assertEquals(expected, labeledText.getFill());
@@ -135,7 +135,7 @@
     public void testLabeledUnderlineStyleAffectsLabeledText() {
         
         label.setStyle("-fx-underline: true;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assert(label.isUnderline() == true);
         assert(labeledText.isUnderline() == true);
     
@@ -144,7 +144,7 @@
     @Test
     public void testLabeledBlendModeStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-blend-mode: color-burn;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(BlendMode.COLOR_BURN,label.getBlendMode());
         assertFalse(BlendMode.COLOR_BURN.equals(labeledText.getBlendMode())); 
     }
@@ -152,7 +152,7 @@
     @Test
     public void testLabeledCursorStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-cursor: crosshair;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(Cursor.CROSSHAIR,label.getCursor());
         assertFalse(Cursor.CROSSHAIR.equals(labeledText.getCursor()));
     }
@@ -160,7 +160,7 @@
     @Test
     public void testLabeledEffectStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-effect: dropshadow(one-pass-box, red, 64, .5, 2, 3);");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertNotNull(label.getEffect());
         assertNull(labeledText.getEffect()); 
     }
@@ -168,7 +168,7 @@
     @Test
     public void testLabeledFocusTraversableStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-focus-traversable: true;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assert(label.focusTraversableProperty().get() == true);   
         assert(labeledText.focusTraversableProperty().get() == false);   
     }
@@ -176,7 +176,7 @@
     @Test
     public void testLabeledOpacityStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-opacity: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getOpacity(), .5, .0000001);   
         assertEquals(labeledText.getOpacity(), 1, .0000001);   
     }
@@ -184,7 +184,7 @@
     @Test
     public void testLabeledRotateStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-rotate: 180;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getRotate(), 180, .0000001);
         assertEquals(labeledText.getRotate(), 0, .0000001);   
     }
@@ -192,7 +192,7 @@
     @Test
     public void testLabeledScaleXStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-scale-x: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getScaleX(), .5, .0000001);
         assertEquals(labeledText.getScaleX(), 1, .0000001);   
     }
@@ -200,7 +200,7 @@
     @Test
     public void testLabeledScaleYStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-scale-y: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getScaleY(), .5, .0000001);
         assertEquals(labeledText.getScaleY(), 1, .0000001);   
     }
@@ -208,7 +208,7 @@
     @Test
     public void testLabeledScaleZStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-scale-z: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getScaleZ(), .5, .0000001);
         assertEquals(labeledText.getScaleZ(), 1, .0000001);   
     }
@@ -216,7 +216,7 @@
     @Test
     public void testLabeledTranslateXStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-translate-x: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getTranslateX(), .5, .0000001);
         assertEquals(labeledText.getTranslateX(), 0, .0000001);   
     }
@@ -224,7 +224,7 @@
     @Test
     public void testLabeledTranslateYStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-translate-y: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getTranslateY(), .5, .0000001);
         assertEquals(labeledText.getTranslateY(), 0, .0000001);   
     }
@@ -232,7 +232,7 @@
     @Test
     public void testLabeledTranslateZStyleDoesNotAffectLabeledText() {
         label.setStyle("-fx-translate-z: .5;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assertEquals(label.getTranslateZ(), .5, .0000001);
         assertEquals(labeledText.getTranslateZ(), 0, .0000001);   
     }
@@ -240,7 +240,7 @@
     @Test
     public void testLabeledVisibilityStyleDoesNotAffectLabeledText() {
         label.setStyle("visibility: false;");
-        label.impl_processCSS(false);
+        label.impl_processCSS(true);
         assert(label.visibleProperty().get() == false);   
         assert(labeledText.visibleProperty().get() == true);   
     }