Commit 0eb6dc60 authored by dcheng@chromium.org's avatar dcheng@chromium.org

2011-05-13 Daniel Cheng <dcheng@chromium.org>

        Reviewed by Tony Chang.

        Improve drag start logic
        https://bugs.webkit.org/show_bug.cgi?id=59409

        Add a new test to test drag start edge cases on Mac (because of a non-zero text drag delay)
        as well as rebase an existing test.

        * fast/css/user-drag-none.html: Text nodes are no longer draggable.
        * platform/mac/editing/pasteboard/drag-selections-to-contenteditable-expected.txt: Added.
        * platform/mac/editing/pasteboard/drag-selections-to-contenteditable.html: Added.
2011-05-13  Daniel Cheng  <dcheng@chromium.org>

        Reviewed by Tony Chang.

        Improve drag start logic
        https://bugs.webkit.org/show_bug.cgi?id=59409

        Rewrite and simplify the dragging logic to better match IE, Firefox, and the behavior
        defined in the spec. Among other things:
        - draggableNode() no longer returns text nodes when dragging anchors.
        - When starting a drag over an image in a selection, prefer to drag the selection.
        - Several redundant hit tests have been removed.
        - Minor refactoring to make the logic easier to follow.

        Test: platform/mac/editing/pasteboard/drag-selections-to-contenteditable.html

        * WebCore.xcodeproj/project.pbxproj:
        * page/DragController.cpp:
        (WebCore::DragController::draggableNode):
        (WebCore::DragController::startDrag):
        * page/DragController.h:
        * page/DragState.h:
        (WebCore::DragState::shouldDispatchEvents):
        * page/EventHandler.cpp:
        (WebCore::EventHandler::EventHandler):
        (WebCore::EventHandler::eventMayStartDrag):
        (WebCore::EventHandler::updateDragSourceActionsAllowed):
        (WebCore::EventHandler::updateDragAndDrop):
        (WebCore::EventHandler::cancelDragAndDrop):
        (WebCore::EventHandler::dragHysteresisExceeded):
        (WebCore::EventHandler::dragSourceEndedAt):
        (WebCore::ExactlyOneBitSet):
        (WebCore::EventHandler::handleDrag):
        * page/EventHandler.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86472 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 14c5dd6c
2011-05-13 Daniel Cheng <dcheng@chromium.org>
Reviewed by Tony Chang.
Improve drag start logic
https://bugs.webkit.org/show_bug.cgi?id=59409
Add a new test to test drag start edge cases on Mac (because of a non-zero text drag delay)
as well as rebase an existing test.
* fast/css/user-drag-none.html: Text nodes are no longer draggable.
* platform/mac/editing/pasteboard/drag-selections-to-contenteditable-expected.txt: Added.
* platform/mac/editing/pasteboard/drag-selections-to-contenteditable.html: Added.
2011-05-13 Anders Carlsson <andersca@apple.com> 2011-05-13 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig. Reviewed by Sam Weinig.
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
<img class="drag-none" src="resources/greenbox.png"> <img class="drag-none" src="resources/greenbox.png">
</div> </div>
<div class="box" expect="IMG text text A nil"> <div class="box" expect="IMG A A A nil">
<a href="#"><img src="resources/greenbox.png">x<br><span>y</span></a> <a href="#"><img src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
<div class="box" expect="IMG text text A nil"> <div class="box" expect="IMG A A A nil">
<a href="#" class="drag-element"><img src="resources/greenbox.png">x<br><span>y</span></a> <a href="#" class="drag-element"><img src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
<a href="#" class="drag-none"><img src="resources/greenbox.png">x<br><span>y</span></a> <a href="#" class="drag-none"><img src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
<div class="box" expect="A text text A nil"> <div class="box" expect="A A A A nil">
<a href="#"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a> <a href="#"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
<div class="box" expect="A text text A nil"> <div class="box" expect="A A A A nil">
<a href="#" class="drag-element"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a> <a href="#" class="drag-element"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
...@@ -43,11 +43,11 @@ ...@@ -43,11 +43,11 @@
<a href="#" class="drag-none"><img src="resources/greenbox.png">x<br><span>y</span></a> <a href="#" class="drag-none"><img src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
<div class="box drag-element" expect="A text text A DIV"> <div class="box drag-element" expect="A A A A DIV">
<a href="#"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a> <a href="#"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
<div class="box drag-element" expect="A text text A DIV"> <div class="box drag-element" expect="A A A A DIV">
<a href="#" class="drag-element"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a> <a href="#" class="drag-element"><img class="drag-none" src="resources/greenbox.png">x<br><span>y</span></a>
</div> </div>
</div> </div>
......
  Link Random text.
Link Random text.
This test checks selection drag edge cases on Mac. To run the test manually:
Select everything above, start the drag over the image, and with no delay, drag it to the content editable area. Only the image should be dragged.
Select everything above, start the drag over the link, and with no delay, drag it to the content editable area. The entire selection should be dragged.
Select everything above, start the drag over the text, and with no delay, drag it to the content editable area. Nothing should be dragged, but a bunch of text should be selected instead.
Dumping info about contenteditable div:
Number of children: 4
Contents:
IMG
IMG
A
SPAN
Number of selected ranges: 1
<html>
<head>
<script>
function log(message) {
var console = document.getElementById("console");
var div = document.createElement("div");
var text = document.createTextNode(message);
console.appendChild(div);
div.appendChild(text);
}
function runTest() {
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
} else
return;
selectSelection();
dragElementToContentEditable(document.getElementById("dragimage"));
selectSelection();
dragElementToContentEditable(document.getElementById("draglink"));
selectSelection();
dragElementToContentEditable(document.getElementById("dragtext"));
var target = document.getElementById("target");
log("Dumping info about contenteditable div:");
log("Number of children: " + target.children.length);
log("Contents:");
log(target.children[0].tagName);
log(target.children[1].tagName);
log(target.children[2].tagName);
log(target.children[3].tagName);
log("Number of selected ranges: " + window.getSelection().rangeCount);
layoutTestController.notifyDone();
}
function selectSelection() {
window.getSelection().selectAllChildren(document.getElementById("selection"));
}
function dragElementToContentEditable(dragSource)
{
x = dragSource.offsetLeft + dragSource.offsetWidth / 2;
y = dragSource.offsetTop + dragSource.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
var dropTarget = document.getElementById("target");
x = dropTarget.offsetLeft + dropTarget.offsetWidth / 2;
y = dropTarget.offsetTop + dropTarget.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseUp();
}
</script>
</head>
<body style="padding:0; margin:0" onload="runTest();">
<div id="target" style="border: 1px solid black; width: 300px; height: 200px;" contenteditable="true"></div>
<div id="selection">
<img id="dragimage" src="../../../../editing/resources/abe.png">
<a href="#" id="draglink">Link</a>
<span id="dragtext">Random text.</span></div>
<p>This test checks selection drag edge cases on Mac. To run the test manually:
<ol>
<li>Select everything above, start the drag over the image, and with no delay, drag it to the content editable area. Only the image should be dragged.
<li>Select everything above, start the drag over the link, and with no delay, drag it to the content editable area. The entire selection should be dragged.
<li>Select everything above, start the drag over the text, and with no delay, drag it to the content editable area. Nothing should be dragged, but a bunch of text should be selected instead.
</ol>
</p>
<div id="console"></ul>
</body>
2011-05-13 Daniel Cheng <dcheng@chromium.org>
Reviewed by Tony Chang.
Improve drag start logic
https://bugs.webkit.org/show_bug.cgi?id=59409
Rewrite and simplify the dragging logic to better match IE, Firefox, and the behavior
defined in the spec. Among other things:
- draggableNode() no longer returns text nodes when dragging anchors.
- When starting a drag over an image in a selection, prefer to drag the selection.
- Several redundant hit tests have been removed.
- Minor refactoring to make the logic easier to follow.
Test: platform/mac/editing/pasteboard/drag-selections-to-contenteditable.html
* WebCore.xcodeproj/project.pbxproj:
* page/DragController.cpp:
(WebCore::DragController::draggableNode):
(WebCore::DragController::startDrag):
* page/DragController.h:
* page/DragState.h:
(WebCore::DragState::shouldDispatchEvents):
* page/EventHandler.cpp:
(WebCore::EventHandler::EventHandler):
(WebCore::EventHandler::eventMayStartDrag):
(WebCore::EventHandler::updateDragSourceActionsAllowed):
(WebCore::EventHandler::updateDragAndDrop):
(WebCore::EventHandler::cancelDragAndDrop):
(WebCore::EventHandler::dragHysteresisExceeded):
(WebCore::EventHandler::dragSourceEndedAt):
(WebCore::ExactlyOneBitSet):
(WebCore::EventHandler::handleDrag):
* page/EventHandler.h:
2011-05-13 Oliver Hunt <oliver@apple.com> 2011-05-13 Oliver Hunt <oliver@apple.com>
Reviewed by Geoffrey Garen. Reviewed by Geoffrey Garen.
...@@ -1675,7 +1675,7 @@ ...@@ -1675,7 +1675,7 @@
81BE209911F4AB8D00915DFA /* IDBCursorBackendInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE209411F4AB8D00915DFA /* IDBCursorBackendInterface.h */; }; 81BE209911F4AB8D00915DFA /* IDBCursorBackendInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE209411F4AB8D00915DFA /* IDBCursorBackendInterface.h */; };
81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; }; 81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; };
81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; }; 81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; };
81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; }; 81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; settings = {ATTRIBUTES = (Private, ); }; };
82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; }; 82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; };
82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; }; 82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; };
82AB1773125C826700C5069D /* InspectorStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */; }; 82AB1773125C826700C5069D /* InspectorStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */; };
This diff is collapsed.
...@@ -37,6 +37,7 @@ namespace WebCore { ...@@ -37,6 +37,7 @@ namespace WebCore {
class Document; class Document;
class DragClient; class DragClient;
class DragData; class DragData;
struct DragState;
class Element; class Element;
class Frame; class Frame;
class FrameSelection; class FrameSelection;
...@@ -75,13 +76,12 @@ namespace WebCore { ...@@ -75,13 +76,12 @@ namespace WebCore {
DragDestinationAction dragDestinationAction() const { return m_dragDestinationAction; } DragDestinationAction dragDestinationAction() const { return m_dragDestinationAction; }
DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint); DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint);
Node* draggableNode(const Frame*, Node*, bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const; Node* draggableNode(const Frame*, Node*, const IntPoint&, DragState&) const;
bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos, Node*) const;
void dragEnded(); void dragEnded();
void placeDragCaret(const IntPoint&); void placeDragCaret(const IntPoint&);
bool startDrag(Frame* src, Clipboard*, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag); bool startDrag(Frame* src, const DragState&, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin);
static const IntSize& maxDragImageSize(); static const IntSize& maxDragImageSize();
static const int LinkDragBorderInset; static const int LinkDragBorderInset;
......
...@@ -26,23 +26,29 @@ ...@@ -26,23 +26,29 @@
#ifndef DragState_h #ifndef DragState_h
#define DragState_h #define DragState_h
#include "DragActions.h"
#include <wtf/Forward.h> #include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h> #include <wtf/RefPtr.h>
namespace WebCore { namespace WebCore {
class Clipboard;
class Node;
struct DragState { struct DragState {
WTF_MAKE_NONCOPYABLE(DragState); WTF_MAKE_NONCOPYABLE(DragState);
WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_FAST_ALLOCATED;
public: public:
enum EventDispatchPolicy {
DoNotDispatchEvents,
DispatchEvents,
};
DragState() { } DragState() { }
bool shouldDispatchEvents() const { return m_eventDispatchPolicy == DispatchEvents; }
RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
bool m_dragSrcIsLink; EventDispatchPolicy m_eventDispatchPolicy;
bool m_dragSrcIsImage; DragSourceAction m_dragType;
bool m_dragSrcInSelection;
bool m_dragSrcMayBeDHTML;
bool m_dragSrcMayBeUA; // Are DHTML and/or the UserAgent allowed to drag out?
bool m_dragSrcIsDHTML;
RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
}; };
......
This diff is collapsed.
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define EventHandler_h #define EventHandler_h
#include "DragActions.h" #include "DragActions.h"
#include "DragState.h"
#include "FocusDirection.h" #include "FocusDirection.h"
#include "HitTestRequest.h" #include "HitTestRequest.h"
#include "PlatformMouseEvent.h" #include "PlatformMouseEvent.h"
...@@ -49,7 +50,6 @@ namespace WebCore { ...@@ -49,7 +50,6 @@ namespace WebCore {
class Clipboard; class Clipboard;
class Cursor; class Cursor;
struct DragState;
class Event; class Event;
class EventTarget; class EventTarget;
class FloatPoint; class FloatPoint;
...@@ -323,7 +323,7 @@ private: ...@@ -323,7 +323,7 @@ private:
void defaultArrowEventHandler(FocusDirection, KeyboardEvent*); void defaultArrowEventHandler(FocusDirection, KeyboardEvent*);
#if ENABLE(DRAG_SUPPORT) #if ENABLE(DRAG_SUPPORT)
void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const; DragSourceAction updateDragSourceActionsAllowed() const;
#endif #endif
// The following are called at the beginning of handleMouseUp and handleDrag. // The following are called at the beginning of handleMouseUp and handleDrag.
...@@ -360,6 +360,7 @@ private: ...@@ -360,6 +360,7 @@ private:
bool m_mouseDownMayStartSelect; bool m_mouseDownMayStartSelect;
#if ENABLE(DRAG_SUPPORT) #if ENABLE(DRAG_SUPPORT)
bool m_mouseDownMayStartDrag; bool m_mouseDownMayStartDrag;
bool m_dragMayStartSelectionInstead;
#endif #endif
bool m_mouseDownWasSingleClickInSelection; bool m_mouseDownWasSingleClickInSelection;
bool m_beganSelectingText; bool m_beganSelectingText;
......
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