<!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>[163406] 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/163406">163406</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2014-02-04 15:24:00 -0800 (Tue, 04 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add WK2 event handling path for iOS, and make Mac and iOS code more similar
https://bugs.webkit.org/show_bug.cgi?id=128199

Reviewed by Sam Weinig.

EventHandlerIOS need some changes for WebKit2, where we have no native
widget. Merge those changes from EventHandlerMac.

Make a few drive-by changes to match EventHandlerMac behavior.

Clean up EventHandlerMac, removing trailing whitespace and fixing
the odd comment.

* page/ios/EventHandlerIOS.mm:
(WebCore::EventHandler::passWidgetMouseDownEventToWidget):
(WebCore::EventHandler::passMouseDownEventToWidget):
(WebCore::EventHandler::passSubframeEventToSubframe):
(WebCore::EventHandler::passWheelEventToWidget):
(WebCore::EventHandler::mouseDown):
(WebCore::EventHandler::mouseMoved):
(WebCore::frameHasPlatformWidget):
(WebCore::EventHandler::passMousePressEventToSubframe):
(WebCore::EventHandler::passMouseMoveEventToSubframe):
(WebCore::EventHandler::passMouseReleaseEventToSubframe):
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::passWidgetMouseDownEventToWidget):
(WebCore::EventHandler::passMouseDownEventToWidget):
(WebCore::findViewInSubviews):
(WebCore::EventHandler::eventLoopHandleMouseUp):
(WebCore::EventHandler::passWheelEventToWidget):
(WebCore::EventHandler::mouseMoved):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageiosEventHandlerIOSmm">trunk/Source/WebCore/page/ios/EventHandlerIOS.mm</a></li>
<li><a href="#trunkSourceWebCorepagemacEventHandlerMacmm">trunk/Source/WebCore/page/mac/EventHandlerMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163405 => 163406)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-04 23:21:23 UTC (rev 163405)
+++ trunk/Source/WebCore/ChangeLog        2014-02-04 23:24:00 UTC (rev 163406)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2014-02-04  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Add WK2 event handling path for iOS, and make Mac and iOS code more similar
+        https://bugs.webkit.org/show_bug.cgi?id=128199
+
+        Reviewed by Sam Weinig.
+
+        EventHandlerIOS need some changes for WebKit2, where we have no native
+        widget. Merge those changes from EventHandlerMac.
+        
+        Make a few drive-by changes to match EventHandlerMac behavior.
+        
+        Clean up EventHandlerMac, removing trailing whitespace and fixing
+        the odd comment.
+
+        * page/ios/EventHandlerIOS.mm:
+        (WebCore::EventHandler::passWidgetMouseDownEventToWidget):
+        (WebCore::EventHandler::passMouseDownEventToWidget):
+        (WebCore::EventHandler::passSubframeEventToSubframe):
+        (WebCore::EventHandler::passWheelEventToWidget):
+        (WebCore::EventHandler::mouseDown):
+        (WebCore::EventHandler::mouseMoved):
+        (WebCore::frameHasPlatformWidget):
+        (WebCore::EventHandler::passMousePressEventToSubframe):
+        (WebCore::EventHandler::passMouseMoveEventToSubframe):
+        (WebCore::EventHandler::passMouseReleaseEventToSubframe):
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::passWidgetMouseDownEventToWidget):
+        (WebCore::EventHandler::passMouseDownEventToWidget):
+        (WebCore::findViewInSubviews):
+        (WebCore::EventHandler::eventLoopHandleMouseUp):
+        (WebCore::EventHandler::passWheelEventToWidget):
+        (WebCore::EventHandler::mouseMoved):
+
</ins><span class="cx"> 2014-02-04  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [OSX] Limit progress bar's dimensions to ushort
</span></span></pre></div>
<a id="trunkSourceWebCorepageiosEventHandlerIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ios/EventHandlerIOS.mm (163405 => 163406)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ios/EventHandlerIOS.mm        2014-02-04 23:21:23 UTC (rev 163405)
+++ trunk/Source/WebCore/page/ios/EventHandlerIOS.mm        2014-02-04 23:24:00 UTC (rev 163406)
</span><span class="lines">@@ -169,7 +169,7 @@
</span><span class="cx"> bool EventHandler::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&amp; event)
</span><span class="cx"> {
</span><span class="cx">     // Figure out which view to send the event to.
</span><del>-    RenderObject* target = event.targetNode() ? event.targetNode()-&gt;renderer() : nullptr;
</del><ins>+    auto target = event.targetNode() ? event.targetNode()-&gt;renderer() : nullptr;
</ins><span class="cx">     if (!target || !target-&gt;isWidget())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="lines">@@ -216,6 +216,11 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // In WebKit2 we will never have a native widget. Just return early and let the regular event handler machinery take care of
+    // dispatching the event.
+    if (!widget-&gt;platformWidget())
+        return false;
+
</ins><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> 
</span><span class="cx">     NSView *nodeView = widget-&gt;platformWidget();
</span><span class="lines">@@ -251,7 +256,12 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!m_sendingEventToSubview);
</span><span class="cx">     m_sendingEventToSubview = true;
</span><del>-    [view mouseDown:currentEvent()];
</del><ins>+
+    {
+        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
+        [view mouseDown:currentEvent()];
+    }
+
</ins><span class="cx">     m_sendingEventToSubview = false;
</span><span class="cx">     
</span><span class="cx">     if (!wasDeferringLoading)
</span><span class="lines">@@ -353,7 +363,7 @@
</span><span class="cx">             Node* node = event.targetNode();
</span><span class="cx">             if (!node)
</span><span class="cx">                 return false;
</span><del>-            RenderObject* renderer = node-&gt;renderer();
</del><ins>+            auto renderer = node-&gt;renderer();
</ins><span class="cx">             if (!renderer || !renderer-&gt;isWidget())
</span><span class="cx">                 return false;
</span><span class="cx">             Widget* widget = toRenderWidget(renderer)-&gt;widget();
</span><span class="lines">@@ -391,10 +401,18 @@
</span><span class="cx"> {
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> 
</span><ins>+    if (!widget)
+        return false;
+
+    NSView* nodeView = widget-&gt;platformWidget();
+    if (!nodeView) {
+        // WK2 code path. No wheel events on iOS anyway.
+        return false;
+    }
+
</ins><span class="cx">     if (currentEvent().type != WebEventScrollWheel || m_sendingEventToSubview || !widget)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    NSView* nodeView = widget-&gt;platformWidget();
</del><span class="cx">     ASSERT(nodeView);
</span><span class="cx">     ASSERT([nodeView superview]);
</span><span class="cx">     NSView *view = [nodeView hitTest:[[nodeView superview] convertPoint:currentEvent().locationInWindow fromView:nil]];
</span><span class="lines">@@ -421,6 +439,7 @@
</span><span class="cx"> 
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> 
</span><ins>+    // FIXME: Why is this here? EventHandler::handleMousePressEvent() calls it.
</ins><span class="cx">     m_frame.loader().resetMultipleFormSubmissionProtection();
</span><span class="cx"> 
</span><span class="cx">     m_mouseDownView = nil;
</span><span class="lines">@@ -463,25 +482,54 @@
</span><span class="cx">     WKBeginObservingContentChanges(true);
</span><span class="cx">     CurrentEventScope scope(event);
</span><span class="cx">     event.wasHandled = mouseMoved(currentPlatformMouseEvent());
</span><ins>+    
+    // FIXME: Why is this here?
</ins><span class="cx">     m_frame.document()-&gt;updateStyleIfNeeded();
</span><span class="cx">     WKStopObservingContentChanges();
</span><span class="cx"> 
</span><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool frameHasPlatformWidget(const Frame&amp; frame)
+{
+    if (FrameView* frameView = frame.view()) {
+        if (frameView-&gt;platformWidget())
+            return true;
+    }
+
+    return false;
+}
+
</ins><span class="cx"> bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults&amp; mev, Frame* subframe)
</span><span class="cx"> {
</span><del>-    return passSubframeEventToSubframe(mev, subframe);
</del><ins>+    // WebKit1 code path.
+    if (frameHasPlatformWidget(m_frame))
+        return passSubframeEventToSubframe(mev, subframe);
+
+    // WebKit2 code path.
+    subframe-&gt;eventHandler().handleMousePressEvent(mev.event());
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool EventHandler::passMouseMoveEventToSubframe(MouseEventWithHitTestResults&amp; mev, Frame* subframe, HitTestResult* hoveredNode)
</span><span class="cx"> {
</span><del>-    return passSubframeEventToSubframe(mev, subframe, hoveredNode);
</del><ins>+    // WebKit1 code path.
+    if (frameHasPlatformWidget(m_frame))
+        return passSubframeEventToSubframe(mev, subframe, hoveredNode);
+
+    subframe-&gt;eventHandler().handleMouseMoveEvent(mev.event(), hoveredNode);
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&amp; mev, Frame* subframe)
</span><span class="cx"> {
</span><del>-    return passSubframeEventToSubframe(mev, subframe);
</del><ins>+    // WebKit1 code path.
+    if (frameHasPlatformWidget(m_frame))
+        return passSubframeEventToSubframe(mev, subframe);
+
+    // WebKit2 code path.
+    subframe-&gt;eventHandler().handleMouseReleaseEvent(mev.event());
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> unsigned EventHandler::accessKeyModifiers()
</span></span></pre></div>
<a id="trunkSourceWebCorepagemacEventHandlerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (163405 => 163406)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2014-02-04 23:21:23 UTC (rev 163405)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2014-02-04 23:24:00 UTC (rev 163406)
</span><span class="lines">@@ -138,13 +138,13 @@
</span><span class="cx"> bool EventHandler::passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&amp; event)
</span><span class="cx"> {
</span><span class="cx">     // Figure out which view to send the event to.
</span><del>-    auto target = event.targetNode() ? event.targetNode()-&gt;renderer() : 0;
</del><ins>+    auto target = event.targetNode() ? event.targetNode()-&gt;renderer() : nullptr;
</ins><span class="cx">     if (!target || !target-&gt;isWidget())
</span><span class="cx">         return false;
</span><del>-    
-    // Double-click events don't exist in Cocoa. Since passWidgetMouseDownEventToWidget will
</del><ins>+
+    // Double-click events don't exist in Cocoa. Since passWidgetMouseDownEventToWidget() will
</ins><span class="cx">     // just pass currentEvent down to the widget, we don't want to call it for events that
</span><del>-    // don't correspond to Cocoa events.  The mousedown/ups will have already been passed on as
</del><ins>+    // don't correspond to Cocoa events. The mousedown/ups will have already been passed on as
</ins><span class="cx">     // part of the pressed/released handling.
</span><span class="cx">     return passMouseDownEventToWidget(toRenderWidget(target)-&gt;widget());
</span><span class="cx"> }
</span><span class="lines">@@ -176,7 +176,7 @@
</span><span class="cx"> {
</span><span class="cx">     // FIXME: This function always returns true. It should be changed either to return
</span><span class="cx">     // false in some cases or the return value should be removed.
</span><del>-    
</del><ins>+
</ins><span class="cx">     RefPtr&lt;Widget&gt; widget = pWidget;
</span><span class="cx"> 
</span><span class="cx">     if (!widget) {
</span><span class="lines">@@ -184,13 +184,13 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // In WebKit2 we will never have an NSView. Just return early and let the regular event handler machinery take care of
</del><ins>+    // In WebKit2 we will never have a native widget. Just return early and let the regular event handler machinery take care of
</ins><span class="cx">     // dispatching the event.
</span><span class="cx">     if (!widget-&gt;platformWidget())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><del>-    
</del><ins>+
</ins><span class="cx">     NSView *nodeView = widget-&gt;platformWidget();
</span><span class="cx">     ASSERT([nodeView superview]);
</span><span class="cx">     NSView *view = [nodeView hitTest:[[nodeView superview] convertPoint:[currentNSEvent() locationInWindow] fromView:nil]];
</span><span class="lines">@@ -198,7 +198,7 @@
</span><span class="cx">         // We probably hit the border of a RenderWidget
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><del>-    
</del><ins>+
</ins><span class="cx">     Page* page = m_frame.page();
</span><span class="cx">     if (!page)
</span><span class="cx">         return true;
</span><span class="lines">@@ -212,11 +212,11 @@
</span><span class="cx"> 
</span><span class="cx">     // We need to &quot;defer loading&quot; while tracking the mouse, because tearing down the
</span><span class="cx">     // page while an AppKit control is tracking the mouse can cause a crash.
</span><del>-    
</del><ins>+
</ins><span class="cx">     // FIXME: In theory, WebCore now tolerates tear-down while tracking the
</span><span class="cx">     // mouse. We should confirm that, and then remove the deferrsLoading
</span><span class="cx">     // hack entirely.
</span><del>-    
</del><ins>+
</ins><span class="cx">     bool wasDeferringLoading = page-&gt;defersLoading();
</span><span class="cx">     if (!wasDeferringLoading)
</span><span class="cx">         page-&gt;setDefersLoading(true);
</span><span class="lines">@@ -237,7 +237,7 @@
</span><span class="cx">     // Remember which view we sent the event to, so we can direct the release event properly.
</span><span class="cx">     m_mouseDownView = view;
</span><span class="cx">     m_mouseDownWasInSubframe = false;
</span><del>-    
</del><ins>+
</ins><span class="cx">     // Many AppKit widgets run their own event loops and consume events while the mouse is down.
</span><span class="cx">     // When they finish, currentEvent is the mouseUp that they exited on.  We need to update
</span><span class="cx">     // the EventHandler state with this mouseUp, which we never saw.
</span><span class="lines">@@ -250,7 +250,7 @@
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> // Note that this does the same kind of check as [target isDescendantOf:superview].
</span><span class="cx"> // There are two differences: This is a lot slower because it has to walk the whole
</span><span class="cx"> // tree, and this works in cases where the target has already been deallocated.
</span><span class="lines">@@ -265,7 +265,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS;
</span><del>-    
</del><ins>+
</ins><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -307,13 +307,13 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(DRAG_SUPPORT)
</span><del>-    
</del><ins>+
</ins><span class="cx"> bool EventHandler::eventLoopHandleMouseUp(const MouseEventWithHitTestResults&amp;)
</span><span class="cx"> {
</span><span class="cx">     NSView *view = mouseDownViewIfStillGood();
</span><span class="cx">     if (!view)
</span><span class="cx">         return false;
</span><del>-    
</del><ins>+
</ins><span class="cx">     if (!m_mouseDownWasInSubframe) {
</span><span class="cx">         ASSERT(!m_sendingEventToSubview);
</span><span class="cx">         m_sendingEventToSubview = true;
</span><span class="lines">@@ -440,9 +440,10 @@
</span><span class="cx">     ASSERT(nodeView);
</span><span class="cx">     ASSERT([nodeView superview]);
</span><span class="cx">     NSView *view = [nodeView hitTest:[[nodeView superview] convertPoint:[currentNSEvent() locationInWindow] fromView:nil]];
</span><del>-    if (!view)
</del><ins>+    if (!view) {
</ins><span class="cx">         // We probably hit the border of a RenderWidget
</span><span class="cx">         return false;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     ASSERT(!m_sendingEventToSubview);
</span><span class="cx">     m_sendingEventToSubview = true;
</span><span class="lines">@@ -454,7 +455,7 @@
</span><span class="cx">     setNSScrollViewScrollWheelShouldRetainSelf(false);
</span><span class="cx">     m_sendingEventToSubview = false;
</span><span class="cx">     return true;
</span><del>-            
</del><ins>+
</ins><span class="cx">     END_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="lines">@@ -591,7 +592,7 @@
</span><span class="cx">     // These happen because WebKit sometimes has to fake up moved events.
</span><span class="cx">     if (!m_frame.view() || m_mousePressed || m_sendingEventToSubview)
</span><span class="cx">         return;
</span><del>-    
</del><ins>+
</ins><span class="cx">     BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><span class="cx">     CurrentEventScope scope(event);
</span><span class="cx">     mouseMoved(currentPlatformMouseEvent());
</span></span></pre>
</div>
</div>

</body>
</html>