| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_ | |
| 6 #define UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_ | |
| 7 | |
| 8 #include <string> | |
| 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" | |
| 15 | |
| 16 namespace gfx { | |
| 17 class Rect; | |
| 18 } // namespace gfx | |
| 19 | |
| 20 namespace ui { | |
| 21 class CandidateWindow; | |
| 22 class KeyEvent; | |
| 23 } // namespace ui | |
| 24 | |
| 25 namespace chromeos { | |
| 26 | |
| 27 class CompositionText; | |
| 28 | |
| 29 class UI_BASE_EXPORT IMEInputContextHandlerInterface { | |
| 30 public: | |
| 31 // Called when the engine commit a text. | |
| 32 virtual void CommitText(const std::string& text) = 0; | |
| 33 | |
| 34 // Called when the engine updates composition text. | |
| 35 virtual void UpdateCompositionText(const CompositionText& text, | |
| 36 uint32 cursor_pos, | |
| 37 bool visible) = 0; | |
| 38 | |
| 39 // Called when the engine request deleting surrounding string. | |
| 40 virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0; | |
| 41 }; | |
| 42 | |
| 43 | |
| 44 // A interface to handle the engine handler method call. | |
| 45 class UI_BASE_EXPORT IMEEngineHandlerInterface { | |
| 46 public: | |
| 47 typedef base::Callback<void (bool consumed)> KeyEventDoneCallback; | |
| 48 | |
| 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. | |
| 52 struct InputContext { | |
| 53 InputContext(ui::TextInputType type_, ui::TextInputMode mode_) : | |
| 54 type(type_), mode(mode_) {} | |
| 55 | |
| 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 }; | |
| 65 | |
| 66 virtual ~IMEEngineHandlerInterface() {} | |
| 67 | |
| 68 // Called when the Chrome input field get the focus. | |
| 69 virtual void FocusIn(const InputContext& input_context) = 0; | |
| 70 | |
| 71 // Called when the Chrome input field lose the focus. | |
| 72 virtual void FocusOut() = 0; | |
| 73 | |
| 74 // Called when the IME is enabled. | |
| 75 virtual void Enable(const std::string& component_id) = 0; | |
| 76 | |
| 77 // Called when the IME is disabled. | |
| 78 virtual void Disable() = 0; | |
| 79 | |
| 80 // Called when a property is activated or changed. | |
| 81 virtual void PropertyActivate(const std::string& property_name) = 0; | |
| 82 | |
| 83 // Called when the IME is reset. | |
| 84 virtual void Reset() = 0; | |
| 85 | |
| 86 // Called when the key event is received. | |
| 87 // Actual implementation must call |callback| after key event handling. | |
| 88 virtual void ProcessKeyEvent(const ui::KeyEvent& key_event, | |
| 89 const KeyEventDoneCallback& callback) = 0; | |
| 90 | |
| 91 // Called when the candidate in lookup table is clicked. The |index| is 0 | |
| 92 // based candidate index in lookup table. | |
| 93 virtual void CandidateClicked(uint32 index) = 0; | |
| 94 | |
| 95 // Called when a new surrounding text is set. The |text| is surrounding text | |
| 96 // and |cursor_pos| is 0 based index of cursor position in |text|. If there is | |
| 97 // selection range, |anchor_pos| represents opposite index from |cursor_pos|. | |
| 98 // Otherwise |anchor_pos| is equal to |cursor_pos|. | |
| 99 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos, | |
| 100 uint32 anchor_pos) = 0; | |
| 101 | |
| 102 protected: | |
| 103 IMEEngineHandlerInterface() {} | |
| 104 }; | |
| 105 | |
| 106 // A interface to handle the candidate window related method call. | |
| 107 class UI_BASE_EXPORT IMECandidateWindowHandlerInterface { | |
| 108 public: | |
| 109 virtual ~IMECandidateWindowHandlerInterface() {} | |
| 110 | |
| 111 // Called when the IME updates the lookup table. | |
| 112 virtual void UpdateLookupTable(const ui::CandidateWindow& candidate_window, | |
| 113 bool visible) = 0; | |
| 114 | |
| 115 // Called when the IME updates the preedit text. The |text| is given in | |
| 116 // UTF-16 encoding. | |
| 117 virtual void UpdatePreeditText(const base::string16& text, | |
| 118 uint32 cursor_pos, | |
| 119 bool visible) = 0; | |
| 120 | |
| 121 // Called when the application changes its caret bounds. | |
| 122 virtual void SetCursorBounds(const gfx::Rect& cursor_bounds, | |
| 123 const gfx::Rect& composition_head) = 0; | |
| 124 | |
| 125 // Called when the text field's focus state is changed. | |
| 126 // |is_focused| is true when the text field gains the focus. | |
| 127 virtual void FocusStateChanged(bool is_focused) {} | |
| 128 | |
| 129 protected: | |
| 130 IMECandidateWindowHandlerInterface() {} | |
| 131 }; | |
| 132 | |
| 133 | |
| 134 // IMEBridge provides access of each IME related handler. This class | |
| 135 // is used for IME implementation. | |
| 136 class UI_BASE_EXPORT IMEBridge { | |
| 137 public: | |
| 138 virtual ~IMEBridge(); | |
| 139 | |
| 140 // Allocates the global instance. Must be called before any calls to Get(). | |
| 141 static void Initialize(); | |
| 142 | |
| 143 // Releases the global instance. | |
| 144 static void Shutdown(); | |
| 145 | |
| 146 // Returns IMEBridge global instance. Initialize() must be called first. | |
| 147 static IMEBridge* Get(); | |
| 148 | |
| 149 // Returns current InputContextHandler. This function returns NULL if input | |
| 150 // context is not ready to use. | |
| 151 virtual IMEInputContextHandlerInterface* GetInputContextHandler() const = 0; | |
| 152 | |
| 153 // Updates current InputContextHandler. If there is no active input context, | |
| 154 // pass NULL for |handler|. Caller must release |handler|. | |
| 155 virtual void SetInputContextHandler( | |
| 156 IMEInputContextHandlerInterface* handler) = 0; | |
| 157 | |
| 158 // Updates current EngineHandler. If there is no active engine service, pass | |
| 159 // NULL for |handler|. Caller must release |handler|. | |
| 160 virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) = 0; | |
| 161 | |
| 162 // Returns current EngineHandler. This function returns NULL if current engine | |
| 163 // is not ready to use. | |
| 164 virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const = 0; | |
| 165 | |
| 166 // Returns current CandidateWindowHandler. This function returns NULL if | |
| 167 // current candidate window is not ready to use. | |
| 168 virtual IMECandidateWindowHandlerInterface* GetCandidateWindowHandler() | |
| 169 const = 0; | |
| 170 | |
| 171 // Updates current CandidatWindowHandler. If there is no active candidate | |
| 172 // window service, pass NULL for |handler|. Caller must release |handler|. | |
| 173 virtual void SetCandidateWindowHandler( | |
| 174 IMECandidateWindowHandlerInterface* handler) = 0; | |
| 175 | |
| 176 // Updates current text input type. | |
| 177 virtual void SetCurrentTextInputType(ui::TextInputType input_type) = 0; | |
| 178 | |
| 179 // Returns the current text input type. | |
| 180 virtual ui::TextInputType GetCurrentTextInputType() const = 0; | |
| 181 | |
| 182 protected: | |
| 183 IMEBridge(); | |
| 184 | |
| 185 private: | |
| 186 DISALLOW_COPY_AND_ASSIGN(IMEBridge); | |
| 187 }; | |
| 188 | |
| 189 } // namespace chromeos | |
| 190 | |
| 191 #endif // UI_BASE_IME_CHROMEOS_IME_BRIDGE_H_ | |
| OLD | NEW |