Commit b63b2932 authored by oliver's avatar oliver

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

        Reviewed by Ada, Lou and Steve.

        Moving basic components of ClipboardMac to Clipboard, 
        last of the basic common code merge will come later (namely setting the 
        drag element/image).
        
        Tidying up in DragController including a few bad PassRefPtr uses and
        removing unnecessary accessors.  Also initialise fields properly to
        fix <rdar:/problems/5014889>

        * dom/Clipboard.cpp:
        (WebCore::Clipboard::Clipboard):
          New constructor
          
        * dom/Clipboard.h:
        (WebCore::Clipboard::isForDragging):
        (WebCore::Clipboard::dragLocation):
        (WebCore::Clipboard::dragImage):
        (WebCore::Clipboard::dragImageElement):
          Exposing common data
          
        * page/DragController.cpp:
        (WebCore::DragController::DragController):
          Initialise m_isHandlingDrag (oops)
        (WebCore::documentFragmentFromDragData):
        (WebCore::DragController::tryDocumentDrag):
          Fixing PassRefPtr misuse
        (WebCore::DragController::canProcessDrag):
        (WebCore::DragController::startDrag):
        (WebCore::DragController::doSystemDrag):
          Make sure we're using the correct coordinate space
          
        * page/EventHandler.cpp:
        (WebCore::EventHandler::handleDrag):
          Reset drag source correctly
          
        * platform/mac/ClipboardMac.h:
        * platform/mac/ClipboardMac.mm:
        (WebCore::ClipboardMac::ClipboardMac):
          update constructor to use new Clipboard constructor



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@19808 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 85492aca
2007-02-22 Oliver Hunt <oliver@apple.com>
Reviewed by Ada, Lou and Steve.
Moving basic components of ClipboardMac to Clipboard,
last of the basic common code merge will come later (namely setting the
drag element/image).
Tidying up in DragController including a few bad PassRefPtr uses and
removing unnecessary accessors. Also initialise fields properly to
fix <rdar:/problems/5014889>
* dom/Clipboard.cpp:
(WebCore::Clipboard::Clipboard):
New constructor
* dom/Clipboard.h:
(WebCore::Clipboard::isForDragging):
(WebCore::Clipboard::dragLocation):
(WebCore::Clipboard::dragImage):
(WebCore::Clipboard::dragImageElement):
Exposing common data
* page/DragController.cpp:
(WebCore::DragController::DragController):
Initialise m_isHandlingDrag (oops)
(WebCore::documentFragmentFromDragData):
(WebCore::DragController::tryDocumentDrag):
Fixing PassRefPtr misuse
(WebCore::DragController::canProcessDrag):
(WebCore::DragController::startDrag):
(WebCore::DragController::doSystemDrag):
Make sure we're using the correct coordinate space
* page/EventHandler.cpp:
(WebCore::EventHandler::handleDrag):
Reset drag source correctly
* platform/mac/ClipboardMac.h:
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::ClipboardMac):
update constructor to use new Clipboard constructor
2007-02-22 Adele Peterson <adele@apple.com>
Reviewed by Darin.
......
......@@ -34,6 +34,14 @@
namespace WebCore {
Clipboard::Clipboard(ClipboardAccessPolicy policy, bool isForDragging)
: m_policy(policy)
, m_dragStarted(false)
, m_forDragging(isForDragging)
, m_dragImage(0)
{
}
bool Clipboard::canSaveAsWebArchive(Frame* frame)
{
ASSERT(frame);
......
......@@ -31,6 +31,7 @@
#include "ClipboardAccessPolicy.h"
#include "DragActions.h"
#include "DragImage.h"
#include "IntPoint.h"
#include "Node.h"
#include "Shared.h"
......@@ -40,7 +41,6 @@ namespace WebCore {
class Element;
class Frame;
class Image;
class IntPoint;
class KURL;
class Range;
class String;
......@@ -48,11 +48,11 @@ namespace WebCore {
// State available during IE's events for drag and drop and copy/paste
class Clipboard : public Shared<Clipboard> {
public:
Clipboard(ClipboardAccessPolicy policy) : m_policy(policy), m_dragStarted(false) { }
Clipboard(ClipboardAccessPolicy policy, bool isForDragging);
virtual ~Clipboard() { }
// Is this operation a drag-drop or a copy-paste?
virtual bool isForDragging() const = 0;
bool isForDragging() const { return m_forDragging; }
String dropEffect() const { return m_dropEffect; }
void setDropEffect(const String&);
......@@ -67,10 +67,10 @@ namespace WebCore {
// extensions beyond IE's API
virtual HashSet<String> types() const = 0;
virtual IntPoint dragLocation() const = 0;
virtual CachedImage* dragImage() const = 0;
IntPoint dragLocation() const { return m_dragLoc; }
CachedImage* dragImage() const { return m_dragImage; }
virtual void setDragImage(CachedImage*, const IntPoint&) = 0;
virtual Node* dragImageElement() = 0;
Node* dragImageElement() { return m_dragImageElement.get(); }
virtual void setDragImageElement(Node*, const IntPoint&) = 0;
//Provides the DOM specified
......@@ -90,14 +90,22 @@ namespace WebCore {
void setDragHasStarted() { m_dragStarted = true; }
static bool canSaveAsWebArchive(Frame*);
protected:
ClipboardAccessPolicy policy() const { return m_policy; }
bool dragStarted() const { return m_dragStarted; }
private:
ClipboardAccessPolicy m_policy;
String m_dropEffect;
String m_effectAllowed;
bool m_dragStarted;
protected:
bool m_forDragging;
IntPoint m_dragLoc;
CachedImage* m_dragImage;
RefPtr<Node> m_dragImageElement;
};
} // namespace WebCore
......
......@@ -76,6 +76,7 @@ DragController::DragController(Page* page, DragClient* client)
, m_dragDestinationAction(DragDestinationActionNone)
, m_dragSourceAction(DragSourceActionNone)
, m_didInitiateDrag(false)
, m_isHandlingDrag(false)
, m_dragOperation(DragOperationNone)
{
}
......@@ -94,7 +95,7 @@ static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragD
Document* document = context->startNode()->document();
ASSERT(document);
if (document && dragData->containsCompatibleContent()) {
if (DocumentFragment* fragment = dragData->asFragment(document).get())
if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(document))
return fragment;
if (dragData->containsURL()) {
......@@ -259,12 +260,10 @@ DragOperation DragController::tryDocumentDrag(DragData* dragData, DragDestinatio
operation = tryDHTMLDrag(dragData);
m_isHandlingDrag = operation != DragOperationNone;
RefPtr<FrameView> frameView = 0;
if (!m_document || !(frameView = m_document->view()))
RefPtr<FrameView> frameView = m_document->view();
if (!frameView)
return operation;
if ((actionMask & DragDestinationActionEdit) && !m_isHandlingDrag && canProcessDrag(dragData)) {
if (dragData->containsColor())
return DragOperationGeneric;
......@@ -376,17 +375,18 @@ bool DragController::canProcessDrag(DragData* dragData)
if (!dragData->containsCompatibleContent())
return false;
IntPoint point = m_document->view()->windowToContents(dragData->clientPosition());
IntPoint point = m_page->mainFrame()->view()->windowToContents(dragData->clientPosition());
HitTestResult result = HitTestResult(point);
if (!m_page->mainFrame()->renderer())
return false;
result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, true);
if (!result.innerNonSharedNode() || !result.innerNonSharedNode()->isContentEditable())
if (!result.innerNonSharedNode() || !result.innerNonSharedNode()->isContentEditable())
return false;
if (m_didInitiateDrag && m_document == m_dragInitiator && result.isSelected())
return false;
return true;
}
......@@ -592,7 +592,7 @@ bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation s
m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset);
dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
}
doSystemDrag(dragImage, dragLoc, src->view()->contentsToWindow(mouseDraggedPoint), clipboard, src, true);
doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true);
} else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) {
RefPtr<Range> selectionRange = src->selectionController()->toRange();
ASSERT(selectionRange);
......@@ -672,7 +672,8 @@ void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, c
// Protect this frame and view, as a load may occur mid drag and attempt to unload this frame
RefPtr<Frame> frameProtector = m_page->mainFrame();
RefPtr<FrameView> viewProtector = frameProtector->view();
m_client->startDrag(image, viewProtector->windowToContents(frame->view()->contentsToWindow(dragLoc)), eventPos, clipboard, frameProtector.get(), forLink);
m_client->startDrag(image, viewProtector->windowToContents(frame->view()->contentsToWindow(dragLoc)),
viewProtector->windowToContents(frame->view()->contentsToWindow(eventPos)), clipboard, frameProtector.get(), forLink);
// Drag has ended, dragEnded *should* have been called, however it is possible
// for the UIDelegate to take over the drag, and fail to send the appropriate
......
......@@ -1376,7 +1376,7 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
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);
......@@ -1407,6 +1407,7 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
// 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;
dragState().m_dragSrc = 0;
// ...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;
......
......@@ -51,8 +51,6 @@ class ClipboardMac : public Clipboard, public CachedResourceClient {
public:
ClipboardMac(bool forDragging, NSPasteboard *, ClipboardAccessPolicy, Frame* = 0);
virtual ~ClipboardMac();
bool isForDragging() const;
void clearData(const String& type);
void clearAllData();
......@@ -64,10 +62,7 @@ public:
// extensions beyond IE's API
virtual HashSet<String> types() const;
IntPoint dragLocation() const; // same point as client passed us
CachedImage* dragImage() const;
void setDragImage(CachedImage*, const IntPoint&);
Node* dragImageElement();
void setDragImageElement(Node *, const IntPoint&);
virtual DragImageRef createDragImage(IntPoint& dragLoc) const;
......@@ -82,10 +77,6 @@ private:
void setDragImage(CachedImage*, Node*, const IntPoint&);
RetainPtr<NSPasteboard> m_pasteboard;
bool m_forDragging;
IntPoint m_dragLoc;
CachedImage* m_dragImage;
RefPtr<Node> m_dragImageElement;
int m_changeCount;
Frame* m_frame; // used on the source side to generate dragging images
};
......
......@@ -50,10 +50,8 @@
namespace WebCore {
ClipboardMac::ClipboardMac(bool forDragging, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame *frame)
: Clipboard(policy)
: Clipboard(policy, forDragging)
, m_pasteboard(pasteboard)
, m_forDragging(forDragging)
, m_dragImage(0)
, m_frame(frame)
{
m_changeCount = [m_pasteboard.get() changeCount];
......@@ -68,11 +66,6 @@ bool ClipboardMac::hasData()
return m_pasteboard && [m_pasteboard.get() types] && [[m_pasteboard.get() types] count] > 0;
}
bool ClipboardMac::isForDragging() const
{
return m_forDragging;
}
static NSString *cocoaTypeFromMIMEType(const String& type)
{
String qType = type.stripWhiteSpace();
......@@ -277,26 +270,11 @@ HashSet<String> ClipboardMac::types() const
// The rest of these getters don't really have any impact on security, so for now make no checks
IntPoint ClipboardMac::dragLocation() const
{
return m_dragLoc;
}
CachedImage* ClipboardMac::dragImage() const
{
return m_dragImage;
}
void ClipboardMac::setDragImage(CachedImage* img, const IntPoint &loc)
{
setDragImage(img, 0, loc);
}
Node *ClipboardMac::dragImageElement()
{
return m_dragImageElement.get();
}
void ClipboardMac::setDragImageElement(Node *node, const IntPoint &loc)
{
setDragImage(0, node, loc);
......
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