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

Use Element instead of Node in DragState, also redo DragState struct

https://bugs.webkit.org/show_bug.cgi?id=116411

Reviewed by Sam Weinig.

The drag source is an element, so use RefPtr<Element> instead of RefPtr<Node>.

Also, the entire drag state is about dragging, so no need for the word "drag" in the
name of its members. Also, it's a struct, so the members don't need m_ prefixes.

* page/DragController.cpp: Removed unneeded include of Node.h since it's included by
Element.h, which is also included.
(WebCore::DragController::draggableElement): Renamed from Node to Element and changed
the types and names of arguments accordingly. Also made this function handle a
startElement of 0 so callers don't need to. Also updated for changes to DragState members.
(WebCore::DragController::startDrag): Updated for changes to DragState members.
Since dragSource can only be an element, was able to get rid of isElementNode checks.

* page/DragController.h: Fixed style of forward declarations of structs. Updated for
change of draggableNode to draggableElement. Also removed declarations of nonexistent
selectionDraggingRect and doDrag functions.

* page/DragState.h: Rewrote practically this whole header. Added an include of Element
instead of Node since that's what we use now. Removed includes that are redundant.
There's no problem copying a DragState, so removed WTF_MAKE_NONCOPYABLE. There's no need
to allocate a DragState on the heap, so removed WTF_MAKE_FAST_ALLOCATED. The event dispatch
boolean is never set to a constant, so there's no need for a policy enum; it can just be
a boolean. Removed the "m_" prefixes from the struct members, since this is a struct with
public members and we don't use the prefix in those cases. Removed the word "drag" from the
struct member names since this entire struct is about dragging and has drag in its name.
Left the comments mostly intact, even though I'm not certain of their value.

* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent): Updated for changes to DragState.
(WebCore::EventHandler::eventMayStartDrag):
Use innerElement instead of innerNode to call draggableElement instead of draggableNode.
(WebCore::EventHandler::updateDragAndDrop): Updated for changes to DragState.
(WebCore::EventHandler::cancelDragAndDrop): Ditto.
(WebCore::EventHandler::handleWheelEvent): Added FIXME.
(WebCore::EventHandler::dragHysteresisExceeded): Updated for changes to DragState.
(WebCore::EventHandler::freeClipboard): Updated for changes to DragState. Also re-added
code to release the clipboard object, which is needed here to avoid keeping it around in
memory until the next drag.
(WebCore::EventHandler::dragSourceEndedAt): Updated for changes to DragState.
(WebCore::EventHandler::updateDragStateAfterEditDragIfNeeded): Ditto.
(WebCore::EventHandler::dispatchDragSrcEvent): Ditto.
(WebCore::EventHandler::handleDrag): Updated for changes to DragState. Use innerElement
instead of innerNode to call draggableElement instead of draggableNode. No longer need to
null check innerElement because draggableElement does that. Removed unneeded else that was
setting m_dragSrc to zero since it's guaranteed to already be zero.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@150354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 247ec59d
2013-05-19 Darin Adler <darin@apple.com>
Use Element instead of Node in DragState, also redo DragState struct
https://bugs.webkit.org/show_bug.cgi?id=116411
Reviewed by Sam Weinig.
The drag source is an element, so use RefPtr<Element> instead of RefPtr<Node>.
Also, the entire drag state is about dragging, so no need for the word "drag" in the
name of its members. Also, it's a struct, so the members don't need m_ prefixes.
* page/DragController.cpp: Removed unneeded include of Node.h since it's included by
Element.h, which is also included.
(WebCore::DragController::draggableElement): Renamed from Node to Element and changed
the types and names of arguments accordingly. Also made this function handle a
startElement of 0 so callers don't need to. Also updated for changes to DragState members.
(WebCore::DragController::startDrag): Updated for changes to DragState members.
Since dragSource can only be an element, was able to get rid of isElementNode checks.
* page/DragController.h: Fixed style of forward declarations of structs. Updated for
change of draggableNode to draggableElement. Also removed declarations of nonexistent
selectionDraggingRect and doDrag functions.
* page/DragState.h: Rewrote practically this whole header. Added an include of Element
instead of Node since that's what we use now. Removed includes that are redundant.
There's no problem copying a DragState, so removed WTF_MAKE_NONCOPYABLE. There's no need
to allocate a DragState on the heap, so removed WTF_MAKE_FAST_ALLOCATED. The event dispatch
boolean is never set to a constant, so there's no need for a policy enum; it can just be
a boolean. Removed the "m_" prefixes from the struct members, since this is a struct with
public members and we don't use the prefix in those cases. Removed the word "drag" from the
struct member names since this entire struct is about dragging and has drag in its name.
Left the comments mostly intact, even though I'm not certain of their value.
* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent): Updated for changes to DragState.
(WebCore::EventHandler::eventMayStartDrag):
Use innerElement instead of innerNode to call draggableElement instead of draggableNode.
(WebCore::EventHandler::updateDragAndDrop): Updated for changes to DragState.
(WebCore::EventHandler::cancelDragAndDrop): Ditto.
(WebCore::EventHandler::handleWheelEvent): Added FIXME.
(WebCore::EventHandler::dragHysteresisExceeded): Updated for changes to DragState.
(WebCore::EventHandler::freeClipboard): Updated for changes to DragState. Also re-added
code to release the clipboard object, which is needed here to avoid keeping it around in
memory until the next drag.
(WebCore::EventHandler::dragSourceEndedAt): Updated for changes to DragState.
(WebCore::EventHandler::updateDragStateAfterEditDragIfNeeded): Ditto.
(WebCore::EventHandler::dispatchDragSrcEvent): Ditto.
(WebCore::EventHandler::handleDrag): Updated for changes to DragState. Use innerElement
instead of innerNode to call draggableElement instead of draggableNode. No longer need to
null check innerElement because draggableElement does that. Removed unneeded else that was
setting m_dragSrc to zero since it's guaranteed to already be zero.
2013-05-19 Anders Carlsson <andersca@apple.com>
Remove ChromeClient::webView()
......
/*
* Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2007, 2009, 2010, 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
......@@ -59,7 +59,6 @@
#include "Image.h"
#include "ImageOrientation.h"
#include "MoveSelectionCommand.h"
#include "Node.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PluginDocument.h"
......@@ -635,17 +634,19 @@ bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
return true;
}
Node* DragController::draggableNode(const Frame* src, Node* startNode, const IntPoint& dragOrigin, DragState& state) const
Element* DragController::draggableElement(const Frame* sourceFrame, Element* startElement, const IntPoint& dragOrigin, DragState& state) const
{
state.m_dragType = (src->selection()->contains(dragOrigin)) ? DragSourceActionSelection : DragSourceActionNone;
state.type = (sourceFrame->selection()->contains(dragOrigin)) ? DragSourceActionSelection : DragSourceActionNone;
if (!startElement)
return 0;
for (const RenderObject* renderer = startNode->renderer(); renderer; renderer = renderer->parent()) {
for (const RenderObject* renderer = startElement->renderer(); renderer; renderer = renderer->parent()) {
Node* node = renderer->nonPseudoNode();
if (!node)
// Anonymous render blocks don't correspond to actual DOM nodes, so we skip over them
// for the purposes of finding a draggable node.
continue;
if (!(state.m_dragType & DragSourceActionSelection) && node->isTextNode() && node->canStartSelection())
if (!(state.type & DragSourceActionSelection) && node->isTextNode() && node->canStartSelection())
// In this case we have a click in the unselected portion of text. If this text is
// selectable, we want to start the selection process instead of looking for a parent
// to try to drag.
......@@ -653,29 +654,29 @@ Node* DragController::draggableNode(const Frame* src, Node* startNode, const Int
if (node->isElementNode()) {
EUserDrag dragMode = renderer->style()->userDrag();
if ((m_dragSourceAction & DragSourceActionDHTML) && dragMode == DRAG_ELEMENT) {
state.m_dragType = static_cast<DragSourceAction>(state.m_dragType | DragSourceActionDHTML);
return node;
state.type = static_cast<DragSourceAction>(state.type | DragSourceActionDHTML);
return toElement(node);
}
if (dragMode == DRAG_AUTO) {
if ((m_dragSourceAction & DragSourceActionImage)
&& node->hasTagName(HTMLNames::imgTag)
&& src->settings()
&& src->settings()->loadsImagesAutomatically()) {
state.m_dragType = static_cast<DragSourceAction>(state.m_dragType | DragSourceActionImage);
return node;
&& sourceFrame->settings()
&& sourceFrame->settings()->loadsImagesAutomatically()) {
state.type = static_cast<DragSourceAction>(state.type | DragSourceActionImage);
return toElement(node);
}
if ((m_dragSourceAction & DragSourceActionLink)
&& node->hasTagName(HTMLNames::aTag)
&& static_cast<HTMLAnchorElement*>(node)->isLiveLink()) {
state.m_dragType = static_cast<DragSourceAction>(state.m_dragType | DragSourceActionLink);
return node;
state.type = static_cast<DragSourceAction>(state.type | DragSourceActionLink);
return toElement(node);
}
}
}
}
// We either have nothing to drag or we have a selection and we're not over a draggable element.
return (state.m_dragType & DragSourceActionSelection) ? startNode : 0;
return (state.type & DragSourceActionSelection) ? startElement : 0;
}
static CachedImage* getCachedImage(Element* element)
......@@ -748,7 +749,7 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
return false;
HitTestResult hitTestResult = src->eventHandler()->hitTestResultAtPoint(dragOrigin, HitTestRequest::ReadOnly | HitTestRequest::Active);
if (!state.m_dragSrc->contains(hitTestResult.innerNode()))
if (!state.source->contains(hitTestResult.innerNode()))
// The original node being dragged isn't under the drag origin anymore... maybe it was
// hidden or moved out from under the cursor. Regardless, we don't want to start a drag on
// something that's not actually under the drag origin.
......@@ -765,10 +766,10 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
IntPoint dragLoc(0, 0);
IntPoint dragImageOffset(0, 0);
Clipboard* clipboard = state.m_dragClipboard.get();
if (state.m_dragType == DragSourceActionDHTML)
Clipboard* clipboard = state.clipboard.get();
if (state.type == DragSourceActionDHTML)
dragImage = clipboard->createDragImage(dragImageOffset);
if (state.m_dragType == DragSourceActionSelection || !imageURL.isEmpty() || !linkURL.isEmpty())
if (state.type == DragSourceActionSelection || !imageURL.isEmpty() || !linkURL.isEmpty())
// Selection, image, and link drags receive a default set of allowed drag operations that
// follows from:
// http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebHTMLView.mm?rev=48526#L3430
......@@ -783,10 +784,10 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
bool startedDrag = true; // optimism - we almost always manage to start the drag
Node* node = state.m_dragSrc.get();
Element* element = state.source.get();
Image* image = node->isElementNode() ? getImage(toElement(node)) : 0;
if (state.m_dragType == DragSourceActionSelection) {
Image* image = getImage(element);
if (state.type == DragSourceActionSelection) {
if (!clipboard->hasData()) {
if (enclosingTextFormControl(src->selection()->start()))
clipboard->writePlainText(src->editor().selectedTextForClipboard());
......@@ -804,12 +805,11 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
}
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false);
} else if (!imageURL.isEmpty() && node && node->isElementNode() && image && !image->isNull()
} else if (!imageURL.isEmpty() && element && image && !image->isNull()
&& (m_dragSourceAction & DragSourceActionImage)) {
// We shouldn't be starting a drag for an image that can't provide an extension.
// This is an early detection for problems encountered later upon drop.
ASSERT(!image->filenameExtension().isEmpty());
Element* element = toElement(node);
if (!clipboard->hasData()) {
m_draggingImageURL = imageURL;
prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, hitTestResult.altDisplayString());
......@@ -849,12 +849,12 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
}
doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true);
} else if (state.m_dragType == DragSourceActionDHTML) {
} else if (state.type == DragSourceActionDHTML) {
ASSERT(m_dragSourceAction & DragSourceActionDHTML);
m_client->willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, clipboard);
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false);
} else {
// draggableNode() determined an image or link node was draggable, but it turns out the
// draggableElement() determined an image or link node was draggable, but it turns out the
// image or link had no URL, so there is nothing to drag.
startedDrag = false;
}
......
......@@ -37,8 +37,6 @@ namespace WebCore {
class Document;
class DragClient;
class DragData;
struct DragSession;
struct DragState;
class Element;
class Frame;
class FrameSelection;
......@@ -49,7 +47,10 @@ namespace WebCore {
class Page;
class PlatformMouseEvent;
class Range;
struct DragSession;
struct DragState;
class DragController {
WTF_MAKE_NONCOPYABLE(DragController); WTF_MAKE_FAST_ALLOCATED;
public:
......@@ -78,7 +79,7 @@ namespace WebCore {
DragDestinationAction dragDestinationAction() const { return m_dragDestinationAction; }
DragSourceAction delegateDragSourceAction(const IntPoint& rootViewPoint);
Node* draggableNode(const Frame*, Node*, const IntPoint&, DragState&) const;
Element* draggableElement(const Frame*, Element* start, const IntPoint&, DragState&) const;
void dragEnded();
void placeDragCaret(const IntPoint&);
......@@ -109,8 +110,6 @@ namespace WebCore {
void mouseMovedIntoDocument(Document*);
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);
void cleanupAfterSystemDrag();
......
/*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 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
......@@ -28,30 +29,15 @@
#include "Clipboard.h"
#include "DragActions.h"
#include "Node.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
#include "Element.h"
namespace WebCore {
class Clipboard;
class Node;
struct DragState {
WTF_MAKE_NONCOPYABLE(DragState);
WTF_MAKE_FAST_ALLOCATED;
public:
enum EventDispatchPolicy {
DoNotDispatchEvents,
DispatchEvents,
};
DragState() { }
bool shouldDispatchEvents() const { return m_eventDispatchPolicy == DispatchEvents; }
RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
EventDispatchPolicy m_eventDispatchPolicy;
DragSourceAction m_dragType;
RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
RefPtr<Element> source; // Element that may be a drag source, for the current mouse gesture.
bool shouldDispatchEvents;
DragSourceAction type;
RefPtr<Clipboard> clipboard; // Used on only the source side of dragging.
};
} // namespace WebCore
......
This diff is collapsed.
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