Skip to content

Commit

Permalink
Fixed properly IM context state reset on focus change, initialize nat…
Browse files Browse the repository at this point in the history
…iveContext ptr with null in order to avoid mess in IMEStateManager
  • Loading branch information
tmeshkova committed Jan 22, 2013
1 parent 5189a2d commit 2cbda16
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 58 deletions.
82 changes: 51 additions & 31 deletions embedding/embedlite/embedthread/EmbedLitePuppetWidget.cpp
Expand Up @@ -105,6 +105,7 @@ EmbedLitePuppetWidget::EmbedLitePuppetWidget(EmbedLiteViewThreadChild* aEmbed, u
: mEmbed(aEmbed)
, mVisible(false)
, mEnabled(false)
, mIMEComposing(false)
, mId(aId)
{
MOZ_COUNT_CTOR(EmbedLitePuppetWidget);
Expand Down Expand Up @@ -289,50 +290,35 @@ EmbedLitePuppetWidget::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)

NS_ABORT_IF_FALSE(listener, "No listener!");

#if 0
if (event->message == NS_COMPOSITION_START) {
mIMEComposing = true;
if (event->eventStructType == NS_KEY_EVENT) {
RemoveIMEComposition();
}
switch (event->eventStructType) {
case NS_COMPOSITION_EVENT:
mIMELastReceivedSeqno = static_cast<nsCompositionEvent*>(event)->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
case NS_TEXT_EVENT:
mIMELastReceivedSeqno = static_cast<nsTextEvent*>(event)->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
case NS_SELECTION_EVENT:
mIMELastReceivedSeqno = static_cast<nsSelectionEvent*>(event)->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
default:
break;
}
#endif

aStatus = listener->HandleEvent(event, mUseAttachedEvents);

#if 0
if (event->message == NS_COMPOSITION_END) {
mIMEComposing = false;
switch (event->message) {
case NS_COMPOSITION_START:
MOZ_ASSERT(!mIMEComposing);
mIMEComposing = true;
break;
case NS_COMPOSITION_END:
MOZ_ASSERT(mIMEComposing);
mIMEComposing = false;
mIMEComposingText.Truncate();
break;
case NS_TEXT_TEXT:
MOZ_ASSERT(mIMEComposing);
mIMEComposingText = static_cast<nsTextEvent*>(event)->theText;
break;
}
#endif

return NS_OK;
}

NS_IMETHODIMP
EmbedLitePuppetWidget::ResetInputState()
{
LOGNI();
#if 0
RemoveIMEComposition();
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_RESETINPUTSTATE, 0);
#endif
return NS_OK;
}

Expand Down Expand Up @@ -386,6 +372,40 @@ EmbedLitePuppetWidget::GetInputContext()
return mInputContext;
}

NS_IMETHODIMP EmbedLitePuppetWidget::OnIMEFocusChange(bool aFocus)
{
LOGF("aFocus:%i", aFocus);
if (!aFocus) {
mIMEComposing = false;
mIMEComposingText.Truncate();
}

return NS_OK;
}

void
EmbedLitePuppetWidget::RemoveIMEComposition()
{
// Remove composition on Gecko side
if (!mIMEComposing)
return;

if (mEmbed)
mEmbed->ResetInputState();

nsRefPtr<EmbedLitePuppetWidget> kungFuDeathGrip(this);

nsTextEvent textEvent(true, NS_TEXT_TEXT, this);
textEvent.time = PR_Now() / 1000;
textEvent.theText = mIMEComposingText;
nsEventStatus status;
DispatchEvent(&textEvent, status);

nsCompositionEvent event(true, NS_COMPOSITION_END, this);
event.time = PR_Now() / 1000;
DispatchEvent(&event, status);
}

LayerManager*
EmbedLitePuppetWidget::GetLayerManager(PLayersChild* aShadowManager,
LayersBackend aBackendHint,
Expand Down
7 changes: 6 additions & 1 deletion embedding/embedlite/embedthread/EmbedLitePuppetWidget.h
Expand Up @@ -55,7 +55,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget, public nsSupportsWeakReferenc

NS_IMETHOD Show(bool aState);
virtual bool IsVisible() const
{ LOGF(); return mVisible; }
{ return mVisible; }
NS_IMETHOD ConstrainPosition(bool /*ignored aAllowSlop*/,
int32_t* aX,
int32_t* aY)
Expand Down Expand Up @@ -101,6 +101,8 @@ class EmbedLitePuppetWidget : public nsBaseWidget, public nsSupportsWeakReferenc
const InputContextAction& aAction);
NS_IMETHOD_(InputContext) GetInputContext();

NS_IMETHOD OnIMEFocusChange(bool aFocus);

// This API is going away, steer clear.
virtual void Scroll(const nsIntPoint& aDelta,
const nsTArray<nsIntRect>& aDestRects,
Expand All @@ -125,12 +127,15 @@ class EmbedLitePuppetWidget : public nsBaseWidget, public nsSupportsWeakReferenc

EmbedLitePuppetWidget* TopWindow();
bool IsTopLevel();
void RemoveIMEComposition();

EmbedLiteViewThreadChild* mEmbed;

bool mVisible;
bool mEnabled;
InputContext mInputContext;
bool mIMEComposing;
nsString mIMEComposingText;
nsRefPtr<EmbedLitePuppetWidget> mChild;

uint32_t mId;
Expand Down
44 changes: 26 additions & 18 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp
Expand Up @@ -44,7 +44,7 @@ EmbedLiteViewThreadChild::EmbedLiteViewThreadChild(uint32_t aId)
, mDispatchSynthMouseEvents(true)
, mHadResizeSinceLastFrameUpdate(false)
, mModalDepth(0)
, mIsComposition(false)
, mIMEComposing(false)
{
LOGT();
AddRef();
Expand Down Expand Up @@ -345,15 +345,18 @@ EmbedLiteViewThreadChild::RecvHandleTextEvent(const nsString& commit, const nsSt
{
nsPoint offset;
nsCOMPtr<nsIWidget> widget = mHelper->GetWidget(&offset);
if (!widget)
const InputContext& ctx = mWidget->GetInputContext();

printf(">>>>>>Func:%s::%d ctx.mIMEState.mEnabled:%i, com:%s, pre:%s\n", __FUNCTION__, __LINE__, ctx.mIMEState.mEnabled, NS_ConvertUTF16toUTF8(commit).get(), NS_ConvertUTF16toUTF8(preEdit).get());
if (!widget || !ctx.mIMEState.mEnabled)
return false;

// probably logic here is over engineered, but clean enough
bool prevIsComposition = mIsComposition;
bool prevIsComposition = mIMEComposing;
bool StartComposite = !prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty();
bool UpdateComposite = prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty();
bool EndComposite = prevIsComposition && !commit.IsEmpty() && preEdit.IsEmpty();
mIsComposition = UpdateComposite || StartComposite;
mIMEComposing = UpdateComposite || StartComposite;
nsString pushStr = preEdit.IsEmpty() ? commit : preEdit;
if (!commit.IsEmpty() && !EndComposite) {
StartComposite = UpdateComposite = EndComposite = true;
Expand All @@ -363,37 +366,42 @@ EmbedLiteViewThreadChild::RecvHandleTextEvent(const nsString& commit, const nsSt
{
nsCompositionEvent event(true, NS_COMPOSITION_START, widget);
mHelper->InitEvent(event, nullptr);
event.data = pushStr;
mHelper->DispatchWidgetEvent(event);
}

if (StartComposite || UpdateComposite)
{
nsCompositionEvent event(true, NS_COMPOSITION_UPDATE, widget);
mHelper->InitEvent(event, nullptr);
mHelper->DispatchWidgetEvent(event);
}

if (StartComposite || UpdateComposite || EndComposite)
{
{
nsCompositionEvent event(true, NS_COMPOSITION_UPDATE, widget);
mHelper->InitEvent(event, nullptr);
event.data = pushStr;
mHelper->DispatchWidgetEvent(event);
}
{
nsTextEvent event(true, NS_TEXT_TEXT, widget);
mHelper->InitEvent(event, nullptr);
event.theText = pushStr;
mHelper->DispatchWidgetEvent(event);
}
nsTextEvent event(true, NS_TEXT_TEXT, widget);
mHelper->InitEvent(event, nullptr);
event.theText = pushStr;
mHelper->DispatchWidgetEvent(event);
}

if (EndComposite)
{
nsCompositionEvent event(true, NS_COMPOSITION_END, widget);
mHelper->InitEvent(event, nullptr);
event.data = pushStr;
mHelper->DispatchWidgetEvent(event);
}

return true;
}

void EmbedLiteViewThreadChild::ResetInputState()
{
if (!mIMEComposing)
return;

mIMEComposing = false;
}

bool
EmbedLiteViewThreadChild::RecvHandleKeyPressEvent(const int& domKeyCode, const int& gmodifiers, const int& charCode)
{
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h
Expand Up @@ -35,6 +35,7 @@ class EmbedLiteViewThreadChild : public PEmbedLiteViewChild,

void WaitForPromptResult(EmbedLiteViewPromptResponse*);
void PushPendingAuthRequest(EmbedAsyncAuthPrompt*);
void ResetInputState();

protected:
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
Expand Down Expand Up @@ -103,7 +104,7 @@ class EmbedLiteViewThreadChild : public PEmbedLiteViewChild,
bool mDispatchSynthMouseEvents;
bool mHadResizeSinceLastFrameUpdate;
int mModalDepth;
bool mIsComposition;
bool mIMEComposing;
std::map<uint64_t, EmbedLiteViewPromptResponse*> modalWinMap;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteViewThreadChild);
Expand Down
21 changes: 14 additions & 7 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadParent.cpp
Expand Up @@ -121,6 +121,7 @@ EmbedLiteViewThreadParent::EmbedLiteViewThreadParent(const uint32_t& id)
, mLastScale(1.0f)
, mInTouchProcess(false)
, mUILoop(MessageLoop::current())
, mIMEEnabled(false)
{
MOZ_COUNT_CTOR(EmbedLiteViewThreadParent);
LOGT("id:%u", mId);
Expand Down Expand Up @@ -616,9 +617,13 @@ EmbedLiteViewThreadParent::ReceiveInputEvent(const InputData& aEvent)
void
EmbedLiteViewThreadParent::TextEvent(const char* composite, const char* preEdit)
{
LOGT("commit:%s, pre:%s", composite, preEdit);
unused << SendHandleTextEvent(NS_ConvertUTF8toUTF16(nsDependentCString(composite)),
NS_ConvertUTF8toUTF16(nsDependentCString(preEdit)));
LOGT("commit:%s, pre:%s, mIMEEnabled:%i", composite, preEdit, mIMEEnabled);
if (mIMEEnabled) {
unused << SendHandleTextEvent(NS_ConvertUTF8toUTF16(nsDependentCString(composite)),
NS_ConvertUTF8toUTF16(nsDependentCString(preEdit)));
} else {
NS_ERROR("Text event must not be sent while IME disabled");
}
}

void
Expand Down Expand Up @@ -751,9 +756,10 @@ EmbedLiteViewThreadParent::RecvGetInputContext(int32_t* aIMEEnabled,
int32_t* aIMEOpen,
intptr_t* aNativeIMEContext)
{
LOGT();
*aIMEEnabled = IMEState::ENABLED;
LOGT("mIMEEnabled:%i", mIMEEnabled);
*aIMEEnabled = mIMEEnabled ? IMEState::ENABLED : IMEState::DISABLED;
*aIMEOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
*aNativeIMEContext = 0;
return true;
}

Expand All @@ -766,9 +772,10 @@ EmbedLiteViewThreadParent::RecvSetInputContext(const int32_t& aIMEEnabled,
const int32_t& aCause,
const int32_t& aFocusChange)
{
LOGT("IMEEnabled:%i, IMEOpen:%i, type:%s, imMode:%s, actHint:%s, cause:%i, focusChange:%i",
LOGT("IMEEnabled:%i, IMEOpen:%i, type:%s, imMode:%s, actHint:%s, cause:%i, focusChange:%i, mIMEEnabled:%i->%i",
aIMEEnabled, aIMEOpen, NS_ConvertUTF16toUTF8(aType).get(), NS_ConvertUTF16toUTF8(aInputmode).get(),
NS_ConvertUTF16toUTF8(aActionHint).get(), aCause, aFocusChange);
NS_ConvertUTF16toUTF8(aActionHint).get(), aCause, aFocusChange, mIMEEnabled, aIMEEnabled == IMEState::ENABLED ? true : false);
mIMEEnabled = aIMEEnabled == IMEState::ENABLED ? true : false;
mView->GetListener()->IMENotification(aIMEEnabled, aIMEOpen, aCause, aFocusChange);
return true;
}
Expand Down
Expand Up @@ -185,6 +185,7 @@ class EmbedLiteViewThreadParent : public PEmbedLiteViewParent,
gfxSize mViewSize;
bool mInTouchProcess;
MessageLoop* mUILoop;
bool mIMEEnabled;

DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteViewThreadParent);
};
Expand Down

0 comments on commit 2cbda16

Please sign in to comment.