<!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>[191606] trunk/Source/WebKit2</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/191606">191606</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2015-10-26 15:51:57 -0700 (Mon, 26 Oct 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>WKView being inside WKWebView leads to weird API issues
https://bugs.webkit.org/show_bug.cgi?id=150174
Reviewed by Anders Carlsson.
* UIProcess/API/mac/WKView.mm:
(-[WKView mouseDown:]):
(-[WKView mouseDragged:]):
(-[WKView draggedImage:endedAt:operation:]):
(-[WKView draggingEntered:]):
(-[WKView draggingUpdated:]):
(-[WKView draggingExited:]):
(-[WKView prepareForDragOperation:]):
(-[WKView performDragOperation:]):
(-[WKView _hitTest:dragTypes:]):
(-[WKView initWithFrame:processPool:configuration:webView:]):
(-[WKView applicationFlags:]): Deleted.
(maybeCreateSandboxExtensionFromPasteboard): Deleted.
(createSandboxExtensionsForFileUpload): Deleted.
(-[WKView _registerDraggedTypes]): Deleted.
* UIProcess/Cocoa/WebViewImpl.h:
(WebKit::WebViewImpl::ignoresMouseDraggedEvents):
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::setIgnoresMouseDraggedEvents):
(WebKit::WebViewImpl::draggedImage):
(WebKit::applicationFlagsForDrag):
(WebKit::WebViewImpl::draggingEntered):
(WebKit::WebViewImpl::draggingUpdated):
(WebKit::WebViewImpl::draggingExited):
(WebKit::WebViewImpl::prepareForDragOperation):
(WebKit::maybeCreateSandboxExtensionFromPasteboard):
(WebKit::createSandboxExtensionsForFileUpload):
(WebKit::WebViewImpl::performDragOperation):
(WebKit::WebViewImpl::hitTestForDragTypes):
(WebKit::WebViewImpl::registerDraggedTypes):
Move some drag-related things to WebViewImpl.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPImacWKViewmm">trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplh">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebViewImplmm">trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (191605 => 191606)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-10-26 22:49:50 UTC (rev 191605)
+++ trunk/Source/WebKit2/ChangeLog        2015-10-26 22:51:57 UTC (rev 191606)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2015-10-26 Tim Horton <timothy_horton@apple.com>
+
+ WKView being inside WKWebView leads to weird API issues
+ https://bugs.webkit.org/show_bug.cgi?id=150174
+
+ Reviewed by Anders Carlsson.
+
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView mouseDown:]):
+ (-[WKView mouseDragged:]):
+ (-[WKView draggedImage:endedAt:operation:]):
+ (-[WKView draggingEntered:]):
+ (-[WKView draggingUpdated:]):
+ (-[WKView draggingExited:]):
+ (-[WKView prepareForDragOperation:]):
+ (-[WKView performDragOperation:]):
+ (-[WKView _hitTest:dragTypes:]):
+ (-[WKView initWithFrame:processPool:configuration:webView:]):
+ (-[WKView applicationFlags:]): Deleted.
+ (maybeCreateSandboxExtensionFromPasteboard): Deleted.
+ (createSandboxExtensionsForFileUpload): Deleted.
+ (-[WKView _registerDraggedTypes]): Deleted.
+ * UIProcess/Cocoa/WebViewImpl.h:
+ (WebKit::WebViewImpl::ignoresMouseDraggedEvents):
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::setIgnoresMouseDraggedEvents):
+ (WebKit::WebViewImpl::draggedImage):
+ (WebKit::applicationFlagsForDrag):
+ (WebKit::WebViewImpl::draggingEntered):
+ (WebKit::WebViewImpl::draggingUpdated):
+ (WebKit::WebViewImpl::draggingExited):
+ (WebKit::WebViewImpl::prepareForDragOperation):
+ (WebKit::maybeCreateSandboxExtensionFromPasteboard):
+ (WebKit::createSandboxExtensionsForFileUpload):
+ (WebKit::WebViewImpl::performDragOperation):
+ (WebKit::WebViewImpl::hitTestForDragTypes):
+ (WebKit::WebViewImpl::registerDraggedTypes):
+ Move some drag-related things to WebViewImpl.
+
</ins><span class="cx"> 2015-10-26 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Pipe custom context menu handling through to the UIDelegate object
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPImacWKViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191605 => 191606)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2015-10-26 22:49:50 UTC (rev 191605)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2015-10-26 22:51:57 UTC (rev 191606)
</span><span class="lines">@@ -194,7 +194,6 @@
</span><span class="cx">
</span><span class="cx"> BOOL _willBecomeFirstResponderAgain;
</span><span class="cx"> NSEvent *_mouseDownEvent;
</span><del>- BOOL _ignoringMouseDraggedEvents;
</del><span class="cx">
</span><span class="cx"> BOOL _hasSpellCheckerDocumentTag;
</span><span class="cx"> NSInteger _spellCheckerDocumentTag;
</span><span class="lines">@@ -1073,7 +1072,7 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> [self _setMouseDownEvent:event];
</span><del>- _data->_ignoringMouseDraggedEvents = NO;
</del><ins>+ _data->_impl->setIgnoresMouseDraggedEvents(false);
</ins><span class="cx">
</span><span class="cx"> [self mouseDownInternal:event];
</span><span class="cx"> }
</span><span class="lines">@@ -1091,9 +1090,9 @@
</span><span class="cx"> {
</span><span class="cx"> if (_data->_impl->ignoresNonWheelEvents())
</span><span class="cx"> return;
</span><del>-
- if (_data->_ignoringMouseDraggedEvents)
</del><ins>+ if (_data->_impl->ignoresMouseDraggedEvents())
</ins><span class="cx"> return;
</span><ins>+
</ins><span class="cx"> [self mouseDraggedInternal:event];
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -2110,144 +2109,39 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><del>-- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
</del><ins>+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)endPoint operation:(NSDragOperation)operation
</ins><span class="cx"> {
</span><del>- NSPoint windowImageLoc = [[self window] convertScreenToBase:aPoint];
- NSPoint windowMouseLoc = windowImageLoc;
-
- // Prevent queued mouseDragged events from coming after the drag and fake mouseUp event.
- _data->_ignoringMouseDraggedEvents = YES;
-
- _data->_page->dragEnded(IntPoint(windowMouseLoc), globalPoint(windowMouseLoc, [self window]), operation);
</del><ins>+ _data->_impl->draggedImage(image, NSPointToCGPoint(endPoint), operation);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-- (DragApplicationFlags)applicationFlags:(id <NSDraggingInfo>)draggingInfo
-{
- uint32_t flags = 0;
- if ([NSApp modalWindow])
- flags = DragApplicationIsModal;
- if ([[self window] attachedSheet])
- flags |= DragApplicationHasAttachedSheet;
- if ([draggingInfo draggingSource] == self)
- flags |= DragApplicationIsSource;
- if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
- flags |= DragApplicationIsCopyKeyDown;
- return static_cast<DragApplicationFlags>(flags);
-}
-
</del><span class="cx"> - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
</span><span class="cx"> {
</span><del>- IntPoint client([self convertPoint:[draggingInfo draggingLocation] fromView:nil]);
- IntPoint global(globalPoint([draggingInfo draggingLocation], [self window]));
- DragData dragData(draggingInfo, client, global, static_cast<DragOperation>([draggingInfo draggingSourceOperationMask]), [self applicationFlags:draggingInfo]);
-
- _data->_page->resetCurrentDragInformation();
- _data->_page->dragEntered(dragData, [[draggingInfo draggingPasteboard] name]);
- return NSDragOperationCopy;
</del><ins>+ return _data->_impl->draggingEntered(draggingInfo);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)draggingInfo
</span><span class="cx"> {
</span><del>- IntPoint client([self convertPoint:[draggingInfo draggingLocation] fromView:nil]);
- IntPoint global(globalPoint([draggingInfo draggingLocation], [self window]));
- DragData dragData(draggingInfo, client, global, static_cast<DragOperation>([draggingInfo draggingSourceOperationMask]), [self applicationFlags:draggingInfo]);
- _data->_page->dragUpdated(dragData, [[draggingInfo draggingPasteboard] name]);
-
- NSInteger numberOfValidItemsForDrop = _data->_page->currentDragNumberOfFilesToBeAccepted();
- NSDraggingFormation draggingFormation = NSDraggingFormationNone;
- if (_data->_page->currentDragIsOverFileInput() && numberOfValidItemsForDrop > 0)
- draggingFormation = NSDraggingFormationList;
-
- if ([draggingInfo numberOfValidItemsForDrop] != numberOfValidItemsForDrop)
- [draggingInfo setNumberOfValidItemsForDrop:numberOfValidItemsForDrop];
- if ([draggingInfo draggingFormation] != draggingFormation)
- [draggingInfo setDraggingFormation:draggingFormation];
-
- return _data->_page->currentDragOperation();
</del><ins>+ return _data->_impl->draggingUpdated(draggingInfo);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)draggingExited:(id <NSDraggingInfo>)draggingInfo
</span><span class="cx"> {
</span><del>- IntPoint client([self convertPoint:[draggingInfo draggingLocation] fromView:nil]);
- IntPoint global(globalPoint([draggingInfo draggingLocation], [self window]));
- DragData dragData(draggingInfo, client, global, static_cast<DragOperation>([draggingInfo draggingSourceOperationMask]), [self applicationFlags:draggingInfo]);
- _data->_page->dragExited(dragData, [[draggingInfo draggingPasteboard] name]);
- _data->_page->resetCurrentDragInformation();
</del><ins>+ _data->_impl->draggingExited(draggingInfo);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)draggingInfo
</span><span class="cx"> {
</span><del>- return YES;
</del><ins>+ return _data->_impl->prepareForDragOperation(draggingInfo);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// FIXME: This code is more or less copied from Pasteboard::getBestURL.
-// It would be nice to be able to share the code somehow.
-static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard, SandboxExtension::Handle& sandboxExtensionHandle)
-{
- NSArray *types = [pasteboard types];
- if (![types containsObject:NSFilenamesPboardType])
- return false;
-
- NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
- if ([files count] != 1)
- return false;
-
- NSString *file = [files objectAtIndex:0];
- BOOL isDirectory;
- if (![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory])
- return false;
-
- if (isDirectory)
- return false;
-
- SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
- return true;
-}
-
-static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, SandboxExtension::HandleArray& handles)
-{
- NSArray *types = [pasteboard types];
- if (![types containsObject:NSFilenamesPboardType])
- return;
-
- NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
- handles.allocate([files count]);
- for (unsigned i = 0; i < [files count]; i++) {
- NSString *file = [files objectAtIndex:i];
- if (![[NSFileManager defaultManager] fileExistsAtPath:file])
- continue;
- SandboxExtension::Handle handle;
- SandboxExtension::createHandle(file, SandboxExtension::ReadOnly, handles[i]);
- }
-}
-
</del><span class="cx"> - (BOOL)performDragOperation:(id <NSDraggingInfo>)draggingInfo
</span><span class="cx"> {
</span><del>- IntPoint client([self convertPoint:[draggingInfo draggingLocation] fromView:nil]);
- IntPoint global(globalPoint([draggingInfo draggingLocation], [self window]));
- DragData dragData(draggingInfo, client, global, static_cast<DragOperation>([draggingInfo draggingSourceOperationMask]), [self applicationFlags:draggingInfo]);
-
- SandboxExtension::Handle sandboxExtensionHandle;
- bool createdExtension = maybeCreateSandboxExtensionFromPasteboard([draggingInfo draggingPasteboard], sandboxExtensionHandle);
- if (createdExtension)
- _data->_page->process().willAcquireUniversalFileReadSandboxExtension();
-
- SandboxExtension::HandleArray sandboxExtensionForUpload;
- createSandboxExtensionsForFileUpload([draggingInfo draggingPasteboard], sandboxExtensionForUpload);
-
- _data->_page->performDragOperation(dragData, [[draggingInfo draggingPasteboard] name], sandboxExtensionHandle, sandboxExtensionForUpload);
-
- return YES;
</del><ins>+ return _data->_impl->performDragOperation(draggingInfo);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// This code is needed to support drag and drop when the drag types cannot be matched.
-// This is the case for elements that do not place content
-// in the drag pasteboard automatically when the drag start (i.e. dragging a DIV element).
</del><span class="cx"> - (NSView *)_hitTest:(NSPoint *)point dragTypes:(NSSet *)types
</span><span class="cx"> {
</span><del>- if ([[self superview] mouse:*point inRect:[self frame]])
- return self;
- return nil;
</del><ins>+ return _data->_impl->hitTestForDragTypes(NSPointToCGPoint(*point), types);
</ins><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(DRAG_SUPPORT)
</span><span class="cx">
</span><span class="lines">@@ -2859,10 +2753,9 @@
</span><span class="cx"> _data->_page->initializeWebPage();
</span><span class="cx">
</span><span class="cx"> _data->_mouseDownEvent = nil;
</span><del>- _data->_ignoringMouseDraggedEvents = NO;
</del><span class="cx"> _data->_windowOcclusionDetectionEnabled = YES;
</span><span class="cx">
</span><del>- [self _registerDraggedTypes];
</del><ins>+ _data->_impl->registerDraggedTypes();
</ins><span class="cx">
</span><span class="cx"> self.wantsLayer = YES;
</span><span class="cx">
</span><span class="lines">@@ -2877,14 +2770,6 @@
</span><span class="cx"> return self;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (void)_registerDraggedTypes
-{
- NSMutableSet *types = [[NSMutableSet alloc] initWithArray:PasteboardTypes::forEditing()];
- [types addObjectsFromArray:PasteboardTypes::forURL()];
- [self registerForDraggedTypes:[types allObjects]];
- [types release];
-}
-
</del><span class="cx"> #if WK_API_ENABLED
</span><span class="cx"> - (void)_setThumbnailView:(_WKThumbnailView *)thumbnailView
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191605 => 191606)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2015-10-26 22:49:50 UTC (rev 191605)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h        2015-10-26 22:51:57 UTC (rev 191606)
</span><span class="lines">@@ -217,6 +217,8 @@
</span><span class="cx"> bool ignoresNonWheelEvents() const { return m_ignoresNonWheelEvents; }
</span><span class="cx"> void setIgnoresAllEvents(bool);
</span><span class="cx"> bool ignoresAllEvents() const { return m_ignoresAllEvents; }
</span><ins>+ void setIgnoresMouseDraggedEvents(bool);
+ bool ignoresMouseDraggedEvents() const { return m_ignoresMouseDraggedEvents; }
</ins><span class="cx">
</span><span class="cx"> void accessibilityRegisterUIProcessTokens();
</span><span class="cx">
</span><span class="lines">@@ -237,6 +239,17 @@
</span><span class="cx"> _WKThumbnailView *thumbnailView() const { return m_thumbnailView; }
</span><span class="cx"> #endif // WK_API_ENABLED
</span><span class="cx">
</span><ins>+#if ENABLE(DRAG_SUPPORT)
+ void draggedImage(NSImage *, CGPoint endPoint, NSDragOperation);
+ NSDragOperation draggingEntered(id <NSDraggingInfo>);
+ NSDragOperation draggingUpdated(id <NSDraggingInfo>);
+ void draggingExited(id <NSDraggingInfo>);
+ bool prepareForDragOperation(id <NSDraggingInfo>);
+ bool performDragOperation(id <NSDraggingInfo>);
+ NSView *hitTestForDragTypes(CGPoint, NSSet *types);
+ void registerDraggedTypes();
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx"> WeakPtr<WebViewImpl> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
</span><span class="cx">
</span><span class="lines">@@ -313,6 +326,7 @@
</span><span class="cx">
</span><span class="cx"> bool m_ignoresNonWheelEvents { false };
</span><span class="cx"> bool m_ignoresAllEvents { false };
</span><ins>+ bool m_ignoresMouseDraggedEvents { false };
</ins><span class="cx">
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
</span><span class="cx"> RetainPtr<WKImmediateActionController> m_immediateActionController;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebViewImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191605 => 191606)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2015-10-26 22:49:50 UTC (rev 191605)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm        2015-10-26 22:51:57 UTC (rev 191606)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import "NativeWebKeyboardEvent.h"
</span><span class="cx"> #import "NativeWebMouseEvent.h"
</span><span class="cx"> #import "PageClient.h"
</span><ins>+#import "PasteboardTypes.h"
</ins><span class="cx"> #import "StringUtilities.h"
</span><span class="cx"> #import "WKFullScreenWindowController.h"
</span><span class="cx"> #import "WKImmediateActionController.h"
</span><span class="lines">@@ -42,15 +43,18 @@
</span><span class="cx"> #import "WKWebView.h"
</span><span class="cx"> #import "WebEditCommandProxy.h"
</span><span class="cx"> #import "WebPageProxy.h"
</span><ins>+#import "WebProcessProxy.h"
</ins><span class="cx"> #import "_WKThumbnailViewInternal.h"
</span><span class="cx"> #import <HIToolbox/CarbonEventsCore.h>
</span><span class="cx"> #import <WebCore/AXObjectCache.h>
</span><span class="cx"> #import <WebCore/DataDetectorsSPI.h>
</span><span class="cx"> #import <WebCore/DictionaryLookup.h>
</span><ins>+#import <WebCore/DragData.h>
</ins><span class="cx"> #import <WebCore/KeypressCommand.h>
</span><span class="cx"> #import <WebCore/LookupSPI.h>
</span><span class="cx"> #import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
</span><span class="cx"> #import <WebCore/NSWindowSPI.h>
</span><ins>+#import <WebCore/PlatformEventFactoryMac.h>
</ins><span class="cx"> #import <WebCore/SoftLinking.h>
</span><span class="cx"> #import <WebCore/ViewState.h>
</span><span class="cx"> #import <WebCore/WebActionDisablingCALayerDelegate.h>
</span><span class="lines">@@ -1451,6 +1455,11 @@
</span><span class="cx"> setIgnoresNonWheelEvents(ignoresAllEvents);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void WebViewImpl::setIgnoresMouseDraggedEvents(bool ignoresMouseDraggedEvents)
+{
+ m_ignoresMouseDraggedEvents = ignoresMouseDraggedEvents;
+}
+
</ins><span class="cx"> void WebViewImpl::accessibilityRegisterUIProcessTokens()
</span><span class="cx"> {
</span><span class="cx"> // Initialize remote accessibility when the window connection has been established.
</span><span class="lines">@@ -1647,6 +1656,159 @@
</span><span class="cx"> }
</span><span class="cx"> #endif // WK_API_ENABLED
</span><span class="cx">
</span><ins>+#if ENABLE(DRAG_SUPPORT)
+void WebViewImpl::draggedImage(NSImage *image, CGPoint endPoint, NSDragOperation operation)
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ NSPoint windowImageLoc = [m_view.window convertScreenToBase:NSPointFromCGPoint(endPoint)];
+#pragma clang diagnostic pop
+ NSPoint windowMouseLoc = windowImageLoc;
+
+ // Prevent queued mouseDragged events from coming after the drag and fake mouseUp event.
+ m_ignoresMouseDraggedEvents = true;
+
+ m_page.dragEnded(WebCore::IntPoint(windowMouseLoc), WebCore::globalPoint(windowMouseLoc, m_view.window), operation);
+}
+
+static WebCore::DragApplicationFlags applicationFlagsForDrag(NSView *view, id <NSDraggingInfo> draggingInfo)
+{
+ uint32_t flags = 0;
+ if ([NSApp modalWindow])
+ flags = WebCore::DragApplicationIsModal;
+ if (view.window.attachedSheet)
+ flags |= WebCore::DragApplicationHasAttachedSheet;
+ if (draggingInfo.draggingSource == view)
+ flags |= WebCore::DragApplicationIsSource;
+ if ([NSApp currentEvent].modifierFlags & NSAlternateKeyMask)
+ flags |= WebCore::DragApplicationIsCopyKeyDown;
+ return static_cast<WebCore::DragApplicationFlags>(flags);
+
+}
+
+NSDragOperation WebViewImpl::draggingEntered(id <NSDraggingInfo> draggingInfo)
+{
+ WebCore::IntPoint client([m_view convertPoint:draggingInfo.draggingLocation fromView:nil]);
+ WebCore::IntPoint global(WebCore::globalPoint(draggingInfo.draggingLocation, m_view.window));
+ WebCore::DragData dragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view, draggingInfo));
+
+ m_page.resetCurrentDragInformation();
+ m_page.dragEntered(dragData, draggingInfo.draggingPasteboard.name);
+ return NSDragOperationCopy;
+}
+
+NSDragOperation WebViewImpl::draggingUpdated(id <NSDraggingInfo> draggingInfo)
+{
+ WebCore::IntPoint client([m_view convertPoint:draggingInfo.draggingLocation fromView:nil]);
+ WebCore::IntPoint global(WebCore::globalPoint(draggingInfo.draggingLocation, m_view.window));
+ WebCore::DragData dragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view, draggingInfo));
+ m_page.dragUpdated(dragData, draggingInfo.draggingPasteboard.name);
+
+ NSInteger numberOfValidItemsForDrop = m_page.currentDragNumberOfFilesToBeAccepted();
+ NSDraggingFormation draggingFormation = NSDraggingFormationNone;
+ if (m_page.currentDragIsOverFileInput() && numberOfValidItemsForDrop > 0)
+ draggingFormation = NSDraggingFormationList;
+
+ if (draggingInfo.numberOfValidItemsForDrop != numberOfValidItemsForDrop)
+ [draggingInfo setNumberOfValidItemsForDrop:numberOfValidItemsForDrop];
+ if (draggingInfo.draggingFormation != draggingFormation)
+ [draggingInfo setDraggingFormation:draggingFormation];
+
+ return m_page.currentDragOperation();
+}
+
+void WebViewImpl::draggingExited(id <NSDraggingInfo> draggingInfo)
+{
+ WebCore::IntPoint client([m_view convertPoint:draggingInfo.draggingLocation fromView:nil]);
+ WebCore::IntPoint global(WebCore::globalPoint(draggingInfo.draggingLocation, m_view.window));
+ WebCore::DragData dragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view, draggingInfo));
+ m_page.dragExited(dragData, draggingInfo.draggingPasteboard.name);
+ m_page.resetCurrentDragInformation();
+}
+
+bool WebViewImpl::prepareForDragOperation(id <NSDraggingInfo>)
+{
+ return true;
+}
+
+// FIXME: This code is more or less copied from Pasteboard::getBestURL.
+// It would be nice to be able to share the code somehow.
+static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard, SandboxExtension::Handle& sandboxExtensionHandle)
+{
+ NSArray *types = pasteboard.types;
+ if (![types containsObject:NSFilenamesPboardType])
+ return false;
+
+ NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
+ if (files.count != 1)
+ return false;
+
+ NSString *file = [files objectAtIndex:0];
+ BOOL isDirectory;
+ if (![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory])
+ return false;
+
+ if (isDirectory)
+ return false;
+
+ SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
+ return true;
+}
+
+static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, SandboxExtension::HandleArray& handles)
+{
+ NSArray *types = pasteboard.types;
+ if (![types containsObject:NSFilenamesPboardType])
+ return;
+
+ NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
+ handles.allocate(files.count);
+ for (unsigned i = 0; i < files.count; i++) {
+ NSString *file = [files objectAtIndex:i];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:file])
+ continue;
+ SandboxExtension::Handle handle;
+ SandboxExtension::createHandle(file, SandboxExtension::ReadOnly, handles[i]);
+ }
+}
+
+bool WebViewImpl::performDragOperation(id <NSDraggingInfo> draggingInfo)
+{
+ WebCore::IntPoint client([m_view convertPoint:draggingInfo.draggingLocation fromView:nil]);
+ WebCore::IntPoint global(WebCore::globalPoint(draggingInfo.draggingLocation, m_view.window));
+ WebCore::DragData dragData(draggingInfo, client, global, static_cast<WebCore::DragOperation>(draggingInfo.draggingSourceOperationMask), applicationFlagsForDrag(m_view, draggingInfo));
+
+ SandboxExtension::Handle sandboxExtensionHandle;
+ bool createdExtension = maybeCreateSandboxExtensionFromPasteboard(draggingInfo.draggingPasteboard, sandboxExtensionHandle);
+ if (createdExtension)
+ m_page.process().willAcquireUniversalFileReadSandboxExtension();
+
+ SandboxExtension::HandleArray sandboxExtensionForUpload;
+ createSandboxExtensionsForFileUpload(draggingInfo.draggingPasteboard, sandboxExtensionForUpload);
+
+ m_page.performDragOperation(dragData, draggingInfo.draggingPasteboard.name, sandboxExtensionHandle, sandboxExtensionForUpload);
+
+ return true;
+}
+
+NSView *WebViewImpl::hitTestForDragTypes(CGPoint point, NSSet *types)
+{
+ // This code is needed to support drag and drop when the drag types cannot be matched.
+ // This is the case for elements that do not place content
+ // in the drag pasteboard automatically when the drag start (i.e. dragging a DIV element).
+ if ([[m_view superview] mouse:NSPointFromCGPoint(point) inRect:[m_view frame]])
+ return m_view;
+ return nil;
+}
+
+void WebViewImpl::registerDraggedTypes()
+{
+ auto types = adoptNS([[NSMutableSet alloc] initWithArray:PasteboardTypes::forEditing()]);
+ [types addObjectsFromArray:PasteboardTypes::forURL()];
+ [m_view registerForDraggedTypes:[types allObjects]];
+}
+#endif // ENABLE(DRAG_SUPPORT)
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx">
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre>
</div>
</div>
</body>
</html>