Commit ecdb6a3b authored by Katie D's avatar Katie D Committed by Commit Bot

Tapping an Select-to-Speak tray icon cancels further event propagation.

This makes it possible to read content in menus with the Select-to-Speak
tray button, for example on tablet mode.

Bug: 870922
Change-Id: I3501625721c8d49a2ec422377a83b9f8f036b228
Reviewed-on: https://chromium-review.googlesource.com/1176181
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583694}
parent b4bbf2b8
...@@ -333,6 +333,7 @@ component("ash") { ...@@ -333,6 +333,7 @@ component("ash") {
"sticky_keys/sticky_keys_state.h", "sticky_keys/sticky_keys_state.h",
"system/accessibility/dictation_button_tray.h", "system/accessibility/dictation_button_tray.h",
"system/accessibility/select_to_speak_tray.h", "system/accessibility/select_to_speak_tray.h",
"system/accessibility/select_to_speak_tray_utils.h",
"system/audio/audio_detailed_view.h", "system/audio/audio_detailed_view.h",
"system/audio/display_speaker_controller.h", "system/audio/display_speaker_controller.h",
"system/audio/tray_audio.h", "system/audio/tray_audio.h",
...@@ -970,6 +971,7 @@ component("ash") { ...@@ -970,6 +971,7 @@ component("ash") {
"sticky_keys/sticky_keys_overlay.cc", "sticky_keys/sticky_keys_overlay.cc",
"system/accessibility/dictation_button_tray.cc", "system/accessibility/dictation_button_tray.cc",
"system/accessibility/select_to_speak_tray.cc", "system/accessibility/select_to_speak_tray.cc",
"system/accessibility/select_to_speak_tray_utils.cc",
"system/audio/audio_detailed_view.cc", "system/audio/audio_detailed_view.cc",
"system/audio/display_speaker_controller.cc", "system/audio/display_speaker_controller.cc",
"system/audio/tray_audio.cc", "system/audio/tray_audio.cc",
......
...@@ -73,6 +73,10 @@ void SelectToSpeakTray::OnAccessibilityStatusChanged() { ...@@ -73,6 +73,10 @@ void SelectToSpeakTray::OnAccessibilityStatusChanged() {
CheckStatusAndUpdateIcon(); CheckStatusAndUpdateIcon();
} }
bool SelectToSpeakTray::ContainsPointInScreen(const gfx::Point& point) {
return GetBoundsInScreen().Contains(point);
}
void SelectToSpeakTray::CheckStatusAndUpdateIcon() { void SelectToSpeakTray::CheckStatusAndUpdateIcon() {
if (!Shell::Get()->accessibility_controller()->IsSelectToSpeakEnabled()) { if (!Shell::Get()->accessibility_controller()->IsSelectToSpeakEnabled()) {
SetVisible(false); SetVisible(false);
......
...@@ -34,6 +34,10 @@ class ASH_EXPORT SelectToSpeakTray : public TrayBackgroundView, ...@@ -34,6 +34,10 @@ class ASH_EXPORT SelectToSpeakTray : public TrayBackgroundView,
// AccessibilityObserver: // AccessibilityObserver:
void OnAccessibilityStatusChanged() override; void OnAccessibilityStatusChanged() override;
// Returns true if the screen point passed in is contained within this tray's
// bounds.
bool ContainsPointInScreen(const gfx::Point& point);
private: private:
friend class SelectToSpeakTrayTest; friend class SelectToSpeakTrayTest;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/accessibility/select_to_speak_tray_utils.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/accessibility/select_to_speak_tray.h"
#include "ash/system/status_area_widget.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/point.h"
namespace ash {
namespace select_to_speak_tray_utils {
bool SelectToSpeakTrayContainsPointInScreen(const gfx::Point& point) {
for (aura::Window* window : Shell::GetAllRootWindows()) {
SelectToSpeakTray* tray =
Shelf::ForWindow(window)->GetStatusAreaWidget()->select_to_speak_tray();
if (tray && tray->ContainsPointInScreen(point))
return true;
}
return false;
}
} // namespace select_to_speak_tray_utils
} // namespace ash
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_ACCESSIBILITY_SELECT_TO_SPEAK_TRAY_UTILS_H_
#define ASH_SYSTEM_ACCESSIBILITY_SELECT_TO_SPEAK_TRAY_UTILS_H_
#include "ash/ash_export.h"
namespace gfx {
class Point;
}
namespace ash {
namespace select_to_speak_tray_utils {
// Returns true if either the select-to-speak tray icon contains the
// given point (in screen space).
ASH_EXPORT bool SelectToSpeakTrayContainsPointInScreen(const gfx::Point& point);
} // namespace select_to_speak_tray_utils
} // namespace ash
#endif // ASH_SYSTEM_ACCESSIBILITY_SELECT_TO_SPEAK_TRAY_UTILS_H_
...@@ -12,6 +12,10 @@ specific_include_rules = { ...@@ -12,6 +12,10 @@ specific_include_rules = {
"+ash/magnifier/magnification_controller.h", "+ash/magnifier/magnification_controller.h",
"+ash/shell.h", "+ash/shell.h",
], ],
"select_to_speak_event_handler\.cc": [
# TODO(mash): Port the EventHandler to ash. http://crbug.com/874295
"+ash/system/accessibility/select_to_speak_tray_utils.h",
],
"switch_access_event_handler\.cc": [ "switch_access_event_handler\.cc": [
# TODO(mash): Fix. https://crbug.com/854025 # TODO(mash): Fix. https://crbug.com/854025
"+ash/shell.h", "+ash/shell.h",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/system/accessibility/select_to_speak_tray_utils.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/event_handler_common.h" #include "chrome/browser/chromeos/accessibility/event_handler_common.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
...@@ -166,8 +167,13 @@ void SelectToSpeakEventHandler::OnMouseEvent(ui::MouseEvent* event) { ...@@ -166,8 +167,13 @@ void SelectToSpeakEventHandler::OnMouseEvent(ui::MouseEvent* event) {
return; return;
DCHECK(event); DCHECK(event);
if (state_ == INACTIVE) if (state_ == INACTIVE) {
if (event->type() == ui::ET_MOUSE_PRESSED) {
// Check if the mouse event occurred on the tray button.
CancelEventIfOverSelectToSpeakTray(event);
}
return; return;
}
if (event->type() == ui::ET_MOUSE_PRESSED) { if (event->type() == ui::ET_MOUSE_PRESSED) {
if (state_ == SEARCH_DOWN || state_ == MOUSE_RELEASED) if (state_ == SEARCH_DOWN || state_ == MOUSE_RELEASED)
...@@ -207,6 +213,12 @@ void SelectToSpeakEventHandler::OnTouchEvent(ui::TouchEvent* event) { ...@@ -207,6 +213,12 @@ void SelectToSpeakEventHandler::OnTouchEvent(ui::TouchEvent* event) {
return; return;
DCHECK(event); DCHECK(event);
if (state_ == INACTIVE && event->type() == ui::ET_TOUCH_PRESSED) {
// Check if the touch event occurred on the tray button.
CancelEventIfOverSelectToSpeakTray(event);
}
// Only capture touch events if selection was requested or we are capturing // Only capture touch events if selection was requested or we are capturing
// touch events already. // touch events already.
if (state_ != SELECTION_REQUESTED && state_ != CAPTURING_TOUCH_ONLY) if (state_ != SELECTION_REQUESTED && state_ != CAPTURING_TOUCH_ONLY)
...@@ -296,4 +308,16 @@ void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { ...@@ -296,4 +308,16 @@ void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) {
} }
} }
// TODO(katie): Refactor this for mash, http://crbug.com/874295.
void SelectToSpeakEventHandler::CancelEventIfOverSelectToSpeakTray(
ui::LocatedEvent* event) {
if (ash::select_to_speak_tray_utils::SelectToSpeakTrayContainsPointInScreen(
event->root_location())) {
// Cancel the event so it does not cause any UI changes after a button tap.
CancelEvent(event);
// Enter the selecting mode as if we've clicked or tapped the button.
chromeos::AccessibilityManager::Get()->RequestSelectToSpeakStateChange();
}
}
} // namespace chromeos } // namespace chromeos
...@@ -52,6 +52,11 @@ class SelectToSpeakEventHandler : public ui::EventHandler { ...@@ -52,6 +52,11 @@ class SelectToSpeakEventHandler : public ui::EventHandler {
// Forwards a mouse event to the Select-to-Speak extension. // Forwards a mouse event to the Select-to-Speak extension.
void ForwardMouseEventToExtension(ui::MouseEvent* event); void ForwardMouseEventToExtension(ui::MouseEvent* event);
// For touch and mouse events events, the Select-to-Speak tray needs to
// cancel all further event propagation so that dialogs and menus do not
// close and therefore can be read by the user.
void CancelEventIfOverSelectToSpeakTray(ui::LocatedEvent* event);
enum State { enum State {
// The search key is not down, no selection has been requested. // The search key is not down, no selection has been requested.
// No other keys or mouse events are captured. // No other keys or mouse events are captured.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment