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

Side by Side 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: hover layout 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/input/MouseEventManager.h" 5 #include "core/input/MouseEventManager.h"
6 6
7 #include "core/clipboard/DataObject.h" 7 #include "core/clipboard/DataObject.h"
8 #include "core/clipboard/DataTransfer.h" 8 #include "core/clipboard/DataTransfer.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/ElementTraversal.h" 10 #include "core/dom/ElementTraversal.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 Traversal<HTMLCanvasElement>::FirstAncestorOrSelf(*element); 49 Traversal<HTMLCanvasElement>::FirstAncestorOrSelf(*element);
50 // In this case, the event target is canvas and mouse rerouting doesn't 50 // In this case, the event target is canvas and mouse rerouting doesn't
51 // happen. 51 // happen.
52 if (canvas == element) 52 if (canvas == element)
53 return String(); 53 return String();
54 return canvas->GetIdFromControl(element); 54 return canvas->GetIdFromControl(element);
55 } 55 }
56 56
57 // The amount of time to wait before sending a fake mouse event triggered 57 // The amount of time to wait before sending a fake mouse event triggered
58 // during a scroll. 58 // during a scroll.
59 const double kFakeMouseMoveInterval = 0.1; 59 const double kFakeMouseMoveIntervalDuringScroll = 0.1;
60
61 // The amount of time to wait before sending a fake mouse event on style and
62 // layout changes sets to 50Hz, same as common screen refresh rate.
63 const double kFakeMouseMoveIntervalPerFrame = 0.02;
dtapuska 2017/06/28 19:15:17 I believe constexpr is preferred
lanwei 2017/07/04 18:37:15 Done.
60 64
61 // TODO(crbug.com/653490): Read these values from the OS. 65 // TODO(crbug.com/653490): Read these values from the OS.
62 #if OS(MACOSX) 66 #if OS(MACOSX)
63 const int kDragThresholdX = 3; 67 const int kDragThresholdX = 3;
64 const int kDragThresholdY = 3; 68 const int kDragThresholdY = 3;
65 constexpr TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.15); 69 constexpr TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.15);
66 #else 70 #else
67 const int kDragThresholdX = 4; 71 const int kDragThresholdX = 4;
68 const int kDragThresholdY = 4; 72 const int kDragThresholdY = 4;
69 constexpr TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.0); 73 constexpr TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.0);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 FloatPoint MouseEventManager::LastKnownMousePositionGlobal() { 578 FloatPoint MouseEventManager::LastKnownMousePositionGlobal() {
575 return last_known_mouse_global_position_; 579 return last_known_mouse_global_position_;
576 } 580 }
577 581
578 void MouseEventManager::SetLastKnownMousePosition(const WebMouseEvent& event) { 582 void MouseEventManager::SetLastKnownMousePosition(const WebMouseEvent& event) {
579 is_mouse_position_unknown_ = false; 583 is_mouse_position_unknown_ = false;
580 last_known_mouse_position_ = event.PositionInRootFrame(); 584 last_known_mouse_position_ = event.PositionInRootFrame();
581 last_known_mouse_global_position_ = event.PositionInScreen(); 585 last_known_mouse_global_position_ = event.PositionInScreen();
582 } 586 }
583 587
584 void MouseEventManager::DispatchFakeMouseMoveEventSoon() { 588 void MouseEventManager::DispatchFakeMouseMoveEventSoon(
589 DispatchInterval dispatch_interval) {
585 if (mouse_pressed_) 590 if (mouse_pressed_)
dtapuska 2017/06/28 19:15:18 So if mouse is pressed or cursor isn't known then
lanwei 2017/07/04 18:37:15 We should update hover states and mouse cursor whe
586 return; 591 return;
587 592
588 if (is_mouse_position_unknown_) 593 if (is_mouse_position_unknown_)
589 return; 594 return;
590 595
591 // Reschedule the timer, to prevent dispatching mouse move events 596 // Reschedule the timer, to prevent dispatching mouse move events
592 // during a scroll. This avoids a potential source of scroll jank. 597 // during a scroll. This avoids a potential source of scroll jank.
593 fake_mouse_move_event_timer_.StartOneShot(kFakeMouseMoveInterval, 598 // Or dispatch a fake mouse move to update hover states when the layout
594 BLINK_FROM_HERE); 599 // changes.
600 double interval = dispatch_interval == DispatchInterval::kDuringScroll
601 ? kFakeMouseMoveIntervalDuringScroll
602 : kFakeMouseMoveIntervalPerFrame;
603 fake_mouse_move_event_timer_.StartOneShot(interval, BLINK_FROM_HERE);
595 } 604 }
596 605
597 void MouseEventManager::DispatchFakeMouseMoveEventSoonInQuad( 606 void MouseEventManager::DispatchFakeMouseMoveEventSoonInQuad(
598 const FloatQuad& quad) { 607 const FloatQuad& quad) {
599 LocalFrameView* view = frame_->View(); 608 LocalFrameView* view = frame_->View();
600 if (!view) 609 if (!view)
601 return; 610 return;
602 611
603 if (!quad.ContainsPoint( 612 if (!quad.ContainsPoint(
604 view->RootFrameToContents(last_known_mouse_position_))) 613 view->RootFrameToContents(last_known_mouse_position_)))
605 return; 614 return;
606 615
607 DispatchFakeMouseMoveEventSoon(); 616 DispatchFakeMouseMoveEventSoon(DispatchInterval::kDuringScroll);
608 } 617 }
609 618
610 WebInputEventResult MouseEventManager::HandleMousePressEvent( 619 WebInputEventResult MouseEventManager::HandleMousePressEvent(
611 const MouseEventWithHitTestResults& event) { 620 const MouseEventWithHitTestResults& event) {
612 TRACE_EVENT0("blink", "MouseEventManager::handleMousePressEvent"); 621 TRACE_EVENT0("blink", "MouseEventManager::handleMousePressEvent");
613 622
614 ResetDragState(); 623 ResetDragState();
615 CancelFakeMouseMoveEvent(); 624 CancelFakeMouseMoveEvent();
616 625
617 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 626 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 } 1099 }
1091 1100
1092 void MouseEventManager::SetClickCount(int click_count) { 1101 void MouseEventManager::SetClickCount(int click_count) {
1093 click_count_ = click_count; 1102 click_count_ = click_count;
1094 } 1103 }
1095 1104
1096 bool MouseEventManager::MouseDownMayStartDrag() { 1105 bool MouseEventManager::MouseDownMayStartDrag() {
1097 return mouse_down_may_start_drag_; 1106 return mouse_down_may_start_drag_;
1098 } 1107 }
1099 1108
1109 bool MouseEventManager::FakeMouseMovePending() {
1110 return fake_mouse_move_event_timer_.IsActive();
1111 }
1112
1100 } // namespace blink 1113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698