| 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 <utility> |
| 8 |
| 7 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/common/extensions/api/input_ime.h" | 10 #include "chrome/common/extensions/api/input_ime.h" |
| 9 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" | 11 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" |
| 10 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
| 11 | 13 |
| 12 namespace input_ime = extensions::api::input_ime; | 14 namespace input_ime = extensions::api::input_ime; |
| 13 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; | 15 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; |
| 14 using ui::IMEEngineHandlerInterface; | 16 using ui::IMEEngineHandlerInterface; |
| 15 | 17 |
| 16 namespace ui { | 18 namespace ui { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 context_value.context_id = context.id; | 29 context_value.context_id = context.id; |
| 28 context_value.type = | 30 context_value.type = |
| 29 input_ime::ParseInputContextType(ConvertInputContextType(context)); | 31 input_ime::ParseInputContextType(ConvertInputContextType(context)); |
| 30 context_value.auto_correct = ConvertInputContextAutoCorrect(context); | 32 context_value.auto_correct = ConvertInputContextAutoCorrect(context); |
| 31 context_value.auto_complete = ConvertInputContextAutoComplete(context); | 33 context_value.auto_complete = ConvertInputContextAutoComplete(context); |
| 32 context_value.spell_check = ConvertInputContextSpellCheck(context); | 34 context_value.spell_check = ConvertInputContextSpellCheck(context); |
| 33 | 35 |
| 34 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); | 36 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); |
| 35 | 37 |
| 36 DispatchEventToExtension(extensions::events::INPUT_IME_ON_FOCUS, | 38 DispatchEventToExtension(extensions::events::INPUT_IME_ON_FOCUS, |
| 37 input_ime::OnFocus::kEventName, args.Pass()); | 39 input_ime::OnFocus::kEventName, std::move(args)); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ImeObserver::OnBlur(int context_id) { | 42 void ImeObserver::OnBlur(int context_id) { |
| 41 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName)) | 43 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName)) |
| 42 return; | 44 return; |
| 43 | 45 |
| 44 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); | 46 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); |
| 45 | 47 |
| 46 DispatchEventToExtension(extensions::events::INPUT_IME_ON_BLUR, | 48 DispatchEventToExtension(extensions::events::INPUT_IME_ON_BLUR, |
| 47 input_ime::OnBlur::kEventName, args.Pass()); | 49 input_ime::OnBlur::kEventName, std::move(args)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void ImeObserver::OnKeyEvent( | 52 void ImeObserver::OnKeyEvent( |
| 51 const std::string& component_id, | 53 const std::string& component_id, |
| 52 const IMEEngineHandlerInterface::KeyboardEvent& event, | 54 const IMEEngineHandlerInterface::KeyboardEvent& event, |
| 53 IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) { | 55 IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) { |
| 54 if (extension_id_.empty()) | 56 if (extension_id_.empty()) |
| 55 return; | 57 return; |
| 56 | 58 |
| 57 // If there is no listener for the event, no need to dispatch the event to | 59 // If there is no listener for the event, no need to dispatch the event to |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 key_data_value.code = event.code; | 77 key_data_value.code = event.code; |
| 76 key_data_value.alt_key.reset(new bool(event.alt_key)); | 78 key_data_value.alt_key.reset(new bool(event.alt_key)); |
| 77 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); | 79 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); |
| 78 key_data_value.shift_key.reset(new bool(event.shift_key)); | 80 key_data_value.shift_key.reset(new bool(event.shift_key)); |
| 79 key_data_value.caps_lock.reset(new bool(event.caps_lock)); | 81 key_data_value.caps_lock.reset(new bool(event.caps_lock)); |
| 80 | 82 |
| 81 scoped_ptr<base::ListValue> args( | 83 scoped_ptr<base::ListValue> args( |
| 82 input_ime::OnKeyEvent::Create(component_id, key_data_value)); | 84 input_ime::OnKeyEvent::Create(component_id, key_data_value)); |
| 83 | 85 |
| 84 DispatchEventToExtension(extensions::events::INPUT_IME_ON_KEY_EVENT, | 86 DispatchEventToExtension(extensions::events::INPUT_IME_ON_KEY_EVENT, |
| 85 input_ime::OnKeyEvent::kEventName, args.Pass()); | 87 input_ime::OnKeyEvent::kEventName, std::move(args)); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void ImeObserver::OnReset(const std::string& component_id) { | 90 void ImeObserver::OnReset(const std::string& component_id) { |
| 89 if (extension_id_.empty() || !HasListener(input_ime::OnReset::kEventName)) | 91 if (extension_id_.empty() || !HasListener(input_ime::OnReset::kEventName)) |
| 90 return; | 92 return; |
| 91 | 93 |
| 92 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); | 94 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); |
| 93 | 95 |
| 94 DispatchEventToExtension(extensions::events::INPUT_IME_ON_RESET, | 96 DispatchEventToExtension(extensions::events::INPUT_IME_ON_RESET, |
| 95 input_ime::OnReset::kEventName, args.Pass()); | 97 input_ime::OnReset::kEventName, std::move(args)); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void ImeObserver::OnDeactivated(const std::string& component_id) { | 100 void ImeObserver::OnDeactivated(const std::string& component_id) { |
| 99 if (extension_id_.empty() || | 101 if (extension_id_.empty() || |
| 100 !HasListener(input_ime::OnDeactivated::kEventName)) | 102 !HasListener(input_ime::OnDeactivated::kEventName)) |
| 101 return; | 103 return; |
| 102 | 104 |
| 103 scoped_ptr<base::ListValue> args( | 105 scoped_ptr<base::ListValue> args( |
| 104 input_ime::OnDeactivated::Create(component_id)); | 106 input_ime::OnDeactivated::Create(component_id)); |
| 105 | 107 |
| 106 DispatchEventToExtension(extensions::events::INPUT_IME_ON_DEACTIVATED, | 108 DispatchEventToExtension(extensions::events::INPUT_IME_ON_DEACTIVATED, |
| 107 input_ime::OnDeactivated::kEventName, args.Pass()); | 109 input_ime::OnDeactivated::kEventName, |
| 110 std::move(args)); |
| 108 } | 111 } |
| 109 | 112 |
| 110 // TODO(azurewei): This function implementation should be shared on all | 113 // TODO(azurewei): This function implementation should be shared on all |
| 111 // platforms, while with some changing on the current code on ChromeOS. | 114 // platforms, while with some changing on the current code on ChromeOS. |
| 112 void ImeObserver::OnCompositionBoundsChanged( | 115 void ImeObserver::OnCompositionBoundsChanged( |
| 113 const std::vector<gfx::Rect>& bounds) {} | 116 const std::vector<gfx::Rect>& bounds) {} |
| 114 | 117 |
| 115 bool ImeObserver::ShouldForwardKeyEvent() const { | 118 bool ImeObserver::ShouldForwardKeyEvent() const { |
| 116 // Only forward key events to extension if there are non-lazy listeners | 119 // Only forward key events to extension if there are non-lazy listeners |
| 117 // for onKeyEvent. Because if something wrong with the lazy background | 120 // for onKeyEvent. Because if something wrong with the lazy background |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 321 } |
| 319 | 322 |
| 320 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { | 323 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { |
| 321 if (profile->HasOffTheRecordProfile()) | 324 if (profile->HasOffTheRecordProfile()) |
| 322 profile = profile->GetOffTheRecordProfile(); | 325 profile = profile->GetOffTheRecordProfile(); |
| 323 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( | 326 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( |
| 324 profile); | 327 profile); |
| 325 } | 328 } |
| 326 | 329 |
| 327 } // namespace extensions | 330 } // namespace extensions |
| OLD | NEW |