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 @@ + + +
++ ++ + +