Fix for bug 402284 (Switching between designMode and contentEditable broken). r=cpearce, sr=roc, a=beltzner.

This commit is contained in:
peterv%propagandism.org 2007-11-05 21:19:52 +00:00
Родитель 59c12a4045
Коммит 57c5353a96
1 изменённых файлов: 28 добавлений и 24 удалений

Просмотреть файл

@ -3987,25 +3987,27 @@ nsHTMLDocument::EditingStateChanged()
nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRBool makeWindowEditable = (mEditingState == eOff) && HasPresShell(window);
if (!makeWindowEditable) {
if (!HasPresShell(window)) {
// We should not make the window editable or setup its editor.
// It's probably style=display:none.
return NS_OK;
}
// Editing is being turned on (through designMode or contentEditable)
// Turn on editor.
// XXX This can cause flushing which can change the editing state, so make
// sure to avoid recursing.
EditingState oldState = mEditingState;
mEditingState = eSettingUp;
PRBool makeWindowEditable = mEditingState == eOff;
if (makeWindowEditable) {
// Editing is being turned on (through designMode or contentEditable)
// Turn on editor.
// XXX This can cause flushing which can change the editing state, so make
// sure to avoid recursing.
EditingState oldState = mEditingState;
mEditingState = eSettingUp;
rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
mEditingState = oldState;
mEditingState = oldState;
}
// XXX Need to call TearDownEditorOnWindow for all failures.
nsCOMPtr<nsIEditorDocShell> editorDocShell =
@ -4072,20 +4074,22 @@ nsHTMLDocument::EditingStateChanged()
mEditingState = newState;
// Set the editor to not insert br's on return when in p
// elements by default.
// XXX Do we only want to do this for designMode?
PRBool unused;
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
NS_LITERAL_STRING("false"), &unused);
if (makeWindowEditable) {
// Set the editor to not insert br's on return when in p
// elements by default.
// XXX Do we only want to do this for designMode?
PRBool unused;
rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
NS_LITERAL_STRING("false"), &unused);
if (NS_FAILED(rv)) {
// Editor setup failed. Editing is not on after all.
// XXX Should we reset the editable flag on nodes?
editSession->TearDownEditorOnWindow(window, PR_TRUE);
mEditingState = eOff;
if (NS_FAILED(rv)) {
// Editor setup failed. Editing is not on after all.
// XXX Should we reset the editable flag on nodes?
editSession->TearDownEditorOnWindow(window, PR_TRUE);
mEditingState = eOff;
return rv;
return rv;
}
}
if (updateState) {