Commit 48060cf4 authored by oshima's avatar oshima Committed by Commit bot

Correctly convert warp bounds from screen to native.

This is a regression in https://codereview.chromium.org/1114633002c

BUG=485832
TEST=covered by unittests

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

Cr-Commit-Position: refs/heads/master@{#329567}
parent 5377f4d5
......@@ -780,6 +780,7 @@
'display/display_error_observer_chromeos_unittest.cc',
'display/display_info_unittest.cc',
'display/display_manager_unittest.cc',
'display/display_util_unittest.cc',
'display/extended_mouse_warp_controller_unittest.cc',
'display/mirror_window_controller_unittest.cc',
'display/mouse_cursor_event_filter_unittest.cc',
......
......@@ -164,31 +164,21 @@ gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host,
aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
gfx::Rect native_bounds = host->GetBounds();
native_bounds.Inset(ash_host->GetHostInsets());
bool vertical = bounds_in_screen.width() < bounds_in_screen.height();
gfx::Point start_in_native;
gfx::Point end_in_native;
if (vertical) {
start_in_native = bounds_in_screen.origin();
end_in_native = start_in_native;
end_in_native.set_y(bounds_in_screen.bottom());
} else {
start_in_native = bounds_in_screen.origin();
end_in_native = start_in_native;
end_in_native.set_x(bounds_in_screen.right());
}
gfx::Point start_in_native = bounds_in_screen.origin();
gfx::Point end_in_native = bounds_in_screen.bottom_right();
ConvertPointFromScreenToNative(host, &start_in_native);
ConvertPointFromScreenToNative(host, &end_in_native);
if (vertical) {
if (std::abs(start_in_native.x() - end_in_native.x()) <
std::abs(start_in_native.y() - end_in_native.y())) {
// vertical in native
int x = std::abs(native_bounds.x() - start_in_native.x()) <
std::abs(native_bounds.right() - start_in_native.x())
? native_bounds.x()
: native_bounds.right() - 1;
return gfx::Rect(x, std::min(start_in_native.y(), end_in_native.y()), 1,
end_in_native.y() - start_in_native.y());
std::abs(end_in_native.y() - start_in_native.y()));
} else {
// horizontal in native
int y = std::abs(native_bounds.y() - start_in_native.y()) <
......@@ -196,7 +186,7 @@ gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host,
? native_bounds.y()
: native_bounds.bottom() - 1;
return gfx::Rect(std::min(start_in_native.x(), end_in_native.x()), y,
end_in_native.x() - start_in_native.x(), 1);
std::abs(end_in_native.x() - start_in_native.x()), 1);
}
}
......
......@@ -42,8 +42,8 @@ void ComputeBoundary(const gfx::Display& primary_display,
// Creates edge bounds from |bounds_in_screen| that fits the edge
// of the native window for |ash_host|.
gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host,
const gfx::Rect& bounds_in_screen);
ASH_EXPORT gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host,
const gfx::Rect& bounds_in_screen);
// Moves the cursor to the point inside the |ash_host| that is closest to
// the point_in_screen, which may be outside of the root window.
......
// 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/display_util.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
namespace ash {
typedef test::AshTestBase DisplayUtilTest;
TEST_F(DisplayUtilTest, RotatedDisplay) {
if (!SupportsMultipleDisplays())
return;
{
UpdateDisplay("10+10-500x400,600+10-1000x600/r");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
EXPECT_EQ("509,20 1x300", rect0.ToString());
EXPECT_EQ("1289,10 300x1", rect1.ToString());
}
{
UpdateDisplay("10+10-500x400,600+10-1000x600/l");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
EXPECT_EQ("509,20 1x300", rect0.ToString());
EXPECT_EQ("610,609 300x1", rect1.ToString());
}
{
UpdateDisplay("10+10-500x400,600+10-1000x600/u");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
EXPECT_EQ("509,20 1x300", rect0.ToString());
EXPECT_EQ("1599,299 1x300", rect1.ToString());
}
{
UpdateDisplay("10+10-500x400/r,600+10-1000x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(399, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(400, 10, 1, 300));
EXPECT_EQ("199,409 300x1", rect0.ToString());
EXPECT_EQ("600,20 1x300", rect1.ToString());
}
{
UpdateDisplay("10+10-500x400/l,600+10-1000x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
EXPECT_EQ("20,10 300x1", rect0.ToString());
EXPECT_EQ("600,20 1x300", rect1.ToString());
}
{
UpdateDisplay("10+10-500x400/u,600+10-1000x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
AshWindowTreeHost* host0 =
GetRootWindowController(root_windows[0])->ash_host();
AshWindowTreeHost* host1 =
GetRootWindowController(root_windows[1])->ash_host();
gfx::Rect rect0 = GetNativeEdgeBounds(host0, gfx::Rect(499, 10, 1, 300));
gfx::Rect rect1 = GetNativeEdgeBounds(host1, gfx::Rect(500, 10, 1, 300));
EXPECT_EQ("10,99 1x300", rect0.ToString());
EXPECT_EQ("600,20 1x300", rect1.ToString());
}
}
} // namespace
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