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 "chromeos/ime/input_method_descriptor.h"
19 class CandidateWindow;
25 struct InputMethodMenuItem;
31 class CompositionText;
33 namespace input_method {
34 struct KeyEventHandle;
35 } // namespace input_method
37 class InputMethodEngine : public InputMethodEngineInterface {
41 virtual ~InputMethodEngine();
43 void Initialize(scoped_ptr<InputMethodEngineInterface::Observer> observer,
44 const char* extension_id);
46 // InputMethodEngineInterface overrides.
47 virtual const std::string& GetActiveComponentId() const override;
48 virtual bool SetComposition(int context_id,
53 const std::vector<SegmentInfo>& segments,
54 std::string* error) override;
55 virtual bool ClearComposition(int context_id, std::string* error) override;
56 virtual bool CommitText(int context_id, const char* text,
57 std::string* error) override;
58 virtual bool SendKeyEvents(int context_id,
59 const std::vector<KeyboardEvent>& events) override;
60 virtual const CandidateWindowProperty&
61 GetCandidateWindowProperty() const override;
62 virtual void SetCandidateWindowProperty(
63 const CandidateWindowProperty& property) override;
64 virtual bool SetCandidateWindowVisible(bool visible,
65 std::string* error) override;
66 virtual bool SetCandidates(int context_id,
67 const std::vector<Candidate>& candidates,
68 std::string* error) override;
69 virtual bool SetCursorPosition(int context_id, int candidate_id,
70 std::string* error) override;
71 virtual bool SetMenuItems(const std::vector<MenuItem>& items) override;
72 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) override;
73 virtual bool IsActive() const override;
74 virtual bool DeleteSurroundingText(int context_id,
76 size_t number_of_chars,
77 std::string* error) override;
79 // IMEEngineHandlerInterface overrides.
81 const IMEEngineHandlerInterface::InputContext& input_context) override;
82 virtual void FocusOut() override;
83 virtual void Enable(const std::string& component_id) override;
84 virtual void Disable() override;
85 virtual void PropertyActivate(const std::string& property_name) override;
86 virtual void Reset() override;
87 virtual void ProcessKeyEvent(const ui::KeyEvent& key_event,
88 const KeyEventDoneCallback& callback) override;
89 virtual void CandidateClicked(uint32 index) override;
90 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos,
91 uint32 anchor_pos) override;
92 virtual void HideInputView() override;
93 virtual void SetCompositionBounds(const gfx::Rect& bounds) override;
95 int GetCotextIdForTesting() { return context_id_; }
98 // Converts MenuItem to InputMethodMenuItem.
99 void MenuItemToProperty(const MenuItem& item,
100 ash::ime::InputMethodMenuItem* property);
102 // Enables overriding input view page to Virtual Keyboard window.
103 void EnableInputView();
105 ui::TextInputType current_input_type_;
107 // ID that is used for the current input context. False if there is no focus.
110 // Next id that will be assigned to a context.
111 int next_context_id_;
113 // The input_component ID in IME extension's manifest.
114 std::string active_component_id_;
116 // The IME extension ID.
117 std::string extension_id_;
119 // The observer object recieving events for this IME.
120 scoped_ptr<InputMethodEngineInterface::Observer> observer_;
122 // The current preedit text, and it's cursor position.
123 scoped_ptr<CompositionText> composition_text_;
124 int composition_cursor_;
126 // The current candidate window.
127 scoped_ptr<ui::CandidateWindow> candidate_window_;
129 // The current candidate window property.
130 CandidateWindowProperty candidate_window_property_;
132 // Indicates whether the candidate window is visible.
133 bool window_visible_;
135 // Mapping of candidate index to candidate id.
136 std::vector<int> candidate_ids_;
138 // Mapping of candidate id to index.
139 std::map<int, int> candidate_indexes_;
141 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event
142 // sent to ProcessKeyEvent is sent by SendKeyEvents.
143 const ui::KeyEvent* sent_key_event_;
146 } // namespace chromeos
148 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_