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

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: Realigned test outcomes. Created 4 years, 3 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 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 1511
1512 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler. 1512 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
1513 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent) 1513 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent)
1514 { 1514 {
1515 ASSERT(mouseEventType == EventTypeNames::mousedown 1515 ASSERT(mouseEventType == EventTypeNames::mousedown
1516 || mouseEventType == EventTypeNames::mousemove 1516 || mouseEventType == EventTypeNames::mousemove
1517 || mouseEventType == EventTypeNames::mouseup); 1517 || mouseEventType == EventTypeNames::mouseup);
1518 1518
1519 Node* lastNodeUnderMouse = updateMouseEventTargetNode(targetNode, mouseEvent ); 1519 Node* lastNodeUnderMouse = updateMouseEventTargetNode(targetNode, mouseEvent );
1520 1520
1521 if (mouseEvent.getSyntheticEventType() == PlatformMouseEvent::FromTouch)
bokan 2016/08/26 16:55:14 Help me understand, why was this removed?
mustaq 2016/08/26 17:19:03 This was added as a quick fix to prevent PE-firing
bokan 2016/08/26 17:31:53 So is this now ok because gesture events don't com
mustaq 2016/08/26 19:02:06 Right: from the overall event handling perspective
1522 return dispatchMouseEvent(mouseEventType, m_nodeUnderMouse, clickCount, mouseEvent);
1523
1524 Node* newNodeUnderMouse = nullptr; 1521 Node* newNodeUnderMouse = nullptr;
1525 const auto& eventResult = m_pointerEventManager.sendMousePointerEvent( 1522 const auto& eventResult = m_pointerEventManager.sendMousePointerEvent(
1526 m_nodeUnderMouse, mouseEventType, clickCount, mouseEvent, 1523 m_nodeUnderMouse, mouseEventType, clickCount, mouseEvent,
1527 lastNodeUnderMouse, &newNodeUnderMouse); 1524 lastNodeUnderMouse, &newNodeUnderMouse);
1528 m_nodeUnderMouse = newNodeUnderMouse; 1525 m_nodeUnderMouse = newNodeUnderMouse;
1529 return eventResult; 1526 return eventResult;
1530 } 1527 }
1531 1528
1532 void EventHandler::setClickNode(Node* node) 1529 void EventHandler::setClickNode(Node* node)
1533 { 1530 {
1534 m_clickNode = node; 1531 m_clickNode = node;
1535 } 1532 }
1536 1533
1537 WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestRe sults& targetedEvent, InputDeviceCapabilities* sourceCapabilities) 1534 WebInputEventResult EventHandler::handleMouseFocus(const HitTestResult& hitTestR esult, InputDeviceCapabilities* sourceCapabilities)
1538 { 1535 {
1539 // If clicking on a frame scrollbar, do not mess up with content focus. 1536 // If clicking on a frame scrollbar, do not mess up with content focus.
1540 if (targetedEvent.hitTestResult().scrollbar() && !m_frame->contentLayoutItem ().isNull()) { 1537 if (hitTestResult.scrollbar() && !m_frame->contentLayoutItem().isNull()) {
1541 if (targetedEvent.hitTestResult().scrollbar()->getScrollableArea() == m_ frame->contentLayoutItem().getScrollableArea()) 1538 if (hitTestResult.scrollbar()->getScrollableArea() == m_frame->contentLa youtItem().getScrollableArea())
1542 return WebInputEventResult::NotHandled; 1539 return WebInputEventResult::NotHandled;
1543 } 1540 }
1544 1541
1545 // The layout needs to be up to date to determine if an element is focusable . 1542 // The layout needs to be up to date to determine if an element is focusable .
1546 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1543 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
1547 1544
1548 Element* element = nullptr; 1545 Element* element = nullptr;
1549 if (m_nodeUnderMouse) 1546 if (m_nodeUnderMouse)
1550 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement(); 1547 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement();
1551 for (; element; element = element->parentOrShadowHostElement()) { 1548 for (; element; element = element->parentOrShadowHostElement()) {
(...skipping 13 matching lines...) Expand all
1565 // TODO(yosin) We should not create |Range| object for calling 1562 // TODO(yosin) We should not create |Range| object for calling
1566 // |isNodeFullyContained()|. 1563 // |isNodeFullyContained()|.
1567 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element) 1564 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element)
1568 && element->isDescendantOf(m_frame->document()->focusedElement())) 1565 && element->isDescendantOf(m_frame->document()->focusedElement()))
1569 return WebInputEventResult::NotHandled; 1566 return WebInputEventResult::NotHandled;
1570 } 1567 }
1571 1568
1572 1569
1573 // Only change the focus when clicking scrollbars if it can transfered to a 1570 // Only change the focus when clicking scrollbars if it can transfered to a
1574 // mouse focusable node. 1571 // mouse focusable node.
1575 if (!element && targetedEvent.hitTestResult().scrollbar()) 1572 if (!element && hitTestResult.scrollbar())
1576 return WebInputEventResult::HandledSystem; 1573 return WebInputEventResult::HandledSystem;
1577 1574
1578 if (Page* page = m_frame->page()) { 1575 if (Page* page = m_frame->page()) {
1579 // If focus shift is blocked, we eat the event. Note we should never 1576 // If focus shift is blocked, we eat the event. Note we should never
1580 // clear swallowEvent if the page already set it (e.g., by canceling 1577 // clear swallowEvent if the page already set it (e.g., by canceling
1581 // default behavior). 1578 // default behavior).
1582 if (element) { 1579 if (element) {
1583 if (slideFocusOnShadowHostIfNecessary(*element)) 1580 if (slideFocusOnShadowHostIfNecessary(*element))
1584 return WebInputEventResult::HandledSystem; 1581 return WebInputEventResult::HandledSystem;
1585 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) ) 1582 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
2102 result.setInnerNode(targetNode); 2099 result.setInnerNode(targetNode);
2103 doc->updateHoverActiveState(request, result.innerElement()); 2100 doc->updateHoverActiveState(request, result.innerElement());
2104 2101
2105 // The contextmenu event is a mouse event even when invoked using the keyboa rd. 2102 // The contextmenu event is a mouse event even when invoked using the keyboa rd.
2106 // This is required for web compatibility. 2103 // This is required for web compatibility.
2107 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; 2104 PlatformEvent::EventType eventType = PlatformEvent::MousePressed;
2108 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) 2105 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp())
2109 eventType = PlatformEvent::MouseReleased; 2106 eventType = PlatformEvent::MouseReleased;
2110 2107
2111 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition, 2108 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition,
2112 WebPointerProperties::Button::Right, eventType, 1, 2109 WebPointerProperties::Button::NoButton, eventType, /* clickCount */ 0,
2113 PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistinguishable, 2110 PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistinguishable,
2114 WTF::monotonicallyIncreasingTime(), WebPointerProperties::PointerType::M ouse); 2111 WTF::monotonicallyIncreasingTime(), WebPointerProperties::PointerType::M ouse);
2115 2112
2116 return sendContextMenuEvent(mouseEvent, overrideTargetElement); 2113 return sendContextMenuEvent(mouseEvent, overrideTargetElement);
2117 } 2114 }
2118 2115
2119 void EventHandler::scheduleHoverStateUpdate() 2116 void EventHandler::scheduleHoverStateUpdate()
2120 { 2117 {
2121 if (!m_hoverTimer.isActive()) 2118 if (!m_hoverTimer.isActive())
2122 m_hoverTimer.startOneShot(0, BLINK_FROM_HERE); 2119 m_hoverTimer.startOneShot(0, BLINK_FROM_HERE);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 2597
2601 FrameHost* EventHandler::frameHost() const 2598 FrameHost* EventHandler::frameHost() const
2602 { 2599 {
2603 if (!m_frame->page()) 2600 if (!m_frame->page())
2604 return nullptr; 2601 return nullptr;
2605 2602
2606 return &m_frame->page()->frameHost(); 2603 return &m_frame->page()->frameHost();
2607 } 2604 }
2608 2605
2609 } // namespace blink 2606 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698