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

Side by Side Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 2249663002: Fixed & refactored mouse event firing at gesture context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests, removed one overfitting Created 4 years, 4 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 // m_selectionInitiationState is initialized after dispatching mousedown 865 // m_selectionInitiationState is initialized after dispatching mousedown
866 // event in order not to keep the selection by DOM APIs because we can't 866 // event in order not to keep the selection by DOM APIs because we can't
867 // give the user the chance to handle the selection by user action like 867 // give the user the chance to handle the selection by user action like
868 // dragging if we keep the selection in case of mousedown. FireFox also has 868 // dragging if we keep the selection in case of mousedown. FireFox also has
869 // the same behavior and it's more compatible with other browsers. 869 // the same behavior and it's more compatible with other browsers.
870 selectionController().initializeSelectionState(); 870 selectionController().initializeSelectionState();
871 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly); 871 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly);
872 InputDeviceCapabilities* sourceCapabilities = mouseEvent.getSyntheticEventTy pe() == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEvent sSourceCapabilities() : 872 InputDeviceCapabilities* sourceCapabilities = mouseEvent.getSyntheticEventTy pe() == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEvent sSourceCapabilities() :
873 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities(); 873 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities();
874 if (eventResult == WebInputEventResult::NotHandled) 874 if (eventResult == WebInputEventResult::NotHandled)
875 eventResult = handleMouseFocus(MouseEventWithHitTestResults(mev.event(), hitTestResult), sourceCapabilities); 875 eventResult = handleMouseFocus(hitTestResult, sourceCapabilities);
876 m_capturesDragging = eventResult == WebInputEventResult::NotHandled || mev.s crollbar(); 876 m_capturesDragging = eventResult == WebInputEventResult::NotHandled || mev.s crollbar();
877 877
878 // If the hit testing originally determined the event was in a scrollbar, re fetch the MouseEventWithHitTestResults 878 // If the hit testing originally determined the event was in a scrollbar, re fetch the MouseEventWithHitTestResults
879 // in case the scrollbar widget was destroyed when the mouse event was handl ed. 879 // in case the scrollbar widget was destroyed when the mouse event was handl ed.
880 if (mev.scrollbar()) { 880 if (mev.scrollbar()) {
881 const bool wasLastScrollBar = mev.scrollbar() == m_lastScrollbarUnderMou se.get(); 881 const bool wasLastScrollBar = mev.scrollbar() == m_lastScrollbarUnderMou se.get();
882 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active ); 882 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active );
883 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mou seEvent); 883 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mou seEvent);
884 if (wasLastScrollBar && mev.scrollbar() != m_lastScrollbarUnderMouse.get ()) 884 if (wasLastScrollBar && mev.scrollbar() != m_lastScrollbarUnderMouse.get ())
885 m_lastScrollbarUnderMouse = nullptr; 885 m_lastScrollbarUnderMouse = nullptr;
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 1503
1504 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler. 1504 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
1505 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent) 1505 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent)
1506 { 1506 {
1507 ASSERT(mouseEventType == EventTypeNames::mousedown 1507 ASSERT(mouseEventType == EventTypeNames::mousedown
1508 || mouseEventType == EventTypeNames::mousemove 1508 || mouseEventType == EventTypeNames::mousemove
1509 || mouseEventType == EventTypeNames::mouseup); 1509 || mouseEventType == EventTypeNames::mouseup);
1510 1510
1511 Node* lastNodeUnderMouse = updateMouseEventTargetNode(targetNode, mouseEvent ); 1511 Node* lastNodeUnderMouse = updateMouseEventTargetNode(targetNode, mouseEvent );
1512 1512
1513 if (mouseEvent.getSyntheticEventType() == PlatformMouseEvent::FromTouch)
1514 return dispatchMouseEvent(mouseEventType, m_nodeUnderMouse, clickCount, mouseEvent);
1515
1516 Node* newNodeUnderMouse = nullptr; 1513 Node* newNodeUnderMouse = nullptr;
1517 const auto& eventResult = m_pointerEventManager.sendMousePointerEvent( 1514 const auto& eventResult = m_pointerEventManager.sendMousePointerEvent(
1518 m_nodeUnderMouse, mouseEventType, clickCount, mouseEvent, nullptr, 1515 m_nodeUnderMouse, mouseEventType, clickCount, mouseEvent, nullptr,
1519 lastNodeUnderMouse, &newNodeUnderMouse); 1516 lastNodeUnderMouse, &newNodeUnderMouse);
1520 m_nodeUnderMouse = newNodeUnderMouse; 1517 m_nodeUnderMouse = newNodeUnderMouse;
1521 return eventResult; 1518 return eventResult;
1522 } 1519 }
1523 1520
1524 void EventHandler::setClickNode(Node* node) 1521 void EventHandler::setClickNode(Node* node)
1525 { 1522 {
1526 m_clickNode = node; 1523 m_clickNode = node;
1527 } 1524 }
1528 1525
1529 WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestRe sults& targetedEvent, InputDeviceCapabilities* sourceCapabilities) 1526 WebInputEventResult EventHandler::handleMouseFocus(const HitTestResult& hitTestR esult, InputDeviceCapabilities* sourceCapabilities)
1530 { 1527 {
1531 // If clicking on a frame scrollbar, do not mess up with content focus. 1528 // If clicking on a frame scrollbar, do not mess up with content focus.
1532 if (targetedEvent.hitTestResult().scrollbar() && !m_frame->contentLayoutItem ().isNull()) { 1529 if (hitTestResult.scrollbar() && !m_frame->contentLayoutItem().isNull()) {
1533 if (targetedEvent.hitTestResult().scrollbar()->getScrollableArea() == m_ frame->contentLayoutItem().getScrollableArea()) 1530 if (hitTestResult.scrollbar()->getScrollableArea() == m_frame->contentLa youtItem().getScrollableArea())
1534 return WebInputEventResult::NotHandled; 1531 return WebInputEventResult::NotHandled;
1535 } 1532 }
1536 1533
1537 // The layout needs to be up to date to determine if an element is focusable . 1534 // The layout needs to be up to date to determine if an element is focusable .
1538 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1535 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
1539 1536
1540 Element* element = nullptr; 1537 Element* element = nullptr;
1541 if (m_nodeUnderMouse) 1538 if (m_nodeUnderMouse)
1542 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement(); 1539 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement();
1543 for (; element; element = element->parentOrShadowHostElement()) { 1540 for (; element; element = element->parentOrShadowHostElement()) {
(...skipping 13 matching lines...) Expand all
1557 // TODO(yosin) We should not create |Range| object for calling 1554 // TODO(yosin) We should not create |Range| object for calling
1558 // |isNodeFullyContained()|. 1555 // |isNodeFullyContained()|.
1559 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element) 1556 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element)
1560 && element->isDescendantOf(m_frame->document()->focusedElement())) 1557 && element->isDescendantOf(m_frame->document()->focusedElement()))
1561 return WebInputEventResult::NotHandled; 1558 return WebInputEventResult::NotHandled;
1562 } 1559 }
1563 1560
1564 1561
1565 // Only change the focus when clicking scrollbars if it can transfered to a 1562 // Only change the focus when clicking scrollbars if it can transfered to a
1566 // mouse focusable node. 1563 // mouse focusable node.
1567 if (!element && targetedEvent.hitTestResult().scrollbar()) 1564 if (!element && hitTestResult.scrollbar())
1568 return WebInputEventResult::HandledSystem; 1565 return WebInputEventResult::HandledSystem;
1569 1566
1570 if (Page* page = m_frame->page()) { 1567 if (Page* page = m_frame->page()) {
1571 // If focus shift is blocked, we eat the event. Note we should never 1568 // If focus shift is blocked, we eat the event. Note we should never
1572 // clear swallowEvent if the page already set it (e.g., by canceling 1569 // clear swallowEvent if the page already set it (e.g., by canceling
1573 // default behavior). 1570 // default behavior).
1574 if (element) { 1571 if (element) {
1575 if (slideFocusOnShadowHostIfNecessary(*element)) 1572 if (slideFocusOnShadowHostIfNecessary(*element))
1576 return WebInputEventResult::HandledSystem; 1573 return WebInputEventResult::HandledSystem;
1577 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) ) 1574 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) )
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 result.setInnerNode(targetNode); 2091 result.setInnerNode(targetNode);
2095 doc->updateHoverActiveState(request, result.innerElement()); 2092 doc->updateHoverActiveState(request, result.innerElement());
2096 2093
2097 // The contextmenu event is a mouse event even when invoked using the keyboa rd. 2094 // The contextmenu event is a mouse event even when invoked using the keyboa rd.
2098 // This is required for web compatibility. 2095 // This is required for web compatibility.
2099 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; 2096 PlatformEvent::EventType eventType = PlatformEvent::MousePressed;
2100 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) 2097 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp())
2101 eventType = PlatformEvent::MouseReleased; 2098 eventType = PlatformEvent::MouseReleased;
2102 2099
2103 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition, 2100 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition,
2104 RightButton, eventType, 1, 2101 NoButton, eventType, /* clickCount */ 0,
2105 PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistinguishable, 2102 PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistinguishable,
2106 WTF::monotonicallyIncreasingTime(), WebPointerProperties::PointerType::M ouse); 2103 WTF::monotonicallyIncreasingTime(), WebPointerProperties::PointerType::M ouse);
2107 2104
2108 return sendContextMenuEvent(mouseEvent, overrideTargetElement); 2105 return sendContextMenuEvent(mouseEvent, overrideTargetElement);
2109 } 2106 }
2110 2107
2111 void EventHandler::scheduleHoverStateUpdate() 2108 void EventHandler::scheduleHoverStateUpdate()
2112 { 2109 {
2113 if (!m_hoverTimer.isActive()) 2110 if (!m_hoverTimer.isActive())
2114 m_hoverTimer.startOneShot(0, BLINK_FROM_HERE); 2111 m_hoverTimer.startOneShot(0, BLINK_FROM_HERE);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 2589
2593 FrameHost* EventHandler::frameHost() const 2590 FrameHost* EventHandler::frameHost() const
2594 { 2591 {
2595 if (!m_frame->page()) 2592 if (!m_frame->page())
2596 return nullptr; 2593 return nullptr;
2597 2594
2598 return &m_frame->page()->frameHost(); 2595 return &m_frame->page()->frameHost();
2599 } 2596 }
2600 2597
2601 } // namespace blink 2598 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698