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 "base/time/time.h"
12 #include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
13 #include "ui/base/ime/chromeos/input_method_descriptor.h"
19 class CandidateWindow
;
23 struct InputMethodMenuItem
;
29 class CompositionText
;
31 namespace input_method
{
32 struct KeyEventHandle
;
33 } // namespace input_method
35 class InputMethodEngine
: public InputMethodEngineInterface
{
39 ~InputMethodEngine() override
;
41 void Initialize(scoped_ptr
<InputMethodEngineInterface::Observer
> observer
,
42 const char* extension_id
);
44 // InputMethodEngineInterface overrides.
45 const std::string
& GetActiveComponentId() const override
;
46 bool SetComposition(int context_id
,
51 const std::vector
<SegmentInfo
>& segments
,
52 std::string
* error
) override
;
53 bool ClearComposition(int context_id
, std::string
* error
) override
;
54 bool CommitText(int context_id
,
56 std::string
* error
) override
;
57 bool SendKeyEvents(int context_id
,
58 const std::vector
<KeyboardEvent
>& events
) override
;
59 const CandidateWindowProperty
& GetCandidateWindowProperty() const override
;
60 void SetCandidateWindowProperty(
61 const CandidateWindowProperty
& property
) override
;
62 bool SetCandidateWindowVisible(bool visible
, std::string
* error
) override
;
63 bool SetCandidates(int context_id
,
64 const std::vector
<Candidate
>& candidates
,
65 std::string
* error
) override
;
66 bool SetCursorPosition(int context_id
,
68 std::string
* error
) override
;
69 bool SetMenuItems(const std::vector
<MenuItem
>& items
) override
;
70 bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) override
;
71 bool IsActive() const override
;
72 bool DeleteSurroundingText(int context_id
,
74 size_t number_of_chars
,
75 std::string
* error
) override
;
77 // IMEEngineHandlerInterface overrides.
79 const IMEEngineHandlerInterface::InputContext
& input_context
) override
;
80 void FocusOut() override
;
81 void Enable(const std::string
& component_id
) override
;
82 void Disable() override
;
83 void PropertyActivate(const std::string
& property_name
) override
;
84 void Reset() override
;
85 void ProcessKeyEvent(const ui::KeyEvent
& key_event
,
86 const KeyEventDoneCallback
& callback
) override
;
87 void CandidateClicked(uint32 index
) override
;
88 void SetSurroundingText(const std::string
& text
,
90 uint32 anchor_pos
) override
;
91 void HideInputView() override
;
92 void SetCompositionBounds(const std::vector
<gfx::Rect
>& bounds
) override
;
94 int GetCotextIdForTesting() { return context_id_
; }
97 // Converts MenuItem to InputMethodMenuItem.
98 void MenuItemToProperty(const MenuItem
& item
,
99 ui::ime::InputMethodMenuItem
* property
);
101 // Enables overriding input view page to Virtual Keyboard window.
102 void EnableInputView();
104 ui::TextInputType current_input_type_
;
106 // ID that is used for the current input context. False if there is no focus.
109 // Next id that will be assigned to a context.
110 int next_context_id_
;
112 // The input_component ID in IME extension's manifest.
113 std::string active_component_id_
;
115 // The IME extension ID.
116 std::string extension_id_
;
118 // The observer object recieving events for this IME.
119 scoped_ptr
<InputMethodEngineInterface::Observer
> observer_
;
121 // The current preedit text, and it's cursor position.
122 scoped_ptr
<CompositionText
> composition_text_
;
123 int composition_cursor_
;
125 // The current candidate window.
126 scoped_ptr
<ui::CandidateWindow
> candidate_window_
;
128 // The current candidate window property.
129 CandidateWindowProperty candidate_window_property_
;
131 // Indicates whether the candidate window is visible.
132 bool window_visible_
;
134 // Mapping of candidate index to candidate id.
135 std::vector
<int> candidate_ids_
;
137 // Mapping of candidate id to index.
138 std::map
<int, int> candidate_indexes_
;
140 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event
141 // sent to ProcessKeyEvent is sent by SendKeyEvents.
142 const ui::KeyEvent
* sent_key_event_
;
145 } // namespace chromeos
147 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_