Bug 969773 - Restore Selection/Controller state when disconnecting the editor. r=ehsan

This commit is contained in:
Mats Palmgren 2014-02-10 02:14:38 +00:00
parent 73bca3faa9
commit 48a4213ce5
4 changed files with 69 additions and 0 deletions

View File

@ -232,6 +232,21 @@ nsEditorEventListener::Disconnect()
return;
}
UninstallFromEditor();
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> domFocus;
fm->GetFocusedElement(getter_AddRefs(domFocus));
nsCOMPtr<nsINode> focusedElement = do_QueryInterface(domFocus);
mozilla::dom::Element* root = mEditor->GetRoot();
if (focusedElement && root &&
nsContentUtils::ContentIsDescendantOf(focusedElement, root)) {
// Reset the Selection ancestor limiter and SelectionController state
// that nsEditor::InitializeSelection set up.
mEditor->FinalizeSelection();
}
}
mEditor = nullptr;
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Contenteditable Selection Test Case</title>
<script>
function runTests() {
var text = document.getElementById("text");
text.focus();
setTimeout(function () {
document.body.offsetHeight;
document.documentElement.removeAttribute('class');
}, 0);
}
document.addEventListener('MozReftestInvalidate', runTests, false);
</script>
</head>
<body>
<div>This is a contenteditable.</div>
<div id="text" tabindex="0">This is focusable text</div>
</body>
</html>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<meta charset="utf-8">
<title>Contenteditable Selection Test Case</title>
<script>
function runTests() {
var editable = document.getElementById("editable");
var text = document.getElementById("text");
editable.focus();
setTimeout(function () {
editable.setAttribute("contenteditable", "false");
text.focus();
setTimeout(function () {
document.body.offsetHeight;
document.documentElement.removeAttribute('class');
}, 0);
}, 0);
}
document.addEventListener('MozReftestInvalidate', runTests, false);
</script>
</head>
<body>
<div id="editable" contenteditable="true" tabindex="0" spellcheck="false">This is a contenteditable.</div>
<div id="text" tabindex="0">This is focusable text</div>
</body>
</html>

View File

@ -125,3 +125,4 @@ needs-focus == spellcheck-contenteditable-focused-reframe.html spellcheck-conten
== spellcheck-contenteditable-attr-dynamic-override-inherit.html spellcheck-contenteditable-disabled-ref.html
== spellcheck-contenteditable-property-dynamic-override.html spellcheck-contenteditable-disabled-ref.html
== spellcheck-contenteditable-property-dynamic-override-inherit.html spellcheck-contenteditable-disabled-ref.html
needs-focus == 969773.html 969773-ref.html