Bug 918863 - MutationObserver doesnt recognize all deleted elements, keypress is fired if keydown is canceled. r=yxl, r=kanru
authorJan Jongboom <janjongboom@gmail.com>
Tue, 03 Dec 2013 08:37:38 -0500
changeset 174243 0e1a6c3f57698cccb1698caee839d3c90de36f43
parent 174242 ad72f0b9e16af506926f5bb66b4833f4becef640
child 174244 68a34c25a2ab9048d0a4868a7d21bf068ff9e218
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyxl, kanru
bugs918863
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 918863 - MutationObserver doesnt recognize all deleted elements, keypress is fired if keydown is canceled. r=yxl, r=kanru
dom/inputmethod/forms.js
--- a/dom/inputmethod/forms.js
+++ b/dom/inputmethod/forms.js
@@ -278,27 +278,28 @@ let FormAssistant = {
         this._editor.addEditorObserver(this);
       }
 
       // If our focusedElement is removed from DOM we want to handle it properly
       let MutationObserver = element.ownerDocument.defaultView.MutationObserver;
       this._observer = new MutationObserver(function(mutations) {
         var del = [].some.call(mutations, function(m) {
           return [].some.call(m.removedNodes, function(n) {
-            return n === element;
+            return n.contains(element);
           });
         });
         if (del && element === self.focusedElement) {
           // item was deleted, fake a blur so all state gets set correctly
           self.handleEvent({ target: element, type: "blur" });
         }
       });
 
-      this._observer.observe(element.parentNode, {
-        childList: true
+      this._observer.observe(element.ownerDocument.body, {
+        childList: true,
+        subtree: true
       });
     }
 
     this.focusedElement = element;
   },
 
   get documentEncoder() {
     return this._documentEncoder;
@@ -512,20 +513,26 @@ let FormAssistant = {
         event.initEvent('input', true, false);
         target.dispatchEvent(event);
         break;
       }
 
       case "Forms:Input:SendKey":
         CompositionManager.endComposition('');
 
-        ["keydown", "keypress", "keyup"].forEach(function(type) {
-          domWindowUtils.sendKeyEvent(type, json.keyCode, json.charCode,
-            json.modifiers);
-        });
+        this._editing = true;
+        let doKeypress = domWindowUtils.sendKeyEvent('keydown', json.keyCode,
+                                  json.charCode, json.modifiers);
+        if (doKeypress) {
+          domWindowUtils.sendKeyEvent('keypress', json.keyCode,
+                                  json.charCode, json.modifiers);
+        }
+        domWindowUtils.sendKeyEvent('keyup', json.keyCode,
+                                  json.charCode, json.modifiers);
+        this._editing = false;
 
         if (json.requestId) {
           sendAsyncMessage("Forms:SendKey:Result:OK", {
             requestId: json.requestId
           });
         }
         break;