Chromium Code Reviews| Index: chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc |
| diff --git a/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc b/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc |
| index 40d7840550974c7d3377ab1d662b8fdc77a0a60f..b511adc1d2b3b7bac955c5e508a7e01aab6428fe 100644 |
| --- a/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc |
| +++ b/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc |
| @@ -6,19 +6,40 @@ |
| #include "ash/shell.h" |
| #include "base/logging.h" |
| +#include "chrome/browser/chromeos/accessibility/event_handler_common.h" |
| #include "chrome/browser/speech/tts_controller.h" |
| #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
| -#include "chrome/common/extensions/api/automation_api_constants.h" |
| +#include "chrome/common/extensions/extension_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "ui/accessibility/ax_tree_id_registry.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/render_widget_host.h" |
| +#include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| +#include "ui/aura/client/screen_position_client.h" |
| #include "ui/aura/window.h" |
| #include "ui/display/display.h" |
| +#include "ui/events/blink/web_input_event.h" |
| #include "ui/events/event.h" |
| #include "ui/views/view.h" |
| #include "ui/views/widget/widget.h" |
| namespace chromeos { |
| +namespace { |
| + |
| +gfx::Point GetScreenLocationFromEvent(const ui::LocatedEvent& event) { |
| + aura::Window* root = |
| + static_cast<aura::Window*>(event.target())->GetRootWindow(); |
|
David Tseng
2017/05/07 06:10:27
Are all of these (|root|, |event.target()| always
dmazzoni
2017/05/10 19:43:18
I checked a few other places and it seems like the
|
| + aura::client::ScreenPositionClient* spc = |
| + aura::client::GetScreenPositionClient(root); |
| + if (!spc) |
| + return event.root_location(); |
| + |
| + gfx::Point screen_location(event.root_location()); |
| + spc->ConvertPointToScreen(root, &screen_location); |
| + return screen_location; |
| +} |
| +} // namespace |
| + |
| SelectToSpeakEventHandler::SelectToSpeakEventHandler() { |
| if (ash::Shell::HasInstance()) |
| ash::Shell::Get()->GetPrimaryRootWindow()->AddPreTargetHandler(this); |
| @@ -29,6 +50,11 @@ SelectToSpeakEventHandler::~SelectToSpeakEventHandler() { |
| ash::Shell::Get()->GetPrimaryRootWindow()->RemovePreTargetHandler(this); |
| } |
| +void SelectToSpeakEventHandler::CaptureForwardedEventsForTesting( |
| + SelectToSpeakForwardedEventDelegateForTesting* delegate) { |
| + event_delegate_for_testing_ = delegate; |
| +} |
| + |
| void SelectToSpeakEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| DCHECK(event); |
| @@ -96,42 +122,29 @@ void SelectToSpeakEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
| if (state_ != CAPTURING) |
| return; |
| - // If we're in the capturing state, send accessibility events to |
| - // the Select-to-speak extension based on the mouse event. |
| - // First, figure out what event to send. |
| - ui::AXEvent ax_event = ui::AX_EVENT_NONE; |
| - switch (event->type()) { |
| - case ui::ET_MOUSE_PRESSED: |
| - ax_event = ui::AX_EVENT_MOUSE_PRESSED; |
| - break; |
| - case ui::ET_MOUSE_DRAGGED: |
| - ax_event = ui::AX_EVENT_MOUSE_DRAGGED; |
| - break; |
| - case ui::ET_MOUSE_RELEASED: |
| - state_ = MOUSE_RELEASED; |
| - ax_event = ui::AX_EVENT_MOUSE_RELEASED; |
| - break; |
| - case ui::ET_MOUSE_MOVED: |
| - case ui::ET_MOUSE_ENTERED: |
| - case ui::ET_MOUSE_EXITED: |
| - ax_event = ui::AX_EVENT_MOUSE_MOVED; |
| - break; |
| - default: |
| + if (event->type() == ui::ET_MOUSE_RELEASED) |
| + state_ = MOUSE_RELEASED; |
| + |
| + // If we're in the capturing state, forward the mouse event to |
| + // select-to-speak. |
| + if (event_delegate_for_testing_) { |
| + event_delegate_for_testing_->OnForwardEventToSelectToSpeakExtension(*event); |
| + } else { |
| + extensions::ExtensionHost* host = GetAccessibilityExtensionHost( |
| + extension_misc::kSelectToSpeakExtensionId); |
| + if (!host) |
| return; |
| - } |
| - CancelEvent(event); |
| + content::RenderViewHost* rvh = host->render_view_host(); |
| + if (!rvh) |
| + return; |
| - ui::AXTreeIDRegistry* registry = ui::AXTreeIDRegistry::GetInstance(); |
| - ui::AXHostDelegate* delegate = |
| - registry->GetHostDelegate(extensions::api::automation::kDesktopTreeID); |
| - if (delegate) { |
| - ui::AXActionData action; |
| - action.action = ui::AX_ACTION_HIT_TEST; |
| - action.target_point = event->root_location(); |
| - action.hit_test_event_to_fire = ax_event; |
| - delegate->PerformAction(action); |
| + const blink::WebMouseEvent web_event = |
| + ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent)); |
| + rvh->GetWidget()->ForwardMouseEvent(web_event); |
| } |
| + |
| + CancelEvent(event); |
| } |
| void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { |