Bug 923376 - Spellcheck all appended nodes, not just the first; r=ehsan

This commit is contained in:
Aryeh Gregor 2014-04-06 17:56:08 +03:00
parent 930a4eb7ae
commit 168b96deba
6 changed files with 88 additions and 3 deletions

View File

@ -3227,12 +3227,22 @@ nsHTMLEditor::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer,
nsIContent* aFirstNewContent,
int32_t aIndexInContainer)
{
ContentInserted(aDocument, aContainer, aFirstNewContent, aIndexInContainer);
DoContentInserted(aDocument, aContainer, aFirstNewContent, aIndexInContainer,
eAppended);
}
void
nsHTMLEditor::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer,
nsIContent* aChild, int32_t aIndexInContainer)
{
DoContentInserted(aDocument, aContainer, aChild, aIndexInContainer,
eInserted);
}
void
nsHTMLEditor::DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer,
nsIContent* aChild, int32_t aIndexInContainer,
InsertedOrAppended aInsertedOrAppended)
{
if (!aChild) {
return;
@ -3257,8 +3267,17 @@ nsHTMLEditor::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer,
// Update spellcheck for only the newly-inserted node (bug 743819)
if (mInlineSpellChecker) {
nsRefPtr<nsRange> range = new nsRange(aChild);
int32_t endIndex = aIndexInContainer + 1;
if (aInsertedOrAppended == eAppended) {
// Count all the appended nodes
nsIContent* sibling = aChild->GetNextSibling();
while (sibling) {
endIndex++;
sibling = sibling->GetNextSibling();
}
}
nsresult res = range->Set(aContainer, aIndexInContainer,
aContainer, aIndexInContainer + 1);
aContainer, endIndex);
if (NS_SUCCEEDED(res)) {
mInlineSpellChecker->SpellCheckRange(range);
}

View File

@ -950,7 +950,10 @@ private:
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue);
typedef enum { eInserted, eAppended } InsertedOrAppended;
void DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer,
nsIContent* aChild, int32_t aIndexInContainer,
InsertedOrAppended aInsertedOrAppended);
};
#endif //nsHTMLEditor_h__

View File

@ -0,0 +1,13 @@
<!doctype html>
<div contenteditable>something missspelled<br>something elsed#</div>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script>
var div = document.body.firstChild;
div.focus();
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm",
window);
onSpellCheck(div, function() {
div.blur();
parent.reportFinish();
});
</script>

View File

@ -0,0 +1,16 @@
<!doctype html>
<div contenteditable></div>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script>
var div = document.body.firstChild;
div.focus();
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm",
window);
onSpellCheck(div, function() {
div.innerHTML = 'something missspelled<br>something elsed#';
onSpellCheck(div, function() {
div.blur();
parent.reportFinish();
});
});
</script>

View File

@ -10,6 +10,8 @@ support-files =
file_bug674770-1.html
file_select_all_without_body.html
green.png
923376.html
923376-ref.html
[test_CF_HTML_clipboard.html]
[test_bug200416.html]
@ -94,6 +96,7 @@ skip-if = toolkit == 'android' || e10s
[test_bug796839.html]
[test_bug832025.html]
[test_bug857487.html]
[test_bug923376.html]
[test_bug966155.html]
skip-if = os != "win"
[test_bug966552.html]

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=923376 -->
<title>Test for Bug 923376</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=923376">Mozilla Bug 923376</a>
<script>
SimpleTest.waitForExplicitFinish();
var numFinished = 0;
window.reportFinish = function() {
numFinished++;
if (numFinished == 2) {
doTest();
}
}
function doTest() {
var test = document.querySelectorAll("iframe")[0].contentWindow;
var ref = document.querySelectorAll("iframe")[1].contentWindow;
assertSnapshots(snapshotWindow(test, false), snapshotWindow(ref, false),
true, "test", "ref");
SimpleTest.finish();
}
</script>
<iframe src="923376.html"></iframe>
<iframe src="923376-ref.html"></iframe>