changeset 2885:c9d36dae8a70

RT-28907: CSS should only reset properites to initial values if there are no styles to apply to the node after an in-line style or stylesheet change
author David Grieve<david.grieve@oracle.com>
date Tue, 12 Mar 2013 14:04:23 -0400
parents e4bdba51e3b6
children ad5cee5bfad6
files javafx-ui-common/src/javafx/scene/CssStyleHelper.java javafx-ui-common/src/javafx/scene/Node.java javafx-ui-common/src/javafx/scene/Parent.java javafx-ui-common/src/javafx/scene/Scene.java
diffstat 4 files changed, 36 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Mon Mar 11 17:34:49 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/CssStyleHelper.java	Tue Mar 12 14:04:23 2013 -0400
@@ -133,6 +133,16 @@
                 }
                 
                 if (mightInherit == false) {
+                    
+                    // If this node had a style helper but no longer has
+                    // a StyleHelper, then reset properties to thier initial
+                    // value. If this node were to have a StyleHelper after
+                    // exiting this method, then transitionToState would take
+                    // care of resetting properties if needed. 
+                    if (node.styleHelper != null) {
+                        node.styleHelper.resetToInitialValues(node);
+                    }
+                    
                     return null;
                 }
             }
@@ -309,7 +319,6 @@
         // new styles, reset the properties to initial values.
         if (cacheMetaData != null) {
             
-            node.impl_cssResetInitialValues();
             cacheMetaData.localStyleCache.clear();
             
             // do we have any styles at all now?
@@ -322,6 +331,7 @@
                     // initial state so that calls to transitionToState 
                     // become a no-op.
                     cacheMetaData = null;
+                    resetToInitialValues(node);
                 }
                 
                 // If smap isn't empty, then there are styles that
@@ -357,6 +367,28 @@
         }
         
     }
+    
+    private void resetToInitialValues(Styleable styleable) {
+        
+        final List<CssMetaData<? extends Styleable, ?>> metaDataList = styleable.getCssMetaData();
+        final int nStyleables = metaDataList != null ? metaDataList.size() : 0;
+        for (int n=0; n<nStyleables; n++) {
+            final CssMetaData metaData = metaDataList.get(n);
+            if (metaData.isSettable(styleable) == false) continue;
+            final StyleableProperty<?> styleableProperty = metaData.getStyleableProperty(styleable);
+            if (styleableProperty != null) {
+                final StyleOrigin origin = styleableProperty.getStyleOrigin();
+                if (origin != null && origin != StyleOrigin.USER) {
+                    // If a property is never set by the user or by CSS, then 
+                    // the StyleOrigin of the property is null. So, passing null 
+                    // here makes the property look (to CSS) like it was
+                    // initialized but never used.
+                    metaData.set(styleable, metaData.getInitialValue(styleable), null);
+                }
+            }
+        }        
+    }
+    
         
     private Map<String, List<CascadingStyle>> getStyleMap() {
         if (cacheMetaData == null) return null;
--- a/javafx-ui-common/src/javafx/scene/Node.java	Mon Mar 11 17:34:49 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/Node.java	Tue Mar 12 14:04:23 2013 -0400
@@ -8183,38 +8183,6 @@
      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
      */
     @Deprecated
-    public void impl_cssResetInitialValues() {
-        
-        //
-        // RT-9784: reset all properties that have been set by CSS back
-        // to their default value. Called when a stylesheet is removed from
-        // a parent or from the scene. This has to be done before calling 
-        // impl_reapplyCSS.
-        //
-        final List<CssMetaData<? extends Styleable, ?>> metaDataList = getCssMetaData();
-        final int nStyleables = metaDataList != null ? metaDataList.size() : 0;
-        for (int n=0; n<nStyleables; n++) {
-            final CssMetaData metaData = metaDataList.get(n);
-            if (metaData.isSettable(this) == false) continue;
-            final StyleableProperty<?> styleableProperty = metaData.getStyleableProperty(this);
-            if (styleableProperty != null) {
-                final StyleOrigin origin = styleableProperty.getStyleOrigin();
-                if (origin != null && origin != StyleOrigin.USER) {
-                    // If a property is never set by the user or by CSS, then 
-                    // the StyleOrigin of the property is null. So, passing null 
-                    // here makes the property look (to CSS) like it was
-                    // initialized but never used.
-                    metaData.set(this, metaData.getInitialValue(this), null);
-                }
-            }
-        }        
-    }
-    
-    /**
-     * @treatAsPrivate implementation detail
-     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
-     */
-    @Deprecated
     public final void impl_reapplyCSS() {
         // If there is no scene, then we cannot make it dirty, so we'll leave
         // the flag alone
@@ -8327,9 +8295,11 @@
 
         if (cssFlag == CssFlags.REAPPLY) {
             
+            final boolean hadStyles = styleHelper != null;
+            
             // Match new styles if my own indicates I need to reapply
             styleHelper = CssStyleHelper.createStyleHelper(this);
-
+            
         } else if (cssFlag == CssFlags.RECALCULATE) {
             
             // Recalculate means that the in-line style has changed.
--- a/javafx-ui-common/src/javafx/scene/Parent.java	Mon Mar 11 17:34:49 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/Parent.java	Tue Mar 12 14:04:23 2013 -0400
@@ -1080,7 +1080,6 @@
                     if (c.wasRemoved() == false) {
                         continue;
                     }
-                    impl_cssResetInitialValues();
                     break; // no point in resetting more than once...
                 }
                 
@@ -1167,21 +1166,6 @@
         }
     }
     
-    /**
-     * @treatAsPrivate implementation detail
-     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
-     */
-    @Deprecated
-    @Override public void impl_cssResetInitialValues() {
-        // RT-9784
-        super.impl_cssResetInitialValues();
-
-        for (int i=0, max=children.size(); i<max; i++) {
-            children.get(i).impl_cssResetInitialValues();
-        }
-    }
-    
-
     /***********************************************************************
      *                               Misc                                  *
      *                                                                     *
--- a/javafx-ui-common/src/javafx/scene/Scene.java	Mon Mar 11 17:34:49 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/Scene.java	Tue Mar 12 14:04:23 2013 -0400
@@ -1394,7 +1394,6 @@
                 if (c.wasRemoved() == false) {
                     continue;
                 }
-                getRoot().impl_cssResetInitialValues();
                 break; // no point in resetting more than once...
             }
             getRoot().impl_reapplyCSS();