<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[163975] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/163975">163975</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2014-02-12 12:40:17 -0800 (Wed, 12 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Wheel events don't latch to inner scrollable elements 
https://bugs.webkit.org/show_bug.cgi?id=128225
&lt;rdar://problem/12183688&gt;

Reviewed by Simon Fraser

* WebCore.exp.in: Add declarations for new scrolledToTop, scrolledToBottom, scrolledToLeft, and scrolledToRight.
* page/EventHandler.cpp:
(WebCore::EventHandler::EventHandler):
(WebCore::EventHandler::clear):
(WebCore::findScrollableContainer): New helper function to locate first node
in enclosing region of document that is capable of handling mouse wheel events.
(WebCore::isAtMaxDominantScrollPosition): Predicate to check if the scrollable
area is at the limit we will hit based on scroll direction.
(WebCore::EventHandler::handleWheelEvent): Identify the case where we have hit
the end of a scroll, and treat that as a valid 'handled' case. If the scroll event
is just starting, treat end-of-scroll as unhandled so the parent element can
handle things.
* page/EventHandler.h:
* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::shouldHandleWheelEventSynchronously): Use new methods
on the PlatformWheelEvent class.
(WebCore::ScrollingTree::setOrClearLatchedNode): Ditto
* platform/PlatformWheelEvent.h:
(WebCore::PlatformWheelEvent::shouldConsiderLatching): Moved implementation from ScrollingTree.
(WebCore::PlatformWheelEvent::shouldClearLatchedNode): Ditto
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::scrolledToTop): Added
(WebCore::ScrollableArea::scrolledToBottom):Added
(WebCore::ScrollableArea::scrolledToLeft): Added
(WebCore::ScrollableArea::scrolledToRight): Added
* platform/ScrollableArea.h:
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::scrolledToTop): Added
(WebCore::RenderListBox::scrolledToBottom): Added
(WebCore::RenderListBox::scrolledToLeft): Added
(WebCore::RenderListBox::scrolledToRight): Added
* rendering/RenderListBox.h: Changed to public inheritance of ScrollableArea to
allow generic use of this type in scroll wheel logic.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlerh">trunk/Source/WebCore/page/EventHandler.h</a></li>
<li><a href="#trunkSourceWebCorepagemacEventHandlerMacmm">trunk/Source/WebCore/page/mac/EventHandlerMac.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingTreecpp">trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformPlatformWheelEventh">trunk/Source/WebCore/platform/PlatformWheelEvent.h</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreacpp">trunk/Source/WebCore/platform/ScrollableArea.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreah">trunk/Source/WebCore/platform/ScrollableArea.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderListBoxcpp">trunk/Source/WebCore/rendering/RenderListBox.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderListBoxh">trunk/Source/WebCore/rendering/RenderListBox.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/ChangeLog        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,3 +1,45 @@
</span><ins>+2014-02-12  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Wheel events don't latch to inner scrollable elements 
+        https://bugs.webkit.org/show_bug.cgi?id=128225
+        &lt;rdar://problem/12183688&gt;
+
+        Reviewed by Simon Fraser
+
+        * WebCore.exp.in: Add declarations for new scrolledToTop, scrolledToBottom, scrolledToLeft, and scrolledToRight.
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::EventHandler):
+        (WebCore::EventHandler::clear):
+        (WebCore::findScrollableContainer): New helper function to locate first node
+        in enclosing region of document that is capable of handling mouse wheel events.
+        (WebCore::isAtMaxDominantScrollPosition): Predicate to check if the scrollable
+        area is at the limit we will hit based on scroll direction.
+        (WebCore::EventHandler::handleWheelEvent): Identify the case where we have hit
+        the end of a scroll, and treat that as a valid 'handled' case. If the scroll event
+        is just starting, treat end-of-scroll as unhandled so the parent element can
+        handle things.
+        * page/EventHandler.h:
+        * page/scrolling/ScrollingTree.cpp:
+        (WebCore::ScrollingTree::shouldHandleWheelEventSynchronously): Use new methods
+        on the PlatformWheelEvent class.
+        (WebCore::ScrollingTree::setOrClearLatchedNode): Ditto
+        * platform/PlatformWheelEvent.h:
+        (WebCore::PlatformWheelEvent::shouldConsiderLatching): Moved implementation from ScrollingTree.
+        (WebCore::PlatformWheelEvent::shouldClearLatchedNode): Ditto
+        * platform/ScrollableArea.cpp:
+        (WebCore::ScrollableArea::scrolledToTop): Added
+        (WebCore::ScrollableArea::scrolledToBottom):Added
+        (WebCore::ScrollableArea::scrolledToLeft): Added
+        (WebCore::ScrollableArea::scrolledToRight): Added
+        * platform/ScrollableArea.h:
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::scrolledToTop): Added
+        (WebCore::RenderListBox::scrolledToBottom): Added
+        (WebCore::RenderListBox::scrolledToLeft): Added
+        (WebCore::RenderListBox::scrolledToRight): Added
+        * rendering/RenderListBox.h: Changed to public inheritance of ScrollableArea to
+        allow generic use of this type in scroll wheel logic.
+
</ins><span class="cx"> 2014-02-12  Brendan Long  &lt;b.long@cablelabs.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement DataCue for metadata cues
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -396,6 +396,10 @@
</span><span class="cx"> __ZN7WebCore14ScrollableArea15contentsResizedEv
</span><span class="cx"> __ZN7WebCore14ScrollableArea15didAddScrollbarEPNS_9ScrollbarENS_20ScrollbarOrientationE
</span><span class="cx"> __ZN7WebCore14ScrollableArea16handleWheelEventERKNS_18PlatformWheelEventE
</span><ins>+__ZNK7WebCore14ScrollableArea16scrolledToBottomEv
+__ZNK7WebCore14ScrollableArea14scrolledToLeftEv
+__ZNK7WebCore14ScrollableArea13scrolledToTopEv
+__ZNK7WebCore14ScrollableArea15scrolledToRightEv
</ins><span class="cx"> __ZN7WebCore14ScrollableArea17willEndLiveResizeEv
</span><span class="cx"> __ZN7WebCore14ScrollableArea19invalidateScrollbarEPNS_9ScrollbarERKNS_7IntRectE
</span><span class="cx"> __ZN7WebCore14ScrollableArea19willRemoveScrollbarEPNS_9ScrollbarENS_20ScrollbarOrientationE
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/page/EventHandler.cpp        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006-2014 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
</span><span class="cx">  * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
</span><span class="cx">  *
</span><span class="lines">@@ -72,6 +72,7 @@
</span><span class="cx"> #include &quot;PluginDocument.h&quot;
</span><span class="cx"> #include &quot;RenderFrameSet.h&quot;
</span><span class="cx"> #include &quot;RenderLayer.h&quot;
</span><ins>+#include &quot;RenderListBox.h&quot;
</ins><span class="cx"> #include &quot;RenderTextControlSingleLine.h&quot;
</span><span class="cx"> #include &quot;RenderView.h&quot;
</span><span class="cx"> #include &quot;RenderWidget.h&quot;
</span><span class="lines">@@ -353,6 +354,7 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     , m_mouseDownView(nil)
</span><span class="cx">     , m_sendingEventToSubview(false)
</span><ins>+    , m_startedGestureAtScrollLimit(false)
</ins><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     , m_activationEventNumber(-1)
</span><span class="cx"> #endif // !PLATFORM(IOS)
</span><span class="lines">@@ -432,6 +434,9 @@
</span><span class="cx">     m_capturesDragging = false;
</span><span class="cx">     m_capturingMouseEventsElement = nullptr;
</span><span class="cx">     m_latchedWheelEventElement = nullptr;
</span><ins>+#if PLATFORM(COCOA)
+    m_latchedScrollableContainer = nullptr;
+#endif
</ins><span class="cx">     m_previousWheelScrolledElement = nullptr;
</span><span class="cx"> #if ENABLE(TOUCH_EVENTS) &amp;&amp; !ENABLE(IOS_TOUCH_EVENTS)
</span><span class="cx">     m_originatingTouchPointTargets.clear();
</span><span class="lines">@@ -2442,6 +2447,27 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if !PLATFORM(MAC)
+void EventHandler::platformPrepareForWheelEvents(const PlatformWheelEvent&amp;, const HitTestResult&amp;, Element*&amp;, ContainerNode*&amp;, ScrollableArea*&amp;, bool&amp;)
+{
+}
+
+void EventHandler::platformRecordWheelEvent(const PlatformWheelEvent&amp; event)
+{
+    m_recentWheelEventDeltaTracker-&gt;recordWheelEventDelta(event);
+}
+
+bool EventHandler::platformCompleteWheelEvent(const PlatformWheelEvent&amp; event, ContainerNode*, ScrollableArea*)
+{
+    // We do another check on the frame view because the event handler can run JS which results in the frame getting destroyed.
+    FrameView* view = m_frame.view();
+    
+    bool didHandleEvent = view ? view-&gt;wheelEvent(event) : false;
+    m_isHandlingWheelEvent = false;
+    return didHandleEvent;
+}
+#endif
+
</ins><span class="cx"> bool EventHandler::handleWheelEvent(const PlatformWheelEvent&amp; e)
</span><span class="cx"> {
</span><span class="cx">     Document* document = m_frame.document();
</span><span class="lines">@@ -2463,28 +2489,14 @@
</span><span class="cx">     HitTestResult result(vPoint);
</span><span class="cx">     document-&gt;renderView()-&gt;hitTest(request, result);
</span><span class="cx"> 
</span><del>-    bool useLatchedWheelEventElement = e.useLatchedEventElement();
-
</del><span class="cx">     Element* element = result.innerElement();
</span><span class="cx"> 
</span><del>-    bool isOverWidget;
-    if (useLatchedWheelEventElement) {
-        if (!m_latchedWheelEventElement) {
-            m_latchedWheelEventElement = element;
-            m_widgetIsLatched = result.isOverWidget();
-        } else
-            element = m_latchedWheelEventElement.get();
</del><ins>+    bool isOverWidget = result.isOverWidget();
</ins><span class="cx"> 
</span><del>-        isOverWidget = m_widgetIsLatched;
-    } else {
-        if (m_latchedWheelEventElement)
-            m_latchedWheelEventElement = nullptr;
-        if (m_previousWheelScrolledElement)
-            m_previousWheelScrolledElement = nullptr;
</del><ins>+    ContainerNode* scrollableContainer = nullptr;
+    ScrollableArea* scrollableArea = nullptr;
+    platformPrepareForWheelEvents(e, result, element, scrollableContainer, scrollableArea, isOverWidget);
</ins><span class="cx"> 
</span><del>-        isOverWidget = result.isOverWidget();
-    }
-
</del><span class="cx">     // FIXME: It should not be necessary to do this mutation here.
</span><span class="cx">     // Instead, the handlers should know convert vertical scrolls
</span><span class="cx">     // appropriately.
</span><span class="lines">@@ -2492,21 +2504,8 @@
</span><span class="cx">     if (m_baseEventType == PlatformEvent::NoType &amp;&amp; shouldTurnVerticalTicksIntoHorizontal(result, e))
</span><span class="cx">         event = event.copyTurningVerticalTicksIntoHorizontalTicks();
</span><span class="cx"> 
</span><del>-#if PLATFORM(COCOA)
-    switch (event.phase()) {
-    case PlatformWheelEventPhaseBegan:
-        m_recentWheelEventDeltaTracker-&gt;beginTrackingDeltas();
-        break;
-    case PlatformWheelEventPhaseEnded:
-        m_recentWheelEventDeltaTracker-&gt;endTrackingDeltas();
-        break;
-    default:
-        break;
-    }
-#endif
</del><ins>+    platformRecordWheelEvent(event);
</ins><span class="cx"> 
</span><del>-    m_recentWheelEventDeltaTracker-&gt;recordWheelEventDelta(event);
-
</del><span class="cx">     if (element) {
</span><span class="cx">         // Figure out which view to send the event to.
</span><span class="cx">         RenderElement* target = element-&gt;renderer();
</span><span class="lines">@@ -2525,12 +2524,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-
-    // We do another check on the frame view because the event handler can run JS which results in the frame getting destroyed.
-    view = m_frame.view();
-    bool didHandleEvent = view ? view-&gt;wheelEvent(event) : false;
-    m_isHandlingWheelEvent = false;
-    return didHandleEvent;
</del><ins>+    return platformCompleteWheelEvent(e, scrollableContainer, scrollableArea);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEvent)
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.h (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.h        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/page/EventHandler.h        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006-2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -69,6 +69,7 @@
</span><span class="cx"> 
</span><span class="cx"> class AutoscrollController;
</span><span class="cx"> class Clipboard;
</span><ins>+class ContainerNode;
</ins><span class="cx"> class Document;
</span><span class="cx"> class Element;
</span><span class="cx"> class Event;
</span><span class="lines">@@ -90,6 +91,7 @@
</span><span class="cx"> class RenderElement;
</span><span class="cx"> class RenderLayer;
</span><span class="cx"> class RenderWidget;
</span><ins>+class ScrollableArea;
</ins><span class="cx"> class SVGElementInstance;
</span><span class="cx"> class Scrollbar;
</span><span class="cx"> class TextEvent;
</span><span class="lines">@@ -197,6 +199,10 @@
</span><span class="cx">     void defaultWheelEventHandler(Node*, WheelEvent*);
</span><span class="cx">     bool handlePasteGlobalSelection(const PlatformMouseEvent&amp;);
</span><span class="cx"> 
</span><ins>+    void platformPrepareForWheelEvents(const PlatformWheelEvent&amp; wheelEvent, const HitTestResult&amp; result, Element*&amp; wheelEventTarget, ContainerNode*&amp; scrollableContainer, ScrollableArea*&amp; scrollableArea, bool&amp; isOverWidget);
+    void platformRecordWheelEvent(const PlatformWheelEvent&amp;);
+    bool platformCompleteWheelEvent(const PlatformWheelEvent&amp;, ContainerNode* scrollableContainer, ScrollableArea* scrollableArea);
+
</ins><span class="cx"> #if ENABLE(IOS_TOUCH_EVENTS) || ENABLE(IOS_GESTURE_EVENTS)
</span><span class="cx">     typedef Vector&lt;RefPtr&lt;Touch&gt;&gt; TouchArray;
</span><span class="cx">     typedef HashMap&lt;EventTarget*, TouchArray*&gt; EventTargetTouchMap;
</span><span class="lines">@@ -520,7 +526,9 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     NSView *m_mouseDownView;
</span><ins>+    RefPtr&lt;ContainerNode&gt; m_latchedScrollableContainer;
</ins><span class="cx">     bool m_sendingEventToSubview;
</span><ins>+    bool m_startedGestureAtScrollLimit;
</ins><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     int m_activationEventNumber;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorepagemacEventHandlerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006, 2007, 2008, 2009, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,15 +38,20 @@
</span><span class="cx"> #include &quot;FrameLoader.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><span class="cx"> #include &quot;KeyboardEvent.h&quot;
</span><ins>+#include &quot;MainFrame.h&quot;
</ins><span class="cx"> #include &quot;MouseEventWithHitTestResults.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><span class="cx"> #include &quot;Page.h&quot;
</span><span class="cx"> #include &quot;Pasteboard.h&quot;
</span><span class="cx"> #include &quot;PlatformEventFactoryMac.h&quot;
</span><ins>+#include &quot;RenderLayer.h&quot;
+#include &quot;RenderListBox.h&quot;
</ins><span class="cx"> #include &quot;RenderWidget.h&quot;
</span><span class="cx"> #include &quot;RuntimeApplicationChecks.h&quot;
</span><ins>+#include &quot;ScrollableArea.h&quot;
</ins><span class="cx"> #include &quot;Scrollbar.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> #include &quot;WebCoreSystemInterface.h&quot;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #include &lt;wtf/NeverDestroyed.h&gt;
</span><span class="lines">@@ -734,4 +739,121 @@
</span><span class="cx">     return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static ContainerNode* findEnclosingScrollableContainer(ContainerNode&amp; node)
+{
+    // Find the first node with a valid scrollable area starting with the current
+    // node and traversing its parents (or shadow hosts).
+    for (ContainerNode* candidate = &amp;node; candidate; candidate = candidate-&gt;parentOrShadowHostNode()) {
+        RenderBox* box = candidate-&gt;renderBox();
+        if (box &amp;&amp; box-&gt;canBeScrolledAndHasScrollableArea())
+            return candidate;
+    }
+    
+    return nullptr;
</ins><span class="cx"> }
</span><ins>+
+static bool scrolledToEdgeInDominantDirection(const ScrollableArea&amp; area, DominantScrollGestureDirection direction, float deltaX, float deltaY)
+{
+    if (DominantScrollGestureDirection::Horizontal == direction &amp;&amp; deltaX) {
+        if (deltaX &lt; 0)
+            return area.scrolledToRight();
+        
+        return area.scrolledToLeft();
+    }
+    
+    if (deltaY &lt; 0)
+        return area.scrolledToBottom();
+    
+    return area.scrolledToTop();
+}
+
+void EventHandler::platformPrepareForWheelEvents(const PlatformWheelEvent&amp; wheelEvent, const HitTestResult&amp; result, Element*&amp; wheelEventTarget, ContainerNode*&amp; scrollableContainer, ScrollableArea*&amp; scrollableArea, bool&amp; isOverWidget)
+{
+    FrameView* view = m_frame.view();
+
+    scrollableContainer = nullptr;
+    scrollableArea = nullptr;
+    if (!view || !view-&gt;frame().isMainFrame()) {
+        scrollableContainer = wheelEventTarget;
+        scrollableArea = view;
+    } else {
+        scrollableContainer = findEnclosingScrollableContainer(*wheelEventTarget);
+        if (scrollableContainer) {
+            if (RenderBox* box = scrollableContainer-&gt;renderBox()) {
+                if (box-&gt;isListBox())
+                    scrollableArea = toRenderListBox(box);
+                else
+                    scrollableArea = box-&gt;layer();
+            }
+        }
+    }
+    
+    if (wheelEvent.shouldConsiderLatching()) {
+        if (scrollableArea)
+            m_startedGestureAtScrollLimit = scrolledToEdgeInDominantDirection(*scrollableArea, m_recentWheelEventDeltaTracker-&gt;dominantScrollGestureDirection(), wheelEvent.deltaX(), wheelEvent.deltaY());
+        else
+            m_startedGestureAtScrollLimit = false;
+        m_latchedWheelEventElement = wheelEventTarget;
+        m_latchedScrollableContainer = scrollableContainer;
+        m_widgetIsLatched = result.isOverWidget();
+        isOverWidget = m_widgetIsLatched;
+        m_recentWheelEventDeltaTracker-&gt;beginTrackingDeltas();
+    } else if (wheelEvent.shouldResetLatching()) {
+        m_latchedWheelEventElement = nullptr;
+        m_latchedScrollableContainer = nullptr;
+        m_widgetIsLatched = false;
+        m_previousWheelScrolledElement = nullptr;
+        m_recentWheelEventDeltaTracker-&gt;endTrackingDeltas();
+    }
+    
+    if (!wheelEvent.shouldResetLatching() &amp;&amp; m_latchedWheelEventElement) {
+        wheelEventTarget = m_latchedWheelEventElement.get();
+        isOverWidget = m_widgetIsLatched;
+    }
+}
+
+void EventHandler::platformRecordWheelEvent(const PlatformWheelEvent&amp; wheelEvent)
+{
+    switch (wheelEvent.phase()) {
+        case PlatformWheelEventPhaseBegan:
+            m_recentWheelEventDeltaTracker-&gt;beginTrackingDeltas();
+            break;
+        case PlatformWheelEventPhaseEnded:
+            m_recentWheelEventDeltaTracker-&gt;endTrackingDeltas();
+            break;
+        default:
+            break;
+    }
+
+    m_recentWheelEventDeltaTracker-&gt;recordWheelEventDelta(wheelEvent);
+}
+
+bool EventHandler::platformCompleteWheelEvent(const PlatformWheelEvent&amp; wheelEvent, ContainerNode* scrollableContainer, ScrollableArea* scrollableArea)
+{
+    // We do another check on the frame view because the event handler can run JS which results in the frame getting destroyed.
+    FrameView* view = m_frame.view();
+
+    if (wheelEvent.useLatchedEventElement() &amp;&amp; m_latchedScrollableContainer) {
+        if (!view || !view-&gt;frame().isMainFrame()) {
+            bool didHandleWheelEvent = view &amp;&amp; view-&gt;wheelEvent(wheelEvent);
+            if (!didHandleWheelEvent &amp;&amp; scrollableContainer == m_latchedScrollableContainer) {
+                // If we are just starting a scroll event, and have nowhere left to scroll, allow
+                // the enclosing frame to handle the scroll.
+                didHandleWheelEvent = !m_startedGestureAtScrollLimit;
+            }
+            m_isHandlingWheelEvent = false;
+            return didHandleWheelEvent;
+        }
+        
+        if (scrollableArea &amp;&amp; !m_startedGestureAtScrollLimit &amp;&amp; scrollableContainer == m_latchedScrollableContainer) {
+            m_isHandlingWheelEvent = false;
+            return true;
+        }
+    }
+    
+    bool didHandleEvent = view ? view-&gt;wheelEvent(wheelEvent) : false;
+    m_isHandlingWheelEvent = false;
+    return didHandleEvent;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -58,23 +58,6 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool shouldConsiderLatching(const PlatformWheelEvent&amp; wheelEvent)
-{
-    return wheelEvent.phase() == PlatformWheelEventPhaseBegan
-        || wheelEvent.phase() == PlatformWheelEventPhaseMayBegin;
-}
-
-static bool eventShouldClearLatchedNode(const PlatformWheelEvent&amp; wheelEvent)
-{
-    if (wheelEvent.phase() == PlatformWheelEventPhaseCancelled)
-        return true;
-    
-    if (wheelEvent.phase() == PlatformWheelEventPhaseNone &amp;&amp; wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded)
-        return true;
-    
-    return false;
-}
-
</del><span class="cx"> bool ScrollingTree::shouldHandleWheelEventSynchronously(const PlatformWheelEvent&amp; wheelEvent)
</span><span class="cx"> {
</span><span class="cx">     // This method is invoked by the event handling thread
</span><span class="lines">@@ -83,7 +66,7 @@
</span><span class="cx">     if (m_hasWheelEventHandlers)
</span><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    bool shouldSetLatch = shouldConsiderLatching(wheelEvent);
</del><ins>+    bool shouldSetLatch = wheelEvent.shouldConsiderLatching();
</ins><span class="cx">     
</span><span class="cx">     if (hasLatchedNode() &amp;&amp; !shouldSetLatch)
</span><span class="cx">         return false;
</span><span class="lines">@@ -103,9 +86,9 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollingTree::setOrClearLatchedNode(const PlatformWheelEvent&amp; wheelEvent, ScrollingNodeID nodeID)
</span><span class="cx"> {
</span><del>-    if (shouldConsiderLatching(wheelEvent))
</del><ins>+    if (wheelEvent.shouldConsiderLatching())
</ins><span class="cx">         setLatchedNode(nodeID);
</span><del>-    else if (eventShouldClearLatchedNode(wheelEvent))
</del><ins>+    else if (wheelEvent.shouldResetLatching())
</ins><span class="cx">         clearLatchedNode();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPlatformWheelEventh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PlatformWheelEvent.h (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PlatformWheelEvent.h        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/platform/PlatformWheelEvent.h        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -167,6 +167,20 @@
</span><span class="cx">             return m_phase == PlatformWheelEventPhaseBegan || m_phase == PlatformWheelEventPhaseChanged
</span><span class="cx">                 || m_momentumPhase == PlatformWheelEventPhaseBegan || m_momentumPhase == PlatformWheelEventPhaseChanged;
</span><span class="cx">         }
</span><ins>+        bool shouldConsiderLatching() const
+        {
+            return m_phase == PlatformWheelEventPhaseBegan || m_phase == PlatformWheelEventPhaseMayBegin;
+        }
+        bool shouldResetLatching() const
+        {
+            if (m_phase == PlatformWheelEventPhaseCancelled || m_phase == PlatformWheelEventPhaseMayBegin)
+                return true;
+            
+            if (m_phase == PlatformWheelEventPhaseNone &amp;&amp; m_momentumPhase == PlatformWheelEventPhaseEnded)
+                return true;
+            
+            return false;
+        }
</ins><span class="cx"> #else
</span><span class="cx">         bool useLatchedEventElement() const { return false; }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.cpp        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (c) 2010, Google Inc. All rights reserved.
</span><del>- * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2008, 2011, 2014 Apple Inc. All Rights Reserved.
</ins><span class="cx">  * 
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions are
</span><span class="lines">@@ -422,6 +422,26 @@
</span><span class="cx">     return IntPoint(totalContentsSize().width() - visibleWidth(), totalContentsSize().height() - visibleHeight());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool ScrollableArea::scrolledToTop() const
+{
+    return scrollPosition().y() &lt;= minimumScrollPosition().y();
+}
+
+bool ScrollableArea::scrolledToBottom() const
+{
+    return scrollPosition().y() &gt;= maximumScrollPosition().y();
+}
+
+bool ScrollableArea::scrolledToLeft() const
+{
+    return scrollPosition().x() &lt;= minimumScrollPosition().x();
+}
+
+bool ScrollableArea::scrolledToRight() const
+{
+    return scrollPosition().x() &gt;= maximumScrollPosition().x();
+}
+
</ins><span class="cx"> IntSize ScrollableArea::totalContentsSize() const
</span><span class="cx"> {
</span><span class="cx">     IntSize totalContentsSize = contentsSize();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.h (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.h        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/platform/ScrollableArea.h        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2008, 2011, 2014 Apple Inc. All Rights Reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -149,6 +149,10 @@
</span><span class="cx">     virtual IntPoint scrollPosition() const;
</span><span class="cx">     virtual IntPoint minimumScrollPosition() const;
</span><span class="cx">     virtual IntPoint maximumScrollPosition() const;
</span><ins>+    virtual bool scrolledToTop() const;
+    virtual bool scrolledToBottom() const;
+    virtual bool scrolledToLeft() const;
+    virtual bool scrolledToRight() const;
</ins><span class="cx"> 
</span><span class="cx">     enum VisibleContentRectIncludesScrollbars { ExcludeScrollbars, IncludeScrollbars };
</span><span class="cx">     enum VisibleContentRectBehavior {
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderListBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderListBox.cpp (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderListBox.cpp        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/rendering/RenderListBox.cpp        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006, 2007, 2008, 2011, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *               2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -831,4 +831,36 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool RenderListBox::scrolledToTop() const
+{
+    Scrollbar* vbar = verticalScrollbar();
+    if (!vbar)
+        return true;
+    
+    return vbar-&gt;value() &lt;= 0;
+}
+
+bool RenderListBox::scrolledToBottom() const
+{
+    Scrollbar* vbar = verticalScrollbar();
+    if (!vbar)
+        return true;
+
+    return vbar-&gt;value() &gt;= vbar-&gt;maximum();
+}
+
+bool RenderListBox::scrolledToLeft() const
+{
+    // We do not scroll horizontally in a select element, so always report
+    // that we are at the full extent of the scroll.
+    return true;
+}
+
+bool RenderListBox::scrolledToRight() const
+{
+    // We do not scroll horizontally in a select element, so always report
+    // that we are at the full extent of the scroll.
+    return true;
+}
+    
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderListBoxh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderListBox.h (163974 => 163975)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderListBox.h        2014-02-12 20:39:24 UTC (rev 163974)
+++ trunk/Source/WebCore/rendering/RenderListBox.h        2014-02-12 20:40:17 UTC (rev 163975)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * This file is part of the select element renderer in WebCore.
</span><span class="cx">  *
</span><del>- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006, 2007, 2009, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx"> 
</span><span class="cx"> class HTMLSelectElement;
</span><span class="cx"> 
</span><del>-class RenderListBox final : public RenderBlockFlow, private ScrollableArea {
</del><ins>+class RenderListBox final : public RenderBlockFlow, public ScrollableArea {
</ins><span class="cx"> public:
</span><span class="cx">     RenderListBox(HTMLSelectElement&amp;, PassRef&lt;RenderStyle&gt;);
</span><span class="cx">     virtual ~RenderListBox();
</span><span class="lines">@@ -59,6 +59,11 @@
</span><span class="cx"> 
</span><span class="cx">     int size() const;
</span><span class="cx"> 
</span><ins>+    virtual bool scrolledToTop() const override;
+    virtual bool scrolledToBottom() const override;
+    virtual bool scrolledToLeft() const override;
+    virtual bool scrolledToRight() const override;
+
</ins><span class="cx"> private:
</span><span class="cx">     void element() const = delete;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>