Bug 740784 - Don't allow old bogus nodes to trail textarea content. r=ehsan a=lsblakk

This commit is contained in:
Graeme McCutcheon 2012-04-12 21:55:48 +01:00
Родитель 03a3c4d899
Коммит 1d61565fd6
4 изменённых файлов: 62 добавлений и 1 удалений

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

@ -1105,6 +1105,17 @@ nsTextEditRules::CreateTrailingBRIfNeeded()
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> unused;
res = CreateMozBR(body, rootLen, address_of(unused));
} else {
// Check to see if the trailing BR is a former bogus node - this will have stuck
// around if we previously morphed a trailing node into a bogus node
nsCOMPtr<nsIContent> lastBR = do_QueryInterface(lastChild);
if (!mEditor->IsMozEditorBogusNode(lastBR))
return NS_OK;
// Morph it back to a mozBR
dom::Element* elem = lastBR->AsElement();
elem->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
elem->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("_moz"), true);
}
return res;
}

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

@ -65,6 +65,7 @@ _TEST_FILES = \
test_bug645914.html \
test_bug681229.html \
test_bug692520.html \
test_bug740784.html \
test_dom_input_event_on_texteditor.html \
$(NULL)

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

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this file,
- You can obtain one at http://mozilla.org/MPL/2.0/. -->
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=740784
-->
<head>
<title>Test for Bug 740784</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body onload="doTest();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=740784">Mozilla Bug 740784</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 740784 **/
SimpleTest.waitForExplicitFinish();
function doTest() {
var t1 = $("t1");
t1.focus();
synthesizeKey("VK_END", {});
synthesizeKey("VK_BACK_SPACE", {});
synthesizeKey("Z", {accelKey: true});
// Was the former bogus node changed to a mozBR?
is(t1.value, "a", "trailing <br> correctly ignored");
SimpleTest.finish();
}
</script>
</pre>
<textarea id="t1" rows="2" columns="80">a</textarea>
</body>
</html>

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

@ -104,7 +104,7 @@ function runTests()
inputEvent = null;
synthesizeKey("z", { accelKey: true });
is(aElement.value, (aIsTextarea ? " \n" : " "), aDescription + "Accel+Z key didn't undo the value");
is(aElement.value, " ", aDescription + "Accel+Z key didn't undo the value");
ok(inputEvent, aDescription + "input event wasn't fired by Undo");
ok(inputEvent.isTrusted, aDescription + "input event by Undo wasn't trusted event");