Bug 917322 part.21 Ensure to cancel composition when TextInputProcessor is released r=smaug

This commit is contained in:
Masayuki Nakano 2015-01-28 15:27:33 +09:00
parent 59ab646b5e
commit 99c3b62e28
3 changed files with 45 additions and 2 deletions

View File

@ -65,6 +65,16 @@ TextInputProcessor::TextInputProcessor()
TextInputProcessor::~TextInputProcessor()
{
if (mDispatcher && mDispatcher->IsComposing()) {
// If this is composing and not canceling the composition, nobody can steal
// the rights of TextEventDispatcher from this instance. Therefore, this
// needs to cancel the composition here.
if (NS_SUCCEEDED(IsValidStateForComposition())) {
nsRefPtr<TextEventDispatcher> kungFuDeathGrip(mDispatcher);
nsEventStatus status = nsEventStatus_eIgnore;
mDispatcher->CommitComposition(status, &EmptyString());
}
}
}
NS_IMETHODIMP

View File

@ -34,9 +34,10 @@ public:
NS_IMETHOD_(void)
OnRemovedFrom(TextEventDispatcher* aTextEventDispatcher) MOZ_OVERRIDE;
private:
~TextInputProcessor();
protected:
virtual ~TextInputProcessor();
private:
nsresult InitInternal(nsIDOMWindow* aWindow,
nsITextInputProcessorCallback* aCallback,
bool aForTests,

View File

@ -250,6 +250,37 @@ function runInitMethodTests()
}
}
function runReleaseTests()
{
var description = "runReleaseTests(): ";
var TIP = createTIP();
ok(TIP.initForTests(window),
description + "TIP.initForTests() should succeed");
input.value = "";
input.focus();
TIP.setPendingCompositionString("foo");
TIP.appendClauseToPendingComposition(3, TIP.ATTR_RAW_CLAUSE);
TIP.setCaretInPendingComposition(3);
TIP.flushPendingComposition();
is(input.value, "foo",
description + "the input should have composition string");
// Release the TIP
TIP = null;
// Needs to run GC forcibly for testing this.
SpecialPowers.gc();
is(input.value, "",
description + "the input should be empty because the composition should be canceled");
TIP = createTIP();
ok(TIP.initForTests(window),
description + "TIP.initForTests() should succeed #2");
}
function runCompositionTests()
{
var description = "runCompositionTests(): ";
@ -988,6 +1019,7 @@ function runTests()
textareaInFrame = iframe.contentDocument.getElementById("textarea");
runInitMethodTests();
runReleaseTests();
runCompositionTests();
runErrorTests();
runCommitCompositionTests();