Bug 683736 - Backspace key in form fields in desktop Linux Fennec goes back a page instead of deleting r=mbrubeck
authorOleg Romashin <romaxa@gmail.com>
Thu, 01 Sep 2011 12:26:25 -0700
changeset 76406 d4c725db736947534fe1d17533f53b406902abf2
parent 76405 4f3eb6d6dcf5454c74e5bb69bcd39fd838ac7e66
child 76407 1b633e26f8a3896422bd12c1adfcd676e4db41e1
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmbrubeck
bugs683736
milestone9.0a1
Bug 683736 - Backspace key in form fields in desktop Linux Fennec goes back a page instead of deleting r=mbrubeck
mobile/chrome/content/browser.js
mobile/chrome/content/common-ui.js
mobile/chrome/content/content.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -177,16 +177,17 @@ var Browser = {
     // XXX change
 
     /* handles dispatching clicks on browser into clicks in content or zooms */
     Elements.browsers.customDragger = new Browser.MainDragger();
 
     /* handles web progress management for open browsers */
     Elements.browsers.webProgress = new Browser.WebProgress();
 
+    this.keyFilter = new KeyFilter(Elements.browsers);
     let mouseModule = new MouseModule();
     let gestureModule = new GestureModule(Elements.browsers);
     let scrollWheelModule = new ScrollwheelModule(Elements.browsers);
 
     ContentTouchHandler.init();
 
     // Warning, total hack ahead. All of the real-browser related scrolling code
     // lies in a pretend scrollbox here. Let's not land this as-is. Maybe it's time
@@ -1220,24 +1221,29 @@ var Browser = {
         // a message for this particular tab
         setTimeout(function(self) {
           let tab = self.getTabForBrowser(browser);
           self._doCloseTab(tab);
         }, 0, this);
         break;
       }
 
-      case "Browser:KeyPress":
+      case "Browser:KeyPress": {
+        let keyset = document.getElementById("mainKeyset");
+        keyset.setAttribute("disabled", "false");
+        if (json.preventDefault)
+          break;
+
         let event = document.createEvent("KeyEvents");
         event.initKeyEvent("keypress", true, true, null,
                            json.ctrlKey, json.altKey, json.shiftKey, json.metaKey,
                            json.keyCode, json.charCode);
-        document.getElementById("mainKeyset").dispatchEvent(event);
+        keyset.dispatchEvent(event);
         break;
-
+      }
       case "Browser:ZoomToPoint:Return":
         if (json.zoomTo) {
           let rect = Rect.fromRect(json.zoomTo);
           this.zoomToPoint(json.x, json.y, rect);
         } else {
           this.zoomFromPoint(json.x, json.y);
         }
         break;
@@ -1967,16 +1973,41 @@ const ContentTouchHandler = {
     this._dispatchMouseEvent("Browser:MouseLong", aX, aY);
   },
 
   toString: function toString() {
     return "[ContentTouchHandler] { }";
   }
 };
 
+
+/** Prevent chrome from consuming key events before remote content has a chance. */
+function KeyFilter(container) {
+  container.addEventListener("keypress", this, false);
+  container.addEventListener("keyup", this, false);
+  container.addEventListener("keydown", this, false);
+}
+
+KeyFilter.prototype = {
+  handleEvent: function handleEvent(aEvent) {
+    if (Elements.contentShowing.getAttribute("disabled") == "true")
+      return;
+
+    let browser = getBrowser();
+    if (browser && browser.active && browser.getAttribute("remote") == "true") {
+        document.getElementById("mainKeyset").setAttribute("disabled", "true");
+    }
+  },
+
+  toString: function toString() {
+    return "[KeyFilter] { }";
+  }
+};
+
+
 /**
  * Utility class to handle manipulations of the identity indicators in the UI
  */
 function IdentityHandler() {
   this._staticStrings = {};
   this._staticStrings[this.IDENTITY_MODE_DOMAIN_VERIFIED] = {
     encryption_label: Strings.browser.GetStringFromName("identity.encrypted2")
   };
--- a/mobile/chrome/content/common-ui.js
+++ b/mobile/chrome/content/common-ui.js
@@ -822,16 +822,17 @@ var FormHelperUI = {
         }
 
         // If the focus is not on the browser element, the key will not be sent
         // to the content so do it ourself
         let focusedElement = gFocusManager.getFocusedElementForWindow(window, true, {});
         if (focusedElement && focusedElement.localName == "browser")
           return;
 
+        Browser.keyFilter.handleEvent(aEvent);
         break;
 
       case "SizeChanged":
         setTimeout(function(self) {
           SelectHelperUI.sizeToContent();
           self._zoom(self._currentElementRect, self._currentCaretRect);
         }, 0, this);
         break;
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -294,26 +294,24 @@ let Content = {
   },
 
   handleEvent: function handleEvent(aEvent) {
     switch (aEvent.type) {
       // If the keypress is a trusted event and has not been consume by content
       // let's send it back to the chrome process to have it handle shortcuts
       case "keypress":
         let timer = new Util.Timeout(function() {
-          if(aEvent.getPreventDefault())
-            return;
-
           let eventData = {
             ctrlKey: aEvent.ctrlKey,
             altKey: aEvent.altKey,
             shiftKey: aEvent.shiftKey,
             metaKey: aEvent.metaKey,
             keyCode: aEvent.keyCode,
-            charCode: aEvent.charCode
+            charCode: aEvent.charCode,
+            preventDefault: aEvent.getPreventDefault()
           };
           sendAsyncMessage("Browser:KeyPress", eventData);
         });
         timer.once(0);
         break;
 
       case "DOMActivate": {
         // In a local tab, open remote links in new tabs.