| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 class ImeObserverChromeOS : public ui::ImeObserver { | 78 class ImeObserverChromeOS : public ui::ImeObserver { |
| 79 public: | 79 public: |
| 80 ImeObserverChromeOS(const std::string& extension_id, Profile* profile) | 80 ImeObserverChromeOS(const std::string& extension_id, Profile* profile) |
| 81 : ImeObserver(extension_id, profile) {} | 81 : ImeObserver(extension_id, profile) {} |
| 82 | 82 |
| 83 ~ImeObserverChromeOS() override {} | 83 ~ImeObserverChromeOS() override {} |
| 84 | 84 |
| 85 // ui::IMEEngineObserver overrides | 85 // ui::IMEEngineObserver overrides |
| 86 void OnActivate(const std::string& component_id) override { | |
| 87 if (extension_id_.empty() || | |
| 88 !HasListener(input_ime::OnActivate::kEventName)) | |
| 89 return; | |
| 90 | |
| 91 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( | |
| 92 component_id, | |
| 93 input_ime::ParseScreenType(GetCurrentScreenType()))); | |
| 94 | |
| 95 DispatchEventToExtension(extensions::events::INPUT_IME_ON_ACTIVATE, | |
| 96 input_ime::OnActivate::kEventName, | |
| 97 std::move(args)); | |
| 98 } | |
| 99 | |
| 100 void OnInputContextUpdate( | 86 void OnInputContextUpdate( |
| 101 const IMEEngineHandlerInterface::InputContext& context) override { | 87 const IMEEngineHandlerInterface::InputContext& context) override { |
| 102 if (extension_id_.empty() || | 88 if (extension_id_.empty() || |
| 103 !HasListener(input_ime::OnInputContextUpdate::kEventName)) | 89 !HasListener(input_ime::OnInputContextUpdate::kEventName)) |
| 104 return; | 90 return; |
| 105 | 91 |
| 106 input_ime::InputContext context_value; | 92 input_ime::InputContext context_value; |
| 107 context_value.context_id = context.id; | 93 context_value.context_id = context.id; |
| 108 context_value.type = | 94 context_value.type = |
| 109 input_ime::ParseInputContextType(ConvertInputContextType(context)); | 95 input_ime::ParseInputContextType(ConvertInputContextType(context)); |
| 110 | 96 |
| 111 scoped_ptr<base::ListValue> args( | 97 scoped_ptr<base::ListValue> args( |
| 112 input_ime::OnInputContextUpdate::Create(context_value)); | 98 input_ime::OnInputContextUpdate::Create(context_value)); |
| 113 | 99 |
| 114 DispatchEventToExtension( | 100 DispatchEventToExtension( |
| 115 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE, | 101 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE, |
| 116 input_ime::OnInputContextUpdate::kEventName, std::move(args)); | 102 input_ime::OnInputContextUpdate::kEventName, std::move(args)); |
| 117 } | 103 } |
| 118 | 104 |
| 119 bool IsInterestedInKeyEvent() const override { | |
| 120 return ShouldForwardKeyEvent(); | |
| 121 } | |
| 122 | |
| 123 void OnCandidateClicked( | 105 void OnCandidateClicked( |
| 124 const std::string& component_id, | 106 const std::string& component_id, |
| 125 int candidate_id, | 107 int candidate_id, |
| 126 ui::IMEEngineObserver::MouseButtonEvent button) override { | 108 ui::IMEEngineObserver::MouseButtonEvent button) override { |
| 127 if (extension_id_.empty() || | 109 if (extension_id_.empty() || |
| 128 !HasListener(input_ime::OnCandidateClicked::kEventName)) | 110 !HasListener(input_ime::OnCandidateClicked::kEventName)) |
| 129 return; | 111 return; |
| 130 | 112 |
| 131 input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE; | 113 input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE; |
| 132 switch (button) { | 114 switch (button) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 return; | 142 return; |
| 161 | 143 |
| 162 scoped_ptr<base::ListValue> args( | 144 scoped_ptr<base::ListValue> args( |
| 163 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); | 145 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); |
| 164 | 146 |
| 165 DispatchEventToExtension( | 147 DispatchEventToExtension( |
| 166 extensions::events::INPUT_IME_ON_MENU_ITEM_ACTIVATED, | 148 extensions::events::INPUT_IME_ON_MENU_ITEM_ACTIVATED, |
| 167 input_ime::OnMenuItemActivated::kEventName, std::move(args)); | 149 input_ime::OnMenuItemActivated::kEventName, std::move(args)); |
| 168 } | 150 } |
| 169 | 151 |
| 170 void OnSurroundingTextChanged(const std::string& component_id, | |
| 171 const std::string& text, | |
| 172 int cursor_pos, | |
| 173 int anchor_pos, | |
| 174 int offset_pos) override { | |
| 175 if (extension_id_.empty() || | |
| 176 !HasListener(input_ime::OnSurroundingTextChanged::kEventName)) | |
| 177 return; | |
| 178 | |
| 179 input_ime::OnSurroundingTextChanged::SurroundingInfo info; | |
| 180 info.text = text; | |
| 181 info.focus = cursor_pos; | |
| 182 info.anchor = anchor_pos; | |
| 183 info.offset = offset_pos; | |
| 184 scoped_ptr<base::ListValue> args( | |
| 185 input_ime::OnSurroundingTextChanged::Create(component_id, info)); | |
| 186 | |
| 187 DispatchEventToExtension( | |
| 188 extensions::events::INPUT_IME_ON_SURROUNDING_TEXT_CHANGED, | |
| 189 input_ime::OnSurroundingTextChanged::kEventName, std::move(args)); | |
| 190 } | |
| 191 | |
| 192 void OnCompositionBoundsChanged( | 152 void OnCompositionBoundsChanged( |
| 193 const std::vector<gfx::Rect>& bounds) override { | 153 const std::vector<gfx::Rect>& bounds) override { |
| 194 if (extension_id_.empty() || | 154 if (extension_id_.empty() || |
| 195 !HasListener(kOnCompositionBoundsChangedEventName)) | 155 !HasListener(kOnCompositionBoundsChangedEventName)) |
| 196 return; | 156 return; |
| 197 | 157 |
| 198 // Note: this is a private API event. | 158 // Note: this is a private API event. |
| 199 base::ListValue* bounds_list = new base::ListValue(); | 159 base::ListValue* bounds_list = new base::ListValue(); |
| 200 for (size_t i = 0; i < bounds.size(); ++i) { | 160 for (size_t i = 0; i < bounds.size(); ++i) { |
| 201 base::DictionaryValue* bounds_value = new base::DictionaryValue(); | 161 base::DictionaryValue* bounds_value = new base::DictionaryValue(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 scoped_ptr<extensions::Event> event( | 214 scoped_ptr<extensions::Event> event( |
| 255 new extensions::Event(histogram_value, event_name, std::move(args))); | 215 new extensions::Event(histogram_value, event_name, std::move(args))); |
| 256 event->restrict_to_browser_context = profile_; | 216 event->restrict_to_browser_context = profile_; |
| 257 extensions::EventRouter::Get(profile_) | 217 extensions::EventRouter::Get(profile_) |
| 258 ->DispatchEventToExtension(extension_id_, std::move(event)); | 218 ->DispatchEventToExtension(extension_id_, std::move(event)); |
| 259 } | 219 } |
| 260 | 220 |
| 261 // The component IME extensions need to know the current screen type (e.g. | 221 // The component IME extensions need to know the current screen type (e.g. |
| 262 // lock screen, login screen, etc.) so that its on-screen keyboard page | 222 // lock screen, login screen, etc.) so that its on-screen keyboard page |
| 263 // won't open new windows/pages. See crbug.com/395621. | 223 // won't open new windows/pages. See crbug.com/395621. |
| 264 std::string GetCurrentScreenType() { | 224 std::string GetCurrentScreenType() override { |
| 265 switch (chromeos::input_method::InputMethodManager::Get() | 225 switch (chromeos::input_method::InputMethodManager::Get() |
| 266 ->GetUISessionState()) { | 226 ->GetUISessionState()) { |
| 267 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN: | 227 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN: |
| 268 return "login"; | 228 return "login"; |
| 269 case chromeos::input_method::InputMethodManager::STATE_LOCK_SCREEN: | 229 case chromeos::input_method::InputMethodManager::STATE_LOCK_SCREEN: |
| 270 return "lock"; | 230 return "lock"; |
| 271 case chromeos::input_method::InputMethodManager::STATE_BROWSER_SCREEN: | 231 case chromeos::input_method::InputMethodManager::STATE_BROWSER_SCREEN: |
| 272 return chromeos::UserAddingScreen::Get()->IsRunning() | 232 return chromeos::UserAddingScreen::Get()->IsRunning() |
| 273 ? "secondary-login" | 233 ? "secondary-login" |
| 274 : "normal"; | 234 : "normal"; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 error_ = kErrorEngineNotAvailable; | 646 error_ = kErrorEngineNotAvailable; |
| 687 return false; | 647 return false; |
| 688 } | 648 } |
| 689 | 649 |
| 690 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, | 650 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, |
| 691 &error_); | 651 &error_); |
| 692 return true; | 652 return true; |
| 693 } | 653 } |
| 694 | 654 |
| 695 } // namespace extensions | 655 } // namespace extensions |
| OLD | NEW |