Fixed a bug in SuggestBox where the SuggestBoxPopup did not shrink to fit the suggestions when the number of suggestions decreased. SuggestBox was setting the visibility of the popup instead of removing it from the DOM (hiding it), so the popup didn't rerender itself. This bug only affects IE in standards mode.
Patch by: jlabanca
Review by: ecc (desk review)
Issue: 2392
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2816 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
index e5513e9..888987c 100644
--- a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
+++ b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
@@ -34,6 +34,7 @@
addIssue(new Issue2331());
addIssue(new Issue2338());
addIssue(new Issue2339());
+ addIssue(new Issue2392());
addIssue(new TestFireEvents());
}
}
diff --git a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue2392.java b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue2392.java
new file mode 100644
index 0000000..644dc33
--- /dev/null
+++ b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue2392.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.museum.client.defaultmuseum;
+
+import com.google.gwt.museum.client.common.AbstractIssue;
+import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
+import com.google.gwt.user.client.ui.SuggestBox;
+import com.google.gwt.user.client.ui.SuggestOracle;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * SuggestBox does not shrink to fit its contents when the number of suggestions
+ * is reduced. This issue was reported against IE in standards mode.
+ */
+public class Issue2392 extends AbstractIssue {
+ private MultiWordSuggestOracle oracle = null;
+
+ @Override
+ public Widget createIssue() {
+ SuggestBox box = new SuggestBox(getSuggestOracle());
+
+ // Enable animations to ensure that the suggestions are only animated when
+ // they are opened the first time.
+ box.setAnimationEnabled(true);
+
+ return box;
+ }
+
+ @Override
+ public String getInstructions() {
+ return "Type in the word 'add' one letter at a time. As the number of "
+ + "suggestions is reduced, the red box around the SuggestPopup should "
+ + "shrink to just fit the contents.";
+ }
+
+ @Override
+ public String getSummary() {
+ return "SuggestBox does not shrink when the number of suggestions is "
+ + "reduced";
+ }
+
+ @Override
+ public boolean hasCSS() {
+ return true;
+ }
+
+ /**
+ * Create a {@link SuggestOracle} that returns random words. Only one suggest
+ * oracle is created.
+ *
+ * @return a {@link SuggestOracle}
+ */
+ private SuggestOracle getSuggestOracle() {
+ if (oracle == null) {
+ oracle = new MultiWordSuggestOracle();
+ for (char a = 'a'; a <= 'z'; a++) {
+ for (char b = 'a'; b <= 'm'; b++) {
+ for (char c = 'a'; c <= 'd'; c++) {
+ oracle.add("" + a + b + c);
+ }
+ }
+ }
+ }
+ return oracle;
+ }
+
+}
diff --git a/reference/code-museum/src/com/google/gwt/museum/public/DefaultMuseum.html b/reference/code-museum/src/com/google/gwt/museum/public/DefaultMuseum.html
index c2fa0c5..a4ffbdc 100644
--- a/reference/code-museum/src/com/google/gwt/museum/public/DefaultMuseum.html
+++ b/reference/code-museum/src/com/google/gwt/museum/public/DefaultMuseum.html
@@ -1,3 +1,4 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Museum</title>
diff --git a/reference/code-museum/src/com/google/gwt/museum/public/Museum.html b/reference/code-museum/src/com/google/gwt/museum/public/Museum.html
index 1b1871e..6e53528 100644
--- a/reference/code-museum/src/com/google/gwt/museum/public/Museum.html
+++ b/reference/code-museum/src/com/google/gwt/museum/public/Museum.html
@@ -1,3 +1,4 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Museum</title>
diff --git a/reference/code-museum/src/com/google/gwt/museum/public/SingleIssue.html b/reference/code-museum/src/com/google/gwt/museum/public/SingleIssue.html
index 17d4f33..8acd8e6 100644
--- a/reference/code-museum/src/com/google/gwt/museum/public/SingleIssue.html
+++ b/reference/code-museum/src/com/google/gwt/museum/public/SingleIssue.html
@@ -1,3 +1,4 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Single issue from Museum</title>
diff --git a/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue2392.css b/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue2392.css
new file mode 100644
index 0000000..dcb68c1
--- /dev/null
+++ b/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue2392.css
@@ -0,0 +1,16 @@
+@import url("MasterIssue.css");
+
+/* Outside of the popup */
+.gwt-SuggestBoxPopup {
+ border: 1px solid red;
+}
+
+/* The cell containing the suggestions */
+.gwt-SuggestBoxPopup .suggestPopupMiddleCenter {
+ border: 1px solid blue;
+}
+
+/* The div containing the suggests */
+.gwt-SuggestBoxPopup .suggestPopupContent {
+ border: 1px solid green;
+}
diff --git a/user/src/com/google/gwt/user/client/ui/SuggestBox.java b/user/src/com/google/gwt/user/client/ui/SuggestBox.java
index fca4e5f..b1b7d4b 100644
--- a/user/src/com/google/gwt/user/client/ui/SuggestBox.java
+++ b/user/src/com/google/gwt/user/client/ui/SuggestBox.java
@@ -615,19 +615,14 @@
private void showSuggestions(Collection<? extends Suggestion> suggestions) {
if (suggestions.size() > 0) {
- /* Hide the popup before we manipulate the menu within it. If we do not
- do this, some browsers will redraw the popup as items are removed
- and added to the menu.
-
- As an optimization, setVisible(false) is used in place of the hide()
- method. hide() removes the popup from the DOM, whereas setVisible(false)
- does not. Since the popup is going to be shown again as soon as the menu
- is rebuilt, it makes more sense to leave the popup attached to the DOM.
-
- Notice that setVisible(true) is never called. This is because the call
- to showAlignedPopup() will cause show() to be called, which in turn
- calls setVisible(true). */
- suggestionPopup.setVisible(false);
+ // Hide the popup before we manipulate the menu within it. If we do not
+ // do this, some browsers will redraw the popup as items are removed
+ // and added to the menu.
+ boolean isAnimationEnabled = suggestionPopup.isAnimationEnabled();
+ if (suggestionPopup.isAttached()) {
+ suggestionPopup.setAnimationEnabled(false);
+ suggestionPopup.hide();
+ }
suggestionMenu.clearItems();
@@ -647,6 +642,7 @@
suggestionMenu.selectItem(0);
suggestionPopup.showAlignedPopup();
+ suggestionPopup.setAnimationEnabled(isAnimationEnabled);
} else {
suggestionPopup.hide();
}