Commit ab7033b3 authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Fix accessibility text caret highlight in web contents

The text insertion caret in web contents can have a positive height but
zero width. Ensure the a11y highlight is still visible in this case.

This regressed in:
https://chromium-review.googlesource.com/c/chromium/src/+/1152373

due to the change to AccessibilityHighlightController::IsCaretVisible.

Bug: 882762
Test: added to ash_unittests
Change-Id: I2743cb234b49eb5c0d71ba5bf1d25e3869c2492f
Reviewed-on: https://chromium-review.googlesource.com/1241215Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593681}
parent 34963da9
......@@ -135,13 +135,19 @@ bool AccessibilityHighlightController::IsCursorVisible() {
bool AccessibilityHighlightController::IsCaretVisible(
const gfx::Rect& caret_bounds_in_screen) {
// Empty bounds are not visible. Don't use IsEmpty() because web contents
// carets can have positive height but zero width.
if (caret_bounds_in_screen.width() == 0 &&
caret_bounds_in_screen.height() == 0) {
return false;
}
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* active_window =
::wm::GetActivationClient(root_window)->GetActiveWindow();
if (!active_window)
active_window = root_window;
return !caret_bounds_in_screen.IsEmpty() &&
active_window->GetBoundsInScreen().Contains(caret_point_);
return active_window->GetBoundsInScreen().Contains(caret_point_);
}
void AccessibilityHighlightController::UpdateFocusAndCaretHighlights() {
......
......@@ -267,6 +267,34 @@ TEST_F(AccessibilityHighlightControllerTest, CaretRingDrawnOnlyWithinBounds) {
EXPECT_FALSE(focus_ring_controller->caret_layer_for_testing());
}
// Tests that a zero-width text caret still results in a visible highlight.
// https://crbug.com/882762
TEST_F(AccessibilityHighlightControllerTest, ZeroWidthCaretRingVisible) {
AccessibilityHighlightController highlight_controller;
MockTextInputClient text_input_client;
highlight_controller.HighlightCaret(true);
// Simulate a zero-width text caret.
gfx::Rect zero_width(0, 16);
text_input_client.SetCaretBounds(zero_width);
highlight_controller.OnCaretBoundsChanged(&text_input_client);
// Caret ring is created.
EXPECT_TRUE(Shell::Get()
->accessibility_focus_ring_controller()
->caret_layer_for_testing());
// Simulate an empty text caret.
gfx::Rect empty;
text_input_client.SetCaretBounds(empty);
highlight_controller.OnCaretBoundsChanged(&text_input_client);
// Caret ring is gone.
EXPECT_FALSE(Shell::Get()
->accessibility_focus_ring_controller()
->caret_layer_for_testing());
}
// Tests setting the caret bounds explicitly via AccessibilityController, rather
// than via the input method observer. This path is used in production in mash.
TEST_F(AccessibilityHighlightControllerTest, SetCaretBounds) {
......
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