2007-01-23 Oliver Hunt <oliver@apple.com>
Reviewed by Adam.
Added DragController to handled drag and drop state and control logic.
Currently this only handles logic for Dragging and Dropping, and is
unable to initialise a drag itself.
platform/DragData encapsulate the paltform Drag data (NSDraggingInfo on Mac,
QMimeType in Qt). This provides methods to pull data out the drag data as a String,
a URL, a DocumentFragment (for rich content), or a Colour.
* WebCore.exp:
* WebCore.pro:
* WebCore.xcodeproj/project.pbxproj:
* dom/Clipboard.cpp: Added.
(WebCore::Clipboard::setAccessPolicy):
(WebCore::dragOpFromIEOp):
(WebCore::IEOpFromDragOp):
(WebCore::Clipboard::sourceOperation):
(WebCore::Clipboard::destinationOperation):
(WebCore::Clipboard::setSourceOperation):
(WebCore::Clipboard::setDestinationOperation):
(WebCore::Clipboard::setDropEffect):
(WebCore::Clipboard::setEffectAllowed):
move platform independent functions from ClipboardMac to Clipboard
* dom/Clipboard.h:
(WebCore::Clipboard::Clipboard):
(WebCore::Clipboard::dropEffect):
(WebCore::Clipboard::effectAllowed):
(WebCore::Clipboard::policy):
as above -- also removed virtual modifier from now
platform independent methods
* editing/Editor.cpp:
(WebCore::Editor::smartInsertDeleteEnabled):
(WebCore::Editor::shouldApplyStyle):
* editing/Editor.h:
adding calls through to EditorClient
* page/DragActions.h: Added.
(WebCore::):
Replicates a number of NS* enums in the WebCore namespace
* page/DragClient.h: Added.
(WebCore::DragClient::~DragClient):
Standard client interface for dragging UIDelegate
* page/DragController.cpp: Added.
(WebCore::createMouseEvent):
(WebCore::DragController::DragController):
(WebCore::DragController::~DragController):
(WebCore::documentFragmentFromDragData):
(WebCore::DragController::isMoveDrag):
(WebCore::visiblePositionForPoint):
(WebCore::DragController::cancelDrag):
(WebCore::documentAtPoint):
(WebCore::DragController::dragEntered):
(WebCore::DragController::dragExited):
(WebCore::DragController::dragUpdated):
(WebCore::DragController::performDrag):
(WebCore::DragController::dragEnteredOrUpdated):
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::operationForLoad):
(WebCore::DragController::concludeDrag):
(WebCore::DragController::canProcessDrag):
(WebCore::DragController::tryDHTMLDrag):
Class to handle state and logic for dragging and dropping
* page/DragController.h: Added.
(WebCore::DragController::client):
(WebCore::DragController::didInitiateDrag):
(WebCore::DragController::isHandlingDrag):
(WebCore::DragController::dragOperation):
(WebCore::DragController::document):
(WebCore::DragController::dragInitiator):
(WebCore::DragController::dragDestinationAction):
(WebCore::DragController::dragSourceAction):
(WebCore::DragController::dragEnded):
(WebCore::DragController::setIsHandlingDrag):
(WebCore::DragController::setDidInitiateDrag):
(WebCore::DragController::setDragOperation):
(WebCore::DragController::setDragSourceAction):
(WebCore::DragController::setDragInitiator):
See above
* page/Page.cpp:
(WebCore::Page::Page):
Update Page to have DragController
* page/Page.h:
(WebCore::Page::dragController):
ditto
* page/mac/DragControllerMac.mm: Added.
(WebCore::DragController::isCopyKeyDown):
(WebCore::DragController::dragOperation):
Platform specific portions of the DragController
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::handleDrag):
(WebCore::EventHandler::dragSourceEndedAt):
Convert from NSDragOperation to WebCore::DragOperation
* page/mac/WebCoreFrameBridge.h:
* page/mac/WebCoreFrameBridge.mm:
Remove obsolete Drag functions
* page/qt/DragControllerQt.cpp: Added.
(WebCore::DragController::isCopyKeyDown):
(WebCore::DragController::dragOperation):
Basic stubs to maintain Qt build
* platform/DragData.cpp: Added.
(WebCore::DragData::DragData):
* platform/DragData.h: Added.
(WebCore::DragData::clientPosition):
(WebCore::DragData::globalPosition):
(WebCore::DragData::platformData):
(WebCore::DragData::draggingSourceOperationMask):
DragData class to encapsulate platform drag data/event
* platform/graphics/svg/SVGImage.cpp:
(WebCore::SVGImage::setData):
Addition of dummy DragClient
* platform/graphics/svg/SVGImageEmptyClients.h:
(WebCore::SVGEmptyDragClient::~SVGEmptyDragClient):
(WebCore::SVGEmptyDragClient::willPerformDragDestinationAction):
(WebCore::SVGEmptyDragClient::actionMaskForDrag):
(WebCore::SVGEmptyDragClient::dragControllerDestroyed):
ditto
* platform/mac/ClipboardMac.h:
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::ClipboardMac):
(WebCore::ClipboardMac::clearData):
(WebCore::ClipboardMac::clearAllData):
(WebCore::ClipboardMac::getData):
(WebCore::ClipboardMac::setData):
(WebCore::ClipboardMac::types):
(WebCore::ClipboardMac::setDragImage):
Moving platform independent logic to Clipboard, and updating
platform specific methods to use appropriate accessors rather than
directly manipulating data they no longer own
* platform/mac/DragDataMac.mm: Added.
(WebCore::DragData::DragData):
(WebCore::DragData::canSmartReplace):
(WebCore::DragData::containsColor):
(WebCore::DragData::containsPlainText):
(WebCore::DragData::asPlainText):
(WebCore::DragData::asColor):
(WebCore::DragData::createClipboard):
(WebCore::imageExistsAtPaths):
(WebCore::DragData::containsCompatibleContent):
(WebCore::DragData::containsURL):
(WebCore::DragData::asURL):
(WebCore::DragData::asFragment):
Mac implementations of DragData methods. A number of these use
a Helper class that accesses WebKit functionality. That functionality
should be migrated to WebCore in the future.
* platform/mac/PasteboardHelper.h: Added.
(WebCore::PasteboardHelper::~PasteboardHelper):
Temporary, and Mac only, helper class to access WebKit functionality
from WebCore
* platform/qt/DragDataQt.cpp: Added.
(WebCore::DragData::canSmartReplace):
(WebCore::DragData::containsColor):
(WebCore::DragData::containsPlainText):
(WebCore::DragData::asPlainText):
(WebCore::DragData::asColor):
(WebCore::DragData::createClipboard):
(WebCore::DragData::containsCompatibleContent):
(WebCore::DragData::containsURL):
(WebCore::DragData::asURL):
(WebCore::DragData::asFragment):
Basic stubs to maintain Qt build
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::HitTestResult):
Correct HitTestResult copy contructor to copy localPoint
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@19039 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/platform/DragData.cpp b/WebCore/platform/DragData.cpp
new file mode 100644
index 0000000..bf2275a
--- /dev/null
+++ b/WebCore/platform/DragData.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DragData.h"
+
+namespace WebCore {
+
+#if !PLATFORM(MAC)
+DragData::DragData(DragDataRef data, const IntPoint& clientPosition, const IntPoint& globalPosition,
+ DragOperation sourceOperationMask)
+ : m_clientPosition(clientPosition)
+ , m_globalPosition(globalPosition)
+ , m_platformDragData(data)
+ , m_draggingSourceOperationMask(sourceOperationMask)
+{
+}
+#endif
+
+}
diff --git a/WebCore/platform/DragData.h b/WebCore/platform/DragData.h
new file mode 100644
index 0000000..2ebc448
--- /dev/null
+++ b/WebCore/platform/DragData.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DragData_h
+#define DragData_h
+
+#include "ClipboardAccessPolicy.h"
+#include "Color.h"
+#include "DragActions.h"
+#include "IntPoint.h"
+
+#include <wtf/Forward.h>
+
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+#import <Foundation/Foundation.h>
+#import <AppKit/NSDragging.h>
+typedef id <NSDraggingInfo> DragDataRef;
+#else
+typedef void* DragDataRef;
+#endif
+#elif PLATFORM(QT)
+typedef class QMimeData* DragDataRef;
+#elif PLATFORM(WIN)
+typedef struct IDataObject* DragDataRef;
+#endif
+
+
+namespace WebCore {
+
+ class Clipboard;
+ class Document;
+ class DocumentFragment;
+ class KURL;
+
+#if PLATFORM(MAC)
+ class PasteboardHelper;
+#endif
+
+
+ class DragData {
+ public:
+#if PLATFORM(MAC)
+ //FIXME: In the future the WebKit functions provided by the helper class should be moved into WebCore,
+ //after which this constructor should be removed
+ DragData(DragDataRef data, const IntPoint& clientPosition, const IntPoint& globalPosition,
+ DragOperation operation, PasteboardHelper*);
+#else
+ //clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left
+ DragData(DragDataRef data, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation operation);
+#endif
+ const IntPoint& clientPosition() const { return m_clientPosition; }
+ const IntPoint& globalPosition() const { return m_globalPosition; }
+ DragDataRef platformData() const { return m_platformDragData; }
+ DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; }
+ Clipboard* createClipboard(ClipboardAccessPolicy) const;
+ bool containsURL() const;
+ bool containsPlainText() const;
+ bool containsCompatibleContent() const;
+ String asURL(String* title = 0) const;
+ String asPlainText() const;
+ Color asColor() const;
+ PassRefPtr<DocumentFragment> asFragment(Document*) const;
+ bool canSmartReplace() const;
+ bool containsColor() const;
+
+ private:
+ IntPoint m_clientPosition;
+ IntPoint m_globalPosition;
+ DragDataRef m_platformDragData;
+ DragOperation m_draggingSourceOperationMask;
+#if PLATFORM(MAC)
+ PasteboardHelper* m_pasteboardHelper;
+#endif
+};
+
+} //namespace WebCore
+
+#endif //!DragData_h
+
diff --git a/WebCore/platform/graphics/svg/SVGImage.cpp b/WebCore/platform/graphics/svg/SVGImage.cpp
index ddfe985..99d3eb4 100644
--- a/WebCore/platform/graphics/svg/SVGImage.cpp
+++ b/WebCore/platform/graphics/svg/SVGImage.cpp
@@ -125,11 +125,12 @@
static FrameLoaderClient* dummyFrameLoaderClient = new SVGEmptyFrameLoaderClient;
static EditorClient* dummyEditorClient = new SVGEmptyEditorClient;
static ContextMenuClient* dummyContextMenuClient = new SVGEmptyContextMenuClient;
+ static DragClient* dummyDragClient = new SVGEmptyDragClient;
static Settings* dummySettings = new Settings;
// FIXME: If this SVG ends up loading itself, we'll leak this Frame (and associated DOM & render trees).
// The Cache code does not know about CachedImages holding Frames and won't know to break the cycle.
- m_page.set(new Page(dummyChromeClient, dummyContextMenuClient, dummyEditorClient));
+ m_page.set(new Page(dummyChromeClient, dummyContextMenuClient, dummyEditorClient, dummyDragClient));
m_frame = new FrameMac(m_page.get(), 0, dummyFrameLoaderClient);
m_frameView = new FrameView(m_frame.get());
m_frameView->deref(); // FIXME: FrameView starts with a refcount of 1
diff --git a/WebCore/platform/graphics/svg/SVGImageEmptyClients.h b/WebCore/platform/graphics/svg/SVGImageEmptyClients.h
index 228c738..656e196 100644
--- a/WebCore/platform/graphics/svg/SVGImageEmptyClients.h
+++ b/WebCore/platform/graphics/svg/SVGImageEmptyClients.h
@@ -30,6 +30,7 @@
#include "ChromeClient.h"
#include "ContextMenuClient.h"
+#include "DragClient.h"
#include "EditorClient.h"
#include "FocusDirection.h"
#include "FrameLoaderClient.h"
@@ -352,6 +353,14 @@
#endif
};
+class SVGEmptyDragClient : public DragClient {
+public:
+ virtual ~SVGEmptyDragClient() {}
+ virtual void willPerformDragDestinationAction(DragDestinationAction, DragData*) { }
+ virtual DragDestinationAction actionMaskForDrag(DragData*) { return DragDestinationActionNone; }
+ virtual void dragControllerDestroyed() { }
+};
+
}
#endif // SVG_SUPPORT
diff --git a/WebCore/platform/mac/ClipboardMac.h b/WebCore/platform/mac/ClipboardMac.h
index 8b6483d..6c3703b 100644
--- a/WebCore/platform/mac/ClipboardMac.h
+++ b/WebCore/platform/mac/ClipboardMac.h
@@ -32,6 +32,7 @@
#include "Clipboard.h"
#include "ClipboardAccessPolicy.h"
#include "CachedResourceClient.h"
+#include "RetainPtr.h"
#ifdef __OBJC__
@class NSImage;
@@ -53,11 +54,6 @@
bool isForDragging() const;
- String dropEffect() const;
- void setDropEffect(const String&);
- String effectAllowed() const;
- void setEffectAllowed(const String&);
-
void clearData(const String& type);
void clearAllData();
String getData(const String& type, bool& success) const;
@@ -74,25 +70,17 @@
// Methods for getting info in Cocoa's type system
NSImage *dragNSImage(NSPoint&); // loc converted from dragLoc, based on whole image size
- bool sourceOperation(NSDragOperation&) const;
- bool destinationOperation(NSDragOperation&) const;
- void setSourceOperation(NSDragOperation);
- void setDestinationOperation(NSDragOperation);
- void setAccessPolicy(ClipboardAccessPolicy);
void setDragHasStarted() { m_dragStarted = true; }
private:
void setDragImage(CachedImage*, Node*, const IntPoint&);
- NSPasteboard *m_pasteboard;
+ RetainPtr<NSPasteboard> m_pasteboard;
bool m_forDragging;
- String m_dropEffect;
- String m_effectAllowed;
IntPoint m_dragLoc;
CachedImage* m_dragImage;
RefPtr<Node> m_dragImageElement;
- ClipboardAccessPolicy m_policy;
int m_changeCount;
bool m_dragStarted;
FrameMac* m_frame; // used on the source side to generate dragging images
diff --git a/WebCore/platform/mac/ClipboardMac.mm b/WebCore/platform/mac/ClipboardMac.mm
index 6b0fac6..6b5d780 100644
--- a/WebCore/platform/mac/ClipboardMac.mm
+++ b/WebCore/platform/mac/ClipboardMac.mm
@@ -37,19 +37,18 @@
namespace WebCore {
ClipboardMac::ClipboardMac(bool forDragging, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, FrameMac *frame)
- : m_pasteboard(HardRetain(pasteboard))
+ : Clipboard(policy)
+ , m_pasteboard(pasteboard)
, m_forDragging(forDragging)
, m_dragImage(0)
- , m_policy(policy)
, m_dragStarted(false)
, m_frame(frame)
{
- m_changeCount = [m_pasteboard changeCount];
+ m_changeCount = [m_pasteboard.get() changeCount];
}
ClipboardMac::~ClipboardMac()
{
- HardRelease(m_pasteboard);
}
bool ClipboardMac::isForDragging() const
@@ -57,13 +56,6 @@
return m_forDragging;
}
-void ClipboardMac::setAccessPolicy(ClipboardAccessPolicy policy)
-{
- // once you go numb, can never go back
- ASSERT(m_policy != ClipboardNumb || policy == ClipboardNumb);
- m_policy = policy;
-}
-
static NSString *cocoaTypeFromMIMEType(const String& type)
{
String qType = type.stripWhiteSpace();
@@ -121,36 +113,36 @@
void ClipboardMac::clearData(const String& type)
{
- if (m_policy != ClipboardWritable)
+ if (policy() != ClipboardWritable)
return;
// note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
NSString *cocoaType = cocoaTypeFromMIMEType(type);
if (cocoaType) {
- [m_pasteboard setString:@"" forType:cocoaType];
+ [m_pasteboard.get() setString:@"" forType:cocoaType];
}
}
void ClipboardMac::clearAllData()
{
- if (m_policy != ClipboardWritable)
+ if (policy() != ClipboardWritable)
return;
// note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
- [m_pasteboard declareTypes:[NSArray array] owner:nil];
+ [m_pasteboard.get() declareTypes:[NSArray array] owner:nil];
}
String ClipboardMac::getData(const String& type, bool& success) const
{
success = false;
- if (m_policy != ClipboardReadable)
+ if (policy() != ClipboardReadable)
return String();
NSString *cocoaType = cocoaTypeFromMIMEType(type);
NSString *cocoaValue = nil;
- NSArray *availableTypes = [m_pasteboard types];
+ NSArray *availableTypes = [m_pasteboard.get() types];
// Fetch the data in different ways for the different Cocoa types
@@ -158,7 +150,7 @@
// When both URL and filenames are present, filenames is superior since it can contain a list.
// must check this or we get a printf from CF when there's no data of this type
if ([availableTypes containsObject:NSFilenamesPboardType]) {
- NSArray *fileList = [m_pasteboard propertyListForType:NSFilenamesPboardType];
+ NSArray *fileList = [m_pasteboard.get() propertyListForType:NSFilenamesPboardType];
if (fileList && [fileList isKindOfClass:[NSArray class]]) {
unsigned count = [fileList count];
if (count > 0) {
@@ -184,19 +176,19 @@
if (!cocoaValue) {
// must check this or we get a printf from CF when there's no data of this type
if ([availableTypes containsObject:NSURLPboardType]) {
- NSURL *url = [NSURL URLFromPasteboard:m_pasteboard];
+ NSURL *url = [NSURL URLFromPasteboard:m_pasteboard.get()];
if (url) {
cocoaValue = [url absoluteString];
}
}
}
} else if (cocoaType) {
- cocoaValue = [m_pasteboard stringForType:cocoaType];
+ cocoaValue = [m_pasteboard.get() stringForType:cocoaType];
}
// Enforce changeCount ourselves for security. We check after reading instead of before to be
// sure it doesn't change between our testing the change count and accessing the data.
- if (cocoaValue && m_changeCount == [m_pasteboard changeCount]) {
+ if (cocoaValue && m_changeCount == [m_pasteboard.get() changeCount]) {
success = true;
return String(DeprecatedString::fromNSString(cocoaValue));
}
@@ -206,7 +198,7 @@
bool ClipboardMac::setData(const String &type, const String &data)
{
- if (m_policy != ClipboardWritable)
+ if (policy() != ClipboardWritable)
return false;
// note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
@@ -214,14 +206,14 @@
NSString *cocoaData = data;
if ([cocoaType isEqualToString:NSURLPboardType]) {
- [m_pasteboard addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil];
+ [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSURLPboardType] owner:nil];
NSURL *url = [[NSURL alloc] initWithString:cocoaData];
- [url writeToPasteboard:m_pasteboard];
+ [url writeToPasteboard:m_pasteboard.get()];
if ([url isFileURL]) {
- [m_pasteboard addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil];
+ [m_pasteboard.get() addTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil];
NSArray *fileList = [NSArray arrayWithObject:[url path]];
- [m_pasteboard setPropertyList:fileList forType:NSFilenamesPboardType];
+ [m_pasteboard.get() setPropertyList:fileList forType:NSFilenamesPboardType];
}
[url release];
@@ -230,8 +222,8 @@
if (cocoaType) {
// everything else we know of goes on the pboard as a string
- [m_pasteboard addTypes:[NSArray arrayWithObject:cocoaType] owner:nil];
- return [m_pasteboard setString:cocoaData forType:cocoaType];
+ [m_pasteboard.get() addTypes:[NSArray arrayWithObject:cocoaType] owner:nil];
+ return [m_pasteboard.get() setString:cocoaData forType:cocoaType];
}
return false;
@@ -239,14 +231,14 @@
HashSet<String> ClipboardMac::types() const
{
- if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
+ if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
return HashSet<String>();
- NSArray *types = [m_pasteboard types];
+ NSArray *types = [m_pasteboard.get() types];
// Enforce changeCount ourselves for security. We check after reading instead of before to be
// sure it doesn't change between our testing the change count and accessing the data.
- if (m_changeCount != [m_pasteboard changeCount])
+ if (m_changeCount != [m_pasteboard.get() changeCount])
return HashSet<String>();
HashSet<String> result;
@@ -295,7 +287,7 @@
void ClipboardMac::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
{
- if (m_policy == ClipboardImageWritable || m_policy == ClipboardWritable) {
+ if (policy() == ClipboardImageWritable || policy() == ClipboardWritable) {
if (m_dragImage)
m_dragImage->deref(this);
m_dragImage = image;
@@ -305,7 +297,7 @@
m_dragLoc = loc;
m_dragImageElement = node;
- if (m_dragStarted && m_changeCount == [m_pasteboard changeCount]) {
+ if (m_dragStarted && m_changeCount == [m_pasteboard.get() changeCount]) {
NSPoint cocoaLoc;
NSImage* cocoaImage = dragNSImage(cocoaLoc);
if (cocoaImage) {
@@ -350,100 +342,4 @@
return result;
}
-String ClipboardMac::dropEffect() const
-{
- return m_dropEffect;
-}
-
-void ClipboardMac::setDropEffect(const String &s)
-{
- if (m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable) {
- m_dropEffect = s;
- }
-}
-
-String ClipboardMac::effectAllowed() const
-{
- return m_effectAllowed;
-}
-
-void ClipboardMac::setEffectAllowed(const String &s)
-{
- if (m_policy == ClipboardWritable)
- m_effectAllowed = s;
-}
-
-// These "conversion" methods are called by the bridge and part, and never make sense to JS, so we don't
-// worry about security for these. They don't allow access to the pasteboard anyway.
-
-static NSDragOperation cocoaOpFromIEOp(const String& op)
-{
- // yep, it's really just this fixed set
- if (op == "none")
- return NSDragOperationNone;
- if (op == "copy")
- return NSDragOperationCopy;
- if (op == "link")
- return NSDragOperationLink;
- if (op == "move")
- return NSDragOperationGeneric;
- if (op == "copyLink")
- return NSDragOperationCopy | NSDragOperationLink;
- if (op == "copyMove")
- return NSDragOperationCopy | NSDragOperationGeneric | NSDragOperationMove;
- if (op == "linkMove")
- return NSDragOperationLink | NSDragOperationGeneric | NSDragOperationMove;
- if (op == "all")
- return NSDragOperationEvery;
- return NSDragOperationPrivate; // really a marker for "no conversion"
-}
-
-static String IEOpFromCocoaOp(NSDragOperation op)
-{
- bool moveSet = ((NSDragOperationGeneric | NSDragOperationMove) & op) != 0;
-
- if ((moveSet && (op & NSDragOperationCopy) && (op & NSDragOperationLink))
- || (op == NSDragOperationEvery))
- return "all";
- if (moveSet && (op & NSDragOperationCopy))
- return "copyMove";
- if (moveSet && (op & NSDragOperationLink))
- return "linkMove";
- if ((op & NSDragOperationCopy) && (op & NSDragOperationLink))
- return "copyLink";
- if (moveSet)
- return "move";
- if (op & NSDragOperationCopy)
- return "copy";
- if (op & NSDragOperationLink)
- return "link";
- return "none";
-}
-
-bool ClipboardMac::sourceOperation(NSDragOperation& op) const
-{
- if (m_effectAllowed.isNull())
- return false;
- op = cocoaOpFromIEOp(m_effectAllowed);
- return true;
-}
-
-bool ClipboardMac::destinationOperation(NSDragOperation& op) const
-{
- if (m_dropEffect.isNull())
- return false;
- op = cocoaOpFromIEOp(m_dropEffect);
- return true;
-}
-
-void ClipboardMac::setSourceOperation(NSDragOperation op)
-{
- m_effectAllowed = IEOpFromCocoaOp(op);
-}
-
-void ClipboardMac::setDestinationOperation(NSDragOperation op)
-{
- m_dropEffect = IEOpFromCocoaOp(op);
-}
-
}
diff --git a/WebCore/platform/mac/DragDataMac.mm b/WebCore/platform/mac/DragDataMac.mm
new file mode 100644
index 0000000..353d321
--- /dev/null
+++ b/WebCore/platform/mac/DragDataMac.mm
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "DragData.h"
+
+#import "ClipboardMac.h"
+#import "ClipboardAccessPolicy.h"
+#import "Document.h"
+#import "DocumentFragment.h"
+#import "DOMDocumentFragment.h"
+#import "DOMDocumentFragmentInternal.h"
+#import "MimeTypeRegistry.h"
+#import "Pasteboard.h"
+#import "PasteboardHelper.h"
+
+namespace WebCore {
+
+DragData::DragData(DragDataRef data, const IntPoint& clientPosition, const IntPoint& globalPosition,
+ DragOperation sourceOperationMask, PasteboardHelper* pasteboardHelper)
+ : m_clientPosition(clientPosition)
+ , m_globalPosition(globalPosition)
+ , m_platformDragData(data)
+ , m_draggingSourceOperationMask(sourceOperationMask)
+ , m_pasteboardHelper(pasteboardHelper)
+{
+ ASSERT(pasteboardHelper);
+}
+
+bool DragData::canSmartReplace() const
+{
+ //Need to call this so that the various Pasteboard type strings are intialised
+ Pasteboard::generalPasteboard();
+ return [[[m_platformDragData draggingPasteboard] types] containsObject:WebSmartPastePboardType];
+}
+
+bool DragData::containsColor() const
+{
+ return [[[m_platformDragData draggingPasteboard] types] containsObject:NSColorPboardType];
+}
+
+bool DragData::containsPlainText() const
+{
+ NSPasteboard *pasteboard = [m_platformDragData draggingPasteboard];
+ NSArray *types = [pasteboard types];
+
+ return [types containsObject:NSStringPboardType]
+ || [types containsObject:NSRTFDPboardType]
+ || [types containsObject:NSRTFPboardType]
+ || [types containsObject:NSFilenamesPboardType]
+ || [NSURL URLFromPasteboard:pasteboard];
+}
+
+String DragData::asPlainText() const
+{
+ return m_pasteboardHelper->plainTextFromPasteboard([m_platformDragData draggingPasteboard]);
+}
+
+Color DragData::asColor() const
+{
+ NSColor *color = [NSColor colorFromPasteboard:[m_platformDragData draggingPasteboard]];
+ return makeRGBA((int)([color redComponent] * 255.0 + 0.5), (int)([color greenComponent] * 255.0 + 0.5),
+ (int)([color blueComponent] * 255.0 + 0.5), (int)([color alphaComponent] * 255.0 + 0.5));
+}
+
+Clipboard* DragData::createClipboard(ClipboardAccessPolicy policy) const
+{
+ return new ClipboardMac(true, [m_platformDragData draggingPasteboard], policy);
+}
+
+static bool imageExistsAtPaths(NSArray* paths)
+{
+ NSEnumerator *enumerator = [paths objectEnumerator];
+ NSString *path;
+
+ while ((path = [enumerator nextObject]) != nil)
+ if (MimeTypeRegistry::isSupportedImageResourceMIMEType(MimeTypeRegistry::getMIMETypeForExtension([path pathExtension])))
+ return true;
+
+ return false;
+}
+
+bool DragData::containsCompatibleContent() const
+{
+
+ NSPasteboard *pasteboard = [m_platformDragData draggingPasteboard];
+ NSMutableSet *types = [NSMutableSet setWithArray:[pasteboard types]];
+ [types intersectSet:[NSSet setWithArray:m_pasteboardHelper->insertablePasteboardTypes()]];
+ if ([types count] == 0)
+ return false;
+ return !([types count] == 1 && [types containsObject:NSFilenamesPboardType] &&
+ !imageExistsAtPaths([pasteboard propertyListForType:NSFilenamesPboardType]));
+}
+
+bool DragData::containsURL() const
+{
+ //FIXME: is it worth doing the initial [types contains URL] check?
+ return [[[m_platformDragData draggingPasteboard] types] containsObject:NSURLPboardType] || !asURL().isEmpty();
+}
+
+String DragData::asURL(String* title) const
+{
+ return m_pasteboardHelper->urlFromPasteboard([m_platformDragData draggingPasteboard], title);
+}
+
+
+PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const
+{
+ return [m_pasteboardHelper->fragmentFromPasteboard([m_platformDragData draggingPasteboard]) _documentFragment];
+}
+
+}
+
diff --git a/WebCore/platform/mac/PasteboardHelper.h b/WebCore/platform/mac/PasteboardHelper.h
new file mode 100644
index 0000000..4ae964d
--- /dev/null
+++ b/WebCore/platform/mac/PasteboardHelper.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PasteboardHelper_h
+#define PasteboardHelper_h
+
+/* FIXME: This is a helper class used to provide access to functionality inside
+ * WebKit. The required functionality should eventually be migrated to WebCore
+ * so that this class can be removed.
+ */
+#if PLATFORM(MAC)
+
+#import <wtf/Forward.h>
+
+#ifdef __OBJC__
+@class DOMDocumentFragment;
+#else
+class DOMDocumentFragment;
+#endif
+
+namespace WebCore {
+
+ class String;
+ class Document;
+
+ class PasteboardHelper {
+ public:
+ virtual ~PasteboardHelper() {}
+ virtual String urlFromPasteboard(const NSPasteboard*, String* title) const = 0;
+ virtual String plainTextFromPasteboard(const NSPasteboard*) const = 0;
+ virtual DOMDocumentFragment* fragmentFromPasteboard(const NSPasteboard*) const = 0;
+ virtual NSArray* insertablePasteboardTypes() const = 0;
+ };
+
+}
+#endif // PLATFORM(MAC)
+
+#endif // !PasteboardHelper_h
diff --git a/WebCore/platform/qt/DragDataQt.cpp b/WebCore/platform/qt/DragDataQt.cpp
new file mode 100644
index 0000000..5269388
--- /dev/null
+++ b/WebCore/platform/qt/DragDataQt.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DragData.h"
+
+namespace WebCore {
+
+bool DragData::canSmartReplace()
+{
+ return false;
+}
+
+bool DragData::containsColor()
+{
+ return false;
+}
+
+bool DragData::containsPlainText()
+{
+ return false;
+}
+
+String DragData::asPlainText()
+{
+ return String();
+}
+
+Color DragData::asColor()
+{
+ return Color();
+}
+
+Clipboard* DragData::createClipboard(ClipboardAccessPolicy)
+{
+ return 0;
+}
+
+bool DragData::containsCompatibleContent()
+{
+ return false;
+}
+
+bool DragData::containsURL()
+{
+ return false;
+}
+
+String DragData::asURL(String* title)
+{
+ return String();
+}
+
+
+PassRefPtr<DocumentFragment> DragData::asFragment(Document*)
+{
+ return 0;
+}
+
+}
+