2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #import "WebDragClient.h"
28 #import "WebArchive.h"
29 #import "WebDOMOperations.h"
31 #import "WebFrameInternal.h"
32 #import "WebHTMLViewInternal.h"
33 #import "WebHTMLViewPrivate.h"
34 #import "WebKitLogging.h"
35 #import "WebKitNSStringExtras.h"
36 #import "WebNSPasteboardExtras.h"
37 #import "WebNSURLExtras.h"
38 #import "WebStringTruncator.h"
39 #import "WebUIDelegate.h"
40 #import "WebUIDelegatePrivate.h"
41 #import "WebViewInternal.h"
42 #import <WebCore/ClipboardMac.h>
43 #import <WebCore/DragData.h>
44 #import <WebCore/Editor.h>
45 #import <WebCore/EditorClient.h>
46 #import <WebCore/EventHandler.h>
47 #import <WebCore/Frame.h>
48 #import <WebCore/FrameView.h>
49 #import <WebCore/Image.h>
50 #import <WebCore/Page.h>
52 using namespace WebCore;
54 WebDragClient::WebDragClient(WebView* webView)
59 static WebHTMLView *getTopHTMLView(Frame* frame)
62 ASSERT(frame->page());
63 return (WebHTMLView*)[[kit(frame->page()->mainFrame()) frameView] documentView];
66 WebCore::DragDestinationAction WebDragClient::actionMaskForDrag(WebCore::DragData* dragData)
68 return (WebCore::DragDestinationAction)[[m_webView _UIDelegateForwarder] webView:m_webView dragDestinationActionMaskForDraggingInfo:dragData->platformData()];
71 void WebDragClient::willPerformDragDestinationAction(WebCore::DragDestinationAction action, WebCore::DragData* dragData)
73 [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:dragData->platformData()];
77 WebCore::DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint& windowPoint)
79 NSPoint viewPoint = [m_webView convertPoint:windowPoint fromView:nil];
80 return (DragSourceAction)[[m_webView _UIDelegateForwarder] webView:m_webView dragSourceActionMaskForPoint:viewPoint];
83 void WebDragClient::willPerformDragSourceAction(WebCore::DragSourceAction action, const WebCore::IntPoint& mouseDownPoint, WebCore::Clipboard* clipboard)
86 [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard:static_cast<WebCore::ClipboardMac*>(clipboard)->pasteboard()];
89 void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool linkDrag)
94 RetainPtr<WebHTMLView> htmlView = (WebHTMLView*)[[kit(frame) frameView] documentView];
95 if (![htmlView.get() isKindOfClass:[WebHTMLView class]])
98 NSEvent *event = linkDrag ? frame->eventHandler()->currentNSEvent() : [htmlView.get() _mouseDownEvent];
99 WebHTMLView* topHTMLView = getTopHTMLView(frame);
100 RetainPtr<WebHTMLView> topViewProtector = topHTMLView;
102 [topHTMLView _stopAutoscrollTimer];
103 NSPasteboard *pasteboard = static_cast<ClipboardMac*>(clipboard)->pasteboard();
105 NSImage *dragNSImage = dragImage.get();
106 WebHTMLView *sourceHTMLView = htmlView.get();
108 id delegate = [m_webView UIDelegate];
109 SEL selector = @selector(webView:dragImage:at:offset:event:pasteboard:source:slideBack:forView:);
110 if ([delegate respondsToSelector:selector]) {
111 if ([m_webView _catchesDelegateExceptions]) {
113 [delegate webView:m_webView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES forView:topHTMLView];
114 } @catch (id exception) {
115 ReportDiscardedDelegateException(selector, exception);
118 [delegate webView:m_webView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES forView:topHTMLView];
120 [topHTMLView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES];
123 void WebDragClient::declareAndWriteDragImage(NSPasteboard* pasteboard, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame)
127 WebHTMLView *source = getTopHTMLView(frame);
128 WebArchive *archive = [element webArchive];
130 [pasteboard _web_declareAndWriteDragImageForElement:element URL:URL title:title archive:archive source:source];
133 void WebDragClient::dragControllerDestroyed()