Bug 524501 - Form UI doesn't go to Search Mail or Search the Web buttons in Gmail [r=mark.finkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 09 Dec 2009 03:03:04 -0500
changeset 65896 44b44310d65886a30bd404176ced6f430420cbde
parent 65895 1e97a0406b6f88da4a64d4f9efa43b59897d2395
child 65897 ca9809d6d5f2e8b8fe884469827d37343ac0f1da
push idunknown
push userunknown
push dateunknown
reviewersmark.finkle
bugs524501
Bug 524501 - Form UI doesn't go to Search Mail or Search the Web buttons in Gmail [r=mark.finkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1115,16 +1115,19 @@ var FormHelper = {
       SelectHelper.close();
     }
   },
 
   _isValidElement: function(aElement) {
     if (aElement.disabled)
       return false;
 
+    if (aElement.getAttribute("role") == "button" && aElement.hasAttribute("tabindex"))
+      return this._isElementVisible(aElement);
+
     if (this._isValidSelectElement(aElement) || aElement instanceof HTMLTextAreaElement)
       return this._isElementVisible(aElement);
     
     if (aElement instanceof HTMLInputElement) {
       let ignoreInputElements = ["checkbox", "radio", "hidden", "reset", "button", "image"];
       let isValidElement = (ignoreInputElements.indexOf(aElement.type) == -1);
       if (!isValidElement)
        return false;
@@ -1139,39 +1142,33 @@ var FormHelper = {
     return (aElement instanceof HTMLSelectElement) || (aElement instanceof Ci.nsIDOMXULMenuListElement);
   },
 
   _isElementVisible: function(aElement) {
     let rect = aElement.getBoundingClientRect();
     return (rect.height != 0 || rect.width != 0);
   },
 
-  _nsResolver: function(aPrefix) {
-    var ns = {
-      "xhtml" : "http://www.w3.org/1999/xhtml"
-    };
-    return ns[aPrefix] || null;
-  },
+  _getAll: function() {
+    let elements = [];
+
+    // get all the documents
+    let documents = [getBrowser().contentDocument];
+    let iframes = getBrowser().contentDocument.getElementsByTagName("iframe");
+    for (let i = 0; i < iframes.length; i++)
+      documents.push(iframes[i].contentDocument);
 
-  _getAll: function() {
-    let doc = getBrowser().contentDocument;
-    let prefix = doc.documentElement.wrappedJSObject.namespaceURI ? "xhtml" : "";
-    let expression = "//input|//select|//button|//textarea".replace("//", "//" + prefix + ":");
-    let nodes = doc.evaluate(expression,
-                             doc,
-                             this._nsResolver,
-                             XPathResult.ORDERED_NODE_ITERATOR_TYPE,
-                             null);
+    for (let i = 0; i < documents.length; i++) {
+      let nodes = documents[i].querySelectorAll("input, button, select, textarea, [role=button]");
 
-    let elements = [];
-    let node = nodes.iterateNext();
-    while (node) {
-      if (this._isValidElement(node))
-        elements.push(node);
-      node = nodes.iterateNext();
+      for (let j =0; j < nodes.length; j++) {
+        let node = nodes[j];
+        if (this._isValidElement(node))
+          elements.push(node.wrappedJSObject || node);
+      }
     }
 
     function orderByTabIndex(a, b) {
       // for an explanation on tabbing navigation see 
       // http://www.w3.org/TR/html401/interact/forms.html#h-17.11.1
       // In resume tab index navigation order is 1, 2, 3, ..., 32767, 0
       if (a.tabIndex == 0 || b.tabIndex == 0)
         return b.tabIndex;
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -656,17 +656,17 @@ var Browser = {
    */
   get selectedBrowser() {
     return this._selectedTab.browser;
   },
 
   getTabForDocument: function(aDocument) {
     let tabs = this._tabs;
     for (let i = 0; i < tabs.length; i++) {
-      if (tabs[i].browser.contentDocument === aDocument)
+      if (tabs[i].browser.contentDocument == aDocument)
         return tabs[i];
     }
     return null;
   },
 
   getTabAtIndex: function(index) {
     if (index > this._tabs.length || index < 0)
       return null;
@@ -1117,23 +1117,25 @@ var Browser = {
     if (!bv.isDefaultZoom()) {
       let [elementX, elementY] = this.transformClientToBrowser(cX, cY);
       let zoomRect = this._getZoomRectForPoint(elementX, elementY, zoomLevel);
       this.setVisibleRect(zoomRect);
     }
   },
 
   getBoundingContentRect: function getBoundingContentRect(contentElem) {
-    let tab = Browser.getTabForDocument(contentElem.ownerDocument);
-    if (!tab)
+    let document = contentElem.ownerDocument;
+    while(document.defaultView.frameElement)
+      document = document.defaultView.frameElement.ownerDocument;
+
+    let tab = Browser.getTabForDocument(document);
+    if (!tab || !tab.browser)
       return null;
+
     let browser = tab.browser;
-    if (!browser)
-      return null;
-
     let offset = BrowserView.Util.getContentScrollOffset(browser);
 
     let r = contentElem.getBoundingClientRect();
 
     // step out of iframes and frames, offsetting scroll values
     for (let frame = contentElem.ownerDocument.defaultView; frame != browser.contentWindow; frame = frame.parent) {
       // adjust client coordinates' origin to be top left of iframe viewport
       let rect = frame.frameElement.getBoundingClientRect();