Commit b3d030a1 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

Force accessibility focus rings to draw onscreen

Bug: 955783
Change-Id: I4a09ea2a5797d3438b3ba79b6010c3f0fe680624
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580595Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#654552}
parent 3ebcdfe3
...@@ -93,8 +93,13 @@ AccessibilityFocusRing CreateFromThreeRects(const gfx::Rect& top, ...@@ -93,8 +93,13 @@ AccessibilityFocusRing CreateFromThreeRects(const gfx::Rect& top,
return ring; return ring;
} }
constexpr int kScreenPaddingDip = 2;
} // namespace } // namespace
int AccessibilityFocusRing::GetScreenPaddingForTesting() {
return kScreenPaddingDip;
}
// static // static
gfx::Rect AccessibilityFocusRing::screen_bounds_for_testing_; gfx::Rect AccessibilityFocusRing::screen_bounds_for_testing_;
...@@ -163,26 +168,28 @@ AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape( ...@@ -163,26 +168,28 @@ AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape(
gfx::Rect top = orig_top_line; gfx::Rect top = orig_top_line;
gfx::Rect middle = orig_body; gfx::Rect middle = orig_body;
gfx::Rect bottom = orig_bottom_line; gfx::Rect bottom = orig_bottom_line;
gfx::Rect display = GetScreenBoundsForRect(middle);
gfx::Rect screen_bounds = GetScreenBoundsForRect(middle);
screen_bounds.Inset(kScreenPaddingDip, kScreenPaddingDip);
// Don't force a focus ring that is entirely offscreen to display. // Don't force a focus ring that is entirely offscreen to display.
if (IsFocusRingOffscreen(top, middle, bottom, display)) if (IsFocusRingOffscreen(top, middle, bottom, screen_bounds))
return CreateFromThreeRects(top, middle, bottom, margin); return CreateFromThreeRects(top, middle, bottom, margin);
if (top.Intersects(display)) if (top.Intersects(screen_bounds))
top.Intersect(display); top.Intersect(screen_bounds);
else else
ClipToBounds(&top, display); ClipToBounds(&top, screen_bounds);
if (middle.Intersects(display)) if (middle.Intersects(screen_bounds))
middle.Intersect(display); middle.Intersect(screen_bounds);
else else
ClipToBounds(&middle, display); ClipToBounds(&middle, screen_bounds);
if (bottom.Intersects(display)) if (bottom.Intersects(screen_bounds))
bottom.Intersect(display); bottom.Intersect(screen_bounds);
else else
ClipToBounds(&bottom, display); ClipToBounds(&bottom, screen_bounds);
int min_height = std::min(top.height(), bottom.height()); int min_height = std::min(top.height(), bottom.height());
margin = std::min(margin, min_height / 2); margin = std::min(margin, min_height / 2);
......
...@@ -94,6 +94,7 @@ struct ASH_EXPORT AccessibilityFocusRing { ...@@ -94,6 +94,7 @@ struct ASH_EXPORT AccessibilityFocusRing {
static void set_screen_bounds_for_testing(const gfx::Rect& bounds) { static void set_screen_bounds_for_testing(const gfx::Rect& bounds) {
screen_bounds_for_testing_ = bounds; screen_bounds_for_testing_ = bounds;
} }
static int GetScreenPaddingForTesting();
gfx::Point points[36]; gfx::Point points[36];
static gfx::Rect screen_bounds_for_testing_; static gfx::Rect screen_bounds_for_testing_;
......
...@@ -92,7 +92,7 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsSimpleBoundsCheck) { ...@@ -92,7 +92,7 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsSimpleBoundsCheck) {
// Easy sanity check. Given a single rectangle, make sure we get back // Easy sanity check. Given a single rectangle, make sure we get back
// a focus ring with the same bounds. // a focus ring with the same bounds.
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(10, 30, 70, 150)); rects.push_back(gfx::Rect(20, 30, 70, 150));
std::vector<AccessibilityFocusRing> rings; std::vector<AccessibilityFocusRing> rings;
group_.RectsToRings(rects, &rings); group_.RectsToRings(rects, &rings);
ASSERT_EQ(1U, rings.size()); ASSERT_EQ(1U, rings.size());
...@@ -117,13 +117,14 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsSnapToScreen) { ...@@ -117,13 +117,14 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsSnapToScreen) {
int x = -10; // offscreen int x = -10; // offscreen
int y = -20; // offscreen int y = -20; // offscreen
int length = 50; int length = 50;
int padding = AccessibilityFocusRing::GetScreenPaddingForTesting();
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(x, y, length, length)); rects.push_back(gfx::Rect(x, y, length, length));
std::vector<AccessibilityFocusRing> rings; std::vector<AccessibilityFocusRing> rings;
group_.RectsToRings(rects, &rings); group_.RectsToRings(rects, &rings);
gfx::Rect result(0, 0, length + x + group_.GetMargin(), gfx::Rect result(padding, padding, length + x + group_.GetMargin() - padding,
length + y + group_.GetMargin()); length + y + group_.GetMargin() - padding);
ASSERT_EQ(1U, rings.size()); ASSERT_EQ(1U, rings.size());
ASSERT_EQ(result, rings[0].GetBounds()); ASSERT_EQ(result, rings[0].GetBounds());
...@@ -133,75 +134,77 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsVerticalStack) { ...@@ -133,75 +134,77 @@ TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsVerticalStack) {
// Given two rects, one on top of each other, we should get back a // Given two rects, one on top of each other, we should get back a
// focus ring that surrounds them both. // focus ring that surrounds them both.
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(10, 10, 60, 30)); rects.push_back(gfx::Rect(20, 20, 60, 30));
rects.push_back(gfx::Rect(10, 40, 60, 30)); rects.push_back(gfx::Rect(20, 50, 60, 30));
std::vector<AccessibilityFocusRing> rings; std::vector<AccessibilityFocusRing> rings;
group_.RectsToRings(rects, &rings); group_.RectsToRings(rects, &rings);
ASSERT_EQ(1U, rings.size()); ASSERT_EQ(1U, rings.size());
ASSERT_EQ(AddMargin(gfx::Rect(10, 10, 60, 60)), rings[0].GetBounds()); ASSERT_EQ(AddMargin(gfx::Rect(20, 20, 60, 60)), rings[0].GetBounds());
} }
TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsHorizontalStack) { TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsHorizontalStack) {
// Given two rects, one next to the other horizontally, we should get back a // Given two rects, one next to the other horizontally, we should get back a
// focus ring that surrounds them both. // focus ring that surrounds them both.
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(10, 10, 60, 30)); rects.push_back(gfx::Rect(20, 20, 60, 30));
rects.push_back(gfx::Rect(70, 10, 60, 30)); rects.push_back(gfx::Rect(80, 20, 60, 30));
std::vector<AccessibilityFocusRing> rings; std::vector<AccessibilityFocusRing> rings;
group_.RectsToRings(rects, &rings); group_.RectsToRings(rects, &rings);
ASSERT_EQ(1U, rings.size()); ASSERT_EQ(1U, rings.size());
ASSERT_EQ(AddMargin(gfx::Rect(10, 10, 120, 30)), rings[0].GetBounds()); ASSERT_EQ(AddMargin(gfx::Rect(20, 20, 120, 30)), rings[0].GetBounds());
} }
TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsParagraphShape) { TEST_F(AccessibilityFocusRingGroupTest, RectsToRingsParagraphShape) {
// Given a simple paragraph shape, make sure we get something that // Given a simple paragraph shape, make sure we get something that
// outlines it correctly. // outlines it correctly.
AccessibilityFocusRing::set_screen_bounds_for_testing(
gfx::Rect(0, 0, 1000, 1000));
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect(10, 10, 180, 80)); rects.push_back(gfx::Rect(110, 110, 180, 80));
rects.push_back(gfx::Rect(10, 110, 580, 280)); rects.push_back(gfx::Rect(110, 210, 580, 280));
rects.push_back(gfx::Rect(410, 410, 180, 80)); rects.push_back(gfx::Rect(510, 510, 180, 80));
std::vector<AccessibilityFocusRing> rings; std::vector<AccessibilityFocusRing> rings;
group_.RectsToRings(rects, &rings); group_.RectsToRings(rects, &rings);
ASSERT_EQ(1U, rings.size()); ASSERT_EQ(1U, rings.size());
EXPECT_EQ(gfx::Rect(0, 0, 600, 500), rings[0].GetBounds()); EXPECT_EQ(gfx::Rect(100, 100, 600, 500), rings[0].GetBounds());
const gfx::Point* points = rings[0].points; const gfx::Point* points = rings[0].points;
EXPECT_EQ(gfx::Point(0, 90), points[0]); EXPECT_EQ(gfx::Point(100, 190), points[0]);
EXPECT_EQ(gfx::Point(0, 10), points[1]); EXPECT_EQ(gfx::Point(100, 110), points[1]);
EXPECT_EQ(gfx::Point(0, 0), points[2]); EXPECT_EQ(gfx::Point(100, 100), points[2]);
EXPECT_EQ(gfx::Point(10, 0), points[3]); EXPECT_EQ(gfx::Point(110, 100), points[3]);
EXPECT_EQ(gfx::Point(190, 0), points[4]); EXPECT_EQ(gfx::Point(290, 100), points[4]);
EXPECT_EQ(gfx::Point(200, 0), points[5]); EXPECT_EQ(gfx::Point(300, 100), points[5]);
EXPECT_EQ(gfx::Point(200, 10), points[6]); EXPECT_EQ(gfx::Point(300, 110), points[6]);
EXPECT_EQ(gfx::Point(200, 90), points[7]); EXPECT_EQ(gfx::Point(300, 190), points[7]);
EXPECT_EQ(gfx::Point(200, 100), points[8]); EXPECT_EQ(gfx::Point(300, 200), points[8]);
EXPECT_EQ(gfx::Point(210, 100), points[9]); EXPECT_EQ(gfx::Point(310, 200), points[9]);
EXPECT_EQ(gfx::Point(590, 100), points[10]); EXPECT_EQ(gfx::Point(690, 200), points[10]);
EXPECT_EQ(gfx::Point(600, 100), points[11]); EXPECT_EQ(gfx::Point(700, 200), points[11]);
EXPECT_EQ(gfx::Point(600, 110), points[12]); EXPECT_EQ(gfx::Point(700, 210), points[12]);
EXPECT_EQ(gfx::Point(600, 390), points[13]); EXPECT_EQ(gfx::Point(700, 490), points[13]);
EXPECT_EQ(gfx::Point(600, 400), points[14]); EXPECT_EQ(gfx::Point(700, 500), points[14]);
EXPECT_EQ(gfx::Point(600, 400), points[15]); EXPECT_EQ(gfx::Point(700, 500), points[15]);
EXPECT_EQ(gfx::Point(600, 400), points[16]); EXPECT_EQ(gfx::Point(700, 500), points[16]);
EXPECT_EQ(gfx::Point(600, 400), points[17]); EXPECT_EQ(gfx::Point(700, 500), points[17]);
EXPECT_EQ(gfx::Point(600, 410), points[18]); EXPECT_EQ(gfx::Point(700, 510), points[18]);
EXPECT_EQ(gfx::Point(600, 490), points[19]); EXPECT_EQ(gfx::Point(700, 590), points[19]);
EXPECT_EQ(gfx::Point(600, 500), points[20]); EXPECT_EQ(gfx::Point(700, 600), points[20]);
EXPECT_EQ(gfx::Point(590, 500), points[21]); EXPECT_EQ(gfx::Point(690, 600), points[21]);
EXPECT_EQ(gfx::Point(410, 500), points[22]); EXPECT_EQ(gfx::Point(510, 600), points[22]);
EXPECT_EQ(gfx::Point(400, 500), points[23]); EXPECT_EQ(gfx::Point(500, 600), points[23]);
EXPECT_EQ(gfx::Point(400, 490), points[24]); EXPECT_EQ(gfx::Point(500, 590), points[24]);
EXPECT_EQ(gfx::Point(400, 410), points[25]); EXPECT_EQ(gfx::Point(500, 510), points[25]);
EXPECT_EQ(gfx::Point(400, 400), points[26]); EXPECT_EQ(gfx::Point(500, 500), points[26]);
EXPECT_EQ(gfx::Point(390, 400), points[27]); EXPECT_EQ(gfx::Point(490, 500), points[27]);
EXPECT_EQ(gfx::Point(10, 400), points[28]); EXPECT_EQ(gfx::Point(110, 500), points[28]);
EXPECT_EQ(gfx::Point(0, 400), points[29]); EXPECT_EQ(gfx::Point(100, 500), points[29]);
EXPECT_EQ(gfx::Point(0, 390), points[30]); EXPECT_EQ(gfx::Point(100, 490), points[30]);
EXPECT_EQ(gfx::Point(0, 110), points[31]); EXPECT_EQ(gfx::Point(100, 210), points[31]);
EXPECT_EQ(gfx::Point(0, 100), points[32]); EXPECT_EQ(gfx::Point(100, 200), points[32]);
EXPECT_EQ(gfx::Point(0, 100), points[33]); EXPECT_EQ(gfx::Point(100, 200), points[33]);
EXPECT_EQ(gfx::Point(0, 100), points[34]); EXPECT_EQ(gfx::Point(100, 200), points[34]);
EXPECT_EQ(gfx::Point(0, 100), points[35]); EXPECT_EQ(gfx::Point(100, 200), points[35]);
} }
} // namespace ash } // namespace ash
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