| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 9 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
| 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 namespace chromeos { | 99 namespace chromeos { |
| 100 class ImeObserver : public InputMethodEngineInterface::Observer { | 100 class ImeObserver : public InputMethodEngineInterface::Observer { |
| 101 public: | 101 public: |
| 102 explicit ImeObserver(const std::string& extension_id) | 102 explicit ImeObserver(const std::string& extension_id) |
| 103 : extension_id_(extension_id) {} | 103 : extension_id_(extension_id) {} |
| 104 | 104 |
| 105 virtual ~ImeObserver() {} | 105 virtual ~ImeObserver() {} |
| 106 | 106 |
| 107 virtual void OnActivate(const std::string& component_id) OVERRIDE { | 107 virtual void OnActivate(const std::string& component_id) override { |
| 108 if (extension_id_.empty()) | 108 if (extension_id_.empty()) |
| 109 return; | 109 return; |
| 110 | 110 |
| 111 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( | 111 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( |
| 112 component_id, | 112 component_id, |
| 113 input_ime::OnActivate::ParseScreen(GetCurrentScreenType()))); | 113 input_ime::OnActivate::ParseScreen(GetCurrentScreenType()))); |
| 114 | 114 |
| 115 DispatchEventToExtension( | 115 DispatchEventToExtension( |
| 116 extension_id_, input_ime::OnActivate::kEventName, args.Pass()); | 116 extension_id_, input_ime::OnActivate::kEventName, args.Pass()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void OnDeactivated(const std::string& component_id) OVERRIDE { | 119 virtual void OnDeactivated(const std::string& component_id) override { |
| 120 if (extension_id_.empty()) | 120 if (extension_id_.empty()) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 scoped_ptr<base::ListValue> args( | 123 scoped_ptr<base::ListValue> args( |
| 124 input_ime::OnDeactivated::Create(component_id)); | 124 input_ime::OnDeactivated::Create(component_id)); |
| 125 | 125 |
| 126 DispatchEventToExtension( | 126 DispatchEventToExtension( |
| 127 extension_id_, input_ime::OnDeactivated::kEventName, args.Pass()); | 127 extension_id_, input_ime::OnDeactivated::kEventName, args.Pass()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 virtual void OnFocus( | 130 virtual void OnFocus( |
| 131 const InputMethodEngineInterface::InputContext& context) OVERRIDE { | 131 const InputMethodEngineInterface::InputContext& context) override { |
| 132 if (extension_id_.empty()) | 132 if (extension_id_.empty()) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 input_ime::InputContext context_value; | 135 input_ime::InputContext context_value; |
| 136 context_value.context_id = context.id; | 136 context_value.context_id = context.id; |
| 137 context_value.type = input_ime::InputContext::ParseType(context.type); | 137 context_value.type = input_ime::InputContext::ParseType(context.type); |
| 138 | 138 |
| 139 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); | 139 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); |
| 140 | 140 |
| 141 DispatchEventToExtension( | 141 DispatchEventToExtension( |
| 142 extension_id_, input_ime::OnFocus::kEventName, args.Pass()); | 142 extension_id_, input_ime::OnFocus::kEventName, args.Pass()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 virtual void OnBlur(int context_id) OVERRIDE { | 145 virtual void OnBlur(int context_id) override { |
| 146 if (extension_id_.empty()) | 146 if (extension_id_.empty()) |
| 147 return; | 147 return; |
| 148 | 148 |
| 149 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); | 149 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); |
| 150 | 150 |
| 151 DispatchEventToExtension( | 151 DispatchEventToExtension( |
| 152 extension_id_, input_ime::OnBlur::kEventName, args.Pass()); | 152 extension_id_, input_ime::OnBlur::kEventName, args.Pass()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual void OnInputContextUpdate( | 155 virtual void OnInputContextUpdate( |
| 156 const InputMethodEngineInterface::InputContext& context) OVERRIDE { | 156 const InputMethodEngineInterface::InputContext& context) override { |
| 157 if (extension_id_.empty()) | 157 if (extension_id_.empty()) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 input_ime::InputContext context_value; | 160 input_ime::InputContext context_value; |
| 161 context_value.context_id = context.id; | 161 context_value.context_id = context.id; |
| 162 context_value.type = input_ime::InputContext::ParseType(context.type); | 162 context_value.type = input_ime::InputContext::ParseType(context.type); |
| 163 | 163 |
| 164 scoped_ptr<base::ListValue> args( | 164 scoped_ptr<base::ListValue> args( |
| 165 input_ime::OnInputContextUpdate::Create(context_value)); | 165 input_ime::OnInputContextUpdate::Create(context_value)); |
| 166 | 166 |
| 167 DispatchEventToExtension(extension_id_, | 167 DispatchEventToExtension(extension_id_, |
| 168 input_ime::OnInputContextUpdate::kEventName, | 168 input_ime::OnInputContextUpdate::kEventName, |
| 169 args.Pass()); | 169 args.Pass()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 virtual void OnKeyEvent( | 172 virtual void OnKeyEvent( |
| 173 const std::string& component_id, | 173 const std::string& component_id, |
| 174 const InputMethodEngineInterface::KeyboardEvent& event, | 174 const InputMethodEngineInterface::KeyboardEvent& event, |
| 175 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE { | 175 chromeos::input_method::KeyEventHandle* key_data) override { |
| 176 if (extension_id_.empty()) | 176 if (extension_id_.empty()) |
| 177 return; | 177 return; |
| 178 | 178 |
| 179 // If there is no listener for the event, no need to dispatch the event to | 179 // If there is no listener for the event, no need to dispatch the event to |
| 180 // extension. Instead, releases the key event for default system behavior. | 180 // extension. Instead, releases the key event for default system behavior. |
| 181 if (!ShouldForwardKeyEvent()) { | 181 if (!ShouldForwardKeyEvent()) { |
| 182 // Continue processing the key event so that the physical keyboard can | 182 // Continue processing the key event so that the physical keyboard can |
| 183 // still work. | 183 // still work. |
| 184 CallbackKeyEventHandle(key_data, false); | 184 CallbackKeyEventHandle(key_data, false); |
| 185 return; | 185 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 scoped_ptr<base::ListValue> args( | 206 scoped_ptr<base::ListValue> args( |
| 207 input_ime::OnKeyEvent::Create(component_id, key_data_value)); | 207 input_ime::OnKeyEvent::Create(component_id, key_data_value)); |
| 208 | 208 |
| 209 DispatchEventToExtension( | 209 DispatchEventToExtension( |
| 210 extension_id_, input_ime::OnKeyEvent::kEventName, args.Pass()); | 210 extension_id_, input_ime::OnKeyEvent::kEventName, args.Pass()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 virtual void OnCandidateClicked( | 213 virtual void OnCandidateClicked( |
| 214 const std::string& component_id, | 214 const std::string& component_id, |
| 215 int candidate_id, | 215 int candidate_id, |
| 216 InputMethodEngineInterface::MouseButtonEvent button) OVERRIDE { | 216 InputMethodEngineInterface::MouseButtonEvent button) override { |
| 217 if (extension_id_.empty()) | 217 if (extension_id_.empty()) |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 input_ime::OnCandidateClicked::Button button_enum = | 220 input_ime::OnCandidateClicked::Button button_enum = |
| 221 input_ime::OnCandidateClicked::BUTTON_NONE; | 221 input_ime::OnCandidateClicked::BUTTON_NONE; |
| 222 switch (button) { | 222 switch (button) { |
| 223 case InputMethodEngineInterface::MOUSE_BUTTON_MIDDLE: | 223 case InputMethodEngineInterface::MOUSE_BUTTON_MIDDLE: |
| 224 button_enum = input_ime::OnCandidateClicked::BUTTON_MIDDLE; | 224 button_enum = input_ime::OnCandidateClicked::BUTTON_MIDDLE; |
| 225 break; | 225 break; |
| 226 | 226 |
| 227 case InputMethodEngineInterface::MOUSE_BUTTON_RIGHT: | 227 case InputMethodEngineInterface::MOUSE_BUTTON_RIGHT: |
| 228 button_enum = input_ime::OnCandidateClicked::BUTTON_RIGHT; | 228 button_enum = input_ime::OnCandidateClicked::BUTTON_RIGHT; |
| 229 break; | 229 break; |
| 230 | 230 |
| 231 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT: | 231 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT: |
| 232 // Default to left. | 232 // Default to left. |
| 233 default: | 233 default: |
| 234 button_enum = input_ime::OnCandidateClicked::BUTTON_LEFT; | 234 button_enum = input_ime::OnCandidateClicked::BUTTON_LEFT; |
| 235 break; | 235 break; |
| 236 } | 236 } |
| 237 | 237 |
| 238 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( | 238 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( |
| 239 component_id, candidate_id, button_enum)); | 239 component_id, candidate_id, button_enum)); |
| 240 | 240 |
| 241 DispatchEventToExtension( | 241 DispatchEventToExtension( |
| 242 extension_id_, input_ime::OnCandidateClicked::kEventName, args.Pass()); | 242 extension_id_, input_ime::OnCandidateClicked::kEventName, args.Pass()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 virtual void OnMenuItemActivated(const std::string& component_id, | 245 virtual void OnMenuItemActivated(const std::string& component_id, |
| 246 const std::string& menu_id) OVERRIDE { | 246 const std::string& menu_id) override { |
| 247 if (extension_id_.empty()) | 247 if (extension_id_.empty()) |
| 248 return; | 248 return; |
| 249 | 249 |
| 250 scoped_ptr<base::ListValue> args( | 250 scoped_ptr<base::ListValue> args( |
| 251 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); | 251 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); |
| 252 | 252 |
| 253 DispatchEventToExtension( | 253 DispatchEventToExtension( |
| 254 extension_id_, input_ime::OnMenuItemActivated::kEventName, args.Pass()); | 254 extension_id_, input_ime::OnMenuItemActivated::kEventName, args.Pass()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 virtual void OnSurroundingTextChanged(const std::string& component_id, | 257 virtual void OnSurroundingTextChanged(const std::string& component_id, |
| 258 const std::string& text, | 258 const std::string& text, |
| 259 int cursor_pos, | 259 int cursor_pos, |
| 260 int anchor_pos) OVERRIDE { | 260 int anchor_pos) override { |
| 261 if (extension_id_.empty()) | 261 if (extension_id_.empty()) |
| 262 return; | 262 return; |
| 263 | 263 |
| 264 input_ime::OnSurroundingTextChanged::SurroundingInfo info; | 264 input_ime::OnSurroundingTextChanged::SurroundingInfo info; |
| 265 info.text = text; | 265 info.text = text; |
| 266 info.focus = cursor_pos; | 266 info.focus = cursor_pos; |
| 267 info.anchor = anchor_pos; | 267 info.anchor = anchor_pos; |
| 268 scoped_ptr<base::ListValue> args( | 268 scoped_ptr<base::ListValue> args( |
| 269 input_ime::OnSurroundingTextChanged::Create(component_id, info)); | 269 input_ime::OnSurroundingTextChanged::Create(component_id, info)); |
| 270 | 270 |
| 271 DispatchEventToExtension(extension_id_, | 271 DispatchEventToExtension(extension_id_, |
| 272 input_ime::OnSurroundingTextChanged::kEventName, | 272 input_ime::OnSurroundingTextChanged::kEventName, |
| 273 args.Pass()); | 273 args.Pass()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 virtual void OnReset(const std::string& component_id) OVERRIDE { | 276 virtual void OnReset(const std::string& component_id) override { |
| 277 if (extension_id_.empty()) | 277 if (extension_id_.empty()) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); | 280 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); |
| 281 | 281 |
| 282 DispatchEventToExtension( | 282 DispatchEventToExtension( |
| 283 extension_id_, input_ime::OnReset::kEventName, args.Pass()); | 283 extension_id_, input_ime::OnReset::kEventName, args.Pass()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 private: | 286 private: |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 851 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
| 852 if (engine) | 852 if (engine) |
| 853 engine->Enable(engine->GetActiveComponentId()); | 853 engine->Enable(engine->GetActiveComponentId()); |
| 854 } | 854 } |
| 855 | 855 |
| 856 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | 856 InputImeEventRouter* InputImeAPI::input_ime_event_router() { |
| 857 return InputImeEventRouter::GetInstance(); | 857 return InputImeEventRouter::GetInstance(); |
| 858 } | 858 } |
| 859 | 859 |
| 860 } // namespace extensions | 860 } // namespace extensions |
| OLD | NEW |