Commit fedbb0d1 authored by acolwell's avatar acolwell Committed by Commit bot

Revert of Remove deprecated cursor event filter for Ozone (patchset #2...

Revert of Remove deprecated cursor event filter for Ozone (patchset #2 id:20001 of https://codereview.chromium.org/580553002/)

Reason for revert:
This appears to be causing ImmersiveFullscreenControllerTest.MouseEventsVerticalDisplayLayout to fail on Chromium OS Ozone bots.
http://build.chromium.org/p/chromium.chromiumos/buildstatus?builder=Linux%20ChromiumOS%20Ozone%20Tests%20%281%29&number=3404
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Ozone%20Tests%20%281%29/builds/3405

Original issue's description:
> Remove deprecated cursor event filter for Ozone
>
> Removes the old filter in favor of the new one which is enabled
> by default on non-Ozone CrOS builds.
>
> BUG=none
> TESTS=ran ash_unittests --gtest_filter=MouseCursorEventFilterTest.* on an Ozone build and manually tested on link_freon
>
> Committed: https://crrev.com/cee48a5ba8c24eb8b8ea7f789e3025ac79549a4d
> Cr-Commit-Position: refs/heads/master@{#295169}

TBR=oshima@chromium.org,dnicoara@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=none

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

Cr-Commit-Position: refs/heads/master@{#295178}
parent 85aa9d79
......@@ -112,6 +112,12 @@ 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,6 +89,7 @@
'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,6 +152,7 @@ void MouseCursorEventFilter::OnDisplaysInitialized() {
OnDisplayConfigurationChanged();
}
#if !defined(USE_OZONE)
void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
// Extra check for |num_connected_displays()| is for SystemDisplayApiTest
// that injects MockScreen.
......@@ -173,6 +174,7 @@ void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
else
UpdateVerticalEdgeBounds();
}
#endif
void MouseCursorEventFilter::OnMouseEvent(ui::MouseEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
......@@ -222,6 +224,7 @@ 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;
......@@ -260,6 +263,7 @@ bool MouseCursorEventFilter::WarpMouseCursorInNativeCoords(
return true;
}
#endif
void MouseCursorEventFilter::UpdateHorizontalEdgeBounds() {
bool from_primary = Shell::GetPrimaryRootWindow() == drag_source_root_;
......@@ -370,6 +374,7 @@ 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) {
......@@ -378,5 +383,6 @@ bool MouseCursorEventFilter::WarpMouseCursorIfNecessaryForTest(
target_root->GetHost()->ConvertPointToNativeScreen(&native);
return WarpMouseCursorInNativeCoords(native, point_in_screen);
}
#endif
} // namespace ash
......@@ -80,8 +80,14 @@ 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,6 +134,54 @@ 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.
......@@ -166,6 +214,37 @@ 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) {
......
......@@ -68,8 +68,7 @@ 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));
// Right and bottom edges are exclusive.
cursor_location_.SetToMin(gfx::PointF(size.width() - 1, size.height() - 1));
cursor_location_.SetToMin(gfx::PointF(size.width(), size.height()));
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