input_method_library.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
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
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 "cros/chromeos_input_method.h"
16
17namespace 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()
23class 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(InputMethodLibrary* obj) = 0;
30
31    // Called when input method properties (see chromeos_input_method.h
32    // for details) are changed.
33    virtual void ImePropertiesChanged(InputMethodLibrary* obj) = 0;
34
35    // Called when the active input methods are changed.
36    virtual void ActiveInputMethodsChanged(InputMethodLibrary* obj) = 0;
37  };
38  virtual ~InputMethodLibrary() {}
39
40  // Adds an observer to receive notifications of input method related
41  // changes as desribed in the Observer class above.
42  virtual void AddObserver(Observer* observer) = 0;
43  virtual void RemoveObserver(Observer* observer) = 0;
44
45  // Returns the list of input methods we can select (i.e. active). If the cros
46  // library is not found or IBus/DBus daemon is not alive, this function
47  // returns a fallback input method list (and never returns NULL).
48  virtual InputMethodDescriptors* GetActiveInputMethods() = 0;
49
50  // Returns the number of active input methods.
51  virtual size_t GetNumActiveInputMethods() = 0;
52
53  // Returns the list of input methods we support, including ones not active.
54  // If the cros library is not found or IBus/DBus daemon is not alive, this
55  // function returns a fallback input method list (and never returns NULL).
56  virtual InputMethodDescriptors* GetSupportedInputMethods() = 0;
57
58  // Changes the current input method to |input_method_id|.
59  virtual void ChangeInputMethod(const std::string& input_method_id) = 0;
60
61  // Sets whether the input method property specified by |key| is activated. If
62  // |activated| is true, activates the property. If |activate| is false,
63  // deactivates the property. Examples of keys:
64  // - "InputMode.Katakana"
65  // - "InputMode.HalfWidthKatakana"
66  // - "TypingMode.Romaji"
67  // - "TypingMode.Kana"
68  virtual void SetImePropertyActivated(const std::string& key,
69                                       bool activated) = 0;
70
71  // Returns true if the input method specified by |input_method_id| is active.
72  virtual bool InputMethodIsActivated(const std::string& input_method_id) = 0;
73
74  // Get a configuration of ibus-daemon or IBus engines and stores it on
75  // |out_value|. Returns true if |out_value| is successfully updated.
76  // When you would like to retrieve 'panel/custom_font', |section| should
77  // be "panel", and |config_name| should be "custom_font".
78  virtual bool GetImeConfig(
79      const char* section, const char* config_name,
80      ImeConfigValue* out_value) = 0;
81
82  // Updates a configuration of ibus-daemon or IBus engines with |value|.
83  // Returns true if the configuration (and all pending configurations, if any)
84  // are processed. If ibus-daemon is not running, this function just queues
85  // the request and returns false.
86  // You can specify |section| and |config_name| arguments in the same way
87  // as GetImeConfig() above.
88  // Notice: This function might call the Observer::ActiveInputMethodsChanged()
89  // callback function immediately, before returning from the SetImeConfig
90  // function. See also http://crosbug.com/5217.
91  virtual bool SetImeConfig(const char* section,
92                            const char* config_name,
93                            const ImeConfigValue& value) = 0;
94
95  // Sets the IME state to enabled, and launches its processes if needed.
96  virtual void StartInputMethodProcesses() = 0;
97
98  // Disables the IME, and kills the processes if they are running.
99  virtual void StopInputMethodProcesses() = 0;
100
101  // Controls whether the IME process is started when preload engines are
102  // specificed, or defered until a non-default method is activated.
103  virtual void SetDeferImeStartup(bool defer) = 0;
104
105  virtual const InputMethodDescriptor& previous_input_method() const = 0;
106  virtual const InputMethodDescriptor& current_input_method() const = 0;
107
108  virtual const ImePropertyList& current_ime_properties() const = 0;
109
110  // Factory function, creates a new instance and returns ownership.
111  // For normal usage, access the singleton via CrosLibrary::Get().
112  static InputMethodLibrary* GetImpl(bool stub);
113};
114
115}  // namespace chromeos
116
117#endif  // CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_
118