Revision: 8856
Author: [email protected]
Date: Thu Sep 23 12:26:00 2010
Log: Element.getTabIndex() returns undefined on Safari 3 for non-focusable elements, including divs, which can cause our tests to hang. This patch updates Element to return -1 if tabIndex is undefined. We use a typeof check instead of the standard this.tabIndex || -1 trick because 0 is a valid return value for this.tabIndex. Also fixes AbstractHasDataTestBase.testSetTabIndex() to skip Safari 3, because divs are not focusable in Safari 3 and earlier.

Review at http://gwt-code-reviews.appspot.com/905802

http://code.google.com/p/google-web-toolkit/source/detail?r=8856

Modified:
 /trunk/user/src/com/google/gwt/dom/client/DOMImpl.java
 /trunk/user/src/com/google/gwt/dom/client/DOMImplSafari.java
 /trunk/user/src/com/google/gwt/dom/client/Element.java
 /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml
/trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java

=======================================
--- /trunk/user/src/com/google/gwt/dom/client/DOMImpl.java Fri Apr 2 06:00:38 2010 +++ /trunk/user/src/com/google/gwt/dom/client/DOMImpl.java Thu Sep 23 12:26:00 2010
@@ -260,6 +260,10 @@
     return doc.getViewportElement().getScrollTop();
   }

+  public native int getTabIndex(Element elem) /*-{
+    return elem.tabIndex;
+  }-*/;
+
   public native String getTagName(Element elem) /*-{
     return elem.tagName;
   }-*/;
=======================================
--- /trunk/user/src/com/google/gwt/dom/client/DOMImplSafari.java Tue Jun 22 06:26:45 2010 +++ /trunk/user/src/com/google/gwt/dom/client/DOMImplSafari.java Thu Sep 23 12:26:00 2010
@@ -237,6 +237,13 @@
     // strict mode.
     return doc.getBody().getScrollTop();
   }
+
+  @Override
+  public native int getTabIndex(Element elem) /*-{
+ // tabIndex is undefined for divs and other non-focusable elements prior to
+    // Safari 4.
+    return typeof elem.tabIndex != 'undefined' ? elem.tabIndex : -1;
+  }-*/;

   @Override
   public native boolean isOrHasChild(Node parent, Node child) /*-{
=======================================
--- /trunk/user/src/com/google/gwt/dom/client/Element.java Fri Apr 2 06:00:38 2010 +++ /trunk/user/src/com/google/gwt/dom/client/Element.java Thu Sep 23 12:26:00 2010
@@ -436,9 +436,9 @@
    *
* @see <a href="http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#adef-tabindex";>W3C HTML Specification</a>
    */
-  public final native int getTabIndex() /*-{
-    return this.tabIndex;
-  }-*/;
+  public final int getTabIndex() {
+    return DOMImpl.impl.getTabIndex(this);
+  }

   /**
    * Gets the element's full tag name, including the namespace-prefix if
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml Mon Aug 2 11:31:26 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml Thu Sep 23 12:26:00 2010
@@ -17,6 +17,7 @@
    <inherits name="com.google.gwt.user.User"/>
    <inherits name="com.google.gwt.cell.Cell"/>
    <inherits name="com.google.gwt.view.View"/>
+   <inherits name="com.google.gwt.user.UserAgent"/>
    <source path="client"/>

   <!-- Standard CellBasedWidgetImpl implementation. -->
=======================================
--- /trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java Wed Sep 22 12:58:01 2010 +++ /trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java Thu Sep 23 12:26:00 2010
@@ -16,6 +16,9 @@
 package com.google.gwt.user.cellview.client;

 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.regexp.shared.MatchResult;
+import com.google.gwt.regexp.shared.RegExp;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.view.client.ListDataProvider;

 import java.util.ArrayList;
@@ -79,6 +82,16 @@
   }

   public void testSetTabIndex() {
+ // Skip this test on Safari 3 because it does not support focusable divs.
+    String userAgent = Window.Navigator.getUserAgent();
+    if (userAgent.contains("Safari")) {
+      RegExp versionRegExp = RegExp.compile("Version/[0-3]", "ig");
+      MatchResult result = versionRegExp.exec(userAgent);
+      if (result.getGroupCount() > 0) {
+        return;
+      }
+    }
+
     AbstractHasData<String> display = createAbstractHasData();
     ListDataProvider<String> provider = new ListDataProvider<String>(
         createData(0, 10));
@@ -102,7 +115,7 @@
   /**
    * Create an {...@link AbstractHasData} to test.
    *
-   * @return the widget to tezst
+   * @return the widget to test
    */
   protected abstract AbstractHasData<String> createAbstractHasData();

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

Reply via email to