mozc-ibus-1.5.4.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. Index: engine_interface.h
  2. ===================================================================
  3. --- unix/ibus/engine_interface.h (revision 177)
  4. +++ unix/ibus/engine_interface.h (working copy)
  5. @@ -106,6 +106,11 @@
  6. gint y,
  7. gint w,
  8. gint h) = 0;
  9. +
  10. + // The interface function for the "set-content-type" signal
  11. + virtual void SetContentType(IBusEngine *engine,
  12. + guint purpose,
  13. + guint hints) = 0;
  14. };
  15. } // namespace ibus
  16. Index: engine_registrar.cc
  17. ===================================================================
  18. --- unix/ibus/engine_registrar.cc (revision 177)
  19. +++ unix/ibus/engine_registrar.cc (working copy)
  20. @@ -63,7 +63,9 @@
  21. engine_class->reset = Reset;
  22. engine_class->set_capabilities = SetCapabilities;
  23. engine_class->set_cursor_location = SetCursorLocation;
  24. -
  25. +#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
  26. + engine_class->set_content_type = SetContentType;
  27. +#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
  28. return true;
  29. }
  30. @@ -87,6 +89,9 @@
  31. engine_class->reset = NULL;
  32. engine_class->set_capabilities = NULL;
  33. engine_class->set_cursor_location = NULL;
  34. +#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
  35. + engine_class->set_content_type = NULL;
  36. +#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
  37. mozc::ibus::EngineInterface *previous = g_engine;
  38. g_engine = NULL;
  39. @@ -179,5 +184,12 @@
  40. g_engine->SetCursorLocation(engine, x, y, w, h);
  41. }
  42. +void EngineRegistrar::SetContentType(
  43. + IBusEngine *engine,
  44. + guint purpose,
  45. + guint hints) {
  46. + g_engine->SetContentType(engine, purpose, hints);
  47. +}
  48. +
  49. } // namespace ibus
  50. } // namespace mozc
  51. Index: engine_registrar.h
  52. ===================================================================
  53. --- unix/ibus/engine_registrar.h (revision 177)
  54. +++ unix/ibus/engine_registrar.h (working copy)
  55. @@ -84,6 +84,9 @@
  56. gint y,
  57. gint w,
  58. gint h);
  59. + static void SetContentType(IBusEngine *engine,
  60. + guint purpose,
  61. + guint hints);
  62. };
  63. } // namespace ibus
  64. Index: ibus_header.h
  65. ===================================================================
  66. --- unix/ibus/ibus_header.h (revision 177)
  67. +++ unix/ibus/ibus_header.h (working copy)
  68. @@ -36,5 +36,10 @@
  69. #error "ibus-mozc now requires IBus>=1.4.1"
  70. #endif // libibus (<1.4.1)
  71. +#if IBUS_CHECK_VERSION(1, 5, 4)
  72. +#if !defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
  73. +#define MOZC_ENABLE_IBUS_INPUT_PURPOSE
  74. +#endif // !MOZC_ENABLE_IBUS_INPUT_PURPOSE
  75. +#endif // libibus(>=1.5.4)
  76. #endif // MOZC_UNIX_IBUS_IBUS_HEADER_H_
  77. Index: mozc_engine.cc
  78. ===================================================================
  79. --- unix/ibus/mozc_engine.cc (revision 177)
  80. +++ unix/ibus/mozc_engine.cc (working copy)
  81. @@ -372,6 +372,7 @@
  82. void MozcEngine::FocusOut(IBusEngine *engine) {
  83. GetCandidateWindowHandler(engine)->Hide(engine);
  84. + property_handler_->ResetContentType(engine);
  85. // Do not call SubmitSession or RevertSession. Preedit string will commit on
  86. // Focus Out event automatically by ibus_engine_update_preedit_text_with_mode
  87. @@ -397,6 +398,11 @@
  88. VLOG(2) << "keyval: " << keyval
  89. << ", keycode: " << keycode
  90. << ", modifiers: " << modifiers;
  91. + if (property_handler_->IsDisabled()) {
  92. + // It is each enginze's responsibility for ignoreing keyevents on
  93. + // the password field on the locked screen since IBus 1.5.4.
  94. + return FALSE;
  95. + }
  96. // Send current caret location to mozc_server to manage suggest window
  97. // position.
  98. @@ -501,6 +507,18 @@
  99. // Do nothing
  100. }
  101. +void MozcEngine::SetContentType(IBusEngine *engine,
  102. + guint purpose,
  103. + guint hints) {
  104. + const bool prev_disabled =
  105. + property_handler_->IsDisabled();
  106. + property_handler_->UpdateContentType(engine);
  107. + if (!prev_disabled && property_handler_->IsDisabled()) {
  108. + // Make sure on-going composition is reverted.
  109. + RevertSession(engine);
  110. + }
  111. +}
  112. +
  113. GType MozcEngine::GetType() {
  114. static GType type = 0;
  115. Index: mozc_engine.h
  116. ===================================================================
  117. --- unix/ibus/mozc_engine.h (revision 177)
  118. +++ unix/ibus/mozc_engine.h (working copy)
  119. @@ -99,6 +99,9 @@
  120. gint y,
  121. gint w,
  122. gint h);
  123. + void SetContentType(IBusEngine *engine,
  124. + guint purpose,
  125. + guint hints);
  126. // Returns the GType which this class represents.
  127. static GType GetType();
  128. Index: property_handler.cc
  129. ===================================================================
  130. --- unix/ibus/property_handler.cc (revision 177)
  131. +++ unix/ibus/property_handler.cc (working copy)
  132. @@ -61,6 +61,19 @@
  133. bool IsMozcToolAvailable() {
  134. return FileUtil::FileExists(SystemUtil::GetToolPath());
  135. }
  136. +
  137. +bool GetDisabled(IBusEngine *engine) {
  138. + bool disabled = false;
  139. +#if defined(MOZC_ENABLE_IBUS_INPUT_PURPOSE)
  140. + guint purpose = IBUS_INPUT_PURPOSE_FREE_FORM;
  141. + guint hints = IBUS_INPUT_HINT_NONE;
  142. + ibus_engine_get_content_type(engine, &purpose, &hints);
  143. + disabled = (purpose == IBUS_INPUT_PURPOSE_PASSWORD ||
  144. + purpose == IBUS_INPUT_PURPOSE_PIN);
  145. +#endif // MOZC_ENABLE_IBUS_INPUT_PURPOSE
  146. + return disabled;
  147. +}
  148. +
  149. } // namespace
  150. PropertyHandler::PropertyHandler(MessageTranslatorInterface *translator,
  151. @@ -71,7 +84,8 @@
  152. client_(client),
  153. translator_(translator),
  154. original_composition_mode_(kMozcEngineInitialCompositionMode),
  155. - is_activated_(true) {
  156. + is_activated_(true),
  157. + is_disabled_(false) {
  158. AppendCompositionPropertyToPanel();
  159. #ifndef OS_CHROMEOS
  160. @@ -105,6 +119,7 @@
  161. void PropertyHandler::Register(IBusEngine *engine) {
  162. ibus_engine_register_properties(engine, prop_root_);
  163. + UpdateContentType(engine);
  164. }
  165. // TODO(nona): do not use kMozcEngine*** directory.
  166. @@ -228,8 +243,34 @@
  167. ibus_prop_list_append(prop_root_, prop_mozc_tool_);
  168. }
  169. +void PropertyHandler::UpdateContentTypeImpl(IBusEngine *engine,
  170. + bool disabled) {
  171. + const bool prev_is_disabled = is_disabled_;
  172. + is_disabled_ = disabled;
  173. + if (prev_is_disabled == is_disabled_) {
  174. + return;
  175. + }
  176. + const commands::CompositionMode visible_mode =
  177. + (prev_is_disabled && !is_disabled_ && IsActivated())
  178. + ? original_composition_mode_ :
  179. + kMozcEnginePropertyIMEOffState->composition_mode;
  180. + UpdateCompositionModeIcon(engine, visible_mode);
  181. +}
  182. +
  183. +void PropertyHandler::ResetContentType(IBusEngine *engine) {
  184. + UpdateContentTypeImpl(engine, false);
  185. +}
  186. +
  187. +void PropertyHandler::UpdateContentType(IBusEngine *engine) {
  188. + UpdateContentTypeImpl(engine, GetDisabled(engine));
  189. +}
  190. +
  191. void PropertyHandler::Update(IBusEngine *engine,
  192. const commands::Output &output) {
  193. + if (IsDisabled()) {
  194. + return;
  195. + }
  196. +
  197. if (output.has_status() &&
  198. (output.status().activated() != is_activated_ ||
  199. output.status().mode() != original_composition_mode_)) {
  200. @@ -325,6 +366,10 @@
  201. const gchar *property_name,
  202. guint property_state) {
  203. #ifndef OS_CHROMEOS
  204. + if (IsDisabled()) {
  205. + return;
  206. + }
  207. +
  208. if (prop_mozc_tool_) {
  209. for (guint prop_index = 0; ; ++prop_index) {
  210. IBusProperty *prop = ibus_prop_list_get(
  211. @@ -371,9 +416,13 @@
  212. }
  213. bool PropertyHandler::IsActivated() const {
  214. - return is_activated_;
  215. + return is_activated_ && !IsDisabled();
  216. }
  217. +bool PropertyHandler::IsDisabled() const {
  218. + return is_disabled_;
  219. +}
  220. +
  221. commands::CompositionMode PropertyHandler::GetOriginalCompositionMode() const {
  222. return original_composition_mode_;
  223. }
  224. Index: property_handler.h
  225. ===================================================================
  226. --- unix/ibus/property_handler.h (revision 177)
  227. +++ unix/ibus/property_handler.h (working copy)
  228. @@ -54,14 +54,19 @@
  229. virtual ~PropertyHandler();
  230. virtual void Register(IBusEngine *engine);
  231. + virtual void ResetContentType(IBusEngine *engine);
  232. + virtual void UpdateContentType(IBusEngine *engine);
  233. virtual void Update(IBusEngine *engine, const commands::Output &output);
  234. virtual void ProcessPropertyActivate(IBusEngine *engine,
  235. const gchar *property_name,
  236. guint property_state);
  237. virtual bool IsActivated() const;
  238. + virtual bool IsDisabled() const;
  239. virtual commands::CompositionMode GetOriginalCompositionMode() const;
  240. private:
  241. + void UpdateContentTypeImpl(IBusEngine *engine, bool disabled);
  242. +
  243. // Appends composition properties into panel
  244. void AppendCompositionPropertyToPanel();
  245. // Appends tool properties into panel
  246. @@ -79,6 +84,7 @@
  247. scoped_ptr<MessageTranslatorInterface> translator_;
  248. commands::CompositionMode original_composition_mode_;
  249. bool is_activated_;
  250. + bool is_disabled_;
  251. };
  252. } // namespace ibus
  253. Index: property_handler_interface.h
  254. ===================================================================
  255. --- unix/ibus/property_handler_interface.h (revision 177)
  256. +++ unix/ibus/property_handler_interface.h (working copy)
  257. @@ -45,6 +45,9 @@
  258. // Registers current properties into engine.
  259. virtual void Register(IBusEngine *engine) ABSTRACT;
  260. + virtual void ResetContentType(IBusEngine *engine) ABSTRACT;
  261. + virtual void UpdateContentType(IBusEngine *engine) ABSTRACT;
  262. +
  263. // Update properties.
  264. virtual void Update(IBusEngine *engine,
  265. const commands::Output &output) ABSTRACT;
  266. @@ -55,6 +58,9 @@
  267. // Returns if IME is activated or not.
  268. virtual bool IsActivated() const ABSTRACT;
  269. + // Returns if IME is forcesully disabled, e.g. on a password field.
  270. + virtual bool IsDisabled() const ABSTRACT;
  271. +
  272. // Returns original composition mode before.
  273. virtual commands::CompositionMode GetOriginalCompositionMode() const ABSTRACT;
  274. };