summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/API/mac
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
commit2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch)
tree988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/WebKit2/UIProcess/API/mac
parentdd91e772430dc294e3bf478c119ef8d43c0a3358 (diff)
downloadqtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/WebKit2/UIProcess/API/mac')
-rw-r--r--Source/WebKit2/UIProcess/API/mac/PDFViewController.h2
-rw-r--r--Source/WebKit2/UIProcess/API/mac/PDFViewController.mm62
-rw-r--r--Source/WebKit2/UIProcess/API/mac/PageClientImpl.h14
-rw-r--r--Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm24
-rw-r--r--Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm32
-rw-r--r--Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm20
-rw-r--r--Source/WebKit2/UIProcess/API/mac/WKView.mm251
-rw-r--r--Source/WebKit2/UIProcess/API/mac/WKViewInternal.h4
8 files changed, 328 insertions, 81 deletions
diff --git a/Source/WebKit2/UIProcess/API/mac/PDFViewController.h b/Source/WebKit2/UIProcess/API/mac/PDFViewController.h
index 3a4f2f600..46aaf8458 100644
--- a/Source/WebKit2/UIProcess/API/mac/PDFViewController.h
+++ b/Source/WebKit2/UIProcess/API/mac/PDFViewController.h
@@ -62,6 +62,8 @@ public:
static Class pdfPreviewViewClass();
+ bool forwardScrollWheelEvent(NSEvent *);
+
NSPrintOperation *makePrintOperation(NSPrintInfo *);
void openPDFInFinder();
void savePDFToDownloadsFolder();
diff --git a/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm b/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm
index c5441a49f..91fcf34b2 100644
--- a/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm
+++ b/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm
@@ -36,6 +36,7 @@
#import "WebPreferences.h"
#import <PDFKit/PDFKit.h>
#import <WebCore/LocalizedStrings.h>
+#import <objc/runtime.h>
#import <wtf/text/CString.h>
#import <wtf/text/WTFString.h>
@@ -114,6 +115,7 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
- (PDFView *)pdfView;
- (void)setDocument:(PDFDocument *)pdfDocument;
+- (BOOL)forwardScrollWheelEvent:(NSEvent *)wheelEvent;
- (void)_applyPDFPreferences;
- (PDFSelection *)_nextMatchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag fromSelection:(PDFSelection *)initialSelection startInSelection:(BOOL)startInSelection;
@end
@@ -383,6 +385,11 @@ static void insertOpenWithDefaultPDFMenuItem(NSMenu *menu, NSUInteger index)
_pdfViewController->print();
}
+- (BOOL)forwardScrollWheelEvent:(NSEvent *)wheelEvent
+{
+ return _pdfViewController->forwardScrollWheelEvent(wheelEvent);
+}
+
@end
namespace WebKit {
@@ -486,7 +493,54 @@ Class PDFViewController::pdfPreviewViewClass()
return pdfPreviewViewClass;
}
+
+bool PDFViewController::forwardScrollWheelEvent(NSEvent *wheelEvent)
+{
+ CGFloat deltaX = [wheelEvent deltaX];
+ if ((deltaX > 0 && !page()->canGoBack()) || (deltaX < 0 && !page()->canGoForward()))
+ return false;
+
+ [m_wkView scrollWheel:wheelEvent];
+ return true;
+}
+
+#ifndef BUILDING_ON_SNOW_LEOPARD
+static IMP oldPDFViewScrollView_scrollWheel;
+
+static WKPDFView *findEnclosingWKPDFView(NSView *view)
+{
+ for (NSView *superview = [view superview]; superview; superview = [superview superview]) {
+ if ([superview isKindOfClass:[WKPDFView class]])
+ return static_cast<WKPDFView *>(superview);
+ }
+
+ return nil;
+}
+
+static void PDFViewScrollView_scrollWheel(NSScrollView* self, SEL _cmd, NSEvent *wheelEvent)
+{
+ CGFloat deltaX = [wheelEvent deltaX];
+ CGFloat deltaY = [wheelEvent deltaY];
+
+ NSSize contentsSize = [[self documentView] bounds].size;
+ NSRect visibleRect = [self documentVisibleRect];
+
+ // We only want to forward the wheel events if the horizontal delta is non-zero,
+ // and only if we're pinned to either the left or right side.
+ // We also never want to forward momentum scroll events.
+ if ([wheelEvent momentumPhase] == NSEventPhaseNone && deltaX && fabsf(deltaY) < fabsf(deltaX)
+ && ((deltaX > 0 && visibleRect.origin.x <= 0) || (deltaX < 0 && contentsSize.width <= NSMaxX(visibleRect)))) {
+ if (WKPDFView *pdfView = findEnclosingWKPDFView(self)) {
+ if ([pdfView forwardScrollWheelEvent:wheelEvent])
+ return;
+ }
+ }
+
+ oldPDFViewScrollView_scrollWheel(self, _cmd, wheelEvent);
+}
+#endif
+
NSBundle* PDFViewController::pdfKitBundle()
{
static NSBundle *pdfKitBundle;
@@ -502,6 +556,14 @@ NSBundle* PDFViewController::pdfKitBundle()
pdfKitBundle = [NSBundle bundleWithPath:pdfKitPath];
if (![pdfKitBundle load])
LOG_ERROR("Couldn't load PDFKit.framework");
+
+#ifndef BUILDING_ON_SNOW_LEOPARD
+ if (Class pdfViewScrollViewClass = [pdfKitBundle classNamed:@"PDFViewScrollView"]) {
+ if (Method scrollWheel = class_getInstanceMethod(pdfViewScrollViewClass, @selector(scrollWheel:)))
+ oldPDFViewScrollView_scrollWheel = method_setImplementation(scrollWheel, reinterpret_cast<IMP>(PDFViewScrollView_scrollWheel));
+ }
+#endif
+
return pdfKitBundle;
}
diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
index dbe947a39..a9d7a9fa9 100644
--- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
+++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
@@ -55,7 +55,7 @@ private:
virtual bool isViewFocused();
virtual bool isViewVisible();
virtual bool isViewInWindow();
- virtual LayerHostingMode layerHostingMode();
+ virtual LayerHostingMode viewLayerHostingMode() OVERRIDE;
virtual void processDidCrash();
virtual void pageClosed();
@@ -63,7 +63,7 @@ private:
virtual void toolTipChanged(const String& oldToolTip, const String& newToolTip);
virtual void setCursor(const WebCore::Cursor&);
virtual void setCursorHiddenUntilMouseMoves(bool);
- virtual void didChangeViewportProperties(const WebCore::ViewportArguments&);
+ virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&);
virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
virtual void clearAllEditCommands();
@@ -72,6 +72,8 @@ private:
virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, Vector<WebCore::KeypressCommand>&);
virtual bool executeSavedCommandBySelector(const String& selector);
virtual void setDragImage(const WebCore::IntPoint& clientPosition, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag);
+ virtual void setPromisedData(const String& pasteboardName, PassRefPtr<WebCore::SharedBuffer> imageBuffer, const String& filename, const String& extension, const String& title,
+ const String& url, const String& visibleUrl, PassRefPtr<WebCore::SharedBuffer> archiveBuffer);
virtual void updateTextInputState(bool updateSecureInputState);
virtual void resetTextInputState();
@@ -118,10 +120,10 @@ private:
virtual void didPerformDictionaryLookup(const String&, double scaleFactor, const DictionaryPopupInfo&);
virtual void dismissDictionaryLookupPanel();
- virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
- virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel);
- virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel);
- virtual void recordAutocorrectionResponse(WebCore::EditorClient::AutocorrectionResponseType, const String& replacedString, const String& replacementString);
+ virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings);
+ virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText);
+ virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText);
+ virtual void recordAutocorrectionResponse(WebCore::AutocorrectionResponseType, const String& replacedString, const String& replacementString);
virtual void recommendedScrollbarStyleDidChange(int32_t newStyle);
diff --git a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
index 71a1a5075..72ea3493e 100644
--- a/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
+++ b/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
@@ -37,12 +37,15 @@
#import "WebContextMenuProxyMac.h"
#import "WebEditCommandProxy.h"
#import "WebPopupMenuProxyMac.h"
+#import <WebCore/BitmapImage.h>
#import <WebCore/Cursor.h>
#import <WebCore/FloatRect.h>
#import <WebCore/FoundationExtras.h>
#import <WebCore/GraphicsContext.h>
+#import <WebCore/Image.h>
#import <WebCore/KeyboardEvent.h>
#import <WebCore/NotImplemented.h>
+#import <WebCore/SharedBuffer.h>
#import <wtf/PassOwnPtr.h>
#import <wtf/text/CString.h>
#import <wtf/text/WTFString.h>
@@ -190,7 +193,7 @@ bool PageClientImpl::isViewInWindow()
return [m_wkView window];
}
-LayerHostingMode PageClientImpl::layerHostingMode()
+LayerHostingMode PageClientImpl::viewLayerHostingMode()
{
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
if (![m_wkView window])
@@ -233,7 +236,7 @@ void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
[NSCursor setHiddenUntilMouseMoves:hiddenUntilMouseMoves];
}
-void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportArguments&)
+void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes&)
{
}
@@ -278,6 +281,13 @@ void PageClientImpl::setDragImage(const IntPoint& clientPosition, PassRefPtr<Sha
[m_wkView _setDragImage:dragNSImage.get() at:clientPosition linkDrag:isLinkDrag];
}
+void PageClientImpl::setPromisedData(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 _setPromisedData:image.get() withFileName:filename withExtension:extension withTitle:title withURL:url withVisibleURL:visibleUrl withArchive:archiveBuffer.get() forPasteboard:pasteboardName];
+}
+
void PageClientImpl::updateTextInputState(bool updateSecureInputState)
{
[m_wkView _updateTextInputStateIncludingSecureInputState:updateSecureInputState];
@@ -453,7 +463,7 @@ void PageClientImpl::dismissDictionaryLookupPanel()
#endif
}
-void PageClientImpl::showCorrectionPanel(CorrectionPanelInfo::PanelType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
+void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
{
#if !defined(BUILDING_ON_SNOW_LEOPARD)
if (!isViewVisible() || !isViewInWindow())
@@ -462,14 +472,14 @@ void PageClientImpl::showCorrectionPanel(CorrectionPanelInfo::PanelType type, co
#endif
}
-void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingCorrectionPanel reason)
+void PageClientImpl::dismissCorrectionPanel(ReasonForDismissingAlternativeText reason)
{
#if !defined(BUILDING_ON_SNOW_LEOPARD)
m_correctionPanel.dismiss(reason);
#endif
}
-String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel reason)
+String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingAlternativeText reason)
{
#if !defined(BUILDING_ON_SNOW_LEOPARD)
return m_correctionPanel.dismiss(reason);
@@ -478,10 +488,10 @@ String PageClientImpl::dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCo
#endif
}
-void PageClientImpl::recordAutocorrectionResponse(EditorClient::AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
+void PageClientImpl::recordAutocorrectionResponse(AutocorrectionResponseType responseType, const String& replacedString, const String& replacementString)
{
#if !defined(BUILDING_ON_SNOW_LEOPARD)
- NSCorrectionResponse response = responseType == EditorClient::AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
+ NSCorrectionResponse response = responseType == AutocorrectionReverted ? NSCorrectionResponseReverted : NSCorrectionResponseEdited;
CorrectionPanel::recordAutocorrectionResponse(m_wkView, response, replacedString, replacementString);
#endif
}
diff --git a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
index 13aefb82b..63c58895f 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
@@ -27,6 +27,7 @@
#import "WKPrintingView.h"
#import "Logging.h"
+#import "PDFKitImports.h"
#import "PrintInfo.h"
#import "WebData.h"
#import "WebPageProxy.h"
@@ -228,8 +229,8 @@ static void pageDidDrawToPDF(WKDataRef dataRef, WKErrorRef, void* untypedContext
ASSERT([view _isPrintingPreview]);
if (data) {
- pair<HashMap<WebCore::IntRect, Vector<uint8_t> >::iterator, bool> entry = view->_pagePreviews.add(iter->second, Vector<uint8_t>());
- entry.first->second.append(data->bytes(), data->size());
+ HashMap<WebCore::IntRect, Vector<uint8_t> >::AddResult entry = view->_pagePreviews.add(iter->second, Vector<uint8_t>());
+ entry.iterator->second.append(data->bytes(), data->size());
}
view->_expectedPreviewCallbacks.remove(context->callbackID);
bool receivedResponseToLatestRequest = view->_latestExpectedPreviewCallback == context->callbackID;
@@ -411,33 +412,6 @@ static void prepareDataForPrintingOnSecondaryThread(void* untypedContext)
return 0; // Invalid page number.
}
-static NSString *pdfKitFrameworkPath()
-{
- NSString *systemLibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, NO) objectAtIndex:0];
- return [systemLibraryPath stringByAppendingPathComponent:@"Frameworks/Quartz.framework/Frameworks/PDFKit.framework"];
-}
-
-static Class classFromPDFKit(NSString *className)
-{
- static NSBundle *pdfKitBundle = [NSBundle bundleWithPath:pdfKitFrameworkPath()];
- [pdfKitBundle load];
- return [pdfKitBundle classNamed:className];
-}
-
-static Class pdfAnnotationLinkClass()
-{
- static Class pdfAnnotationLinkClass = classFromPDFKit(@"PDFAnnotationLink");
- ASSERT(pdfAnnotationLinkClass);
- return pdfAnnotationLinkClass;
-}
-
-static Class pdfDocumentClass()
-{
- static Class pdfDocumentClass = classFromPDFKit(@"PDFDocument");
- ASSERT(pdfDocumentClass);
- return pdfDocumentClass;
-}
-
- (void)_drawPDFDocument:(PDFDocument *)pdfDocument page:(unsigned)page atPoint:(NSPoint)point
{
if (!pdfDocument) {
diff --git a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm
index 8c69b08b6..2be0cfd3c 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKTextInputWindowController.mm
@@ -28,6 +28,23 @@
#import <WebKitSystemInterface.h>
+@interface WKTextInputView : NSTextView {
+}
+@end
+
+@implementation WKTextInputView
+
+- (NSArray *)validAttributesForMarkedText
+{
+ // Let TSM know that a bottom input window would be created for marked text.
+ NSArray *regularAttributes = [super validAttributesForMarkedText];
+ NSMutableArray *floatingWindowAttributes = [NSMutableArray arrayWithArray:regularAttributes];
+ [floatingWindowAttributes addObject:@"__NSUsesFloatingInputWindow"];
+ return floatingWindowAttributes;
+}
+
+@end
+
@interface WKTextInputPanel : NSPanel {
NSTextView *_inputTextView;
}
@@ -65,7 +82,7 @@
[self setFrame:frame display:NO];
- _inputTextView = [[NSTextView alloc] initWithFrame:[(NSView *)self.contentView frame]];
+ _inputTextView = [[WKTextInputView alloc] initWithFrame:[(NSView *)self.contentView frame]];
_inputTextView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable | NSViewMaxXMargin | NSViewMinXMargin | NSViewMaxYMargin | NSViewMinYMargin;
NSScrollView* scrollView = [[NSScrollView alloc] initWithFrame:[(NSView *)self.contentView frame]];
@@ -91,6 +108,7 @@
*string = nil;
// Let TSM know that a bottom input window would be created for marked text.
+ // FIXME: Can be removed once we can rely on __NSUsesFloatingInputWindow (or a better API) being available everywhere.
EventRef carbonEvent = static_cast<EventRef>(const_cast<void*>([event eventRef]));
if (carbonEvent) {
Boolean ignorePAH = true;
diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
index a326dd089..8cd3027a3 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
@@ -64,6 +64,7 @@
#import <WebCore/DragData.h>
#import <WebCore/DragSession.h>
#import <WebCore/FloatRect.h>
+#import <WebCore/Image.h>
#import <WebCore/IntRect.h>
#import <WebCore/KeyboardEvent.h>
#import <WebCore/LocalizedStrings.h>
@@ -71,7 +72,11 @@
#import <WebCore/PlatformScreen.h>
#import <WebCore/Region.h>
#import <WebCore/RunLoop.h>
+#import <WebCore/SharedBuffer.h>
+#import <WebCore/WebCoreNSStringExtras.h>
+#import <WebCore/FileSystem.h>
#import <WebKitSystemInterface.h>
+#import <sys/stat.h>
#import <wtf/RefPtr.h>
#import <wtf/RetainPtr.h>
@@ -92,10 +97,13 @@
@end
@interface NSWindow (WKNSWindowDetails)
+#if defined(BUILDING_ON_SNOW_LEOPARD)
- (NSRect)_growBoxRect;
- (id)_growBoxOwner;
- (void)_setShowOpaqueGrowBoxForOwner:(id)owner;
- (BOOL)_updateGrowBoxForWindowFrameChange;
+#endif
+
- (NSRect)_intersectBottomCornersWithRect:(NSRect)viewRect;
- (void)_maskRoundedBottomCorners:(NSRect)clipRect;
@end
@@ -169,7 +177,6 @@ struct WKViewInterpretKeyEventsParameters {
bool _inResignFirstResponder;
NSEvent *_mouseDownEvent;
BOOL _ignoringMouseDraggedEvents;
- BOOL _dragHasStarted;
id _flagsChangedEventMonitor;
#if ENABLE(GESTURE_EVENTS)
@@ -194,6 +201,9 @@ struct WKViewInterpretKeyEventsParameters {
// We use this flag to determine when we need to paint the background (white or clear)
// when the web process is unresponsive or takes too long to paint.
BOOL _windowHasValidBackingStore;
+ RefPtr<WebCore::Image> _promisedImage;
+ String _promisedFilename;
+ String _promisedURL;
}
@end
@@ -374,7 +384,6 @@ struct WKViewInterpretKeyEventsParameters {
// Send back an empty string to the plug-in. This will disable text input.
_data->_page->sendComplexTextInputToPlugin(_data->_pluginComplexTextInputIdentifier, String());
- _data->_pluginComplexTextInputIdentifier = 0; // Always reset the identifier when the plugin is disabled.
}
typedef HashMap<SEL, String> SelectorNameMap;
@@ -527,11 +536,17 @@ WEBCORE_COMMAND(yankAndSelect)
- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
{
- Vector<String> pasteboardTypes;
size_t numTypes = [types count];
- for (size_t i = 0; i < numTypes; ++i)
- pasteboardTypes.append([types objectAtIndex:i]);
- return _data->_page->writeSelectionToPasteboard([pasteboard name], pasteboardTypes);
+ [pasteboard declareTypes:types owner:nil];
+ for (size_t i = 0; i < numTypes; ++i) {
+ if ([[types objectAtIndex:i] isEqualTo:NSStringPboardType])
+ [pasteboard setString:_data->_page->stringSelectionForPasteboard() forType:NSStringPboardType];
+ else {
+ RefPtr<SharedBuffer> buffer = _data->_page->dataSelectionForPasteboard([types objectAtIndex:i]);
+ [pasteboard setData:buffer ? [buffer->createNSData() autorelease] : nil forType:[types objectAtIndex:i]];
+ }
+ }
+ return YES;
}
- (void)centerSelectionInVisibleArea:(id)sender
@@ -711,9 +726,9 @@ static void validateCommandCallback(WKStringRef commandName, bool isEnabled, int
return YES;
// Add this item to the vector of items for a given command that are awaiting validation.
- pair<ValidationMap::iterator, bool> addResult = _data->_validationMap.add(commandName, ValidationVector());
- addResult.first->second.append(item);
- if (addResult.second) {
+ ValidationMap::AddResult addResult = _data->_validationMap.add(commandName, ValidationVector());
+ addResult.iterator->second.append(item);
+ if (addResult.isNewEntry) {
// If we are not already awaiting validation for this command, start the asynchronous validation process.
// FIXME: Theoretically, there is a race here; when we get the answer it might be old, from a previous time
// we asked for the same command; there is no guarantee the answer is still valid.
@@ -1024,7 +1039,6 @@ NATIVE_EVENT_HANDLER(scrollWheel, Wheel)
{
[self _setMouseDownEvent:event];
_data->_ignoringMouseDraggedEvents = NO;
- _data->_dragHasStarted = NO;
[self mouseDownInternal:event];
}
@@ -1124,9 +1138,11 @@ static const short kIOHIDEventTypeScroll = 6;
// As in insertText:replacementRange:, we assume that the call comes from an input method if there is marked text.
bool isFromInputMethod = _data->_page->editorState().hasComposition;
- if (parameters && !isFromInputMethod)
- parameters->commands->append(KeypressCommand(NSStringFromSelector(selector)));
- else {
+ if (parameters && !isFromInputMethod) {
+ KeypressCommand command(NSStringFromSelector(selector));
+ parameters->commands->append(command);
+ _data->_page->registerKeypressCommandName(command.commandName);
+ } else {
// FIXME: Send the command to Editor synchronously and only send it along the
// responder chain if it's a selector that does not correspond to an editing command.
[super doCommandBySelector:selector];
@@ -1171,7 +1187,9 @@ static const short kIOHIDEventTypeScroll = 6;
// then we also execute it immediately, as there will be no other chance.
if (parameters && !isFromInputMethod) {
ASSERT(replacementRange.location == NSNotFound);
- parameters->commands->append(KeypressCommand("insertText:", text));
+ KeypressCommand command("insertText:", text);
+ parameters->commands->append(command);
+ _data->_page->registerKeypressCommandName(command.commandName);
return;
}
@@ -1264,10 +1282,8 @@ static const short kIOHIDEventTypeScroll = 6;
if (string) {
_data->_page->sendComplexTextInputToPlugin(_data->_pluginComplexTextInputIdentifier, string);
- if (!usingLegacyCocoaTextInput) {
+ if (!usingLegacyCocoaTextInput)
_data->_pluginComplexTextInputState = PluginComplexTextInputDisabled;
- _data->_pluginComplexTextInputIdentifier = 0; // Always reset the identifier when the plugin is disabled.
- }
}
return didHandleEvent;
@@ -1678,6 +1694,23 @@ static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard,
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]);
@@ -1689,7 +1722,10 @@ static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard,
if (createdExtension)
_data->_page->process()->willAcquireUniversalFileReadSandboxExtension();
- _data->_page->performDrag(&dragData, [[draggingInfo draggingPasteboard] name], sandboxExtensionHandle);
+ SandboxExtension::HandleArray sandboxExtensionForUpload;
+ createSandboxExtensionsForFileUpload([draggingInfo draggingPasteboard], sandboxExtensionForUpload);
+
+ _data->_page->performDrag(&dragData, [[draggingInfo draggingPasteboard] name], sandboxExtensionHandle, sandboxExtensionForUpload);
return YES;
}
@@ -1716,6 +1752,8 @@ static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard,
_data->_page->updateWindowIsVisible([[self window] isVisible]);
}
+
+#if defined(BUILDING_ON_SNOW_LEOPARD)
- (BOOL)_ownsWindowGrowBox
{
NSWindow* window = [self window];
@@ -1764,6 +1802,7 @@ static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard,
return ownsGrowBox;
}
+#endif
// FIXME: Use AppKit constants for these when they are available.
static NSString * const windowDidChangeBackingPropertiesNotification = @"NSWindowDidChangeBackingPropertiesNotification";
@@ -1821,9 +1860,11 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
[self removeWindowObservers];
[self addWindowObserversForWindow:window];
-
+
+#if defined(BUILDING_ON_SNOW_LEOPARD)
if ([currentWindow _growBoxOwner] == self)
[currentWindow _setShowOpaqueGrowBoxForOwner:nil];
+#endif
}
- (void)viewDidMoveToWindow
@@ -1989,8 +2030,7 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
[self getRectsBeingDrawn:&rectsBeingDrawn count:&numRectsBeingDrawn];
for (NSInteger i = 0; i < numRectsBeingDrawn; ++i) {
Region unpaintedRegion;
- IntRect rect = enclosingIntRect(rectsBeingDrawn[i]);
- drawingArea->paint(context, rect, unpaintedRegion);
+ drawingArea->paint(context, enclosingIntRect(rectsBeingDrawn[i]), unpaintedRegion);
// If the window doesn't have a valid backing store, we need to fill the parts of the page that we
// didn't paint with the background color (white or clear), to avoid garbage in those areas.
@@ -2117,7 +2157,8 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
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];
- [self mouseMoved:fakeEvent];
+ NativeWebMouseEvent webEvent(fakeEvent, self);
+ _data->_page->handleMouseEvent(webEvent);
}
- (NSInteger)conversationIdentifier
@@ -2167,8 +2208,10 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
- (PassOwnPtr<WebKit::DrawingAreaProxy>)_createDrawingAreaProxy
{
+#if ENABLE(THREADED_SCROLLING)
if ([self _shouldUseTiledDrawingArea])
return TiledCoreAnimationDrawingAreaProxy::create(_data->_page.get());
+#endif
return DrawingAreaProxyImpl::create(_data->_page.get());
}
@@ -2184,6 +2227,9 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
- (void)_processDidCrash
{
+ if (_data->_layerHostingView)
+ [self _exitAcceleratedCompositingMode];
+
[self _updateRemoteAccessibilityRegistration:NO];
}
@@ -2434,7 +2480,8 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
[CATransaction begin];
[CATransaction setDisableActions:YES];
- [self addSubview:_data->_layerHostingView.get()];
+
+ [self addSubview:_data->_layerHostingView.get() positioned:NSWindowBelow relativeTo:nil];
// Create a root layer that will back the NSView.
RetainPtr<CALayer> rootLayer(AdoptNS, [[CALayer alloc] init]);
@@ -2519,7 +2566,7 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
if (pageHasCustomRepresentation)
_data->_pdfViewController = PDFViewController::create(self);
-
+
if (pageHasCustomRepresentation != hadPDFView)
_data->_page->drawingArea()->pageCustomRepresentationChanged();
}
@@ -2565,12 +2612,6 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
- (void)_setDragImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag
{
- // We need to prevent re-entering this call to avoid crashing in AppKit.
- // Given the asynchronous nature of WebKit2 this can now happen.
- if (_data->_dragHasStarted)
- return;
-
- _data->_dragHasStarted = YES;
IntSize size([image size]);
size.scale(1.0 / _data->_page->deviceScaleFactor());
[image setSize:size];
@@ -2585,7 +2626,121 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
source:self
slideBack:YES];
- _data->_dragHasStarted = NO;
+}
+
+static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension)
+{
+ NSString *extensionAsSuffix = [@"." stringByAppendingString:extension];
+ return hasCaseInsensitiveSuffix(filename, extensionAsSuffix) || (stringIsCaseInsensitiveEqualToString(extension, @"jpeg")
+ && hasCaseInsensitiveSuffix(filename, @".jpg"));
+}
+
+- (void)_setPromisedData:(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.get() addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
+ [pasteboard declareTypes:types.get() owner:self];
+ if (!matchesExtensionOrEquivalent(filename, extension))
+ filename = [[filename stringByAppendingString:@"."] stringByAppendingString:extension];
+
+ [pasteboard setString:url forType:NSURLPboardType];
+ [pasteboard setString:visibleUrl forType:PasteboardTypes::WebURLPboardType];
+ [pasteboard setString:title forType:PasteboardTypes::WebURLNamePboardType];
+ [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:url], [NSArray arrayWithObject:title], nil] forType:PasteboardTypes::WebURLsWithTitlesPboardType];
+ [pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
+
+ if (archiveBuffer)
+ [pasteboard setData:[archiveBuffer->createNSData() autorelease] forType:PasteboardTypes::WebArchivePboardType];
+
+ _data->_promisedImage = image;
+ _data->_promisedFilename = filename;
+ _data->_promisedURL = url;
+}
+
+- (void)pasteboardChangedOwner:(NSPasteboard *)pasteboard
+{
+ _data->_promisedImage = 0;
+ _data->_promisedFilename = "";
+ _data->_promisedURL = "";
+}
+
+- (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 = 0;
+ }
+}
+
+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.adoptNS(_data->_promisedImage->data()->createNSData());
+ wrapper.adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
+ [wrapper.get() setPreferredFilename:_data->_promisedFilename];
+ }
+
+ if (!wrapper) {
+ 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.get() preferredFilename]];
+ path = pathWithUniqueFilenameForPath(path);
+ if (![wrapper.get() writeToFile:path atomically:NO updateFilenames:YES])
+ LOG_ERROR("Failed to create image file via -[NSFileWrapper writeToFile:atomically:updateFilenames:]");
+
+ if (!_data->_promisedURL.isEmpty())
+ WebCore::setMetadataURL(_data->_promisedURL, "", String(path));
+
+ return [NSArray arrayWithObject:[path lastPathComponent]];
}
- (void)_updateSecureInputState
@@ -2643,10 +2798,17 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
- (void)_didChangeScrollbarsForMainFrame
{
+#if defined(BUILDING_ON_SNOW_LEOPARD)
[self _updateGrowBoxForWindowFrameChange];
+#endif
}
#if ENABLE(FULLSCREEN_API)
+- (BOOL)hasFullScreenWindowController
+{
+ return (bool)_data->_fullScreenWindowController;
+}
+
- (WKFullScreenWindowController*)fullScreenWindowController
{
if (!_data->_fullScreenWindowController) {
@@ -2700,7 +2862,7 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
- (void)handleCorrectionPanelResult:(NSString*)result
{
- _data->_page->handleCorrectionPanelResult(result);
+ _data->_page->handleAlternativeTextUIResult(result);
}
@end
@@ -2748,8 +2910,8 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
_data->_pageClient = PageClientImpl::create(self);
_data->_page = toImpl(contextRef)->createWebPage(_data->_pageClient.get(), toImpl(pageGroupRef));
- _data->_page->initializeWebPage();
_data->_page->setIntrinsicDeviceScaleFactor([self _intrinsicDeviceScaleFactor]);
+ _data->_page->initializeWebPage();
#if ENABLE(FULLSCREEN_API)
_data->_page->fullScreenManager()->setWebView(self);
#endif
@@ -2759,12 +2921,10 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
[self _registerDraggedTypes];
if ([self _shouldUseTiledDrawingArea]) {
- CALayer *layer = [CALayer layer];
- layer.backgroundColor = CGColorGetConstantColor(kCGColorWhite);
- self.layer = layer;
-
- self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever;
self.wantsLayer = YES;
+
+ // Explicitly set the layer contents placement so AppKit will make sure that our layer has masksToBounds set to YES.
+ self.layerContentsPlacement = NSViewLayerContentsPlacementTopLeft;
}
WebContext::statistics().wkViewCount++;
@@ -2772,6 +2932,21 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
return self;
}
+#if !defined(BUILDING_ON_SNOW_LEOPARD) && !defined(BUILDING_ON_LION)
+- (BOOL)wantsUpdateLayer
+{
+ return [self _shouldUseTiledDrawingArea];
+}
+
+- (void)updateLayer
+{
+ self.layer.backgroundColor = CGColorGetConstantColor(kCGColorWhite);
+
+ if (DrawingAreaProxy* drawingArea = _data->_page->drawingArea())
+ drawingArea->waitForPossibleGeometryUpdate();
+}
+#endif
+
- (WKPageRef)pageRef
{
return toAPI(_data->_page.get());
diff --git a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
index 83346d3f1..6b6eb6bf4 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
+++ b/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
@@ -35,6 +35,8 @@ namespace CoreIPC {
namespace WebCore {
struct KeypressCommand;
+ class Image;
+ class SharedBuffer;
}
namespace WebKit {
@@ -78,6 +80,7 @@ namespace WebKit {
- (void)_findStringInCustomRepresentation:(NSString *)string withFindOptions:(WebKit::FindOptions)options maxMatchCount:(NSUInteger)count;
- (void)_countStringMatchesInCustomRepresentation:(NSString *)string withFindOptions:(WebKit::FindOptions)options maxMatchCount:(NSUInteger)count;
- (void)_setDragImage:(NSImage *)image at:(NSPoint)clientPoint linkDrag:(BOOL)linkDrag;
+- (void)_setPromisedData:(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;
- (void)_updateSecureInputState;
- (void)_updateTextInputStateIncludingSecureInputState:(BOOL)updateSecureInputState;
- (void)_resetTextInputState;
@@ -85,6 +88,7 @@ namespace WebKit {
- (void)_didChangeScrollbarsForMainFrame;
#if ENABLE(FULLSCREEN_API)
+- (BOOL)hasFullScreenWindowController;
- (WKFullScreenWindowController*)fullScreenWindowController;
- (void)closeFullScreenWindowController;
#endif