bug 582644 - IME event remoting, patch for android r=blassey blocking-fennec=2.0a1+

This commit is contained in:
Jim Chen 2010-08-16 14:48:32 -07:00
parent a60ca48289
commit 3d4ef5adca
4 changed files with 62 additions and 23 deletions

View File

@ -71,6 +71,11 @@
#include "nsIContent.h" #include "nsIContent.h"
#include "mozilla/unused.h" #include "mozilla/unused.h"
#ifdef ANDROID
#include "AndroidBridge.h"
using namespace mozilla;
#endif
using mozilla::ipc::DocumentRendererParent; using mozilla::ipc::DocumentRendererParent;
using mozilla::ipc::DocumentRendererShmemParent; using mozilla::ipc::DocumentRendererShmemParent;
using mozilla::ipc::DocumentRendererNativeIDParent; using mozilla::ipc::DocumentRendererNativeIDParent;
@ -570,7 +575,27 @@ TabParent::RecvAsyncMessage(const nsString& aMessage,
bool bool
TabParent::RecvQueryContentResult(const nsQueryContentEvent& event) TabParent::RecvQueryContentResult(const nsQueryContentEvent& event)
{ {
#ifdef ANDROID
if (!event.mSucceeded) {
AndroidBridge::Bridge()->ReturnIMEQueryResult(nsnull, 0, 0, 0);
return true; 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 bool

View File

@ -1261,6 +1261,20 @@ public:
mInput.mLength = aLength; 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; PRBool mSucceeded;
PRPackedBool mWasAsync; PRPackedBool mWasAsync;
struct { struct {

View File

@ -37,7 +37,10 @@
#include <android/log.h> #include <android/log.h>
#ifdef MOZ_IPC
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
#include "nsXULAppAPI.h"
#endif
#include <pthread.h> #include <pthread.h>
#include <prthread.h> #include <prthread.h>
#include "nsXPCOMStrings.h" #include "nsXPCOMStrings.h"
@ -192,8 +195,12 @@ AndroidBridge::NotifyIME(int aType, int aState)
if (sBridge) if (sBridge)
JNI()->CallStaticVoidMethod(sBridge->mGeckoAppShellClass, JNI()->CallStaticVoidMethod(sBridge->mGeckoAppShellClass,
sBridge->jNotifyIME, aType, aState); 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); mozilla::dom::ContentChild::GetSingleton()->SendNotifyIME(aType, aState);
#endif
} }
void void
@ -201,9 +208,11 @@ AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen,
int aStart, int aEnd, int aNewEnd) int aStart, int aEnd, int aNewEnd)
{ {
if (!sBridge) { if (!sBridge) {
#ifdef MOZ_IPC
mozilla::dom::ContentChild::GetSingleton()-> mozilla::dom::ContentChild::GetSingleton()->
SendNotifyIMEChange(nsAutoString(aText), aTextLen, SendNotifyIMEChange(nsAutoString(aText), aTextLen,
aStart, aEnd, aNewEnd); aStart, aEnd, aNewEnd);
#endif
return; return;
} }

View File

@ -1365,11 +1365,11 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
AndroidBridge::Bridge()->ReturnIMEQueryResult( AndroidBridge::Bridge()->ReturnIMEQueryResult(
nsnull, 0, 0, 0); nsnull, 0, 0, 0);
return; 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()); //ALOGIME("IME: -> l=%u", event.mReply.mString.Length());
} }
return; return;
@ -1411,21 +1411,13 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
AndroidBridge::Bridge()->ReturnIMEQueryResult( AndroidBridge::Bridge()->ReturnIMEQueryResult(
nsnull, 0, 0, 0); nsnull, 0, 0, 0);
return; 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()); //ALOGIME("IME: -> o=%u, l=%u", event.mReply.mOffset, event.mReply.mString.Length());
} }
return; return;
@ -1520,10 +1512,9 @@ NS_IMETHODIMP
nsWindow::OnIMEFocusChange(PRBool aFocus) nsWindow::OnIMEFocusChange(PRBool aFocus)
{ {
ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus); ALOGIME("IME: OnIMEFocusChange: f=%d", aFocus);
if (AndroidBridge::Bridge()) AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE,
AndroidBridge::NotifyIME(AndroidBridge::NOTIFY_IME_FOCUSCHANGE, int(aFocus));
int(aFocus));
return NS_OK; return NS_OK;
} }