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

Unified Diff: chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc

Issue 2827103003: Revert of Finish implementation of automation API hit testing for the desktop. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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..b9b9ba1577bc3fed3ace3960a068c5180831092b 100644
--- a/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc
+++ b/chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc
@@ -8,12 +8,11 @@
#include "base/logging.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 "content/public/browser/browser_thread.h"
-#include "ui/accessibility/ax_tree_id_registry.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/events/event.h"
+#include "ui/views/focus/view_storage.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
@@ -122,15 +121,42 @@
CancelEvent(event);
- 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);
+ // Find the View to post the accessibility event on.
+ aura::Window* event_target = static_cast<aura::Window*>(event->target());
+ aura::Window* hit_window = event_target;
+ if (!hit_window)
+ return;
+
+ views::Widget* hit_widget = views::Widget::GetWidgetForNativeView(hit_window);
+ while (!hit_widget) {
+ hit_window = hit_window->parent();
+ if (!hit_window)
+ break;
+
+ hit_widget = views::Widget::GetWidgetForNativeView(hit_window);
+ }
+
+ if (!hit_window || !hit_widget)
+ return;
+
+ gfx::Point window_location = event->location();
+ aura::Window::ConvertPointToTarget(event_target, hit_window,
+ &window_location);
+
+ views::View* root_view = hit_widget->GetRootView();
+ views::View* hit_view = root_view->GetEventHandlerForPoint(window_location);
+
+ if (hit_view) {
+ // Send the accessibility event, then save the view so we can post the
+ // cancel event on the same view if possible.
+ hit_view->NotifyAccessibilityEvent(ax_event, true);
+ if (!last_view_storage_id_) {
+ last_view_storage_id_ =
+ views::ViewStorage::GetInstance()->CreateStorageID();
+ }
+ views::ViewStorage::GetInstance()->RemoveView(last_view_storage_id_);
+ views::ViewStorage::GetInstance()->StoreView(last_view_storage_id_,
+ hit_view);
}
}
@@ -143,8 +169,20 @@
}
void SelectToSpeakEventHandler::SendCancelAXEvent() {
- AutomationManagerAura::GetInstance()->HandleEvent(
- nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED);
+ // If the user releases Search while the button is still down, cancel
+ // the Select-to-speak gesture. Try to post it on the same View that
+ // was last targeted, but if that's impossible, post it on the desktop.
+ views::View* last_view =
+ last_view_storage_id_
+ ? views::ViewStorage::GetInstance()->RetrieveView(
+ last_view_storage_id_)
+ : nullptr;
+ if (last_view) {
+ last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true);
+ } else {
+ AutomationManagerAura::GetInstance()->HandleEvent(
+ nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED);
+ }
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698