Commit 0043bf42 authored by glevin's avatar glevin Committed by Commit bot

Don't center screen magnification on empty focus rectangle

BUG=574951
TEST=On OOBE or login screen, turn on screen magnifier, then click on
blank parts of page.  Magnification shouldn't move to upper left of
screen.

Review URL: https://codereview.chromium.org/1564973002

Cr-Commit-Position: refs/heads/master@{#368443}
parent d6738334
......@@ -435,6 +435,10 @@ void MagnificationControllerImpl::HandleFocusedNodeChanged(
if (is_editable_node)
return;
// Nothing to recenter on.
if (node_bounds_in_screen.IsEmpty())
return;
gfx::Rect node_bounds_in_root =
ScreenUtil::ConvertRectFromScreen(root_window_, node_bounds_in_screen);
if (GetViewportRect().Contains(node_bounds_in_root))
......
......@@ -266,6 +266,33 @@ TEST_F(MagnificationControllerTest, PointOfInterest) {
EXPECT_EQ("450,350", CurrentPointOfInterest());
}
TEST_F(MagnificationControllerTest, FollowFocusChanged) {
// Enables magnifier and confirm the viewport is at center.
GetMagnificationController()->SetEnabled(true);
EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
EXPECT_EQ("200,150 400x300", GetViewport().ToString());
// Don't move viewport when focusing edit box.
GetMagnificationController()->HandleFocusedNodeChanged(
true, gfx::Rect(0, 0, 10, 10));
EXPECT_EQ("200,150 400x300", GetViewport().ToString());
// Move viewport to element in upper left.
GetMagnificationController()->HandleFocusedNodeChanged(
false, gfx::Rect(0, 0, 10, 10));
EXPECT_EQ("0,0 400x300", GetViewport().ToString());
// Move viewport to element in lower right.
GetMagnificationController()->HandleFocusedNodeChanged(
false, gfx::Rect(790, 590, 10, 10));
EXPECT_EQ("400,300 400x300", GetViewport().ToString());
// Don't follow focus onto empty rectangle.
GetMagnificationController()->HandleFocusedNodeChanged(
false, gfx::Rect(0, 0, 0, 0));
EXPECT_EQ("400,300 400x300", GetViewport().ToString());
}
TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) {
const aura::Env* env = aura::Env::GetInstance();
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
......
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