Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / input_method_engine.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
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"
14 #include "url/gurl.h"
15
16 class Profile;
17
18 namespace ui {
19 class CandidateWindow;
20 class KeyEvent;
21 }  // namespace ui
22
23 namespace ash {
24 namespace ime {
25 struct InputMethodMenuItem;
26 }  // namespace ime
27 }  // namespace ash
28
29 namespace chromeos {
30
31 class CompositionText;
32
33 namespace input_method {
34 struct KeyEventHandle;
35 }  // namespace input_method
36
37 class InputMethodEngine : public InputMethodEngineInterface {
38  public:
39   InputMethodEngine();
40
41   virtual ~InputMethodEngine();
42
43   void Initialize(scoped_ptr<InputMethodEngineInterface::Observer> observer,
44                   const char* extension_id);
45
46   // InputMethodEngineInterface overrides.
47   virtual const std::string& GetActiveComponentId() const override;
48   virtual bool SetComposition(int context_id,
49                               const char* text,
50                               int selection_start,
51                               int selection_end,
52                               int cursor,
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,
75                                      int offset,
76                                      size_t number_of_chars,
77                                      std::string* error) override;
78
79   // IMEEngineHandlerInterface overrides.
80   virtual void FocusIn(
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;
94
95   int GetCotextIdForTesting() { return context_id_; }
96
97  private:
98   // Converts MenuItem to InputMethodMenuItem.
99   void MenuItemToProperty(const MenuItem& item,
100                           ash::ime::InputMethodMenuItem* property);
101
102   // Enables overriding input view page to Virtual Keyboard window.
103   void EnableInputView();
104
105   ui::TextInputType current_input_type_;
106
107   // ID that is used for the current input context.  False if there is no focus.
108   int context_id_;
109
110   // Next id that will be assigned to a context.
111   int next_context_id_;
112
113   // The input_component ID in IME extension's manifest.
114   std::string active_component_id_;
115
116   // The IME extension ID.
117   std::string extension_id_;
118
119   // The observer object recieving events for this IME.
120   scoped_ptr<InputMethodEngineInterface::Observer> observer_;
121
122   // The current preedit text, and it's cursor position.
123   scoped_ptr<CompositionText> composition_text_;
124   int composition_cursor_;
125
126   // The current candidate window.
127   scoped_ptr<ui::CandidateWindow> candidate_window_;
128
129   // The current candidate window property.
130   CandidateWindowProperty candidate_window_property_;
131
132   // Indicates whether the candidate window is visible.
133   bool window_visible_;
134
135   // Mapping of candidate index to candidate id.
136   std::vector<int> candidate_ids_;
137
138   // Mapping of candidate id to index.
139   std::map<int, int> candidate_indexes_;
140
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_;
144 };
145
146 }  // namespace chromeos
147
148 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_