1 // Copyright 2014 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 UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_
6 #define UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_
9 #include "base/basictypes.h"
10 #include "base/callback.h"
11 #include "base/strings/string16.h"
12 #include "ui/base/ime/text_input_mode.h"
13 #include "ui/base/ime/text_input_type.h"
14 #include "ui/base/ui_base_export.h"
21 class CandidateWindow;
27 class CompositionText;
29 class UI_BASE_EXPORT IMEInputContextHandlerInterface {
31 // Called when the engine commit a text.
32 virtual void CommitText(const std::string& text) = 0;
34 // Called when the engine updates composition text.
35 virtual void UpdateCompositionText(const CompositionText& text,
39 // Called when the engine request deleting surrounding string.
40 virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0;
44 // A interface to handle the engine handler method call.
45 class UI_BASE_EXPORT IMEEngineHandlerInterface {
47 typedef base::Callback<void (bool consumed)> KeyEventDoneCallback;
49 // A information about a focused text input field.
50 // A type of each member is based on the html spec, but InputContext can be
51 // used to specify about a non html text field like Omnibox.
53 InputContext(ui::TextInputType type_, ui::TextInputMode mode_, int flags_) :
54 type(type_), mode(mode_), flags(flags_) {}
56 // An attribute of the field defined at
57 // http://www.w3.org/TR/html401/interact/forms.html#input-control-types.
58 ui::TextInputType type;
59 // An attribute of the field defined at
60 // http://www.whatwg.org/specs/web-apps/current-work/multipage/
61 // association-of-controls-and-forms.html#input-modalities
62 // :-the-inputmode-attribute.
63 ui::TextInputMode mode;
64 // An antribute to indicate the flags for web input fields. Please refer to
69 virtual ~IMEEngineHandlerInterface() {}
71 // Called when the Chrome input field get the focus.
72 virtual void FocusIn(const InputContext& input_context) = 0;
74 // Called when the Chrome input field lose the focus.
75 virtual void FocusOut() = 0;
77 // Called when the IME is enabled.
78 virtual void Enable(const std::string& component_id) = 0;
80 // Called when the IME is disabled.
81 virtual void Disable() = 0;
83 // Called when a property is activated or changed.
84 virtual void PropertyActivate(const std::string& property_name) = 0;
86 // Called when the IME is reset.
87 virtual void Reset() = 0;
89 // Called when the key event is received.
90 // Actual implementation must call |callback| after key event handling.
91 virtual void ProcessKeyEvent(const ui::KeyEvent& key_event,
92 const KeyEventDoneCallback& callback) = 0;
94 // Called when the candidate in lookup table is clicked. The |index| is 0
95 // based candidate index in lookup table.
96 virtual void CandidateClicked(uint32 index) = 0;
98 // Called when a new surrounding text is set. The |text| is surrounding text
99 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is
100 // selection range, |anchor_pos| represents opposite index from |cursor_pos|.
101 // Otherwise |anchor_pos| is equal to |cursor_pos|.
102 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos,
103 uint32 anchor_pos) = 0;
105 // Called when the composition bounds changed.
106 virtual void SetCompositionBounds(const gfx::Rect& bounds) = 0;
109 IMEEngineHandlerInterface() {}
112 // A interface to handle the candidate window related method call.
113 class UI_BASE_EXPORT IMECandidateWindowHandlerInterface {
115 virtual ~IMECandidateWindowHandlerInterface() {}
117 // Called when the IME updates the lookup table.
118 virtual void UpdateLookupTable(const ui::CandidateWindow& candidate_window,
121 // Called when the IME updates the preedit text. The |text| is given in
123 virtual void UpdatePreeditText(const base::string16& text,
127 // Called when the application changes its caret bounds.
128 virtual void SetCursorBounds(const gfx::Rect& cursor_bounds,
129 const gfx::Rect& composition_head) = 0;
131 // Called when the text field's focus state is changed.
132 // |is_focused| is true when the text field gains the focus.
133 virtual void FocusStateChanged(bool is_focused) {}
136 IMECandidateWindowHandlerInterface() {}
140 // IMEBridge provides access of each IME related handler. This class
141 // is used for IME implementation.
142 class UI_BASE_EXPORT IMEBridge {
144 virtual ~IMEBridge();
146 // Allocates the global instance. Must be called before any calls to Get().
147 static void Initialize();
149 // Releases the global instance.
150 static void Shutdown();
152 // Returns IMEBridge global instance. Initialize() must be called first.
153 static IMEBridge* Get();
155 // Returns current InputContextHandler. This function returns NULL if input
156 // context is not ready to use.
157 virtual IMEInputContextHandlerInterface* GetInputContextHandler() const = 0;
159 // Updates current InputContextHandler. If there is no active input context,
160 // pass NULL for |handler|. Caller must release |handler|.
161 virtual void SetInputContextHandler(
162 IMEInputContextHandlerInterface* handler) = 0;
164 // Updates current EngineHandler. If there is no active engine service, pass
165 // NULL for |handler|. Caller must release |handler|.
166 virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) = 0;
168 // Returns current EngineHandler. This function returns NULL if current engine
169 // is not ready to use.
170 virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const = 0;
172 // Returns current CandidateWindowHandler. This function returns NULL if
173 // current candidate window is not ready to use.
174 virtual IMECandidateWindowHandlerInterface* GetCandidateWindowHandler()
177 // Updates current CandidatWindowHandler. If there is no active candidate
178 // window service, pass NULL for |handler|. Caller must release |handler|.
179 virtual void SetCandidateWindowHandler(
180 IMECandidateWindowHandlerInterface* handler) = 0;
182 // Updates current text input type.
183 virtual void SetCurrentTextInputType(ui::TextInputType input_type) = 0;
185 // Returns the current text input type.
186 virtual ui::TextInputType GetCurrentTextInputType() const = 0;
192 DISALLOW_COPY_AND_ASSIGN(IMEBridge);
195 } // namespace chromeos
197 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_