summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 14:40:23 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 14:40:23 +0000
commited44e7227cdb483f3377ac49289eaab837467c39 (patch)
treeece9a1b6bf453f849edb9cf2a768873ce32f4a9b
parent2202cf7b4ea5334b7b3f88bd59c57e33350c2474 (diff)
downloadchromium_src-ed44e7227cdb483f3377ac49289eaab837467c39.zip
chromium_src-ed44e7227cdb483f3377ac49289eaab837467c39.tar.gz
chromium_src-ed44e7227cdb483f3377ac49289eaab837467c39.tar.bz2
Use floored value for screen size and mouse location for consistency.
This is causing mismatch between expected bounds and actual mouse position in auto-hide code. - don't synthesize mouse event if the current location is outside of root window. This happens when dragging window and unnecessary to handle. - Fix system location in synthesized event. It's using screen coordinates instead of system coordinates. BUG=222137 TEST=updated the test. Tested manually. see bug. Review URL: https://chromiumcodereview.appspot.com/12579012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189269 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/display/display_info.cc2
-rw-r--r--ash/display/screen_position_controller_unittest.cc2
-rw-r--r--ash/wm/ash_native_cursor_manager_unittest.cc15
-rw-r--r--ui/aura/root_window.cc25
-rw-r--r--ui/aura/window_unittest.cc18
-rw-r--r--ui/base/events/event.cc7
6 files changed, 49 insertions, 20 deletions
diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc
index 7715c82..b46dceb 100644
--- a/ash/display/display_info.cc
+++ b/ash/display/display_info.cc
@@ -177,7 +177,7 @@ void DisplayInfo::UpdateDisplaySize() {
size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width());
gfx::SizeF size_f(size_in_pixel_);
size_f.Scale(ui_scale_);
- size_in_pixel_ = gfx::ToRoundedSize(size_f);
+ size_in_pixel_ = gfx::ToFlooredSize(size_f);
}
void DisplayInfo::SetOverscanInsets(bool custom,
diff --git a/ash/display/screen_position_controller_unittest.cc b/ash/display/screen_position_controller_unittest.cc
index bb82cf8..0cd4ca0 100644
--- a/ash/display/screen_position_controller_unittest.cc
+++ b/ash/display/screen_position_controller_unittest.cc
@@ -251,7 +251,7 @@ TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenUIScale) {
EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300));
// The point is on the 2nd host. Point on 2nd host (60,150) -
// - screen [+(150,0)]
- EXPECT_EQ("210,51", ConvertHostPointToScreen(60, 450));
+ EXPECT_EQ("210,49", ConvertHostPointToScreen(60, 450));
// Move |window_| to the 2nd.
window_->SetBoundsInScreen(gfx::Rect(300, 20, 50, 50),
diff --git a/ash/wm/ash_native_cursor_manager_unittest.cc b/ash/wm/ash_native_cursor_manager_unittest.cc
index ca0597d..e907b4c 100644
--- a/ash/wm/ash_native_cursor_manager_unittest.cc
+++ b/ash/wm/ash_native_cursor_manager_unittest.cc
@@ -12,6 +12,7 @@
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
+#include "ui/gfx/screen.h"
using views::corewm::CursorManager;
@@ -26,8 +27,10 @@ class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
MouseEventLocationDelegate() {}
virtual ~MouseEventLocationDelegate() {}
- const gfx::Point& mouse_event_location() const {
- return mouse_event_location_;
+ gfx::Point GetMouseEventLocationAndReset() {
+ gfx::Point p = mouse_event_location_;
+ mouse_event_location_.SetPoint(-100, -100);
+ return p;
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
@@ -143,21 +146,23 @@ TEST_F(AshNativeCursorManagerTest, MAYBE_DisabledMouseEventsLocation) {
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event);
// Location was in window.
- local_point = delegate->mouse_event_location();
+ local_point = delegate->GetMouseEventLocationAndReset();
aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
EXPECT_TRUE(window->bounds().Contains(local_point));
// Location is now out of window.
cursor_manager->DisableMouseEvents();
RunAllPendingInMessageLoop();
- local_point = delegate->mouse_event_location();
+ local_point = delegate->GetMouseEventLocationAndReset();
aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
EXPECT_FALSE(window->bounds().Contains(local_point));
+ EXPECT_FALSE(window->bounds().Contains(
+ gfx::Screen::GetScreenFor(window.get())->GetCursorScreenPoint()));
// Location is back in window.
cursor_manager->EnableMouseEvents();
RunAllPendingInMessageLoop();
- local_point = delegate->mouse_event_location();
+ local_point = delegate->GetMouseEventLocationAndReset();
aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
EXPECT_TRUE(window->bounds().Contains(local_point));
}
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 6ddc1c5..7c95443 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -266,7 +266,7 @@ void RootWindow::OnMouseEventsEnableStateChanged(bool enabled) {
void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
gfx::Point3F point_3f(location_in_dip);
GetRootTransform().TransformPoint(point_3f);
- host_->MoveCursorTo(gfx::ToRoundedPoint(point_3f.AsPointF()));
+ host_->MoveCursorTo(gfx::ToFlooredPoint(point_3f.AsPointF()));
SetLastMouseLocation(this, location_in_dip);
client::CursorClient* cursor_client = client::GetCursorClient(this);
if (cursor_client) {
@@ -398,13 +398,13 @@ void RootWindow::ConvertPointFromNativeScreen(gfx::Point* point) const {
void RootWindow::ConvertPointToHost(gfx::Point* point) const {
gfx::Point3F point_3f(*point);
GetRootTransform().TransformPoint(point_3f);
- *point = gfx::ToRoundedPoint(point_3f.AsPointF());
+ *point = gfx::ToFlooredPoint(point_3f.AsPointF());
}
void RootWindow::ConvertPointFromHost(gfx::Point* point) const {
gfx::Point3F point_3f(*point);
GetRootTransform().TransformPointReverse(point_3f);
- *point = gfx::ToRoundedPoint(point_3f.AsPointF());
+ *point = gfx::ToFlooredPoint(point_3f.AsPointF());
}
void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event,
@@ -807,10 +807,10 @@ void RootWindow::UpdateWindowSize(const gfx::Size& host_size) {
new_bounds.Scale(root_window_scale_ * root_window_scale_);
// Ignore the origin because RootWindow's insets are handled by
// the transform.
- // Round the size because the bounds is no longer aligned to
+ // Floor the size because the bounds is no longer aligned to
// backing pixel when |root_window_scale_| is specified
// (850 height at 1.25 scale becomes 1062.5 for example.)
- SetBounds(gfx::Rect(gfx::ToRoundedSize(new_bounds.size())));
+ SetBounds(gfx::Rect(gfx::ToFlooredSize(new_bounds.size())));
}
void RootWindow::OnWindowAddedToRootWindow(Window* attached) {
@@ -1134,17 +1134,20 @@ void RootWindow::SynthesizeMouseMoveEvent() {
if (!synthesize_mouse_move_)
return;
synthesize_mouse_move_ = false;
- gfx::Point3F point(GetLastMouseLocationInRoot());
- GetRootTransform().TransformPoint(point);
- gfx::Point orig_mouse_location = gfx::ToFlooredPoint(point.AsPointF());
+ gfx::Point root_mouse_location = GetLastMouseLocationInRoot();
+ if (!bounds().Contains(root_mouse_location))
+ return;
+ gfx::Point host_mouse_location = root_mouse_location;
+ ConvertPointToHost(&host_mouse_location);
// TODO(derat|oshima): Don't use mouse_button_flags_ as it's
// currently broken. See/ crbug.com/107931.
ui::MouseEvent event(ui::ET_MOUSE_MOVED,
- orig_mouse_location,
- orig_mouse_location,
+ host_mouse_location,
+ host_mouse_location,
ui::EF_IS_SYNTHESIZED);
- event.set_system_location(Env::GetInstance()->last_mouse_location());
+ ConvertPointToNativeScreen(&root_mouse_location);
+ event.set_system_location(root_mouse_location);
OnHostMouseEvent(&event);
}
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 8b31582..0800ec5 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -2089,6 +2089,24 @@ TEST_F(WindowTest, MouseEventsOnWindowChange) {
w11.reset();
RunAllPendingInMessageLoop();
EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset());
+
+ // Make sure we don't synthesize events if the mouse
+ // is outside of the root window.
+ generator.MoveMouseTo(-10, -10);
+ EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset());
+
+ // Adding new windows.
+ w11.reset(CreateTestWindowWithDelegate(
+ &d11, 1, gfx::Rect(0, 0, 100, 100), w1.get()));
+ RunAllPendingInMessageLoop();
+ EXPECT_EQ("0 0 0", d1.GetMouseMotionCountsAndReset());
+ EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset());
+
+ // Closing windows
+ w11.reset();
+ RunAllPendingInMessageLoop();
+ EXPECT_EQ("0 0 0", d1.GetMouseMotionCountsAndReset());
+ EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset());
}
class StackingMadrigalLayoutManager : public LayoutManager {
diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc
index b593259..dd0cb47 100644
--- a/ui/base/events/event.cc
+++ b/ui/base/events/event.cc
@@ -272,8 +272,11 @@ void LocatedEvent::UpdateForRootTransform(
// Transform has to be done at root level.
gfx::Point3F p(location_);
root_transform.TransformPointReverse(p);
- // Use ToRoundedPoint so that the value -0.00001 becomes 0.
- root_location_ = location_ = gfx::ToRoundedPoint(p.AsPointF());
+ // TODO(oshima): Translating a point using reversed matrix can
+ // results in small error like 0 -> -0.01, whose floored value
+ // is -1 instead of 0. Investigate the best way to handle this,
+ // instead of just rounding it.
+ root_location_ = location_ = gfx::ToFlooredPoint(p.AsPointF());
}
////////////////////////////////////////////////////////////////////////////////