summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/root_window.cc28
-rw-r--r--ui/aura/root_window.h10
-rw-r--r--ui/aura/root_window_unittest.cc42
-rw-r--r--ui/aura/test/event_generator.cc1
-rw-r--r--ui/base/events/event.cc3
5 files changed, 76 insertions, 8 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 7c95443..ac66bdf 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -669,8 +669,28 @@ void RootWindow::ClearMouseHandlers() {
////////////////////////////////////////////////////////////////////////////////
// RootWindow, private:
-void RootWindow::TransformEventForDeviceScaleFactor(ui::LocatedEvent* event) {
+void RootWindow::TransformEventForDeviceScaleFactor(bool keep_inside_root,
+ ui::LocatedEvent* event) {
event->UpdateForRootTransform(GetRootTransform());
+#if defined(OS_CHROMEOS)
+ const gfx::Rect& root_bounds = bounds();
+ if (keep_inside_root &
+ host_->GetBounds().Contains(event->system_location()) &&
+ !root_bounds.Contains(event->root_location())) {
+ // Make sure that the mouse location inside the host window gets
+ // translated inside root window.
+ // TODO(oshima): This is (hopefully) short term bandaid to deal
+ // with calculation error in inverted matrix. We'll try better
+ // alternative (crbug.com/222483) for m28.
+ int x = event->location().x();
+ int y = event->location().y();
+ x = std::min(std::max(x, root_bounds.x()), root_bounds.right());
+ y = std::min(std::max(y, root_bounds.y()), root_bounds.bottom());
+ const gfx::Point new_location(x, y);
+ event->set_location(new_location);
+ event->set_root_location(new_location);
+ }
+#endif // defined(OS_CHROMEOS)
}
void RootWindow::HandleMouseMoved(const ui::MouseEvent& event, Window* target) {
@@ -884,7 +904,7 @@ bool RootWindow::OnHostMouseEvent(ui::MouseEvent* event) {
bool RootWindow::OnHostScrollEvent(ui::ScrollEvent* event) {
DispatchHeldEvents();
- TransformEventForDeviceScaleFactor(event);
+ TransformEventForDeviceScaleFactor(false, event);
SetLastMouseLocation(this, event->location());
synthesize_mouse_move_ = false;
@@ -930,7 +950,7 @@ bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) {
default:
break;
}
- TransformEventForDeviceScaleFactor(event);
+ TransformEventForDeviceScaleFactor(false, event);
bool handled = false;
Window* target = client::GetCaptureWindow(this);
if (!target) {
@@ -1031,7 +1051,7 @@ RootWindow* RootWindow::AsRootWindow() {
// RootWindow, private:
bool RootWindow::DispatchMouseEventImpl(ui::MouseEvent* event) {
- TransformEventForDeviceScaleFactor(event);
+ TransformEventForDeviceScaleFactor(true, event);
Window* target = mouse_pressed_handler_ ?
mouse_pressed_handler_ : client::GetCaptureWindow(this);
if (!target)
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 57d58f6..f2b8647 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
@@ -293,6 +294,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
void ClearMouseHandlers();
private:
+ FRIEND_TEST_ALL_PREFIXES(RootWindowTest, KeepTranslatedEventInRoot);
+
friend class Window;
friend class TestScreen;
@@ -308,8 +311,11 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// factor. The RootWindowHostDelegate dispatches events in the physical pixel
// coordinate. But the event processing from RootWindow onwards happen in
// device-independent pixel coordinate. So it is necessary to update the event
- // received from the host.
- void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event);
+ // received from the host. When |keep_inside_root| is true and the event's
+ // system location is inside host window's bounds, the location will be
+ // kept inside the root window's bounds.
+ void TransformEventForDeviceScaleFactor(bool keep_inside_root,
+ ui::LocatedEvent* event);
// Called whenever the mouse moves, tracks the current |mouse_moved_handler_|,
// sending exited and entered events as its value changes.
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index 8ff53c7..43b43ca 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -25,6 +25,7 @@
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
+#include "ui/gfx/transform.h"
namespace aura {
namespace {
@@ -208,6 +209,47 @@ TEST_F(RootWindowTest, TranslatedEvent) {
EXPECT_EQ("100,100", translated_event.root_location().ToString());
}
+#if defined(OS_CHROMEOS)
+// Make sure the mouse location is translated within the root
+// window. crbug.com/222483.
+TEST_F(RootWindowTest, KeepTranslatedEventInRoot) {
+ // Clockwise.
+ gfx::Transform rotate;
+ rotate.Translate(599, 0);
+ rotate.Rotate(90);
+ root_window()->SetTransform(rotate);
+
+ gfx::Point top_edge_on_host(100, 0);
+ ui::MouseEvent top_event(ui::ET_MOUSE_PRESSED,
+ top_edge_on_host,
+ top_edge_on_host, 0);
+ root_window()->TransformEventForDeviceScaleFactor(true, &top_event);
+ EXPECT_TRUE(root_window()->bounds().Contains(top_event.location()));
+
+ // Counter clockwise.
+ rotate.MakeIdentity();
+ rotate.Translate(0, 799);
+ rotate.Rotate(270);
+ root_window()->SetTransform(rotate);
+
+ gfx::Point bottom_edge_on_host(500, 799);
+ ui::MouseEvent bottom_event(ui::ET_MOUSE_PRESSED,
+ bottom_edge_on_host,
+ bottom_edge_on_host, 0);
+ root_window()->TransformEventForDeviceScaleFactor(true, &bottom_event);
+ EXPECT_TRUE(root_window()->bounds().Contains(bottom_event.location()));
+
+ // The locaion can be outside if |keep_inside_root| is false.
+ ui::MouseEvent bottom_event_outside(ui::ET_MOUSE_PRESSED,
+ bottom_edge_on_host,
+ bottom_edge_on_host, 0);
+ root_window()->TransformEventForDeviceScaleFactor(false,
+ &bottom_event_outside);
+ EXPECT_FALSE(root_window()->bounds().Contains(
+ bottom_event_outside.location()));
+}
+#endif
+
namespace {
class TestEventClient : public client::EventClient {
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc
index 82735fc..2285e42 100644
--- a/ui/aura/test/event_generator.cc
+++ b/ui/aura/test/event_generator.cc
@@ -156,6 +156,7 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) {
UpdateCurrentRootWindow(move_point);
ConvertPointToTarget(current_root_window_, &move_point);
ui::MouseEvent mouseev(event_type, move_point, move_point, flags_);
+ mouseev.set_system_location(move_point);
Dispatch(&mouseev);
}
current_location_ = point;
diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc
index dd0cb47..288eab9 100644
--- a/ui/base/events/event.cc
+++ b/ui/base/events/event.cc
@@ -274,8 +274,7 @@ void LocatedEvent::UpdateForRootTransform(
root_transform.TransformPointReverse(p);
// 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.
+ // is -1 instead of 0. crbug.com/222483.
root_location_ = location_ = gfx::ToFlooredPoint(p.AsPointF());
}