Diff
Modified: trunk/Source/WebKit2/ChangeLog (191647 => 191648)
--- trunk/Source/WebKit2/ChangeLog 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/ChangeLog 2015-10-28 00:44:51 UTC (rev 191648)
@@ -1,3 +1,63 @@
+2015-10-27 Tim Horton <timothy_hor...@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 mouseUp:]):
+ (-[WKView acceptsFirstMouse:]):
+ (-[WKView shouldDelayWindowOrderingForEvent:]):
+ (-[WKView pasteboardChangedOwner:]):
+ (-[WKView pasteboard:provideDataForType:]):
+ (-[WKView namesOfPromisedFilesDroppedAtDestination:]):
+ (-[WKView _startWindowDrag]):
+ (-[WKView _setMouseDownEvent:]): Deleted.
+ (-[WKView _colorSpace]): Deleted.
+ (-[WKView _dragImageForView:withImage:at:linkDrag:]): Deleted.
+ (matchesExtensionOrEquivalent): Deleted.
+ (-[WKView _setFileAndURLTypes:withExtension:withTitle:withURL:withVisibleURL:forPasteboard:]): Deleted.
+ (-[WKView _setPromisedDataForImage:withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:forPasteboard:]): Deleted.
+ (-[WKView _setPromisedDataForAttachment:withExtension:withTitle:withURL:withVisibleURL:forPasteboard:]): Deleted.
+ (fileExists): Deleted.
+ (pathWithUniqueFilenameForPath): Deleted.
+ (-[WKView spellCheckerDocumentTag]): Deleted.
+ (-[WKView handleAcceptedAlternativeText:]): Deleted.
+ (-[WKView initWithFrame:processPool:configuration:webView:]): Deleted.
+ * UIProcess/API/mac/WKViewInternal.h:
+ * UIProcess/Cocoa/WebViewImpl.h:
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::handleAcceptedAlternativeText):
+ (WebKit::WebViewImpl::spellCheckerDocumentTag):
+ (WebKit::WebViewImpl::startWindowDrag):
+ (WebKit::WebViewImpl::dragImageForView):
+ (WebKit::matchesExtensionOrEquivalent):
+ (WebKit::WebViewImpl::setFileAndURLTypes):
+ (WebKit::WebViewImpl::setPromisedDataForImage):
+ (WebKit::WebViewImpl::setPromisedDataForAttachment):
+ (WebKit::WebViewImpl::pasteboardChangedOwner):
+ (WebKit::WebViewImpl::provideDataForPasteboard):
+ (WebKit::fileExists):
+ (WebKit::pathWithUniqueFilenameForPath):
+ (WebKit::WebViewImpl::namesOfPromisedFilesDroppedAtDestination):
+ (WebKit::WebViewImpl::setLastMouseDownEvent):
+ * UIProcess/mac/CorrectionPanel.h:
+ * UIProcess/mac/CorrectionPanel.mm:
+ (WebKit::CorrectionPanel::show):
+ (WebKit::CorrectionPanel::recordAutocorrectionResponse):
+ (WebKit::CorrectionPanel::handleAcceptedReplacement):
+ * UIProcess/mac/PageClientImpl.mm:
+ (WebKit::PageClientImpl::colorSpace):
+ (WebKit::PageClientImpl::setDragImage):
+ (WebKit::PageClientImpl::setPromisedDataForImage):
+ (WebKit::PageClientImpl::setPromisedDataForAttachment):
+ (WebKit::PageClientImpl::showCorrectionPanel):
+ (WebKit::PageClientImpl::recordAutocorrectionResponse):
+ (WebKit::PageClientImpl::showDictationAlternativeUI):
+ Move some pasteboard and spellcheck code.
+
2015-10-27 Wenson Hsieh <wenson_hs...@apple.com>
Implement viewport-width-based fast-click heuristic
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-10-28 00:44:51 UTC (rev 191648)
@@ -176,15 +176,7 @@
#endif
BOOL _willBecomeFirstResponderAgain;
- NSEvent *_mouseDownEvent;
- BOOL _hasSpellCheckerDocumentTag;
- NSInteger _spellCheckerDocumentTag;
-
- RefPtr<WebCore::Image> _promisedImage;
- String _promisedFilename;
- String _promisedURL;
-
BOOL _windowOcclusionDetectionEnabled;
CGFloat _totalHeightOfBanners;
@@ -896,17 +888,6 @@
return YES;
}
-- (void)_setMouseDownEvent:(NSEvent *)event
-{
- ASSERT(!event || [event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown);
-
- if (event == _data->_mouseDownEvent)
- return;
-
- [_data->_mouseDownEvent release];
- _data->_mouseDownEvent = [event retain];
-}
-
#if USE(ASYNC_NSTEXTINPUTCLIENT)
#define NATIVE_MOUSE_EVENT_HANDLER(Selector) \
- (void)Selector:(NSEvent *)theEvent \
@@ -1016,7 +997,7 @@
if (_data->_impl->ignoresNonWheelEvents())
return;
- [self _setMouseDownEvent:event];
+ _data->_impl->setLastMouseDownEvent(event);
_data->_impl->setIgnoresMouseDraggedEvents(false);
[self mouseDownInternal:event];
@@ -1027,7 +1008,7 @@
if (_data->_impl->ignoresNonWheelEvents())
return;
- [self _setMouseDownEvent:nil];
+ _data->_impl->setLastMouseDownEvent(nil);
[self mouseUpInternal:event];
}
@@ -1056,9 +1037,9 @@
if (![self hitTest:[event locationInWindow]])
return NO;
- [self _setMouseDownEvent:event];
+ _data->_impl->setLastMouseDownEvent(event);
bool result = _data->_page->acceptsFirstMouse([event eventNumber], WebEventFactory::createWebMouseEvent(event, _data->_impl->lastPressureEvent(), self));
- [self _setMouseDownEvent:nil];
+ _data->_impl->setLastMouseDownEvent(nil);
return result;
}
@@ -1077,9 +1058,9 @@
if (![self hitTest:[event locationInWindow]])
return NO;
- [self _setMouseDownEvent:event];
+ _data->_impl->setLastMouseDownEvent(event);
bool result = _data->_page->shouldDelayWindowOrderingForEvent(WebEventFactory::createWebMouseEvent(event, _data->_impl->lastPressureEvent(), self));
- [self _setMouseDownEvent:nil];
+ _data->_impl->setLastMouseDownEvent(nil);
return result;
}
@@ -2220,11 +2201,6 @@
return std::make_unique<TiledCoreAnimationDrawingAreaProxy>(*_data->_page);
}
-- (WebKit::ColorSpaceData)_colorSpace
-{
- return _data->_impl->colorSpace();
-}
-
- (void)_processDidExit
{
_data->_impl->notifyInputContextAboutDiscardedComposition();
@@ -2332,161 +2308,19 @@
return _data->_impl->stringForToolTip(tag);
}
-- (void)_dragImageForView:(NSView *)view withImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag
-{
- // The call below could release this WKView.
- RetainPtr<WKView> protector(self);
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- [view dragImage:image
- at:clientPoint
- offset:NSZeroSize
- event:(linkDrag) ? [NSApp currentEvent] : _data->_mouseDownEvent
- pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
- source:self
- slideBack:YES];
-#pragma clang diagnostic pop
-}
-
-static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension)
-{
- NSString *extensionAsSuffix = [@"." stringByAppendingString:extension];
- return hasCaseInsensitiveSuffix(filename, extensionAsSuffix) || (stringIsCaseInsensitiveEqualToString(extension, @"jpeg")
- && hasCaseInsensitiveSuffix(filename, @".jpg"));
-}
-
-- (void)_setFileAndURLTypes:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSPasteboard *)pasteboard
-{
- if (!matchesExtensionOrEquivalent(filename, extension))
- filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension];
-
- [pasteboard setString:visibleUrl forType:NSStringPboardType];
- [pasteboard setString:visibleUrl forType:PasteboardTypes::WebURLPboardType];
- [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType];
- [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:visibleUrl], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType];
- [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
- _data->_promisedFilename = filename;
- _data->_promisedURL = url;
-}
-
-- (void)_setPromisedDataForImage:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName
-
-{
- NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
- RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
-
- [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
- [pasteboard declareTypes:types.get() owner:self];
- [self _setFileAndURLTypes:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboard];
-
- if (archiveBuffer)
- [pasteboard setData:archiveBuffer->createNSData().get() forType:PasteboardTypes::WebArchivePboardType];
-
- _data->_promisedImage = image;
-}
-
-#if ENABLE(ATTACHMENT_ELEMENT)
-- (void)_setPromisedDataForAttachment:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSString *)pasteboardName
-
-{
- NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
- RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
- [types addObjectsFromArray:PasteboardTypes::forURL()];
- [pasteboard declareTypes:types.get() owner:self];
- [self _setFileAndURLTypes:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboard];
-
- RetainPtr<NSMutableArray> paths = adoptNS([[NSMutableArray alloc] init]);
- [paths addObject:title];
- [pasteboard setPropertyList:paths.get() forType:NSFilenamesPboardType];
-
- _data->_promisedImage = nullptr;
-}
-#endif
-
- (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
{
- _data->_promisedImage = nullptr;
- _data->_promisedFilename = "";
- _data->_promisedURL = "";
+ _data->_impl->pasteboardChangedOwner(pasteboard);
}
- (void)pasteboard:(NSPasteboard *)pasteboard provideDataForType:(NSString *)type
{
- // FIXME: need to support NSRTFDPboardType
-
- if ([type isEqual:NSTIFFPboardType] && _data->_promisedImage) {
- [pasteboard setData:(NSData *)_data->_promisedImage->getTIFFRepresentation() forType:NSTIFFPboardType];
- _data->_promisedImage = nullptr;
- }
+ _data->_impl->provideDataForPasteboard(pasteboard, type);
}
-static BOOL fileExists(NSString *path)
-{
- struct stat statBuffer;
- return !lstat([path fileSystemRepresentation], &statBuffer);
-}
-
-static NSString *pathWithUniqueFilenameForPath(NSString *path)
-{
- // "Fix" the filename of the path.
- NSString *filename = filenameByFixingIllegalCharacters([path lastPathComponent]);
- path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
-
- if (fileExists(path)) {
- // Don't overwrite existing file by appending "-n", "-n.ext" or "-n.ext.ext" to the filename.
- NSString *extensions = nil;
- NSString *pathWithoutExtensions;
- NSString *lastPathComponent = [path lastPathComponent];
- NSRange periodRange = [lastPathComponent rangeOfString:@"."];
-
- if (periodRange.location == NSNotFound) {
- pathWithoutExtensions = path;
- } else {
- extensions = [lastPathComponent substringFromIndex:periodRange.location + 1];
- lastPathComponent = [lastPathComponent substringToIndex:periodRange.location];
- pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
- }
-
- for (unsigned i = 1; ; i++) {
- NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
- path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber;
- if (!fileExists(path))
- break;
- }
- }
-
- return path;
-}
-
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
{
- RetainPtr<NSFileWrapper> wrapper;
- RetainPtr<NSData> data;
-
- if (_data->_promisedImage) {
- data = ""
- wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
- } else
- wrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL URLWithString:_data->_promisedURL] options:NSFileWrapperReadingImmediate error:nil]);
-
- if (wrapper)
- [wrapper setPreferredFilename:_data->_promisedFilename];
- else {
- LOG_ERROR("Failed to create image file.");
- return nil;
- }
-
- // FIXME: Report an error if we fail to create a file.
- NSString *path = [[dropDestination path] stringByAppendingPathComponent:[wrapper preferredFilename]];
- path = pathWithUniqueFilenameForPath(path);
- if (![wrapper writeToURL:[NSURL fileURLWithPath:path] options:NSFileWrapperWritingWithNameUpdating originalContentsURL:nil error:nullptr])
- LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToURL:options:originalContentsURL:error:]");
-
- if (!_data->_promisedURL.isEmpty())
- WebCore::setMetadataURL(_data->_promisedURL, "", String(path));
-
- return [NSArray arrayWithObject:[path lastPathComponent]];
+ return _data->_impl->namesOfPromisedFilesDroppedAtDestination(dropDestination);
}
- (bool)_executeSavedCommandBySelector:(SEL)selector
@@ -2500,20 +2334,6 @@
return ![sink didReceiveUnhandledCommand];
}
-- (NSInteger)spellCheckerDocumentTag
-{
- if (!_data->_hasSpellCheckerDocumentTag) {
- _data->_spellCheckerDocumentTag = [NSSpellChecker uniqueSpellDocumentTag];
- _data->_hasSpellCheckerDocumentTag = YES;
- }
- return _data->_spellCheckerDocumentTag;
-}
-
-- (void)handleAcceptedAlternativeText:(NSString*)text
-{
- _data->_page->handleAlternativeTextUIResult(text);
-}
-
- (instancetype)initWithFrame:(NSRect)frame processPool:(WebProcessPool&)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView
{
self = [super initWithFrame:frame];
@@ -2536,7 +2356,6 @@
_data->_page->initializeWebPage();
- _data->_mouseDownEvent = nil;
_data->_windowOcclusionDetectionEnabled = YES;
_data->_impl->registerDraggedTypes();
@@ -2583,7 +2402,7 @@
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
- (void)_startWindowDrag
{
- [[self window] performWindowDragWithEvent:_data->_mouseDownEvent];
+ _data->_impl->startWindowDrag();
}
#endif
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2015-10-28 00:44:51 UTC (rev 191648)
@@ -37,19 +37,9 @@
class PageConfiguration;
}
-namespace IPC {
-class DataReference;
-}
-
-namespace WebCore {
-class Image;
-class SharedBuffer;
-}
-
namespace WebKit {
class DrawingAreaProxy;
class WebProcessPool;
-struct ColorSpaceData;
}
@class WKWebView;
@@ -72,17 +62,6 @@
- (NSRect)_convertToDeviceSpace:(NSRect)rect;
- (NSRect)_convertToUserSpace:(NSRect)rect;
-- (void)_dragImageForView:(NSView *)view withImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag;
-- (void)_setPromisedDataForImage:(WebCore::Image *)image withFileName:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl withArchive:(WebCore::SharedBuffer*) archiveBuffer forPasteboard:(NSString *)pasteboardName;
-#if ENABLE(ATTACHMENT_ELEMENT)
-- (void)_setPromisedDataForAttachment:(NSString *)filename withExtension:(NSString *)extension withTitle:(NSString *)title withURL:(NSString *)url withVisibleURL:(NSString *)visibleUrl forPasteboard:(NSString *)pasteboardName;
-#endif
-
-- (WebKit::ColorSpaceData)_colorSpace;
-
-- (NSInteger)spellCheckerDocumentTag;
-- (void)handleAcceptedAlternativeText:(NSString*)text;
-
#if WK_API_ENABLED
@property (nonatomic, setter=_setThumbnailView:) _WKThumbnailView *_thumbnailView;
#endif
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2015-10-28 00:44:51 UTC (rev 191648)
@@ -176,6 +176,9 @@
bool tryPostProcessPluginComplexTextInputKeyDown(NSEvent *);
PluginComplexTextInputState pluginComplexTextInputState() const { return m_pluginComplexTextInputState; }
uint64_t pluginComplexTextInputIdentifier() const { return m_pluginComplexTextInputIdentifier; }
+
+ void handleAcceptedAlternativeText(const String&);
+ NSInteger spellCheckerDocumentTag();
void pressureChangeWithEvent(NSEvent *);
NSEvent *lastPressureEvent() { return m_lastPressureEvent.get(); }
@@ -266,6 +269,20 @@
void registerDraggedTypes();
#endif
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+ void startWindowDrag();
+#endif
+
+ void dragImageForView(NSView *, NSImage *, CGPoint clientPoint, bool linkDrag);
+ void setFileAndURLTypes(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSPasteboard *);
+ void setPromisedDataForImage(WebCore::Image*, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName);
+#if ENABLE(ATTACHMENT_ELEMENT)
+ void setPromisedDataForAttachment(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSString *pasteboardName);
+#endif
+ void pasteboardChangedOwner(NSPasteboard *);
+ void provideDataForPasteboard(NSPasteboard *, NSString *type);
+ NSArray *namesOfPromisedFilesDroppedAtDestination(NSURL *dropDestination);
+
RefPtr<ViewSnapshot> takeViewSnapshot();
ViewGestureController* gestureController() { return m_gestureController.get(); }
@@ -290,6 +307,8 @@
void rotateWithEvent(NSEvent *);
void smartMagnifyWithEvent(NSEvent *);
+ void setLastMouseDownEvent(NSEvent *);
+
void gestureEventWasNotHandledByWebCore(NSEvent *);
void gestureEventWasNotHandledByWebCoreFromViewOnly(NSEvent *);
@@ -365,6 +384,7 @@
RetainPtr<NSColorSpace> m_colorSpace;
+ RetainPtr<NSEvent> m_lastMouseDownEvent;
RetainPtr<NSEvent> m_lastPressureEvent;
bool m_ignoresNonWheelEvents { false };
@@ -397,6 +417,12 @@
bool m_allowsMagnification { false };
RetainPtr<id> m_remoteAccessibilityChild;
+
+ RefPtr<WebCore::Image> m_promisedImage;
+ String m_promisedFilename;
+ String m_promisedURL;
+
+ WTF::Optional<NSInteger> m_spellCheckerDocumentTag;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2015-10-28 00:44:51 UTC (rev 191648)
@@ -65,6 +65,7 @@
#import <WebCore/WebCoreCALayerExtras.h>
#import <WebCore/WebCoreFullScreenPlaceholderView.h>
#import <WebCore/WebCoreFullScreenWindow.h>
+#import <WebCore/WebCoreNSStringExtras.h>
#import <WebKitSystemInterface.h>
SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
@@ -1168,6 +1169,19 @@
return handlePluginComplexTextInputKeyDown(event);
}
+void WebViewImpl::handleAcceptedAlternativeText(const String& acceptedAlternative)
+{
+ m_page.handleAlternativeTextUIResult(acceptedAlternative);
+}
+
+
+NSInteger WebViewImpl::spellCheckerDocumentTag()
+{
+ if (!m_spellCheckerDocumentTag)
+ m_spellCheckerDocumentTag = [NSSpellChecker uniqueSpellDocumentTag];
+ return m_spellCheckerDocumentTag.value();
+}
+
void WebViewImpl::pressureChangeWithEvent(NSEvent *event)
{
#if defined(__LP64__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101003
@@ -1904,6 +1918,168 @@
}
#endif // ENABLE(DRAG_SUPPORT)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+void WebViewImpl::startWindowDrag()
+{
+ [m_view.window performWindowDragWithEvent:m_lastMouseDownEvent.get()];
+}
+#endif
+
+void WebViewImpl::dragImageForView(NSView *view, NSImage *image, CGPoint clientPoint, bool linkDrag)
+{
+ // The call below could release the view.
+ RetainPtr<NSView> protector(m_view);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ [view dragImage:image
+ at:clientPoint
+ offset:NSZeroSize
+ event:linkDrag ? [NSApp currentEvent] : m_lastMouseDownEvent.get()
+ pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
+ source:m_view
+ slideBack:YES];
+#pragma clang diagnostic pop
+}
+
+static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension)
+{
+ NSString *extensionAsSuffix = [@"." stringByAppendingString:extension];
+ return hasCaseInsensitiveSuffix(filename, extensionAsSuffix) || (stringIsCaseInsensitiveEqualToString(extension, @"jpeg")
+ && hasCaseInsensitiveSuffix(filename, @".jpg"));
+}
+
+void WebViewImpl::setFileAndURLTypes(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSPasteboard *pasteboard)
+{
+ if (!matchesExtensionOrEquivalent(filename, extension))
+ filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension];
+
+ [pasteboard setString:visibleURL forType:NSStringPboardType];
+ [pasteboard setString:visibleURL forType:PasteboardTypes::WebURLPboardType];
+ [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType];
+ [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:visibleURL], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType];
+ [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
+ m_promisedFilename = filename;
+ m_promisedURL = url;
+}
+
+void WebViewImpl::setPromisedDataForImage(WebCore::Image* image, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName)
+{
+ NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
+ RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
+
+ [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
+ [pasteboard declareTypes:types.get() owner:m_view];
+ setFileAndURLTypes(filename, extension, title, url, visibleURL, pasteboard);
+
+ if (archiveBuffer)
+ [pasteboard setData:archiveBuffer->createNSData().get() forType:PasteboardTypes::WebArchivePboardType];
+
+ m_promisedImage = image;
+}
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+void WebViewImpl::setPromisedDataForAttachment(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSString *pasteboardName)
+{
+ NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
+ RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil]);
+ [types addObjectsFromArray:PasteboardTypes::forURL()];
+ [pasteboard declareTypes:types.get() owner:m_view];
+ setFileAndURLTypes(filename, extension, title, url, visibleURL, pasteboard);
+
+ RetainPtr<NSMutableArray> paths = adoptNS([[NSMutableArray alloc] init]);
+ [paths addObject:title];
+ [pasteboard setPropertyList:paths.get() forType:NSFilenamesPboardType];
+
+ m_promisedImage = nullptr;
+}
+#endif
+
+void WebViewImpl::pasteboardChangedOwner(NSPasteboard *pasteboard)
+{
+ m_promisedImage = nullptr;
+ m_promisedFilename = "";
+ m_promisedURL = "";
+}
+
+void WebViewImpl::provideDataForPasteboard(NSPasteboard *pasteboard, NSString *type)
+{
+ // FIXME: need to support NSRTFDPboardType
+
+ if ([type isEqual:NSTIFFPboardType] && m_promisedImage) {
+ [pasteboard setData:(NSData *)m_promisedImage->getTIFFRepresentation() forType:NSTIFFPboardType];
+ m_promisedImage = nullptr;
+ }
+}
+
+static BOOL fileExists(NSString *path)
+{
+ struct stat statBuffer;
+ return !lstat([path fileSystemRepresentation], &statBuffer);
+}
+
+static NSString *pathWithUniqueFilenameForPath(NSString *path)
+{
+ // "Fix" the filename of the path.
+ NSString *filename = filenameByFixingIllegalCharacters([path lastPathComponent]);
+ path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
+
+ if (fileExists(path)) {
+ // Don't overwrite existing file by appending "-n", "-n.ext" or "-n.ext.ext" to the filename.
+ NSString *extensions = nil;
+ NSString *pathWithoutExtensions;
+ NSString *lastPathComponent = [path lastPathComponent];
+ NSRange periodRange = [lastPathComponent rangeOfString:@"."];
+
+ if (periodRange.location == NSNotFound) {
+ pathWithoutExtensions = path;
+ } else {
+ extensions = [lastPathComponent substringFromIndex:periodRange.location + 1];
+ lastPathComponent = [lastPathComponent substringToIndex:periodRange.location];
+ pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
+ }
+
+ for (unsigned i = 1; ; i++) {
+ NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
+ path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber;
+ if (!fileExists(path))
+ break;
+ }
+ }
+
+ return path;
+}
+
+NSArray *WebViewImpl::namesOfPromisedFilesDroppedAtDestination(NSURL *dropDestination)
+{
+ RetainPtr<NSFileWrapper> wrapper;
+ RetainPtr<NSData> data;
+
+ if (m_promisedImage) {
+ data = ""
+ wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
+ } else
+ wrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL URLWithString:m_promisedURL] options:NSFileWrapperReadingImmediate error:nil]);
+
+ if (wrapper)
+ [wrapper setPreferredFilename:m_promisedFilename];
+ else {
+ LOG_ERROR("Failed to create image file.");
+ return nil;
+ }
+
+ // FIXME: Report an error if we fail to create a file.
+ NSString *path = [[dropDestination path] stringByAppendingPathComponent:[wrapper preferredFilename]];
+ path = pathWithUniqueFilenameForPath(path);
+ if (![wrapper writeToURL:[NSURL fileURLWithPath:path] options:NSFileWrapperWritingWithNameUpdating originalContentsURL:nil error:nullptr])
+ LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToURL:options:originalContentsURL:error:]");
+
+ if (!m_promisedURL.isEmpty())
+ WebCore::setMetadataURL(m_promisedURL, "", String(path));
+
+ return [NSArray arrayWithObject:[path lastPathComponent]];
+}
+
static RetainPtr<CGImageRef> takeWindowSnapshot(CGSWindowID windowID, bool captureAtNominalResolution)
{
CGSWindowCaptureOptions options = kCGSCaptureIgnoreGlobalClipShape;
@@ -2141,6 +2317,16 @@
ensureGestureController().handleSmartMagnificationGesture([m_view convertPoint:event.locationInWindow fromView:nil]);
}
+void WebViewImpl::setLastMouseDownEvent(NSEvent *event)
+{
+ ASSERT(!event || event.type == NSLeftMouseDown || event.type == NSRightMouseDown || event.type == NSOtherMouseDown);
+
+ if (event == m_lastMouseDownEvent.get())
+ return;
+
+ m_lastMouseDownEvent = event;
+}
+
#if ENABLE(MAC_GESTURE_EVENTS)
void WebViewImpl::rotateWithEvent(NSEvent *event)
{
Modified: trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.h (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.h 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.h 2015-10-28 00:44:51 UTC (rev 191648)
@@ -34,27 +34,28 @@
#import <WebCore/AlternativeTextClient.h>
#import <wtf/RetainPtr.h>
-@class WKView;
-
namespace WebKit {
+class WebViewImpl;
+
class CorrectionPanel {
public:
CorrectionPanel();
~CorrectionPanel();
- void show(WKView*, WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
+ void show(NSView *, WebViewImpl&, WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
String dismiss(WebCore::ReasonForDismissingAlternativeText);
- static void recordAutocorrectionResponse(WKView*, NSCorrectionResponse, const String& replacedString, const String& replacementString);
+ static void recordAutocorrectionResponse(NSView *, NSInteger spellCheckerDocumentTag, NSCorrectionResponse, const String& replacedString, const String& replacementString);
private:
bool isShowing() const { return m_view; }
String dismissInternal(WebCore::ReasonForDismissingAlternativeText, bool dismissingExternally);
- void handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType);
+ void handleAcceptedReplacement(WebViewImpl&, NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType);
bool m_wasDismissedExternally;
WebCore::ReasonForDismissingAlternativeText m_reasonForDismissing;
- RetainPtr<WKView> m_view;
+ RetainPtr<NSView> m_view;
RetainPtr<NSString> m_resultForDismissal;
+ NSInteger m_spellCheckerDocumentTag;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/mac/CorrectionPanel.mm 2015-10-28 00:44:51 UTC (rev 191648)
@@ -29,8 +29,7 @@
#if USE(AUTOCORRECTION_PANEL)
#import "WebPageProxy.h"
-#import "WKView.h"
-#import "WKViewInternal.h"
+#import "WebViewImpl.h"
using namespace WebCore;
@@ -64,16 +63,19 @@
dismissInternal(ReasonForDismissingAlternativeTextIgnored, false);
}
-void CorrectionPanel::show(WKView* view, AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
+void CorrectionPanel::show(NSView *view, WebViewImpl& webViewImpl, AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
{
dismissInternal(ReasonForDismissingAlternativeTextIgnored, false);
if (!view)
return;
+ NSInteger spellCheckerDocumentTag = webViewImpl.spellCheckerDocumentTag();
+
NSString* replacedStringAsNSString = replacedString;
NSString* replacementStringAsNSString = replacementString;
m_view = view;
+ m_spellCheckerDocumentTag = spellCheckerDocumentTag;
NSCorrectionIndicatorType indicatorType = correctionIndicatorType(type);
NSMutableArray* alternativeStrings = 0;
@@ -86,7 +88,7 @@
NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker];
[spellChecker showCorrectionIndicatorOfType:indicatorType primaryString:replacementStringAsNSString alternativeStrings:alternativeStrings forStringInRect:boundingBoxOfReplacedString view:m_view.get() completionHandler:^(NSString* acceptedString) {
- handleAcceptedReplacement(acceptedString, replacedStringAsNSString, replacementStringAsNSString, indicatorType);
+ handleAcceptedReplacement(webViewImpl, acceptedString, replacedStringAsNSString, replacementStringAsNSString, indicatorType);
}];
}
@@ -107,42 +109,42 @@
return m_resultForDismissal.get();
}
-void CorrectionPanel::recordAutocorrectionResponse(WKView* view, NSCorrectionResponse response, const String& replacedString, const String& replacementString)
+void CorrectionPanel::recordAutocorrectionResponse(NSView *view, NSInteger spellCheckerDocumentTag, NSCorrectionResponse response, const String& replacedString, const String& replacementString)
{
- [[NSSpellChecker sharedSpellChecker] recordResponse:response toCorrection:replacementString forWord:replacedString language:nil inSpellDocumentWithTag:[view spellCheckerDocumentTag]];
+ [[NSSpellChecker sharedSpellChecker] recordResponse:response toCorrection:replacementString forWord:replacedString language:nil inSpellDocumentWithTag:spellCheckerDocumentTag];
}
-void CorrectionPanel::handleAcceptedReplacement(NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType correctionIndicatorType)
+void CorrectionPanel::handleAcceptedReplacement(WebViewImpl& webViewImpl, NSString* acceptedReplacement, NSString* replaced, NSString* proposedReplacement, NSCorrectionIndicatorType correctionIndicatorType)
{
if (!m_view)
return;
NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker];
- NSInteger documentTag = [m_view spellCheckerDocumentTag];
switch (correctionIndicatorType) {
case NSCorrectionIndicatorTypeDefault:
if (acceptedReplacement)
- [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag];
+ [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:m_spellCheckerDocumentTag];
else {
if (!m_wasDismissedExternally || m_reasonForDismissing == ReasonForDismissingAlternativeTextCancelled)
- [spellChecker recordResponse:NSCorrectionResponseRejected toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag];
+ [spellChecker recordResponse:NSCorrectionResponseRejected toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:m_spellCheckerDocumentTag];
else
- [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag];
+ [spellChecker recordResponse:NSCorrectionResponseIgnored toCorrection:proposedReplacement forWord:replaced language:nil inSpellDocumentWithTag:m_spellCheckerDocumentTag];
}
break;
case NSCorrectionIndicatorTypeReversion:
if (acceptedReplacement)
- [spellChecker recordResponse:NSCorrectionResponseReverted toCorrection:replaced forWord:acceptedReplacement language:nil inSpellDocumentWithTag:documentTag];
+ [spellChecker recordResponse:NSCorrectionResponseReverted toCorrection:replaced forWord:acceptedReplacement language:nil inSpellDocumentWithTag:m_spellCheckerDocumentTag];
break;
case NSCorrectionIndicatorTypeGuesses:
if (acceptedReplacement)
- [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:documentTag];
+ [spellChecker recordResponse:NSCorrectionResponseAccepted toCorrection:acceptedReplacement forWord:replaced language:nil inSpellDocumentWithTag:m_spellCheckerDocumentTag];
break;
}
- [m_view handleAcceptedAlternativeText:acceptedReplacement];
- m_view.clear();
+ webViewImpl.handleAcceptedAlternativeText(acceptedReplacement);
+ m_spellCheckerDocumentTag = 0;
+ m_view = nullptr;
if (acceptedReplacement)
m_resultForDismissal = adoptNS([acceptedReplacement copy]);
}
Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (191647 => 191648)
--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2015-10-28 00:35:24 UTC (rev 191647)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm 2015-10-28 00:44:51 UTC (rev 191648)
@@ -236,7 +236,7 @@
ColorSpaceData PageClientImpl::colorSpace()
{
- return [m_wkView _colorSpace];
+ return m_impl->colorSpace();
}
void PageClientImpl::processDidExit()
@@ -361,23 +361,23 @@
#if WK_API_ENABLED
if (m_webView) {
NSPoint webViewPosition = [m_wkView convertPoint:clientPosition toView:m_webView];
- [m_wkView _dragImageForView:m_webView withImage:dragNSImage.get() at:webViewPosition linkDrag:isLinkDrag];
+ m_impl->dragImageForView(m_webView, dragNSImage.get(), webViewPosition, isLinkDrag);
} else
#endif
- [m_wkView _dragImageForView:m_wkView withImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag];
+ m_impl->dragImageForView(m_wkView, dragNSImage.get(), clientPosition, isLinkDrag);
}
-void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, PassRefPtr<SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, PassRefPtr<SharedBuffer> archiveBuffer)
+void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, PassRefPtr<SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, PassRefPtr<SharedBuffer> archiveBuffer)
{
RefPtr<Image> image = BitmapImage::create();
image->setData(imageBuffer.get(), true);
- [m_wkView _setPromisedDataForImage:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
+ m_impl->setPromisedDataForImage(image.get(), filename, extension, title, url, visibleURL, archiveBuffer.get(), pasteboardName);
}
#if ENABLE(ATTACHMENT_ELEMENT)
-void PageClientImpl::setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl)
+void PageClientImpl::setPromisedDataForAttachment(const String& pasteboardName, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL)
{
- [m_wkView _setPromisedDataForAttachment:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl forPasteboard:pasteboardName];
+ m_impl->setPromisedDataForAttachment(filename, extension, title, url, visibleURL, pasteboardName);
}
#endif
@@ -564,7 +564,7 @@
#if USE(AUTOCORRECTION_PANEL)
if (!isViewVisible() || !isViewInWindow())
return;
- m_correctionPanel.show(m_wkView, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
+ m_correctionPanel.show(m_wkView, *m_impl, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
#endif
}
@@ -587,7 +587,7 @@
void PageClientImpl::recordAutocorrectionResponse(AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
{
NSCorrectionResponse response = responseType == AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
- CorrectionPanel::recordAutocorrectionResponse(m_wkView, response, replacedString, replacementString);
+ CorrectionPanel::recordAutocorrectionResponse(m_wkView, m_impl->spellCheckerDocumentTag(), response, replacedString, replacementString);
}
void PageClientImpl::recommendedScrollbarStyleDidChange(ScrollbarStyle newStyle)
@@ -635,8 +635,8 @@
{
if (!isViewVisible() || !isViewInWindow())
return;
- m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString* acceptedAlternative){
- [m_wkView handleAcceptedAlternativeText:acceptedAlternative];
+ m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString *acceptedAlternative) {
+ m_impl->handleAcceptedAlternativeText(acceptedAlternative);
});
}