Bug 587461 - Don't split out of ancestors in insertHTML r=ehsan

This commit is contained in:
Aryeh Gregor 2013-04-04 17:27:41 +03:00
parent 18e123ea19
commit 49adbae7e2
5 changed files with 37 additions and 14 deletions

View File

@ -226,7 +226,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString,
{
return DoInsertHTMLWithContext(aInputString, aContextStr, aInfoStr,
aFlavor, aSourceDoc, aDestNode, aDestOffset, aDeleteSelection,
true);
/* trusted input */ true, /* clear style */ false);
}
nsresult
@ -238,7 +238,8 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
nsIDOMNode *aDestNode,
int32_t aDestOffset,
bool aDeleteSelection,
bool aTrustedInput)
bool aTrustedInput,
bool aClearStyle)
{
NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
@ -366,12 +367,14 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
rv = DeleteSelectionAndPrepareToCreateNode();
NS_ENSURE_SUCCESS(rv, rv);
// pasting does not inherit local inline styles
nsCOMPtr<nsIDOMNode> tmpNode =
do_QueryInterface(selection->GetAnchorNode());
int32_t tmpOffset = selection->GetAnchorOffset();
rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
if (aClearStyle) {
// pasting does not inherit local inline styles
nsCOMPtr<nsIDOMNode> tmpNode =
do_QueryInterface(selection->GetAnchorNode());
int32_t tmpOffset = selection->GetAnchorOffset();
rv = ClearStyle(address_of(tmpNode), &tmpOffset, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
}
}
else
{

View File

@ -726,6 +726,9 @@ protected:
// if it's coming from a transferable object), in which case aTrustedInput should
// be set to false, otherwise, the caller should set it to true, which means that
// the HTML will be inserted in the DOM verbatim.
//
// aClearStyle should be set to false if you want the paste to be affected by
// local style (e.g., for the insertHTML command).
nsresult DoInsertHTMLWithContext(const nsAString& aInputString,
const nsAString& aContextStr,
const nsAString& aInfoStr,
@ -734,7 +737,8 @@ protected:
nsIDOMNode* aDestNode,
int32_t aDestOffset,
bool aDeleteSelection,
bool aTrustedInput);
bool aTrustedInput,
bool aClearStyle = true);
nsresult ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
nsIAtom* aProperty, const nsAString* aAttribute);

View File

@ -47,6 +47,7 @@ MOCHITEST_FILES = \
test_bug552782.html \
test_bug570144.html \
test_bug578771.html \
test_bug587461.html \
test_bug592592.html \
test_bug597784.html \
test_bug599322.html \

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=587461
-->
<title>Test for Bug 587461</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=587461">Mozilla Bug 587461</a>
<div contenteditable><b>foobar</b></div>
<script>
var div = document.querySelector("div");
getSelection().collapse(div.firstChild.firstChild, 3);
document.execCommand("inserthtml", false, "a");
is(div.innerHTML, "<b>fooabar</b>", "innerHTML");
</script>

View File

@ -23,11 +23,10 @@ addLoadEvent(function() {
document.designMode = "on";
var content = document.getElementById("content");
getSelection().collapse(content, 0);
var html1 = "<test:tag>test:tag</test:tag>";
var html2 = "<a href=\"http://mozilla.org/\" test:attr=\"test:attr\" custom=\"value\">link</a>";
document.execCommand("insertHTML", false, html1);
document.execCommand("insertHTML", false, html2);
is(content.innerHTML, html1 + html2,
var html = "<test:tag>test:tag</test:tag>" +
"<a href=\"http://mozilla.org/\" test:attr=\"test:attr\" custom=\"value\">link</a>";
document.execCommand("insertHTML", false, html);
is(content.innerHTML, html,
"The custom tags and attributes should be inserted into the document using the insertHTML command");
SimpleTest.finish();
});