Bug 468353 - designmode.css is not removed after designMode is turned off; r=bzbarsky sr=(bzbarsky + peterv)

This commit is contained in:
Mike Kaplinskiy 2009-02-12 05:15:59 +01:00
parent f6e651b4c4
commit 194202d83d
3 changed files with 126 additions and 3 deletions

View File

@ -3262,12 +3262,13 @@ void
nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor)
{
if (IsEditingOn()) {
EditingState oldState = mEditingState;
mEditingState = eTearingDown;
nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(aEditor);
if (editorss) {
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css"));
if (mEditingState == eDesignMode)
if (oldState == eDesignMode)
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));
}
}
@ -3366,6 +3367,7 @@ nsHTMLDocument::EditingStateChanged()
nsCOMPtr<nsIEditor> editor;
{
EditingState oldState = mEditingState;
nsAutoEditingState push(this, eSettingUp);
if (makeWindowEditable) {
@ -3404,9 +3406,9 @@ nsHTMLDocument::EditingStateChanged()
NS_ENSURE_SUCCESS(rv, rv);
updateState = PR_TRUE;
spellRecheckAll = mEditingState == eContentEditable;
spellRecheckAll = oldState == eContentEditable;
}
else if (mEditingState == eDesignMode) {
else if (oldState == eDesignMode) {
// designMode is being turned off (contentEditable is still on).
editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css"));

View File

@ -71,6 +71,7 @@ _TEST_FILES = test_bug1682.html \
test_bug403868.html \
test_bug403868.xhtml \
test_bug404320.html \
test_bug468353.html \
test_form-parsing.html \
test_viewport.html \
test_documentAll.html \

View File

@ -0,0 +1,120 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=468353
-->
<head>
<title>Test for Bug 468353</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=468353">Mozilla Bug 468353</a>
<p id="display"></p>
<div id="content">
<iframe></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var styleSheets = null;
function checkStylesheets() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Evidently RemoveStyleSheet is the only method in nsIEditorStyleSheets
// that would throw. RemoveOverrideStyleSheet returns NS_OK even if the
// sheet is not there
var removed = 0;
try
{
styleSheets.removeStyleSheet("resource://gre/res/designmode.css");
removed++;
}
catch (ex) { }
try {
styleSheets.removeStyleSheet("resource://gre/res/contenteditable.css");
removed++;
}
catch (ex) { }
is(removed, 0, "Should have thrown if stylesheet was not there");
}
function runTest() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Ci = Components.interfaces;
const Cc = Components.classes;
/** Found while fixing bug 440614 **/
var editframe = window.frames[0];
var editdoc = editframe.document;
var editor = null;
editdoc.write('');
editdoc.close();
editdoc.designMode='on';
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)
.getEditorForWindow(editframe);
styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
editdoc.designMode='off';
checkStylesheets();
// Let go
editor = null;
styleSheets = null;
editdoc.body.contentEditable = true;
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)
.getEditorForWindow(editframe);
styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
editdoc.body.contentEditable = false;
checkStylesheets();
editdoc.designMode = "on";
editdoc.body.contentEditable = true;
editdoc.designMode = "off";
// Hold the reference to the editor
editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession)
.getEditorForWindow(editframe);
styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
editdoc.body.contentEditable = false;
checkStylesheets();
SimpleTest.finish();
}
//XXX I don't know if this is necessary, but we're dealing with iframes...
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
</script>
</pre>
</body>
</html>