| 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 | 8 |
| 8 #include <string> | 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/logging.h" // DCHECK | 14 #include "base/logging.h" // DCHECK |
| 14 #include "base/string_split.h" | 15 #include "base/string_split.h" |
| 16 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 namespace input_method { | 19 namespace input_method { |
| 18 | 20 |
| 19 class InputMethodDescriptor; | 21 struct InputMethodConfigValue; |
| 20 typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; | 22 struct InputMethodProperty; |
| 21 class InputMethodWhitelist; | |
| 22 | |
| 23 // A structure which represents an input method. | |
| 24 class InputMethodDescriptor { | |
| 25 public: | |
| 26 InputMethodDescriptor(); | |
| 27 InputMethodDescriptor(const InputMethodWhitelist& whitelist, | |
| 28 const std::string& in_id, | |
| 29 const std::string& in_name, | |
| 30 const std::string& in_raw_layout, | |
| 31 const std::string& in_language_code); | |
| 32 ~InputMethodDescriptor(); | |
| 33 | |
| 34 bool operator==(const InputMethodDescriptor& other) const { | |
| 35 return (id() == other.id()); | |
| 36 } | |
| 37 | |
| 38 // Debug print function. | |
| 39 std::string ToString() const; | |
| 40 | |
| 41 const std::string& id() const { return id_; } | |
| 42 const std::string& name() const { return name_; } | |
| 43 const std::string& keyboard_layout() const { return keyboard_layout_; } | |
| 44 const std::vector<std::string>& virtual_keyboard_layouts() const { | |
| 45 return virtual_keyboard_layouts_; | |
| 46 } | |
| 47 const std::string& language_code() const { return language_code_; } | |
| 48 | |
| 49 // Returns the fallback input method descriptor (the very basic US | |
| 50 // keyboard). This function is mostly used for testing, but may be used | |
| 51 // as the fallback, when there is no other choice. | |
| 52 static InputMethodDescriptor GetFallbackInputMethodDescriptor(); | |
| 53 | |
| 54 private: | |
| 55 // For GetFallbackInputMethodDescriptor(). Use the public constructor instead. | |
| 56 InputMethodDescriptor(const std::string& in_id, | |
| 57 const std::string& in_name, | |
| 58 const std::string& in_keyboard_layout, | |
| 59 const std::string& in_virtual_keyboard_layouts, | |
| 60 const std::string& in_language_code); | |
| 61 | |
| 62 // An ID that identifies an input method engine (e.g., "t:latn-post", | |
| 63 // "pinyin", "hangul"). | |
| 64 std::string id_; | |
| 65 // A name used to specify the user-visible name of this input method. It is | |
| 66 // only used by extension IMEs, and should be blank for internal IMEs. | |
| 67 std::string name_; | |
| 68 // A preferred physical keyboard layout for the input method (e.g., "us", | |
| 69 // "us(dvorak)", "jp"). Comma separated layout names do NOT appear. | |
| 70 std::string keyboard_layout_; | |
| 71 // Preferred virtual keyboard layouts for the input method. Comma separated | |
| 72 // layout names in order of priority, such as "handwriting,us", could appear. | |
| 73 std::vector<std::string> virtual_keyboard_layouts_; | |
| 74 // Language code like "ko", "ja", "en-US", and "zh-CN". | |
| 75 std::string language_code_; | |
| 76 }; | |
| 77 | |
| 78 // A structure which represents a property for an input method engine. | |
| 79 struct InputMethodProperty { | |
| 80 InputMethodProperty(const std::string& in_key, | |
| 81 const std::string& in_label, | |
| 82 bool in_is_selection_item, | |
| 83 bool in_is_selection_item_checked, | |
| 84 int in_selection_item_id); | |
| 85 | |
| 86 InputMethodProperty(); | |
| 87 ~InputMethodProperty(); | |
| 88 | |
| 89 // Debug print function. | |
| 90 std::string ToString() const; | |
| 91 | |
| 92 std::string key; // A key which identifies the property. Non-empty string. | |
| 93 // (e.g. "InputMode.HalfWidthKatakana") | |
| 94 std::string label; // A description of the property. Non-empty string. | |
| 95 // (e.g. "Switch to full punctuation mode", "Hiragana") | |
| 96 bool is_selection_item; // true if the property is a selection item. | |
| 97 bool is_selection_item_checked; // true if |is_selection_item| is true and | |
| 98 // the selection_item is selected. | |
| 99 int selection_item_id; // A group ID (>= 0) of the selection item. | |
| 100 // kInvalidSelectionItemId if |is_selection_item| is | |
| 101 // false. | |
| 102 static const int kInvalidSelectionItemId = -1; | |
| 103 }; | |
| 104 typedef std::vector<InputMethodProperty> InputMethodPropertyList; | 23 typedef std::vector<InputMethodProperty> InputMethodPropertyList; |
| 105 | |
| 106 // A structure which represents a value of an input method configuration item. | |
| 107 // This struct is used by SetInputMethodConfig(). | |
| 108 struct InputMethodConfigValue { | |
| 109 InputMethodConfigValue(); | |
| 110 ~InputMethodConfigValue(); | |
| 111 | |
| 112 // Debug print function. | |
| 113 std::string ToString() const; | |
| 114 | |
| 115 enum ValueType { | |
| 116 kValueTypeString = 0, | |
| 117 kValueTypeInt, | |
| 118 kValueTypeBool, | |
| 119 kValueTypeStringList, | |
| 120 }; | |
| 121 | |
| 122 // A value is stored on |string_value| member if |type| is kValueTypeString. | |
| 123 // The same is true for other enum values. | |
| 124 ValueType type; | |
| 125 | |
| 126 std::string string_value; | |
| 127 int int_value; | |
| 128 bool bool_value; | |
| 129 std::vector<std::string> string_list_value; | |
| 130 }; | |
| 131 | |
| 132 typedef std::vector<std::pair<double, double> > HandwritingStroke; | 24 typedef std::vector<std::pair<double, double> > HandwritingStroke; |
| 133 | 25 |
| 134 // IBusController is used to interact with the IBus daemon. | 26 // IBusController is used to interact with the IBus daemon. |
| 135 class IBusController { | 27 class IBusController { |
| 136 public: | 28 public: |
| 137 class Observer { | 29 class Observer { |
| 138 public: | 30 public: |
| 139 virtual ~Observer() {} | 31 virtual ~Observer() {} |
| 140 | 32 |
| 141 // Called when current input method is changed by a user. | 33 // Called when current input method is changed by a user. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 virtual void CancelHandwriting(int n_strokes) = 0; | 138 virtual void CancelHandwriting(int n_strokes) = 0; |
| 247 | 139 |
| 248 // Creates an InputMethodDescriptor object. |raw_layout| is a comma-separated | 140 // Creates an InputMethodDescriptor object. |raw_layout| is a comma-separated |
| 249 // list of XKB and virtual keyboard layouts. | 141 // list of XKB and virtual keyboard layouts. |
| 250 // (e.g. "special-us-virtual-keyboard-for-the-input-method,us") | 142 // (e.g. "special-us-virtual-keyboard-for-the-input-method,us") |
| 251 virtual InputMethodDescriptor CreateInputMethodDescriptor( | 143 virtual InputMethodDescriptor CreateInputMethodDescriptor( |
| 252 const std::string& id, | 144 const std::string& id, |
| 253 const std::string& name, | 145 const std::string& name, |
| 254 const std::string& raw_layout, | 146 const std::string& raw_layout, |
| 255 const std::string& language_code) = 0; | 147 const std::string& language_code) = 0; |
| 256 | |
| 257 // Gets all input method engines that are supported, including ones not | |
| 258 // active. Caller has to delete the returned list. This function never | |
| 259 // returns NULL. | |
| 260 virtual InputMethodDescriptors* GetSupportedInputMethods() = 0; | |
| 261 | |
| 262 // | |
| 263 // FUNCTIONS BELOW ARE ONLY FOR UNIT TESTS. DO NOT USE THEM. | |
| 264 // | |
| 265 // Returns true if |input_method_id| is whitelisted. | |
| 266 virtual bool InputMethodIdIsWhitelisted( | |
| 267 const std::string& input_method_id) = 0; | |
| 268 // Returns true if |xkb_layout| is supported. | |
| 269 virtual bool XkbLayoutIsSupported(const std::string& xkb_layout) = 0; | |
| 270 }; | 148 }; |
| 271 | 149 |
| 272 } // namespace input_method | 150 } // namespace input_method |
| 273 } // namespace chromeos | 151 } // namespace chromeos |
| 274 | 152 |
| 275 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ | 153 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_ |
| OLD | NEW |