Bug 707353 - Implement ANPWindow::showKeyboard() for Android plugins. r=snorp a=blocking-fennec
authorJames Willcox <jwillcox@mozilla.com>
Fri, 20 Apr 2012 09:49:50 -0700
changeset 92044 b0eac121f6196cd3327018f929a440e300a7e1cf
parent 92043 f1d0e75d425aae16eede355eaf00996c1d698d65
child 92045 566721f5c440f395cda6a78c444f374cad568517
push id22498
push userphilringnalda@gmail.com
push dateSat, 21 Apr 2012 02:58:04 +0000
treeherdermozilla-central@bce6cabacc88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, blocking-fennec
bugs707353
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 707353 - Implement ANPWindow::showKeyboard() for Android plugins. r=snorp a=blocking-fennec
dom/plugins/base/android/ANPWindow.cpp
dom/plugins/base/android/Makefile.in
mobile/android/base/GeckoInputConnection.java
widget/android/nsWindow.cpp
widget/android/nsWindow.h
--- a/dom/plugins/base/android/ANPWindow.cpp
+++ b/dom/plugins/base/android/ANPWindow.cpp
@@ -38,38 +38,55 @@
 
 #include "assert.h"
 #include "ANPBase.h"
 #include <android/log.h>
 #include "AndroidBridge.h"
 #include "nsNPAPIPluginInstance.h"
 #include "nsIPluginInstanceOwner.h"
 #include "nsPluginInstanceOwner.h"
+#include "nsWindow.h"
 
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
 #define ASSIGN(obj, name)   (obj)->name = anp_window_##name
 
 using namespace mozilla;
+using namespace mozilla::widget;
 
 void
 anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count)
 {
   NOT_IMPLEMENTED();
 }
 
 void
 anp_window_clearVisibleRects(NPP instance)
 {
   NOT_IMPLEMENTED();
 }
 
 void
 anp_window_showKeyboard(NPP instance, bool value)
 {
-  NOT_IMPLEMENTED();
+  InputContext context;
+  context.mIMEState.mEnabled = IMEState::PLUGIN;
+  context.mIMEState.mOpen = value ? IMEState::OPEN : IMEState::CLOSED;
+  context.mActionHint.Assign(EmptyString());
+
+  InputContextAction action;
+  action.mCause = InputContextAction::CAUSE_UNKNOWN;
+  action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
+
+  nsWindow* window = nsWindow::TopWindow();
+  if (!window) {
+    LOG("Couldn't get top window?");
+    return;
+  }
+
+  window->SetInputContext(context, action);
 }
 
 void
 anp_window_requestFullScreen(NPP instance)
 {
   NOT_IMPLEMENTED();
 }
 
--- a/dom/plugins/base/android/Makefile.in
+++ b/dom/plugins/base/android/Makefile.in
@@ -67,16 +67,17 @@ CPPSRCS += ANPAudio.cpp    \
            ANPNativeWindow.cpp \
            ANPSurface.cpp  \
            ANPVideo.cpp    \
            ANPOpenGL.cpp   \
            $(NULL)
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/widget/android \
+  -I$(topsrcdir)/widget/xpwidgets \
   -I$(topsrcdir)/dom/plugins/base \
   -I$(topsrcdir)/dom/plugins/base/android/include \
   -I$(topsrcdir)/gfx/gl \
   $(MOZ_CAIRO_CFLAGS) \
   $(NULL)
 
 DEFINES += -DMOZ_APP_NAME='"$(MOZ_APP_NAME)"'
 
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -1036,18 +1036,17 @@ public class GeckoInputConnection
                 return;
 
             if (mReset)
                 imm.restartInput(v);
 
             if (!mEnable)
                 return;
 
-            if (mIMEState != IME_STATE_DISABLED &&
-                mIMEState != IME_STATE_PLUGIN)
+            if (mIMEState != IME_STATE_DISABLED)
                 imm.showSoftInput(v, 0);
             else
                 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
         }
     }
 
     public void setEditable(String contents) {
         mEditable.removeSpan(this);
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -148,18 +148,18 @@ static bool sFailedToCreateGLContext = f
 static bool sValidSurface;
 static bool sSurfaceExists = false;
 static void *sNativeWindow = nsnull;
 
 // Multitouch swipe thresholds in inches
 static const double SWIPE_MAX_PINCH_DELTA_INCHES = 0.4;
 static const double SWIPE_MIN_DISTANCE_INCHES = 0.6;
 
-static nsWindow*
-TopWindow()
+nsWindow*
+nsWindow::TopWindow()
 {
     if (!gTopLevelWindows.IsEmpty())
         return gTopLevelWindows[0];
     return nsnull;
 }
 
 void
 nsWindow::LogWindow(nsWindow *win, int index, int indent)
@@ -329,17 +329,17 @@ nsWindow::SetParent(nsIWidget *aNewParen
         mParent->mChildren.RemoveElement(this);
 
     mParent = (nsWindow*)aNewParent;
 
     if (mParent)
         mParent->mChildren.AppendElement(this);
 
     // if we are now in the toplevel window's hierarchy, schedule a redraw
-    if (FindTopLevel() == TopWindow())
+    if (FindTopLevel() == nsWindow::TopWindow())
         RedrawAll();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::ReparentNativeWidget(nsIWidget *aNewParent)
 {
@@ -385,29 +385,29 @@ nsWindow::Show(bool aState)
         // to pretend that the top window always has focus.  Not sure
         // if Show() is the right place to do this, though.
 
         if (aState) {
             // It just became visible, so send a resize update if necessary
             // and bring it to the front.
             Resize(0, 0, gAndroidBounds.width, gAndroidBounds.height, false);
             BringToFront();
-        } else if (TopWindow() == this) {
+        } else if (nsWindow::TopWindow() == this) {
             // find the next visible window to show
             unsigned int i;
             for (i = 1; i < gTopLevelWindows.Length(); i++) {
                 nsWindow *win = gTopLevelWindows[i];
                 if (!win->mIsVisible)
                     continue;
 
                 win->BringToFront();
                 break;
             }
         }
-    } else if (FindTopLevel() == TopWindow()) {
+    } else if (FindTopLevel() == nsWindow::TopWindow()) {
         RedrawAll();
     }
 
 #ifdef DEBUG_ANDROID_WIDGET
     DumpWindows();
 #endif
 
     return NS_OK;
@@ -485,17 +485,17 @@ nsWindow::Resize(PRInt32 aX,
     mBounds.y = aY;
     mBounds.width = aWidth;
     mBounds.height = aHeight;
 
     if (needSizeDispatch)
         OnSizeChanged(gfxIntSize(aWidth, aHeight));
 
     // Should we skip honoring aRepaint here?
-    if (aRepaint && FindTopLevel() == TopWindow())
+    if (aRepaint && FindTopLevel() == nsWindow::TopWindow())
         RedrawAll();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::SetZIndex(PRInt32 aZIndex)
 {
@@ -584,17 +584,17 @@ nsWindow::BringToFront()
 {
     // If the window to be raised is the same as the currently raised one,
     // do nothing. We need to check the focus manager as well, as the first
     // window that is created will be first in the window list but won't yet
     // be focused.
     nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
     nsCOMPtr<nsIDOMWindow> existingTopWindow;
     fm->GetActiveWindow(getter_AddRefs(existingTopWindow));
-    if (existingTopWindow && FindTopLevel() == TopWindow())
+    if (existingTopWindow && FindTopLevel() == nsWindow::TopWindow())
         return;
 
     if (!IsTopLevel()) {
         FindTopLevel()->BringToFront();
         return;
     }
 
     nsRefPtr<nsWindow> kungFuDeathGrip(this);
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -71,16 +71,17 @@ public:
 
     nsWindow();
     virtual ~nsWindow();
 
     NS_DECL_ISUPPORTS_INHERITED
 
     static void OnGlobalAndroidEvent(mozilla::AndroidGeckoEvent *ae);
     static gfxIntSize GetAndroidScreenBounds();
+    static nsWindow* TopWindow();
 
     nsWindow* FindWindowForPoint(const nsIntPoint& pt);
 
     void OnAndroidEvent(mozilla::AndroidGeckoEvent *ae);
     void OnDraw(mozilla::AndroidGeckoEvent *ae);
     bool OnMultitouchEvent(mozilla::AndroidGeckoEvent *ae);
     void OnGestureEvent(mozilla::AndroidGeckoEvent *ae);
     void OnMotionEvent(mozilla::AndroidGeckoEvent *ae);