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
;
24 namespace input_method
{
25 struct InputMethodProperty
;
26 struct KeyEventHandle
;
27 } // namespace input_method
29 class InputMethodEngine
: public InputMethodEngineInterface
{
33 virtual ~InputMethodEngine();
36 InputMethodEngineInterface::Observer
* observer
,
37 const char* engine_name
,
38 const char* extension_id
,
39 const char* engine_id
,
40 const std::vector
<std::string
>& languages
,
41 const std::vector
<std::string
>& layouts
,
42 const GURL
& options_page
,
43 const GURL
& input_view
);
45 // InputMethodEngineInterface overrides.
46 virtual const input_method::InputMethodDescriptor
& GetDescriptor()
48 virtual void StartIme() OVERRIDE
;
49 virtual bool SetComposition(int context_id
,
54 const std::vector
<SegmentInfo
>& segments
,
55 std::string
* error
) OVERRIDE
;
56 virtual bool ClearComposition(int context_id
, std::string
* error
) OVERRIDE
;
57 virtual bool CommitText(int context_id
, const char* text
,
58 std::string
* error
) OVERRIDE
;
59 virtual bool SendKeyEvents(int context_id
,
60 const std::vector
<KeyboardEvent
>& events
) OVERRIDE
;
61 virtual const CandidateWindowProperty
&
62 GetCandidateWindowProperty() const OVERRIDE
;
63 virtual void SetCandidateWindowProperty(
64 const CandidateWindowProperty
& property
) OVERRIDE
;
65 virtual bool SetCandidateWindowVisible(bool visible
,
66 std::string
* error
) OVERRIDE
;
67 virtual bool SetCandidates(int context_id
,
68 const std::vector
<Candidate
>& candidates
,
69 std::string
* error
) OVERRIDE
;
70 virtual bool SetCursorPosition(int context_id
, int candidate_id
,
71 std::string
* error
) OVERRIDE
;
72 virtual bool SetMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
73 virtual bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) OVERRIDE
;
74 virtual bool IsActive() const OVERRIDE
;
75 virtual void KeyEventDone(input_method::KeyEventHandle
* key_data
,
76 bool handled
) OVERRIDE
;
77 virtual bool DeleteSurroundingText(int context_id
,
79 size_t number_of_chars
,
80 std::string
* error
) OVERRIDE
;
82 // IBusEngineHandlerInterface overrides.
84 const IBusEngineHandlerInterface::InputContext
& input_context
) OVERRIDE
;
85 virtual void FocusOut() OVERRIDE
;
86 virtual void Enable() OVERRIDE
;
87 virtual void Disable() OVERRIDE
;
88 virtual void PropertyActivate(const std::string
& property_name
) OVERRIDE
;
89 virtual void Reset() OVERRIDE
;
90 virtual void ProcessKeyEvent(const ui::KeyEvent
& key_event
,
91 const KeyEventDoneCallback
& callback
) OVERRIDE
;
92 virtual void CandidateClicked(uint32 index
) OVERRIDE
;
93 virtual void SetSurroundingText(const std::string
& text
, uint32 cursor_pos
,
94 uint32 anchor_pos
) OVERRIDE
;
95 virtual void HideInputView() OVERRIDE
;
98 // Converts MenuItem to InputMethodProperty.
99 void MenuItemToProperty(const MenuItem
& item
,
100 input_method::InputMethodProperty
* property
);
102 // Descriptor of this input method.
103 input_method::InputMethodDescriptor descriptor_
;
105 // True if the current context has focus.
108 // True if this engine is active.
111 // ID that is used for the current input context. False if there is no focus.
114 // Next id that will be assigned to a context.
115 int next_context_id_
;
117 // This IME ID in Chrome Extension.
118 std::string engine_id_
;
120 // This IME ID in InputMethodManager.
123 // Pointer to the object recieving events for this IME.
124 InputMethodEngineInterface::Observer
* observer_
;
126 // The current preedit text, and it's cursor position.
127 scoped_ptr
<IBusText
> preedit_text_
;
130 // The current candidate window.
131 scoped_ptr
<ui::CandidateWindow
> candidate_window_
;
133 // The current candidate window property.
134 CandidateWindowProperty candidate_window_property_
;
136 // Indicates whether the candidate window is visible.
137 bool window_visible_
;
139 // Mapping of candidate index to candidate id.
140 std::vector
<int> candidate_ids_
;
142 // Mapping of candidate id to index.
143 std::map
<int, int> candidate_indexes_
;
145 // Used for input view window.
146 GURL input_view_url_
;
149 } // namespace chromeos
151 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_