http://gwt-code-reviews.appspot.com/132818


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7445 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/TabLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/TabLayoutPanel.java
index affa84b..8a4448f 100644
--- a/user/src/com/google/gwt/user/client/ui/TabLayoutPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/TabLayoutPanel.java
@@ -18,8 +18,8 @@
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.Display;
 import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.dom.client.Style.Visibility;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
@@ -381,13 +381,17 @@
 
     // Update the tabs being selected and unselected.
     if (selectedIndex != -1) {
-      Element container = panel.getWidgetContainerElement(children.get(selectedIndex));
-      container.getStyle().setVisibility(Visibility.HIDDEN);
+      Widget child = children.get(selectedIndex);
+      Element container = panel.getWidgetContainerElement(child);
+      container.getStyle().setDisplay(Display.NONE);
+      child.setVisible(false);
       tabs.get(selectedIndex).setSelected(false);
     }
 
-    Element container = panel.getWidgetContainerElement(children.get(index));
-    container.getStyle().clearVisibility();
+    Widget child = children.get(index);
+    Element container = panel.getWidgetContainerElement(child);
+    container.getStyle().clearDisplay();
+    child.setVisible(true);
     tabs.get(index).setSelected(true);
     selectedIndex = index;
 
@@ -472,7 +476,8 @@
   private void layoutChild(Widget child) {
     panel.setWidgetLeftRight(child, 0, Unit.PX, 0, Unit.PX);
     panel.setWidgetTopBottom(child, barHeight, barUnit, 0, Unit.PX);
-    panel.getWidgetContainerElement(child).getStyle().setVisibility(
-        Visibility.HIDDEN);
+    panel.getWidgetContainerElement(child).getStyle().setDisplay(
+        Display.NONE);
+    child.setVisible(false);
   }
 }
diff --git a/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java b/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
index 9c387d6..f168b48 100644
--- a/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/TabLayoutPanelTest.java
@@ -176,6 +176,37 @@
   }
 
   /**
+   * Test that {@link TabLayoutPanel} calls widget.setVisible(true/false) on
+   * each widget, when it is shown/hidden.
+   */
+  public void testSetWidgetVisible() {
+    TabLayoutPanel p = new TabLayoutPanel(1, Unit.EM);
+    Label[] labels = new Label[3];
+    for (int i = 0; i < labels.length; i++) {
+      labels[i] = new Label("content" + i);
+      p.add(labels[i]);
+    }
+
+    // Initially, the first widget should be visible.
+    assertTrue(labels[0].isVisible());
+    assertFalse(labels[1].isVisible());
+    assertFalse(labels[2].isVisible());
+
+    // Show widget at index 1, make sure it becomes visible, and the one at
+    // index 0 is hidden.
+    p.selectTab(1);
+    assertFalse(labels[0].isVisible());
+    assertTrue(labels[1].isVisible());
+    assertFalse(labels[2].isVisible());
+
+    // Show widget at index 0, make sure it changed back to the initial state.
+    p.selectTab(0);
+    assertTrue(labels[0].isVisible());
+    assertFalse(labels[1].isVisible());
+    assertFalse(labels[2].isVisible());
+  }
+
+  /**
    * Tests that tabs actually line up properly (see issue 4447).
    */
   @DoNotRunWith(Platform.HtmlUnit)