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"
20 class IBusLookupTable
;
23 class IBusEngineService
;
24 namespace input_method
{
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 bool SetCandidateWindowVisible(bool visible
,
59 std::string
* error
) OVERRIDE
;
60 virtual void SetCandidateWindowCursorVisible(bool visible
) OVERRIDE
;
61 virtual void SetCandidateWindowVertical(bool vertical
) OVERRIDE
;
62 virtual void SetCandidateWindowPageSize(int size
) OVERRIDE
;
63 virtual void SetCandidateWindowAuxText(const char* text
) OVERRIDE
;
64 virtual void SetCandidateWindowAuxTextVisible(bool visible
) OVERRIDE
;
65 virtual void SetCandidateWindowPosition(
66 CandidateWindowPosition position
) OVERRIDE
;
67 virtual bool SetCandidates(int context_id
,
68 const std::vector
<Candidate
>& candidates
,
69 std::string
* error
) OVERRIDE
;
70 virtual bool SetCursorPosition(int context_id
, int candidate_id
,
71 std::string
* error
) OVERRIDE
;
72 virtual bool SetMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
73 virtual bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
74 virtual bool IsActive() const OVERRIDE
;
75 virtual void KeyEventDone(input_method::KeyEventHandle
* key_data
,
76 bool handled
) OVERRIDE
;
77 virtual bool DeleteSurroundingText(int context_id
,
79 size_t number_of_chars
,
80 std::string
* error
) OVERRIDE
;
82 // IBusEngineHandlerInterface overrides.
83 virtual void FocusIn() OVERRIDE
;
84 virtual void FocusOut() OVERRIDE
;
85 virtual void Enable() OVERRIDE
;
86 virtual void Disable() OVERRIDE
;
87 virtual void PropertyActivate(
88 const std::string
& property_name
,
89 ibus::IBusPropertyState property_state
) OVERRIDE
;
90 virtual void PropertyShow(const std::string
& property_name
) OVERRIDE
;
91 virtual void PropertyHide(const std::string
& property_name
) OVERRIDE
;
92 virtual void SetCapability(IBusCapability capability
) OVERRIDE
;
93 virtual void Reset() OVERRIDE
;
94 virtual void ProcessKeyEvent(uint32 keysym
, uint32 keycode
, uint32 state
,
95 const KeyEventDoneCallback
& callback
) OVERRIDE
;
96 virtual void CandidateClicked(uint32 index
, ibus::IBusMouseButton button
,
97 uint32 state
) OVERRIDE
;
98 virtual void SetSurroundingText(const std::string
& text
, uint32 cursor_pos
,
99 uint32 anchor_pos
) OVERRIDE
;
101 // Called when the connection with ibus-daemon is connected.
104 // Called whtn the connection with ibus-daemon is disconnected.
105 void OnDisconnected();
108 // Returns true if the connection to ibus-daemon is avaiable.
111 // Converts MenuItem to IBusProperty.
112 bool MenuItemToProperty(const MenuItem
& item
, IBusProperty
* property
);
114 // Registers the engine component.
115 void RegisterComponent();
117 // Called when the RegisterComponent is failed.
118 void OnComponentRegistrationFailed();
120 // Called when the RegisterComponent is succeeded.
121 void OnComponentRegistered();
123 // Called when the ibus-daemon sends CreateEngine message with corresponding
125 void CreateEngineHandler(
126 const IBusEngineFactoryService::CreateEngineResponseSender
& sender
);
128 // Returns current IBusEngineService, if there is no available service, this
129 // function returns NULL.
130 IBusEngineService
* GetCurrentService();
132 // True if the current context has focus.
135 // True if this engine is active.
138 // ID that is used for the current input context. False if there is no focus.
141 // Next id that will be assigned to a context.
142 int next_context_id_
;
144 // This IME ID in Chrome Extension.
145 std::string engine_id_
;
147 // This IME ID in ibus.
148 std::string ibus_id_
;
150 // The current object path.
151 dbus::ObjectPath object_path_
;
153 // The current auxialy text and it's visiblity.
154 scoped_ptr
<IBusText
> aux_text_
;
155 bool aux_text_visible_
;
157 // Pointer to the object recieving events for this IME.
158 InputMethodEngine::Observer
* observer_
;
160 // The current preedit text, and it's cursor position.
161 scoped_ptr
<IBusText
> preedit_text_
;
164 // The current engine component.
165 scoped_ptr
<IBusComponent
> component_
;
167 // The current lookup table.
168 scoped_ptr
<IBusLookupTable
> table_
;
170 // Indicates whether the candidate window is visible.
171 bool window_visible_
;
173 // Mapping of candidate index to candidate id.
174 std::vector
<int> candidate_ids_
;
176 // Mapping of candidate id to index.
177 std::map
<int, int> candidate_indexes_
;
179 // Used for making callbacks.
180 base::WeakPtrFactory
<InputMethodEngineIBus
> weak_ptr_factory_
;
183 } // namespace chromeos
185 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_IBUS_H_