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 CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_
6 #define CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_vector.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client_implementation_type.h"
14 #include "chromeos/dbus/ibus/ibus_constants.h"
23 class IBusLookupTable
;
26 typedef ScopedVector
<IBusProperty
> IBusPropertyList
;
28 // A interface to handle the engine handler method call.
29 class CHROMEOS_EXPORT IBusEngineHandlerInterface
{
31 typedef base::Callback
<void (bool consumed
)> KeyEventDoneCallback
;
33 // Following capability mask is introduced from
34 // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusCapabilite
35 // TODO(nona): Move to ibus_contants and merge one in ui/base/ime/*
37 IBUS_CAPABILITY_PREEDIT_TEXT
= 1U,
38 IBUS_CAPABILITY_FOCUS
= 8U,
41 virtual ~IBusEngineHandlerInterface() {}
43 // Called when the Chrome input field get the focus.
44 virtual void FocusIn() = 0;
46 // Called when the Chrome input field lose the focus.
47 virtual void FocusOut() = 0;
49 // Called when the IME is enabled.
50 virtual void Enable() = 0;
52 // Called when the IME is disabled.
53 virtual void Disable() = 0;
55 // Called when a property is activated or changed.
56 virtual void PropertyActivate(const std::string
& property_name
,
57 ibus::IBusPropertyState property_state
) = 0;
59 // Called when a property is shown.
60 virtual void PropertyShow(const std::string
& property_name
) = 0;
62 // Called when a property is hidden.
63 virtual void PropertyHide(const std::string
& property_name
) = 0;
65 // Called when the Chrome input field set their capabilities.
66 virtual void SetCapability(IBusCapability capability
) = 0;
68 // Called when the IME is reset.
69 virtual void Reset() = 0;
71 // Called when the key event is received. The |keycode| is raw layout
72 // independent keycode. The |keysym| is result of XLookupString function
73 // which translate |keycode| to keyboard layout dependent symbol value.
74 // Actual implementation must call |callback| after key event handling.
75 // For example: key press event for 'd' key on us layout and dvorak layout.
76 // keyval keycode state
77 // us layout : 0x64 0x20 0x00
78 // dvorak layout : 0x65 0x20 0x00
79 virtual void ProcessKeyEvent(uint32 keysym
, uint32 keycode
, uint32 state
,
80 const KeyEventDoneCallback
& callback
) = 0;
82 // Called when the candidate in lookup table is clicked. The |index| is 0
83 // based candidate index in lookup table. The |state| is same value as
85 // http://developer.gnome.org/gdk/stable/gdk-Windows.html#GdkModifierType
86 virtual void CandidateClicked(uint32 index
, ibus::IBusMouseButton button
,
89 // Called when a new surrounding text is set. The |text| is surrounding text
90 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is
91 // selection range, |anchor_pos| represents opposite index from |cursor_pos|.
92 // Otherwise |anchor_pos| is equal to |cursor_pos|.
93 virtual void SetSurroundingText(const std::string
& text
, uint32 cursor_pos
,
94 uint32 anchor_pos
) = 0;
97 IBusEngineHandlerInterface() {}
100 // A class to make the actual DBus method call handling for IBusEngine service.
101 // The exported method call is used by ibus-demon to process key event, because
102 // Chrome works engine service if the extension IME is enabled. This class is
103 // managed by DBusThreadManager.
104 class CHROMEOS_EXPORT IBusEngineService
{
106 // Following value should be same in
107 // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusPreeditFocusMode
108 enum IBusEnginePreeditFocusOutMode
{
109 IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_CLEAR
= 0,
110 IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT
= 1,
113 virtual ~IBusEngineService();
115 // Sets a new IBus engine handler and old handler will be overridden.
116 // This class doesn't take the ownership of |handler|.
117 virtual void SetEngine(IBusEngineHandlerInterface
* handler
) = 0;
119 // Unsets the current IBus engine handler.
120 virtual void UnsetEngine() = 0;
122 // Emits RegisterProperties signal.
123 virtual void RegisterProperties(
124 const IBusPropertyList
& property_list
) = 0;
125 // Emits UpdatePreedit signal.
126 virtual void UpdatePreedit(const IBusText
& ibus_text
,
129 IBusEnginePreeditFocusOutMode mode
) = 0;
130 // Emits UpdateAuxiliaryText signal.
131 virtual void UpdateAuxiliaryText(const IBusText
& ibus_text
,
132 bool is_visible
) = 0;
133 // Emits UpdateLookupTable signal.
134 virtual void UpdateLookupTable(const IBusLookupTable
& lookup_table
,
135 bool is_visible
) = 0;
136 // Emits UpdateProperty signal.
137 virtual void UpdateProperty(const IBusProperty
& property
) = 0;
138 // Emits ForwardKeyEvent signal.
139 virtual void ForwardKeyEvent(uint32 keyval
, uint32 keycode
, uint32 state
) = 0;
140 // Emits RequireSurroundingText signal.
141 virtual void RequireSurroundingText() = 0;
142 // Emits CommitText signal.
143 virtual void CommitText(const std::string
& text
) = 0;
145 // Factory function, creates a new instance and returns ownership.
146 // For normal usage, access the singleton via DBusThreadManager::Get().
147 static CHROMEOS_EXPORT IBusEngineService
* Create(
148 DBusClientImplementationType type
,
150 const dbus::ObjectPath
& object_path
);
153 // Create() should be used instead.
157 DISALLOW_COPY_AND_ASSIGN(IBusEngineService
);
160 } // namespace chromeos
162 #endif // CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_