Revision: 9620
Author: gwt.mirror...@gmail.com
Date: Wed Jan 26 09:27:21 2011
Log: 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: rchan...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9620

Modified:
/trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java

=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java Tue Nov 23 05:52:59 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImpl.java Wed Jan 26 05:22:54 2011
@@ -50,7 +50,7 @@
   /**
    * The set of natively focusable elements.
    */
-  private final Set<String> focusableTypes;
+  final Set<String> focusableTypes;

   CellBasedWidgetImpl() {
     focusableTypes = new HashSet<String>();
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java Wed Sep 22 12:58:01 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplTrident.java Wed Jan 26 05:22:54 2011
@@ -245,6 +245,12 @@
     changeEventTriggers.add("mouseup");
     changeEventTriggers.add("mousewheel");
   }
+
+  @Override
+  public boolean isFocusable(Element elem) {
+    return focusableTypes.contains(elem.getTagName().toLowerCase())
+        || getTabIndexIfSpecified(elem) >= 0;
+  }

   @Override
   public void onBrowserEvent(final Widget widget, Event event) {
@@ -340,6 +346,16 @@
       return super.sinkEvent(widget, typeName);
     }
   }
+
+  /**
+   * 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.

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to