| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ | 5 #ifndef CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ |
| 6 #define CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ | 6 #define CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "ui/base/ime/chromeos/input_method_descriptor.h" | 12 #include "ui/base/ime/chromeos/input_method_descriptor.h" |
| 13 #include "ui/base/ime/ime_engine_handler_interface.h" | 13 #include "ui/base/ime/ime_engine_handler_interface.h" |
| 14 #include "ui/base/ime/ime_engine_observer.h" | 14 #include "ui/base/ime/ime_engine_observer.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 struct CompositionText; | 20 struct CompositionText; |
| 21 class IMEEngineHandlerInterface; | 21 class IMEEngineHandlerInterface; |
| 22 class IMEEngineObserver; | 22 class IMEEngineObserver; |
| 23 class KeyEvent; | 23 class KeyEvent; |
| 24 } // namespace ui | 24 } // namespace ui |
| 25 | 25 |
| 26 namespace input_method { | 26 namespace input_method { |
| 27 | 27 |
| 28 class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { | 28 class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { |
| 29 public: | 29 public: |
| 30 struct KeyboardEvent { |
| 31 KeyboardEvent(); |
| 32 virtual ~KeyboardEvent(); |
| 33 |
| 34 std::string type; |
| 35 std::string key; |
| 36 std::string code; |
| 37 int key_code; // only used by on-screen keyboards. |
| 38 std::string extension_id; |
| 39 bool alt_key; |
| 40 bool ctrl_key; |
| 41 bool shift_key; |
| 42 bool caps_lock; |
| 43 }; |
| 44 |
| 45 enum SegmentStyle { |
| 46 SEGMENT_STYLE_UNDERLINE, |
| 47 SEGMENT_STYLE_DOUBLE_UNDERLINE, |
| 48 SEGMENT_STYLE_NO_UNDERLINE, |
| 49 }; |
| 50 |
| 51 struct SegmentInfo { |
| 52 int start; |
| 53 int end; |
| 54 SegmentStyle style; |
| 55 }; |
| 56 |
| 57 #if defined(OS_CHROMEOS) |
| 58 enum MouseButtonEvent { |
| 59 MOUSE_BUTTON_LEFT, |
| 60 MOUSE_BUTTON_RIGHT, |
| 61 MOUSE_BUTTON_MIDDLE, |
| 62 }; |
| 63 #endif |
| 64 |
| 65 class Observer : public ui::IMEEngineObserver { |
| 66 public: |
| 67 ~Observer() override; |
| 68 |
| 69 // Called when the user pressed a key with a text field focused. |
| 70 virtual void OnKeyEvent( |
| 71 const std::string& engine_id, |
| 72 const InputMethodEngineBase::KeyboardEvent& event, |
| 73 ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) = 0; |
| 74 |
| 75 #if defined(OS_CHROMEOS) |
| 76 // Called when the user clicks on an item in the candidate list. |
| 77 virtual void OnCandidateClicked( |
| 78 const std::string& component_id, |
| 79 int candidate_id, |
| 80 InputMethodEngineBase::MouseButtonEvent button) = 0; |
| 81 #endif // defined(OS_CHROMEOS) |
| 82 }; |
| 83 |
| 30 InputMethodEngineBase(); | 84 InputMethodEngineBase(); |
| 31 | 85 |
| 32 ~InputMethodEngineBase() override; | 86 ~InputMethodEngineBase() override; |
| 33 | 87 |
| 34 void Initialize(scoped_ptr<ui::IMEEngineObserver> observer, | 88 void Initialize(scoped_ptr<InputMethodEngineBase::Observer> observer, |
| 35 const char* extension_id, | 89 const char* extension_id, |
| 36 Profile* profile); | 90 Profile* profile); |
| 37 | 91 |
| 38 // IMEEngineHandlerInterface overrides. | 92 // IMEEngineHandlerInterface overrides. |
| 39 void FocusIn(const ui::IMEEngineHandlerInterface::InputContext& input_context) | 93 void FocusIn(const ui::IMEEngineHandlerInterface::InputContext& input_context) |
| 40 override; | 94 override; |
| 41 void FocusOut() override; | 95 void FocusOut() override; |
| 42 void Enable(const std::string& component_id) override; | 96 void Enable(const std::string& component_id) override; |
| 43 void Disable() override; | 97 void Disable() override; |
| 44 void Reset() override; | 98 void Reset() override; |
| 45 void ProcessKeyEvent(const ui::KeyEvent& key_event, | 99 void ProcessKeyEvent(const ui::KeyEvent& key_event, |
| 46 KeyEventDoneCallback& callback) override; | 100 KeyEventDoneCallback& callback) override; |
| 47 void SetSurroundingText(const std::string& text, | 101 void SetSurroundingText(const std::string& text, |
| 48 uint32_t cursor_pos, | 102 uint32_t cursor_pos, |
| 49 uint32_t anchor_pos, | 103 uint32_t anchor_pos, |
| 50 uint32_t offset_pos) override; | 104 uint32_t offset_pos) override; |
| 51 void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override; | 105 void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override; |
| 52 bool SetComposition(int context_id, | |
| 53 const char* text, | |
| 54 int selection_start, | |
| 55 int selection_end, | |
| 56 int cursor, | |
| 57 const std::vector<SegmentInfo>& segments, | |
| 58 std::string* error) override; | |
| 59 bool ClearComposition(int context_id, std::string* error) override; | 106 bool ClearComposition(int context_id, std::string* error) override; |
| 60 bool CommitText(int context_id, | 107 bool CommitText(int context_id, |
| 61 const char* text, | 108 const char* text, |
| 62 std::string* error) override; | 109 std::string* error) override; |
| 63 const std::string& GetActiveComponentId() const override; | 110 const std::string& GetActiveComponentId() const override; |
| 64 bool DeleteSurroundingText(int context_id, | 111 bool DeleteSurroundingText(int context_id, |
| 65 int offset, | 112 int offset, |
| 66 size_t number_of_chars, | 113 size_t number_of_chars, |
| 67 std::string* error) override; | 114 std::string* error) override; |
| 68 int GetCotextIdForTesting() { return context_id_; } | 115 int GetCotextIdForTesting() { return context_id_; } |
| 69 bool IsInterestedInKeyEvent() const override; | 116 bool IsInterestedInKeyEvent() const override; |
| 70 | 117 |
| 118 // Send the sequence of key events. |
| 119 virtual bool SendKeyEvents(int context_id, |
| 120 const std::vector<KeyboardEvent>& events) = 0; |
| 121 |
| 122 // Set the current composition and associated properties. |
| 123 bool SetComposition(int context_id, |
| 124 const char* text, |
| 125 int selection_start, |
| 126 int selection_end, |
| 127 int cursor, |
| 128 const std::vector<SegmentInfo>& segments, |
| 129 std::string* error); |
| 130 |
| 71 protected: | 131 protected: |
| 72 ui::TextInputType current_input_type_; | 132 ui::TextInputType current_input_type_; |
| 73 | 133 |
| 74 // ID that is used for the current input context. False if there is no focus. | 134 // ID that is used for the current input context. False if there is no focus. |
| 75 int context_id_; | 135 int context_id_; |
| 76 | 136 |
| 77 // Next id that will be assigned to a context. | 137 // Next id that will be assigned to a context. |
| 78 int next_context_id_; | 138 int next_context_id_; |
| 79 | 139 |
| 80 // The input_component ID in IME extension's manifest. | 140 // The input_component ID in IME extension's manifest. |
| 81 std::string active_component_id_; | 141 std::string active_component_id_; |
| 82 | 142 |
| 83 // The IME extension ID. | 143 // The IME extension ID. |
| 84 std::string extension_id_; | 144 std::string extension_id_; |
| 85 | 145 |
| 86 // The observer object recieving events for this IME. | 146 // The observer object recieving events for this IME. |
| 87 scoped_ptr<ui::IMEEngineObserver> observer_; | 147 scoped_ptr<InputMethodEngineBase::Observer> observer_; |
| 88 | 148 |
| 89 // The current preedit text, and it's cursor position. | 149 // The current preedit text, and it's cursor position. |
| 90 scoped_ptr<ui::CompositionText> composition_text_; | 150 scoped_ptr<ui::CompositionText> composition_text_; |
| 91 int composition_cursor_; | 151 int composition_cursor_; |
| 92 | 152 |
| 93 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event | 153 // Used with SendKeyEvents and ProcessKeyEvent to check if the key event |
| 94 // sent to ProcessKeyEvent is sent by SendKeyEvents. | 154 // sent to ProcessKeyEvent is sent by SendKeyEvents. |
| 95 const ui::KeyEvent* sent_key_event_; | 155 const ui::KeyEvent* sent_key_event_; |
| 96 | 156 |
| 97 Profile* profile_; | 157 Profile* profile_; |
| 98 }; | 158 }; |
| 99 | 159 |
| 100 } // namespace input_method | 160 } // namespace input_method |
| 101 | 161 |
| 102 #endif // CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ | 162 #endif // CHROME_BROWSER_INPUT_METHOD_INPUT_METHOD_ENGINE_BASE_H_ |
| OLD | NEW |