Bug 975387 Notify TextComposition instance of that nsIMEStateManager stops managing it r=smaug, sec-a=abillings

This commit is contained in:
Masayuki Nakano 2014-02-25 15:59:28 +09:00
parent 9505201b3d
commit 7644ee9553
3 changed files with 21 additions and 0 deletions

View File

@ -35,6 +35,15 @@ TextComposition::TextComposition(nsPresContext* aPresContext,
{
}
void
TextComposition::Destroy()
{
mPresContext = nullptr;
mNode = nullptr;
// TODO: If the editor is still alive and this is held by it, we should tell
// this being destroyed for cleaning up the stuff.
}
bool
TextComposition::MatchesNativeContext(nsIWidget* aWidget) const
{
@ -53,6 +62,10 @@ TextComposition::DispatchEvent(WidgetGUIEvent* aEvent,
nsEventDispatcher::Dispatch(mNode, mPresContext,
aEvent, nullptr, aStatus, aCallBack);
if (!mPresContext) {
return;
}
// Emulate editor behavior of text event handler if no editor handles
// composition/text events.
if (aEvent->message == NS_TEXT_TEXT && !HasEditor()) {

View File

@ -45,6 +45,7 @@ public:
// WARNING: mPresContext may be destroying, so, be careful if you touch it.
}
bool Destroyed() const { return !mPresContext; }
nsPresContext* GetPresContext() const { return mPresContext; }
nsINode* GetEventTargetNode() const { return mNode; }
// The latest CompositionEvent.data value except compositionstart event.
@ -62,6 +63,11 @@ public:
bool MatchesNativeContext(nsIWidget* aWidget) const;
/**
* This is called when nsIMEStateManager stops managing the instance.
*/
void Destroy();
/**
* SynthesizeCommit() dispatches compositionupdate, text and compositionend
* events for emulating commit on the content.

View File

@ -117,6 +117,7 @@ nsIMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
sTextCompositions->IndexOf(aPresContext);
if (i != TextCompositionArray::NoIndex) {
// there should be only one composition per presContext object.
sTextCompositions->ElementAt(i)->Destroy();
sTextCompositions->RemoveElementAt(i);
MOZ_ASSERT(sTextCompositions->IndexOf(aPresContext) ==
TextCompositionArray::NoIndex);
@ -579,6 +580,7 @@ nsIMEStateManager::DispatchCompositionEvent(nsINode* aEventTargetNode,
TextCompositionArray::index_type i =
sTextCompositions->IndexOf(GUIEvent->widget);
if (i != TextCompositionArray::NoIndex) {
sTextCompositions->ElementAt(i)->Destroy();
sTextCompositions->RemoveElementAt(i);
}
}