summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-26 01:39:49 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-26 01:39:49 +0000
commit68a8e06e889030ab860eb3c8040d9812d4b2b8fa (patch)
tree60717f024907613aeb469f16900c2e371d8ca69a
parentfb0f86daed8fed754c67e8fb4828c4c89061ef1d (diff)
downloadchromium_src-68a8e06e889030ab860eb3c8040d9812d4b2b8fa.zip
chromium_src-68a8e06e889030ab860eb3c8040d9812d4b2b8fa.tar.gz
chromium_src-68a8e06e889030ab860eb3c8040d9812d4b2b8fa.tar.bz2
Use translated root location in WebInputEvent
This adds root_location to LocatedEvent Converted a couple of tests to use EventGenerator. BUG=none TEST=added TranslatedEvent test to window_unittests. Review URL: http://codereview.chromium.org/9117018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119169 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/drag_drop/drag_drop_controller.cc13
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc85
-rw-r--r--ash/tooltips/tooltip_controller_unittest.cc39
-rw-r--r--ash/wm/root_window_event_filter_unittest.cc24
-rw-r--r--content/browser/renderer_host/web_input_event_aura.cc23
-rw-r--r--ui/aura/event.cc26
-rw-r--r--ui/aura/event.h25
-rw-r--r--ui/aura/event_unittest.cc8
-rw-r--r--ui/aura/root_window.cc9
-rw-r--r--ui/aura/root_window_unittest.cc28
-rw-r--r--ui/aura/test/event_generator.cc38
-rw-r--r--ui/aura/test/event_generator.h13
-rw-r--r--ui/aura/window_unittest.cc17
13 files changed, 186 insertions, 162 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index c2db4ac..42a58ab 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -100,12 +100,18 @@ void DragDropController::DragUpdate(aura::Window* target,
}
dragged_window_ = target;
if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
- aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
+ aura::DropTargetEvent e(*drag_data_,
+ event.location(),
+ event.root_location(),
+ drag_operation_);
delegate->OnDragEntered(e);
}
} else {
if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
- aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
+ aura::DropTargetEvent e(*drag_data_,
+ event.location(),
+ event.root_location(),
+ drag_operation_);
int op = delegate->OnDragUpdated(e);
gfx::NativeCursor cursor = (op == ui::DragDropTypes::DRAG_NONE)?
aura::kCursorMove : aura::kCursorHand;
@@ -126,7 +132,8 @@ void DragDropController::Drop(aura::Window* target,
aura::client::DragDropDelegate* delegate = NULL;
DCHECK(target == dragged_window_);
if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
- aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
+ aura::DropTargetEvent e(
+ *drag_data_, event.location(), event.root_location(), drag_operation_);
drag_operation_ = delegate->OnPerformDrop(e);
if (drag_operation_ == 0)
StartCanceledAnimation();
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index 49273ce..1c0a054 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -10,6 +10,7 @@
#include "base/utf_string_conversions.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/test/event_generator.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
@@ -208,14 +209,10 @@ TEST_F(DragDropControllerTest, DragDropInSingleViewTest) {
scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view = new DragTestView;
AddViewToWidgetAndResize(widget.get(), drag_view);
- gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
-
- aura::MouseEvent event1(ui::ET_MOUSE_PRESSED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event1);
+ aura::test::EventGenerator generator(widget->GetNativeView());
+ generator.PressLeftButton();
int num_drags = 17;
for (int i = 0; i < num_drags; ++i) {
@@ -225,15 +222,10 @@ TEST_F(DragDropControllerTest, DragDropInSingleViewTest) {
// drag_data_ to a fake drag data object that we created.
if (i > 0)
UpdateDragData(&data);
- point.Offset(0, 1);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.MoveMouseBy(0, 1);
}
- aura::MouseEvent event2(ui::ET_MOUSE_RELEASED, point, 0);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event2);
+ generator.ReleaseLeftButton();
EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
EXPECT_EQ(num_drags - 1 - drag_view->VerticalDragThreshold(),
@@ -254,17 +246,16 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsSingleWidgetTest) {
scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view1 = new DragTestView;
AddViewToWidgetAndResize(widget.get(), drag_view1);
- gfx::Point point = drag_view1->bounds().CenterPoint();
DragTestView* drag_view2 = new DragTestView;
AddViewToWidgetAndResize(widget.get(), drag_view2);
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
- aura::MouseEvent event1(ui::ET_MOUSE_PRESSED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event1);
+ aura::test::EventGenerator generator;
+ generator.MoveMouseRelativeTo(widget->GetNativeView(),
+ drag_view1->bounds().CenterPoint());
+ generator.PressLeftButton();
int num_drags = drag_view1->width();
for (int i = 0; i < num_drags; ++i) {
@@ -274,15 +265,10 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsSingleWidgetTest) {
// drag_data_ to a fake drag data object that we created.
if (i > 0)
UpdateDragData(&data);
- point.Offset(1, 0);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.MoveMouseBy(1, 0);
}
- aura::MouseEvent event2(ui::ET_MOUSE_RELEASED, point, 0);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event2);
+ generator.ReleaseLeftButton();
EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
EXPECT_EQ(num_drags - 1 - drag_view1->HorizontalDragThreshold(),
@@ -312,7 +298,6 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsMultipleWidgetsTest) {
scoped_ptr<views::Widget> widget1(CreateNewWidget());
DragTestView* drag_view1 = new DragTestView;
AddViewToWidgetAndResize(widget1.get(), drag_view1);
- gfx::Point point = drag_view1->bounds().CenterPoint();
scoped_ptr<views::Widget> widget2(CreateNewWidget());
DragTestView* drag_view2 = new DragTestView;
AddViewToWidgetAndResize(widget2.get(), drag_view2);
@@ -324,10 +309,8 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsMultipleWidgetsTest) {
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
- aura::MouseEvent event1(ui::ET_MOUSE_PRESSED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event1);
+ aura::test::EventGenerator generator(widget1->GetNativeView());
+ generator.PressLeftButton();
int num_drags = drag_view1->width();
for (int i = 0; i < num_drags; ++i) {
@@ -337,15 +320,10 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsMultipleWidgetsTest) {
// drag_data_ to a fake drag data object that we created.
if (i > 0)
UpdateDragData(&data);
- point.Offset(1, 0);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.MoveMouseBy(1, 0);
}
- aura::MouseEvent event2(ui::ET_MOUSE_RELEASED, point, 0);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event2);
+ generator.ReleaseLeftButton();
EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
EXPECT_EQ(num_drags - 1 - drag_view1->HorizontalDragThreshold(),
@@ -379,10 +357,9 @@ TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
- aura::MouseEvent event1(ui::ET_MOUSE_PRESSED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event1);
+ aura::test::EventGenerator generator;
+ generator.MoveMouseToCenterOf(widget->GetNativeView());
+ generator.PressLeftButton();
int num_drags_1 = 17;
for (int i = 0; i < num_drags_1; ++i) {
@@ -392,11 +369,7 @@ TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
// drag_data_ to a fake drag data object that we created.
if (i > 0)
UpdateDragData(&data);
- point.Offset(0, 1);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.MoveMouseBy(0, 1);
}
drag_view->parent()->RemoveChildView(drag_view);
@@ -404,15 +377,10 @@ TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
int num_drags_2 = 23;
for (int i = 0; i < num_drags_2; ++i) {
UpdateDragData(&data);
- point.Offset(0, 1);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.MoveMouseBy(0, 1);
}
- aura::MouseEvent event2(ui::ET_MOUSE_RELEASED, point, 0);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event2);
+ generator.ReleaseLeftButton();
EXPECT_TRUE(drag_drop_controller_->drag_start_received_);
EXPECT_EQ(num_drags_1 + num_drags_2 - 1 - drag_view->VerticalDragThreshold(),
@@ -445,17 +413,14 @@ TEST_F(DragDropControllerTest, DragCopiesDataToClipboardTest) {
scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view = new DragTestView;
AddViewToWidgetAndResize(widget.get(), drag_view);
- gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
+
+ aura::test::EventGenerator generator(widget->GetNativeView());
ui::OSExchangeData data;
std::string data_str("I am being dragged");
data.SetString(ASCIIToUTF16(data_str));
- aura::MouseEvent event(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event);
- point.Offset(0, drag_view->VerticalDragThreshold() + 1);
- aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, point,
- ui::EF_LEFT_MOUSE_BUTTON);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+ generator.PressLeftButton();
+ generator.MoveMouseBy(0, drag_view->VerticalDragThreshold() + 1);
EXPECT_TRUE(cb->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
ui::Clipboard::BUFFER_STANDARD));
diff --git a/ash/tooltips/tooltip_controller_unittest.cc b/ash/tooltips/tooltip_controller_unittest.cc
index 16f0c01..9f3e19a 100644
--- a/ash/tooltips/tooltip_controller_unittest.cc
+++ b/ash/tooltips/tooltip_controller_unittest.cc
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "ui/aura/client/tooltip_client.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/gfx/point.h"
#include "ui/views/view.h"
@@ -69,11 +70,6 @@ ash::internal::TooltipController* GetController() {
aura::client::GetTooltipClient());
}
-void SimulateMouseMoveAtPoint(const gfx::Point& point) {
- aura::MouseEvent event(ui::ET_MOUSE_MOVED, point, 0);
- aura::RootWindow::GetInstance()->DispatchMouseEvent(&event);
-}
-
} // namespace
class TooltipControllerTest : public AuraShellTestBase {
@@ -115,12 +111,12 @@ TEST_F(TooltipControllerTest, ViewTooltip) {
view->set_tooltip_text(ASCIIToUTF16("Tooltip Text"));
EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
EXPECT_EQ(NULL, GetTooltipWindow());
+ aura::test::EventGenerator generator;
+ generator.MoveMouseToCenterOf(widget->GetNativeView());
- gfx::Point point = gfx::Rect(view->bounds()).CenterPoint();
- SimulateMouseMoveAtPoint(point);
aura::Window* window = widget->GetNativeView();
- EXPECT_EQ(window,
- aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ EXPECT_EQ(window, aura::RootWindow::GetInstance()->GetEventHandlerForPoint(
+ generator.current_location()));
EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
@@ -131,8 +127,7 @@ TEST_F(TooltipControllerTest, ViewTooltip) {
FireTooltipTimer();
EXPECT_TRUE(IsTooltipVisible());
- point.Offset(1, 0);
- SimulateMouseMoveAtPoint(point);
+ generator.MoveMouseBy(1, 0);
EXPECT_TRUE(IsTooltipVisible());
EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
@@ -153,18 +148,19 @@ TEST_F(TooltipControllerTest, TooltipsInMultipleViews) {
AddViewToWidgetAndResize(widget, view2);
aura::Window* window = widget->GetNativeView();
- gfx::Point point = gfx::Rect(view1->bounds()).CenterPoint();
// Fire tooltip timer so tooltip becomes visible.
- SimulateMouseMoveAtPoint(point);
+ aura::test::EventGenerator generator;
+ generator.MoveMouseRelativeTo(window,
+ view1->bounds().CenterPoint());
FireTooltipTimer();
EXPECT_TRUE(IsTooltipVisible());
for (int i = 0; i < 50; i++) {
- point.Offset(1, 0);
- SimulateMouseMoveAtPoint(point);
+ generator.MoveMouseBy(1, 0);
EXPECT_TRUE(IsTooltipVisible());
EXPECT_EQ(window,
- aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ aura::RootWindow::GetInstance()->GetEventHandlerForPoint(
+ generator.current_location()));
EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
@@ -172,11 +168,11 @@ TEST_F(TooltipControllerTest, TooltipsInMultipleViews) {
EXPECT_EQ(window, GetTooltipWindow());
}
for (int i = 0; i < 50; i++) {
- point.Offset(1, 0);
- SimulateMouseMoveAtPoint(point);
+ generator.MoveMouseBy(1, 0);
EXPECT_FALSE(IsTooltipVisible());
EXPECT_EQ(window,
- aura::RootWindow::GetInstance()->GetEventHandlerForPoint(point));
+ aura::RootWindow::GetInstance()->GetEventHandlerForPoint(
+ generator.current_location()));
EXPECT_TRUE(aura::client::GetTooltipText(window) != NULL);
string16 expected_tooltip = ASCIIToUTF16("");
EXPECT_EQ(expected_tooltip, *aura::client::GetTooltipText(window));
@@ -193,8 +189,9 @@ TEST_F(TooltipControllerTest, EnableOrDisableTooltips) {
EXPECT_EQ(ASCIIToUTF16(""), GetTooltipText());
EXPECT_EQ(NULL, GetTooltipWindow());
- gfx::Point point = gfx::Rect(view->bounds()).CenterPoint();
- SimulateMouseMoveAtPoint(point);
+ aura::test::EventGenerator generator;
+ generator.MoveMouseRelativeTo(widget->GetNativeView(),
+ view->bounds().CenterPoint());
string16 expected_tooltip = ASCIIToUTF16("Tooltip Text");
// Fire tooltip timer so tooltip becomes visible.
diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc
index 94e6cbb..8e02a81 100644
--- a/ash/wm/root_window_event_filter_unittest.cc
+++ b/ash/wm/root_window_event_filter_unittest.cc
@@ -93,12 +93,9 @@ TEST_F(RootWindowEventFilterTest, Focus) {
SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get()));
// Click on a sub-window (w121) to focus it.
- gfx::Point click_point = w121->bounds().CenterPoint();
- aura::Window::ConvertPointToWindow(w121->parent(), root_window, &click_point);
- aura::MouseEvent mouse(ui::ET_MOUSE_PRESSED,
- click_point,
- ui::EF_LEFT_MOUSE_BUTTON);
- root_window->DispatchMouseEvent(&mouse);
+ aura::test::EventGenerator generator(w121.get());
+ generator.ClickLeftButton();
+
aura::internal::FocusManager* focus_manager = w121->GetFocusManager();
EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow());
@@ -108,7 +105,7 @@ TEST_F(RootWindowEventFilterTest, Focus) {
EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
// Touch on a sub-window (w122) to focus it.
- click_point = w122->bounds().CenterPoint();
+ gfx::Point click_point = w122->bounds().CenterPoint();
aura::Window::ConvertPointToWindow(w122->parent(), root_window, &click_point);
aura::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0);
root_window->DispatchTouchEvent(&touchev);
@@ -305,11 +302,11 @@ TEST_F(RootWindowEventFilterTest, MouseEventCursors) {
// Create two mouse movement events we can switch between.
gfx::Point point1(kWindowLeft, kWindowTop);
aura::Window::ConvertPointToWindow(window->parent(), root_window, &point1);
- aura::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, 0x0);
+ aura::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0);
gfx::Point point2(kWindowLeft + 1, kWindowTop + 1);
aura::Window::ConvertPointToWindow(window->parent(), root_window, &point2);
- aura::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, 0x0);
+ aura::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0);
// Cursor starts as null.
EXPECT_EQ(aura::kCursorNull, root_window->last_cursor());
@@ -376,11 +373,13 @@ TEST_F(RootWindowEventFilterTest, TransformActivate) {
transform.TransformPoint(miss_point);
aura::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
miss_point,
+ miss_point,
ui::EF_LEFT_MOUSE_BUTTON);
root_window->DispatchMouseEvent(&mouseev1);
EXPECT_FALSE(w1->GetFocusManager()->GetFocusedWindow());
aura::MouseEvent mouseup(ui::ET_MOUSE_RELEASED,
miss_point,
+ miss_point,
ui::EF_LEFT_MOUSE_BUTTON);
root_window->DispatchMouseEvent(&mouseup);
@@ -388,6 +387,7 @@ TEST_F(RootWindowEventFilterTest, TransformActivate) {
transform.TransformPoint(hit_point);
aura::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED,
hit_point,
+ hit_point,
ui::EF_LEFT_MOUSE_BUTTON);
root_window->DispatchMouseEvent(&mouseev2);
EXPECT_TRUE(IsActiveWindow(w1.get()));
@@ -418,7 +418,8 @@ TEST_F(RootWindowEventFilterTest, AdditionalFilters) {
// Dispatches mouse and keyboard events.
aura::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
root_window->DispatchKeyEvent(&key_event);
- aura::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 0x0);
+ aura::MouseEvent mouse_pressed(
+ ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0);
root_window->DispatchMouseEvent(&mouse_pressed);
// Both filters should get the events.
@@ -436,7 +437,8 @@ TEST_F(RootWindowEventFilterTest, AdditionalFilters) {
// Dispatches events.
root_window->DispatchKeyEvent(&key_event);
- aura::MouseEvent mouse_released(ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), 0x0);
+ aura::MouseEvent mouse_released(
+ ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0);
root_window->DispatchMouseEvent(&mouse_released);
// f1 should still get the events but f2 no longer gets them.
diff --git a/content/browser/renderer_host/web_input_event_aura.cc b/content/browser/renderer_host/web_input_event_aura.cc
index 6405303..984224e 100644
--- a/content/browser/renderer_host/web_input_event_aura.cc
+++ b/content/browser/renderer_host/web_input_event_aura.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -67,10 +67,9 @@ WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event) {
webkit_event.windowX = webkit_event.x = event->x();
webkit_event.windowY = webkit_event.y = event->y();
- const gfx::Point host_point =
- ui::EventLocationFromNative(event->native_event());
- webkit_event.globalX = host_point.x();
- webkit_event.globalY = host_point.y();
+ const gfx::Point root_point = event->root_location();
+ webkit_event.globalX = root_point.x();
+ webkit_event.globalY = root_point.y();
return webkit_event;
}
@@ -90,10 +89,9 @@ WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::MouseEvent* event) {
webkit_event.windowX = webkit_event.x = event->x();
webkit_event.windowY = webkit_event.y = event->y();
- const gfx::Point host_point =
- ui::EventLocationFromNative(event->native_event());
- webkit_event.globalX = host_point.x();
- webkit_event.globalY = host_point.y();
+ const gfx::Point root_point = event->root_location();
+ webkit_event.globalX = root_point.x();
+ webkit_event.globalY = root_point.y();
return webkit_event;
}
@@ -113,10 +111,9 @@ WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::ScrollEvent* event) {
webkit_event.windowX = webkit_event.x = event->x();
webkit_event.windowY = webkit_event.y = event->y();
- const gfx::Point host_point =
- ui::EventLocationFromNative(event->native_event());
- webkit_event.globalX = host_point.x();
- webkit_event.globalY = host_point.y();
+ const gfx::Point root_point = event->root_location();
+ webkit_event.globalX = root_point.x();
+ webkit_event.globalY = root_point.y();
return webkit_event;
}
diff --git a/ui/aura/event.cc b/ui/aura/event.cc
index c62ff40..6723e38 100644
--- a/ui/aura/event.cc
+++ b/ui/aura/event.cc
@@ -95,29 +95,36 @@ LocatedEvent::LocatedEvent(const base::NativeEvent& native_event)
: Event(native_event,
ui::EventTypeFromNative(native_event),
ui::EventFlagsFromNative(native_event)),
- location_(ui::EventLocationFromNative(native_event)) {
+ location_(ui::EventLocationFromNative(native_event)),
+ root_location_(location_) {
}
LocatedEvent::LocatedEvent(const LocatedEvent& model,
Window* source,
Window* target)
: Event(model),
- location_(model.location_) {
+ location_(model.location_),
+ root_location_(model.root_location_) {
if (target && target != source)
Window::ConvertPointToWindow(source, target, &location_);
}
LocatedEvent::LocatedEvent(ui::EventType type,
const gfx::Point& location,
+ const gfx::Point& root_location,
int flags)
: Event(type, flags),
- location_(location) {
+ location_(location),
+ root_location_(location) {
}
-void LocatedEvent::UpdateForTransform(const ui::Transform& transform) {
+void LocatedEvent::UpdateForRootTransform(const ui::Transform& root_transform) {
+ // Transform has to be done at root level.
+ DCHECK_EQ(root_location_.x(), location_.x());
+ DCHECK_EQ(root_location_.y(), location_.y());
gfx::Point3f p(location_);
- transform.TransformPointReverse(p);
- location_ = p.AsPoint();
+ root_transform.TransformPointReverse(p);
+ root_location_ = location_ = p.AsPoint();
}
MouseEvent::MouseEvent(const base::NativeEvent& native_event)
@@ -142,8 +149,9 @@ MouseEvent::MouseEvent(const MouseEvent& model,
MouseEvent::MouseEvent(ui::EventType type,
const gfx::Point& location,
+ const gfx::Point& root_location,
int flags)
- : LocatedEvent(type, location, flags) {
+ : LocatedEvent(type, location, root_location, flags) {
}
// static
@@ -256,7 +264,7 @@ TouchEvent::TouchEvent(const TouchEvent& model,
TouchEvent::TouchEvent(ui::EventType type,
const gfx::Point& location,
int touch_id)
- : LocatedEvent(type, location, 0),
+ : LocatedEvent(type, location, location, 0),
touch_id_(touch_id),
radius_x_(1.0f),
radius_y_(1.0f),
@@ -359,7 +367,7 @@ GestureEvent::GestureEvent(ui::EventType type,
base::Time time_stamp,
float delta_x,
float delta_y)
- : LocatedEvent(type, gfx::Point(x, y), flags),
+ : LocatedEvent(type, gfx::Point(x, y), gfx::Point(x, y), flags),
delta_x_(delta_x),
delta_y_(delta_y) {
// XXX: Why is aura::Event::time_stamp_ a TimeDelta instead of a Time?
diff --git a/ui/aura/event.h b/ui/aura/event.h
index 9f97661..04fe46d 100644
--- a/ui/aura/event.h
+++ b/ui/aura/event.h
@@ -103,8 +103,10 @@ class AURA_EXPORT LocatedEvent : public Event {
int x() const { return location_.x(); }
int y() const { return location_.y(); }
gfx::Point location() const { return location_; }
+ gfx::Point root_location() const { return root_location_; }
- void UpdateForTransform(const ui::Transform& transform);
+ // Applies the |root_transform| to both |location_| and |root_location_|.
+ void UpdateForRootTransform(const ui::Transform& root_transform);
protected:
explicit LocatedEvent(const base::NativeEvent& native_event);
@@ -115,10 +117,15 @@ class AURA_EXPORT LocatedEvent : public Event {
LocatedEvent(const LocatedEvent& model, Window* source, Window* target);
// Used for synthetic events in testing.
- LocatedEvent(ui::EventType type, const gfx::Point& location, int flags);
+ LocatedEvent(ui::EventType type,
+ const gfx::Point& location,
+ const gfx::Point& root_location,
+ int flags);
gfx::Point location_;
+ gfx::Point root_location_;
+
private:
DISALLOW_COPY_AND_ASSIGN(LocatedEvent);
};
@@ -139,7 +146,10 @@ class AURA_EXPORT MouseEvent : public LocatedEvent {
int flags);
// Used for synthetic events in testing and by the gesture recognizer.
- MouseEvent(ui::EventType type, const gfx::Point& location, int flags);
+ MouseEvent(ui::EventType type,
+ const gfx::Point& location,
+ const gfx::Point& root_location,
+ int flags);
// Compares two mouse down events and returns true if the second one should
// be considered a repeat of the first.
@@ -154,6 +164,8 @@ class AURA_EXPORT MouseEvent : public LocatedEvent {
void SetClickCount(int click_count);
private:
+ gfx::Point root_location_;
+
static MouseEvent* last_click_event_;
// Returns the repeat count based on the previous mouse click, if it is
// recent enough and within a small enough distance.
@@ -172,7 +184,9 @@ class AURA_EXPORT TouchEvent : public LocatedEvent {
TouchEvent(const TouchEvent& model, Window* source, Window* target);
// Used for synthetic events in testing.
- TouchEvent(ui::EventType type, const gfx::Point& location, int touch_id);
+ TouchEvent(ui::EventType type,
+ const gfx::Point& root_location,
+ int touch_id);
int touch_id() const { return touch_id_; }
float radius_x() const { return radius_x_; }
@@ -246,8 +260,9 @@ class AURA_EXPORT DropTargetEvent : public LocatedEvent {
public:
DropTargetEvent(const ui::OSExchangeData& data,
const gfx::Point& location,
+ const gfx::Point& root_location,
int source_operations)
- : LocatedEvent(ui::ET_DROP_TARGET_EVENT, location, 0),
+ : LocatedEvent(ui::ET_DROP_TARGET_EVENT, location, root_location, 0),
data_(data),
source_operations_(source_operations) {
}
diff --git a/ui/aura/event_unittest.cc b/ui/aura/event_unittest.cc
index 8b6b07c..5579031 100644
--- a/ui/aura/event_unittest.cc
+++ b/ui/aura/event_unittest.cc
@@ -71,7 +71,8 @@ TEST(EventTest, GetCharacter) {
}
TEST(EventTest, ClickCount) {
- MouseEvent mouseev(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 0);
+ const gfx::Point origin(0, 0);
+ MouseEvent mouseev(ui::ET_MOUSE_PRESSED, origin, origin, 0);
for (int i = 1; i <=3 ; ++i) {
mouseev.SetClickCount(i);
EXPECT_EQ(i, mouseev.GetClickCount());
@@ -79,8 +80,9 @@ TEST(EventTest, ClickCount) {
}
TEST(EventTest, Repeated) {
- MouseEvent mouse_ev1(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 0);
- MouseEvent mouse_ev2(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 0);
+ const gfx::Point origin(0, 0);
+ MouseEvent mouse_ev1(ui::ET_MOUSE_PRESSED, origin, origin, 0);
+ MouseEvent mouse_ev2(ui::ET_MOUSE_PRESSED, origin, origin, 0);
MouseEvent::TestApi test_ev1(&mouse_ev1);
MouseEvent::TestApi test_ev2(&mouse_ev2);
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 6dc9b4c..573e8e93 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -143,7 +143,7 @@ bool RootWindow::DispatchMouseEvent(MouseEvent* event) {
ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON;
- event->UpdateForTransform(layer()->transform());
+ event->UpdateForRootTransform(layer()->transform());
last_mouse_location_ = event->location();
@@ -188,7 +188,7 @@ bool RootWindow::DispatchKeyEvent(KeyEvent* event) {
}
bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
- event->UpdateForTransform(layer()->transform());
+ event->UpdateForRootTransform(layer()->transform());
last_mouse_location_ = event->location();
@@ -210,7 +210,7 @@ bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
}
bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
- event->UpdateForTransform(layer()->transform());
+ event->UpdateForRootTransform(layer()->transform());
bool handled = false;
Window* target =
touch_event_handler_ ? touch_event_handler_ : capture_window_;
@@ -528,7 +528,8 @@ ui::GestureStatus RootWindow::ProcessGestureEvent(Window* target,
};
gesture_handler_ = target;
for (ui::EventType* type = types; *type != ui::ET_UNKNOWN; ++type) {
- MouseEvent synth(*type, event->location(), event->flags());
+ MouseEvent synth(
+ *type, event->location(), event->root_location(), event->flags());
if (gesture_handler_->delegate()->OnMouseEvent(&synth))
status = ui::GESTURE_STATUS_SYNTH_MOUSE;
// The window that was receiving the gestures may have closed/hidden
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index f20d50e..0dbfe3e 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -75,7 +75,8 @@ TEST_F(RootWindowTest, DispatchMouseEvent) {
// Send a mouse event to window1.
gfx::Point point(101, 201);
- MouseEvent event1(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_MOUSE_BUTTON);
+ MouseEvent event1(
+ ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON);
RootWindow::GetInstance()->DispatchMouseEvent(&event1);
// Event was tested for non-client area for the target window.
@@ -105,6 +106,7 @@ TEST_F(RootWindowTest, MouseButtonState) {
event.reset(new MouseEvent(
ui::ET_MOUSE_PRESSED,
location,
+ location,
ui::EF_LEFT_MOUSE_BUTTON));
root_window->DispatchMouseEvent(event.get());
EXPECT_TRUE(root_window->IsMouseButtonDown());
@@ -113,6 +115,7 @@ TEST_F(RootWindowTest, MouseButtonState) {
event.reset(new MouseEvent(
ui::ET_MOUSE_PRESSED,
location,
+ location,
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
root_window->DispatchMouseEvent(event.get());
EXPECT_TRUE(root_window->IsMouseButtonDown());
@@ -121,6 +124,7 @@ TEST_F(RootWindowTest, MouseButtonState) {
event.reset(new MouseEvent(
ui::ET_MOUSE_RELEASED,
location,
+ location,
ui::EF_RIGHT_MOUSE_BUTTON));
root_window->DispatchMouseEvent(event.get());
EXPECT_TRUE(root_window->IsMouseButtonDown());
@@ -129,6 +133,7 @@ TEST_F(RootWindowTest, MouseButtonState) {
event.reset(new MouseEvent(
ui::ET_MOUSE_RELEASED,
location,
+ location,
ui::EF_SHIFT_DOWN));
root_window->DispatchMouseEvent(event.get());
EXPECT_FALSE(root_window->IsMouseButtonDown());
@@ -137,10 +142,29 @@ TEST_F(RootWindowTest, MouseButtonState) {
event.reset(new MouseEvent(
ui::ET_MOUSE_PRESSED,
location,
+ location,
ui::EF_MIDDLE_MOUSE_BUTTON));
root_window->DispatchMouseEvent(event.get());
EXPECT_TRUE(root_window->IsMouseButtonDown());
}
+TEST_F(RootWindowTest, TranslatedEvent) {
+ RootWindow* root_window = RootWindow::GetInstance();
+ scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
+ gfx::Rect(50, 50, 100, 100), NULL));
+
+ gfx::Point origin(100, 100);
+ MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0);
+
+ EXPECT_EQ("100,100", root.location().ToString());
+ EXPECT_EQ("100,100", root.root_location().ToString());
+
+ MouseEvent translated_event(
+ root, root_window, w1.get(),
+ ui::ET_MOUSE_ENTERED, root.flags());
+ EXPECT_EQ("50,50", translated_event.location().ToString());
+ EXPECT_EQ("100,100", translated_event.root_location().ToString());
+}
+
} // namespace test
} // namespace aura
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc
index 8366915..2a581d3 100644
--- a/ui/aura/test/event_generator.cc
+++ b/ui/aura/test/event_generator.cc
@@ -54,7 +54,8 @@ EventGenerator::~EventGenerator() {
void EventGenerator::PressLeftButton() {
if ((flags_ & ui::EF_LEFT_MOUSE_BUTTON) == 0) {
flags_ |= ui::EF_LEFT_MOUSE_BUTTON;
- MouseEvent mouseev(ui::ET_MOUSE_PRESSED, current_location_, flags_);
+ MouseEvent mouseev(
+ ui::ET_MOUSE_PRESSED, current_location_, current_location_, flags_);
Dispatch(mouseev);
}
}
@@ -62,7 +63,8 @@ void EventGenerator::PressLeftButton() {
void EventGenerator::ReleaseLeftButton() {
if (flags_ & ui::EF_LEFT_MOUSE_BUTTON) {
flags_ ^= ui::EF_LEFT_MOUSE_BUTTON;
- MouseEvent mouseev(ui::ET_MOUSE_RELEASED, current_location_, 0);
+ MouseEvent mouseev(
+ ui::ET_MOUSE_RELEASED, current_location_, current_location_, 0);
Dispatch(mouseev);
}
}
@@ -79,25 +81,29 @@ void EventGenerator::DoubleClickLeftButton() {
ReleaseLeftButton();
}
-void EventGenerator::MoveMouseTo(const gfx::Point& point) {
- if (flags_ & ui::EF_LEFT_MOUSE_BUTTON ) {
- MouseEvent middle(
- ui::ET_MOUSE_DRAGGED, current_location_.Middle(point), flags_);
- Dispatch(middle);
-
- MouseEvent mouseev(ui::ET_MOUSE_DRAGGED, point, flags_);
- Dispatch(mouseev);
- } else {
- MouseEvent middle(
- ui::ET_MOUSE_MOVED, current_location_.Middle(point), flags_);
- Dispatch(middle);
-
- MouseEvent mouseev(ui::ET_MOUSE_MOVED, point, flags_);
+void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) {
+ DCHECK_GT(count, 0);
+ const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
+ ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
+ const gfx::Point diff = point.Subtract(current_location_);
+ for (int i = 1; i <= count; i++) {
+ const gfx::Point move_point = current_location_.Add(
+ gfx::Point(diff.x() / count * i, diff.y() / count * i));
+ MouseEvent mouseev(event_type, move_point, move_point, flags_);
Dispatch(mouseev);
}
current_location_ = point;
}
+void EventGenerator::MoveMouseRelativeTo(const Window* window,
+ const gfx::Point& point) {
+ gfx::Point root_point(point);
+ aura::RootWindow* root_window = aura::RootWindow::GetInstance();
+ aura::Window::ConvertPointToWindow(window, root_window, &root_point);
+
+ MoveMouseTo(root_point);
+}
+
void EventGenerator::DragMouseTo(const gfx::Point& point) {
PressLeftButton();
MoveMouseTo(point);
diff --git a/ui/aura/test/event_generator.h b/ui/aura/test/event_generator.h
index 7859010..94bdfdaf 100644
--- a/ui/aura/test/event_generator.h
+++ b/ui/aura/test/event_generator.h
@@ -47,12 +47,21 @@ class EventGenerator {
void DoubleClickLeftButton();
// Generates events to move mouse to be the given |point|.
- void MoveMouseTo(const gfx::Point& point);
-
+ void MoveMouseTo(const gfx::Point& point, int count);
+ void MoveMouseTo(const gfx::Point& point) {
+ MoveMouseTo(point, 1);
+ }
void MoveMouseTo(int x, int y) {
MoveMouseTo(gfx::Point(x, y));
}
+ // Generates events to move mouse to be the given |point| in |window|'s
+ // coordinates.
+ void MoveMouseRelativeTo(const Window* window, const gfx::Point& point);
+ void MoveMouseRelativeTo(const Window* window, int x, int y) {
+ MoveMouseRelativeTo(window, gfx::Point(x, y));
+ }
+
void MoveMouseBy(int x, int y) {
MoveMouseTo(current_location_.Add(gfx::Point(x, y)));
}
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index a3a781d..a5bd458 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -492,7 +492,7 @@ TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
window->ReleaseCapture();
w2->SetCapture();
delegate2.set_mouse_event_count(0);
- generator.MoveMouseTo(gfx::Point(40, 40));
+ generator.MoveMouseTo(gfx::Point(40, 40), 2);
EXPECT_EQ(0, delegate.mouse_event_count());
EXPECT_EQ(2, delegate2.mouse_event_count());
}
@@ -567,8 +567,6 @@ class MouseEnterExitWindowDelegate : public TestWindowDelegate {
// Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
// mouse transitions from window to window.
TEST_F(WindowTest, MouseEnterExit) {
- RootWindow* root_window = RootWindow::GetInstance();
-
MouseEnterExitWindowDelegate d1;
scoped_ptr<Window> w1(
CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
@@ -576,21 +574,14 @@ TEST_F(WindowTest, MouseEnterExit) {
scoped_ptr<Window> w2(
CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL));
- gfx::Point move_point = w1->bounds().CenterPoint();
- Window::ConvertPointToWindow(w1->parent(), root_window, &move_point);
- MouseEvent mouseev1(ui::ET_MOUSE_MOVED, move_point, 0);
- root_window->DispatchMouseEvent(&mouseev1);
-
+ test::EventGenerator generator;
+ generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
EXPECT_FALSE(d2.entered());
EXPECT_FALSE(d2.exited());
- move_point = w2->bounds().CenterPoint();
- Window::ConvertPointToWindow(w2->parent(), root_window, &move_point);
- MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0);
- root_window->DispatchMouseEvent(&mouseev2);
-
+ generator.MoveMouseToCenterOf(w2.get());
EXPECT_TRUE(d1.entered());
EXPECT_TRUE(d1.exited());
EXPECT_TRUE(d2.entered());