зеркало из https://github.com/mozilla/pjs.git
Bug 599983 part 2 - Don't emit or process _moz_dirty more than necessary; r=ehsan,bz
This commit is contained in:
Родитель
e677a6d17c
Коммит
0f6ff731ff
|
@ -243,6 +243,12 @@ interface nsIDocumentEncoder : nsISupports
|
|||
*/
|
||||
const unsigned long OutputDropInvisibleBreak = (1 << 21);
|
||||
|
||||
/**
|
||||
* Don't check for _moz_dirty attributes when deciding whether to
|
||||
* pretty-print if this flag is set (bug 599983).
|
||||
*/
|
||||
const unsigned long OutputIgnoreMozDirty = (1 << 22);
|
||||
|
||||
/**
|
||||
* Initialize with a pointer to the document and the mime type.
|
||||
* @param aDocument Document to encode.
|
||||
|
|
|
@ -347,8 +347,8 @@ nsHTMLContentSerializer::AppendElementEnd(Element* aElement,
|
|||
--mDisableEntityEncoding;
|
||||
}
|
||||
|
||||
bool forceFormat = content->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::mozdirty);
|
||||
bool forceFormat = !(mFlags & nsIDocumentEncoder::OutputIgnoreMozDirty) &&
|
||||
content->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdirty);
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mPreLevel && !mDoRaw) {
|
||||
DecrIndentation(name);
|
||||
|
|
|
@ -565,8 +565,8 @@ nsXHTMLContentSerializer::CheckElementStart(nsIContent * aContent,
|
|||
// The _moz_dirty attribute is emitted by the editor to
|
||||
// indicate that this element should be pretty printed
|
||||
// even if we're not in pretty printing mode
|
||||
aForceFormat = aContent->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::mozdirty);
|
||||
aForceFormat = !(mFlags & nsIDocumentEncoder::OutputIgnoreMozDirty) &&
|
||||
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdirty);
|
||||
|
||||
nsIAtom *name = aContent->Tag();
|
||||
PRInt32 namespaceID = aContent->GetNameSpaceID();
|
||||
|
@ -592,8 +592,8 @@ nsXHTMLContentSerializer::CheckElementEnd(nsIContent * aContent,
|
|||
{
|
||||
NS_ASSERTION(!mIsHTMLSerializer, "nsHTMLContentSerializer shouldn't call this method !");
|
||||
|
||||
aForceFormat = aContent->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::mozdirty);
|
||||
aForceFormat = !(mFlags & nsIDocumentEncoder::OutputIgnoreMozDirty) &&
|
||||
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdirty);
|
||||
|
||||
nsIAtom *name = aContent->Tag();
|
||||
PRInt32 namespaceID = aContent->GetNameSpaceID();
|
||||
|
|
|
@ -697,13 +697,24 @@ nsGenericHTMLElement::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
|
|||
|
||||
NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult rv = docEncoder->NativeInit(doc, contentType,
|
||||
nsIDocumentEncoder::OutputEncodeBasicEntities |
|
||||
// Output DOM-standard newlines
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
// Don't do linebreaking that's not present in
|
||||
// the source
|
||||
nsIDocumentEncoder::OutputRaw);
|
||||
PRUint32 flags = nsIDocumentEncoder::OutputEncodeBasicEntities |
|
||||
// Output DOM-standard newlines
|
||||
nsIDocumentEncoder::OutputLFLineBreak |
|
||||
// Don't do linebreaking that's not present in
|
||||
// the source
|
||||
nsIDocumentEncoder::OutputRaw |
|
||||
// Only check for mozdirty when necessary (bug 599983)
|
||||
nsIDocumentEncoder::OutputIgnoreMozDirty;
|
||||
|
||||
if (IsEditable()) {
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
GetEditorInternal(getter_AddRefs(editor));
|
||||
if (editor && editor->OutputsMozDirty()) {
|
||||
flags &= ~nsIDocumentEncoder::OutputIgnoreMozDirty;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv = docEncoder->NativeInit(doc, contentType, flags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aIncludeSelf) {
|
||||
|
|
|
@ -55,7 +55,7 @@ interface nsIEditActionListener;
|
|||
interface nsIInlineSpellChecker;
|
||||
interface nsITransferable;
|
||||
|
||||
[scriptable, uuid(2e14b183-29d4-4282-9475-589277a70654)]
|
||||
[scriptable, uuid(7861fe14-9977-413f-a893-3e1000c40817)]
|
||||
|
||||
interface nsIEditor : nsISupports
|
||||
{
|
||||
|
@ -497,6 +497,12 @@ interface nsIEditor : nsISupports
|
|||
*/
|
||||
void deleteNode(in nsIDOMNode child);
|
||||
|
||||
/**
|
||||
* Returns true if markNodeDirty() has any effect. Returns false if
|
||||
* markNodeDirty() is a no-op.
|
||||
*/
|
||||
[notxpcom] boolean outputsMozDirty();
|
||||
|
||||
/**
|
||||
* markNodeDirty() sets a special dirty attribute on the node.
|
||||
* Usually this will be called immediately after creating a new node.
|
||||
|
|
|
@ -1270,9 +1270,23 @@ nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsAString& aAttribute)
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
nsEditor::OutputsMozDirty()
|
||||
{
|
||||
// Return true for Composer (!eEditorAllowInteraction) or mail
|
||||
// (eEditorMailMask), but false for webpages.
|
||||
return !(mFlags & nsIPlaintextEditor::eEditorAllowInteraction) ||
|
||||
(mFlags & nsIPlaintextEditor::eEditorMailMask);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditor::MarkNodeDirty(nsIDOMNode* aNode)
|
||||
{
|
||||
// Mark the node dirty, but not for webpages (bug 599983)
|
||||
if (!OutputsMozDirty()) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
||||
if (element) {
|
||||
element->SetAttr(kNameSpaceID_None, nsEditProperty::mozdirty,
|
||||
|
|
|
@ -50,6 +50,7 @@ _TEST_FILES = \
|
|||
test_bug567213.html \
|
||||
file_bug586662.html \
|
||||
test_bug586662.html \
|
||||
test_bug599983.html \
|
||||
$(NULL)
|
||||
|
||||
_CHROME_TEST_FILES = \
|
||||
|
@ -57,6 +58,7 @@ _CHROME_TEST_FILES = \
|
|||
test_bug46555.html \
|
||||
test_bug646194.xul \
|
||||
test_dragdrop.html \
|
||||
test_bug599983.xul \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=599983
|
||||
-->
|
||||
<title>Test for Bug 599983</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=599983">Mozilla Bug 599983</a>
|
||||
<div contenteditable>foo</div>
|
||||
<script>
|
||||
getSelection().selectAllChildren(document.querySelector("div"));
|
||||
document.execCommand("bold");
|
||||
is(document.querySelector("[_moz_dirty]"), null,
|
||||
"No _moz_dirty allowed in webpages");
|
||||
</script>
|
|
@ -0,0 +1,70 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin"
|
||||
type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=599983
|
||||
-->
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="Mozilla Bug 599983" onload="runTest()">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=599983"
|
||||
target="_blank">Mozilla Bug 599983</a>
|
||||
<editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
id="editor"
|
||||
editortype="html"
|
||||
src="about:blank" />
|
||||
</body>
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
const kAllowInteraction = Components.interfaces.nsIPlaintextEditor
|
||||
.eEditorAllowInteraction;
|
||||
const kMailMask = Components.interfaces.nsIPlaintextEditor.eEditorMailMask;
|
||||
|
||||
function runTest() {
|
||||
testEditor(false, false);
|
||||
testEditor(false, true);
|
||||
testEditor(true, false);
|
||||
testEditor(true, true);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testEditor(setAllowInteraction, setMailMask) {
|
||||
var desc = " with " + (setAllowInteraction ? "" : "no ") +
|
||||
"eEditorAllowInteraction and " +
|
||||
(setMailMask ? "" : "no ") + "eEditorMailMask";
|
||||
|
||||
var editorElem = document.getElementById("editor");
|
||||
|
||||
var editorObj = editorElem.getEditor(editorElem.contentWindow);
|
||||
editorObj.flags = (setAllowInteraction ? kAllowInteraction : 0) |
|
||||
(setMailMask ? kMailMask : 0);
|
||||
|
||||
var editorDoc = editorElem.contentDocument;
|
||||
editorDoc.body.innerHTML = "<p>foo<p>bar";
|
||||
editorDoc.getSelection().selectAllChildren(editorDoc.body.firstChild);
|
||||
editorDoc.execCommand("bold");
|
||||
|
||||
var createsDirty = !setAllowInteraction || setMailMask;
|
||||
|
||||
(createsDirty ? isnot : is)(editorDoc.querySelector("[_moz_dirty]"), null,
|
||||
"Elements with _moz_dirty" + desc);
|
||||
|
||||
// Even if we do create _moz_dirty, we should strip it for innerHTML.
|
||||
is(editorDoc.body.innerHTML, "<p><b>foo</b></p><p>bar</p>",
|
||||
"innerHTML" + desc);
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче