Fixes issues 2907, 4277 and 4278.
Also fixes mail icon showing up in front of the about dialog.
Review: http://gwt-code-reviews.appspot.com/113801

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7226 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/mail/src/com/google/gwt/sample/mail/client/global.css b/samples/mail/src/com/google/gwt/sample/mail/client/global.css
index 2f58ffe..a3efdea 100644
--- a/samples/mail/src/com/google/gwt/sample/mail/client/global.css
+++ b/samples/mail/src/com/google/gwt/sample/mail/client/global.css
@@ -18,6 +18,7 @@
 .gwt-DialogBox {
   background-color: white;
   border: 1px solid #666;
+  z-index: 2;
 }
 .gwt-DialogBox .Caption {
   background: #d3d6dd url(gradient_bg_th.png) repeat-x bottom left;
@@ -33,10 +34,11 @@
 .gwt-DialogBox .gwt-Button {
   margin: 10px;
 }
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #000;
   opacity: 0.3;
   filter: literal("alpha(opacity=30)");
+  z-index: 2;
 }
 
 /* GWT Tree */
diff --git a/user/src/com/google/gwt/user/client/ui/PopupPanel.java b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
index 231ceee..63b616e 100644
--- a/user/src/com/google/gwt/user/client/ui/PopupPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/PopupPanel.java
@@ -64,6 +64,14 @@
  * </p>
  * 
  * <p>
+ * The PopupPanel can be optionally displayed with a "glass" element behind it,
+ * which is commonly used to gray out the widgets behind it. It can be enabled
+ * using {@link #setGlassEnabled(boolean)}. It has a default style name of
+ * "gwt-PopupPanelGlass", which can be changed using
+ * {@link #setGlassStyleName()}.
+ * </p>
+ * 
+ * <p>
  * <h3>Example</h3>
  * {@example com.google.gwt.examples.PopupPanelExample}
  * </p>
@@ -73,7 +81,7 @@
  * <dd>the outside of the popup</dd>
  * <dt>.gwt-PopupPanel .popupContent</dt>
  * <dd>the wrapper around the content</dd>
- * <dt>.gwt-PopupGlass</dt>
+ * <dt>.gwt-PopupPanelGlass</dt>
  * <dd>the glass background behind the popup</dd>
  * </dl>
  */
@@ -267,6 +275,7 @@
       if (showing) {
         if (curPanel.isGlassEnabled) {
           Document.get().getBody().appendChild(curPanel.glass);
+          impl.onShow(curPanel.glass);
           glassShowing = true;
 
           Window.addResizeHandler(curPanel.glassResizer);
@@ -274,6 +283,7 @@
         }
       } else if (glassShowing) {
         Document.get().getBody().removeChild(curPanel.glass);
+        impl.onHide(curPanel.glass);
         glassShowing = false;
       }
     }
@@ -360,6 +370,8 @@
    */
   private Element glass;
 
+  private String glassStyleName = "gwt-PopupPanelGlass";
+
   /**
    * A boolean indicating that a glass element should be used.
    */
@@ -386,7 +398,7 @@
    */
   public PopupPanel() {
     super();
-    DOM.appendChild(super.getContainerElement(), impl.createElement());
+    super.getContainerElement().appendChild(impl.createElement());
 
     // Default position of popup should be in the upper-left corner of the
     // window. By setting a default position, the popup will not appear in
@@ -480,6 +492,16 @@
   }
 
   /**
+   * Gets the style name to be used on the glass element. By default, this is
+   * "gwt-PopupPanelGlass".
+   * 
+   * @return the glass element's style name
+   */
+  public String getGlassStyleName() {
+    return glassStyleName;
+  }
+
+  /**
    * Gets the panel's offset height in pixels. Calls to
    * {@link #setHeight(String)} before the panel's child widget is set will not
    * influence the offset height.
@@ -681,7 +703,7 @@
       autoHidePartners.remove(partner);
     }
   }
-
+  
   /**
    * @deprecated Use the {@link HandlerRegistration#removeHandler} method on the
    *             object returned by {@link #addCloseHandler} instead
@@ -716,7 +738,7 @@
     this.isGlassEnabled = enabled;
     if (enabled && glass == null) {
       glass = Document.get().createDivElement();
-      glass.setClassName("gwt-PopupGlass");
+      glass.setClassName(glassStyleName);
 
       glass.getStyle().setPosition(Position.ABSOLUTE);
       glass.getStyle().setLeft(0, Unit.PX);
@@ -725,6 +747,19 @@
   }
 
   /**
+   * Sets the style name to be used on the glass element. By default, this is
+   * "gwt-PopupPanelGlass".
+   * 
+   * @param glassStyleName the glass element's style name
+   */
+  public void setGlassStyleName(String glassStyleName) {
+    this.glassStyleName = glassStyleName;
+    if (glass != null) {
+      glass.setClassName(glassStyleName);
+    }
+  }
+
+  /**
    * Sets the height of the panel's child widget. If the panel's child widget
    * has not been set, the height passed in will be cached and used to set the
    * height immediately after the child widget is set.
@@ -850,6 +885,9 @@
     // If the PopupImpl creates an iframe shim, it's also necessary to hide it
     // as well.
     impl.setVisible(getElement(), visible);
+    if (glass != null) {
+      impl.setVisible(glass, visible);
+    }
   }
 
   @Override
@@ -914,7 +952,7 @@
 
   @Override
   protected com.google.gwt.user.client.Element getContainerElement() {
-    return impl.getContainerElement(getPopupImplElement());
+    return impl.getContainerElement(getPopupImplElement()).cast();
   }
 
   /**
@@ -929,7 +967,7 @@
 
   @Override
   protected com.google.gwt.user.client.Element getStyleElement() {
-    return impl.getStyleElement(getPopupImplElement());
+    return impl.getStyleElement(getPopupImplElement()).cast();
   }
 
   protected void onPreviewNativeEvent(NativePreviewEvent event) {
diff --git a/user/src/com/google/gwt/user/client/ui/impl/PopupImpl.java b/user/src/com/google/gwt/user/client/ui/impl/PopupImpl.java
index f50b53a..1bbeaa9 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/PopupImpl.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/PopupImpl.java
@@ -15,8 +15,8 @@
  */
 package com.google.gwt.user.client.ui.impl;
 
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Element;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
 
 /**
  * Implementation class used by {@link com.google.gwt.user.client.ui.PopupPanel}.
@@ -24,7 +24,7 @@
 public class PopupImpl {
 
   public Element createElement() {
-    return DOM.createDiv();
+    return Document.get().createDivElement();
   }
 
   public Element getContainerElement(Element popup) {
@@ -32,7 +32,7 @@
   }
 
   public Element getStyleElement(Element popup) {
-    return DOM.getParent(popup);
+    return popup.getParentElement();
   }
 
   /**
@@ -52,7 +52,7 @@
    * @param rect the clip rect
    */
   public void setClip(Element popup, String rect) {
-    DOM.setStyleAttribute(popup, "clip", rect);
+    popup.getStyle().setProperty("clip", rect);
   }
 
   /**
diff --git a/user/src/com/google/gwt/user/client/ui/impl/PopupImplIE6.java b/user/src/com/google/gwt/user/client/ui/impl/PopupImplIE6.java
index 74d28b3..9fa79d1 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/PopupImplIE6.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/PopupImplIE6.java
@@ -15,7 +15,7 @@
  */
 package com.google.gwt.user.client.ui.impl;
 
-import com.google.gwt.user.client.Element;
+import com.google.gwt.dom.client.Element;
 
 /**
  * Internet Explorer 6 implementation of
@@ -59,7 +59,7 @@
     style.filter = 'alpha(opacity=0)';
 
     // Visibility of frame should match visiblity of popup element.
-    style.visibility = popup.style.visibility;
+    style.visibility = popup.currentStyle.visibility;
   
     // Issue 2443: remove styles that affect the size of the iframe
     style.border = 0;
@@ -71,14 +71,14 @@
     style.top = popup.offsetTop;
     style.width = popup.offsetWidth;
     style.height = popup.offsetHeight;
-    style.zIndex = popup.style.zIndex;
+    style.zIndex = popup.currentStyle.zIndex;
 
     // updates position and dimensions as popup is moved & resized
     style.setExpression('left', 'this.__popup.offsetLeft');
     style.setExpression('top', 'this.__popup.offsetTop');
     style.setExpression('width', 'this.__popup.offsetWidth');
     style.setExpression('height', 'this.__popup.offsetHeight');
-    style.setExpression('zIndex', 'this.__popup.style.zIndex');
+    style.setExpression('zIndex', 'this.__popup.currentStyle.zIndex');
     popup.parentElement.insertBefore(frame, popup);
   }-*/;
   
diff --git a/user/src/com/google/gwt/user/client/ui/impl/PopupImplMozilla.java b/user/src/com/google/gwt/user/client/ui/impl/PopupImplMozilla.java
index 89f92c1..0c1dfef 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/PopupImplMozilla.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/PopupImplMozilla.java
@@ -15,10 +15,12 @@
  */
 package com.google.gwt.user.client.ui.impl;
 
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Style.Display;
+import com.google.gwt.dom.client.Style.Overflow;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.DeferredCommand;
-import com.google.gwt.user.client.Element;
 
 /**
  * Implementation class used by {@link com.google.gwt.user.client.ui.PopupPanel}.
@@ -87,7 +89,7 @@
       // of underlying scrollbars. To get around this problem, we introduce an
       // inner div which acts as the new containing element for the PopupPanel,
       // and this element is the one to which all styling is applied to.
-      DOM.setInnerHTML(outerElem, "<div></div>");
+      outerElem.setInnerHTML("<div></div>");
 
       // Mozilla determines the default stacking order for heavyweight elements
       // by their order on the page. If the PopupPanel is declared before
@@ -99,7 +101,7 @@
       // the PopupPanel becomes the highest element in the stacking order.
       DeferredCommand.addCommand(new Command() {
         public void execute() {
-          DOM.setStyleAttribute(outerElem, "overflow", "auto");
+          outerElem.getStyle().setOverflow(Overflow.AUTO);
         }
       });
     }
@@ -109,7 +111,7 @@
 
   @Override
   public Element getContainerElement(Element outerElem) {
-    return isFF2Mac ? DOM.getFirstChild(outerElem) : outerElem;
+    return isFF2Mac ? outerElem.getFirstChildElement() : outerElem;
   }
 
   @Override
@@ -120,7 +122,7 @@
   @Override
   public void setClip(Element popup, String rect) {
     super.setClip(popup, rect);
-    DOM.setStyleAttribute(popup, "display", "none");
-    DOM.setStyleAttribute(popup, "display", "");
+    popup.getStyle().setDisplay(Display.NONE);
+    popup.getStyle().clearDisplay();
   }
 }
diff --git a/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css b/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
index 3fd7335..5cd6bd6 100644
--- a/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
+++ b/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
@@ -479,7 +479,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #000;
   opacity: 0.3;
   filter: alpha(opacity=30);
diff --git a/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css b/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
index 21d0021..e4b3c5e 100644
--- a/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
+++ b/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
@@ -479,7 +479,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #000;
   opacity: 0.3;
   filter: alpha(opacity=30);
diff --git a/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css b/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
index 89225c0..57ba04b 100644
--- a/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
+++ b/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
@@ -463,7 +463,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #0cf;
   opacity: 0.3;
   filter: alpha(opacity=30);
diff --git a/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css b/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
index 5629801..460a3c9 100644
--- a/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
+++ b/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
@@ -463,7 +463,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #0cf;
   opacity: 0.3;
   filter: alpha(opacity=30);
diff --git a/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css b/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
index 4875b67..62a0bcc 100644
--- a/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
+++ b/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
@@ -479,7 +479,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #000;
   opacity: 0.3;
   filter: alpha(opacity=30);
diff --git a/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css b/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
index e2d75f3..a077f7f 100644
--- a/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
+++ b/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
@@ -479,7 +479,7 @@
   overflow: hidden;
 }
 
-.gwt-PopupGlass {
+.gwt-PopupPanelGlass {
   background-color: #000;
   opacity: 0.3;
   filter: alpha(opacity=30);