| Index: ash/display/mouse_cursor_event_filter.cc
|
| diff --git a/ash/display/mouse_cursor_event_filter.cc b/ash/display/mouse_cursor_event_filter.cc
|
| index 94501942ef88499855949b42f9ae696e0c4e40fa..8da1918ce32e144c382aed5bca6c0be561aa732e 100644
|
| --- a/ash/display/mouse_cursor_event_filter.cc
|
| +++ b/ash/display/mouse_cursor_event_filter.cc
|
| @@ -40,15 +40,6 @@ const int kMinimumIndicatorHeight = 200;
|
|
|
| const int kIndicatorThickness = 1;
|
|
|
| -// This is to disable the new mouse warp logic in case
|
| -// it caused the problem in the branch.
|
| -// Events from Ozone don't have a native event
|
| -#if defined(USE_OZONE)
|
| -bool enable_mouse_warp_in_native_coords = false;
|
| -#else
|
| -bool enable_mouse_warp_in_native_coords = true;
|
| -#endif
|
| -
|
| void ConvertPointFromScreenToNative(const aura::Window* root_window,
|
| gfx::Point* point) {
|
| wm::ConvertPointFromScreen(root_window, point);
|
| @@ -115,37 +106,8 @@ void MovePointInside(const gfx::Rect& native_bounds,
|
| point_in_native->set_y(native_bounds.bottom());
|
| }
|
|
|
| -// Moves the cursor to the point inside the root that is closest to
|
| -// the point_in_screen, which is outside of the root window.
|
| -void MoveCursorTo(aura::Window* root, const gfx::Point& point_in_screen) {
|
| - gfx::Point point_in_native = point_in_screen;
|
| - wm::ConvertPointFromScreen(root, &point_in_native);
|
| - root->GetHost()->ConvertPointToNativeScreen(&point_in_native);
|
| -
|
| - // now fit the point inside the native bounds.
|
| - gfx::Rect native_bounds = root->GetHost()->GetBounds();
|
| - gfx::Point native_origin = native_bounds.origin();
|
| - native_bounds.Inset(
|
| - GetRootWindowController(root)->ash_host()->GetHostInsets());
|
| - // Shrink further so that the mouse doesn't warp on the
|
| - // edge. The right/bottom needs to be shrink by 2 to subtract
|
| - // the 1 px from width/height value.
|
| - native_bounds.Inset(1, 1, 2, 2);
|
| -
|
| - MovePointInside(native_bounds, &point_in_native);
|
| - gfx::Point point_in_host = point_in_native;
|
| -
|
| - point_in_host.Offset(-native_origin.x(), -native_origin.y());
|
| - root->GetHost()->MoveCursorToHostLocation(point_in_host);
|
| -}
|
| -
|
| } // namespace
|
|
|
| -// static
|
| -bool MouseCursorEventFilter::IsMouseWarpInNativeCoordsEnabled() {
|
| - return enable_mouse_warp_in_native_coords;
|
| -}
|
| -
|
| MouseCursorEventFilter::MouseCursorEventFilter()
|
| : mouse_warp_mode_(WARP_ALWAYS),
|
| was_mouse_warped_(false),
|
| @@ -190,12 +152,12 @@ void MouseCursorEventFilter::OnDisplaysInitialized() {
|
| OnDisplayConfigurationChanged();
|
| }
|
|
|
| +#if !defined(USE_OZONE)
|
| void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
|
| // Extra check for |num_connected_displays()| is for SystemDisplayApiTest
|
| // that injects MockScreen.
|
| if (Shell::GetScreen()->GetNumDisplays() <= 1 ||
|
| - Shell::GetInstance()->display_manager()->num_connected_displays() <= 1 ||
|
| - !enable_mouse_warp_in_native_coords) {
|
| + Shell::GetInstance()->display_manager()->num_connected_displays() <= 1) {
|
| src_edge_bounds_in_native_.SetRect(0, 0, 0, 0);
|
| dst_edge_bounds_in_native_.SetRect(0, 0, 0, 0);
|
| return;
|
| @@ -212,6 +174,7 @@ void MouseCursorEventFilter::OnDisplayConfigurationChanged() {
|
| else
|
| UpdateVerticalEdgeBounds();
|
| }
|
| +#endif
|
|
|
| void MouseCursorEventFilter::OnMouseEvent(ui::MouseEvent* event) {
|
| aura::Window* target = static_cast<aura::Window*>(event->target());
|
| @@ -237,26 +200,43 @@ void MouseCursorEventFilter::OnMouseEvent(ui::MouseEvent* event) {
|
| event->StopPropagation();
|
| }
|
|
|
| +// static
|
| +void MouseCursorEventFilter::MoveCursorTo(aura::Window* root,
|
| + const gfx::Point& point_in_screen) {
|
| + gfx::Point point_in_native = point_in_screen;
|
| + wm::ConvertPointFromScreen(root, &point_in_native);
|
| + root->GetHost()->ConvertPointToNativeScreen(&point_in_native);
|
| +
|
| + // now fit the point inside the native bounds.
|
| + gfx::Rect native_bounds = root->GetHost()->GetBounds();
|
| + gfx::Point native_origin = native_bounds.origin();
|
| + native_bounds.Inset(
|
| + GetRootWindowController(root)->ash_host()->GetHostInsets());
|
| + // Shrink further so that the mouse doesn't warp on the
|
| + // edge. The right/bottom needs to be shrink by 2 to subtract
|
| + // the 1 px from width/height value.
|
| + native_bounds.Inset(1, 1, 2, 2);
|
| +
|
| + MovePointInside(native_bounds, &point_in_native);
|
| + gfx::Point point_in_host = point_in_native;
|
| +
|
| + point_in_host.Offset(-native_origin.x(), -native_origin.y());
|
| + root->GetHost()->MoveCursorToHostLocation(point_in_host);
|
| +}
|
| +
|
| +#if !defined(USE_OZONE)
|
| bool MouseCursorEventFilter::WarpMouseCursorIfNecessary(ui::MouseEvent* event) {
|
| - if (enable_mouse_warp_in_native_coords) {
|
| - if (!event->HasNativeEvent())
|
| - return false;
|
| + if (!event->HasNativeEvent())
|
| + return false;
|
|
|
| - gfx::Point point_in_native =
|
| - ui::EventSystemLocationFromNative(event->native_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());
|
| - wm::ConvertPointToScreen(target, &point_in_screen);
|
| + gfx::Point point_in_screen = event->location();
|
| + aura::Window* target = static_cast<aura::Window*>(event->target());
|
| + wm::ConvertPointToScreen(target, &point_in_screen);
|
|
|
| - return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen);
|
| - } else {
|
| - 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);
|
| - }
|
| + return WarpMouseCursorInNativeCoords(point_in_native, point_in_screen);
|
| }
|
|
|
| bool MouseCursorEventFilter::WarpMouseCursorInNativeCoords(
|
| @@ -283,77 +263,7 @@ bool MouseCursorEventFilter::WarpMouseCursorInNativeCoords(
|
|
|
| return true;
|
| }
|
| -
|
| -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;
|
| -}
|
| +#endif
|
|
|
| void MouseCursorEventFilter::UpdateHorizontalEdgeBounds() {
|
| bool from_primary = Shell::GetPrimaryRootWindow() == drag_source_root_;
|
| @@ -464,15 +374,15 @@ 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) {
|
| - if (!enable_mouse_warp_in_native_coords)
|
| - return WarpMouseCursorInScreenCoords(target_root, point_in_screen);
|
| gfx::Point native = point_in_screen;
|
| wm::ConvertPointFromScreen(target_root, &native);
|
| target_root->GetHost()->ConvertPointToNativeScreen(&native);
|
| return WarpMouseCursorInNativeCoords(native, point_in_screen);
|
| }
|
| +#endif
|
|
|
| } // namespace ash
|
|
|