OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/input_method_library.h" | 5 #include "chrome/browser/chromeos/cros/input_method_library.h" |
6 | 6 |
7 #include <glib.h> | 7 #include <glib.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 | 9 |
10 #include "unicode/uloc.h" | 10 #include "unicode/uloc.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 if (pending_config_requests_.empty()) { | 321 if (pending_config_requests_.empty()) { |
322 timer_.Stop(); // no-op if it's not running. | 322 timer_.Stop(); // no-op if it's not running. |
323 } else if (!timer_.IsRunning()) { | 323 } else if (!timer_.IsRunning()) { |
324 // Flush is not completed. Start a timer if it's not yet running. | 324 // Flush is not completed. Start a timer if it's not yet running. |
325 static const int64 kTimerIntervalInMsec = 100; | 325 static const int64 kTimerIntervalInMsec = 100; |
326 timer_.Start(base::TimeDelta::FromMilliseconds(kTimerIntervalInMsec), | 326 timer_.Start(base::TimeDelta::FromMilliseconds(kTimerIntervalInMsec), |
327 this, &InputMethodLibraryImpl::FlushImeConfig); | 327 this, &InputMethodLibraryImpl::FlushImeConfig); |
328 } | 328 } |
329 | 329 |
| 330 // Notify the current input method and the number of active input methods to |
| 331 // the UI so that the UI could determine e.g. if it should show/hide the |
| 332 // input method indicator, etc. We have to call FOR_EACH_OBSERVER here since |
| 333 // updating "preload_engine" does not necessarily trigger a DBus signal such |
| 334 // as "global-engine-changed". For example, |
| 335 // 1) If we change the preload_engine from "xkb:us:intl:eng" (i.e. the |
| 336 // indicator is hidden) to "xkb:us:intl:eng,mozc", we have to update UI |
| 337 // so it shows the indicator, but no signal is sent from ibus-daemon |
| 338 // because the current input method is not changed. |
| 339 // 2) If we change the preload_engine from "xkb:us::eng,mozc" (i.e. the |
| 340 // indicator is shown and ibus-daemon is started) to "xkb:us::eng", we |
| 341 // have to update UI so it hides the indicator, but we should not expect |
| 342 // that ibus-daemon could send a DBus signal since the daemon is killed |
| 343 // right after this FlushImeConfig() call. |
330 if (active_input_methods_are_changed) { | 344 if (active_input_methods_are_changed) { |
| 345 scoped_ptr<InputMethodDescriptor> current_input_method( |
| 346 chromeos::GetCurrentInputMethod(input_method_status_connection_)); |
| 347 // The |current_input_method_| member variable should not be used since |
| 348 // the variable might be stale. SetImeConfig("preload_engine") call above |
| 349 // might change the current input method in ibus-daemon, but the variable |
| 350 // is not updated until InputMethodChangedHandler(), which is the handler |
| 351 // for the global-engine-changed DBus signal, is called. |
331 const size_t num_active_input_methods = GetNumActiveInputMethods(); | 352 const size_t num_active_input_methods = GetNumActiveInputMethods(); |
332 FOR_EACH_OBSERVER(Observer, observers_, | 353 if (current_input_method.get()) { |
333 ActiveInputMethodsChanged(this, | 354 FOR_EACH_OBSERVER(Observer, observers_, |
334 current_input_method_, | 355 ActiveInputMethodsChanged(this, |
335 num_active_input_methods)); | 356 *current_input_method.get(), |
| 357 num_active_input_methods)); |
| 358 } |
336 } | 359 } |
337 } | 360 } |
338 | 361 |
339 static void InputMethodChangedHandler( | 362 static void InputMethodChangedHandler( |
340 void* object, | 363 void* object, |
341 const chromeos::InputMethodDescriptor& current_input_method) { | 364 const chromeos::InputMethodDescriptor& current_input_method) { |
342 // The handler is called when the input method method change is | 365 // The handler is called when the input method method change is |
343 // notified via a DBus connection. Since the DBus notificatiosn are | 366 // notified via a DBus connection. Since the DBus notificatiosn are |
344 // handled in the UI thread, we can assume that this function always | 367 // handled in the UI thread, we can assume that this function always |
345 // runs on the UI thread, but just in case. | 368 // runs on the UI thread, but just in case. |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 return new InputMethodLibraryStubImpl(); | 870 return new InputMethodLibraryStubImpl(); |
848 else | 871 else |
849 return new InputMethodLibraryImpl(); | 872 return new InputMethodLibraryImpl(); |
850 } | 873 } |
851 | 874 |
852 } // namespace chromeos | 875 } // namespace chromeos |
853 | 876 |
854 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 877 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
855 // won't be deleted until it's last InvokeLater is run. | 878 // won't be deleted until it's last InvokeLater is run. |
856 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); | 879 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::InputMethodLibraryImpl); |
OLD | NEW |