1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ 7 #pragma once 8 9 #include <string> 10 #include <utility> 11 12 #include "base/observer_list.h" 13 #include "base/time.h" 14 #include "base/timer.h" 15 #include "third_party/cros/chromeos_input_method.h" 16 17 namespace chromeos { 18 19 // This class handles the interaction with the ChromeOS language library APIs. 20 // Classes can add themselves as observers. Users can get an instance of this 21 // library class like this: 22 // chromeos::CrosLibrary::Get()->GetInputMethodLibrary() 23 class InputMethodLibrary { 24 public: 25 class Observer { 26 public: 27 virtual ~Observer() = 0; 28 // Called when the current input method is changed. 29 virtual void InputMethodChanged( 30 InputMethodLibrary* obj, 31 const InputMethodDescriptor& current_input_method, 32 size_t num_active_input_methods) = 0; 33 34 // Called when the active input methods are changed. 35 virtual void ActiveInputMethodsChanged( 36 InputMethodLibrary* obj, 37 const InputMethodDescriptor& current_input_method, 38 size_t num_active_input_methods) = 0; 39 40 // Called when the preferences have to be updated. 41 virtual void PreferenceUpdateNeeded( 42 InputMethodLibrary* obj, 43 const InputMethodDescriptor& previous_input_method, 44 const InputMethodDescriptor& current_input_method) = 0; 45 46 // Called when the list of properties is changed. 47 virtual void PropertyListChanged( 48 InputMethodLibrary* obj, 49 const ImePropertyList& current_ime_properties) = 0; 50 51 // Called by AddObserver() when the first observer is added. 52 virtual void FirstObserverIsAdded(InputMethodLibrary* obj) = 0; 53 }; ~InputMethodLibrary()54 virtual ~InputMethodLibrary() {} 55 56 // Adds an observer to receive notifications of input method related 57 // changes as desribed in the Observer class above. 58 virtual void AddObserver(Observer* observer) = 0; 59 virtual void RemoveObserver(Observer* observer) = 0; 60 61 // Returns the list of input methods we can select (i.e. active). If the cros 62 // library is not found or IBus/DBus daemon is not alive, this function 63 // returns a fallback input method list (and never returns NULL). 64 virtual InputMethodDescriptors* GetActiveInputMethods() = 0; 65 66 // Returns the number of active input methods. 67 virtual size_t GetNumActiveInputMethods() = 0; 68 69 // Returns the list of input methods we support, including ones not active. 70 // If the cros library is not found or IBus/DBus daemon is not alive, this 71 // function returns a fallback input method list (and never returns NULL). 72 virtual InputMethodDescriptors* GetSupportedInputMethods() = 0; 73 74 // Changes the current input method to |input_method_id|. 75 virtual void ChangeInputMethod(const std::string& input_method_id) = 0; 76 77 // Sets whether the input method property specified by |key| is activated. If 78 // |activated| is true, activates the property. If |activate| is false, 79 // deactivates the property. Examples of keys: 80 // - "InputMode.Katakana" 81 // - "InputMode.HalfWidthKatakana" 82 // - "TypingMode.Romaji" 83 // - "TypingMode.Kana" 84 virtual void SetImePropertyActivated(const std::string& key, 85 bool activated) = 0; 86 87 // Returns true if the input method specified by |input_method_id| is active. 88 virtual bool InputMethodIsActivated(const std::string& input_method_id) = 0; 89 90 // Updates a configuration of ibus-daemon or IBus engines with |value|. 91 // Returns true if the configuration (and all pending configurations, if any) 92 // are processed. If ibus-daemon is not running, this function just queues 93 // the request and returns false. 94 // When you would like to set 'panel/custom_font', |section| should 95 // be "panel", and |config_name| should be "custom_font". 96 // Notice: This function might call the Observer::ActiveInputMethodsChanged() 97 // callback function immediately, before returning from the SetImeConfig 98 // function. See also http://crosbug.com/5217. 99 virtual bool SetImeConfig(const std::string& section, 100 const std::string& config_name, 101 const ImeConfigValue& value) = 0; 102 103 // Returns the keyboard overlay ID corresponding to |input_method_id|. 104 // Returns an empty string if there is no corresponding keyboard overlay ID. 105 virtual std::string GetKeyboardOverlayId( 106 const std::string& input_method_id) = 0; 107 108 // Sets the IME state to enabled, and launches input method daemon if needed. 109 // Returns true if the daemon is started. Otherwise, e.g. the daemon is 110 // already started, returns false. 111 virtual bool StartInputMethodDaemon() = 0; 112 113 // Disables the IME, and kills the daemon process if they are running. 114 virtual void StopInputMethodDaemon() = 0; 115 116 // Controls whether the IME process is started when preload engines are 117 // specificed, or defered until a non-default method is activated. 118 virtual void SetDeferImeStartup(bool defer) = 0; 119 120 // Controls whether the IME process is stopped when all non-default preload 121 // engines are removed. 122 virtual void SetEnableAutoImeShutdown(bool enable) = 0; 123 124 125 virtual InputMethodDescriptor previous_input_method() const = 0; 126 virtual InputMethodDescriptor current_input_method() const = 0; 127 128 virtual const ImePropertyList& current_ime_properties() const = 0; 129 130 // Factory function, creates a new instance and returns ownership. 131 // For normal usage, access the singleton via CrosLibrary::Get(). 132 static InputMethodLibrary* GetImpl(bool stub); 133 }; 134 135 } // namespace chromeos 136 137 #endif // CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_ 138