changeset 10556:c03a52eca7f3 jdk-10+15

8177636: Reduce frequency of CSS resetting properties temporarily to initial state Reviewed-by: jgiles
author aghaisas
date Tue, 11 Jul 2017 12:34:02 +0530
parents 4df27a309a40
children f64e758c3bc0 32fc316a8fc7
files modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java
diffstat 1 files changed, 50 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java	Fri Jul 07 14:32:44 2017 -0700
+++ b/modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java	Tue Jul 11 12:34:02 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -157,7 +157,7 @@
                 // If this node had a style helper, then reset properties to their initial value
                 // since the node won't have a style helper after this call
                 if (node.styleHelper != null) {
-                    node.styleHelper.resetToInitialValues(node);
+                    node.styleHelper.resetToInitialValues(node, null);
                 }
 
                 //
@@ -178,9 +178,15 @@
         // If this node had a style helper, then reset properties to their initial value
         // since the style map might now be different
         if (node.styleHelper != null) {
-            node.styleHelper.resetToInitialValues(node);
+            StyleMap oldMap = node.styleHelper.getStyleMap(node);
+            StyleMap newMap = helper.getStyleMap(node);
+
+            if (oldMap != newMap) {
+                node.styleHelper.resetToInitialValues(node, null);
+            } else {
+                node.styleHelper.resetToInitialValues(node, newMap);
+            }
         }
-
         return helper;
     }
 
@@ -432,29 +438,58 @@
         private boolean forceSlowpath = false;
     }
 
-    private void resetToInitialValues(final Styleable styleable) {
+    private void resetToInitialValues(final Styleable styleable, StyleMap smap) {
+
+        // This method is invoked on a styleHelper before it is being reset
+        // to null or a new StyleHelper.
+        //
+        // if smap is null/empty -- it means node will not have any new styles
+        // in immediate future.
+        //
+        // Action taken in this method :
+        // reset all styleableProperties  in cssSetProperties to initial values
+
+        // if smap is a valid StyleMap -- it means node will have styles from
+        // new stylemap in immediate future
+        //
+        // Action taken in this method :
+        // reset styleableProperties in cssSetProperties in case they are not
+        // present in smap
 
         if (cacheContainer == null ||
                 cacheContainer.cssSetProperties == null ||
                 cacheContainer.cssSetProperties.isEmpty()) return;
 
         // RT-31714 - make a copy of the entry set and clear the cssSetProperties immediately.
-        Set<Entry<CssMetaData, CalculatedValue>> entrySet = new HashSet<>(cacheContainer.cssSetProperties.entrySet());
+        Set<Entry<CssMetaData, CalculatedValue>> entrySet =
+                new HashSet<>(cacheContainer.cssSetProperties.entrySet());
         cacheContainer.cssSetProperties.clear();
 
-        for (Entry<CssMetaData, CalculatedValue> resetValues : entrySet) {
-
-            final CssMetaData metaData = resetValues.getKey();
-            final StyleableProperty styleableProperty = metaData.getStyleableProperty(styleable);
-
-            final StyleOrigin styleOrigin = styleableProperty.getStyleOrigin();
-            if (styleOrigin != null && styleOrigin != StyleOrigin.USER) {
-                final CalculatedValue calculatedValue = resetValues.getValue();
-                styleableProperty.applyStyle(calculatedValue.getOrigin(), calculatedValue.getValue());
+        if (smap == null || smap.isEmpty() ) {
+            for (Entry<CssMetaData, CalculatedValue> resetValues : entrySet) {
+                final CssMetaData metaData = resetValues.getKey();
+                setStyleableProperty(metaData.getStyleableProperty(styleable), resetValues.getValue());
+            }
+        } else {
+            Map<String, List<CascadingStyle>> newStyles = smap.getCascadingStyles();
+
+            for (Entry<CssMetaData, CalculatedValue> resetValues : entrySet) {
+                final CssMetaData metaData = resetValues.getKey();
+
+                if (newStyles.containsKey(metaData.getProperty()) == false) {
+                    // earlier set property is not available in new Stylemap - reset it to initial value
+                    setStyleableProperty(metaData.getStyleableProperty(styleable), resetValues.getValue());
+                }
             }
         }
     }
 
+    private void setStyleableProperty(StyleableProperty property, CalculatedValue value) {
+        final StyleOrigin styleOrigin = property.getStyleOrigin();
+        if (styleOrigin != null && styleOrigin != StyleOrigin.USER) {
+            property.applyStyle(value.getOrigin(), value.getValue());
+        }
+    }
 
     private StyleMap getStyleMap(Styleable styleable) {
         if (cacheContainer == null || styleable == null) return null;