Commit 252dcbe7 authored by dcheng@chromium.org's avatar dcheng@chromium.org

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

        Reviewed by Tony Chang.

        Refactor RenderObject::draggableNode.
        https://bugs.webkit.org/show_bug.cgi?id=60503

        This patch lays the ground for refactoring the drag start logic. It moves draggableNode to
        DragController to avoid the awkward plumbing of calling DragController from RenderObject and
        also moves EventHandlerDragState out from EventHandler so it can be shared between
        EventHandler and DragController where appropriate.

        No new tests since there should be no behavior change.

        * GNUmakefile.list.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * page/DragController.cpp:
        (WebCore::DragController::draggableNode):
        (WebCore::DragController::mayStartDragAtEventLocation):
        * page/DragController.h:
        * page/DragState.h: Added.
        (WebCore::DragState::DragState):
        * page/EventHandler.cpp:
        (WebCore::EventHandler::dragState):
        (WebCore::EventHandler::eventMayStartDrag):
        (WebCore::EventHandler::handleDrag):
        * page/EventHandler.h:
        * rendering/RenderObject.cpp:
        * rendering/RenderObject.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7e54c58
2011-05-09 Daniel Cheng <dcheng@chromium.org>
Reviewed by Tony Chang.
Refactor RenderObject::draggableNode.
https://bugs.webkit.org/show_bug.cgi?id=60503
This patch lays the ground for refactoring the drag start logic. It moves draggableNode to
DragController to avoid the awkward plumbing of calling DragController from RenderObject and
also moves EventHandlerDragState out from EventHandler so it can be shared between
EventHandler and DragController where appropriate.
No new tests since there should be no behavior change.
* GNUmakefile.list.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* page/DragController.cpp:
(WebCore::DragController::draggableNode):
(WebCore::DragController::mayStartDragAtEventLocation):
* page/DragController.h:
* page/DragState.h: Added.
(WebCore::DragState::DragState):
* page/EventHandler.cpp:
(WebCore::EventHandler::dragState):
(WebCore::EventHandler::eventMayStartDrag):
(WebCore::EventHandler::handleDrag):
* page/EventHandler.h:
* rendering/RenderObject.cpp:
* rendering/RenderObject.h:
2011-05-09 Luke Macpherson <macpherson@chromium.org>
Reviewed by Darin Adler.
......@@ -2157,6 +2157,7 @@ webcore_sources += \
Source/WebCore/page/DragClient.h \
Source/WebCore/page/DragController.cpp \
Source/WebCore/page/DragController.h \
Source/WebCore/page/DragState.h \
Source/WebCore/page/EditorClient.h \
Source/WebCore/page/EventHandler.cpp \
Source/WebCore/page/EventHandler.h \
......
......@@ -688,6 +688,7 @@
'page/DragActions.h',
'page/DragClient.h',
'page/DragController.h',
'page/DragState.h',
'page/EditorClient.h',
'page/EventHandler.h',
'page/FocusController.h',
......
......@@ -1841,6 +1841,7 @@ HEADERS += \
page/DOMTimer.h \
page/DOMWindow.h \
page/DragController.h \
page/DragState.h \
page/EventHandler.h \
page/EventSource.h \
page/EditorClient.h \
......
......@@ -24497,6 +24497,10 @@
RelativePath="..\page\DragController.h"
>
</File>
<File
RelativePath="..\page\DragState.h"
>
</File>
<File
RelativePath="..\page\win\DragControllerWin.cpp"
>
......@@ -1672,6 +1672,7 @@
81BE209911F4AB8D00915DFA /* IDBCursorBackendInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE209411F4AB8D00915DFA /* IDBCursorBackendInterface.h */; };
81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; };
81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; };
81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; };
82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; };
82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; };
82AB1773125C826700C5069D /* InspectorStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */; };
......@@ -8218,6 +8219,7 @@
81BE209C11F4ABBD00915DFA /* IDBCursor.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDBCursor.idl; sourceTree = "<group>"; };
81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBCursor.cpp; sourceTree = "<group>"; };
81BE20A811F4B66F00915DFA /* JSIDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBCursor.h; sourceTree = "<group>"; };
81F65FF513788FAA00FF6F2D /* DragState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragState.h; sourceTree = "<group>"; };
82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSAgent.cpp; sourceTree = "<group>"; };
82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSAgent.h; sourceTree = "<group>"; };
82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorStyleSheet.cpp; sourceTree = "<group>"; };
......@@ -14105,6 +14107,7 @@
A7CA59620B27C1F200FA021D /* DragClient.h */,
A7CA595C0B27BD9E00FA021D /* DragController.cpp */,
A7CA595B0B27BD9E00FA021D /* DragController.h */,
81F65FF513788FAA00FF6F2D /* DragState.h */,
1AF326770D78B9440068F0C4 /* EditorClient.h */,
93C09A800B064F00005ABD4D /* EventHandler.cpp */,
93C09A520B064DB3005ABD4D /* EventHandler.h */,
......@@ -20789,6 +20792,7 @@
A7CA595D0B27BD9E00FA021D /* DragController.h in Headers */,
A7B6E69F0B291A9600D0529F /* DragData.h in Headers */,
A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */,
81F65FF613788FAA00FF6F2D /* DragState.h in Headers */,
498770DC1242C535002226BA /* DrawingBuffer.h in Headers */,
BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */,
93309DE2099E64920056E581 /* EditAction.h in Headers */,
......@@ -569,7 +569,41 @@ bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
return true;
}
bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node)
Node* DragController::draggableNode(const Frame* src, Node* startNode, bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
{
if (!dhtmlOK && !uaOK)
return 0;
for (const RenderObject* renderer = startNode->renderer(); renderer; renderer = renderer->parent()) {
Node* node = renderer->node();
if (node && node->nodeType() == Node::TEXT_NODE) {
// Since there's no way for the author to address the -webkit-user-drag style for a text node,
// we use our own judgement.
if (uaOK && mayStartDragAtEventLocation(src, IntPoint(x, y), node)) {
dhtmlWillDrag = false;
return node;
}
if (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.
return 0;
} else {
EUserDrag dragMode = renderer->style()->userDrag();
if (dhtmlOK && dragMode == DRAG_ELEMENT) {
dhtmlWillDrag = true;
return node;
}
if (uaOK && dragMode == DRAG_AUTO && mayStartDragAtEventLocation(src, IntPoint(x, y), node)) {
dhtmlWillDrag = false;
return node;
}
}
}
return 0;
}
bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node) const
{
ASSERT(frame);
ASSERT(frame->settings());
......
......@@ -75,7 +75,8 @@ namespace WebCore {
DragDestinationAction dragDestinationAction() const { return m_dragDestinationAction; }
DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint);
bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos, Node*);
Node* draggableNode(const Frame*, Node*, bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos, Node*) const;
void dragEnded();
void placeDragCaret(const IntPoint&);
......
......@@ -35,6 +35,7 @@
#include "CursorList.h"
#include "Document.h"
#include "DragController.h"
#include "DragState.h"
#include "Editor.h"
#include "EventNames.h"
#include "EventQueue.h"
......@@ -217,9 +218,9 @@ EventHandler::~EventHandler()
}
#if ENABLE(DRAG_SUPPORT)
EventHandler::EventHandlerDragState& EventHandler::dragState()
DragState& EventHandler::dragState()
{
DEFINE_STATIC_LOCAL(EventHandlerDragState, state, ());
DEFINE_STATIC_LOCAL(DragState, state, ());
return state;
}
#endif // ENABLE(DRAG_SUPPORT)
......@@ -595,11 +596,15 @@ bool EventHandler::eventMayStartDrag(const PlatformMouseEvent& event) const
if (!view)
return false;
Page* page = m_frame->page();
if (!page)
return false;
HitTestRequest request(HitTestRequest::ReadOnly);
HitTestResult result(view->windowToContents(event.pos()));
m_frame->contentRenderer()->layer()->hitTest(request, result);
bool srcIsDHTML;
return result.innerNode() && result.innerNode()->renderer()->draggableNode(DHTMLFlag, UAFlag, result.point().x(), result.point().y(), srcIsDHTML);
return result.innerNode() && page->dragController()->draggableNode(m_frame, result.innerNode(), DHTMLFlag, UAFlag, result.point().x(), result.point().y(), srcIsDHTML);
}
void EventHandler::updateSelectionForMouseDrag()
......@@ -2639,14 +2644,6 @@ void EventHandler::freeClipboard()
dragState().m_dragClipboard->setAccessPolicy(ClipboardNumb);
}
bool EventHandler::shouldDragAutoNode(Node* node, const IntPoint& point) const
{
if (!node || !m_frame->view())
return false;
Page* page = m_frame->page();
return page && page->dragController()->mayStartDragAtEventLocation(m_frame, point, node);
}
void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, DragOperation operation)
{
if (dragState().m_dragSrc && dragState().m_dragSrcMayBeDHTML) {
......@@ -2695,9 +2692,9 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
HitTestResult result(m_mouseDownPos);
m_frame->contentRenderer()->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);
if (node && m_frame->page())
dragState().m_dragSrc = m_frame->page()->dragController()->draggableNode(m_frame, node, dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
else
dragState().m_dragSrc = 0;
......
......@@ -49,6 +49,7 @@ namespace WebCore {
class Clipboard;
class Cursor;
class DragState;
class Event;
class EventTarget;
class FloatPoint;
......@@ -145,10 +146,6 @@ public:
bool scrollRecursively(ScrollDirection, ScrollGranularity, Node* startingNode = 0);
bool logicalScrollRecursively(ScrollLogicalDirection, ScrollGranularity, Node* startingNode = 0);
#if ENABLE(DRAG_SUPPORT)
bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
#endif
bool tabsToLinks(KeyboardEvent*) const;
bool tabsToAllFormControls(KeyboardEvent*) const;
......@@ -223,20 +220,7 @@ private:
PerformDragAndDrop
};
struct EventHandlerDragState {
WTF_MAKE_NONCOPYABLE(EventHandlerDragState); WTF_MAKE_FAST_ALLOCATED;
public:
EventHandlerDragState() { }
RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
bool m_dragSrcIsLink;
bool m_dragSrcIsImage;
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
};
static EventHandlerDragState& dragState();
static DragState& dragState();
static const double TextDragDelay;
bool canHandleDragAndDropForTarget(DragAndDropHandleType, Node* target, const PlatformMouseEvent&, Clipboard*, bool* accepted = 0);
......
......@@ -1498,43 +1498,6 @@ Color RenderObject::selectionEmphasisMarkColor() const
return selectionColor(CSSPropertyWebkitTextEmphasisColor);
}
#if ENABLE(DRAG_SUPPORT)
Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
{
if (!dhtmlOK && !uaOK)
return 0;
for (const RenderObject* curr = this; curr; curr = curr->parent()) {
Node* elt = curr->node();
if (elt && elt->nodeType() == Node::TEXT_NODE) {
// Since there's no way for the author to address the -webkit-user-drag style for a text node,
// we use our own judgement.
if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
dhtmlWillDrag = false;
return curr->node();
}
if (elt->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.
return 0;
} else {
EUserDrag dragMode = curr->style()->userDrag();
if (dhtmlOK && dragMode == DRAG_ELEMENT) {
dhtmlWillDrag = true;
return curr->node();
}
if (uaOK && dragMode == DRAG_AUTO
&& view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
dhtmlWillDrag = false;
return curr->node();
}
}
}
return 0;
}
#endif // ENABLE(DRAG_SUPPORT)
void RenderObject::selectionStartEnd(int& spos, int& epos) const
{
view()->selectionStartEnd(spos, epos);
......
......@@ -718,10 +718,6 @@ public:
// Whether or not a given block needs to paint selection gaps.
virtual bool shouldPaintSelectionGaps() const { return false; }
#if ENABLE(DRAG_SUPPORT)
Node* draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
#endif
/**
* Returns the local coordinates of the caret within this render object.
* @param caretOffset zero-based offset determining position within the render object.
......
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