Commit 1c49eca9 authored by riajiang's avatar riajiang Committed by Commit bot

Create MouseWheelEvent directly instead of through MouseEvent.

BUG=641828
TEST=ash_unittests, unit_tests, blink_converters_unittests,
     events_unittests, exo_unittests, browser_tests

Review-Url: https://codereview.chromium.org/2287403002
Cr-Commit-Position: refs/heads/master@{#415397}
parent fba5c5c1
...@@ -161,9 +161,16 @@ class StickyKeysTest : public test::AshTestBase { ...@@ -161,9 +161,16 @@ class StickyKeysTest : public test::AshTestBase {
// Creates a synthesized MouseEvent that is not backed by a native event. // Creates a synthesized MouseEvent that is not backed by a native event.
ui::MouseEvent* GenerateSynthesizedMouseEventAt(ui::EventType event_type, ui::MouseEvent* GenerateSynthesizedMouseEventAt(ui::EventType event_type,
const gfx::Point& location) { const gfx::Point& location) {
ui::MouseEvent* event = new ui::MouseEvent( ui::MouseEvent* event;
event_type, location, location, ui::EventTimeForNow(), if (event_type == ui::ET_MOUSEWHEEL) {
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); event = new ui::MouseWheelEvent(
gfx::Vector2d(), location, location, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
} else {
event = new ui::MouseEvent(
event_type, location, location, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
}
ui::Event::DispatcherApi dispatcher(event); ui::Event::DispatcherApi dispatcher(event);
dispatcher.set_target(target_); dispatcher.set_target(target_);
return event; return event;
......
...@@ -339,13 +339,7 @@ TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) { ...@@ -339,13 +339,7 @@ TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) {
} }
// Test mouse event processing for top-of-screen reveal triggering. // Test mouse event processing for top-of-screen reveal triggering.
// TODO: ASan failure happens on ChromeOS (https://crbug.com/641828). TEST_F(ImmersiveFullscreenControllerTest, OnMouseEvent) {
#if defined(OS_CHROMEOS)
#define MAYBE_OnMouseEvent DISABLED_OnMouseEvent
#else
#define MAYBE_OnMouseEvent OnMouseEvent
#endif
TEST_F(ImmersiveFullscreenControllerTest, MAYBE_OnMouseEvent) {
// Set up initial state. // Set up initial state.
SetEnabled(true); SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled()); ASSERT_TRUE(controller()->IsEnabled());
...@@ -360,8 +354,8 @@ TEST_F(ImmersiveFullscreenControllerTest, MAYBE_OnMouseEvent) { ...@@ -360,8 +354,8 @@ TEST_F(ImmersiveFullscreenControllerTest, MAYBE_OnMouseEvent) {
top_container_bounds_in_screen.y()); top_container_bounds_in_screen.y());
// Mouse wheel event does nothing. // Mouse wheel event does nothing.
ui::MouseEvent wheel(ui::ET_MOUSEWHEEL, top_edge_pos, top_edge_pos, ui::MouseWheelEvent wheel(gfx::Vector2d(), top_edge_pos, top_edge_pos,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
event_generator.Dispatch(&wheel); event_generator.Dispatch(&wheel);
EXPECT_FALSE(top_edge_hover_timer_running()); EXPECT_FALSE(top_edge_hover_timer_running());
......
...@@ -2421,10 +2421,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) { ...@@ -2421,10 +2421,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) {
ui::DomKey::CONTROL); ui::DomKey::CONTROL);
PopEvents(&events); PopEvents(&events);
gfx::Point location(0, 0); gfx::Point location(0, 0);
ui::MouseEvent mev(ui::ET_MOUSEWHEEL, location, location, ui::MouseWheelEvent positive(
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, gfx::Vector2d(0, ui::MouseWheelEvent::kWheelDelta), location, location,
ui::EF_LEFT_MOUSE_BUTTON); ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::MouseWheelEvent positive(mev, 0, ui::MouseWheelEvent::kWheelDelta); ui::EF_LEFT_MOUSE_BUTTON);
ui::EventDispatchDetails details = Send(&positive); ui::EventDispatchDetails details = Send(&positive);
ASSERT_FALSE(details.dispatcher_destroyed); ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events); PopEvents(&events);
...@@ -2440,7 +2440,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) { ...@@ -2440,7 +2440,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) {
SendActivateStickyKeyPattern(ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT, SendActivateStickyKeyPattern(ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT,
ui::DomKey::CONTROL); ui::DomKey::CONTROL);
PopEvents(&events); PopEvents(&events);
ui::MouseWheelEvent negative(mev, 0, -ui::MouseWheelEvent::kWheelDelta); ui::MouseWheelEvent negative(
gfx::Vector2d(0, -ui::MouseWheelEvent::kWheelDelta), location, location,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
details = Send(&negative); details = Send(&negative);
ASSERT_FALSE(details.dispatcher_destroyed); ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events); PopEvents(&events);
...@@ -2464,10 +2467,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventModifiersRewritten) { ...@@ -2464,10 +2467,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventModifiersRewritten) {
// expect that it will be rewritten to ALT_DOWN. // expect that it will be rewritten to ALT_DOWN.
ScopedVector<ui::Event> events; ScopedVector<ui::Event> events;
gfx::Point location(0, 0); gfx::Point location(0, 0);
ui::MouseEvent mev( ui::MouseWheelEvent positive(
ui::ET_MOUSEWHEEL, location, location, ui::EventTimeForNow(), gfx::Vector2d(0, ui::MouseWheelEvent::kWheelDelta), location, location,
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN, ui::EF_LEFT_MOUSE_BUTTON); ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN,
ui::MouseWheelEvent positive(mev, 0, ui::MouseWheelEvent::kWheelDelta); ui::EF_LEFT_MOUSE_BUTTON);
ui::EventDispatchDetails details = Send(&positive); ui::EventDispatchDetails details = Send(&positive);
ASSERT_FALSE(details.dispatcher_destroyed); ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events); PopEvents(&events);
......
...@@ -66,14 +66,13 @@ void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform( ...@@ -66,14 +66,13 @@ void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform( void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
const blink::WebMouseWheelEvent& web_wheel, const blink::WebMouseWheelEvent& web_wheel,
const ui::LatencyInfo&) { const ui::LatencyInfo&) {
ui::MouseEvent mouse_event(ui::ET_MOUSEWHEEL, gfx::Point(), gfx::Point(), ui::MouseWheelEvent wheel_event(
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); gfx::Vector2d(web_wheel.deltaX, web_wheel.deltaY), gfx::Point(),
gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
gfx::PointF location(web_wheel.x * device_scale_factor_, gfx::PointF location(web_wheel.x * device_scale_factor_,
web_wheel.y * device_scale_factor_); web_wheel.y * device_scale_factor_);
mouse_event.set_location_f(location); wheel_event.set_location_f(location);
mouse_event.set_root_location_f(location); wheel_event.set_root_location_f(location);
ui::MouseWheelEvent wheel_event(
mouse_event, web_wheel.deltaX, web_wheel.deltaY);
aura::Window* window = GetWindow(); aura::Window* window = GetWindow();
wheel_event.ConvertLocationToTarget(window, window->GetRootWindow()); wheel_event.ConvertLocationToTarget(window, window->GetRootWindow());
......
...@@ -43,10 +43,8 @@ TEST(BlinkInputEventsConvertersTest, KeyEvent) { ...@@ -43,10 +43,8 @@ TEST(BlinkInputEventsConvertersTest, KeyEvent) {
TEST(BlinkInputEventsConvertersTest, WheelEvent) { TEST(BlinkInputEventsConvertersTest, WheelEvent) {
const int kDeltaX = 14; const int kDeltaX = 14;
const int kDeltaY = -3; const int kDeltaY = -3;
ui::MouseWheelEvent ui_event( ui::MouseWheelEvent ui_event(gfx::Vector2d(kDeltaX, kDeltaY), gfx::Point(),
ui::MouseEvent(ui::ET_MOUSEWHEEL, gfx::Point(), gfx::Point(), gfx::Point(), base::TimeTicks(), 0, 0);
base::TimeTicks(), 0, 0),
kDeltaX, kDeltaY);
ui::PointerEvent pointer_event(ui_event); ui::PointerEvent pointer_event(ui_event);
const std::unique_ptr<blink::WebInputEvent> web_event( const std::unique_ptr<blink::WebInputEvent> web_event(
TypeConverter<std::unique_ptr<blink::WebInputEvent>, ui::Event>::Convert( TypeConverter<std::unique_ptr<blink::WebInputEvent>, ui::Event>::Convert(
......
...@@ -523,6 +523,7 @@ MouseEvent::MouseEvent(EventType type, ...@@ -523,6 +523,7 @@ MouseEvent::MouseEvent(EventType type,
flags), flags),
changed_button_flags_(changed_button_flags), changed_button_flags_(changed_button_flags),
pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
DCHECK_NE(ET_MOUSEWHEEL, type);
latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
SetType(ET_MOUSE_DRAGGED); SetType(ET_MOUSE_DRAGGED);
...@@ -680,13 +681,18 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, ...@@ -680,13 +681,18 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
base::TimeTicks time_stamp, base::TimeTicks time_stamp,
int flags, int flags,
int changed_button_flags) int changed_button_flags)
: MouseEvent(ui::ET_MOUSEWHEEL, : MouseEvent(ui::ET_UNKNOWN,
location, location,
root_location, root_location,
time_stamp, time_stamp,
flags, flags,
changed_button_flags), changed_button_flags),
offset_(offset) {} offset_(offset) {
// Set event type to ET_UNKNOWN initially in MouseEvent() to pass the
// DCHECK for type to enforce that we use MouseWheelEvent() to create
// a MouseWheelEvent.
SetType(ui::ET_MOUSEWHEEL);
}
#if defined(OS_WIN) #if defined(OS_WIN)
// This value matches windows WHEEL_DELTA. // This value matches windows WHEEL_DELTA.
......
...@@ -485,6 +485,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { ...@@ -485,6 +485,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
} }
// Used for synthetic events in testing, gesture recognizer and Ozone // Used for synthetic events in testing, gesture recognizer and Ozone
// Note: Use the ctor for MouseWheelEvent if type is ET_MOUSEWHEEL.
MouseEvent(EventType type, MouseEvent(EventType type,
const gfx::Point& location, const gfx::Point& location,
const gfx::Point& root_location, const gfx::Point& root_location,
......
...@@ -738,14 +738,17 @@ TEST(EventTest, PointerEventCanConvertFrom) { ...@@ -738,14 +738,17 @@ TEST(EventTest, PointerEventCanConvertFrom) {
// Common mouse events can be converted. // Common mouse events can be converted.
const EventType mouse_allowed[] = { const EventType mouse_allowed[] = {
ET_MOUSE_PRESSED, ET_MOUSE_DRAGGED, ET_MOUSE_MOVED, ET_MOUSE_PRESSED, ET_MOUSE_DRAGGED, ET_MOUSE_MOVED,
ET_MOUSE_ENTERED, ET_MOUSE_EXITED, ET_MOUSE_RELEASED, ET_MOUSE_ENTERED, ET_MOUSE_EXITED, ET_MOUSE_RELEASED,
ET_MOUSEWHEEL, ET_MOUSE_CAPTURE_CHANGED, ET_MOUSE_CAPTURE_CHANGED,
}; };
for (size_t i = 0; i < arraysize(mouse_allowed); i++) { for (size_t i = 0; i < arraysize(mouse_allowed); i++) {
MouseEvent event(mouse_allowed[i], point, point, time, 0, 0); MouseEvent event(mouse_allowed[i], point, point, time, 0, 0);
EXPECT_TRUE(PointerEvent::CanConvertFrom(event)); EXPECT_TRUE(PointerEvent::CanConvertFrom(event));
} }
// Mouse wheel events can be converted.
MouseWheelEvent event(gfx::Vector2d(), point, point, time, 0, 0);
EXPECT_TRUE(PointerEvent::CanConvertFrom(event));
// Common touch events can be converted. // Common touch events can be converted.
const EventType touch_allowed[] = { const EventType touch_allowed[] = {
......
...@@ -166,9 +166,8 @@ void EventGenerator::ReleaseRightButton() { ...@@ -166,9 +166,8 @@ void EventGenerator::ReleaseRightButton() {
void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) {
gfx::Point location = GetLocationInCurrentRoot(); gfx::Point location = GetLocationInCurrentRoot();
ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, ui::MouseWheelEvent wheelev(gfx::Vector2d(delta_x, delta_y), location,
ui::EventTimeForNow(), flags_, 0); location, ui::EventTimeForNow(), flags_, 0);
ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y);
Dispatch(&wheelev); Dispatch(&wheelev);
} }
......
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