Reviewers: rchandia,
Description:
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
Please review this at http://gwt-code-reviews.appspot.com/1290803/show
Affected files:
M user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java
M
user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java
Index: user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java
(revision 9614)
+++ user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java
(working copy)
@@ -50,7 +50,7 @@
/**
* The set of natively focusable elements.
*/
- private final Set<String> focusableTypes;
+ final Set<String> focusableTypes;
CellBasedWidgetImpl() {
focusableTypes = new HashSet<String>();
Index:
user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java
===================================================================
---
user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java
(revision 9614)
+++
user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java
(working copy)
@@ -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() /*-{
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors