From e610840d16544545196f46c427bfa4973038ddc8 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Mon, 16 Aug 2010 14:48:32 -0700 Subject: [PATCH] bug 582644 - IME event remoting, patch for android r=blassey blocking-fennec=2.0a1+ --- dom/ipc/TabParent.cpp | 25 ++++++++++++++++++++ widget/public/nsGUIEvent.h | 14 +++++++++++ widget/src/android/AndroidBridge.cpp | 11 ++++++++- widget/src/android/nsWindow.cpp | 35 +++++++++++----------------- 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 1a043626018..b3953390917 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -71,6 +71,11 @@ #include "nsIContent.h" #include "mozilla/unused.h" +#ifdef ANDROID +#include "AndroidBridge.h" +using namespace mozilla; +#endif + using mozilla::ipc::DocumentRendererParent; using mozilla::ipc::DocumentRendererShmemParent; using mozilla::ipc::DocumentRendererNativeIDParent; @@ -570,7 +575,27 @@ TabParent::RecvAsyncMessage(const nsString& aMessage, bool TabParent::RecvQueryContentResult(const nsQueryContentEvent& event) { +#ifdef ANDROID + if (!event.mSucceeded) { + AndroidBridge::Bridge()->ReturnIMEQueryResult(nsnull, 0, 0, 0); return true; + } + + switch (event.message) { + case NS_QUERY_TEXT_CONTENT: + AndroidBridge::Bridge()->ReturnIMEQueryResult( + event.mReply.mString.get(), event.mReply.mString.Length(), 0, 0); + break; + case NS_QUERY_SELECTED_TEXT: + AndroidBridge::Bridge()->ReturnIMEQueryResult( + event.mReply.mString.get(), + event.mReply.mString.Length(), + event.GetSelectionStart(), + event.GetSelectionEnd() - event.GetSelectionStart()); + break; + } +#endif + return true; } bool diff --git a/widget/public/nsGUIEvent.h b/widget/public/nsGUIEvent.h index 48ed9c2d43b..9cd985ec6a7 100644 --- a/widget/public/nsGUIEvent.h +++ b/widget/public/nsGUIEvent.h @@ -1261,6 +1261,20 @@ public: mInput.mLength = aLength; } + PRUint32 GetSelectionStart(void) const + { + NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT, + "not querying selection"); + return mReply.mOffset + (mReply.mReversed ? mReply.mString.Length() : 0); + } + + PRUint32 GetSelectionEnd(void) const + { + NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT, + "not querying selection"); + return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length()); + } + PRBool mSucceeded; PRPackedBool mWasAsync; struct { diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index 9e68c60531c..02fe3664318 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -37,7 +37,10 @@ #include +#ifdef MOZ_IPC #include "mozilla/dom/ContentChild.h" +#include "nsXULAppAPI.h" +#endif #include #include #include "nsXPCOMStrings.h" @@ -192,8 +195,12 @@ AndroidBridge::NotifyIME(int aType, int aState) if (sBridge) JNI()->CallStaticVoidMethod(sBridge->mGeckoAppShellClass, sBridge->jNotifyIME, aType, aState); - else +#ifdef MOZ_IPC + // It's possible that we are in chrome process + // but sBridge is not initialized yet + else if (XRE_GetProcessType() == GeckoProcessType_Content) mozilla::dom::ContentChild::GetSingleton()->SendNotifyIME(aType, aState); +#endif } void @@ -201,9 +208,11 @@ AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd) { if (!sBridge) { +#ifdef MOZ_IPC mozilla::dom::ContentChild::GetSingleton()-> SendNotifyIMEChange(nsAutoString(aText), aTextLen, aStart, aEnd, aNewEnd); +#endif return; } diff --git a/widget/src/android/nsWindow.cpp b/widget/src/android/nsWindow.cpp index dfadc9706ee..f37322266b8 100644 --- a/widget/src/android/nsWindow.cpp +++ b/widget/src/android/nsWindow.cpp @@ -1365,11 +1365,11 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae) AndroidBridge::Bridge()->ReturnIMEQueryResult( nsnull, 0, 0, 0); return; + } else if (!event.mWasAsync) { + AndroidBridge::Bridge()->ReturnIMEQueryResult( + event.mReply.mString.get(), + event.mReply.mString.Length(), 0, 0); } - - AndroidBridge::Bridge()->ReturnIMEQueryResult( - event.mReply.mString.get(), - event.mReply.mString.Length(), 0, 0); //ALOGIME("IME: -> l=%u", event.mReply.mString.Length()); } return; @@ -1411,21 +1411,13 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae) AndroidBridge::Bridge()->ReturnIMEQueryResult( nsnull, 0, 0, 0); return; + } else if (!event.mWasAsync) { + AndroidBridge::Bridge()->ReturnIMEQueryResult( + event.mReply.mString.get(), + event.mReply.mString.Length(), + event.GetSelectionStart(), + event.GetSelectionEnd() - event.GetSelectionStart()); } - - int selStart = int(event.mReply.mOffset + - (event.mReply.mReversed ? - event.mReply.mString.Length() : 0)); - - int selLength = event.mReply.mReversed ? - int(event.mReply.mString.Length()) : - -int(event.mReply.mString.Length()); - - AndroidBridge::Bridge()->ReturnIMEQueryResult( - event.mReply.mString.get(), - event.mReply.mString.Length(), - selStart, selLength); - //ALOGIME("IME: -> o=%u, l=%u", event.mReply.mOffset, event.mReply.mString.Length()); } return; @@ -1520,10 +1512,9 @@ NS_IMETHODIMP nsWindow::OnIMEFocusChange(PRBool aFocus) { ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus); - - if (AndroidBridge::Bridge()) - AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE, - int(aFocus)); + + AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE, + int(aFocus)); return NS_OK; }