Diff
Modified: trunk/Source/WebKit2/ChangeLog (191605 => 191606)
--- 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)
@@ -1,3 +1,42 @@
+2015-10-26 Tim Horton <[email protected]>
+
+ 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.
+
2015-10-26 Anders Carlsson <[email protected]>
Pipe custom context menu handling through to the UIDelegate object
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191605 => 191606)
--- 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)
@@ -194,7 +194,6 @@
BOOL _willBecomeFirstResponderAgain;
NSEvent *_mouseDownEvent;
- BOOL _ignoringMouseDraggedEvents;
BOOL _hasSpellCheckerDocumentTag;
NSInteger _spellCheckerDocumentTag;
@@ -1073,7 +1072,7 @@
return;
[self _setMouseDownEvent:event];
- _data->_ignoringMouseDraggedEvents = NO;
+ _data->_impl->setIgnoresMouseDraggedEvents(false);
[self mouseDownInternal:event];
}
@@ -1091,9 +1090,9 @@
{
if (_data->_impl->ignoresNonWheelEvents())
return;
-
- if (_data->_ignoringMouseDraggedEvents)
+ if (_data->_impl->ignoresMouseDraggedEvents())
return;
+
[self mouseDraggedInternal:event];
}
@@ -2110,144 +2109,39 @@
}
#if ENABLE(DRAG_SUPPORT)
-- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
+- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)endPoint operation:(NSDragOperation)operation
{
- 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);
+ _data->_impl->draggedImage(image, NSPointToCGPoint(endPoint), operation);
}
-- (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);
-}
-
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
{
- 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;
+ return _data->_impl->draggingEntered(draggingInfo);
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)draggingInfo
{
- 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();
+ return _data->_impl->draggingUpdated(draggingInfo);
}
- (void)draggingExited:(id <NSDraggingInfo>)draggingInfo
{
- 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();
+ _data->_impl->draggingExited(draggingInfo);
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)draggingInfo
{
- return YES;
+ return _data->_impl->prepareForDragOperation(draggingInfo);
}
-// 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)performDragOperation:(id <NSDraggingInfo>)draggingInfo
{
- 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;
+ return _data->_impl->performDragOperation(draggingInfo);
}
-// 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).
- (NSView *)_hitTest:(NSPoint *)point dragTypes:(NSSet *)types
{
- if ([[self superview] mouse:*point inRect:[self frame]])
- return self;
- return nil;
+ return _data->_impl->hitTestForDragTypes(NSPointToCGPoint(*point), types);
}
#endif // ENABLE(DRAG_SUPPORT)
@@ -2859,10 +2753,9 @@
_data->_page->initializeWebPage();
_data->_mouseDownEvent = nil;
- _data->_ignoringMouseDraggedEvents = NO;
_data->_windowOcclusionDetectionEnabled = YES;
- [self _registerDraggedTypes];
+ _data->_impl->registerDraggedTypes();
self.wantsLayer = YES;
@@ -2877,14 +2770,6 @@
return self;
}
-- (void)_registerDraggedTypes
-{
- NSMutableSet *types = [[NSMutableSet alloc] initWithArray:PasteboardTypes::forEditing()];
- [types addObjectsFromArray:PasteboardTypes::forURL()];
- [self registerForDraggedTypes:[types allObjects]];
- [types release];
-}
-
#if WK_API_ENABLED
- (void)_setThumbnailView:(_WKThumbnailView *)thumbnailView
{
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191605 => 191606)
--- 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)
@@ -217,6 +217,8 @@
bool ignoresNonWheelEvents() const { return m_ignoresNonWheelEvents; }
void setIgnoresAllEvents(bool);
bool ignoresAllEvents() const { return m_ignoresAllEvents; }
+ void setIgnoresMouseDraggedEvents(bool);
+ bool ignoresMouseDraggedEvents() const { return m_ignoresMouseDraggedEvents; }
void accessibilityRegisterUIProcessTokens();
@@ -237,6 +239,17 @@
_WKThumbnailView *thumbnailView() const { return m_thumbnailView; }
#endif // WK_API_ENABLED
+#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
+
private:
WeakPtr<WebViewImpl> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
@@ -313,6 +326,7 @@
bool m_ignoresNonWheelEvents { false };
bool m_ignoresAllEvents { false };
+ bool m_ignoresMouseDraggedEvents { false };
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
RetainPtr<WKImmediateActionController> m_immediateActionController;
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191605 => 191606)
--- 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)
@@ -34,6 +34,7 @@
#import "NativeWebKeyboardEvent.h"
#import "NativeWebMouseEvent.h"
#import "PageClient.h"
+#import "PasteboardTypes.h"
#import "StringUtilities.h"
#import "WKFullScreenWindowController.h"
#import "WKImmediateActionController.h"
@@ -42,15 +43,18 @@
#import "WKWebView.h"
#import "WebEditCommandProxy.h"
#import "WebPageProxy.h"
+#import "WebProcessProxy.h"
#import "_WKThumbnailViewInternal.h"
#import <HIToolbox/CarbonEventsCore.h>
#import <WebCore/AXObjectCache.h>
#import <WebCore/DataDetectorsSPI.h>
#import <WebCore/DictionaryLookup.h>
+#import <WebCore/DragData.h>
#import <WebCore/KeypressCommand.h>
#import <WebCore/LookupSPI.h>
#import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
#import <WebCore/NSWindowSPI.h>
+#import <WebCore/PlatformEventFactoryMac.h>
#import <WebCore/SoftLinking.h>
#import <WebCore/ViewState.h>
#import <WebCore/WebActionDisablingCALayerDelegate.h>
@@ -1451,6 +1455,11 @@
setIgnoresNonWheelEvents(ignoresAllEvents);
}
+void WebViewImpl::setIgnoresMouseDraggedEvents(bool ignoresMouseDraggedEvents)
+{
+ m_ignoresMouseDraggedEvents = ignoresMouseDraggedEvents;
+}
+
void WebViewImpl::accessibilityRegisterUIProcessTokens()
{
// Initialize remote accessibility when the window connection has been established.
@@ -1647,6 +1656,159 @@
}
#endif // WK_API_ENABLED
+#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)
+
} // namespace WebKit
#endif // PLATFORM(MAC)