1 // Copyright 2013 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_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_
11 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
12 #include "chromeos/ime/input_method_descriptor.h"
16 class CandidateWindow
;
22 struct InputMethodMenuItem
;
28 class CompositionText
;
30 namespace input_method
{
31 struct KeyEventHandle
;
32 } // namespace input_method
34 class InputMethodEngine
: public InputMethodEngineInterface
{
38 virtual ~InputMethodEngine();
40 void Initialize(scoped_ptr
<InputMethodEngineInterface::Observer
> observer
,
41 const char* engine_name
,
42 const char* extension_id
,
43 const char* engine_id
,
44 const std::vector
<std::string
>& languages
,
45 const std::vector
<std::string
>& layouts
,
46 const GURL
& options_page
,
47 const GURL
& input_view
);
49 // InputMethodEngineInterface overrides.
50 virtual const input_method::InputMethodDescriptor
& GetDescriptor()
52 virtual void NotifyImeReady() OVERRIDE
;
53 virtual bool SetComposition(int context_id
,
58 const std::vector
<SegmentInfo
>& segments
,
59 std::string
* error
) OVERRIDE
;
60 virtual bool ClearComposition(int context_id
, std::string
* error
) OVERRIDE
;
61 virtual bool CommitText(int context_id
, const char* text
,
62 std::string
* error
) OVERRIDE
;
63 virtual bool SendKeyEvents(int context_id
,
64 const std::vector
<KeyboardEvent
>& events
) OVERRIDE
;
65 virtual const CandidateWindowProperty
&
66 GetCandidateWindowProperty() const OVERRIDE
;
67 virtual void SetCandidateWindowProperty(
68 const CandidateWindowProperty
& property
) OVERRIDE
;
69 virtual bool SetCandidateWindowVisible(bool visible
,
70 std::string
* error
) OVERRIDE
;
71 virtual bool SetCandidates(int context_id
,
72 const std::vector
<Candidate
>& candidates
,
73 std::string
* error
) OVERRIDE
;
74 virtual bool SetCursorPosition(int context_id
, int candidate_id
,
75 std::string
* error
) OVERRIDE
;
76 virtual bool SetMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
77 virtual bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
78 virtual bool IsActive() const OVERRIDE
;
79 virtual void KeyEventDone(input_method::KeyEventHandle
* key_data
,
80 bool handled
) OVERRIDE
;
81 virtual bool DeleteSurroundingText(int context_id
,
83 size_t number_of_chars
,
84 std::string
* error
) OVERRIDE
;
86 // IMEEngineHandlerInterface overrides.
88 const IMEEngineHandlerInterface::InputContext
& input_context
) OVERRIDE
;
89 virtual void FocusOut() OVERRIDE
;
90 virtual void Enable() OVERRIDE
;
91 virtual void Disable() OVERRIDE
;
92 virtual void PropertyActivate(const std::string
& property_name
) OVERRIDE
;
93 virtual void Reset() OVERRIDE
;
94 virtual void ProcessKeyEvent(const ui::KeyEvent
& key_event
,
95 const KeyEventDoneCallback
& callback
) OVERRIDE
;
96 virtual void CandidateClicked(uint32 index
) OVERRIDE
;
97 virtual void SetSurroundingText(const std::string
& text
, uint32 cursor_pos
,
98 uint32 anchor_pos
) OVERRIDE
;
99 virtual void HideInputView() OVERRIDE
;
102 // Converts MenuItem to InputMethodMenuItem.
103 void MenuItemToProperty(const MenuItem
& item
,
104 ash::ime::InputMethodMenuItem
* property
);
106 // Descriptor of this input method.
107 input_method::InputMethodDescriptor descriptor_
;
109 // True if the current context has focus.
112 // True if this engine is active.
115 // ID that is used for the current input context. False if there is no focus.
118 // Next id that will be assigned to a context.
119 int next_context_id_
;
121 // This IME ID in Chrome Extension.
122 std::string engine_id_
;
124 // This IME's Chrome Extension ID.
125 std::string extension_id_
;
127 // This IME ID in InputMethodManager.
130 // The observer object recieving events for this IME.
131 scoped_ptr
<InputMethodEngineInterface::Observer
> observer_
;
133 // The current preedit text, and it's cursor position.
134 scoped_ptr
<CompositionText
> composition_text_
;
135 int composition_cursor_
;
137 // The current candidate window.
138 scoped_ptr
<ui::CandidateWindow
> candidate_window_
;
140 // The current candidate window property.
141 CandidateWindowProperty candidate_window_property_
;
143 // Indicates whether the candidate window is visible.
144 bool window_visible_
;
146 // Mapping of candidate index to candidate id.
147 std::vector
<int> candidate_ids_
;
149 // Mapping of candidate id to index.
150 std::map
<int, int> candidate_indexes_
;
152 // Used for input view window.
153 GURL input_view_url_
;
155 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event
156 // sent to ProcessKeyEvent is sent by SendKeyEvents.
157 const ui::KeyEvent
* sent_key_event_
;
160 } // namespace chromeos
162 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_