changeset 6441:6b2634b9f3bc

RT-33073: MenuItem is wrapped in a container. Need to return MenuItem as the container's styleable parent
author David Grieve<david.grieve@oracle.com>
date Thu, 06 Mar 2014 11:06:53 -0500
parents d3e5f81ba638
children c859882323e3
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java modules/controls/src/main/java/javafx/scene/control/ContextMenu.java modules/controls/src/main/java/javafx/scene/control/MenuItem.java modules/controls/src/main/java/javafx/scene/control/PopupControl.java
diffstat 4 files changed, 53 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Mon Mar 03 08:56:43 2014 -0500
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Thu Mar 06 11:06:53 2014 -0500
@@ -868,6 +868,9 @@
      *                         Stylesheet Handling                             *
      *                                                                         *
      **************************************************************************/
+    @Override public Styleable getStyleableParent() {
+        return contextMenu;
+    }
 
      /** @treatAsPrivate */
     private static class StyleableProperties {
@@ -1018,7 +1021,7 @@
     }
     
     /*
-     * Container responsible for laying out a singel row in the menu - in other
+     * Container responsible for laying out a single row in the menu - in other
      * words, this contains and lays out a single MenuItem, regardless of it's 
      * specific subtype.
      */
--- a/modules/controls/src/main/java/javafx/scene/control/ContextMenu.java	Mon Mar 03 08:56:43 2014 -0500
+++ b/modules/controls/src/main/java/javafx/scene/control/ContextMenu.java	Thu Mar 06 11:06:53 2014 -0500
@@ -247,15 +247,6 @@
         if (getItems().size() == 0) return;
 
         getScene().setNodeOrientation(anchor.getEffectiveNodeOrientation());
-        //RT-27546 : The problem here is before the first show the content of the popup
-        // is not initialized yet and hence the prefWidth & prefHeight remains 0
-        // This leads to incorrect translation of anchor to screen coordinates.
-        // A call to show initializes the content. Skin is null only the very first time.
-        if(getSkin() == null) {
-            // This check is also done in PopupControl#show,
-            // but happens too late for the purposes of calculating perfWidth/perfHeight
-            bridge.applyCss();
-        }
         // FIXME because Side is not yet in javafx.geometry, we have to convert
         // to the old HPos/VPos API here, as Utils can not refer to Side in the
         // charting API.
--- a/modules/controls/src/main/java/javafx/scene/control/MenuItem.java	Mon Mar 03 08:56:43 2014 -0500
+++ b/modules/controls/src/main/java/javafx/scene/control/MenuItem.java	Thu Mar 06 11:06:53 2014 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, 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
@@ -617,4 +617,29 @@
 
         return null;
     }
+
+    @Override public String toString() {
+        StringBuilder sbuf = new StringBuilder(getClass().getSimpleName());
+
+        boolean hasId = id != null && !"".equals(getId());
+        boolean hasStyleClass = !getStyleClass().isEmpty();
+
+        if (!hasId) {
+            sbuf.append('@');
+            sbuf.append(Integer.toHexString(hashCode()));
+        } else {
+            sbuf.append("[id=");
+            sbuf.append(getId());
+            if (!hasStyleClass) sbuf.append("]");
+        }
+
+        if (hasStyleClass) {
+            if (!hasId) sbuf.append('[');
+            else sbuf.append(", ");
+            sbuf.append("styleClass=");
+            sbuf.append(getStyleClass());
+            sbuf.append("]");
+        }
+        return sbuf.toString();
+    }
 }
--- a/modules/controls/src/main/java/javafx/scene/control/PopupControl.java	Mon Mar 03 08:56:43 2014 -0500
+++ b/modules/controls/src/main/java/javafx/scene/control/PopupControl.java	Thu Mar 06 11:06:53 2014 -0500
@@ -957,30 +957,17 @@
     }
 
     private void recomputeSkinSize() {
-        if (!skinSizeComputed)  {
+        if (!skinSizeComputed) {
             // RT-14094, RT-16754: We need the skins of the popup
             // and it children before the stage is visible so we
             // can calculate the popup position based on content
             // size.
-            getScene().getRoot().impl_processCSS(true);
+            bridge.applyCss();
             skinSizeComputed = true;
         }
     }
 //    public double getBaselineOffset() { return getSkinNode() == null? 0 : getSkinNode().getBaselineOffset(); }
 
-    @Override protected void show() {
-
-        //RT-27546 : The problem here is before the first show the content of the popup
-        // is not initialized yet and hence the prefWidth & prefHeight remains 0
-        // This leads to incorrect translation of anchor to screen coordinates.
-        // A call to show initializes the content. Skin is null only the very first time.
-        if(getSkin() == null) {
-            bridge.applyCss();
-        }
-        super.show();
-
-    }
-
     /**
      * Create a new instance of the default skin for this control. This is called to create a skin for the control if
      * no skin is provided via CSS {@code -fx-skin} or set explicitly in a sub-class with {@code  setSkin(...)}.
@@ -1077,7 +1064,25 @@
      */
     @Override
     public Styleable getStyleableParent() {
-        return bridge.getStyleableParent();
+
+        final Node ownerNode = getOwnerNode();
+        if (ownerNode != null) {
+            return ownerNode;
+
+        } else {
+
+            final Window ownerWindow = getOwnerWindow();
+            if (ownerWindow != null) {
+
+                final Scene ownerScene = ownerWindow.getScene();
+                if (ownerScene != null) {
+                    return ownerScene.getRoot();
+                }
+            }
+        }
+
+        return bridge.getParent();
+
     }
 
     /**
@@ -1123,30 +1128,13 @@
             minHeightCache = -1;
             maxWidthCache = -1;
             maxHeightCache = -1;
-            skinSizeComputed = false;
+            //skinSizeComputed = false; -- RT-33073 disabled this
             super.requestLayout();
         }
 
         @Override
         public final Styleable getStyleableParent() {
-
-            final Node ownerNode = getOwnerNode();
-            if (ownerNode != null) {
-                return ownerNode;
-
-            } else {
-
-                final Window ownerWindow = getOwnerWindow();
-                if (ownerWindow != null) {
-
-                    final Scene ownerScene = ownerWindow.getScene();
-                    if (ownerScene != null) {
-                        return ownerScene.getRoot();
-                    }
-                }
-            }
-
-            return bridge.getParent();
+            return PopupControl.this.getStyleableParent();
         }
 
         @Override
@@ -1175,8 +1163,6 @@
                 final Skin<?> defaultSkin = createDefaultSkin();
                 if (defaultSkin != null) {
                     skinProperty().set(defaultSkin);
-                    // we have to reapply css again so that the newly set skin gets css applied as well.
-                    super.impl_processCSS(cacheHint);
                 } else {
                     final String msg = "The -fx-skin property has not been defined in CSS for " + this +
                             " and createDefaultSkin() returned null.";