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. 4 5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_INPUT_CONTEXT_CLIENT_H_ 6 #define CHROMEOS_DBUS_IBUS_IBUS_INPUT_CONTEXT_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/bind.h" 11 #include "base/callback.h" 12 #include "chromeos/chromeos_export.h" 13 #include "chromeos/dbus/dbus_client_implementation_type.h" 14 #include "chromeos/dbus/ibus/ibus_constants.h" 15 #include "dbus/object_path.h" 16 17 namespace dbus { 18 class Bus; 19 } // namespace dbus 20 21 namespace chromeos { 22 23 class IBusText; 24 25 class CHROMEOS_EXPORT IBusInputContextHandlerInterface { 26 public: 27 // Called when the engine commit a text. 28 virtual void CommitText(const IBusText& text) = 0; 29 30 // Called when the engine forward a key event. 31 virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode, uint32 state) = 0; 32 33 // Called when the engine update preedit stroing. 34 virtual void UpdatePreeditText(const IBusText& text, 35 uint32 cursor_pos, 36 bool visible) = 0; 37 38 // Called when the engine request showing preedit string. 39 virtual void ShowPreeditText() = 0; 40 41 // Called when the engine request hiding preedit string. 42 virtual void HidePreeditText() = 0; 43 44 // Called when the engine request deleting surrounding string. 45 virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0; 46 }; 47 48 // A class to make the actual DBus calls for IBusInputContext service. 49 // The ibus-daemon creates object paths on demand, so the target object path is 50 // not determined before calling CreateInputContext. It is good to initialize 51 // this class at the callback from CreateInputContext in IBusClient. This class 52 // is managed by DBusThreadManager as singleton instance, so we can handle only 53 // one input context but it is enough for ChromeOS. 54 class CHROMEOS_EXPORT IBusInputContextClient { 55 public: 56 typedef base::Callback<void(const ibus::Rect& cursor_location, 57 const ibus::Rect& composition_head)> 58 SetCursorLocationHandler; 59 typedef base::Callback<void(bool is_keyevent_used)> ProcessKeyEventCallback; 60 typedef base::Callback<void()> ErrorCallback; 61 62 virtual ~IBusInputContextClient(); 63 64 // Creates object proxy and connects signals. 65 virtual void Initialize(dbus::Bus* bus, 66 const dbus::ObjectPath& object_path) = 0; 67 68 // Sets input context handler. This function can be called multiple times and 69 // also can be passed |handler| as NULL. Caller must release |handler|. 70 virtual void SetInputContextHandler( 71 IBusInputContextHandlerInterface* handler) = 0; 72 73 // Sets SetCursorLocation handler. 74 virtual void SetSetCursorLocationHandler( 75 const SetCursorLocationHandler& set_cursor_location_handler) = 0; 76 77 // Unset SetCursorLocation handler. 78 virtual void UnsetSetCursorLocationHandler() = 0; 79 80 // Resets object proxy. If you want to use InputContext again, should call 81 // Initialize function again. 82 virtual void ResetObjectProxy() = 0; 83 84 // Returns true if the object proxy is ready to communicate with ibus-daemon, 85 // otherwise return false. 86 virtual bool IsObjectProxyReady() const = 0; 87 88 // Invokes SetCapabilities method call. 89 virtual void SetCapabilities(uint32 capability) = 0; 90 // Invokes FocusIn method call. 91 virtual void FocusIn() = 0; 92 // Invokes FocusOut method call. 93 virtual void FocusOut() = 0; 94 // Invokes Reset method call. 95 virtual void Reset() = 0; 96 // Invokes SetCursorLocation method call. 97 virtual void SetCursorLocation(const ibus::Rect& cursor_location, 98 const ibus::Rect& composition_head) = 0; 99 // Invokes ProcessKeyEvent method call. |callback| should not be null. 100 virtual void ProcessKeyEvent(uint32 keyval, 101 uint32 keycode, 102 uint32 state, 103 const ProcessKeyEventCallback& callback, 104 const ErrorCallback& error_callback) = 0; 105 106 // Invokes SetSurroundingText method call. |start_index| is inclusive and 107 // |end_index| is exclusive. 108 virtual void SetSurroundingText(const std::string& text, 109 uint32 start_index, 110 uint32 end_index) = 0; 111 112 // Invokes PropertyActivate method call. The PROP_STATE_INCONSISTENT in 113 // original IBus spec is not supported in Chrome. 114 virtual void PropertyActivate(const std::string& key, 115 ibus::IBusPropertyState state) = 0; 116 117 // Returns true if the current input method is XKB layout. 118 virtual bool IsXKBLayout() = 0; 119 120 // Sets current input method is XKB layout or not. 121 virtual void SetIsXKBLayout(bool is_xkb_layout) = 0; 122 123 // Factory function, creates a new instance and returns ownership. 124 // For normal usage, access the singleton via DBusThreadManager::Get(). 125 static CHROMEOS_EXPORT IBusInputContextClient* Create( 126 DBusClientImplementationType type); 127 128 protected: 129 // Create() should be used instead. 130 IBusInputContextClient(); 131 132 private: 133 DISALLOW_COPY_AND_ASSIGN(IBusInputContextClient); 134 }; 135 136 } // namespace chromeos 137 138 #endif // CHROMEOS_DBUS_IBUS_IBUS_INPUT_CONTEXT_CLIENT_H_ 139