diff --git a/dom/inputmethod/forms.js b/dom/inputmethod/forms.js index 7a3e04fbfac..b43d4d7573c 100644 --- a/dom/inputmethod/forms.js +++ b/dom/inputmethod/forms.js @@ -224,7 +224,8 @@ let FormAssistant = { scrollIntoViewTimeout: null, _focusedElement: null, _focusCounter: 0, // up one for every time we focus a new element - _observer: null, + _focusDeleteObserver: null, + _focusContentObserver: null, _documentEncoder: null, _editor: null, _editing: false, @@ -250,9 +251,13 @@ let FormAssistant = { if (this.focusedElement) { this.focusedElement.removeEventListener('compositionend', this); - if (this._observer) { - this._observer.disconnect(); - this._observer = null; + if (this._focusDeleteObserver) { + this._focusDeleteObserver.disconnect(); + this._focusDeleteObserver = null; + } + if (this._focusContentObserver) { + this._focusContentObserver.disconnect(); + this._focusContentObserver = null; } if (this._selectionPrivate) { this._selectionPrivate.removeSelectionListener(this); @@ -292,7 +297,7 @@ let FormAssistant = { // 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) { + this._focusDeleteObserver = new MutationObserver(function(mutations) { var del = [].some.call(mutations, function(m) { return [].some.call(m.removedNodes, function(n) { return n.contains(element); @@ -305,10 +310,23 @@ let FormAssistant = { } }); - this._observer.observe(element.ownerDocument.body, { + this._focusDeleteObserver.observe(element.ownerDocument.body, { childList: true, subtree: true }); + + // If contenteditable, also add a mutation observer on its content and + // call selectionChanged when a change occurs + if (isContentEditable(element)) { + this._focusContentObserver = new MutationObserver(function() { + this.updateSelection(); + }.bind(this)); + + this._focusContentObserver.observe(element, { + childList: true, + subtree: true + }); + } } this.focusedElement = element; diff --git a/dom/inputmethod/mochitest/file_test_contenteditable.html b/dom/inputmethod/mochitest/file_test_contenteditable.html new file mode 100644 index 00000000000..c7492e51356 --- /dev/null +++ b/dom/inputmethod/mochitest/file_test_contenteditable.html @@ -0,0 +1,17 @@ + + + +
Jan Jongboom
+ + + diff --git a/dom/inputmethod/mochitest/mochitest.ini b/dom/inputmethod/mochitest/mochitest.ini index f20d3851528..7f5b936723b 100644 --- a/dom/inputmethod/mochitest/mochitest.ini +++ b/dom/inputmethod/mochitest/mochitest.ini @@ -6,6 +6,7 @@ support-files = file_inputmethod.html file_inputmethod_1043828.html file_test_app.html + file_test_contenteditable.html file_test_sendkey_cancel.html file_test_sms_app.html file_test_sms_app_1066515.html @@ -18,6 +19,7 @@ support-files = [test_bug978918.html] [test_bug1026997.html] [test_bug1043828.html] +[test_bug1059163.html] [test_bug1066515.html] [test_delete_focused_element.html] [test_sendkey_cancel.html] diff --git a/dom/inputmethod/mochitest/test_bug1059163.html b/dom/inputmethod/mochitest/test_bug1059163.html new file mode 100644 index 00000000000..77c0a575c54 --- /dev/null +++ b/dom/inputmethod/mochitest/test_bug1059163.html @@ -0,0 +1,77 @@ + + + + + Basic test for repeat sendKey events + + + + + +Mozilla Bug 1059163 +

+
+
+
+ + +