Commit ec40fe3e authored by darin@apple.com's avatar darin@apple.com

<https://webkit.org/b/119949> Factor Clipboard into drag and non-drag parts

Reviewed by Sam Weinig.

* dom/Clipboard.cpp:
(WebCore::Clipboard::Clipboard): Move the ClipboardType argument to go after the pasteboard.
Initialize strings more efficiently. Put drag-specific data members inside an if statement.
Replace m_clipboardType with m_forDrag.
(WebCore::Clipboard::createForCopyAndPaste): Moved function up to be close to constructor.
Removed explicit clipboard type since constructor now defaults to copy and paste style.
(WebCore::Clipboard::setAccessPolicy): Tweaked comment.
(WebCore::Clipboard::getData): Put drag-specific code inside #if ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setData): Ditto.
(WebCore::Clipboard::files): Ditto.
(WebCore::Clipboard::dropEffect): Added trivial non-drag versions of these functions to
be used when !ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setDropEffect): Ditto.
(WebCore::Clipboard::effectAllowed): Ditto.
(WebCore::Clipboard::setEffectAllowed): Ditto.
(WebCore::Clipboard::createForDragAndDrop): Renamed Clipboard::create that takes DragData
to this, and kep the overload that does not as well. Made the DragData argument a const&.
(WebCore::Clipboard::canSetDragImage): Moved down here since it is drag-specific.
(WebCore::Clipboard::updateDragImage): Use m_shouldUpdateDragImage directly insted of
calling a dragStarted function.
(WebCore::dragOpFromIEOp): Moved this function down here to the drag-specific section.
(WebCore::IEOpFromDragOp): Ditto.
(WebCore::Clipboard::sourceOperation): Ditto.
(WebCore::Clipboard::destinationOperation): Ditto.
(WebCore::Clipboard::setSourceOperation): Ditto.
(WebCore::Clipboard::setDestinationOperation): Ditto.

* dom/Clipboard.h: Removed unneeded include of "Node.h" and added and removed forward
class declarations as required. Removed non-helpful comment. Made ClipboardType a private
implementation detail. Moved functions that are not part of the DOM API down to a separate
section lower down in the class, and sorted the functions to match the order they appear
in the IDL file. Removed isForCopyAndPaste and isForDragAndDrop. Changed dropEffect and
effectAllowed to not be inlined. Moved the long comment before canSetDragImage into the
implementation since it's an implementation detail. Since this class is no longer polymorphic,
use only private, not protected. Make m_dragImageElement an Element, not a Node.

* dom/Clipboard.idl: Removed flags to tell bindings how to deal with null strings, since
these string properties can never return null strings anyway.

* page/DragController.cpp:
(WebCore::DragController::dragExited): Updated to call the new createForDragAndDrop function.
(WebCore::DragController::performDrag): Ditto.
(WebCore::DragController::tryDHTMLDrag): Ditto.

* platform/mac/ClipboardMac.mm: Added now-needed include of Element.h since Clipboard.h no
longer includes it.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154260 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a2e5728e
2013-08-17 Darin Adler <darin@apple.com>
<https://webkit.org/b/119949> Factor Clipboard into drag and non-drag parts
Reviewed by Sam Weinig.
* dom/Clipboard.cpp:
(WebCore::Clipboard::Clipboard): Move the ClipboardType argument to go after the pasteboard.
Initialize strings more efficiently. Put drag-specific data members inside an if statement.
Replace m_clipboardType with m_forDrag.
(WebCore::Clipboard::createForCopyAndPaste): Moved function up to be close to constructor.
Removed explicit clipboard type since constructor now defaults to copy and paste style.
(WebCore::Clipboard::setAccessPolicy): Tweaked comment.
(WebCore::Clipboard::getData): Put drag-specific code inside #if ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setData): Ditto.
(WebCore::Clipboard::files): Ditto.
(WebCore::Clipboard::dropEffect): Added trivial non-drag versions of these functions to
be used when !ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setDropEffect): Ditto.
(WebCore::Clipboard::effectAllowed): Ditto.
(WebCore::Clipboard::setEffectAllowed): Ditto.
(WebCore::Clipboard::createForDragAndDrop): Renamed Clipboard::create that takes DragData
to this, and kep the overload that does not as well. Made the DragData argument a const&.
(WebCore::Clipboard::canSetDragImage): Moved down here since it is drag-specific.
(WebCore::Clipboard::updateDragImage): Use m_shouldUpdateDragImage directly insted of
calling a dragStarted function.
(WebCore::dragOpFromIEOp): Moved this function down here to the drag-specific section.
(WebCore::IEOpFromDragOp): Ditto.
(WebCore::Clipboard::sourceOperation): Ditto.
(WebCore::Clipboard::destinationOperation): Ditto.
(WebCore::Clipboard::setSourceOperation): Ditto.
(WebCore::Clipboard::setDestinationOperation): Ditto.
* dom/Clipboard.h: Removed unneeded include of "Node.h" and added and removed forward
class declarations as required. Removed non-helpful comment. Made ClipboardType a private
implementation detail. Moved functions that are not part of the DOM API down to a separate
section lower down in the class, and sorted the functions to match the order they appear
in the IDL file. Removed isForCopyAndPaste and isForDragAndDrop. Changed dropEffect and
effectAllowed to not be inlined. Moved the long comment before canSetDragImage into the
implementation since it's an implementation detail. Since this class is no longer polymorphic,
use only private, not protected. Make m_dragImageElement an Element, not a Node.
* dom/Clipboard.idl: Removed flags to tell bindings how to deal with null strings, since
these string properties can never return null strings anyway.
* page/DragController.cpp:
(WebCore::DragController::dragExited): Updated to call the new createForDragAndDrop function.
(WebCore::DragController::performDrag): Ditto.
(WebCore::DragController::tryDHTMLDrag): Ditto.
* platform/mac/ClipboardMac.mm: Added now-needed include of Element.h since Clipboard.h no
longer includes it.
2013-08-18 David Kilzer <ddkilzer@apple.com>
WebCore fails to build with trunk clang: error: 'register' storage class specifier is deprecated [-Werror,-Wdeprecated-register]
This diff is collapsed.
......@@ -29,7 +29,9 @@
#include "DragActions.h"
#include "DragImage.h"
#include "IntPoint.h"
#include "Node.h"
#include <wtf/ListHashSet.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
......@@ -37,104 +39,83 @@ namespace WebCore {
class DataTransferItemList;
class DragData;
class DragImageLoader;
class Element;
class FileList;
class Frame;
class Pasteboard;
class Range;
// State available during IE's events for drag and drop and copy/paste
class Clipboard : public RefCounted<Clipboard> {
public:
// Whether this clipboard is serving a drag-drop or copy-paste request.
enum ClipboardType {
CopyAndPaste,
DragAndDrop,
};
static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*);
static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy);
~Clipboard();
bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
String dropEffect() const;
void setDropEffect(const String&);
bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
String effectAllowed() const { return m_effectAllowed; }
String effectAllowed() const;
void setEffectAllowed(const String&);
ListHashSet<String> types() const;
PassRefPtr<FileList> files() const;
void clearData(const String& type);
void clearData();
void setDragImage(Element*, int x, int y);
String getData(const String& type) const;
bool setData(const String& type, const String& data);
ListHashSet<String> types() const;
PassRefPtr<FileList> files() const;
CachedImage* dragImage() const { return m_dragImage.get(); }
Node* dragImageElement() const { return m_dragImageElement.get(); }
DragImageRef createDragImage(IntPoint& dragLocation) const;
void setDragImage(Element*, int x, int y);
bool hasData();
#if ENABLE(DATA_TRANSFER_ITEMS)
PassRefPtr<DataTransferItemList> items() = 0;
#endif
void setAccessPolicy(ClipboardAccessPolicy);
bool canReadTypes() const;
bool canReadData() const;
bool canWriteData() const;
// Note that the spec doesn't actually allow drag image modification outside the dragstart
// event. This capability is maintained for backwards compatiblity for ports that have
// supported this in the past. On many ports, attempting to set a drag image outside the
// dragstart operation is a no-op anyway.
bool canSetDragImage() const;
Pasteboard& pasteboard() { return *m_pasteboard; }
#if ENABLE(DRAG_SUPPORT)
static PassRefPtr<Clipboard> createForDragAndDrop();
static PassRefPtr<Clipboard> createForDragAndDrop(ClipboardAccessPolicy, const DragData&);
bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
bool hasData();
DragOperation sourceOperation() const;
DragOperation destinationOperation() const;
void setSourceOperation(DragOperation);
void setDestinationOperation(DragOperation);
void setDragHasStarted() { m_dragStarted = true; }
#if ENABLE(DATA_TRANSFER_ITEMS)
PassRefPtr<DataTransferItemList> items() = 0;
void setDragHasStarted() { m_shouldUpdateDragImage = true; }
DragImageRef createDragImage(IntPoint& dragLocation) const;
void updateDragImage();
#endif
static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy);
Pasteboard& pasteboard() { return *m_pasteboard; }
private:
enum ClipboardType { CopyAndPaste, DragAndDrop };
Clipboard(ClipboardAccessPolicy, PassOwnPtr<Pasteboard>, ClipboardType = CopyAndPaste, bool forFileDrag = false);
#if ENABLE(DRAG_SUPPORT)
static PassRefPtr<Clipboard> createForDragAndDrop();
void updateDragImage();
bool canSetDragImage() const;
#endif
protected:
Clipboard(ClipboardAccessPolicy, ClipboardType, PassOwnPtr<Pasteboard>, bool forFileDrag = false);
bool dragStarted() const { return m_dragStarted; }
private:
// Instead of using this member directly, prefer to use the can*() methods above.
ClipboardAccessPolicy m_policy;
OwnPtr<Pasteboard> m_pasteboard;
#if ENABLE(DRAG_SUPPORT)
bool m_forDrag;
bool m_forFileDrag;
String m_dropEffect;
String m_effectAllowed;
bool m_dragStarted;
ClipboardType m_clipboardType;
protected:
bool m_shouldUpdateDragImage;
IntPoint m_dragLocation;
CachedResourceHandle<CachedImage> m_dragImage;
RefPtr<Node> m_dragImageElement;
private:
OwnPtr<Pasteboard> m_pasteboard;
bool m_forFileDrag;
#if ENABLE(DRAG_SUPPORT)
RefPtr<Element> m_dragImageElement;
OwnPtr<DragImageLoader> m_dragImageLoader;
#endif
};
......
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -25,11 +25,13 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
[
SkipVTableValidation
] interface Clipboard {
[TreatReturnedNullStringAs=Undefined] attribute DOMString dropEffect;
[TreatReturnedNullStringAs=Undefined] attribute DOMString effectAllowed;
attribute DOMString dropEffect;
attribute DOMString effectAllowed;
[CustomGetter] readonly attribute Array types;
readonly attribute FileList files;
......@@ -40,4 +42,3 @@
[Conditional=DATA_TRANSFER_ITEMS] readonly attribute DataTransferItemList items;
};
......@@ -196,7 +196,7 @@ void DragController::dragExited(DragData* dragData)
if (RefPtr<FrameView> v = mainFrame->view()) {
ClipboardAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? ClipboardReadable : ClipboardTypesReadable;
RefPtr<Clipboard> clipboard = Clipboard::create(policy, dragData, mainFrame);
RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(policy, *dragData);
clipboard->setSourceOperation(dragData->draggingSourceOperationMask());
mainFrame->eventHandler().cancelDragAndDrop(createMouseEvent(dragData), clipboard.get());
clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security
......@@ -222,7 +222,7 @@ bool DragController::performDrag(DragData* dragData)
bool preventedDefault = false;
if (mainFrame->view()) {
// Sending an event can result in the destruction of the view and part.
RefPtr<Clipboard> clipboard = Clipboard::create(ClipboardReadable, dragData, mainFrame.get());
RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(ClipboardReadable, *dragData);
clipboard->setSourceOperation(dragData->draggingSourceOperationMask());
preventedDefault = mainFrame->eventHandler().performDragAndDrop(createMouseEvent(dragData), clipboard.get());
clipboard->setAccessPolicy(ClipboardNumb); // Invalidate clipboard here for security
......@@ -614,7 +614,7 @@ bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
return false;
ClipboardAccessPolicy policy = m_documentUnderMouse->securityOrigin()->isLocal() ? ClipboardReadable : ClipboardTypesReadable;
RefPtr<Clipboard> clipboard = Clipboard::create(policy, dragData, mainFrame.get());
RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(policy, *dragData);
DragOperation srcOpMask = dragData->draggingSourceOperationMask();
clipboard->setSourceOperation(srcOpMask);
......
......@@ -32,6 +32,7 @@
#import "DragClient.h"
#import "DragController.h"
#import "DragData.h"
#import "Element.h"
#import "Frame.h"
#import "FrameSnapshottingMac.h"
#import "Page.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment