| 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/chromeos/accessibility/spoken_feedback_event_rewriter.h
" | 5 #include "chrome/browser/chromeos/accessibility/spoken_feedback_event_rewriter.h
" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/chromeos/accessibility/event_handler_common.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "content/public/browser/render_view_host.h" | |
| 15 #include "content/public/browser/render_widget_host.h" | |
| 16 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 17 #include "extensions/browser/event_router.h" | 15 #include "extensions/browser/event_router.h" |
| 18 #include "extensions/browser/extension_host.h" | 16 #include "extensions/browser/extension_host.h" |
| 19 #include "extensions/browser/extension_registry.h" | |
| 20 #include "extensions/browser/process_manager.h" | |
| 21 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/content_accelerators/accelerator_util.h" | 18 #include "ui/content_accelerators/accelerator_util.h" |
| 23 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 24 #include "ui/events/event_processor.h" | 20 #include "ui/events/event_processor.h" |
| 25 | 21 |
| 26 SpokenFeedbackEventRewriterDelegate::SpokenFeedbackEventRewriterDelegate() {} | 22 SpokenFeedbackEventRewriterDelegate::SpokenFeedbackEventRewriterDelegate() {} |
| 27 | 23 |
| 28 bool SpokenFeedbackEventRewriterDelegate::IsSpokenFeedbackEnabled() const { | 24 bool SpokenFeedbackEventRewriterDelegate::IsSpokenFeedbackEnabled() const { |
| 29 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled(); | 25 return chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled(); |
| 30 } | 26 } |
| 31 | 27 |
| 32 bool SpokenFeedbackEventRewriterDelegate::DispatchKeyEventToChromeVox( | 28 bool SpokenFeedbackEventRewriterDelegate::DispatchKeyEventToChromeVox( |
| 33 const ui::KeyEvent& key_event, | 29 const ui::KeyEvent& key_event, |
| 34 bool capture) { | 30 bool capture) { |
| 35 if (!chromeos::AccessibilityManager::Get()) | |
| 36 return false; | |
| 37 | |
| 38 content::BrowserContext* context = ProfileManager::GetActiveUserProfile(); | |
| 39 if (!context) | |
| 40 return false; | |
| 41 | |
| 42 const extensions::Extension* extension = | |
| 43 extensions::ExtensionRegistry::Get(context)->enabled_extensions().GetByID( | |
| 44 extension_misc::kChromeVoxExtensionId); | |
| 45 if (!extension) | |
| 46 return false; | |
| 47 | |
| 48 extensions::ExtensionHost* host = | |
| 49 extensions::ProcessManager::Get(context) | |
| 50 ->GetBackgroundHostForExtension(extension->id()); | |
| 51 if (!host) | |
| 52 return false; | |
| 53 | |
| 54 content::RenderViewHost* rvh = host->render_view_host(); | |
| 55 | 31 |
| 56 // Always capture the Search key. | 32 // Always capture the Search key. |
| 57 capture |= key_event.IsCommandDown(); | 33 capture |= key_event.IsCommandDown(); |
| 58 | 34 |
| 59 // Don't capture tab as it gets consumed by Blink so never comes back | 35 // Don't capture tab as it gets consumed by Blink so never comes back |
| 60 // unhandled. In third_party/WebKit/Source/core/input/EventHandler.cpp, a | 36 // unhandled. In third_party/WebKit/Source/core/input/EventHandler.cpp, a |
| 61 // default tab handler consumes tab even when no focusable nodes are found; it | 37 // default tab handler consumes tab even when no focusable nodes are found; it |
| 62 // sets focus to Chrome and eats the event. | 38 // sets focus to Chrome and eats the event. |
| 63 if (key_event.GetDomKey() == ui::DomKey::TAB) | 39 if (key_event.GetDomKey() == ui::DomKey::TAB) |
| 64 capture = false; | 40 capture = false; |
| 65 | 41 |
| 42 extensions::ExtensionHost* host = chromeos::GetAccessibilityExtensionHost( |
| 43 extension_misc::kChromeVoxExtensionId); |
| 44 if (!host) |
| 45 return false; |
| 46 |
| 66 // Listen for any unhandled keyboard events from ChromeVox's background page | 47 // Listen for any unhandled keyboard events from ChromeVox's background page |
| 67 // when capturing keys to reinject. | 48 // when capturing keys to reinject. |
| 68 if (capture) | 49 if (capture) |
| 69 host->host_contents()->SetDelegate(this); | 50 host->host_contents()->SetDelegate(this); |
| 70 else | 51 else |
| 71 host->host_contents()->SetDelegate(nullptr); | 52 host->host_contents()->SetDelegate(nullptr); |
| 72 | 53 |
| 73 // Forward all key events to ChromeVox's background page. | 54 // Forward all key events to ChromeVox's background page. |
| 74 const content::NativeWebKeyboardEvent web_event(key_event); | 55 chromeos::ForwardKeyToExtension(key_event, host); |
| 75 rvh->GetWidget()->ForwardKeyboardEvent(web_event); | |
| 76 | 56 |
| 77 if ((key_event.key_code() >= ui::VKEY_F1) && | 57 if ((key_event.key_code() >= ui::VKEY_F1) && |
| 78 (key_event.key_code() <= ui::VKEY_F12)) | 58 (key_event.key_code() <= ui::VKEY_F12)) |
| 79 return false; | 59 return false; |
| 80 | 60 |
| 81 return capture; | 61 return capture; |
| 82 } | 62 } |
| 83 | 63 |
| 84 void SpokenFeedbackEventRewriterDelegate::HandleKeyboardEvent( | 64 void SpokenFeedbackEventRewriterDelegate::HandleKeyboardEvent( |
| 85 content::WebContents* source, | 65 content::WebContents* source, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (delegate_->DispatchKeyEventToChromeVox(key_event, capture)) | 112 if (delegate_->DispatchKeyEventToChromeVox(key_event, capture)) |
| 133 return ui::EVENT_REWRITE_DISCARD; | 113 return ui::EVENT_REWRITE_DISCARD; |
| 134 return ui::EVENT_REWRITE_CONTINUE; | 114 return ui::EVENT_REWRITE_CONTINUE; |
| 135 } | 115 } |
| 136 | 116 |
| 137 ui::EventRewriteStatus SpokenFeedbackEventRewriter::NextDispatchEvent( | 117 ui::EventRewriteStatus SpokenFeedbackEventRewriter::NextDispatchEvent( |
| 138 const ui::Event& last_event, | 118 const ui::Event& last_event, |
| 139 std::unique_ptr<ui::Event>* new_event) { | 119 std::unique_ptr<ui::Event>* new_event) { |
| 140 return ui::EVENT_REWRITE_CONTINUE; | 120 return ui::EVENT_REWRITE_CONTINUE; |
| 141 } | 121 } |
| OLD | NEW |