Commit cd54bad1 authored by oliver's avatar oliver

2007-02-18 Oliver Hunt <oliver@apple.com>

        Reviewed by Adam.
WebCore:
        More drag and drop migration, now the entirety of the
        drag initiation logic has been rendered platform independent
        This has required a number of new interfaces, and a reasonable
        amount of logic migration.

        As a side effect, this patch also fixes rdar://problem/4945341

        There are some basic Qt stubs that should stop the build from failing,
        however the absence of ClipboardQt means any attempt to initiate a drag 
        may cause a crash.

        * WebCore.exp:
           Exporting new symbols

        * WebCore.xcodeproj/project.pbxproj:
           New files

        * dom/Clipboard.cpp:
        (WebCore::Clipboard::canSaveAsWebArchive):
          Migrated from WebKit

        * dom/Clipboard.h:
          Added more methods to allow Clipboard to be used as a 
          platform independent container for drag and drop

        * page/DragClient.h:
        (WebCore::DragClient::declareAndWriteDragImage):
          This is a mac only helper function, so i've made it have an empty implementation,
          that way we won't need a PLATFORM(MAC) block in SVGImageEmptyClients

        * page/DragController.cpp:
        (WebCore::DragController::dragExited):
        (WebCore::DragController::performDrag):
        (WebCore::DragController::tryDocumentDrag): 
        (WebCore::DragController::tryDHTMLDrag):
          Using RefPtrs now
        (WebCore::getCachedImage):
        (WebCore::getImage):
          Helper functions                   
        (WebCore::dragLocForDHTMLDrag):
        (WebCore::dragLocForSelectionDrag):
        (WebCore::DragController::startDrag):
        (WebCore::DragController::doImageDrag):
        (WebCore::DragController::doSystemDrag):
          Logic that generates drag images and clipboard content, and
          initiates the actual system drag operation

        * page/DragController.h:
          Method and variable declarations

        * page/EventHandler.cpp:
        (WebCore::EventHandler::handleDrag):
          handleDrag is now platform independent
        (WebCore::EventHandler::handleTextInputEvent):
           formatting

        * page/EventHandler.h:
        (WebCore::EventHandler::eventLoopHandleMouseDragged):
          Forgot to define this stub function 

        * page/Frame.h:
          Declaring dragImageForSelection to provide drag image for selected content

        * page/mac/DragControllerMac.mm:
          Defining drag images control vars

        * page/mac/EventHandlerMac.mm:
        (WebCore::EventHandler::createDraggingClipboard):
          Migrated old clipboard creation to here

        * page/mac/FrameMac.mm:
        (WebCore::Frame::dragImageForSelection):
          Wrap FrameMac::selectionImage

        * page/qt/DragControllerQt.cpp:
          Defining drag images control vars

        * page/qt/EventHandlerQt.cpp:
        (WebCore::EventHandler::createDraggingClipboard):
          stub

        * page/qt/FrameQt.cpp:
        (WebCore::Frame::dragImageForSelection):
          stub

        * platform/DragImage.cpp: Added.
        (WebCore::fitDragImageToMaxSize):
        (WebCore::createDragImageForSelection):
           Platform independent processing for drag images

        * platform/DragImage.h: Added.
           Declaring typedefs and wrapper functions to abstract the handling
           of drag images 

        * platform/Pasteboard.h:
          Declaring extracted writeURL and writeSelection methods

        * platform/graphics/svg/SVGImageEmptyClients.h:
        (WebCore::SVGEmptyDragClient::willPerformDragSourceAction):
        (WebCore::SVGEmptyDragClient::startDrag):
        (WebCore::SVGEmptyDragClient::createDragImageForLink):
          Stubs FTW!

        * platform/mac/ClipboardMac.h:
        (WebCore::ClipboardMac::pasteboard):
          Provide accessor for underlying NSPasteboard

        * platform/mac/ClipboardMac.mm:
        (WebCore::ClipboardMac::hasData):
        (WebCore::ClipboardMac::writeRange):
        (WebCore::ClipboardMac::writeURL):
        (WebCore::ClipboardMac::declareAndWriteDragImage):
        (WebCore::ClipboardMac::createDragImage):
           Implemented new Clipboarid functionality.
        (WebCore::ClipboardMac::dragNSImage):
           Made this a const method

        * platform/mac/DragImageMac.mm: Added.
        (WebCore::dragImageSize):
        (WebCore::deleteDragImage):
        (WebCore::scaleDragImage):
        (WebCore::dissolveDragImageToFraction):
        (WebCore::createDragImageFromImage):
        (WebCore::createDragImageIconForCachedImage):
           Implemented platform specific DragImage functions

        * platform/mac/PasteboardMac.mm:
        (WebCore::writeSelection):
        (WebCore::Pasteboard::writeSelection):
        (WebCore::writeURL):
        (WebCore::Pasteboard::writeURL):
           Extracted member implementations of these functions, so that
           Clipboard could also make use of this functionality.
           Pasteboard methods now call the new non-member implementations.
           Also fixed implementations to respect the list of requested types.

        * platform/qt/DragImageQt.cpp: Added.
        (WebCore::dragImageSize):
        (WebCore::deleteDragImage):
        (WebCore::scaleDragImage):
        (WebCore::dissolveDragImageToFraction):
        (WebCore::createDragImageFromImage):
        (WebCore::createDragImageIconForCachedImage):  
          Stubs

WebKit:
        Moving the drag initiation logic to WebCore.
        The redundant code in webkit will be moved out in a later patch.

        * WebCoreSupport/WebDragClient.h:
        * WebCoreSupport/WebDragClient.mm:
        (getTopHTMLView):
          Helper function
        (WebDragClient::willPerformDragSourceAction):
        (WebDragClient::startDrag):
        (WebDragClient::createDragImageForLink):
          Implemented new DragClient methods
        (WebDragClient::declareAndWriteDragImage):
          Helper function for the Mac to allow new drag and drop
          code to match behaviour
          
        * WebView/WebHTMLView.mm:
        (-[WebHTMLView _dragImageForURL:withLabel:]):
        (-[WebHTMLView _dragImageForLinkElement:]):
          Refactoring old _dragImageForLinkElement function so that 
          the link drag image can be created with just a URL and label, 
          rather than requiring the original element
        (-[WebHTMLView dragImage:at:offset:event:pasteboard:source:slideBack:]):
          Removed logic that is no longer necessary                 
        (-[WebHTMLView _mouseDownEvent]):
          The WebDragClient may need the original mouseDownEvent of a drag when initiating
          a drag
        * WebView/WebHTMLViewInternal.h:
          Declaring _mouseDownEvent

        * WebView/WebHTMLViewPrivate.h:
          Declaring _dragImageForURL
                                        
      


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@19689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d309cc7e
2007-02-18 Oliver Hunt <oliver@apple.com>
Reviewed by Adam.
More drag and drop migration, now the entirety of the
drag initiation logic has been rendered platform independent
This has required a number of new interfaces, and a reasonable
amount of logic migration.
As a side effect, this patch also fixes rdar://problem/4945341
There are some basic Qt stubs that should stop the build from failing,
however the absence of ClipboardQt means any attempt to initiate a drag
may cause a crash.
* WebCore.exp:
Exporting new symbols
* WebCore.xcodeproj/project.pbxproj:
New files
* dom/Clipboard.cpp:
(WebCore::Clipboard::canSaveAsWebArchive):
Migrated from WebKit
* dom/Clipboard.h:
Added more methods to allow Clipboard to be used as a
platform independent container for drag and drop
* page/DragClient.h:
(WebCore::DragClient::declareAndWriteDragImage):
This is a mac only helper function, so i've made it have an empty implementation,
that way we won't need a PLATFORM(MAC) block in SVGImageEmptyClients
* page/DragController.cpp:
(WebCore::DragController::dragExited):
(WebCore::DragController::performDrag):
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::tryDHTMLDrag):
Using RefPtrs now
(WebCore::getCachedImage):
(WebCore::getImage):
Helper functions
(WebCore::dragLocForDHTMLDrag):
(WebCore::dragLocForSelectionDrag):
(WebCore::DragController::startDrag):
(WebCore::DragController::doImageDrag):
(WebCore::DragController::doSystemDrag):
Logic that generates drag images and clipboard content, and
initiates the actual system drag operation
* page/DragController.h:
Method and variable declarations
* page/EventHandler.cpp:
(WebCore::EventHandler::handleDrag):
handleDrag is now platform independent
(WebCore::EventHandler::handleTextInputEvent):
formatting
* page/EventHandler.h:
(WebCore::EventHandler::eventLoopHandleMouseDragged):
Forgot to define this stub function
* page/Frame.h:
Declaring dragImageForSelection to provide drag image for selected content
* page/mac/DragControllerMac.mm:
Defining drag images control vars
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::createDraggingClipboard):
Migrated old clipboard creation to here
* page/mac/FrameMac.mm:
(WebCore::Frame::dragImageForSelection):
Wrap FrameMac::selectionImage
* page/qt/DragControllerQt.cpp:
Defining drag images control vars
* page/qt/EventHandlerQt.cpp:
(WebCore::EventHandler::createDraggingClipboard):
stub
* page/qt/FrameQt.cpp:
(WebCore::Frame::dragImageForSelection):
stub
* platform/DragImage.cpp: Added.
(WebCore::fitDragImageToMaxSize):
(WebCore::createDragImageForSelection):
Platform independent processing for drag images
* platform/DragImage.h: Added.
Declaring typedefs and wrapper functions to abstract the handling
of drag images
* platform/Pasteboard.h:
Declaring extracted writeURL and writeSelection methods
* platform/graphics/svg/SVGImageEmptyClients.h:
(WebCore::SVGEmptyDragClient::willPerformDragSourceAction):
(WebCore::SVGEmptyDragClient::startDrag):
(WebCore::SVGEmptyDragClient::createDragImageForLink):
Stubs FTW!
* platform/mac/ClipboardMac.h:
(WebCore::ClipboardMac::pasteboard):
Provide accessor for underlying NSPasteboard
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::hasData):
(WebCore::ClipboardMac::writeRange):
(WebCore::ClipboardMac::writeURL):
(WebCore::ClipboardMac::declareAndWriteDragImage):
(WebCore::ClipboardMac::createDragImage):
Implemented new Clipboarid functionality.
(WebCore::ClipboardMac::dragNSImage):
Made this a const method
* platform/mac/DragImageMac.mm: Added.
(WebCore::dragImageSize):
(WebCore::deleteDragImage):
(WebCore::scaleDragImage):
(WebCore::dissolveDragImageToFraction):
(WebCore::createDragImageFromImage):
(WebCore::createDragImageIconForCachedImage):
Implemented platform specific DragImage functions
* platform/mac/PasteboardMac.mm:
(WebCore::writeSelection):
(WebCore::Pasteboard::writeSelection):
(WebCore::writeURL):
(WebCore::Pasteboard::writeURL):
Extracted member implementations of these functions, so that
Clipboard could also make use of this functionality.
Pasteboard methods now call the new non-member implementations.
Also fixed implementations to respect the list of requested types.
* platform/qt/DragImageQt.cpp: Added.
(WebCore::dragImageSize):
(WebCore::deleteDragImage):
(WebCore::scaleDragImage):
(WebCore::dissolveDragImageToFraction):
(WebCore::createDragImageFromImage):
(WebCore::createDragImageIconForCachedImage):
Stubs
2007-02-17 David Hyatt <hyatt@apple.com>
Fix textarea resizers to not fill with black by making sure the fill color starts off as
......
......@@ -197,6 +197,7 @@ __ZN7WebCore12AtomicString3addEPNS_10StringImplE
__ZN7WebCore12EventHandler10mouseMovedEP7NSEvent
__ZN7WebCore12EventHandler10wheelEventEP7NSEvent
__ZN7WebCore12EventHandler12mouseDraggedEP7NSEvent
__ZN7WebCore12EventHandler14currentNSEventEv
__ZN7WebCore12EventHandler20handleTextInputEventERKNS_6StringEPNS_5EventEbb
__ZN7WebCore12EventHandler20hitTestResultAtPointERKNS_8IntPointEb
__ZN7WebCore12EventHandler20sendContextMenuEventERKNS_18PlatformMouseEventE
......
......@@ -1655,6 +1655,9 @@
A7CA595D0B27BD9E00FA021D /* DragController.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA595B0B27BD9E00FA021D /* DragController.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7CA595E0B27BD9E00FA021D /* DragController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CA595C0B27BD9E00FA021D /* DragController.cpp */; };
A7CA59630B27C1F200FA021D /* DragClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CA59620B27C1F200FA021D /* DragClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7CFB3D10B7ED10A0070C32D /* DragImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7CFB3CF0B7ED10A0070C32D /* DragImage.cpp */; };
A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */ = {isa = PBXBuildFile; fileRef = A7CFB3D00B7ED10A0070C32D /* DragImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7CFB3D50B7ED1180070C32D /* DragImageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */; };
A7D3C5240B576B4B002CA450 /* PasteboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */; settings = {ATTRIBUTES = (Private, ); }; };
A809F1470B73793A002E4D7F /* RenderSVGGradientStop.h in Headers */ = {isa = PBXBuildFile; fileRef = A809F1450B73793A002E4D7F /* RenderSVGGradientStop.h */; };
A809F1480B73793B002E4D7F /* RenderSVGGradientStop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A809F1460B73793A002E4D7F /* RenderSVGGradientStop.cpp */; };
......@@ -4667,8 +4670,11 @@
A79546420B5C4CB4007B438F /* DragData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DragData.cpp; sourceTree = "<group>"; };
A7B6E69D0B291A9600D0529F /* DragData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragData.h; sourceTree = "<group>"; };
A7CA595B0B27BD9E00FA021D /* DragController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragController.h; sourceTree = "<group>"; };
A7CA595C0B27BD9E00FA021D /* DragController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DragController.cpp; sourceTree = "<group>"; };
A7CA595C0B27BD9E00FA021D /* DragController.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 4; path = DragController.cpp; sourceTree = "<group>"; };
A7CA59620B27C1F200FA021D /* DragClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragClient.h; sourceTree = "<group>"; };
A7CFB3CF0B7ED10A0070C32D /* DragImage.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DragImage.cpp; sourceTree = "<group>"; };
A7CFB3D00B7ED10A0070C32D /* DragImage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DragImage.h; sourceTree = "<group>"; };
A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DragImageMac.mm; sourceTree = "<group>"; };
A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PasteboardHelper.h; sourceTree = "<group>"; };
A809F1450B73793A002E4D7F /* RenderSVGGradientStop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGGradientStop.h; sourceTree = "<group>"; };
A809F1460B73793A002E4D7F /* RenderSVGGradientStop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGGradientStop.cpp; sourceTree = "<group>"; };
......@@ -6801,6 +6807,7 @@
6582A14809999D6C00BEEB6D /* mac */ = {
isa = PBXGroup;
children = (
A7CFB3D40B7ED1180070C32D /* DragImageMac.mm */,
A795463D0B5C4C80007B438F /* DragDataMac.mm */,
06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */,
65A640F00533BB1F0085E777 /* BlockExceptions.h */,
......@@ -9052,6 +9059,8 @@
F587853C02DE375901EA4122 /* DeprecatedValueListImpl.cpp */,
F587853B02DE375901EA4122 /* DeprecatedValueListImpl.h */,
A7B6E69D0B291A9600D0529F /* DragData.h */,
A7CFB3D00B7ED10A0070C32D /* DragImage.h */,
A7CFB3CF0B7ED10A0070C32D /* DragImage.cpp */,
934FE9E40B5CA539003E4A73 /* FileChooser.cpp */,
066C772A0AB603B700238CC4 /* FileChooser.h */,
BC6D6DD009AF906600F59759 /* Font.cpp */,
......@@ -9640,6 +9649,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */,
A7D3C5240B576B4B002CA450 /* PasteboardHelper.h in Headers */,
A718760E0B2A120100A16ECE /* DragActions.h in Headers */,
A7B6E69F0B291A9600D0529F /* DragData.h in Headers */,
......@@ -11149,6 +11159,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
knownRegions = (
English,
......@@ -11163,6 +11174,7 @@
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
projectRoot = "";
shouldCheckCompatibility = 1;
targets = (
93F198A508245E59001E9ABC /* WebCore */,
DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
......@@ -12469,6 +12481,8 @@
933A142E0B7D188600A53FFD /* TextEvent.cpp in Sources */,
933A14AA0B7D1D0900A53FFD /* DOMTextEvent.mm in Sources */,
933A14B80B7D1D5200A53FFD /* JSTextEvent.cpp in Sources */,
A7CFB3D10B7ED10A0070C32D /* DragImage.cpp in Sources */,
A7CFB3D50B7ED1180070C32D /* DragImageMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -26,8 +26,24 @@
#include "config.h"
#include "Clipboard.h"
#include "DOMImplementation.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "Image.h"
#include "PlugInInfoStore.h"
namespace WebCore {
bool Clipboard::canSaveAsWebArchive(Frame* frame)
{
ASSERT(frame);
String mimeType = frame->loader()->responseMIMEType();
return !(DOMImplementation::isTextMIMEType(mimeType) ||
Image::supportsType(mimeType) ||
PlugInInfoStore::supportsMIMEType(mimeType));
}
void Clipboard::setAccessPolicy(ClipboardAccessPolicy policy)
{
// once you go numb, can never go back
......
......@@ -30,13 +30,20 @@
#include "AtomicString.h"
#include "ClipboardAccessPolicy.h"
#include "DragActions.h"
#include "DragImage.h"
#include "Node.h"
#include "Shared.h"
namespace WebCore {
class CachedImage;
class Element;
class Frame;
class Image;
class IntPoint;
class KURL;
class Range;
class String;
// State available during IE's events for drag and drop and copy/paste
class Clipboard : public Shared<Clipboard> {
......@@ -65,7 +72,15 @@ namespace WebCore {
virtual void setDragImage(CachedImage*, const IntPoint&) = 0;
virtual Node* dragImageElement() = 0;
virtual void setDragImageElement(Node*, const IntPoint&) = 0;
//Provides the DOM specified
virtual DragImageRef createDragImage(IntPoint& dragLoc) const = 0;
virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) = 0;
virtual void writeURL(const KURL&, const String&, Frame*) = 0;
virtual void writeRange(Range*, Frame*) = 0;
virtual bool hasData() = 0;
void setAccessPolicy(ClipboardAccessPolicy);
bool sourceOperation(DragOperation&) const;
......@@ -74,6 +89,7 @@ namespace WebCore {
void setDestinationOperation(DragOperation);
void setDragHasStarted() { m_dragStarted = true; }
static bool canSaveAsWebArchive(Frame*);
protected:
ClipboardAccessPolicy policy() const { return m_policy; }
bool dragStarted() const { return m_dragStarted; }
......
......@@ -28,21 +28,50 @@
#define DragClient_h
#include "DragActions.h"
#include "DragImage.h"
#include "IntPoint.h"
namespace WebCore {
#if PLATFORM(MAC)
#ifdef __OBJC__
@class DOMElement;
@class NSURL;
@class NSString;
@class NSPasteboard;
#else
class DOMElement;
class NSURL;
class NSString;
class NSPasteboard;
#endif
#endif
namespace WebCore {
class Clipboard;
class DragData;
class Frame;
class Image;
class HTMLImageElement;
class DragClient {
public:
virtual void willPerformDragDestinationAction(DragDestinationAction, DragData*) = 0;
virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*) = 0;
virtual DragDestinationAction actionMaskForDrag(DragData*) = 0;
virtual void dragControllerDestroyed() = 0;
//We work in window rather than view coordinates here
virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint& windowPoint) = 0;
virtual void startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame*, bool linkDrag = false) = 0;
virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*) = 0;
virtual void dragControllerDestroyed() = 0;
#if PLATFORM(MAC)
//Mac specific helper functions to allow access to functionality in webkit -- such as
//web archives and NSPasteboard extras
//not abstract as that would require another #if PLATFORM(MAC) for the SVGImage client empty impl
virtual void declareAndWriteDragImage(NSPasteboard*, DOMElement*, NSURL*, NSString*, Frame*, bool canSaveAsWebArchive) {};
#endif
virtual ~DragClient() {};
};
......
This diff is collapsed.
......@@ -27,7 +27,9 @@
#define DragController_h
#include "DragActions.h"
#include "DragImage.h"
#include "IntPoint.h"
#include "IntRect.h"
#include "KURL.h"
namespace WebCore {
......@@ -36,8 +38,13 @@ namespace WebCore {
class Document;
class DragClient;
class DragData;
class Element;
class Frame;
class Image;
class Node;
class Page;
class PlatformMouseEvent;
class Range;
class SelectionController;
class DragController {
......@@ -74,6 +81,14 @@ namespace WebCore {
bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos);
void dragEnded() { m_dragInitiator = 0; m_didInitiateDrag = false; }
bool startDrag(Frame* src, Clipboard*, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag);
static const int LinkDragBorderInset;
static const IntSize MaxDragImageSize;
static const int MaxOriginalImageArea;
static const int DragIconRightInset;
static const int DragIconBottomInset;
static const float DragImageAlpha;
private:
bool canProcessDrag(DragData*);
bool concludeDrag(DragData*, DragDestinationAction);
......@@ -85,7 +100,11 @@ namespace WebCore {
void cancelDrag();
bool dragIsMove(SelectionController*, DragData*);
bool isCopyKeyDown();
IntRect selectionDraggingRect(Frame*);
bool doDrag(Frame* src, Clipboard* clipboard, DragImageRef dragImage, const KURL& linkURL, const KURL& imageURL, Node* node, IntPoint& dragLoc, IntPoint& dragImageOffset);
void doImageDrag(Element*, const IntPoint&, const IntRect&, Clipboard*, Frame*, IntPoint&);
void doSystemDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool forLink);
Page* m_page;
DragClient* m_client;
......
......@@ -1353,9 +1353,133 @@ bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla
{
return !dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, dragState().m_dragClipboard.get());
}
bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
{
if (event.event().button() != LeftButton || event.event().eventType() != MouseEventMoved) {
// If we allowed the other side of the bridge to handle a drag
// last time, then m_mousePressed might still be set. So we
// clear it now to make sure the next move after a drag
// doesn't look like a drag.
m_mousePressed = false;
return false;
}
if (eventLoopHandleMouseDragged(event))
return true;
// Careful that the drag starting logic stays in sync with eventMayStartDrag()
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
allowDHTMLDrag(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA);
if (!dragState().m_dragSrcMayBeDHTML && !dragState().m_dragSrcMayBeUA)
m_mouseDownMayStartDrag = false; // no element is draggable
}
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
// try to find an element that wants to be dragged
HitTestRequest request(true, false);
HitTestResult result(m_mouseDownPos);
m_frame->renderer()->layer()->hitTest(request, result);
Node* node = result.innerNode();
if (node && node->renderer())
dragState().m_dragSrc = node->renderer()->draggableNode(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
else
dragState().m_dragSrc = 0;
if (!dragState().m_dragSrc)
m_mouseDownMayStartDrag = false; // no element is draggable
else {
// remember some facts about this source, while we have a HitTestResult handy
node = result.URLElement();
dragState().m_dragSrcIsLink = node && node->isLink();
node = result.innerNonSharedNode();
dragState().m_dragSrcIsImage = node && node->renderer() && node->renderer()->isImage();
dragState().m_dragSrcInSelection = m_frame->selectionController()->contains(m_mouseDownPos);
}
}
// For drags starting in the selection, the user must wait between the mousedown and mousedrag,
// or else we bail on the dragging stuff and allow selection to occur
if (m_mouseDownMayStartDrag && dragState().m_dragSrcInSelection && event.event().timestamp() - m_mouseDownTimestamp < TextDragDelay) {
m_mouseDownMayStartDrag = false;
// ...but if this was the first click in the window, we don't even want to start selection
if (eventActivatedView(event.event()))
m_mouseDownMayStartSelect = false;
}
if (!m_mouseDownMayStartDrag)
return !mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll;
// We are starting a text/image/url drag, so the cursor should be an arrow
m_frame->view()->setCursor(pointerCursor());
if (!dragHysteresisExceeded(event.event().pos()))
return true;
// Once we're past the hysteresis point, we don't want to treat this gesture as a click
invalidateClick();
DragOperation srcOp = DragOperationNone;
if (dragState().m_dragSrcMayBeDHTML) {
freeClipboard(); // would only happen if we missed a dragEnd. Do it anyway, just
// to make sure it gets numbified
dragState().m_dragClipboard = createDraggingClipboard();
// Check to see if the is a DOM based drag, if it is get the DOM specified drag
// image and offset
if (dragState().m_dragSrcIsDHTML) {
int srcX, srcY;
dragState().m_dragSrc->renderer()->absolutePosition(srcX, srcY);
IntSize delta = m_mouseDownPos - IntPoint(srcX, srcY);
dragState().m_dragClipboard->setDragImageElement(dragState().m_dragSrc.get(), IntPoint() + delta);
}
m_mouseDownMayStartDrag = dispatchDragSrcEvent(dragstartEvent, m_mouseDown)
&& !m_frame->selectionController()->isInPasswordField();
// Invalidate clipboard here against anymore pasteboard writing for security. The drag
// image can still be changed as we drag, but not the pasteboard data.
dragState().m_dragClipboard->setAccessPolicy(ClipboardImageWritable);
if (m_mouseDownMayStartDrag) {
// gather values from DHTML element, if it set any
dragState().m_dragClipboard->sourceOperation(srcOp);
// Yuck, dragSourceMovedTo() can be called as a result of kicking off the drag with
// dragImage! Because of that dumb reentrancy, we may think we've not started the
// drag when that happens. So we have to assume it's started before we kick it off.
dragState().m_dragClipboard->setDragHasStarted();
}
}
if (m_mouseDownMayStartDrag) {
DragController* dragController = m_frame->page() ? m_frame->page()->dragController() : 0;
bool startedDrag = dragController && dragController->startDrag(m_frame, dragState().m_dragClipboard.get(), srcOp, event.event(), m_mouseDownPos, dragState().m_dragSrcIsDHTML);
if (!startedDrag && dragState().m_dragSrcMayBeDHTML) {
// Drag was canned at the last minute - we owe m_dragSrc a DRAGEND event
PlatformMouseEvent event(PlatformMouseEvent::currentEvent);
dispatchDragSrcEvent(dragendEvent, event);
m_mouseDownMayStartDrag = false;
}
}
if (!m_mouseDownMayStartDrag) {
// something failed to start the drag, cleanup
freeClipboard();
dragState().m_dragSrc = 0;
}
// No more default handling (like selection), whether we're past the hysteresis bounds or not
return true;
}
bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent,
bool isLineBreak, bool isBackTab)
bool isLineBreak, bool isBackTab)
{
if (!m_frame)
return false;
......@@ -1373,7 +1497,8 @@ bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
ExceptionCode ec;
return target->dispatchEvent(event.release(), ec, true);
}
void EventHandler::defaultTextInputEventHandler(TextEvent* event)
{
String data = event->data();
......
......@@ -170,7 +170,9 @@ private:
RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
};
static EventHandlerDragState& dragState();
Clipboard* createDraggingClipboard() const;
bool eventActivatedView(const PlatformMouseEvent&) const;
void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& event);
......@@ -243,6 +245,7 @@ private:
NSView *mouseDownViewIfStillGood();
#else
bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&) { return false; }
bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&) { return false; }
#endif
Frame* m_frame;
......@@ -285,11 +288,11 @@ private:
IntPoint m_currentMousePosition;
IntPoint m_mouseDownPos; // in our view's coords
double m_mouseDownTimestamp;
PlatformMouseEvent m_mouseDown;
#if PLATFORM(MAC)
NSView *m_mouseDownView;
bool m_sendingEventToSubview;
PlatformMouseEvent m_mouseDown;
int m_activationEventNumber;
#endif
......
......@@ -30,6 +30,7 @@
#include "Color.h"
#include "EditAction.h"
#include "DragImage.h"
#include "RenderLayer.h"
#include "TextGranularity.h"
#include <wtf/unicode/Unicode.h>
......@@ -125,6 +126,8 @@ public:
friend class FrameQt;
friend class FrameWin;
DragImageRef dragImageForSelection();
private:
FramePrivate* d;
......
......@@ -33,6 +33,15 @@
namespace WebCore {
const int DragController::LinkDragBorderInset = -2;
const IntSize DragController::MaxDragImageSize(400, 400);
const int DragController::MaxOriginalImageArea = 1500 * 1500;
const int DragController::DragIconRightInset = 7;
const int DragController::DragIconBottomInset = 3;
const float DragController::DragImageAlpha = 0.75f;
bool DragController::isCopyKeyDown()
{
return [[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask;
......
......@@ -30,6 +30,7 @@
#include "ClipboardMac.h"
#include "Cursor.h"
#include "Document.h"
#include "DragController.h"
#include "EventNames.h"
#include "FloatPoint.h"
#include "FocusController.h"
......@@ -340,148 +341,14 @@ bool EventHandler::eventLoopHandleMouseDragged(const MouseEventWithHitTestResult
return true;
}
bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
Clipboard* EventHandler::createDraggingClipboard() const
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
if (event.event().button() != LeftButton || event.event().eventType() != MouseEventMoved) {
// If we allowed the other side of the bridge to handle a drag
// last time, then m_mousePressed might still be set. So we
// clear it now to make sure the next move after a drag
// doesn't look like a drag.
m_mousePressed = false;
return false;
}
if (eventLoopHandleMouseDragged(event))
return true;
// Careful that the drag starting logic stays in sync with eventMayStartDrag()
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
allowDHTMLDrag(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA);
if (!dragState().m_dragSrcMayBeDHTML && !dragState().m_dragSrcMayBeUA)
m_mouseDownMayStartDrag = false; // no element is draggable
}
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
// try to find an element that wants to be dragged
HitTestRequest request(true, false);
HitTestResult result(m_mouseDownPos);
m_frame->renderer()->layer()->hitTest(request, result);
Node* node = result.innerNode();
if (node && node->renderer())
dragState().m_dragSrc = node->renderer()->draggableNode(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
else
dragState().m_dragSrc = 0;
if (!dragState().m_dragSrc)
m_mouseDownMayStartDrag = false; // no element is draggable
else {
// remember some facts about this source, while we have a HitTestResult handy
node = result.URLElement();
dragState().m_dragSrcIsLink = node && node->isLink();