Revision: 9050
Author: jlaba...@google.com
Date: Wed Oct 13 12:59:56 2010
Log: Fixing a few logic and usability bugs in Cell Widgets. CellTree items are now easier to click. Fixed a bug in CellBrowser keyboard navigation on Chrome where we would get async blur events that prevented keyboard navigation. Fixed a few IE7 specific bugs that occur when delayed events fire on elements that have been replaced.

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

Review by: r...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9050

Added:
/trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplSafari.java
Modified:
 /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml
 /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.css
 /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTree.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/cellview/client/CellBasedWidgetImplSafari.java Wed Oct 13 12:59:56 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.user.cellview.client;
+
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+
+/**
+ * Webkit specified Impl used by cell based widgets.
+ */
+public class CellBasedWidgetImplSafari extends CellBasedWidgetImplStandard {
+
+  @Override
+  public void resetFocus(ScheduledCommand command) {
+ // Webkit will not focus an element that was created in this event loop.
+    Scheduler.get().scheduleDeferred(command);
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml Thu Sep 23 12:26:00 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/CellView.gwt.xml Wed Oct 13 12:59:56 2010
@@ -24,7 +24,6 @@
<replace-with class="com.google.gwt.user.cellview.client.CellBasedWidgetImplStandard"> <when-type-is class="com.google.gwt.user.cellview.client.CellBasedWidgetImpl"/>
     <any>
-      <when-property-is name="user.agent" value="safari"/>
       <when-property-is name="user.agent" value="opera"/>
       <when-property-is name="user.agent" value="gecko"/>
       <when-property-is name="user.agent" value="gecko1_8"/>
@@ -40,6 +39,14 @@
     </any>
   </replace-with>

+  <!-- Safari-specific CellBasedWidgetImpl implementation. -->
+ <replace-with class="com.google.gwt.user.cellview.client.CellBasedWidgetImplSafari"> + <when-type-is class="com.google.gwt.user.cellview.client.CellBasedWidgetImpl"/>
+    <any>
+      <when-property-is name="user.agent" value="safari"/>
+    </any>
+  </replace-with>
+
   <!-- IE-specific CellTable implementation. -->
<replace-with class="com.google.gwt.user.cellview.client.CellTable.ImplTrident"> <when-type-is class="com.google.gwt.user.cellview.client.CellTable.Impl"/>
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.css Wed Sep 22 12:58:01 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.css Wed Oct 13 12:59:56 2010
@@ -40,6 +40,7 @@
 @sprite .cellBrowserSelectedItem {
   gwt-image: 'cellBrowserSelectedBackground';
   background-color: #628cd5;
+  background-repeat: repeat-x;
   color: white;
   height: auto;
   overflow: hidden;
@@ -48,6 +49,7 @@
 @sprite .cellBrowserOpenItem {
   gwt-image: 'cellBrowserOpenBackground';
   background-color: #7b7b7b;
+  background-repeat: repeat-x;
   color: white;
   height: auto;
   overflow: hidden;
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.java Tue Oct 12 07:55:56 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellBrowser.java Wed Oct 13 12:59:56 2010
@@ -101,14 +101,16 @@
     /**
      * The background used for open items.
      */
-    @ImageOptions(repeatStyle = RepeatStyle.Horizontal, flipRtl = true)
+    // Use RepeatStyle.BOTH to ensure that we do not bundle the image.
+    @ImageOptions(repeatStyle = RepeatStyle.Both, flipRtl = true)
     ImageResource cellBrowserOpenBackground();

     /**
      * The background used for selected items.
      */
+    // Use RepeatStyle.BOTH to ensure that we do not bundle the image.
     @Source("cellTreeSelectedBackground.png")
-    @ImageOptions(repeatStyle = RepeatStyle.Horizontal, flipRtl = true)
+    @ImageOptions(repeatStyle = RepeatStyle.Both, flipRtl = true)
     ImageResource cellBrowserSelectedBackground();

     /**
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java Tue Oct 12 07:55:56 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java Wed Oct 13 12:59:56 2010
@@ -380,6 +380,9 @@
// If the event causes us to page, then the index will be out of bounds.
         return;
       }
+
+ // Get the cell parent before doing selection in case the list is redrawn.
+      Element cellParent = getCellParent(target);
       T value = getDisplayedItem(indexOnPage);
       if (isMouseDown && !cell.handlesSelection()) {
         doSelection(event, value, indexOnPage);
@@ -392,7 +395,7 @@
       }

       // Fire the event to the cell if the list has not been refreshed.
-      fireEventToCell(event, getCellParent(target), value);
+      fireEventToCell(event, cellParent, value);
     }
   }

=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Wed Oct 13 05:03:29 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Wed Oct 13 12:59:56 2010
@@ -935,7 +935,8 @@
       boolean isMouseDown = "mousedown".equals(eventType);
       int row = tr.getSectionRowIndex();
       if ("mouseover".equals(eventType)) {
-        if (hoveringRow != null) {
+        // Unstyle the old row if it is still part of the table.
+        if (hoveringRow != null && tbody.isOrHasChild(hoveringRow)) {
           setRowStyleName(hoveringRow, style.cellTableHoveredRow(),
               style.cellTableHoveredRowCell(), false);
         }
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTree.java Tue Oct 12 07:55:56 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTree.java Wed Oct 13 12:59:56 2010
@@ -18,6 +18,7 @@
 import com.google.gwt.animation.client.Animation;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style.Display;
 import com.google.gwt.dom.client.Style.Position;
@@ -502,6 +503,11 @@
    */
   private boolean isAnimationEnabled;

+  /**
+   * The deferred command used to keyboard select a node.
+   */
+  private ScheduledCommand keyboardSelectCommand;
+
   /**
* The {...@link CellTreeNodeView} whose children are currently being selected
    * using the keyboard.
@@ -677,7 +683,7 @@
     collectElementChain(chain, getElement(), target);

     boolean isMouseDown = "mousedown".equals(eventType);
-    CellTreeNodeView<?> nodeView = findItemByChain(chain, 0, rootNode);
+ final CellTreeNodeView<?> nodeView = findItemByChain(chain, 0, rootNode);
     if (nodeView != null && nodeView != rootNode) {
       if (isMouseDown) {
         Element showMoreElem = nodeView.getShowMoreElement();
@@ -693,11 +699,21 @@
       }

       // Forward the event to the cell
-      if (nodeView.getCellParent().isOrHasChild(target)) {
+      if (nodeView.getSelectionElement().isOrHasChild(target)) {
         // Move the keyboard focus to the clicked item.
         if ("focus".equals(eventType) || isMouseDown) {
-          isFocused = true;
-          keyboardSelect(nodeView, false);
+          // Wait until any pending blur event has fired.
+ final boolean targetsCellParent = nodeView.getCellParent().isOrHasChild(target);
+          keyboardSelectCommand = new ScheduledCommand() {
+            public void execute() {
+ if (keyboardSelectCommand == this && !nodeView.isDestroyed()) {
+                isFocused = true;
+                keyboardSelectCommand = null;
+                keyboardSelect(nodeView, !targetsCellParent);
+              }
+            }
+          };
+          Scheduler.get().scheduleDeferred(keyboardSelectCommand);
         }

         nodeView.fireEventToCell(event);
@@ -879,7 +895,8 @@
   void resetFocus() {
     CellBasedWidgetImpl.get().resetFocus(new Scheduler.ScheduledCommand() {
       public void execute() {
-        if (isFocused && !keyboardSelectedNode.resetFocusOnCell()) {
+        if (isFocused && !keyboardSelectedNode.isDestroyed()
+            && !keyboardSelectedNode.resetFocusOnCell()) {
           keyboardSelectedNode.setKeyboardSelected(true, true);
         }
       }
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java Wed Oct 6 11:53:24 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTreeNodeView.java Wed Oct 13 12:59:56 2010
@@ -974,6 +974,9 @@
     }

     // Forward the event to the cell.
+    if (!cellParent.isOrHasChild(Element.as(event.getEventTarget()))) {
+      return;
+    }
     Set<String> consumedEvents = parentCell.getConsumedEvents();
     if (consumedEvents != null && consumedEvents.contains(eventType)) {
boolean cellWasEditing = parentCell.isEditing(cellParent, value, key);
@@ -1005,6 +1008,17 @@
   protected Element getImageElement() {
     return getImageElement(getElement());
   }
+
+  /**
+   * Returns the element that selection styles are applied to. The element
+ * includes the open/close image and the rendered value and spans the width of
+   * the tree.
+   *
+   * @return the selection element
+   */
+  protected Element getSelectionElement() {
+    return getSelectionElement(getElement());
+  }

   /**
    * Returns the key for the value of this node using the parent's
@@ -1039,7 +1053,7 @@
       animationFrame = Document.get().createDivElement();
       animationFrame.getStyle().setPosition(Position.RELATIVE);
       animationFrame.getStyle().setOverflow(Overflow.HIDDEN);
-      animationFrame.setId("animFrame");
+      animationFrame.getStyle().setDisplay(Display.NONE);
       getElement().appendChild(animationFrame);
     }
     return animationFrame;

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

Reply via email to