<!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>[173309] trunk/Source/WebKit/mac</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/173309">173309</a></dd>
<dt>Author</dt> <dd>mjs@apple.com</dd>
<dt>Date</dt> <dd>2014-09-05 01:01:35 -0700 (Fri, 05 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use tracking areas instead of (SPI) mouse moved notifications, and follow flags changes with an event monitor
https://bugs.webkit.org/show_bug.cgi?id=136564

Reviewed by Dan Bernstein.
        
WebKit1 depended on mouse moved event notifications to track mouse
moves, and on being specially called by Safari to track flags
changes. WebKit2 does both these things better - it uses a tracking area
and event monitors. Copy those approaches.

* WebKit.order: Remove reference to obsolete call.
* WebView/WebHTMLView.mm:
(-[WebHTMLViewPrivate dealloc]): No need to deallocate tracking
area, since we now just always have one.
(-[WebHTMLViewPrivate clear]): ditto
(-[WebHTMLView _postFakeMouseMovedEventForFlagsChangedEvent:]):
New method that posts a fake mouse move event in response to
a flags change event, for use by the event monitor.
(+[WebHTMLView _postFlagsChangedEvent:]): Empty this old call,
still kept around for benefit of older Safari.
(-[WebHTMLView _updateMouseoverWithEvent:]): Handle Dashboard's
special mouseover mode (previously handled in a weird way).
(-[WebHTMLView close]): No more need to mess with mouse moved observer.
(-[WebHTMLView viewWillMoveToWindow:]): ditto
(-[WebHTMLView viewDidMoveToWindow]): ditto; but now hook up a flags
changed monitor.
(-[WebHTMLView windowDidBecomeKey:]): No need to handle non-key window
tracking area or mouse moved observer.
(-[WebHTMLView windowDidResignKey:]): ditto
(-[WebHTMLView windowWillOrderOnScreen:]): No need to mess with mouse
moved observer.
(-[WebHTMLView windowWillOrderOffScreen:]): ditto
(-[WebHTMLView mouseMoved:]): Converted from the old mouseMovedNotification:
(-[WebHTMLView setDataSource:]): Change if around body to early return. Hook
up tracking area - we have to do it here, because before this point, the
WebHTMLView does not know its WebView, which is where dashboard settings
live.
(-[WebHTMLView _removeMouseMovedObserverUnconditionally]): Deleted.
(-[WebHTMLView addMouseMovedObserver]): Deleted.
(-[WebHTMLView removeMouseMovedObserver]): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebKitorder">trunk/Source/WebKit/mac/WebKit.order</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebHTMLViewmm">trunk/Source/WebKit/mac/WebView/WebHTMLView.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (173308 => 173309)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-09-05 05:58:56 UTC (rev 173308)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-09-05 08:01:35 UTC (rev 173309)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2014-09-04  Maciej Stachowiak  &lt;mjs@apple.com&gt;
+
+        Use tracking areas instead of (SPI) mouse moved notifications, and follow flags changes with an event monitor
+        https://bugs.webkit.org/show_bug.cgi?id=136564
+
+        Reviewed by Dan Bernstein.
+        
+        WebKit1 depended on mouse moved event notifications to track mouse
+        moves, and on being specially called by Safari to track flags
+        changes. WebKit2 does both these things better - it uses a tracking area
+        and event monitors. Copy those approaches.
+
+        * WebKit.order: Remove reference to obsolete call.
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLViewPrivate dealloc]): No need to deallocate tracking
+        area, since we now just always have one.
+        (-[WebHTMLViewPrivate clear]): ditto
+        (-[WebHTMLView _postFakeMouseMovedEventForFlagsChangedEvent:]):
+        New method that posts a fake mouse move event in response to
+        a flags change event, for use by the event monitor.
+        (+[WebHTMLView _postFlagsChangedEvent:]): Empty this old call,
+        still kept around for benefit of older Safari.
+        (-[WebHTMLView _updateMouseoverWithEvent:]): Handle Dashboard's
+        special mouseover mode (previously handled in a weird way).
+        (-[WebHTMLView close]): No more need to mess with mouse moved observer.
+        (-[WebHTMLView viewWillMoveToWindow:]): ditto
+        (-[WebHTMLView viewDidMoveToWindow]): ditto; but now hook up a flags
+        changed monitor.
+        (-[WebHTMLView windowDidBecomeKey:]): No need to handle non-key window
+        tracking area or mouse moved observer.
+        (-[WebHTMLView windowDidResignKey:]): ditto
+        (-[WebHTMLView windowWillOrderOnScreen:]): No need to mess with mouse
+        moved observer.
+        (-[WebHTMLView windowWillOrderOffScreen:]): ditto
+        (-[WebHTMLView mouseMoved:]): Converted from the old mouseMovedNotification:
+        (-[WebHTMLView setDataSource:]): Change if around body to early return. Hook
+        up tracking area - we have to do it here, because before this point, the
+        WebHTMLView does not know its WebView, which is where dashboard settings
+        live.
+        (-[WebHTMLView _removeMouseMovedObserverUnconditionally]): Deleted.
+        (-[WebHTMLView addMouseMovedObserver]): Deleted.
+        (-[WebHTMLView removeMouseMovedObserver]): Deleted.
+
</ins><span class="cx"> 2014-09-04  Pratik Solanki  &lt;psolanki@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Bring back [WebPreferences setDiskImageCacheEnabled:] for backwards compatibility
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebKitorder"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebKit.order (173308 => 173309)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebKit.order        2014-09-05 05:58:56 UTC (rev 173308)
+++ trunk/Source/WebKit/mac/WebKit.order        2014-09-05 08:01:35 UTC (rev 173309)
</span><span class="lines">@@ -502,7 +502,6 @@
</span><span class="cx"> __ZN20WebDocumentLoaderMacD0Ev
</span><span class="cx"> -[WebView _windowChangedKeyState]
</span><span class="cx"> -[WebHTMLView windowDidBecomeKey:]
</span><del>-_WKMouseMovedNotification
</del><span class="cx"> -[WebHTMLView(WebNSTextInputSupport) _updateSecureInputState]
</span><span class="cx"> -[WebView _windowWillOrderOnScreen:]
</span><span class="cx"> -[WebHTMLView windowWillOrderOnScreen:]
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebHTMLViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (173308 => 173309)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2014-09-05 05:58:56 UTC (rev 173308)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2014-09-05 08:01:35 UTC (rev 173309)
</span><span class="lines">@@ -433,7 +433,7 @@
</span><span class="cx"> - (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;
</span><span class="cx"> - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
</span><span class="cx"> - (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;
</span><del>-- (void)_removeMouseMovedObserverUnconditionally;
</del><ins>+- (void)_postFakeMouseMovedEventForFlagsChangedEvent:(NSEvent *)flagsChangedEvent;
</ins><span class="cx"> - (void)_removeSuperviewObservers;
</span><span class="cx"> - (void)_removeWindowObservers;
</span><span class="cx"> #endif
</span><span class="lines">@@ -543,7 +543,6 @@
</span><span class="cx">     BOOL printing;
</span><span class="cx">     BOOL paginateScreenContent;
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    BOOL observingMouseMovedNotifications;
</del><span class="cx">     BOOL observingSuperviewNotifications;
</span><span class="cx">     BOOL observingWindowNotifications;
</span><span class="cx">     
</span><span class="lines">@@ -614,7 +613,8 @@
</span><span class="cx">     SEL selectorForDoCommandBySelector;
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    NSTrackingArea *trackingAreaForNonKeyWindow;
</del><ins>+    BOOL installedTrackingArea;
+    id flagsChangedEventMonitor;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #ifndef NDEBUG
</span><span class="lines">@@ -694,7 +694,6 @@
</span><span class="cx"> #endif
</span><span class="cx">     [dataSource release];
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    [trackingAreaForNonKeyWindow release];
</del><span class="cx">     if (promisedDragTIFFDataSource)
</span><span class="cx">         promisedDragTIFFDataSource-&gt;removeClient(promisedDataClient());
</span><span class="cx"> #endif
</span><span class="lines">@@ -732,7 +731,6 @@
</span><span class="cx"> #endif
</span><span class="cx">     [dataSource release];
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    [trackingAreaForNonKeyWindow release];
</del><span class="cx">     if (promisedDragTIFFDataSource)
</span><span class="cx">         promisedDragTIFFDataSource-&gt;removeClient(promisedDataClient());
</span><span class="cx"> #endif
</span><span class="lines">@@ -746,7 +744,6 @@
</span><span class="cx"> #endif
</span><span class="cx">     dataSource = nil;
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    trackingAreaForNonKeyWindow = nil;
</del><span class="cx">     promisedDragTIFFDataSource = 0;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -993,6 +990,15 @@
</span><span class="cx">     [webView release];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_postFakeMouseMovedEventForFlagsChangedEvent:(NSEvent *)flagsChangedEvent
+{
+    NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved location:flagsChangedEvent.window.mouseLocationOutsideOfEventStream
+        modifierFlags:flagsChangedEvent.modifierFlags timestamp:flagsChangedEvent.timestamp windowNumber:flagsChangedEvent.windowNumber
+        context:flagsChangedEvent.context eventNumber:0 clickCount:0 pressure:0];
+
+    [self mouseMoved:fakeEvent];
+}
+
</ins><span class="cx"> // This method is needed to support Mac OS X services.
</span><span class="cx"> - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard 
</span><span class="cx"> { 
</span><span class="lines">@@ -1006,15 +1012,6 @@
</span><span class="cx">     return YES; 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)_removeMouseMovedObserverUnconditionally
-{
-    if (!_private || !_private-&gt;observingMouseMovedNotifications)
-        return;
-    
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:WKMouseMovedNotification() object:nil];
-    _private-&gt;observingMouseMovedNotifications = false;
-}
-
</del><span class="cx"> - (void)_removeSuperviewObservers
</span><span class="cx"> {
</span><span class="cx">     if (!_private || !_private-&gt;observingSuperviewNotifications)
</span><span class="lines">@@ -1282,22 +1279,7 @@
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx"> + (void)_postFlagsChangedEvent:(NSEvent *)flagsChangedEvent
</span><span class="cx"> {
</span><del>-    // This is a workaround for: &lt;rdar://problem/2981619&gt; NSResponder_Private should include notification for FlagsChanged
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored &quot;-Wdeprecated-declarations&quot;
-    NSEvent *fakeEvent = [NSEvent mouseEventWithType:NSMouseMoved
-        location:[[flagsChangedEvent window] convertScreenToBase:[NSEvent mouseLocation]]
-        modifierFlags:[flagsChangedEvent modifierFlags]
-        timestamp:[flagsChangedEvent timestamp]
-        windowNumber:[flagsChangedEvent windowNumber]
-        context:[flagsChangedEvent context]
-        eventNumber:0 clickCount:0 pressure:0];
-#pragma clang diagnostic pop
-
-    // Pretend it's a mouse move.
-    [[NSNotificationCenter defaultCenter]
-        postNotificationName:WKMouseMovedNotification() object:self
-        userInfo:[NSDictionary dictionaryWithObject:fakeEvent forKey:@&quot;NSEvent&quot;]];
</del><ins>+    // This is obsolete SPI needed only for older versions of Safari
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (id)_bridge
</span><span class="lines">@@ -1792,9 +1774,15 @@
</span><span class="cx">             // newer when legacy scrollbars are enabled, because then WebKit receives mouse events all the time. 
</span><span class="cx">             // If it is one of those cases where the page is not active and the mouse is not pressed, then we can
</span><span class="cx">             // fire a much more restricted and efficient scrollbars-only version of the event.
</span><del>-            if ([[self window] isKeyWindow] || mouseEventIsPartOfClickOrDrag(event))
</del><ins>+
+            if ([[self window] isKeyWindow] 
+                || mouseEventIsPartOfClickOrDrag(event)
+#if ENABLE(DASHBOARD_SUPPORT)
+                || [[self _webView] _dashboardBehavior:WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows]
+#endif
+                ) {
</ins><span class="cx">                 coreFrame-&gt;eventHandler().mouseMoved(event);
</span><del>-            else
</del><ins>+            } else
</ins><span class="cx">                 coreFrame-&gt;eventHandler().passMouseMovedEventToScrollbars(event);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -2121,7 +2109,6 @@
</span><span class="cx"> 
</span><span class="cx">     [self _clearLastHitViewIfSelf];
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-    [self _removeMouseMovedObserverUnconditionally];
</del><span class="cx">     [self _removeWindowObservers];
</span><span class="cx">     [self _removeSuperviewObservers];
</span><span class="cx"> #endif
</span><span class="lines">@@ -3055,41 +3042,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-- (void)addMouseMovedObserver
-{
-    if (!_private-&gt;dataSource || ![self _isTopHTMLView] || _private-&gt;observingMouseMovedNotifications)
-        return;
-
-    // Unless the Dashboard asks us to do this for all windows, keep an observer going only for the key window.
-    if (!([[self window] isKeyWindow] 
-#if ENABLE(DASHBOARD_SUPPORT)
-            || [[self _webView] _dashboardBehavior:WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows]
-#endif
-        ))
-        return;
-
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mouseMovedNotification:)
-        name:WKMouseMovedNotification() object:nil];
-    [self _frameOrBoundsChanged];
-    _private-&gt;observingMouseMovedNotifications = true;
-}
-
-- (void)removeMouseMovedObserver
-{
-#if ENABLE(DASHBOARD_SUPPORT)
-    // Don't remove the observer if we're running the Dashboard.
-    if ([[self _webView] _dashboardBehavior:WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows])
-        return;
-#endif
-
-    // Legacy scrollbars require tracking the mouse at all times.
-    if (WKRecommendedScrollerStyle() == NSScrollerStyleLegacy)
-        return;
-
-    [[self _webView] _mouseDidMoveOverElement:nil modifierFlags:0];
-    [self _removeMouseMovedObserverUnconditionally];
-}
-
</del><span class="cx"> - (void)addSuperviewObservers
</span><span class="cx"> {
</span><span class="cx">     if (_private-&gt;observingSuperviewNotifications)
</span><span class="lines">@@ -3161,7 +3113,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">     // FIXME: Some of these calls may not work because this view may be already removed from it's superview.
</span><del>-    [self _removeMouseMovedObserverUnconditionally];
</del><span class="cx">     [self _removeWindowObservers];
</span><span class="cx">     [self _removeSuperviewObservers];
</span><span class="cx"> #endif
</span><span class="lines">@@ -3186,7 +3137,6 @@
</span><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx">         [self addWindowObservers];
</span><span class="cx">         [self addSuperviewObservers];
</span><del>-        [self addMouseMovedObserver];
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">         // FIXME: This accomplishes the same thing as the call to setCanStartMedia(true) in
</span><span class="lines">@@ -3194,6 +3144,16 @@
</span><span class="cx">         [[self _pluginController] startAllPlugins];
</span><span class="cx"> 
</span><span class="cx">         _private-&gt;lastScrollPosition = NSZeroPoint;
</span><ins>+
+        if (!_private-&gt;flagsChangedEventMonitor) {
+            _private-&gt;flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
+                [self _postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
+                return flagsChangedEvent;
+            }];
+        }
+    } else {
+        [NSEvent removeMonitor:_private-&gt;flagsChangedEventMonitor];
+        _private-&gt;flagsChangedEventMonitor = nil;
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -3672,18 +3632,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (_private-&gt;trackingAreaForNonKeyWindow) {
-        [self removeTrackingArea:_private-&gt;trackingAreaForNonKeyWindow];
-        [_private-&gt;trackingAreaForNonKeyWindow release];
-        _private-&gt;trackingAreaForNonKeyWindow = nil;
-    }
-
</del><span class="cx">     NSWindow *keyWindow = [notification object];
</span><span class="cx"> 
</span><del>-    if (keyWindow == [self window]) {
-        [self addMouseMovedObserver];
</del><ins>+    if (keyWindow == [self window])
</ins><span class="cx">         [self _updateSecureInputState];
</span><del>-    }
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)windowDidResignKey:(NSNotification *)notification
</span><span class="lines">@@ -3695,24 +3647,10 @@
</span><span class="cx"> 
</span><span class="cx">     NSWindow *formerKeyWindow = [notification object];
</span><span class="cx"> 
</span><del>-    if (formerKeyWindow == [self window])
-        [self removeMouseMovedObserver];
-
</del><span class="cx">     if (formerKeyWindow == [self window] || formerKeyWindow == [[self window] attachedSheet]) {
</span><span class="cx">         [self _updateSecureInputState];
</span><span class="cx">         [_private-&gt;completionController endRevertingChange:NO moveLeft:NO];
</span><span class="cx">     }
</span><del>-
-    if (WKRecommendedScrollerStyle() == NSScrollerStyleLegacy) {
-        // Legacy style scrollbars have design details that rely on tracking the mouse all the time.
-        // It's easiest to do this with a tracking area, which we will remove when the window is key
-        // again.
-        _private-&gt;trackingAreaForNonKeyWindow = [[NSTrackingArea alloc] initWithRect:[self bounds]
-                                                    options:NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways
-                                                    owner:self
-                                                    userInfo:nil];
-        [self addTrackingArea:_private-&gt;trackingAreaForNonKeyWindow];
-    }
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)windowWillOrderOnScreen:(NSNotification *)notification
</span><span class="lines">@@ -3721,10 +3659,6 @@
</span><span class="cx">         [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO];
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-
-    // Check if the window is already a key window, which can be the case for NSPopovers.
-    if ([[self window] isKeyWindow])
-        [self addMouseMovedObserver];
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)windowWillOrderOffScreen:(NSNotification *)notification
</span><span class="lines">@@ -3733,10 +3667,6 @@
</span><span class="cx">         [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO];
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-
-    // When the WebView is in a NSPopover the NSWindowDidResignKeyNotification isn't sent
-    // unless the parent window loses key. So we need to remove the mouse moved observer.
-    [self removeMouseMovedObserver];
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)windowWillClose:(NSNotification *)notification
</span><span class="lines">@@ -4107,9 +4037,9 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if !PLATFORM(IOS)
</span><del>-- (void)mouseMovedNotification:(NSNotification *)notification
</del><ins>+- (void)mouseMoved:(NSEvent *)event
</ins><span class="cx"> {
</span><del>-    [self _updateMouseoverWithEvent:[[notification userInfo] objectForKey:@&quot;NSEvent&quot;]];
</del><ins>+    [self _updateMouseoverWithEvent:event];
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -4267,21 +4197,34 @@
</span><span class="cx"> - (void)setDataSource:(WebDataSource *)dataSource 
</span><span class="cx"> {
</span><span class="cx">     ASSERT(dataSource);
</span><del>-    if (_private-&gt;dataSource != dataSource) {
-        ASSERT(!_private-&gt;closed);
-#if !PLATFORM(IOS)
-        BOOL hadDataSource = _private-&gt;dataSource != nil;
-#endif
</del><ins>+    if (_private-&gt;dataSource == dataSource)
+        return;
</ins><span class="cx"> 
</span><del>-        [dataSource retain];
-        [_private-&gt;dataSource release];
-        _private-&gt;dataSource = dataSource;
-        [_private-&gt;pluginController setDataSource:dataSource];
</del><ins>+    ASSERT(!_private-&gt;closed);
</ins><span class="cx"> 
</span><ins>+    [dataSource retain];
+    [_private-&gt;dataSource release];
+    _private-&gt;dataSource = dataSource;
+    [_private-&gt;pluginController setDataSource:dataSource];
+
</ins><span class="cx"> #if !PLATFORM(IOS)
</span><del>-        if (!hadDataSource)
-            [self addMouseMovedObserver];
</del><ins>+    if (!_private-&gt;installedTrackingArea) {
+        NSTrackingAreaOptions options = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect;
+        if (WKRecommendedScrollerStyle() == NSScrollerStyleLegacy
+#if ENABLE(DASHBOARD_SUPPORT)
+            || [[self _webView] _dashboardBehavior:WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows]
</ins><span class="cx"> #endif
</span><ins>+            )
+            options |= NSTrackingActiveAlways;
+        else
+            options |= NSTrackingActiveInKeyWindow;
+
+        NSTrackingArea *trackingArea = [[NSTrackingArea alloc] 
+            initWithRect:[self frame] options:options owner:self userInfo:nil];
+        [self addTrackingArea:trackingArea];
+        [trackingArea release];
+#endif
+        _private-&gt;installedTrackingArea = YES;
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>