Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/accessibility/spoken_feedback_event_rewriter.h " | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | |
| 13 #include "chrome/common/extensions/api/commands/commands_handler.h" | |
| 14 #include "chrome/common/extensions/extension_constants.h" | |
| 15 #include "extensions/browser/event_router.h" | |
| 16 #include "extensions/browser/extension_registry.h" | |
| 17 #include "ui/events/event.h" | |
| 18 | |
| 19 SpokenFeedbackEventRewriter::SpokenFeedbackEventRewriter() { | |
| 20 } | |
| 21 | |
| 22 SpokenFeedbackEventRewriter::~SpokenFeedbackEventRewriter() { | |
| 23 } | |
| 24 | |
| 25 ui::EventRewriteStatus SpokenFeedbackEventRewriter::RewriteEvent( | |
| 26 const ui::Event& event, | |
| 27 scoped_ptr<ui::Event>* new_event) { | |
| 28 if (!chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled() || | |
| 29 event.type() != ui::ET_KEY_PRESSED || | |
| 30 !g_browser_process->profile_manager()) | |
| 31 return ui::EVENT_REWRITE_CONTINUE; | |
| 32 | |
| 33 content::BrowserContext* context = | |
| 34 g_browser_process->profile_manager()->GetLastUsedProfile(); | |
| 35 | |
| 36 const extensions::Extension* extension = | |
| 37 extensions::ExtensionRegistry::Get(context)->enabled_extensions().GetByID( | |
| 38 extension_misc::kChromeVoxExtensionId); | |
|
Finnur
2015/06/16 11:29:49
if (!extension)
return ui::EVENT_REWRITE_CONTINU
David Tseng
2015/06/16 15:31:36
Done.
| |
| 39 const extensions::CommandMap* commands = | |
| 40 extensions::CommandsInfo::GetNamedCommands(extension); | |
| 41 if (!commands) | |
| 42 return ui::EVENT_REWRITE_CONTINUE; | |
| 43 | |
| 44 const ui::KeyEvent key_event = static_cast<const ui::KeyEvent&>(event); | |
| 45 std::string command_name; | |
| 46 for (extensions::CommandMap::const_iterator iter = commands->begin(); | |
| 47 iter != commands->end(); ++iter) { | |
| 48 if (iter->second.accelerator().key_code() == key_event.key_code() && | |
| 49 iter->second.accelerator().modifiers() == key_event.flags()) | |
| 50 command_name = iter->second.command_name(); | |
| 51 } | |
| 52 | |
| 53 if (command_name.empty()) | |
| 54 return ui::EVENT_REWRITE_CONTINUE; | |
| 55 | |
| 56 scoped_ptr<base::ListValue> args(new base::ListValue()); | |
| 57 args->Append(new base::StringValue(command_name)); | |
| 58 | |
| 59 scoped_ptr<extensions::Event> extension_event( | |
| 60 new extensions::Event("commands.onCommand", args.Pass())); | |
| 61 | |
| 62 extensions::EventRouter::Get(context)->DispatchEventToExtension( | |
| 63 extension_misc::kChromeVoxExtensionId, extension_event.Pass()); | |
|
Finnur
2015/06/16 11:29:48
The ExtensionKeybindingRegistry uses:
event->re
David Tseng
2015/06/16 15:31:37
Added. Yes; with the last profile/context logic th
| |
| 64 | |
| 65 return ui::EVENT_REWRITE_DISCARD; | |
| 66 } | |
| 67 | |
| 68 ui::EventRewriteStatus SpokenFeedbackEventRewriter::NextDispatchEvent( | |
| 69 const ui::Event& last_event, | |
| 70 scoped_ptr<ui::Event>* new_event) { | |
| 71 return ui::EVENT_REWRITE_CONTINUE; | |
| 72 } | |
| OLD | NEW |