## javafx-ui-common/src/javafx/scene/Node.java

Print this page

    rev 1582 : RT-22121: Have StyleManager for Parent, also

    1534      */
    1535     public void toFront() {
    1536         if (getParent() != null) {
    1537             getParent().impl_toFront(this);
    1538         }
    1539     }
    1540
    1541     // TODO: need to verify whether this is OK to do starting from a node in
    1542     // the scene graph other than the root.
    1543     private void doCSSPass() {
    1544         if (this.cssFlag != CSSFlags.CLEAN) {
    1545             // The dirty bit isn't checked but we must ensure it is cleared.
    1546             // The cssFlag is set to clean in either Node.processCSS or
    1547             // Node.impl_processCSS(boolean)
    1548
    1549             // Don't clear the dirty bit in case it will cause problems
    1550             // with a full CSS pass on the scene.
    1551             // TODO: is this the right thing to do?
    1552             // this.impl_clearDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS);
    1553
    1554             this.processCSS();
    1555         }
    1556     }
    1557
    1558     /**
    1559      * Recursive function for synchronizing a node and all descendents
    1560      */
    1561     private static void syncAll(Node node) {
    1562         node.impl_syncPGNode();
    1563         if (node instanceof Parent) {
    1564             Parent p = (Parent) node;
    1565             final int childrenCount = p.getChildren().size();
    1566
    1567             for (int i = 0; i < childrenCount; i++) {
    1568                 Node n = p.getChildren().get(i);
    1569                 if (n != null) {
    1570                     syncAll(n);
    1571                 }
    1572             }
    1573         }
    1574         if (node.getClip() != null) {
    7291     private void notifyParentsOfInvalidatedCSS() {
    7292         if (!getScene().getRoot().impl_isDirty(DirtyBits.NODE_CSS)) {
    7293             // Ensure that Scene.root is marked as dirty. If the scene isn't
    7294             // dirty, nothing will get repainted. This bit is cleared from
    7295             // Scene in doCSSPass().
    7296             getScene().getRoot().impl_markDirty(DirtyBits.NODE_CSS);
    7297         }
    7298         Parent parent = getParent();
    7299         while (parent != null) {
    7300             if (parent.cssFlag == CSSFlags.CLEAN) {
    7301                 parent.cssFlag = CSSFlags.DIRTY_BRANCH;
    7302                 parent = parent.getParent();
    7303             } else {
    7304                 parent = null;
    7305             }
    7306         }
    7307     }
    7308
    7309     // this function primarily exists as a hook to aid in testing
    7310     boolean isPseudoclassUsed(String pseudoclass) {
    7311         final StyleHelper styleHelper = impl_getStyleHelper();
    7312         return (styleHelper != null) ? styleHelper.isPseudoclassUsed(pseudoclass) : false;
    7313     }
    7314
    7315     /**
    7316      * @treatAsPrivate implementation detail
    7317      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7318      */
    7319     @Deprecated
    7320     public void impl_cssResetInitialValues() {
    7321
    7322         //
    7323         // RT-9784: reset all properties that have been set by CSS back
    7324         // to their default value. Called when a stylesheet is removed from
    7325         // a parent or from the scene. This has to be done before calling
    7326         // impl_reapplyCSS.
    7327         //
    7328         final List<StyleableProperty> styleables = impl_getStyleableProperties();
    7329         final int nStyleables = styleables != null ? styleables.size() : 0;
    7330         for (int n=0; n<nStyleables; n++) {
    7331             final StyleableProperty styleable = styleables.get(n);
    7355         if (getScene() == null) return;
    7356         // If the css flag is already "REAPPLY", then do nothing
    7357         if (cssFlag == CSSFlags.REAPPLY) return;
    7358         // Update the flag
    7359         cssFlag = CSSFlags.REAPPLY;
    7360
    7361         // One idiom employed by developers is to, during the layout pass,
    7362         // add or remove nodes from the scene. For example, a ScrollPane
    7363         // might add scroll bars to itself if it determines during layout
    7364         // that it needs them, or a ListView might add cells to itself if
    7365         // it determines that it needs to. In such situations we must
    7366         // apply the CSS immediately and not add it to the scene's queue
    7367         // for deferred action.
    7368         if (getParent() != null && getParent().performingLayout) {
    7369             impl_processCSS(true);
    7370         } else if (getScene() != null) {
    7371             notifyParentsOfInvalidatedCSS();
    7372         }
    7373     }
    7374
    7375     void processCSS() {
    7376         switch (cssFlag) {
    7377             case CLEAN:
    7378                 break;
    7379             case DIRTY_BRANCH:
    7380                 Parent me = (Parent)this;
    7381                 // clear the flag first in case the flag is set to something
    7382                 // other than clean by downstream processing.
    7383                 me.cssFlag = CSSFlags.CLEAN;
    7384                 List<Node> children = me.getChildren();
    7385                 for (int i=0, max=children.size(); i<max; i++) {
    7386                     children.get(i).processCSS();
    7387                 }
    7388                 break;
    7389             case REAPPLY:
    7390             case UPDATE:
    7391             default:
    7392                 impl_processCSS(cssFlag == CSSFlags.REAPPLY);
    7393         }
    7394     }
    7395
    7396     /**
    7397      * If invoked, will update / reapply styles from here on down. If reapply
    7398      * is false, then we will only update from here on down, otherwise we will
    7399      * do a full reapply.
    7400      *
    7401      * @treatAsPrivate implementation detail
    7402      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7403      */
    7404     @Deprecated // SB-dependency: RT-21206 has been filed to track this
    7405     public void impl_processCSS(boolean reapply) {

    7406
    7407         StyleHelper styleHelper = null;
    7408         // Create a new StyleHelper either if I am told I need to reapply
    7409         // or if my own flag indicates I need to reapply
    7410         if (reapply || (cssFlag == CSSFlags.REAPPLY)) {
    7411
    7412             styleHelper = impl_createStyleHelper();
    7413
    7414         } else {
    7415             styleHelper = impl_getStyleHelper();
    7416         }
    7417
    7418         // Clear the flag first in case the flag is set to something
    7419         // other than clean by downstream processing.
    7420         cssFlag = CSSFlags.CLEAN;
    7421
    7422         // Transition to the new state
    7423         if (styleHelper != null) {
    7424             styleHelper.transitionToState(this);
    7425         }
    7426     }
    7427
    7428     /**
    7429      * A StyleHelper for this node.
    7430      * A StyleHelper contains all the css styles for this node
    7431      * and knows how to apply them when our state changes.
    7432      */
    7433     private StyleHelper styleHelper;
    7434
    7435     /**
    7436      * @treatAsPrivate implementation detail
    7437      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7438      */
    7439     @Deprecated
    7440     protected StyleHelper impl_createStyleHelper() {
    7441
    7442         styleHelper = getScene().styleManager.getStyleHelper(this);
    7443         return styleHelper;
    7444     }
    7445
    7446     /**
    7447      * Get this nodes StyleHelper
    7448      * @treatAsPrivate implementation detail
    7449      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7450      */
    7451     @Deprecated
    7452     public StyleHelper impl_getStyleHelper() {
    7453         return styleHelper;
    7454     }
    7455
    7456     private static final long HOVER_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("hover");
    7457     private static final long PRESSED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("pressed");
    7458     private static final long DISABLED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("disabled");
    7459     private static final long FOCUSED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("focused");
    7460     private static final long SHOW_MNEMONICS_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("show-mnemonics");
    7461
    7462     /**
    7463      * @treatAsPrivate implementation detail
    7464      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1534      */
    1535     public void toFront() {
    1536         if (getParent() != null) {
    1537             getParent().impl_toFront(this);
    1538         }
    1539     }
    1540
    1541     // TODO: need to verify whether this is OK to do starting from a node in
    1542     // the scene graph other than the root.
    1543     private void doCSSPass() {
    1544         if (this.cssFlag != CSSFlags.CLEAN) {
    1545             // The dirty bit isn't checked but we must ensure it is cleared.
    1546             // The cssFlag is set to clean in either Node.processCSS or
    1547             // Node.impl_processCSS(boolean)
    1548
    1549             // Don't clear the dirty bit in case it will cause problems
    1550             // with a full CSS pass on the scene.
    1551             // TODO: is this the right thing to do?
    1552             // this.impl_clearDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS);
    1553
    1554             this.processCSS(getScene().styleManager);
    1555         }
    1556     }
    1557
    1558     /**
    1559      * Recursive function for synchronizing a node and all descendents
    1560      */
    1561     private static void syncAll(Node node) {
    1562         node.impl_syncPGNode();
    1563         if (node instanceof Parent) {
    1564             Parent p = (Parent) node;
    1565             final int childrenCount = p.getChildren().size();
    1566
    1567             for (int i = 0; i < childrenCount; i++) {
    1568                 Node n = p.getChildren().get(i);
    1569                 if (n != null) {
    1570                     syncAll(n);
    1571                 }
    1572             }
    1573         }
    1574         if (node.getClip() != null) {
    7291     private void notifyParentsOfInvalidatedCSS() {
    7292         if (!getScene().getRoot().impl_isDirty(DirtyBits.NODE_CSS)) {
    7293             // Ensure that Scene.root is marked as dirty. If the scene isn't
    7294             // dirty, nothing will get repainted. This bit is cleared from
    7295             // Scene in doCSSPass().
    7296             getScene().getRoot().impl_markDirty(DirtyBits.NODE_CSS);
    7297         }
    7298         Parent parent = getParent();
    7299         while (parent != null) {
    7300             if (parent.cssFlag == CSSFlags.CLEAN) {
    7301                 parent.cssFlag = CSSFlags.DIRTY_BRANCH;
    7302                 parent = parent.getParent();
    7303             } else {
    7304                 parent = null;
    7305             }
    7306         }
    7307     }
    7308
    7309     // this function primarily exists as a hook to aid in testing
    7310     boolean isPseudoclassUsed(String pseudoclass) {

    7311         return (styleHelper != null) ? styleHelper.isPseudoclassUsed(pseudoclass) : false;
    7312     }
    7313
    7314     /**
    7315      * @treatAsPrivate implementation detail
    7316      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7317      */
    7318     @Deprecated
    7319     public void impl_cssResetInitialValues() {
    7320
    7321         //
    7322         // RT-9784: reset all properties that have been set by CSS back
    7323         // to their default value. Called when a stylesheet is removed from
    7324         // a parent or from the scene. This has to be done before calling
    7325         // impl_reapplyCSS.
    7326         //
    7327         final List<StyleableProperty> styleables = impl_getStyleableProperties();
    7328         final int nStyleables = styleables != null ? styleables.size() : 0;
    7329         for (int n=0; n<nStyleables; n++) {
    7330             final StyleableProperty styleable = styleables.get(n);
    7354         if (getScene() == null) return;
    7355         // If the css flag is already "REAPPLY", then do nothing
    7356         if (cssFlag == CSSFlags.REAPPLY) return;
    7357         // Update the flag
    7358         cssFlag = CSSFlags.REAPPLY;
    7359
    7360         // One idiom employed by developers is to, during the layout pass,
    7361         // add or remove nodes from the scene. For example, a ScrollPane
    7362         // might add scroll bars to itself if it determines during layout
    7363         // that it needs them, or a ListView might add cells to itself if
    7364         // it determines that it needs to. In such situations we must
    7365         // apply the CSS immediately and not add it to the scene's queue
    7366         // for deferred action.
    7367         if (getParent() != null && getParent().performingLayout) {
    7368             impl_processCSS(true);
    7369         } else if (getScene() != null) {
    7370             notifyParentsOfInvalidatedCSS();
    7371         }
    7372     }
    7373
    7374     void processCSS(StyleManager styleManager) {
    7375         switch (cssFlag) {
    7376             case CLEAN:
    7377                 break;
    7378             case DIRTY_BRANCH:
    7379                 Parent me = (Parent)this;
    7380                 // clear the flag first in case the flag is set to something
    7381                 // other than clean by downstream processing.
    7382                 me.cssFlag = CSSFlags.CLEAN;
    7383                 List<Node> children = me.getChildren();
    7384                 for (int i=0, max=children.size(); i<max; i++) {
    7385                     children.get(i).processCSS(styleManager);
    7386                 }
    7387                 break;
    7388             case REAPPLY:
    7389             case UPDATE:
    7390             default:
    7391                 impl_processCSS(styleManager, cssFlag == CSSFlags.REAPPLY);
    7392         }
    7393     }
    7394
    7395     /**
    7396      * If invoked, will update / reapply styles from here on down. If reapply
    7397      * is false, then we will only update from here on down, otherwise we will
    7398      * do a full reapply.
    7399      *
    7400      * @treatAsPrivate implementation detail
    7401      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7402      */
    7403     @Deprecated // SB-dependency: RT-21206 has been filed to track this
    7404     public void impl_processCSS(boolean reapply) {
    7405         final StyleManager styleManager = StyleManager.getStyleManager(this.getScene());
    7406         impl_processCSS(styleManager, reapply);
    7407     }
    7408
    7409     /**
    7410      * If invoked, will update / reapply styles from here on down. If reapply
    7411      * is false, then we will only update from here on down, otherwise we will
    7412      * do a full reapply.
    7413      *
    7414      * @treatAsPrivate implementation detail
    7415      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7416      */
    7417     @Deprecated // SB-dependency: RT-21206 has been filed to track this
    7418     public void impl_processCSS(StyleManager styleManager, boolean reapply) {
    7419

    7420         // Create a new StyleHelper either if I am told I need to reapply
    7421         // or if my own flag indicates I need to reapply
    7422         if (reapply || (cssFlag == CSSFlags.REAPPLY)) {
    7423
    7424             styleHelper = styleManager.getStyleHelper(this);
    7425

    7426         }
    7427
    7428         // Clear the flag first in case the flag is set to something
    7429         // other than clean by downstream processing.
    7430         cssFlag = CSSFlags.CLEAN;
    7431
    7432         // Transition to the new state
    7433         if (styleHelper != null) {
    7434             styleHelper.transitionToState(this);
    7435         }
    7436     }
    7437
    7438     /**
    7439      * A StyleHelper for this node.
    7440      * A StyleHelper contains all the css styles for this node
    7441      * and knows how to apply them when our state changes.
    7442      */
    7443     private StyleHelper styleHelper;
    7444
    7445     /**
    7446      * @treatAsPrivate implementation detail
    7447      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7448      */
    7449 //    @Deprecated
    7450 //    protected StyleHelper impl_createStyleHelper() {
    7451 //
    7452 //        styleHelper = getScene().styleManager.getStyleHelper(this);
    7453 //        return styleHelper;
    7454 //    }
    7455
    7456     /**
    7457      * Get this nodes StyleHelper
    7458      * @treatAsPrivate implementation detail
    7459      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    7460      */
    7461     @Deprecated
    7462     public StyleHelper impl_getStyleHelper() {
    7463         return styleHelper;
    7464     }
    7465
    7466     private static final long HOVER_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("hover");
    7467     private static final long PRESSED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("pressed");
    7468     private static final long DISABLED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("disabled");
    7469     private static final long FOCUSED_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("focused");
    7470     private static final long SHOW_MNEMONICS_PSEUDOCLASS_STATE = StyleManager.getPseudoclassMask("show-mnemonics");
    7471
    7472     /**
    7473      * @treatAsPrivate implementation detail
    7474      * @deprecated This is an internal API that is not intended for use and will be removed in the next version