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

Side by Side Diff: chrome/browser/chromeos/accessibility/spoken_feedback_event_rewriter.cc

Issue 1185753008: Proposed alternative for supporting ChromeVox keyboard commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restrict to browser context and return on null extension. Created 5 years, 6 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
OLDNEW
(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 ||
dmazzoni 2015/06/16 16:30:56 I think you need to handle ET_KEY_RELEASED too. Yo
David Tseng 2015/06/17 22:22:10 If you discard a press event, I think the release
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);
39 if (!extension)
40 return ui::EVENT_REWRITE_CONTINUE;
41
42 const extensions::CommandMap* commands =
43 extensions::CommandsInfo::GetNamedCommands(extension);
44 if (!commands)
45 return ui::EVENT_REWRITE_CONTINUE;
46
47 const ui::KeyEvent key_event = static_cast<const ui::KeyEvent&>(event);
48 std::string command_name;
49 for (extensions::CommandMap::const_iterator iter = commands->begin();
50 iter != commands->end(); ++iter) {
51 if (iter->second.accelerator().key_code() == key_event.key_code() &&
52 iter->second.accelerator().modifiers() == key_event.flags())
53 command_name = iter->second.command_name();
54 }
55
56 if (command_name.empty())
57 return ui::EVENT_REWRITE_CONTINUE;
58
59 scoped_ptr<base::ListValue> args(new base::ListValue());
60 args->Append(new base::StringValue(command_name));
61
62 scoped_ptr<extensions::Event> extension_event(
63 new extensions::Event("commands.onCommand", args.Pass()));
64 extension_event->restrict_to_browser_context = context;
65
66 extensions::EventRouter::Get(context)->DispatchEventToExtension(
67 extension_misc::kChromeVoxExtensionId, extension_event.Pass());
68
69 return ui::EVENT_REWRITE_DISCARD;
70 }
71
72 ui::EventRewriteStatus SpokenFeedbackEventRewriter::NextDispatchEvent(
73 const ui::Event& last_event,
74 scoped_ptr<ui::Event>* new_event) {
75 return ui::EVENT_REWRITE_CONTINUE;
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698