navigate preferably between children of the same parent

The nav cache attempts to take advantage of the order that
the dom is walked to know when multiple nodes have the same
parent. The old implementation doesn't always work, and a
simpler non-cached version makes more sense.

The algorithm now walks nodes until the parent has more than
one child, and assigns that parent as the 'parent group'. On
the other end, nodes with no parent group are never allowed
to get preferential matching treatment.
diff --git a/WebKit/android/nav/CacheBuilder.cpp b/WebKit/android/nav/CacheBuilder.cpp
index 37bdc9a..58be0e8 100644
--- a/WebKit/android/nav/CacheBuilder.cpp
+++ b/WebKit/android/nav/CacheBuilder.cpp
@@ -824,6 +824,16 @@
     setData((CachedFrame*) root);
 }
 
+static Node* ParentWithChildren(Node* node)
+{
+    Node* parent = node;
+    while ((parent = parent->parentNode())) {
+        if (parent->childNodeCount() > 1)
+            return parent;
+    }
+    return 0;
+}
+
 static Node* OneAfter(Node* node) 
 {
     Node* parent = node;
@@ -917,8 +927,6 @@
             lastChildIndex = last->mCachedNodeIndex;
             last = &tracker.last();
         }
-        if (node == last->mParentLastChild)
-            last->mParentLastChild = NULL;
         do {
             const ClipColumnTracker* lastClip = &clipTracker.last();
             if (node != lastClip->mLastChild)
@@ -1211,9 +1219,7 @@
         cachedNode.setMaxLength(maxLength);
         cachedNode.setName(name);
         cachedNode.setParentIndex(last->mCachedNodeIndex);
-        if (last->mParentLastChild == NULL)
-            last->mParentLastChild = OneAfter(node->parentNode()->lastChild());
-        cachedNode.setParentGroup(last->mParentLastChild);
+        cachedNode.setParentGroup(ParentWithChildren(node));
         cachedNode.setTabIndex(tabIndex);
         cachedNode.setTextSize(textSize);
         cachedNode.setType(type);
@@ -1235,7 +1241,6 @@
                 Tracker& working = tracker.last();
                 working.mCachedNodeIndex = lastIndex;
                 working.mLastChild = OneAfter(lastChild);
-                working.mParentLastChild = OneAfter(node->parentNode()->lastChild());
                 last = &tracker.at(tracker.size() - 2);
                 working.mSomeParentTakesFocus = last->mSomeParentTakesFocus | takesFocus;
             } 
diff --git a/WebKit/android/nav/CacheBuilder.h b/WebKit/android/nav/CacheBuilder.h
index 784302c..0c12699 100644
--- a/WebKit/android/nav/CacheBuilder.h
+++ b/WebKit/android/nav/CacheBuilder.h
@@ -200,7 +200,6 @@
         int mCachedNodeIndex;
         int mTabIndex;
         Node* mLastChild;
-        Node* mParentLastChild;
         bool mSomeParentTakesFocus;
     };
     void adjustForColumns(const ClipColumnTracker& track, 
diff --git a/WebKit/android/nav/CachedFrame.cpp b/WebKit/android/nav/CachedFrame.cpp
index 953eed4..54c295d 100644
--- a/WebKit/android/nav/CachedFrame.cpp
+++ b/WebKit/android/nav/CachedFrame.cpp
@@ -687,7 +687,7 @@
 //        return REJECT_TEST;
 //    }
     void* par = cursor ? cursor->parentGroup() : NULL;
-    testData.mCursorChild = test->parentGroup() == par;
+    testData.mCursorChild = par ? test->parentGroup() == par : false;
 #if 0 // not debugged
     if (cursor && cursor->hasMouseOver() && test->hasMouseOver() == false &&
             cursor->bounds().contains(test->bounds()))