Bug 1112212 - Implement dummy-key-events mode for Android; r=esawin
authorJim Chen <nchen@mozilla.com>
Tue, 16 Jun 2015 19:02:39 -0400
changeset 280034 0a03c1ef13d098287902a197db167b23577dcb14
parent 280033 860d548d92d0202485d68869f3ce3614becc1334
child 280035 8d802bb49f338f87e72117baa2f35d62dad736fe
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1112212
milestone41.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 1112212 - Implement dummy-key-events mode for Android; r=esawin
widget/android/nsWindow.cpp
widget/android/nsWindow.h
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1676,16 +1676,33 @@ nsWindow::RemoveIMEComposition()
 
     WidgetCompositionEvent compositionCommitEvent(true,
                                                   NS_COMPOSITION_COMMIT_AS_IS,
                                                   this);
     InitEvent(compositionCommitEvent, nullptr);
     DispatchEvent(&compositionCommitEvent);
 }
 
+/*
+ * Send dummy key events for pages that are unaware of input events,
+ * to provide web compatibility for pages that depend on key events.
+ * Our dummy key events have 0 as the keycode.
+ */
+void
+nsWindow::SendIMEDummyKeyEvents()
+{
+    WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
+    MOZ_ASSERT(downEvent.keyCode == 0);
+    DispatchEvent(&downEvent);
+
+    WidgetKeyboardEvent upEvent(true, NS_KEY_UP, this);
+    MOZ_ASSERT(upEvent.keyCode == 0);
+    DispatchEvent(&upEvent);
+}
+
 void
 nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
 {
     MOZ_ASSERT(!mIMEMaskSelectionUpdate);
     /*
         Rules for managing IME between Gecko and Java:
 
         * Gecko controls the text content, and Java shadows the Gecko text
@@ -1834,16 +1851,20 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *
             // Don't end composition when composing text.
             if (ae->Action() != AndroidGeckoEvent::IME_COMPOSE_TEXT) {
                 WidgetCompositionEvent compositionCommitEvent(
                         true, NS_COMPOSITION_COMMIT_AS_IS, this);
                 InitEvent(compositionCommitEvent, nullptr);
                 DispatchEvent(&compositionCommitEvent);
             }
 
+            if (mInputContext.mMayBeIMEUnaware) {
+                SendIMEDummyKeyEvents();
+            }
+
             FlushIMEChanges();
             GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_REPLY_EVENT);
         }
         break;
 
     case AndroidGeckoEvent::IME_SET_SELECTION:
         {
             /*
@@ -2082,18 +2103,16 @@ nsWindow::SetInputContext(const InputCon
         top->SetInputContext(aContext, aAction);
         return;
     }
 
     ALOGIME("IME: SetInputContext: s=0x%X, 0x%X, action=0x%X, 0x%X",
             aContext.mIMEState.mEnabled, aContext.mIMEState.mOpen,
             aAction.mCause, aAction.mFocusChange);
 
-    mInputContext = aContext;
-
     // Ensure that opening the virtual keyboard is allowed for this specific
     // InputContext depending on the content.ime.strict.policy pref
     if (aContext.mIMEState.mEnabled != IMEState::DISABLED && 
         aContext.mIMEState.mEnabled != IMEState::PLUGIN &&
         Preferences::GetBool("content.ime.strict_policy", false) &&
         !aAction.ContentGotFocusByTrustedCause() &&
         !aAction.UserMightRequestOpenVKB()) {
         return;
@@ -2103,16 +2122,17 @@ nsWindow::SetInputContext(const InputCon
 
     // Only show the virtual keyboard for plugins if mOpen is set appropriately.
     // This avoids showing it whenever a plugin is focused. Bug 747492
     if (aContext.mIMEState.mEnabled == IMEState::PLUGIN &&
         aContext.mIMEState.mOpen != IMEState::OPEN) {
         enabled = IMEState::DISABLED;
     }
 
+    mInputContext = aContext;
     mInputContext.mIMEState.mEnabled = enabled;
 
     if (enabled == IMEState::ENABLED && aAction.UserMightRequestOpenVKB()) {
         // Don't reset keyboard when we should simply open the vkb
         GeckoAppShell::NotifyIME(AndroidBridge::NOTIFY_IME_OPEN_VKB);
         return;
     }
 
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -195,16 +195,17 @@ protected:
         bool IsEmpty() const
         {
             return mStart < 0;
         }
     };
 
     nsRefPtr<mozilla::TextComposition> GetIMEComposition();
     void RemoveIMEComposition();
+    void SendIMEDummyKeyEvents();
     void AddIMETextChange(const IMEChange& aChange);
     void PostFlushIMEChanges();
     void FlushIMEChanges();
 
     void ConfigureAPZCTreeManager() override;
     void ConfigureAPZControllerThread() override;
 
     already_AddRefed<GeckoContentController> CreateRootContentController() override;