Commit ea18a994 authored by dnicoara's avatar dnicoara Committed by Commit bot

Reland of: Remove deprecated cursor event filter for Ozone

Initial code review: https://codereview.chromium.org/580553002/

BUG=none

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

Cr-Commit-Position: refs/heads/master@{#295701}
parent 990cee7b
......@@ -112,12 +112,6 @@ component("ash") {
]
}
if (!use_ozone) {
sources -= [
"display/mouse_cursor_event_filter_ozone.cc",
]
}
if (!use_ozone) {
sources -= [
"host/ash_window_tree_host_ozone.cc",
......
......@@ -89,7 +89,6 @@
'display/mirror_window_controller.h',
'display/mouse_cursor_event_filter.cc',
'display/mouse_cursor_event_filter.h',
'display/mouse_cursor_event_filter_ozone.cc',
'display/projecting_observer_chromeos.cc',
'display/projecting_observer_chromeos.h',
'display/resolution_notification_controller.cc',
......
......@@ -152,7 +152,6 @@ void MouseCursorEventFilter::OnDisplaysInitialized() {
OnDisplayConfigurationChanged();
}
#if !defined(USE_OZONE)
void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
// Extra check for |num_connected_displays()| is for SystemDisplayApiTest
// that injects MockScreen.
......@@ -174,7 +173,6 @@ void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
else
UpdateVerticalEdgeBounds();
}
#endif
void MouseCursorEventFilter::OnMouseEvent(ui::MouseEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
......@@ -224,7 +222,6 @@ void MouseCursorEventFilter::MoveCursorTo(aura::Window* root,
root->GetHost()->MoveCursorToHostLocation(point_in_host);
}
#if !defined(USE_OZONE)
bool MouseCursorEventFilter::WarpMouseCursorIfNecessary(ui::MouseEvent* event) {
if (!event->HasNativeEvent())
return false;
......@@ -232,8 +229,16 @@ bool MouseCursorEventFilter::WarpMouseCursorIfNecessary(ui::MouseEvent* event) {
gfx::Point point_in_native =
ui::EventSystemLocationFromNative(event->native_event());
gfx::Point point_in_screen = event->location();
aura::Window* target = static_cast<aura::Window*>(event->target());
#if defined(USE_OZONE)
// TODO(dnicoara): crbug.com/415680 Move cursor warping into Ozone once Ozone
// has access to the logical display layout.
// Native events in Ozone are in the native window coordinate system. We need
// to translate them to get the global position.
point_in_native.Offset(target->GetHost()->GetBounds().x(),
target->GetHost()->GetBounds().y());
#endif
gfx::Point point_in_screen = event->location();
::wm::ConvertPointToScreen(target, &point_in_screen);
return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen);
......@@ -263,7 +268,6 @@ bool MouseCursorEventFilter::WarpMouseCursorInNativeCoords(
return true;
}
#endif
void MouseCursorEventFilter::UpdateHorizontalEdgeBounds() {
bool from_primary = Shell::GetPrimaryRootWindow() == drag_source_root_;
......@@ -374,7 +378,6 @@ void MouseCursorEventFilter::GetSrcAndDstRootWindows(aura::Window** src_root,
*dst_root = root_windows[0] == *src_root ? root_windows[1] : root_windows[0];
}
#if !defined(USE_OZONE)
bool MouseCursorEventFilter::WarpMouseCursorIfNecessaryForTest(
aura::Window* target_root,
const gfx::Point& point_in_screen) {
......@@ -383,6 +386,5 @@ bool MouseCursorEventFilter::WarpMouseCursorIfNecessaryForTest(
target_root->GetHost()->ConvertPointToNativeScreen(&native);
return WarpMouseCursorInNativeCoords(native, point_in_screen);
}
#endif
} // namespace ash
......@@ -80,14 +80,8 @@ class ASH_EXPORT MouseCursorEventFilter : public ui::EventHandler,
// Returns true if/ the cursor was moved.
bool WarpMouseCursorIfNecessary(ui::MouseEvent* event);
#if defined(USE_OZONE)
bool WarpMouseCursorInScreenCoords(aura::Window* target_root,
const gfx::Point& point_in_screen);
#else
bool WarpMouseCursorInNativeCoords(const gfx::Point& point_in_native,
const gfx::Point& point_in_screen);
#endif
// Update the edge/indicator bounds based on the current
// display configuration.
......
// Copyright 2014 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/display/mouse_cursor_event_filter.h"
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/window_util.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
src_edge_bounds_in_native_.SetRect(0, 0, 0, 0);
dst_edge_bounds_in_native_.SetRect(0, 0, 0, 0);
}
bool MouseCursorEventFilter::WarpMouseCursorIfNecessary(ui::MouseEvent* event) {
if (event->flags() & ui::EF_IS_SYNTHESIZED)
return false;
gfx::Point point_in_screen(event->location());
aura::Window* target = static_cast<aura::Window*>(event->target());
::wm::ConvertPointToScreen(target, &point_in_screen);
return WarpMouseCursorInScreenCoords(target->GetRootWindow(),
point_in_screen);
}
bool MouseCursorEventFilter::WarpMouseCursorInScreenCoords(
aura::Window* target_root,
const gfx::Point& point_in_screen) {
if (Shell::GetScreen()->GetNumDisplays() <= 1 ||
mouse_warp_mode_ == WARP_NONE)
return false;
// Do not warp again right after the cursor was warped. Sometimes the offset
// is not long enough and the cursor moves at the edge of the destination
// display. See crbug.com/278885
// TODO(mukai): simplify the offset calculation below, it would not be
// necessary anymore with this flag.
if (was_mouse_warped_) {
was_mouse_warped_ = false;
return false;
}
aura::Window* root_at_point = wm::GetRootWindowAt(point_in_screen);
gfx::Point point_in_root = point_in_screen;
::wm::ConvertPointFromScreen(root_at_point, &point_in_root);
gfx::Rect root_bounds = root_at_point->bounds();
int offset_x = 0;
int offset_y = 0;
// If the window is dragged between 2x display and 1x display,
// staring from 2x display, pointer location is rounded by the
// source scale factor (2x) so it will never reach the edge (which
// is odd). Shrink by scale factor of the display where the dragging
// started instead. Only integral scale factor is supported for now.
int shrink = scale_when_drag_started_;
// Make the bounds inclusive to detect the edge.
root_bounds.Inset(0, 0, shrink, shrink);
gfx::Rect src_indicator_bounds = src_indicator_bounds_;
src_indicator_bounds.Inset(-shrink, -shrink, -shrink, -shrink);
if (point_in_root.x() <= root_bounds.x()) {
// Use -2, not -1, to avoid infinite loop of pointer warp.
offset_x = -2 * scale_when_drag_started_;
} else if (point_in_root.x() >= root_bounds.right()) {
offset_x = 2 * scale_when_drag_started_;
} else if (point_in_root.y() <= root_bounds.y()) {
offset_y = -2 * scale_when_drag_started_;
} else if (point_in_root.y() >= root_bounds.bottom()) {
offset_y = 2 * scale_when_drag_started_;
} else {
return false;
}
gfx::Point point_in_dst_screen(point_in_screen);
point_in_dst_screen.Offset(offset_x, offset_y);
aura::Window* dst_root = wm::GetRootWindowAt(point_in_dst_screen);
// Warp the mouse cursor only if the location is in the indicator bounds
// or the mouse pointer is in the destination root.
if (mouse_warp_mode_ == WARP_DRAG &&
dst_root != drag_source_root_ &&
!src_indicator_bounds.Contains(point_in_screen)) {
return false;
}
::wm::ConvertPointFromScreen(dst_root, &point_in_dst_screen);
if (dst_root->bounds().Contains(point_in_dst_screen)) {
DCHECK_NE(dst_root, root_at_point);
was_mouse_warped_ = true;
dst_root->MoveCursorTo(point_in_dst_screen);
return true;
}
return false;
}
bool MouseCursorEventFilter::WarpMouseCursorIfNecessaryForTest(
aura::Window* target_root,
const gfx::Point& point_in_screen) {
return WarpMouseCursorInScreenCoords(target_root, point_in_screen);
}
} // namespac
......@@ -134,54 +134,6 @@ TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentSizeDisplays) {
aura::Env::GetInstance()->last_mouse_location().ToString());
}
#if defined(USE_OZONE)
// Verifies if the mouse pointer correctly moves between displays with
// different scale factors.
TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentScaleDisplays) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600*2");
ASSERT_EQ(
DisplayLayout::RIGHT,
Shell::GetInstance()->display_manager()->
GetCurrentDisplayLayout().position);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(900, 123));
// This emulates the dragging to the 2nd display, which has
// higher scale factor, by having 2nd display's root as target
// but have the edge of 1st display.
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[1], gfx::Point(498, 123)));
EXPECT_EQ("502,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
// Touch the edge of 2nd display again and make sure it warps to
// 1st dislay.
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[1], gfx::Point(500, 123)));
EXPECT_EQ("496,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
// Draging back from 1x to 2x.
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[0], gfx::Point(500, 123)));
EXPECT_EQ("496,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
UpdateDisplay("500x500*2,600x600");
// Draging back from 1x to 2x.
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[0], root_windows[1], gfx::Point(250, 123)));
EXPECT_EQ("246,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
#endif
#if !defined(USE_OZONE)
// Verifies if the mouse pointer correctly moves between displays with
// different scale factors. In native coords mode, there is no
// difference between drag and move.
......@@ -214,37 +166,6 @@ TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentScaleDisplaysInNative) {
EXPECT_EQ("498,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
#endif
#if defined(USE_OZONE)
TEST_F(MouseCursorEventFilterTest, DoNotWarpTwice) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(623, 123));
// Touch the right edge of the primary root window. Pointer should warp.
EXPECT_TRUE(event_filter()->WarpMouseCursorIfNecessaryForTest(
root_windows[0], gfx::Point(499, 11)));
EXPECT_EQ("501,11", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
// Touch the left edge of the secondary root window immediately. This should
// be ignored.
EXPECT_FALSE(event_filter()->WarpMouseCursorIfNecessaryForTest(
root_windows[1], gfx::Point(500, 11)));
// Touch the left edge of the secondary root window again, pointer should
// warp for this time.
EXPECT_TRUE(event_filter()->WarpMouseCursorIfNecessaryForTest(
root_windows[1], gfx::Point(500, 11)));
EXPECT_EQ("498,11", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
}
#endif
// Verifies if MouseCursorEventFilter::set_mouse_warp_mode() works as expected.
TEST_F(MouseCursorEventFilterTest, SetMouseWarpModeFlag) {
......
......@@ -543,11 +543,6 @@ TEST_F(ImmersiveFullscreenControllerTest, MouseEventsVerticalDisplayLayout) {
event_generator.MoveMouseTo(x, y_top_edge);
EXPECT_TRUE(top_edge_hover_timer_running());
// TODO(oshima): Provide a test API to handle mouse warp more easily.
#if defined(USE_OZONE)
EXPECT_NE(y_top_edge, aura::Env::GetInstance()->last_mouse_location().y());
#endif
// The timer should continue running if the user overshoots the top edge
// a bit.
event_generator.MoveMouseTo(x, y_top_edge - 2);
......
......@@ -68,7 +68,8 @@ void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget,
DriWindow* window = window_manager_->GetWindow(cursor_window_);
const gfx::Size& size = window->GetBounds().size();
cursor_location_.SetToMax(gfx::PointF(0, 0));
cursor_location_.SetToMin(gfx::PointF(size.width(), size.height()));
// Right and bottom edges are exclusive.
cursor_location_.SetToMin(gfx::PointF(size.width() - 1, size.height() - 1));
if (cursor_.get())
hardware_->MoveHardwareCursor(cursor_window_, bitmap_location());
......
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