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
,
45 // InputMethodEngineInterface overrides.
46 const std::string
& GetActiveComponentId() const override
;
47 bool SetComposition(int context_id
,
52 const std::vector
<SegmentInfo
>& segments
,
53 std::string
* error
) override
;
54 bool ClearComposition(int context_id
, std::string
* error
) override
;
55 bool CommitText(int context_id
,
57 std::string
* error
) override
;
58 bool SendKeyEvents(int context_id
,
59 const std::vector
<KeyboardEvent
>& events
) override
;
60 const CandidateWindowProperty
& GetCandidateWindowProperty() const override
;
61 void SetCandidateWindowProperty(
62 const CandidateWindowProperty
& property
) override
;
63 bool SetCandidateWindowVisible(bool visible
, std::string
* error
) override
;
64 bool SetCandidates(int context_id
,
65 const std::vector
<Candidate
>& candidates
,
66 std::string
* error
) override
;
67 bool SetCursorPosition(int context_id
,
69 std::string
* error
) override
;
70 bool SetMenuItems(const std::vector
<MenuItem
>& items
) override
;
71 bool UpdateMenuItems(const std::vector
<MenuItem
>& items
) override
;
72 bool IsActive() const override
;
73 bool DeleteSurroundingText(int context_id
,
75 size_t number_of_chars
,
76 std::string
* error
) override
;
78 // IMEEngineHandlerInterface overrides.
80 const IMEEngineHandlerInterface::InputContext
& input_context
) override
;
81 void FocusOut() override
;
82 void Enable(const std::string
& component_id
) override
;
83 void Disable() override
;
84 void PropertyActivate(const std::string
& property_name
) override
;
85 void Reset() override
;
86 void ProcessKeyEvent(const ui::KeyEvent
& key_event
,
87 const KeyEventDoneCallback
& callback
) override
;
88 void CandidateClicked(uint32 index
) override
;
89 void SetSurroundingText(const std::string
& text
,
92 uint32 offset_pos
) override
;
93 void HideInputView() override
;
94 void SetCompositionBounds(const std::vector
<gfx::Rect
>& bounds
) override
;
96 int GetCotextIdForTesting() { return context_id_
; }
98 bool IsInterestedInKeyEvent() const override
;
101 bool CheckProfile() const;
102 // Converts MenuItem to InputMethodMenuItem.
103 void MenuItemToProperty(const MenuItem
& item
,
104 ui::ime::InputMethodMenuItem
* property
);
106 // Enables overriding input view page to Virtual Keyboard window.
107 void EnableInputView();
109 ui::TextInputType current_input_type_
;
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 // The input_component ID in IME extension's manifest.
118 std::string active_component_id_
;
120 // The IME extension ID.
121 std::string extension_id_
;
123 // The observer object recieving events for this IME.
124 scoped_ptr
<InputMethodEngineInterface::Observer
> observer_
;
126 // The current preedit text, and it's cursor position.
127 scoped_ptr
<CompositionText
> composition_text_
;
128 int composition_cursor_
;
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 with SendKeyEvents and ProcessKeyEvent to check if the key event
146 // sent to ProcessKeyEvent is sent by SendKeyEvents.
147 const ui::KeyEvent
* sent_key_event_
;
152 } // namespace chromeos
154 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_