File support-input-purpose.patch of Package mozc

Index: engine_interface.h
===================================================================
--- unix/ibus/engine_interface.h	(revision 177)
+++ unix/ibus/engine_interface.h	(working copy)
@@ -106,6 +106,11 @@
                                  gint y,
                                  gint w,
                                  gint h) = 0;
+
+  // The interface function for the "set-content-type" signal
+  virtual void SetContentType(IBusEngine *engine,
+                              guint purpose,
+                              guint hints) = 0;
 };
 
 }  // namespace ibus
Index: engine_registrar.cc
===================================================================
--- unix/ibus/engine_registrar.cc	(revision 177)
+++ unix/ibus/engine_registrar.cc	(working copy)
@@ -63,7 +63,9 @@
   engine_class->reset = Reset;
   engine_class->set_capabilities = SetCapabilities;
   engine_class->set_cursor_location = SetCursorLocation;
-
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+  engine_class->set_content_type = SetContentType;
+#endif  // MOZC_ENABLE_IBUS_INPUT_PURPOSE
   return true;
 }
 
@@ -87,6 +89,9 @@
   engine_class->reset = NULL;
   engine_class->set_capabilities = NULL;
   engine_class->set_cursor_location = NULL;
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+  engine_class->set_content_type = NULL;
+#endif  // MOZC_ENABLE_IBUS_INPUT_PURPOSE
 
   mozc::ibus::EngineInterface *previous = g_engine;
   g_engine = NULL;
@@ -179,5 +184,12 @@
   g_engine->SetCursorLocation(engine, x, y, w, h);
 }
 
+void EngineRegistrar::SetContentType(
+    IBusEngine *engine,
+    guint purpose,
+    guint hints) {
+  g_engine->SetContentType(engine, purpose, hints);
+}
+
 }  // namespace ibus
 }  // namespace mozc
Index: engine_registrar.h
===================================================================
--- unix/ibus/engine_registrar.h	(revision 177)
+++ unix/ibus/engine_registrar.h	(working copy)
@@ -84,6 +84,9 @@
                                 gint y,
                                 gint w,
                                 gint h);
+  static void SetContentType(IBusEngine *engine,
+                             guint purpose,
+                             guint hints);
 };
 
 }  // namespace ibus
Index: ibus_header.h
===================================================================
--- unix/ibus/ibus_header.h	(revision 177)
+++ unix/ibus/ibus_header.h	(working copy)
@@ -36,5 +36,10 @@
 #error "ibus-mozc now requires IBus>=1.4.1"
 #endif  // libibus (<1.4.1)
 
+#if IBUS_CHECK_VERSION(1, 5, 4)
+#if !defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+#define MOZC_ENABLE_IBUS_INPUT_PURPOSE
+#endif  // !MOZC_ENABLE_IBUS_INPUT_PURPOSE
+#endif  // libibus(>=1.5.4)
 
 #endif  // MOZC_UNIX_IBUS_IBUS_HEADER_H_
Index: mozc_engine.cc
===================================================================
--- unix/ibus/mozc_engine.cc	(revision 177)
+++ unix/ibus/mozc_engine.cc	(working copy)
@@ -372,6 +372,7 @@
 
 void MozcEngine::FocusOut(IBusEngine *engine) {
   GetCandidateWindowHandler(engine)->Hide(engine);
+  property_handler_->ResetContentType(engine);
 
   // Do not call SubmitSession or RevertSession. Preedit string will commit on
   // Focus Out event automatically by ibus_engine_update_preedit_text_with_mode
@@ -397,6 +398,11 @@
   VLOG(2) << "keyval: " << keyval
           << ", keycode: " << keycode
           << ", modifiers: " << modifiers;
+  if (property_handler_->IsDisabled()) {
+    // It is each enginze's responsibility for ignoreing keyevents on
+    // the password field on the locked screen since IBus 1.5.4.
+    return FALSE;
+  }
 
   // Send current caret location to mozc_server to manage suggest window
   // position.
@@ -501,6 +507,18 @@
   // Do nothing
 }
 
+void MozcEngine::SetContentType(IBusEngine *engine,
+                                guint purpose,
+                                guint hints) {
+  const bool prev_disabled =
+      property_handler_->IsDisabled();
+  property_handler_->UpdateContentType(engine);
+  if (!prev_disabled && property_handler_->IsDisabled()) {
+    // Make sure on-going composition is reverted.
+    RevertSession(engine);
+  }
+}
+
 GType MozcEngine::GetType() {
   static GType type = 0;
 
Index: mozc_engine.h
===================================================================
--- unix/ibus/mozc_engine.h	(revision 177)
+++ unix/ibus/mozc_engine.h	(working copy)
@@ -99,6 +99,9 @@
                          gint y,
                          gint w,
                          gint h);
+  void SetContentType(IBusEngine *engine,
+                      guint purpose,
+                      guint hints);
 
   // Returns the GType which this class represents.
   static GType GetType();
Index: property_handler.cc
===================================================================
--- unix/ibus/property_handler.cc	(revision 177)
+++ unix/ibus/property_handler.cc	(working copy)
@@ -61,6 +61,19 @@
 bool IsMozcToolAvailable() {
   return FileUtil::FileExists(SystemUtil::GetToolPath());
 }
+
+bool GetDisabled(IBusEngine *engine) {
+  bool disabled = false;
+#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
+  guint purpose = IBUS_INPUT_PURPOSE_FREE_FORM;
+  guint hints = IBUS_INPUT_HINT_NONE;
+  ibus_engine_get_content_type(engine, &purpose, &hints);
+  disabled = (purpose == IBUS_INPUT_PURPOSE_PASSWORD ||
+              purpose == IBUS_INPUT_PURPOSE_PIN);
+#endif  // MOZC_ENABLE_IBUS_INPUT_PURPOSE
+  return disabled;
+}
+
 }  // namespace
 
 PropertyHandler::PropertyHandler(MessageTranslatorInterface *translator,
@@ -71,7 +84,8 @@
       client_(client),
       translator_(translator),
       original_composition_mode_(kMozcEngineInitialCompositionMode),
-      is_activated_(true) {
+      is_activated_(true),
+      is_disabled_(false) {
 
   AppendCompositionPropertyToPanel();
 #ifndef OS_CHROMEOS
@@ -105,6 +119,7 @@
 
 void PropertyHandler::Register(IBusEngine *engine) {
   ibus_engine_register_properties(engine, prop_root_);
+  UpdateContentType(engine);
 }
 
 // TODO(nona): do not use kMozcEngine*** directory.
@@ -228,8 +243,34 @@
   ibus_prop_list_append(prop_root_, prop_mozc_tool_);
 }
 
+void PropertyHandler::UpdateContentTypeImpl(IBusEngine *engine,
+                                            bool disabled) {
+  const bool prev_is_disabled = is_disabled_;
+  is_disabled_ = disabled;
+  if (prev_is_disabled == is_disabled_) {
+    return;
+  }
+  const auto visible_mode = 
+      (prev_is_disabled && !is_disabled_ && IsActivated())
+          ? original_composition_mode_ : 
+            kMozcEnginePropertyIMEOffState->composition_mode;
+  UpdateCompositionModeIcon(engine, visible_mode);
+}
+
+void PropertyHandler::ResetContentType(IBusEngine *engine) {
+  UpdateContentTypeImpl(engine, false);
+}
+
+void PropertyHandler::UpdateContentType(IBusEngine *engine) {
+  UpdateContentTypeImpl(engine, GetDisabled(engine));
+}
+
 void PropertyHandler::Update(IBusEngine *engine,
                              const commands::Output &output) {
+  if (IsDisabled()) {
+    return;
+  }
+
   if (output.has_status() &&
       (output.status().activated() != is_activated_ ||
        output.status().mode() != original_composition_mode_)) {
@@ -325,6 +366,10 @@
                                               const gchar *property_name,
                                               guint property_state) {
 #ifndef OS_CHROMEOS
+  if (IsDisabled()) {
+    return;
+  }
+
   if (prop_mozc_tool_) {
     for (guint prop_index = 0; ; ++prop_index) {
       IBusProperty *prop = ibus_prop_list_get(
@@ -371,9 +416,13 @@
 }
 
 bool PropertyHandler::IsActivated() const {
-  return is_activated_;
+  return is_activated_ && !IsDisabled();
 }
 
+bool PropertyHandler::IsDisabled() const {
+  return is_disabled_;
+}
+
 commands::CompositionMode PropertyHandler::GetOriginalCompositionMode() const {
   return original_composition_mode_;
 }
Index: property_handler.h
===================================================================
--- unix/ibus/property_handler.h	(revision 177)
+++ unix/ibus/property_handler.h	(working copy)
@@ -54,14 +54,19 @@
   virtual ~PropertyHandler();
 
   virtual void Register(IBusEngine *engine);
+  virtual void ResetContentType(IBusEngine *engine);
+  virtual void UpdateContentType(IBusEngine *engine);
   virtual void Update(IBusEngine *engine, const commands::Output &output);
   virtual void ProcessPropertyActivate(IBusEngine *engine,
                                        const gchar *property_name,
                                        guint property_state);
   virtual bool IsActivated() const;
+  virtual bool IsDisabled() const;
   virtual commands::CompositionMode GetOriginalCompositionMode() const;
 
  private:
+  void UpdateContentTypeImpl(IBusEngine *engine, bool disabled);
+
   // Appends composition properties into panel
   void AppendCompositionPropertyToPanel();
   // Appends tool properties into panel
@@ -79,6 +84,7 @@
   scoped_ptr<MessageTranslatorInterface> translator_;
   commands::CompositionMode original_composition_mode_;
   bool is_activated_;
+  bool is_disabled_;
 };
 
 }  // namespace ibus
Index: property_handler_interface.h
===================================================================
--- unix/ibus/property_handler_interface.h	(revision 177)
+++ unix/ibus/property_handler_interface.h	(working copy)
@@ -45,6 +45,9 @@
   // Registers current properties into engine.
   virtual void Register(IBusEngine *engine) ABSTRACT;
 
+  virtual void ResetContentType(IBusEngine *engine) ABSTRACT;
+  virtual void UpdateContentType(IBusEngine *engine) ABSTRACT;
+
   // Update properties.
   virtual void Update(IBusEngine *engine,
                       const commands::Output &output) ABSTRACT;
@@ -55,6 +58,9 @@
   // Returns if IME is activated or not.
   virtual bool IsActivated() const ABSTRACT;
 
+  // Returns if IME is forcesully disabled, e.g. on a password field.
+  virtual bool IsDisabled() const ABSTRACT;
+
   // Returns original composition mode before.
   virtual commands::CompositionMode GetOriginalCompositionMode() const ABSTRACT;
 };
openSUSE Build Service is sponsored by