OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | |
14 #include "base/logging.h" // DCHECK | |
15 #include "base/string_split.h" | |
16 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" | |
17 | |
18 namespace chromeos { | 13 namespace chromeos { |
19 namespace input_method { | 14 namespace input_method { |
20 | 15 |
21 struct InputMethodConfigValue; | 16 struct InputMethodConfigValue; |
22 struct InputMethodProperty; | 17 struct InputMethodProperty; |
23 typedef std::vector<InputMethodProperty> InputMethodPropertyList; | 18 typedef std::vector<InputMethodProperty> InputMethodPropertyList; |
24 typedef std::vector<std::pair<double, double> > HandwritingStroke; | |
25 | 19 |
26 // IBusController is used to interact with the IBus daemon. | 20 // IBusController is used to interact with the system input method framework |
| 21 // (which is currently IBus). |
27 class IBusController { | 22 class IBusController { |
28 public: | 23 public: |
29 class Observer { | 24 class Observer { |
30 public: | 25 public: |
31 virtual ~Observer() {} | 26 virtual ~Observer() {} |
32 | 27 virtual void PropertyChanged() = 0; |
33 // Called when current input method is changed by a user. | 28 // TODO(yusukes): Add functions for IPC error handling. |
34 virtual void OnCurrentInputMethodChanged( | |
35 const InputMethodDescriptor& current_input_method) = 0; | |
36 | |
37 // Called when "RegisterProperties" signal is sent from | |
38 // ibus-daemon. The signal contains a list of properties for a | |
39 // specific input method engine. For example, Japanese input method | |
40 // might have the following properties: | |
41 // | |
42 // ---------------------------------- | |
43 // key: InputMode.Hiragana | |
44 // label: Hiragana | |
45 // is_selection_item: true | |
46 // is_selection_item_checked: true | |
47 // selection_item_id: 1 | |
48 // ---------------------------------- | |
49 // key: InputMode.Katakana | |
50 // label: Katakana | |
51 // is_selection_item: true | |
52 // is_selection_item_checked: false | |
53 // selection_item_id: 1 | |
54 // ---------------------------------- | |
55 // ... | |
56 // ---------------------------------- | |
57 virtual void OnRegisterImeProperties( | |
58 const InputMethodPropertyList& prop_list) = 0; | |
59 | |
60 // Called when "UpdateProperty" signal is sent from ibus-daemon. The | |
61 // signal contains one or more properties which is updated | |
62 // recently. Keys the signal contains are a subset of keys registered | |
63 // by the "RegisterProperties" signal above. For example, Japanese | |
64 // input method might send the following properties: | |
65 // | |
66 // ---------------------------------- | |
67 // key: InputMode.Hiragana | |
68 // label: Hiragana | |
69 // is_selection_item: true | |
70 // is_selection_item_checked: false | |
71 // selection_item_id: ... | |
72 // ---------------------------------- | |
73 // key: InputMode.Katakana | |
74 // label: Katakana | |
75 // is_selection_item: true | |
76 // is_selection_item_checked: true | |
77 // selection_item_id: ... | |
78 // ---------------------------------- | |
79 // | |
80 // Note: Please do not use selection_item_ids in |prop_list|. Dummy | |
81 // values are filled in the field. | |
82 virtual void OnUpdateImeProperty( | |
83 const InputMethodPropertyList& prop_list) = 0; | |
84 | |
85 // Called when ibus connects or disconnects. | |
86 virtual void OnConnectionChange(bool connected) = 0; | |
87 }; | 29 }; |
88 | 30 |
89 // Creates an instance of the class. The constructor is unused. | 31 // Creates an instance of the class. |
90 static IBusController* Create(); | 32 static IBusController* Create(); |
91 | 33 |
92 virtual ~IBusController(); | 34 virtual ~IBusController(); |
93 | 35 |
94 // Connects to the IBus daemon. | |
95 virtual void Connect() = 0; | |
96 | |
97 // Adds and removes observers for IBus UI notifications. Clients must be | |
98 // sure to remove the observer before they go away. To capture the | |
99 // initial connection change, you should add an observer before calling | |
100 // Connect(). | |
101 virtual void AddObserver(Observer* observer) = 0; | 36 virtual void AddObserver(Observer* observer) = 0; |
102 virtual void RemoveObserver(Observer* observer) = 0; | 37 virtual void RemoveObserver(Observer* observer) = 0; |
103 | 38 |
104 // Stops ibus-daemon. Returns true on success. | 39 // Starts the system input method framework. No-op if it's already started. |
105 virtual bool StopInputMethodProcess() = 0; | 40 virtual bool Start() = 0; |
106 | 41 |
107 // Changes the current input method engine to |name|. Returns true on | 42 // Stops the system input method framework. |
108 // success. Examples of names: "pinyin", "m17n:ar:kbd", | 43 virtual bool Stop() = 0; |
109 // "xkb:us:dvorak:eng". | |
110 virtual bool ChangeInputMethod(const std::string& name) = 0; | |
111 | 44 |
112 // Sets whether the input method property specified by |key| is activated. | 45 // Sets a configuration of an input method engine. Returns true if the |
113 // If |activated| is true, activates the property. If |activated| is false, | 46 // configuration is successfully set. For example, when you set |
114 // deactivates the property. | 47 // "engine/Mozc/history_learning_level", |section| should be "engine/Mozc", |
115 // TODO(yusukes): "SetInputMethodPropertyActivated" might be better? | 48 // and |config_name| should be "history_learning_level". |
116 virtual void SetImePropertyActivated(const std::string& key, | |
117 bool activated) = 0; | |
118 | |
119 // Sets a configuration of ibus-daemon or IBus engines to |value|. | |
120 // Returns true if the configuration is successfully set. | |
121 // | |
122 // To set 'panel/custom_font', |section| should be "panel", and | |
123 // |config_name| should be "custom_font". | |
124 virtual bool SetInputMethodConfig(const std::string& section, | 49 virtual bool SetInputMethodConfig(const std::string& section, |
125 const std::string& config_name, | 50 const std::string& config_name, |
126 const InputMethodConfigValue& value) = 0; | 51 const InputMethodConfigValue& value) = 0; |
127 | 52 |
128 // Sends a handwriting stroke to ibus-daemon. The std::pair contains x | 53 // Changes the current input method engine to |id|. Returns true on success. |
129 // and y coordinates. (0.0, 0.0) represents the top-left corner of a | 54 // Example IDs: "mozc", "m17n:ar:kbd". |
130 // handwriting area, and (1.0, 1.0) does the bottom-right. For example, | 55 virtual bool ChangeInputMethod(const std::string& id) = 0; |
131 // the second stroke for U+30ED (Katakana character Ro) would be | 56 |
132 // something like [(0,0), (1,0), (1,1)]. stroke.size() should always be | 57 // Activates the input method property specified by the |key|. Returns true on |
133 // >= 2 (i.e. a single dot is not allowed). | 58 // success. |
| 59 virtual bool ActivateInputMethodProperty(const std::string& key) = 0; |
| 60 |
| 61 // Gets the latest input method property send from the system input method |
| 62 // framework. |
| 63 virtual const InputMethodPropertyList& GetCurrentProperties() const = 0; |
| 64 |
| 65 #if defined(USE_VIRTUAL_KEYBOARD) |
| 66 typedef std::vector<std::pair<double, double> > HandwritingStroke; |
| 67 |
| 68 // Sends a handwriting stroke to the system input method. The std::pair |
| 69 // contains x and y coordinates. (0.0, 0.0) represents the top-left corner of |
| 70 // a handwriting area, and (1.0, 1.0) does the bottom-right. For example, the |
| 71 // second stroke for U+30ED (Katakana character Ro) would be something like |
| 72 // [(0,0), (1,0), (1,1)]. stroke.size() should always be >= 2 (i.e. a single |
| 73 // dot is not allowed). |
134 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) = 0; | 74 virtual void SendHandwritingStroke(const HandwritingStroke& stroke) = 0; |
135 | 75 |
136 // Clears the last N handwriting strokes. Pass zero for clearing all strokes. | 76 // Clears the last N handwriting strokes. Pass zero for clearing all strokes. |
137 // TODO(yusukes): Currently ibus-daemon only accepts 0 for |n_strokes|. | 77 // TODO(yusukes): Currently ibus-daemon only accepts 0 for |n_strokes|. |
138 virtual void CancelHandwriting(int n_strokes) = 0; | 78 virtual void CancelHandwriting(int n_strokes) = 0; |
139 | 79 #endif |
140 // Creates an InputMethodDescriptor object. |raw_layout| is a comma-separated | |
141 // list of XKB and virtual keyboard layouts. | |
142 // (e.g. "special-us-virtual-keyboard-for-the-input-method,us") | |
143 virtual InputMethodDescriptor CreateInputMethodDescriptor( | |
144 const std::string& id, | |
145 const std::string& name, | |
146 const std::string& raw_layout, | |
147 const std::string& language_code) = 0; | |
148 }; | 80 }; |
149 | 81 |
150 } // namespace input_method | 82 } // namespace input_method |
151 } // namespace chromeos | 83 } // namespace chromeos |
152 | 84 |
| 85 // TODO(yusukes,nona): This interface does not depend on IBus actually. |
| 86 // Rename the file if needed. |
| 87 |
153 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ |
OLD | NEW |