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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_IBUS_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_IBUS_H_
11 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
12 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h"
13 #include "chromeos/dbus/ibus/ibus_engine_service.h"
14 #include "chromeos/ime/ibus_bridge.h"
15 #include "dbus/object_path.h"
22 class IBusEngineService;
23 namespace input_method {
24 class CandidateWindow;
25 struct KeyEventHandle;
26 } // namespace input_method
28 class InputMethodEngineIBus : public InputMethodEngine,
29 public IBusEngineHandlerInterface {
31 InputMethodEngineIBus();
33 virtual ~InputMethodEngineIBus();
36 InputMethodEngine::Observer* observer,
37 const char* engine_name,
38 const char* extension_id,
39 const char* engine_id,
40 const char* description,
41 const std::vector<std::string>& languages,
42 const std::vector<std::string>& layouts,
43 const GURL& options_page,
46 // InputMethodEngine overrides.
47 virtual void StartIme() OVERRIDE;
48 virtual bool SetComposition(int context_id,
53 const std::vector<SegmentInfo>& segments,
54 std::string* error) OVERRIDE;
55 virtual bool ClearComposition(int context_id, std::string* error) OVERRIDE;
56 virtual bool CommitText(int context_id, const char* text,
57 std::string* error) OVERRIDE;
58 virtual const CandidateWindowProperty&
59 GetCandidateWindowProperty() const OVERRIDE;
60 virtual void SetCandidateWindowProperty(
61 const CandidateWindowProperty& property) OVERRIDE;
62 virtual bool SetCandidateWindowVisible(bool visible,
63 std::string* error) OVERRIDE;
64 virtual void SetCandidateWindowAuxText(const char* text) OVERRIDE;
65 virtual void SetCandidateWindowAuxTextVisible(bool visible) OVERRIDE;
66 virtual bool SetCandidates(int context_id,
67 const std::vector<Candidate>& candidates,
68 std::string* error) OVERRIDE;
69 virtual bool SetCursorPosition(int context_id, int candidate_id,
70 std::string* error) OVERRIDE;
71 virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
72 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE;
73 virtual bool IsActive() const OVERRIDE;
74 virtual void KeyEventDone(input_method::KeyEventHandle* key_data,
75 bool handled) OVERRIDE;
76 virtual bool DeleteSurroundingText(int context_id,
78 size_t number_of_chars,
79 std::string* error) OVERRIDE;
81 // IBusEngineHandlerInterface overrides.
82 virtual void FocusIn(ibus::TextInputType text_input_type) OVERRIDE;
83 virtual void FocusOut() OVERRIDE;
84 virtual void Enable() OVERRIDE;
85 virtual void Disable() OVERRIDE;
86 virtual void PropertyActivate(const std::string& property_name) OVERRIDE;
87 virtual void PropertyShow(const std::string& property_name) OVERRIDE;
88 virtual void PropertyHide(const std::string& property_name) OVERRIDE;
89 virtual void SetCapability(IBusCapability capability) OVERRIDE;
90 virtual void Reset() OVERRIDE;
91 virtual void ProcessKeyEvent(uint32 keysym, uint32 keycode, uint32 state,
92 const KeyEventDoneCallback& callback) OVERRIDE;
93 virtual void CandidateClicked(uint32 index, ibus::IBusMouseButton button,
94 uint32 state) OVERRIDE;
95 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos,
96 uint32 anchor_pos) OVERRIDE;
98 // Called when the connection with ibus-daemon is connected.
101 // Called whtn the connection with ibus-daemon is disconnected.
102 void OnDisconnected();
105 // Returns true if the connection to ibus-daemon is avaiable.
108 // Converts MenuItem to InputMethodProperty.
109 void MenuItemToProperty(const MenuItem& item,
110 input_method::InputMethodProperty* property);
112 // Registers the engine component.
113 void RegisterComponent();
115 // Called when the RegisterComponent is failed.
116 void OnComponentRegistrationFailed();
118 // Called when the RegisterComponent is succeeded.
119 void OnComponentRegistered();
121 // Called when the ibus-daemon sends CreateEngine message with corresponding
123 void CreateEngineHandler(
124 const IBusEngineFactoryService::CreateEngineResponseSender& sender);
126 // Returns current IBusEngineService, if there is no available service, this
127 // function returns NULL.
128 IBusEngineService* GetCurrentService();
130 // True if the current context has focus.
133 // True if this engine is active.
136 // ID that is used for the current input context. False if there is no focus.
139 // Next id that will be assigned to a context.
140 int next_context_id_;
142 // This IME ID in Chrome Extension.
143 std::string engine_id_;
145 // This IME ID in ibus.
146 std::string ibus_id_;
148 // The current object path.
149 dbus::ObjectPath object_path_;
151 // The current auxialy text and it's visiblity.
152 scoped_ptr<IBusText> aux_text_;
153 bool aux_text_visible_;
155 // Pointer to the object recieving events for this IME.
156 InputMethodEngine::Observer* observer_;
158 // The current preedit text, and it's cursor position.
159 scoped_ptr<IBusText> preedit_text_;
162 // The current engine component.
163 scoped_ptr<IBusComponent> component_;
165 // The current candidate window.
166 scoped_ptr<input_method::CandidateWindow> candidate_window_;
168 // The current candidate window property.
169 CandidateWindowProperty candidate_window_property_;
171 // Indicates whether the candidate window is visible.
172 bool window_visible_;
174 // Mapping of candidate index to candidate id.
175 std::vector<int> candidate_ids_;
177 // Mapping of candidate id to index.
178 std::map<int, int> candidate_indexes_;
180 // Used for making callbacks.
181 base::WeakPtrFactory<InputMethodEngineIBus> weak_ptr_factory_;
184 } // namespace chromeos
186 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_IBUS_H_