Bug 538700 - Add preferences to control form fill assistant behavior [r=mark.finkle]
authorVivien Nicolas <21@vingtetun.org>
Tue, 30 Mar 2010 13:56:06 -0400
changeset 66080 22dbca551a43ae343efb8228739d0d30abfb08cf
parent 66079 cd520136470b09b4d2d7bc75c09ec68c88f73dad
child 66081 13e85f60b30f78e64fe9777e11de18bb64fa5d3a
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmark
bugs538700
Bug 538700 - Add preferences to control form fill assistant behavior [r=mark.finkle]
mobile/app/mobile.js
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -129,16 +129,21 @@ pref("alerts.slideIncrementTime", 10);
 pref("alerts.totalOpenTime", 6000);
 pref("alerts.height", 50);
 
 /* password manager */
 pref("signon.rememberSignons", true);
 pref("signon.expireMasterPassword", false);
 pref("signon.SignonFileName", "signons.txt");
 
+/* form helper */
+pref("formhelper.enabled", true);
+pref("formhelper.autozoom", true);
+pref("formhelper.restore", false);
+
 /* autocomplete */
 pref("browser.formfill.enable", true);
 
 #ifdef WINCE
 pref("layout.css.devPixelsPerPx", "1");
 #endif
 
 /* spellcheck */
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1341,17 +1341,17 @@ var FormHelper = {
 
       return this._isElementVisible(aElement);
     }
 
     return false;
   },
 
   _isValidSelectElement: function(aElement) {
-    return (aElement instanceof HTMLSelectElement) || (aElement instanceof Ci.nsIDOMXULMenuListElement);
+    return SelectHelper.canShowUIFor(aElement);
   },
 
   _isElementVisible: function(aElement) {
     let style = aElement.ownerDocument.defaultView.getComputedStyle(aElement, null);
     let isVisible = (style.getPropertyValue("visibility") != "hidden");
     let isOpaque = (style.getPropertyValue("opacity") != 0);
 
     let rect = aElement.getBoundingClientRect();
@@ -1486,25 +1486,33 @@ var FormHelper = {
   },
 
   open: function formHelperOpen(aElement) {
     if (this._open == true && aElement == this._currentElement &&
         gFocusManager.focusedElement == this._currentElement)
       return false;
 
     this._open = true;
+    this._restore ={  zoom: Browser._browserView.getZoomLevel(),
+                      scroll: Browser.getScrollboxPosition(Browser.contentScrollboxScroller)
+                    };
     window.addEventListener("keyup", this, false);
     let bv = Browser._browserView;
     bv.ignorePageScroll(true);
 
     this._container.hidden = false;
     this._helperSpacer.hidden = false;
 
     this._nodes = this._getAll();
     this.setCurrentElement(aElement);
+
+    let evt = document.createEvent("UIEvents");
+    evt.initUIEvent("FormUI", true, true, window, this._open);
+    this._container.dispatchEvent(evt);
+
     return true;
   },
 
   close: function formHelperHide() {
     if (!this._open)
       return;
 
     this._updateSelect(this._currentElement, null);
@@ -1517,17 +1525,29 @@ var FormHelper = {
     Browser.contentScrollboxScroller.scrollBy(0, 0);
     bv.onAfterVisibleMove();
 
     bv.ignorePageScroll(false);
 
     window.removeEventListener("keyup", this, false);
     this._container.hidden = true;
     this._currentElement = null;
+
+    if (gPrefService.getBoolPref("formhelper.restore") && this._restore) {
+      bv.setZoomLevel(this._restore.zoom);
+      Browser.contentScrollboxScroller.scrollTo(this._restore.scroll.x, this._restore.scroll.y);
+      bv.onAfterVisibleMove();
+      this._restore = null;
+    }
+
     this._open = false;
+
+    let evt = document.createEvent("UIEvents");
+    evt.initUIEvent("FormUI", true, true, window, this._open);
+    this._container.dispatchEvent(evt);
   },
 
   handleEvent: function formHelperHandleEvent(aEvent) {
     let isChromeFocused = gFocusManager.getFocusedElementForWindow(window, false, {}) == gFocusManager.focusedElement;
     if (isChromeFocused)
       return;
 
     let currentElement = this.getCurrentElement();
@@ -1579,18 +1599,21 @@ var FormHelper = {
           SelectHelper.unselectAll();
           SelectHelper.selectByIndex(target.selectedIndex);
         }
         break;
     }
   },
 
   zoom: function formHelperZoom(aElement) {
-    let zoomLevel = Browser._getZoomLevelForElement(aElement);
-    zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
+    let zoomLevel = Browser._browserView.getZoomLevel();
+    if (gPrefService.getBoolPref("formhelper.autozoom")) {
+      zoomLevel = Browser._getZoomLevelForElement(aElement);
+      zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
+    }
 
     let elRect = this._getRectForElement(aElement);
     let zoomRect = Browser._getZoomRectForPoint(elRect.center().x, elRect.y, zoomLevel);
 
     Browser.setVisibleRect(zoomRect);
   },
 
   canShowUIFor: function(aElement) {
@@ -1799,30 +1822,42 @@ var SelectHelper = {
         }
       }
     }
 
     if (!isIdentical)
       this._control.fireOnChange();
   },
 
+
+  _isValidElement: function(aElement) {
+    if (!aElement || aElement.disabled)
+      return false;
+
+    return (aElement instanceof HTMLSelectElement) || (aElement instanceof Ci.nsIDOMXULMenuListElement);
+  },
+
   reset: function() {
     this._updateControl();
     let empty = this._list.cloneNode(false);
     this._list.parentNode.replaceChild(empty, this._list);
     this._list = empty;
   },
 
   close: function() {
     this._list.removeEventListener("click", this, false);
     this._panel.hidden = true;
 
     this.reset();
   },
 
+  canShowUIFor: function(aElement) {
+    return this._isValidElement(aElement);
+  },
+
   unselectAll: function() {
     this._forEachOption(function(aItem, aIndex) aItem.selected = false);
   },
 
   selectByIndex: function(aIndex) {
     for (let i = 0; i < this._list.childNodes.length; i++) {
       let option = this._list.childNodes[i];
       if (option.optionIndex == aIndex) {
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1869,18 +1869,24 @@ ContentCustomClicker.prototype = {
       this._hideCanvas();
 
       let [elementX, elementY] = Browser.transformClientToBrowser(cX, cY);
       let element = Browser.elementFromPoint(elementX, elementY);
       if (modifiers == 0) {
         if (element instanceof HTMLOptionElement)
           element = element.parentNode;
 
-        if (FormHelper.canShowUIFor(element) && FormHelper.open(element))
+        if (gPrefService.getBoolPref("formhelper.enabled")) {
+          if (FormHelper.canShowUIFor(element) && FormHelper.open(element))
+            return;
+        }
+        else if (SelectHelper.canShowUIFor(element)) {
+          SelectHelper.show(element);
           return;
+        }
 
         this._dispatchMouseEvent("mousedown", cX, cY);
         this._dispatchMouseEvent("mouseup", cX, cY);
       }
       else if (modifiers == Ci.nsIDOMNSEvent.CONTROL_MASK) {
         let uri = Util.getHrefForElement(element);
         if (uri)
           Browser.addTab(uri, false);