Fix spurious horizontal scrollbars from appearing in Tree sample in Showcase app. In the dynamic tree, horizontal scrollbars would not dissappear if the overflowing tree item was selected, and then its parent was closed. This problem was happening because the focusable element was still set to underlap the overflowing item. This problem has been fixed by moving the focus to the collapsed item.
Patch by: rdayal
Review by: jgw (TBR)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2406 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/Tree.java b/user/src/com/google/gwt/user/client/ui/Tree.java
index c7778cc..3fdabc7 100644
--- a/user/src/com/google/gwt/user/client/ui/Tree.java
+++ b/user/src/com/google/gwt/user/client/ui/Tree.java
@@ -710,6 +710,25 @@
if (item != null) {
if (DOM.isOrHasChild(item.getImageElement(), hElem)) {
item.setState(!item.getState(), true);
+
+ // If we just closed the item, let's check to see if this item is the parent of
+ // the currently selected item. If so, we should make this item the currently selected
+ // selected item. Note that we only need to do this check in the case where an element's
+ // state is changed due to a click; in the case of keyboard interaction, an item's state
+ // can only be changed if it is the currently selected item.
+ if (!item.getState()) {
+ if (curSelection != null) {
+ TreeItem tempItem = curSelection;
+ while (tempItem != null) {
+ if (tempItem == item) {
+ setSelectedItem(item);
+ break;
+ }
+ tempItem = tempItem.getParentItem();
+ }
+ }
+ }
+
return true;
} else if (DOM.isOrHasChild(item.getElement(), hElem)) {
onSelection(item, true, !shouldTreeDelegateFocusToElement(hElem));