Chromium Code Reviews| Index: third_party/WebKit/Source/core/input/MouseEventManager.cpp |
| diff --git a/third_party/WebKit/Source/core/input/MouseEventManager.cpp b/third_party/WebKit/Source/core/input/MouseEventManager.cpp |
| index e4a1ec7df78bfad490fc49ea7b359e7fa48cdcce..158528c82ff9c56c87296a50c55e0ec917d1494d 100644 |
| --- a/third_party/WebKit/Source/core/input/MouseEventManager.cpp |
| +++ b/third_party/WebKit/Source/core/input/MouseEventManager.cpp |
| @@ -56,7 +56,11 @@ String CanvasRegionId(Node* node, const WebMouseEvent& mouse_event) { |
| // The amount of time to wait before sending a fake mouse event triggered |
| // during a scroll. |
| -const double kFakeMouseMoveInterval = 0.1; |
| +constexpr double kFakeMouseMoveIntervalDuringScroll = 0.1; |
| + |
| +// The amount of time to wait before sending a fake mouse event on style and |
| +// layout changes sets to 50Hz, same as common screen refresh rate. |
| +constexpr double kFakeMouseMoveIntervalPerFrame = 0.02; |
| // TODO(crbug.com/653490): Read these values from the OS. |
| #if OS(MACOSX) |
| @@ -308,7 +312,6 @@ WebInputEventResult MouseEventManager::DispatchMouseClickIfNeeded( |
| void MouseEventManager::FakeMouseMoveEventTimerFired(TimerBase* timer) { |
| TRACE_EVENT0("input", "MouseEventManager::fakeMouseMoveEventTimerFired"); |
| DCHECK(timer == &fake_mouse_move_event_timer_); |
| - DCHECK(!mouse_pressed_); |
| if (is_mouse_position_unknown_) |
| return; |
| @@ -325,16 +328,20 @@ void MouseEventManager::FakeMouseMoveEventTimerFired(TimerBase* timer) { |
| if (!frame_->GetPage()->IsCursorVisible()) |
|
Navid Zolghadr
2017/07/05 17:37:33
Does this apply for layout change causing fake eve
lanwei
2017/07/06 03:04:34
I think we should not send the fake mouse move whe
|
| return; |
| + WebPointerEvent::Button button = WebPointerProperties::Button::kNoButton; |
| + int modifiers = KeyboardEventManager::GetCurrentModifierState() | |
| + WebInputEvent::kRelativeMotionEvent; |
| + if (mouse_pressed_) { |
| + button = WebPointerProperties::Button::kLeft; |
|
Navid Zolghadr
2017/07/05 17:37:33
Shouldn't this still be kNoButton since we are sen
lanwei
2017/07/06 03:04:34
Yes, I tested when we pressed a button and moved t
|
| + modifiers |= WebInputEvent::kLeftButtonDown; |
| + } |
| WebMouseEvent fake_mouse_move_event( |
| WebInputEvent::kMouseMove, |
| WebFloatPoint(last_known_mouse_position_.X(), |
| last_known_mouse_position_.Y()), |
| WebFloatPoint(last_known_mouse_global_position_.X(), |
| last_known_mouse_global_position_.Y()), |
| - WebPointerProperties::Button::kNoButton, 0, |
| - KeyboardEventManager::GetCurrentModifierState() | |
| - WebInputEvent::Modifiers::kRelativeMotionEvent, |
| - TimeTicks::Now().InSeconds()); |
| + button, 0, modifiers, TimeTicks::Now().InSeconds()); |
| // TODO(dtapuska): Update m_lastKnowMousePosition to be viewport coordinates. |
| fake_mouse_move_event.SetFrameScale(1); |
| Vector<WebMouseEvent> coalesced_events; |
| @@ -581,17 +588,30 @@ void MouseEventManager::SetLastKnownMousePosition(const WebMouseEvent& event) { |
| last_known_mouse_global_position_ = event.PositionInScreen(); |
| } |
| -void MouseEventManager::DispatchFakeMouseMoveEventSoon() { |
| - if (mouse_pressed_) |
| +void MouseEventManager::DispatchFakeMouseMoveEventSoon( |
| + MouseEventManager::FakeMouseMoveReason fake_mouse_move_reason) { |
| + if (fake_mouse_move_reason == |
| + MouseEventManager::FakeMouseMoveReason::kDuringScroll && |
| + mouse_pressed_) |
| return; |
| + // When the mouse position is unknown, we do not send the fake mousemove |
| + // event for now, so we cannot update the hover states and mouse cursor. |
| + // We will fix it soon by keeping the last mouse position somehwhere in |
| + // browser. |
| if (is_mouse_position_unknown_) |
| return; |
| // Reschedule the timer, to prevent dispatching mouse move events |
| // during a scroll. This avoids a potential source of scroll jank. |
| - fake_mouse_move_event_timer_.StartOneShot(kFakeMouseMoveInterval, |
| - BLINK_FROM_HERE); |
| + // Or dispatch a fake mouse move to update hover states when the layout |
| + // changes. |
| + double interval = |
| + fake_mouse_move_reason == |
| + MouseEventManager::FakeMouseMoveReason::kDuringScroll |
| + ? kFakeMouseMoveIntervalDuringScroll |
| + : kFakeMouseMoveIntervalPerFrame; |
| + fake_mouse_move_event_timer_.StartOneShot(interval, BLINK_FROM_HERE); |
| } |
| void MouseEventManager::DispatchFakeMouseMoveEventSoonInQuad( |
| @@ -604,7 +624,8 @@ void MouseEventManager::DispatchFakeMouseMoveEventSoonInQuad( |
| view->RootFrameToContents(last_known_mouse_position_))) |
| return; |
| - DispatchFakeMouseMoveEventSoon(); |
| + DispatchFakeMouseMoveEventSoon( |
| + MouseEventManager::FakeMouseMoveReason::kDuringScroll); |
| } |
| WebInputEventResult MouseEventManager::HandleMousePressEvent( |
| @@ -753,8 +774,9 @@ WebInputEventResult MouseEventManager::HandleMouseDraggedEvent( |
| // 3. When pressing Esc key while dragging and the object is outside of the |
| // we get a mouse leave event here |
| if (event.Event().button != WebPointerProperties::Button::kLeft || |
| - event.Event().GetType() == WebInputEvent::kMouseLeave) |
| + event.Event().GetType() == WebInputEvent::kMouseLeave) { |
| mouse_pressed_ = false; |
| + } |
| if (!mouse_pressed_) |
| return WebInputEventResult::kNotHandled; |
| @@ -1097,4 +1119,8 @@ bool MouseEventManager::MouseDownMayStartDrag() { |
| return mouse_down_may_start_drag_; |
| } |
| +bool MouseEventManager::FakeMouseMovePending() const { |
| + return fake_mouse_move_event_timer_.IsActive(); |
| +} |
| + |
| } // namespace blink |