Bug 622247 Remove hack for bug 23558 and bug 271815, and add tests for them r=ehsan

This commit is contained in:
Masayuki Nakano 2012-02-15 10:38:07 +09:00
Родитель 872bbcb297
Коммит f276ee1b9f
2 изменённых файлов: 285 добавлений и 35 удалений

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

@ -958,10 +958,7 @@ nsresult
nsPlaintextEditor::UpdateIMEComposition(const nsAString& aCompositionString,
nsIPrivateTextRangeList* aTextRangeList)
{
if (!aTextRangeList && !aCompositionString.IsEmpty()) {
NS_ERROR("aTextRangeList is null but the composition string is not null");
return NS_ERROR_NULL_POINTER;
}
NS_ABORT_IF_FALSE(aTextRangeList, "aTextRangeList must not be NULL");
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@ -972,29 +969,16 @@ nsPlaintextEditor::UpdateIMEComposition(const nsAString& aCompositionString,
nsRefPtr<nsCaret> caretP = ps->GetCaret();
// We should return caret position if it is possible. Because this event
// dispatcher always expects to be returned the correct caret position.
// But in following cases, we don't need to process the composition string,
// so, we only need to return the caret position.
// Update information of clauses in the new composition string.
// This will be refered by followed methods.
mIMETextRangeList = aTextRangeList;
// aCompositionString.IsEmpty() && !mIMETextNode:
// Workaround for Windows IME bug 23558: We get every IME event twice.
// For escape keypress, this causes an empty string to be passed
// twice, which freaks out the editor.
// aCompositionString.IsEmpty() && !aTextRangeList:
// Some Chinese IMEs for Linux are always composition string and text range
// list are empty when listing the Chinese characters. In this case,
// we don't need to process composition string too. See bug 271815.
bool notifyEditorObservers = false;
if (!aCompositionString.IsEmpty() || (mIMETextNode && aTextRangeList)) {
mIMETextRangeList = aTextRangeList;
// We set mIsIMEComposing properly.
SetIsIMEComposing();
{
nsAutoPlaceHolderBatch batch(this, nsGkAtoms::IMETxnName);
SetIsIMEComposing(); // We set mIsIMEComposing properly.
rv = InsertText(aCompositionString);
mIMEBufferLength = aCompositionString.Length();
@ -1002,20 +986,13 @@ nsPlaintextEditor::UpdateIMEComposition(const nsAString& aCompositionString,
if (caretP) {
caretP->SetCaretDOMSelection(selection);
}
// second part of 23558 fix:
if (aCompositionString.IsEmpty()) {
mIMETextNode = nsnull;
}
// If still composing, we should fire input event via observer.
// Note that if committed, we don't need to notify it since it will be
// notified at followed compositionend event.
// NOTE: We must notify after the auto batch will be gone.
notifyEditorObservers = mIsIMEComposing;
}
if (notifyEditorObservers) {
// If still composing, we should fire input event via observer.
// Note that if committed, we don't need to notify it since it will be
// notified at followed compositionend event.
// NOTE: We must notify after the auto batch will be gone.
if (mIsIMEComposing) {
NotifyEditorObservers();
}

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

@ -1199,6 +1199,279 @@ function runCompositionTest()
!checkSelection(4, "", "runCompositionTest", "#3-5")) {
return;
}
// bug 271815, some Chinese IMEs for Linux make empty composition string
// and compty clause information when it lists up Chinese characters on
// its candidate window.
synthesizeComposition({ type: "compositionstart" });
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#4-1") ||
!checkSelection(4, "", "runCompositionTest", "#4-1")) {
return;
}
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#4-2") ||
!checkSelection(4, "", "runCompositionTest", "#4-2")) {
return;
}
synthesizeComposition({ type: "compositionupdate", data: "\u6700" });
synthesizeText(
{ "composition":
{ "string": "\u6700",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-3") ||
!checkSelection(5, "", "runCompositionTest", "#4-3")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u6700" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-4") ||
!checkSelection(5, "", "runCompositionTest", "#4-4")) {
return;
}
// testing the canceling case
synthesizeComposition({ type: "compositionstart" });
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-5") ||
!checkSelection(5, "", "runCompositionTest", "#4-5")) {
return;
}
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-6") ||
!checkSelection(5, "", "runCompositionTest", "#4-6")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u6700" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#4-7") ||
!checkSelection(5, "", "runCompositionTest", "#4-7")) {
return;
}
// testing whether the empty composition string deletes selected string.
synthesizeKey("VK_LEFT", { shiftKey: true });
synthesizeComposition({ type: "compositionstart" });
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#4-8") ||
!checkSelection(4, "", "runCompositionTest", "#4-8")) {
return;
}
synthesizeComposition({ type: "compositionupdate", data: "\u9AD8" });
synthesizeText(
{ "composition":
{ "string": "\u9AD8",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 1, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u9AD8",
"runCompositionTest", "#4-9") ||
!checkSelection(5, "", "runCompositionTest", "#4-9")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u9AD8" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u9AD8",
"runCompositionTest", "#4-10") ||
!checkSelection(5, "", "runCompositionTest", "#4-10")) {
return;
}
synthesizeKey("VK_BACK_SPACE", {});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#4-11") ||
!checkSelection(4, "", "runCompositionTest", "#4-11")) {
return;
}
// bug 23558, ancient Japanese IMEs on Window may send empty text event
// twice at canceling composition.
synthesizeComposition({ type: "compositionstart" });
synthesizeComposition({ type: "compositionupdate", data: "\u6700" });
synthesizeText(
{ "composition":
{ "string": "\u6700",
"clauses":
[
{ "length": 1, "attr": nsIDOMWindowUtils.COMPOSITION_ATTR_RAWINPUT }
]
},
"caret": { "start": 1, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#5-1") ||
!checkSelection(4 + 1, "", "runCompositionTest", "#5-1")) {
return;
}
synthesizeComposition({ type: "compositionupdate", data: "" });
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#5-2") ||
!checkSelection(4, "", "runCompositionTest", "#5-2")) {
return;
}
synthesizeText(
{ "composition":
{ "string": "",
"clauses":
[
{ "length": 0, "attr": 0 }
]
},
"caret": { "start": 0, "length": 0 }
});
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#5-3") ||
!checkSelection(4, "", "runCompositionTest", "#5-3")) {
return;
}
synthesizeComposition({ type: "compositionend", data: "\u9AD8" });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#5-4") ||
!checkSelection(4, "", "runCompositionTest", "#5-4")) {
return;
}
// Undo tests for the testcases for bug 23558 and bug 271815
synthesizeKey("Z", { accelKey: true });
// XXX this is unexpected behavior, see bug 258291
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#6-1") ||
!checkSelection(4, "", "runCompositionTest", "#6-1")) {
return;
}
synthesizeKey("Z", { accelKey: true });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u9AD8",
"runCompositionTest", "#6-2") ||
!checkSelection(5, "", "runCompositionTest", "#6-2")) {
return;
}
synthesizeKey("Z", { accelKey: true });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#6-3") ||
!checkSelection(4, "\u6700", "runCompositionTest", "#6-3")) {
return;
}
synthesizeKey("Z", { accelKey: true });
// XXX this is unexpected behavior, see bug 258291
if (!checkContent("\u30E9\u30FC\u30E1\u30F3\u6700",
"runCompositionTest", "#6-4") ||
!checkSelection(5, "", "runCompositionTest", "#6-4")) {
return;
}
synthesizeKey("Z", { accelKey: true });
if (!checkContent("\u30E9\u30FC\u30E1\u30F3",
"runCompositionTest", "#6-5") ||
!checkSelection(4, "", "runCompositionTest", "#6-5")) {
return;
}
}
function runCompositionEventTest()