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

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

Issue 2049493002: Remove the default wheel event handler from blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove two tests, fix nit Created 4 years, 6 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #include "platform/scroll/Scrollbar.h" 101 #include "platform/scroll/Scrollbar.h"
102 #include "wtf/Assertions.h" 102 #include "wtf/Assertions.h"
103 #include "wtf/CurrentTime.h" 103 #include "wtf/CurrentTime.h"
104 #include "wtf/StdLibExtras.h" 104 #include "wtf/StdLibExtras.h"
105 #include "wtf/TemporaryChange.h" 105 #include "wtf/TemporaryChange.h"
106 106
107 namespace blink { 107 namespace blink {
108 108
109 namespace { 109 namespace {
110 110
111 // Convert |event->deltaMode()| to scroll granularity and output as |granularity |.
112 bool wheelGranularityToScrollGranularity(const WheelEvent* event, ScrollGranular ity* granularity)
113 {
114 DCHECK(granularity);
115 switch (event->deltaMode()) {
116 case WheelEvent::DOM_DELTA_PAGE:
117 *granularity = ScrollByPage;
118 return true;
119 case WheelEvent::DOM_DELTA_LINE:
120 *granularity = ScrollByLine;
121 return true;
122 case WheelEvent::DOM_DELTA_PIXEL:
123 *granularity = event->hasPreciseScrollingDeltas() ? ScrollByPrecisePixel : ScrollByPixel;
124 return true;
125 default:
126 // Could be other values since the event might come from JavaScript.
127 return false;
128 }
129 }
130
131 // Refetch the event target node if it is removed or currently is the shadow nod e inside an <input> element. 111 // Refetch the event target node if it is removed or currently is the shadow nod e inside an <input> element.
132 // If a mouse event handler changes the input element type to one that has a wid get associated, 112 // If a mouse event handler changes the input element type to one that has a wid get associated,
133 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the 113 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the
134 // event target node can't still be the shadow node. 114 // event target node can't still be the shadow node.
135 bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev) 115 bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev)
136 { 116 {
137 Node* targetNode = mev.innerNode(); 117 Node* targetNode = mev.innerNode();
138 if (!targetNode || !targetNode->parentNode()) 118 if (!targetNode || !targetNode->parentNode())
139 return true; 119 return true;
140 return targetNode->isShadowRoot() && isHTMLInputElement(toShadowRoot(targetN ode)->host()); 120 return targetNode->isShadowRoot() && isHTMLInputElement(toShadowRoot(targetN ode)->host());
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 1614
1635 Node* node = result.innerNode(); 1615 Node* node = result.innerNode();
1636 // Wheel events should not dispatch to text nodes. 1616 // Wheel events should not dispatch to text nodes.
1637 if (node && node->isTextNode()) 1617 if (node && node->isTextNode())
1638 node = FlatTreeTraversal::parent(*node); 1618 node = FlatTreeTraversal::parent(*node);
1639 1619
1640 // If we're over the frame scrollbar, scroll the document. 1620 // If we're over the frame scrollbar, scroll the document.
1641 if (!node && result.scrollbar()) 1621 if (!node && result.scrollbar())
1642 node = doc->documentElement(); 1622 node = doc->documentElement();
1643 1623
1644 bool sendDOMEvent = true;
1645 LocalFrame* subframe = subframeForTargetNode(node); 1624 LocalFrame* subframe = subframeForTargetNode(node);
1646 if (subframe) { 1625 if (subframe) {
1647 WebInputEventResult result = subframe->eventHandler().handleWheelEvent(e vent); 1626 WebInputEventResult result = subframe->eventHandler().handleWheelEvent(e vent);
1648 if (result != WebInputEventResult::NotHandled) { 1627 if (result != WebInputEventResult::NotHandled)
1649 m_scrollManager.setFrameWasScrolledByUser(); 1628 m_scrollManager.setFrameWasScrolledByUser();
1650 return result; 1629 return result;
1651 }
1652 // TODO(dtapuska): Remove this once wheel gesture scroll has
1653 // been enabled everywhere; as we can just return early.
1654 // http://crbug.com/568183
1655 // Don't propagate the DOM event into the parent iframe
1656 // but do dispatch the scroll event.
1657 sendDOMEvent = false;
1658 } 1630 }
1659 1631
1660 if (node) { 1632 if (node) {
1661 WheelEvent* domEvent = WheelEvent::create(event, node->document().domWin dow()); 1633 WheelEvent* domEvent = WheelEvent::create(event, node->document().domWin dow());
1662 if (sendDOMEvent) { 1634 DispatchEventResult domEventResult = node->dispatchEvent(domEvent);
1663 DispatchEventResult domEventResult = node->dispatchEvent(domEvent); 1635 if (domEventResult != DispatchEventResult::NotCanceled)
1664 if (domEventResult != DispatchEventResult::NotCanceled) 1636 return toWebInputEventResult(domEventResult);
1665 return toWebInputEventResult(domEventResult);
1666 } else {
1667 defaultWheelEventHandler(node, domEvent);
1668 if (domEvent->defaultHandled())
1669 return WebInputEventResult::HandledSystem;
1670 }
1671 } 1637 }
1672 1638
1673 return WebInputEventResult::NotHandled; 1639 return WebInputEventResult::NotHandled;
1674 } 1640 }
1675 1641
1676 void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv ent)
1677 {
1678 if (!startNode || !wheelEvent)
1679 return;
1680
1681 Settings* settings = m_frame->settings();
1682 if (settings && settings->wheelGesturesEnabled())
1683 return;
1684
1685 // When the wheelEvent do not scroll, we trigger zoom in/out instead.
1686 if (!wheelEvent->canScroll())
1687 return;
1688
1689 ScrollGranularity granularity;
1690 if (!wheelGranularityToScrollGranularity(wheelEvent, &granularity))
1691 return;
1692 Node* node = nullptr;
1693
1694 // Diagonal movement on a MacBook pro is an example of a 2-dimensional
1695 // mouse wheel event (where both deltaX and deltaY can be set).
1696 FloatSize delta;
1697
1698 if (wheelEvent->getRailsMode() != Event::RailsModeVertical)
1699 delta.setWidth(wheelEvent->deltaX());
1700
1701 if (wheelEvent->getRailsMode() != Event::RailsModeHorizontal)
1702 delta.setHeight(wheelEvent->deltaY());
1703
1704 // We can get page wheel events with non-[0|1] deltas in the case where the
1705 // events are coalesced but we still want to scroll by just one page length.
1706 // TODO(bokan): This seems like it belongs in the coalescing logic.
1707 if (granularity == ScrollByPage) {
1708 if (delta.width())
1709 delta.setWidth(delta.width() > 0 ? 1 : -1);
1710 if (delta.height())
1711 delta.setHeight(delta.height() > 0 ? 1 : -1);
1712 }
1713
1714 // FIXME: enable scroll customization in this case. See crbug.com/410974.
1715 bool consumed = false;
1716
1717 m_scrollManager.physicalScroll(
1718 granularity,
1719 delta,
1720 FloatPoint(),
1721 FloatSize(),
1722 startNode,
1723 &node,
1724 &consumed);
1725
1726 if (consumed)
1727 wheelEvent->setDefaultHandled();
1728 }
1729
1730 WebInputEventResult EventHandler::handleGestureShowPress() 1642 WebInputEventResult EventHandler::handleGestureShowPress()
1731 { 1643 {
1732 m_lastShowPressTimestamp = WTF::monotonicallyIncreasingTime(); 1644 m_lastShowPressTimestamp = WTF::monotonicallyIncreasingTime();
1733 1645
1734 FrameView* view = m_frame->view(); 1646 FrameView* view = m_frame->view();
1735 if (!view) 1647 if (!view)
1736 return WebInputEventResult::NotHandled; 1648 return WebInputEventResult::NotHandled;
1737 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator()) 1649 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator())
1738 scrollAnimator->cancelAnimation(); 1650 scrollAnimator->cancelAnimation();
1739 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas(); 1651 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas();
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
3151 3063
3152 FrameHost* EventHandler::frameHost() const 3064 FrameHost* EventHandler::frameHost() const
3153 { 3065 {
3154 if (!m_frame->page()) 3066 if (!m_frame->page())
3155 return nullptr; 3067 return nullptr;
3156 3068
3157 return &m_frame->page()->frameHost(); 3069 return &m_frame->page()->frameHost();
3158 } 3070 }
3159 3071
3160 } // namespace blink 3072 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | third_party/WebKit/Source/web/WebSettingsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698