Show "Go" for the last textfield in a form.

Fixes http://b/issue?id=2210152
diff --git a/WebKit/android/nav/CacheBuilder.cpp b/WebKit/android/nav/CacheBuilder.cpp
index 522d381..f854e71 100644
--- a/WebKit/android/nav/CacheBuilder.cpp
+++ b/WebKit/android/nav/CacheBuilder.cpp
@@ -1101,6 +1101,7 @@
             if (input->isTextField()) {
                 type = TEXT_INPUT_CACHEDNODETYPE;
                 cachedInput.init();
+                cachedInput.setFormPointer(input->form());
                 cachedInput.setIsTextField(true);
                 cachedInput.setIsReadOnly(input->readOnly());
                 exported = input->value().threadsafeCopy();
@@ -1117,6 +1118,7 @@
             cachedInput.init();
             type = TEXT_INPUT_CACHEDNODETYPE;
             HTMLTextAreaElement* area = static_cast<HTMLTextAreaElement*>(node);
+            cachedInput.setFormPointer(area->form());
             cachedInput.setIsReadOnly(area->readOnly());
             // Although technically it is not an HTMLInputElement, and therefore
             // has no InputType, this one is the most appropriate.
diff --git a/WebKit/android/nav/CachedInput.cpp b/WebKit/android/nav/CachedInput.cpp
index 858402f..52d2066 100644
--- a/WebKit/android/nav/CachedInput.cpp
+++ b/WebKit/android/nav/CachedInput.cpp
@@ -50,6 +50,7 @@
         scratch[index++] = c;
     }
     DUMP_NAV_LOGD("%.*s\"\n", index, scratch);
+    DUMP_NAV_LOGD("// void* mForm=%p;", b->mForm);
     DUMP_NAV_LOGD("// int mMaxLength=%d;\n", b->mMaxLength);
     DUMP_NAV_LOGD("// int mTextSize=%d;\n", b->mTextSize);
     DUMP_NAV_LOGD("// int mInputType=%d;\n", b->mInputType);
diff --git a/WebKit/android/nav/CachedInput.h b/WebKit/android/nav/CachedInput.h
index f4f0e95..f3cf1fe 100644
--- a/WebKit/android/nav/CachedInput.h
+++ b/WebKit/android/nav/CachedInput.h
@@ -38,6 +38,7 @@
         // Initiaized to 0 in its array, so nothing to do in the
         // constructor
     }
+    void* formPointer() const { return mForm; }
     void init() {
         bzero(this, sizeof(CachedInput));
         mName = WebCore::String();
@@ -48,6 +49,7 @@
     bool isTextField() const { return mIsTextField; }
     int maxLength() const { return mMaxLength; };
     const WebCore::String& name() const { return mName; }
+    void setFormPointer(void* form) { mForm = form; }
     void setInputType(WebCore::HTMLInputElement::InputType type) { mInputType = type; }
     void setIsReadOnly(bool isReadOnly) { mIsReadOnly = isReadOnly; }
     void setIsRtlText(bool isRtlText) { mIsRtlText = isRtlText; }
@@ -57,6 +59,7 @@
     void setTextSize(int textSize) { mTextSize = textSize; }
     int textSize() const { return mTextSize; }
 private:
+    void* mForm;
     WebCore::String mName;
     int mMaxLength;
     int mTextSize;
diff --git a/WebKit/android/nav/CachedRoot.cpp b/WebKit/android/nav/CachedRoot.cpp
index 0011f06..2354ebc 100644
--- a/WebKit/android/nav/CachedRoot.cpp
+++ b/WebKit/android/nav/CachedRoot.cpp
@@ -771,9 +771,13 @@
         return FAILURE;
     }
     // Now find the next textfield/area starting with the cursor
-    if (cursorFrame->nextTextField(cursor, 0, true)) {
-        // There is a textfield/area after the cursor, so the textfield under
-        // the cursor should have the NEXT action
+    const CachedFrame* potentialFrame;
+    const CachedNode* potentialNext
+            = cursorFrame->nextTextField(cursor, &potentialFrame, true);
+    if (potentialNext && cursorFrame->textInput(cursor)->formPointer()
+            == potentialFrame->textInput(potentialNext)->formPointer()) {
+        // There is a textfield/area after the cursor in the same form,
+        // so the textfield under the cursor should have the NEXT action
         return NEXT;
     }
     // If this line is reached, we know that the textfield under the cursor is