Commit 766654ac authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

[Docked Magnifier] Follow touch events

Make the docked magnifier follow touch events.

BUG=837285
TEST=Added new test

Change-Id: Id1fdbe047cdcbf3e8cd35cbf5ddd8712c0c3828c
Reviewed-on: https://chromium-review.googlesource.com/1044493Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556154}
parent 05659419
...@@ -318,6 +318,16 @@ void DockedMagnifierController::OnScrollEvent(ui::ScrollEvent* event) { ...@@ -318,6 +318,16 @@ void DockedMagnifierController::OnScrollEvent(ui::ScrollEvent* event) {
} }
} }
void DockedMagnifierController::OnTouchEvent(ui::TouchEvent* event) {
DCHECK(GetEnabled());
aura::Window* target = static_cast<aura::Window*>(event->target());
aura::Window* event_root = target->GetRootWindow();
gfx::Point event_screen_point = event->root_location();
::wm::ConvertPointToScreen(event_root, &event_screen_point);
CenterOnPoint(event_screen_point);
}
void DockedMagnifierController::OnCaretBoundsChanged( void DockedMagnifierController::OnCaretBoundsChanged(
const ui::TextInputClient* client) { const ui::TextInputClient* client) {
DCHECK(GetEnabled()); DCHECK(GetEnabled());
......
...@@ -88,6 +88,7 @@ class ASH_EXPORT DockedMagnifierController ...@@ -88,6 +88,7 @@ class ASH_EXPORT DockedMagnifierController
// ui::EventHandler: // ui::EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
void OnScrollEvent(ui::ScrollEvent* event) override; void OnScrollEvent(ui::ScrollEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
// ui::InputMethodObserver: // ui::InputMethodObserver:
void OnFocus() override {} void OnFocus() override {}
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "ui/display/manager/managed_display_info.h" #include "ui/display/manager/managed_display_info.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash { namespace ash {
...@@ -87,6 +88,40 @@ class DockedMagnifierTest : public NoSessionAshTestBase { ...@@ -87,6 +88,40 @@ class DockedMagnifierTest : public NoSessionAshTestBase {
AccountId::FromUserEmail(email)); AccountId::FromUserEmail(email));
} }
// Tests that when the magnifier layer's transform is applied on the point in
// the |root_window| coordinates that corresponds to the
// |point_of_interest_in_screen|, the resulting point is at the center of the
// magnifier viewport widget.
void TestMagnifierLayerTransform(
const gfx::Point& point_of_interest_in_screen,
const aura::Window* root_window) {
// Convert to root coordinates.
gfx::Point point_of_interest_in_root = point_of_interest_in_screen;
::wm::ConvertPointFromScreen(root_window, &point_of_interest_in_root);
// Account for point of interest being outside the minimum height threshold.
// Do this in gfx::PointF to avoid rounding errors.
gfx::PointF point_of_interest_in_root_f(point_of_interest_in_root);
const float min_pov_height =
controller()->GetMinimumPointOfInterestHeightForTesting();
if (point_of_interest_in_root_f.y() < min_pov_height)
point_of_interest_in_root_f.set_y(min_pov_height);
const ui::Layer* magnifier_layer =
controller()->GetViewportMagnifierLayerForTesting();
// The magnifier layer's transform, when applied to the point of interest
// (in root coordinates), should take it to the point at the center of the
// viewport widget (also in root coordinates).
magnifier_layer->transform().TransformPoint(&point_of_interest_in_root_f);
const views::Widget* viewport_widget =
controller()->GetViewportWidgetForTesting();
const gfx::Point viewport_center_in_root =
viewport_widget->GetNativeWindow()
->GetBoundsInRootWindow()
.CenterPoint();
EXPECT_EQ(viewport_center_in_root,
gfx::ToFlooredPoint(point_of_interest_in_root_f));
}
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -279,6 +314,35 @@ TEST_F(DockedMagnifierTest, DisplaysWorkAreas) { ...@@ -279,6 +314,35 @@ TEST_F(DockedMagnifierTest, DisplaysWorkAreas) {
gfx::Rect(gfx::Point(0, 0), disp_2_bounds.size())); gfx::Rect(gfx::Point(0, 0), disp_2_bounds.size()));
} }
// Tests that the Docked Magnifier follows touch events.
TEST_F(DockedMagnifierTest, TouchEvents) {
UpdateDisplay("800x600,800+0-400x300");
const auto root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2u, root_windows.size());
controller()->SetEnabled(true);
EXPECT_TRUE(controller()->GetEnabled());
controller()->SetScale(4.0f);
// Generate some touch events in both displays and expect the magnifier
// viewport moves accordingly.
gfx::Point touch_point(200, 350);
GetEventGenerator().PressMoveAndReleaseTouchTo(touch_point);
const views::Widget* viewport_widget =
controller()->GetViewportWidgetForTesting();
EXPECT_EQ(root_windows[0], viewport_widget->GetNativeView()->GetRootWindow());
TestMagnifierLayerTransform(touch_point, root_windows[0]);
// Touch a new point in the other display.
touch_point = gfx::Point(900, 200);
GetEventGenerator().PressMoveAndReleaseTouchTo(touch_point);
// New viewport widget is created in the second display.
ASSERT_NE(viewport_widget, controller()->GetViewportWidgetForTesting());
viewport_widget = controller()->GetViewportWidgetForTesting();
EXPECT_EQ(root_windows[1], viewport_widget->GetNativeView()->GetRootWindow());
TestMagnifierLayerTransform(touch_point, root_windows[1]);
}
// Tests the behavior of the magnifier when displays are added or removed. // Tests the behavior of the magnifier when displays are added or removed.
TEST_F(DockedMagnifierTest, AddRemoveDisplays) { TEST_F(DockedMagnifierTest, AddRemoveDisplays) {
// Start with a single display. // Start with a single display.
...@@ -374,35 +438,30 @@ TEST_F(DockedMagnifierTest, TransformSimple) { ...@@ -374,35 +438,30 @@ TEST_F(DockedMagnifierTest, TransformSimple) {
// Move the cursor to the center of the screen. // Move the cursor to the center of the screen.
gfx::Point point_of_interest(400, 400); gfx::Point point_of_interest(400, 400);
GetEventGenerator().MoveMouseTo(point_of_interest); GetEventGenerator().MoveMouseTo(point_of_interest);
const ui::Layer* magnifier_layer = TestMagnifierLayerTransform(point_of_interest, root_windows[0]);
controller()->GetViewportMagnifierLayerForTesting();
// The magnifier layer's transform, when applied to the point of interest,
// should take it to the point at the center of the viewport widget.
magnifier_layer->transform().TransformPoint(&point_of_interest);
const gfx::Point viewport_center(
viewport_widget->GetWindowBoundsInScreen().CenterPoint());
EXPECT_EQ(viewport_center, point_of_interest);
// Move the cursor to the bottom right corner. // Move the cursor to the bottom right corner.
point_of_interest = gfx::Point(799, 799); point_of_interest = gfx::Point(799, 799);
GetEventGenerator().MoveMouseTo(point_of_interest); GetEventGenerator().MoveMouseTo(point_of_interest);
// Similar to the above case the expected transform should still take the TestMagnifierLayerTransform(point_of_interest, root_windows[0]);
// point to the center of the viewport widget.
magnifier_layer->transform().TransformPoint(&point_of_interest);
EXPECT_EQ(viewport_center, point_of_interest);
// Tricky: Move the cursor to the top right corner, such that the cursor is // Tricky: Move the cursor to the top right corner, such that the cursor is
// over the magnifier viewport. The transform should be such that the viewport // over the magnifier viewport. The transform should be such that the viewport
// doesn't show itself. // doesn't show itself.
point_of_interest = gfx::Point(799, 0); point_of_interest = gfx::Point(799, 0);
GetEventGenerator().MoveMouseTo(point_of_interest); GetEventGenerator().MoveMouseTo(point_of_interest);
TestMagnifierLayerTransform(point_of_interest, root_windows[0]);
// In this case, our point of interest is changed to be at the bottom of the // In this case, our point of interest is changed to be at the bottom of the
// separator, and it should go to the center of the top *edge* of the viewport // separator, and it should go to the center of the top *edge* of the viewport
// widget. // widget.
point_of_interest.set_y(viewport_height + point_of_interest.set_y(viewport_height +
DockedMagnifierController::kSeparatorHeight); DockedMagnifierController::kSeparatorHeight);
const gfx::Point viewport_center =
viewport_widget->GetNativeWindow()->GetBoundsInRootWindow().CenterPoint();
gfx::Point viewport_top_edge_center = viewport_center; gfx::Point viewport_top_edge_center = viewport_center;
viewport_top_edge_center.set_y(0); viewport_top_edge_center.set_y(0);
const ui::Layer* magnifier_layer =
controller()->GetViewportMagnifierLayerForTesting();
magnifier_layer->transform().TransformPoint(&point_of_interest); magnifier_layer->transform().TransformPoint(&point_of_interest);
EXPECT_EQ(viewport_top_edge_center, point_of_interest); EXPECT_EQ(viewport_top_edge_center, point_of_interest);
// The minimum height for the point of interest is the bottom of the viewport // The minimum height for the point of interest is the bottom of the viewport
...@@ -419,6 +478,7 @@ TEST_F(DockedMagnifierTest, TransformSimple) { ...@@ -419,6 +478,7 @@ TEST_F(DockedMagnifierTest, TransformSimple) {
EXPECT_FLOAT_EQ(scale2, controller()->GetScale()); EXPECT_FLOAT_EQ(scale2, controller()->GetScale());
// The transform behaves exactly as above even with a different scale. // The transform behaves exactly as above even with a different scale.
point_of_interest = gfx::Point(799, 0); point_of_interest = gfx::Point(799, 0);
TestMagnifierLayerTransform(point_of_interest, root_windows[0]);
point_of_interest.set_y(viewport_height + point_of_interest.set_y(viewport_height +
DockedMagnifierController::kSeparatorHeight); DockedMagnifierController::kSeparatorHeight);
magnifier_layer->transform().TransformPoint(&point_of_interest); magnifier_layer->transform().TransformPoint(&point_of_interest);
...@@ -453,23 +513,15 @@ TEST_F(DockedMagnifierTest, TextInputFieldEvents) { ...@@ -453,23 +513,15 @@ TEST_F(DockedMagnifierTest, TextInputFieldEvents) {
// The text input caret center point will be our point of interest. When it // The text input caret center point will be our point of interest. When it
// goes through the magnifier layer transform, it should end up being in the // goes through the magnifier layer transform, it should end up being in the
// center of the viewport. // center of the viewport.
const ui::Layer* magnifier_layer =
controller()->GetViewportMagnifierLayerForTesting();
gfx::Point caret_center(text_input_helper.GetCaretBounds().CenterPoint()); gfx::Point caret_center(text_input_helper.GetCaretBounds().CenterPoint());
magnifier_layer->transform().TransformPoint(&caret_center); TestMagnifierLayerTransform(caret_center, root_windows[0]);
const views::Widget* viewport_widget =
controller()->GetViewportWidgetForTesting();
const gfx::Point viewport_center(
viewport_widget->GetWindowBoundsInScreen().CenterPoint());
EXPECT_EQ(caret_center, viewport_center);
// Simulate typing by pressing some keys while focus is in the text field. The // Simulate typing by pressing some keys while focus is in the text field. The
// transformed caret center should always go to the viewport center. // transformed caret center should always go to the viewport center.
GetEventGenerator().PressKey(ui::VKEY_A, 0); GetEventGenerator().PressKey(ui::VKEY_A, 0);
GetEventGenerator().ReleaseKey(ui::VKEY_A, 0); GetEventGenerator().ReleaseKey(ui::VKEY_A, 0);
gfx::Point new_caret_center(text_input_helper.GetCaretBounds().CenterPoint()); gfx::Point new_caret_center(text_input_helper.GetCaretBounds().CenterPoint());
magnifier_layer->transform().TransformPoint(&new_caret_center); TestMagnifierLayerTransform(new_caret_center, root_windows[0]);
EXPECT_EQ(new_caret_center, viewport_center);
} }
TEST_F(DockedMagnifierTest, FocusChangeEvents) { TEST_F(DockedMagnifierTest, FocusChangeEvents) {
...@@ -490,23 +542,15 @@ TEST_F(DockedMagnifierTest, FocusChangeEvents) { ...@@ -490,23 +542,15 @@ TEST_F(DockedMagnifierTest, FocusChangeEvents) {
// Focus on the first button and expect the magnifier to be centered around // Focus on the first button and expect the magnifier to be centered around
// its center. // its center.
focus_test_helper.FocusFirstButton(); focus_test_helper.FocusFirstButton();
const ui::Layer* magnifier_layer =
controller()->GetViewportMagnifierLayerForTesting();
gfx::Point button_1_center( gfx::Point button_1_center(
focus_test_helper.GetFirstButtonBoundsInRoot().CenterPoint()); focus_test_helper.GetFirstButtonBoundsInRoot().CenterPoint());
magnifier_layer->transform().TransformPoint(&button_1_center); TestMagnifierLayerTransform(button_1_center, root_windows[0]);
const views::Widget* viewport_widget =
controller()->GetViewportWidgetForTesting();
const gfx::Point viewport_center(
viewport_widget->GetWindowBoundsInScreen().CenterPoint());
EXPECT_EQ(button_1_center, viewport_center);
// Similarly if we focus on the second button. // Similarly if we focus on the second button.
focus_test_helper.FocusSecondButton(); focus_test_helper.FocusSecondButton();
gfx::Point button_2_center( gfx::Point button_2_center(
focus_test_helper.GetSecondButtonBoundsInRoot().CenterPoint()); focus_test_helper.GetSecondButtonBoundsInRoot().CenterPoint());
magnifier_layer->transform().TransformPoint(&button_2_center); TestMagnifierLayerTransform(button_2_center, root_windows[0]);
EXPECT_EQ(button_2_center, viewport_center);
} }
// Tests that viewport layer is inverted properly when the status of the High // Tests that viewport layer is inverted properly when the status of the High
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
-DockedMagnifierTest.TestEnableAndDisable -DockedMagnifierTest.TestEnableAndDisable
-DockedMagnifierTest.TestOutsidePrefsUpdates -DockedMagnifierTest.TestOutsidePrefsUpdates
-DockedMagnifierTest.TextInputFieldEvents -DockedMagnifierTest.TextInputFieldEvents
-DockedMagnifierTest.TouchEvents
-DockedMagnifierTest.TransformSimple -DockedMagnifierTest.TransformSimple
-MagnifiersAcceleratorsTester.TestToggleMagnifiers -MagnifiersAcceleratorsTester.TestToggleMagnifiers
......
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