input_method_engine.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 "chrome/browser/chromeos/input_method/input_method_engine_interface.h" 12#include "chromeos/ime/input_method_descriptor.h" 13#include "url/gurl.h" 14 15namespace ui { 16class CandidateWindow; 17class KeyEvent; 18} // namespace ui 19 20namespace ash { 21namespace ime { 22struct InputMethodMenuItem; 23} // namespace ime 24} // namespace ash 25 26namespace chromeos { 27 28class CompositionText; 29 30namespace input_method { 31struct KeyEventHandle; 32} // namespace input_method 33 34class InputMethodEngine : public InputMethodEngineInterface { 35 public: 36 InputMethodEngine(); 37 38 virtual ~InputMethodEngine(); 39 40 void Initialize(scoped_ptr<InputMethodEngineInterface::Observer> observer, 41 const char* engine_name, 42 const char* extension_id, 43 const char* engine_id, 44 const std::vector<std::string>& languages, 45 const std::vector<std::string>& layouts, 46 const GURL& options_page, 47 const GURL& input_view); 48 49 // InputMethodEngineInterface overrides. 50 virtual const input_method::InputMethodDescriptor& GetDescriptor() 51 const OVERRIDE; 52 virtual void NotifyImeReady() OVERRIDE; 53 virtual bool SetComposition(int context_id, 54 const char* text, 55 int selection_start, 56 int selection_end, 57 int cursor, 58 const std::vector<SegmentInfo>& segments, 59 std::string* error) OVERRIDE; 60 virtual bool ClearComposition(int context_id, std::string* error) OVERRIDE; 61 virtual bool CommitText(int context_id, const char* text, 62 std::string* error) OVERRIDE; 63 virtual bool SendKeyEvents(int context_id, 64 const std::vector<KeyboardEvent>& events) OVERRIDE; 65 virtual const CandidateWindowProperty& 66 GetCandidateWindowProperty() const OVERRIDE; 67 virtual void SetCandidateWindowProperty( 68 const CandidateWindowProperty& property) OVERRIDE; 69 virtual bool SetCandidateWindowVisible(bool visible, 70 std::string* error) OVERRIDE; 71 virtual bool SetCandidates(int context_id, 72 const std::vector<Candidate>& candidates, 73 std::string* error) OVERRIDE; 74 virtual bool SetCursorPosition(int context_id, int candidate_id, 75 std::string* error) OVERRIDE; 76 virtual bool SetMenuItems(const std::vector<MenuItem>& items) OVERRIDE; 77 virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) OVERRIDE; 78 virtual bool IsActive() const OVERRIDE; 79 virtual void KeyEventDone(input_method::KeyEventHandle* key_data, 80 bool handled) OVERRIDE; 81 virtual bool DeleteSurroundingText(int context_id, 82 int offset, 83 size_t number_of_chars, 84 std::string* error) OVERRIDE; 85 86 // IMEEngineHandlerInterface overrides. 87 virtual void FocusIn( 88 const IMEEngineHandlerInterface::InputContext& input_context) OVERRIDE; 89 virtual void FocusOut() OVERRIDE; 90 virtual void Enable() OVERRIDE; 91 virtual void Disable() OVERRIDE; 92 virtual void PropertyActivate(const std::string& property_name) OVERRIDE; 93 virtual void Reset() OVERRIDE; 94 virtual void ProcessKeyEvent(const ui::KeyEvent& key_event, 95 const KeyEventDoneCallback& callback) OVERRIDE; 96 virtual void CandidateClicked(uint32 index) OVERRIDE; 97 virtual void SetSurroundingText(const std::string& text, uint32 cursor_pos, 98 uint32 anchor_pos) OVERRIDE; 99 virtual void HideInputView() OVERRIDE; 100 101 private: 102 // Converts MenuItem to InputMethodMenuItem. 103 void MenuItemToProperty(const MenuItem& item, 104 ash::ime::InputMethodMenuItem* property); 105 106 // Enables or disables overriding input view page to Virtual Keyboard window. 107 void EnableInputView(bool enabled); 108 109 // Descriptor of this input method. 110 input_method::InputMethodDescriptor descriptor_; 111 112 ui::TextInputType current_input_type_; 113 114 // True if this engine is active. 115 bool active_; 116 117 // ID that is used for the current input context. False if there is no focus. 118 int context_id_; 119 120 // Next id that will be assigned to a context. 121 int next_context_id_; 122 123 // This IME ID in Chrome Extension. 124 std::string engine_id_; 125 126 // This IME's Chrome Extension ID. 127 std::string extension_id_; 128 129 // This IME ID in InputMethodManager. 130 std::string imm_id_; 131 132 // The observer object recieving events for this IME. 133 scoped_ptr<InputMethodEngineInterface::Observer> observer_; 134 135 // The current preedit text, and it's cursor position. 136 scoped_ptr<CompositionText> composition_text_; 137 int composition_cursor_; 138 139 // The current candidate window. 140 scoped_ptr<ui::CandidateWindow> candidate_window_; 141 142 // The current candidate window property. 143 CandidateWindowProperty candidate_window_property_; 144 145 // Indicates whether the candidate window is visible. 146 bool window_visible_; 147 148 // Mapping of candidate index to candidate id. 149 std::vector<int> candidate_ids_; 150 151 // Mapping of candidate id to index. 152 std::map<int, int> candidate_indexes_; 153 154 // Used for input view window. 155 GURL input_view_url_; 156 157 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event 158 // sent to ProcessKeyEvent is sent by SendKeyEvents. 159 const ui::KeyEvent* sent_key_event_; 160}; 161 162} // namespace chromeos 163 164#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_H_ 165