Fixing a bug in CellBrowser where the user must click on an element twice to focus on it and enable keyboard support. The problem is that Element.getTabIndex() returns 0 for non-focusable divs, which causes us to assume that the div is focusable. Other browsers return -1 for non-focusable divs. Unfortunately, there is no good way to fix the bug in Element.getTabIndex() because the only way to determine if an element is natively focusable, such as a text box, is to compare the element tagName to a list of known natively focusable element, which isn't scalable. For now, I worked around it in CellBasedWidgetImpl. Issue: 5916 Review at http://gwt-code-reviews.appspot.com/1290803 Review by: rchandia@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9620 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java b/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java index 9c14ce6..a44e9bc 100644 --- a/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java +++ b/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java
@@ -50,7 +50,7 @@ /** * The set of natively focusable elements. */ - private final Set<String> focusableTypes; + final Set<String> focusableTypes; CellBasedWidgetImpl() { focusableTypes = new HashSet<String>();
diff --git a/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java b/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java index cd0cf53..eea60dd 100644 --- a/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java +++ b/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java
@@ -247,6 +247,12 @@ } @Override + public boolean isFocusable(Element elem) { + return focusableTypes.contains(elem.getTagName().toLowerCase()) + || getTabIndexIfSpecified(elem) >= 0; + } + + @Override public void onBrowserEvent(final Widget widget, Event event) { // We need to remove the event listener from the cell now that the event // has fired. @@ -342,6 +348,16 @@ } /** + * Get the tab index of an element if the tab index is specified. + * + * @param elem the Element + * @return the tab index, or -1 if not specified + */ + private native int getTabIndexIfSpecified(Element elem) /*-{ + return elem.getAttributeNode('tabIndex').specified ? elem.tabIndex : -1; + }-*/; + + /** * Initialize the focus event listener. */ private native void initFocusEventSystem() /*-{