Bug 551704 - Part 4: Set the selection to the beginning of the document when we're entering the design mode; r=bzbarsky a=blocking-betaN+

This commit is contained in:
Ehsan Akhgari 2010-11-08 18:30:28 -05:00
parent 45318ab728
commit f576d21989
2 changed files with 27 additions and 1 deletions

View File

@ -3278,6 +3278,13 @@ nsHTMLDocument::EditingStateChanged()
nsCOMPtr<nsIPresShell> presShell = GetShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
// If we're entering the design mode, put the selection at the beginning of
// the document for compatibility reasons.
if (designMode) {
rv = editor->BeginningOfDocument();
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMArray<nsIStyleSheet> agentSheets;
rv = presShell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -77,6 +77,25 @@ SimpleTest.waitForFocus(function() {
var preformatted = document.getElementById("preformatted");
is(preformatted.innerHTML, "a\nb", "No BR node should be injected for preformatted editable fields");
var iframe = document.createElement("iframe");
iframe.addEventListener("load", function() {
var sel = iframe.contentWindow.getSelection();
is(sel.rangeCount, 0, "There should be no range in the selection initially");
iframe.contentDocument.designMode = "on";
sel = iframe.contentWindow.getSelection();
is(sel.rangeCount, 1, "There should be a single range in the selection after setting designMode");
var range = sel.getRangeAt(0);
ok(range.collapsed, "The range should be collapsed");
is(range.startContainer, iframe.contentDocument.body.firstChild, "The range should start on the text");
is(range.startOffset, 0, "The start offset should be zero");
continueTest();
}, false);
iframe.src = "data:text/html,foo";
document.getElementById("content").appendChild(iframe);
});
function continueTest() {
var divs = [];
for (var i = 0; i < 8; ++i) {
divs[i] = document.getElementById("test" + (i+1));
@ -99,7 +118,7 @@ SimpleTest.waitForFocus(function() {
}
doNextTest();
});
}
</script>
</pre>