Changeset 86128 in webkit


Ignore:
Timestamp:
May 9, 2011 9:33:13 PM (13 years ago)
Author:
dcheng@chromium.org
Message:

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:
Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r86120 r86128  
     12011-05-09  Daniel Cheng  <dcheng@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        Refactor RenderObject::draggableNode.
     6        https://bugs.webkit.org/show_bug.cgi?id=60503
     7
     8        This patch lays the ground for refactoring the drag start logic. It moves draggableNode to
     9        DragController to avoid the awkward plumbing of calling DragController from RenderObject and
     10        also moves EventHandlerDragState out from EventHandler so it can be shared between
     11        EventHandler and DragController where appropriate.
     12
     13        No new tests since there should be no behavior change.
     14
     15        * GNUmakefile.list.am:
     16        * WebCore.gypi:
     17        * WebCore.pro:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * page/DragController.cpp:
     21        (WebCore::DragController::draggableNode):
     22        (WebCore::DragController::mayStartDragAtEventLocation):
     23        * page/DragController.h:
     24        * page/DragState.h: Added.
     25        (WebCore::DragState::DragState):
     26        * page/EventHandler.cpp:
     27        (WebCore::EventHandler::dragState):
     28        (WebCore::EventHandler::eventMayStartDrag):
     29        (WebCore::EventHandler::handleDrag):
     30        * page/EventHandler.h:
     31        * rendering/RenderObject.cpp:
     32        * rendering/RenderObject.h:
     33
    1342011-05-09  Luke Macpherson   <macpherson@chromium.org>
    235
  • trunk/Source/WebCore/GNUmakefile.list.am

    r86047 r86128  
    21582158        Source/WebCore/page/DragController.cpp \
    21592159        Source/WebCore/page/DragController.h \
     2160        Source/WebCore/page/DragState.h \
    21602161        Source/WebCore/page/EditorClient.h \
    21612162        Source/WebCore/page/EventHandler.cpp \
  • trunk/Source/WebCore/WebCore.gypi

    r86099 r86128  
    689689            'page/DragClient.h',
    690690            'page/DragController.h',
     691            'page/DragState.h',
    691692            'page/EditorClient.h',
    692693            'page/EventHandler.h',
  • trunk/Source/WebCore/WebCore.pro

    r86054 r86128  
    18421842    page/DOMWindow.h \
    18431843    page/DragController.h \
     1844    page/DragState.h \
    18441845    page/EventHandler.h \
    18451846    page/EventSource.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r86052 r86128  
    2449924499                        </File>
    2450024500                        <File
     24501                                RelativePath="..\page\DragState.h"
     24502                                >
     24503                        </File>
     24504                        <File
    2450124505                                RelativePath="..\page\win\DragControllerWin.cpp"
    2450224506                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r86115 r86128  
    16731673                81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; };
    16741674                81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; };
     1675                81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; };
    16751676                82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; };
    16761677                82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; };
     
    82198220                81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBCursor.cpp; sourceTree = "<group>"; };
    82208221                81BE20A811F4B66F00915DFA /* JSIDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBCursor.h; sourceTree = "<group>"; };
     8222                81F65FF513788FAA00FF6F2D /* DragState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragState.h; sourceTree = "<group>"; };
    82218223                82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSAgent.cpp; sourceTree = "<group>"; };
    82228224                82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSAgent.h; sourceTree = "<group>"; };
     
    1410614108                                A7CA595C0B27BD9E00FA021D /* DragController.cpp */,
    1410714109                                A7CA595B0B27BD9E00FA021D /* DragController.h */,
     14110                                81F65FF513788FAA00FF6F2D /* DragState.h */,
    1410814111                                1AF326770D78B9440068F0C4 /* EditorClient.h */,
    1410914112                                93C09A800B064F00005ABD4D /* EventHandler.cpp */,
     
    2079020793                                A7B6E69F0B291A9600D0529F /* DragData.h in Headers */,
    2079120794                                A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */,
     20795                                81F65FF613788FAA00FF6F2D /* DragState.h in Headers */,
    2079220796                                498770DC1242C535002226BA /* DrawingBuffer.h in Headers */,
    2079320797                                BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */,
  • trunk/Source/WebCore/page/DragController.cpp

    r86039 r86128  
    570570}
    571571
    572 bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node)
     572Node* DragController::draggableNode(const Frame* src, Node* startNode, bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
     573{
     574    if (!dhtmlOK && !uaOK)
     575        return 0;
     576
     577    for (const RenderObject* renderer = startNode->renderer(); renderer; renderer = renderer->parent()) {
     578        Node* node = renderer->node();
     579        if (node && node->nodeType() == Node::TEXT_NODE) {
     580            // Since there's no way for the author to address the -webkit-user-drag style for a text node,
     581            // we use our own judgement.
     582            if (uaOK && mayStartDragAtEventLocation(src, IntPoint(x, y), node)) {
     583                dhtmlWillDrag = false;
     584                return node;
     585            }
     586            if (node->canStartSelection())
     587                // In this case we have a click in the unselected portion of text. If this text is
     588                // selectable, we want to start the selection process instead of looking for a parent
     589                // to try to drag.
     590                return 0;
     591        } else {
     592            EUserDrag dragMode = renderer->style()->userDrag();
     593            if (dhtmlOK && dragMode == DRAG_ELEMENT) {
     594                dhtmlWillDrag = true;
     595                return node;
     596            }
     597            if (uaOK && dragMode == DRAG_AUTO && mayStartDragAtEventLocation(src, IntPoint(x, y), node)) {
     598                dhtmlWillDrag = false;
     599                return node;
     600            }
     601        }
     602    }
     603    return 0;
     604}
     605
     606bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node) const
    573607{
    574608    ASSERT(frame);
  • trunk/Source/WebCore/page/DragController.h

    r85864 r86128  
    7676        DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint);
    7777       
    78         bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos, Node*);
     78        Node* draggableNode(const Frame*, Node*, bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
     79        bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos, Node*) const;
    7980        void dragEnded();
    8081       
  • trunk/Source/WebCore/page/EventHandler.cpp

    r86002 r86128  
    3636#include "Document.h"
    3737#include "DragController.h"
     38#include "DragState.h"
    3839#include "Editor.h"
    3940#include "EventNames.h"
     
    218219   
    219220#if ENABLE(DRAG_SUPPORT)
    220 EventHandler::EventHandlerDragState& EventHandler::dragState()
    221 {
    222     DEFINE_STATIC_LOCAL(EventHandlerDragState, state, ());
     221DragState& EventHandler::dragState()
     222{
     223    DEFINE_STATIC_LOCAL(DragState, state, ());
    223224    return state;
    224225}
     
    596597        return false;
    597598
     599    Page* page = m_frame->page();
     600    if (!page)
     601        return false;
     602
    598603    HitTestRequest request(HitTestRequest::ReadOnly);
    599604    HitTestResult result(view->windowToContents(event.pos()));
    600605    m_frame->contentRenderer()->layer()->hitTest(request, result);
    601606    bool srcIsDHTML;
    602     return result.innerNode() && result.innerNode()->renderer()->draggableNode(DHTMLFlag, UAFlag, result.point().x(), result.point().y(), srcIsDHTML);
     607    return result.innerNode() && page->dragController()->draggableNode(m_frame, result.innerNode(), DHTMLFlag, UAFlag, result.point().x(), result.point().y(), srcIsDHTML);
    603608}
    604609
     
    26402645}
    26412646
    2642 bool EventHandler::shouldDragAutoNode(Node* node, const IntPoint& point) const
    2643 {
    2644     if (!node || !m_frame->view())
    2645         return false;
    2646     Page* page = m_frame->page();
    2647     return page && page->dragController()->mayStartDragAtEventLocation(m_frame, point, node);
    2648 }
    2649 
    26502647void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, DragOperation operation)
    26512648{
     
    26962693        m_frame->contentRenderer()->layer()->hitTest(request, result);
    26972694        Node* node = result.innerNode();
    2698         if (node && node->renderer())
    2699             dragState().m_dragSrc = node->renderer()->draggableNode(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
    2700                                                                     m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
     2695        if (node && m_frame->page())
     2696            dragState().m_dragSrc = m_frame->page()->dragController()->draggableNode(m_frame, node, dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
     2697                                                                                     m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
    27012698        else
    27022699            dragState().m_dragSrc = 0;
  • trunk/Source/WebCore/page/EventHandler.h

    r85864 r86128  
    5050class Clipboard;
    5151class Cursor;
     52class DragState;
    5253class Event;
    5354class EventTarget;
     
    146147    bool logicalScrollRecursively(ScrollLogicalDirection, ScrollGranularity, Node* startingNode = 0);
    147148
    148 #if ENABLE(DRAG_SUPPORT)
    149     bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
    150 #endif
    151 
    152149    bool tabsToLinks(KeyboardEvent*) const;
    153150    bool tabsToAllFormControls(KeyboardEvent*) const;
     
    224221    };
    225222
    226     struct EventHandlerDragState {
    227         WTF_MAKE_NONCOPYABLE(EventHandlerDragState); WTF_MAKE_FAST_ALLOCATED;
    228     public:
    229         EventHandlerDragState() { }
    230         RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
    231         bool m_dragSrcIsLink;
    232         bool m_dragSrcIsImage;
    233         bool m_dragSrcInSelection;
    234         bool m_dragSrcMayBeDHTML;
    235         bool m_dragSrcMayBeUA; // Are DHTML and/or the UserAgent allowed to drag out?
    236         bool m_dragSrcIsDHTML;
    237         RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
    238     };
    239     static EventHandlerDragState& dragState();
     223    static DragState& dragState();
    240224    static const double TextDragDelay;
    241225
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r85577 r86128  
    14991499}
    15001500
    1501 #if ENABLE(DRAG_SUPPORT)
    1502 Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
    1503 {
    1504     if (!dhtmlOK && !uaOK)
    1505         return 0;
    1506 
    1507     for (const RenderObject* curr = this; curr; curr = curr->parent()) {
    1508         Node* elt = curr->node();
    1509         if (elt && elt->nodeType() == Node::TEXT_NODE) {
    1510             // Since there's no way for the author to address the -webkit-user-drag style for a text node,
    1511             // we use our own judgement.
    1512             if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
    1513                 dhtmlWillDrag = false;
    1514                 return curr->node();
    1515             }
    1516             if (elt->canStartSelection())
    1517                 // In this case we have a click in the unselected portion of text.  If this text is
    1518                 // selectable, we want to start the selection process instead of looking for a parent
    1519                 // to try to drag.
    1520                 return 0;
    1521         } else {
    1522             EUserDrag dragMode = curr->style()->userDrag();
    1523             if (dhtmlOK && dragMode == DRAG_ELEMENT) {
    1524                 dhtmlWillDrag = true;
    1525                 return curr->node();
    1526             }
    1527             if (uaOK && dragMode == DRAG_AUTO
    1528                     && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
    1529                 dhtmlWillDrag = false;
    1530                 return curr->node();
    1531             }
    1532         }
    1533     }
    1534     return 0;
    1535 }
    1536 #endif // ENABLE(DRAG_SUPPORT)
    1537 
    15381501void RenderObject::selectionStartEnd(int& spos, int& epos) const
    15391502{
  • trunk/Source/WebCore/rendering/RenderObject.h

    r86109 r86128  
    718718    // Whether or not a given block needs to paint selection gaps.
    719719    virtual bool shouldPaintSelectionGaps() const { return false; }
    720 
    721 #if ENABLE(DRAG_SUPPORT)
    722     Node* draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
    723 #endif
    724720
    725721    /**
Note: See TracChangeset for help on using the changeset viewer.