Bug 931378 Set input purpose to IM context r=karlt
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 28 Jan 2014 18:02:08 +0900
changeset 181598 277e7626551fd7aae037712e1215c5eeae2cd141
parent 181597 0c3b24383c8c02cac818649a02522ee4e339ed68
child 181599 64bf5ddbf7544a3a58912921486d4da75d100e13
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs931378
milestone29.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 931378 Set input purpose to IM context r=karlt
widget/gtk/compat/gtk/gtkenums.h
widget/gtk/nsGtkIMModule.cpp
new file mode 100644
--- /dev/null
+++ b/widget/gtk/compat/gtk/gtkenums.h
@@ -0,0 +1,28 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GTKENUMS_WRAPPER_H
+#define GTKENUMS_WRAPPER_H
+
+#include_next <gtk/gtkenums.h>
+
+#include <gtk/gtkversion.h>
+
+#if !GTK_CHECK_VERSION(3, 6, 0)
+enum GtkInputPurpose
+{
+    GTK_INPUT_PURPOSE_FREE_FORM,
+    GTK_INPUT_PURPOSE_ALPHA,
+    GTK_INPUT_PURPOSE_DIGITS,
+    GTK_INPUT_PURPOSE_NUMBER,
+    GTK_INPUT_PURPOSE_PHONE,
+    GTK_INPUT_PURPOSE_URL,
+    GTK_INPUT_PURPOSE_EMAIL,
+    GTK_INPUT_PURPOSE_NAME,
+    GTK_INPUT_PURPOSE_PASSWORD,
+    GTK_INPUT_PURPOSE_PIN
+};
+#endif // 3.6.0
+
+#endif /* GTKENUMS_WRAPPER_H */
--- a/widget/gtk/nsGtkIMModule.cpp
+++ b/widget/gtk/nsGtkIMModule.cpp
@@ -544,32 +544,60 @@ nsGtkIMModule::SetInputContext(nsWindow*
     if (sLastFocusedModule != this) {
         mInputContext = *aContext;
         PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
             ("    SUCCEEDED, but we're not active"));
         return;
     }
 
     bool changingEnabledState =
-        aContext->mIMEState.mEnabled != mInputContext.mIMEState.mEnabled;
+        aContext->mIMEState.mEnabled != mInputContext.mIMEState.mEnabled ||
+        aContext->mHTMLInputType != mInputContext.mHTMLInputType;
 
     // Release current IME focus if IME is enabled.
     if (changingEnabledState && IsEditable()) {
         CommitIMEComposition(mLastFocusedWindow);
         Blur();
     }
 
     mInputContext = *aContext;
 
-    // Even when aState is not enabled state, we need to set IME focus.
-    // Because some IMs are updating the status bar of them at this time.
-    // Be aware, don't use aWindow here because this method shouldn't move
-    // focus actually.
     if (changingEnabledState) {
+#if (MOZ_WIDGET_GTK == 3)
+        static bool sInputPurposeSupported = !gtk_check_version(3, 6, 0);
+        if (sInputPurposeSupported && IsEditable()) {
+            GtkIMContext* context = GetContext();
+            if (context) {
+                GtkInputPurpose purpose = GTK_INPUT_PURPOSE_FREE_FORM;
+                const nsString& inputType = mInputContext.mHTMLInputType;
+                if (inputType.EqualsLiteral("password")) {
+                    purpose = GTK_INPUT_PURPOSE_PASSWORD;
+                } else if (inputType.EqualsLiteral("email")) {
+                    purpose = GTK_INPUT_PURPOSE_EMAIL;
+                } else if (inputType.EqualsLiteral("url")) {
+                    purpose = GTK_INPUT_PURPOSE_URL;
+                } else if (inputType.EqualsLiteral("tel")) {
+                    purpose = GTK_INPUT_PURPOSE_PHONE;
+                } else if (inputType.EqualsLiteral("number")) {
+                    purpose = GTK_INPUT_PURPOSE_NUMBER;
+                }
+
+                g_object_set(context, "input-purpose", purpose, nullptr);
+            }
+        }
+#endif // #if (MOZ_WIDGET_GTK == 3)
+
+        // Even when aState is not enabled state, we need to set IME focus.
+        // Because some IMs are updating the status bar of them at this time.
+        // Be aware, don't use aWindow here because this method shouldn't move
+        // focus actually.
         Focus();
+
+        // XXX Should we call Blur() when it's not editable?  E.g., it might be
+        //     better to close VKB automatically.
     }
 }
 
 InputContext
 nsGtkIMModule::GetInputContext()
 {
     mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
     return mInputContext;