Changeset 86128 in webkit
- Timestamp:
- May 9, 2011 9:33:13 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r86120 r86128 1 2011-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 1 34 2011-05-09 Luke Macpherson <macpherson@chromium.org> 2 35 -
trunk/Source/WebCore/GNUmakefile.list.am
r86047 r86128 2158 2158 Source/WebCore/page/DragController.cpp \ 2159 2159 Source/WebCore/page/DragController.h \ 2160 Source/WebCore/page/DragState.h \ 2160 2161 Source/WebCore/page/EditorClient.h \ 2161 2162 Source/WebCore/page/EventHandler.cpp \ -
trunk/Source/WebCore/WebCore.gypi
r86099 r86128 689 689 'page/DragClient.h', 690 690 'page/DragController.h', 691 'page/DragState.h', 691 692 'page/EditorClient.h', 692 693 'page/EventHandler.h', -
trunk/Source/WebCore/WebCore.pro
r86054 r86128 1842 1842 page/DOMWindow.h \ 1843 1843 page/DragController.h \ 1844 page/DragState.h \ 1844 1845 page/EventHandler.h \ 1845 1846 page/EventSource.h \ -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r86052 r86128 24499 24499 </File> 24500 24500 <File 24501 RelativePath="..\page\DragState.h" 24502 > 24503 </File> 24504 <File 24501 24505 RelativePath="..\page\win\DragControllerWin.cpp" 24502 24506 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r86115 r86128 1673 1673 81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; }; 1674 1674 81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; }; 1675 81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; }; 1675 1676 82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; }; 1676 1677 82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; }; … … 8219 8220 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBCursor.cpp; sourceTree = "<group>"; }; 8220 8221 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>"; }; 8221 8223 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSAgent.cpp; sourceTree = "<group>"; }; 8222 8224 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSAgent.h; sourceTree = "<group>"; }; … … 14106 14108 A7CA595C0B27BD9E00FA021D /* DragController.cpp */, 14107 14109 A7CA595B0B27BD9E00FA021D /* DragController.h */, 14110 81F65FF513788FAA00FF6F2D /* DragState.h */, 14108 14111 1AF326770D78B9440068F0C4 /* EditorClient.h */, 14109 14112 93C09A800B064F00005ABD4D /* EventHandler.cpp */, … … 20790 20793 A7B6E69F0B291A9600D0529F /* DragData.h in Headers */, 20791 20794 A7CFB3D20B7ED10A0070C32D /* DragImage.h in Headers */, 20795 81F65FF613788FAA00FF6F2D /* DragState.h in Headers */, 20792 20796 498770DC1242C535002226BA /* DrawingBuffer.h in Headers */, 20793 20797 BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */, -
trunk/Source/WebCore/page/DragController.cpp
r86039 r86128 570 570 } 571 571 572 bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node) 572 Node* 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 606 bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node) const 573 607 { 574 608 ASSERT(frame); -
trunk/Source/WebCore/page/DragController.h
r85864 r86128 76 76 DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint); 77 77 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; 79 80 void dragEnded(); 80 81 -
trunk/Source/WebCore/page/EventHandler.cpp
r86002 r86128 36 36 #include "Document.h" 37 37 #include "DragController.h" 38 #include "DragState.h" 38 39 #include "Editor.h" 39 40 #include "EventNames.h" … … 218 219 219 220 #if ENABLE(DRAG_SUPPORT) 220 EventHandler::EventHandlerDragState& EventHandler::dragState()221 { 222 DEFINE_STATIC_LOCAL( EventHandlerDragState, state, ());221 DragState& EventHandler::dragState() 222 { 223 DEFINE_STATIC_LOCAL(DragState, state, ()); 223 224 return state; 224 225 } … … 596 597 return false; 597 598 599 Page* page = m_frame->page(); 600 if (!page) 601 return false; 602 598 603 HitTestRequest request(HitTestRequest::ReadOnly); 599 604 HitTestResult result(view->windowToContents(event.pos())); 600 605 m_frame->contentRenderer()->layer()->hitTest(request, result); 601 606 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); 603 608 } 604 609 … … 2640 2645 } 2641 2646 2642 bool EventHandler::shouldDragAutoNode(Node* node, const IntPoint& point) const2643 {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 2650 2647 void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, DragOperation operation) 2651 2648 { … … 2696 2693 m_frame->contentRenderer()->layer()->hitTest(request, result); 2697 2694 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); 2701 2698 else 2702 2699 dragState().m_dragSrc = 0; -
trunk/Source/WebCore/page/EventHandler.h
r85864 r86128 50 50 class Clipboard; 51 51 class Cursor; 52 class DragState; 52 53 class Event; 53 54 class EventTarget; … … 146 147 bool logicalScrollRecursively(ScrollLogicalDirection, ScrollGranularity, Node* startingNode = 0); 147 148 148 #if ENABLE(DRAG_SUPPORT)149 bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto150 #endif151 152 149 bool tabsToLinks(KeyboardEvent*) const; 153 150 bool tabsToAllFormControls(KeyboardEvent*) const; … … 224 221 }; 225 222 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(); 240 224 static const double TextDragDelay; 241 225 -
trunk/Source/WebCore/rendering/RenderObject.cpp
r85577 r86128 1499 1499 } 1500 1500 1501 #if ENABLE(DRAG_SUPPORT)1502 Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const1503 {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 is1518 // selectable, we want to start the selection process instead of looking for a parent1519 // 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_AUTO1528 && 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 1538 1501 void RenderObject::selectionStartEnd(int& spos, int& epos) const 1539 1502 { -
trunk/Source/WebCore/rendering/RenderObject.h
r86109 r86128 718 718 // Whether or not a given block needs to paint selection gaps. 719 719 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 #endif724 720 725 721 /**
Note: See TracChangeset
for help on using the changeset viewer.