0

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}
This commit is contained in:
riajiang
2016-08-30 12:36:53 -07:00
committed by Commit bot
parent fba5c5c125
commit 1c49eca93d
9 changed files with 49 additions and 39 deletions

@ -161,9 +161,16 @@ class StickyKeysTest : public test::AshTestBase {
// Creates a synthesized MouseEvent that is not backed by a native event.
ui::MouseEvent* GenerateSynthesizedMouseEventAt(ui::EventType event_type,
const gfx::Point& location) {
ui::MouseEvent* event = new ui::MouseEvent(
event_type, location, location, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
ui::MouseEvent* event;
if (event_type == ui::ET_MOUSEWHEEL) {
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);
dispatcher.set_target(target_);
return event;

@ -339,13 +339,7 @@ TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) {
}
// Test mouse event processing for top-of-screen reveal triggering.
// TODO: ASan failure happens on ChromeOS (https://crbug.com/641828).
#if defined(OS_CHROMEOS)
#define MAYBE_OnMouseEvent DISABLED_OnMouseEvent
#else
#define MAYBE_OnMouseEvent OnMouseEvent
#endif
TEST_F(ImmersiveFullscreenControllerTest, MAYBE_OnMouseEvent) {
TEST_F(ImmersiveFullscreenControllerTest, OnMouseEvent) {
// Set up initial state.
SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled());
@ -360,8 +354,8 @@ TEST_F(ImmersiveFullscreenControllerTest, MAYBE_OnMouseEvent) {
top_container_bounds_in_screen.y());
// Mouse wheel event does nothing.
ui::MouseEvent wheel(ui::ET_MOUSEWHEEL, top_edge_pos, top_edge_pos,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
ui::MouseWheelEvent wheel(gfx::Vector2d(), top_edge_pos, top_edge_pos,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
event_generator.Dispatch(&wheel);
EXPECT_FALSE(top_edge_hover_timer_running());

@ -2421,10 +2421,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) {
ui::DomKey::CONTROL);
PopEvents(&events);
gfx::Point location(0, 0);
ui::MouseEvent mev(ui::ET_MOUSEWHEEL, location, location,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
ui::MouseWheelEvent positive(mev, 0, ui::MouseWheelEvent::kWheelDelta);
ui::MouseWheelEvent positive(
gfx::Vector2d(0, ui::MouseWheelEvent::kWheelDelta), location, location,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
ui::EventDispatchDetails details = Send(&positive);
ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events);
@ -2440,7 +2440,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventDispatchImpl) {
SendActivateStickyKeyPattern(ui::VKEY_CONTROL, ui::DomCode::CONTROL_LEFT,
ui::DomKey::CONTROL);
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);
ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events);
@ -2464,10 +2467,10 @@ TEST_F(EventRewriterAshTest, MouseWheelEventModifiersRewritten) {
// expect that it will be rewritten to ALT_DOWN.
ScopedVector<ui::Event> events;
gfx::Point location(0, 0);
ui::MouseEvent mev(
ui::ET_MOUSEWHEEL, location, location, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN, ui::EF_LEFT_MOUSE_BUTTON);
ui::MouseWheelEvent positive(mev, 0, ui::MouseWheelEvent::kWheelDelta);
ui::MouseWheelEvent positive(
gfx::Vector2d(0, ui::MouseWheelEvent::kWheelDelta), location, location,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN,
ui::EF_LEFT_MOUSE_BUTTON);
ui::EventDispatchDetails details = Send(&positive);
ASSERT_FALSE(details.dispatcher_destroyed);
PopEvents(&events);

@ -66,14 +66,13 @@ void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
const blink::WebMouseWheelEvent& web_wheel,
const ui::LatencyInfo&) {
ui::MouseEvent mouse_event(ui::ET_MOUSEWHEEL, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
ui::MouseWheelEvent wheel_event(
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_,
web_wheel.y * device_scale_factor_);
mouse_event.set_location_f(location);
mouse_event.set_root_location_f(location);
ui::MouseWheelEvent wheel_event(
mouse_event, web_wheel.deltaX, web_wheel.deltaY);
wheel_event.set_location_f(location);
wheel_event.set_root_location_f(location);
aura::Window* window = GetWindow();
wheel_event.ConvertLocationToTarget(window, window->GetRootWindow());

@ -43,10 +43,8 @@ TEST(BlinkInputEventsConvertersTest, KeyEvent) {
TEST(BlinkInputEventsConvertersTest, WheelEvent) {
const int kDeltaX = 14;
const int kDeltaY = -3;
ui::MouseWheelEvent ui_event(
ui::MouseEvent(ui::ET_MOUSEWHEEL, gfx::Point(), gfx::Point(),
base::TimeTicks(), 0, 0),
kDeltaX, kDeltaY);
ui::MouseWheelEvent ui_event(gfx::Vector2d(kDeltaX, kDeltaY), gfx::Point(),
gfx::Point(), base::TimeTicks(), 0, 0);
ui::PointerEvent pointer_event(ui_event);
const std::unique_ptr<blink::WebInputEvent> web_event(
TypeConverter<std::unique_ptr<blink::WebInputEvent>, ui::Event>::Convert(

@ -523,6 +523,7 @@ MouseEvent::MouseEvent(EventType type,
flags),
changed_button_flags_(changed_button_flags),
pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
DCHECK_NE(ET_MOUSEWHEEL, type);
latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
SetType(ET_MOUSE_DRAGGED);
@ -680,13 +681,18 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
base::TimeTicks time_stamp,
int flags,
int changed_button_flags)
: MouseEvent(ui::ET_MOUSEWHEEL,
: MouseEvent(ui::ET_UNKNOWN,
location,
root_location,
time_stamp,
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)
// This value matches windows WHEEL_DELTA.

@ -485,6 +485,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
}
// Used for synthetic events in testing, gesture recognizer and Ozone
// Note: Use the ctor for MouseWheelEvent if type is ET_MOUSEWHEEL.
MouseEvent(EventType type,
const gfx::Point& location,
const gfx::Point& root_location,

@ -738,14 +738,17 @@ TEST(EventTest, PointerEventCanConvertFrom) {
// Common mouse events can be converted.
const EventType mouse_allowed[] = {
ET_MOUSE_PRESSED, ET_MOUSE_DRAGGED, ET_MOUSE_MOVED,
ET_MOUSE_ENTERED, ET_MOUSE_EXITED, ET_MOUSE_RELEASED,
ET_MOUSEWHEEL, ET_MOUSE_CAPTURE_CHANGED,
ET_MOUSE_PRESSED, ET_MOUSE_DRAGGED, ET_MOUSE_MOVED,
ET_MOUSE_ENTERED, ET_MOUSE_EXITED, ET_MOUSE_RELEASED,
ET_MOUSE_CAPTURE_CHANGED,
};
for (size_t i = 0; i < arraysize(mouse_allowed); i++) {
MouseEvent event(mouse_allowed[i], point, point, time, 0, 0);
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.
const EventType touch_allowed[] = {

@ -166,9 +166,8 @@ void EventGenerator::ReleaseRightButton() {
void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) {
gfx::Point location = GetLocationInCurrentRoot();
ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location,
ui::EventTimeForNow(), flags_, 0);
ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y);
ui::MouseWheelEvent wheelev(gfx::Vector2d(delta_x, delta_y), location,
location, ui::EventTimeForNow(), flags_, 0);
Dispatch(&wheelev);
}