Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: third_party/WebKit/Source/core/input/MouseEventManager.cpp

Issue 2956023004: Add a flag to update hover effect when a layout is changed (Closed)
Patch Set: Change layout test Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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())
return;
+ WebPointerEvent::Button button = WebPointerProperties::Button::kNoButton;
+ int modifiers = KeyboardEventManager::GetCurrentModifierState() |
+ WebInputEvent::kRelativeMotionEvent;
+ if (mouse_pressed_) {
+ button = WebPointerProperties::Button::kLeft;
+ 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
dtapuska 2017/07/12 17:20:19 This should probably be a TODO with a crbug. (I th
lanwei 2017/07/12 19:00:23 Done.
+ // 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

Powered by Google App Engine
This is Rietveld 408576698