Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 162973002: [IME] Releases key events to default handler if no handler in the active IME extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 10 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 args.Pass()); 157 args.Pass());
158 } 158 }
159 159
160 virtual void OnKeyEvent( 160 virtual void OnKeyEvent(
161 const std::string& engine_id, 161 const std::string& engine_id,
162 const InputMethodEngineInterface::KeyboardEvent& event, 162 const InputMethodEngineInterface::KeyboardEvent& event,
163 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE { 163 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE {
164 if (profile_ == NULL || extension_id_.empty()) 164 if (profile_ == NULL || extension_id_.empty())
165 return; 165 return;
166 166
167 std::string request_id = 167 extensions::InputImeEventRouter* ime_event_router =
168 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, 168 extensions::InputImeEventRouter::GetInstance();
169 key_data); 169
170 const std::string request_id =
171 ime_event_router->AddRequest(engine_id, key_data);
172
173 // If there is no listener for the event, no need to dispatch the event to
174 // extension. Instead, releases the key event for default system behavior.
175 if (!HasKeyEventListener()) {
176 ime_event_router->OnKeyEventHandled(extension_id_, request_id, false);
177 return;
178 }
170 179
171 input_ime::KeyboardEvent key_data_value; 180 input_ime::KeyboardEvent key_data_value;
172 key_data_value.type = input_ime::KeyboardEvent::ParseType(event.type); 181 key_data_value.type = input_ime::KeyboardEvent::ParseType(event.type);
173 key_data_value.request_id = request_id; 182 key_data_value.request_id = request_id;
174 key_data_value.key = event.key; 183 key_data_value.key = event.key;
175 key_data_value.code = event.code; 184 key_data_value.code = event.code;
176 key_data_value.alt_key.reset(new bool(event.alt_key)); 185 key_data_value.alt_key.reset(new bool(event.alt_key));
177 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); 186 key_data_value.ctrl_key.reset(new bool(event.ctrl_key));
178 key_data_value.shift_key.reset(new bool(event.shift_key)); 187 key_data_value.shift_key.reset(new bool(event.shift_key));
179 key_data_value.caps_lock.reset(new bool(event.caps_lock)); 188 key_data_value.caps_lock.reset(new bool(event.caps_lock));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 270
262 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(engine_id)); 271 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(engine_id));
263 272
264 DispatchEventToExtension(profile_, 273 DispatchEventToExtension(profile_,
265 extension_id_, 274 extension_id_,
266 input_ime::OnReset::kEventName, 275 input_ime::OnReset::kEventName,
267 args.Pass()); 276 args.Pass());
268 } 277 }
269 278
270 private: 279 private:
280 bool HasKeyEventListener() const {
281 return extensions::ExtensionSystem::Get(profile_)
282 ->event_router()
283 ->ExtensionHasEventListener(extension_id_,
284 input_ime::OnKeyEvent::kEventName);
285 }
286
271 Profile* profile_; 287 Profile* profile_;
272 std::string extension_id_; 288 std::string extension_id_;
273 std::string engine_id_; 289 std::string engine_id_;
274 290
275 DISALLOW_COPY_AND_ASSIGN(ImeObserver); 291 DISALLOW_COPY_AND_ASSIGN(ImeObserver);
276 }; 292 };
277 293
278 } // namespace chromeos 294 } // namespace chromeos
279 295
280 namespace extensions { 296 namespace extensions {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (input_components->size() > 0) 823 if (input_components->size() > 0)
808 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); 824 input_ime_event_router()->UnregisterAllImes(profile_, extension->id());
809 } 825 }
810 } 826 }
811 827
812 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 828 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
813 return InputImeEventRouter::GetInstance(); 829 return InputImeEventRouter::GetInstance();
814 } 830 }
815 831
816 } // namespace extensions 832 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698