Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Google Inc. | 3 * Copyright (C) 2008 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "core/page/DragController.h" | 27 #include "core/page/DragController.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
| 31 #include "core/InputTypeNames.h" | 31 #include "core/InputTypeNames.h" |
| 32 #include "core/clipboard/DataObject.h" | 32 #include "core/clipboard/DataObject.h" |
| 33 #include "core/clipboard/DataTransfer.h" | 33 #include "core/clipboard/DataTransfer.h" |
| 34 #include "core/clipboard/DataTransferAccessPolicy.h" | 34 #include "core/clipboard/DataTransferAccessPolicy.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/DocumentFragment.h" | 36 #include "core/dom/DocumentFragment.h" |
| 37 #include "core/dom/DocumentUserGestureToken.h" | 37 #include "core/dom/DocumentUserGestureToken.h" |
|
pwnall
2016/10/29 00:24:24
This is from a rebase. Sorry, I forgot to upload t
| |
| 38 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
| 39 #include "core/dom/Node.h" | 39 #include "core/dom/Node.h" |
| 40 #include "core/dom/Text.h" | 40 #include "core/dom/Text.h" |
| 41 #include "core/dom/shadow/ShadowRoot.h" | 41 #include "core/dom/shadow/ShadowRoot.h" |
| 42 #include "core/editing/DragCaretController.h" | 42 #include "core/editing/DragCaretController.h" |
| 43 #include "core/editing/EditingUtilities.h" | 43 #include "core/editing/EditingUtilities.h" |
| 44 #include "core/editing/Editor.h" | 44 #include "core/editing/Editor.h" |
| 45 #include "core/editing/FrameSelection.h" | 45 #include "core/editing/FrameSelection.h" |
| 46 #include "core/editing/commands/DragAndDropCommand.h" | 46 #include "core/editing/commands/DragAndDropCommand.h" |
| 47 #include "core/editing/serializers/Serialization.h" | 47 #include "core/editing/serializers/Serialization.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 237 } |
| 238 | 238 |
| 239 DragSession DragController::dragUpdated(DragData* dragData) { | 239 DragSession DragController::dragUpdated(DragData* dragData) { |
| 240 return dragEnteredOrUpdated(dragData); | 240 return dragEnteredOrUpdated(dragData); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool DragController::performDrag(DragData* dragData) { | 243 bool DragController::performDrag(DragData* dragData) { |
| 244 DCHECK(dragData); | 244 DCHECK(dragData); |
| 245 m_documentUnderMouse = m_page->deprecatedLocalMainFrame()->documentAtPoint( | 245 m_documentUnderMouse = m_page->deprecatedLocalMainFrame()->documentAtPoint( |
| 246 dragData->clientPosition()); | 246 dragData->clientPosition()); |
| 247 UserGestureIndicator gesture(DocumentUserGestureToken::create( | 247 UserGestureIndicator gesture(DocumentUserGestureToken::create( |
|
pwnall
2016/10/29 00:24:24
This is from a rebase. Sorry, I forgot to upload t
| |
| 248 m_documentUnderMouse, UserGestureToken::NewGesture)); | 248 m_documentUnderMouse, UserGestureToken::NewGesture)); |
| 249 if ((m_dragDestinationAction & DragDestinationActionDHTML) && | 249 if ((m_dragDestinationAction & DragDestinationActionDHTML) && |
| 250 m_documentIsHandlingDrag) { | 250 m_documentIsHandlingDrag) { |
| 251 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); | 251 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); |
| 252 bool preventedDefault = false; | 252 bool preventedDefault = false; |
| 253 if (mainFrame->view()) { | 253 if (mainFrame->view()) { |
| 254 // Sending an event can result in the destruction of the view and part. | 254 // Sending an event can result in the destruction of the view and part. |
| 255 DataTransfer* dataTransfer = | 255 DataTransfer* dataTransfer = |
| 256 createDraggingDataTransfer(DataTransferReadable, dragData); | 256 createDraggingDataTransfer(DataTransferReadable, dragData); |
| 257 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask()); | 257 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask()); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 if (dragMode == DRAG_NONE) | 791 if (dragMode == DRAG_NONE) |
| 792 continue; | 792 continue; |
| 793 // Even if the image is part of a selection, we always only drag the image | 793 // Even if the image is part of a selection, we always only drag the image |
| 794 // in this case. | 794 // in this case. |
| 795 if (layoutObject->isImage() && src->settings() && | 795 if (layoutObject->isImage() && src->settings() && |
| 796 src->settings()->loadsImagesAutomatically()) { | 796 src->settings()->loadsImagesAutomatically()) { |
| 797 dragType = DragSourceActionImage; | 797 dragType = DragSourceActionImage; |
| 798 return node; | 798 return node; |
| 799 } | 799 } |
| 800 // Other draggable elements are considered unselectable. | 800 // Other draggable elements are considered unselectable. |
| 801 if (dragMode == DRAG_ELEMENT) { | |
| 802 candidateDragType = DragSourceActionDHTML; | |
| 803 break; | |
| 804 } | |
| 801 if (isHTMLAnchorElement(*node) && | 805 if (isHTMLAnchorElement(*node) && |
| 802 toHTMLAnchorElement(node)->isLiveLink()) { | 806 toHTMLAnchorElement(node)->isLiveLink()) { |
| 803 candidateDragType = DragSourceActionLink; | 807 candidateDragType = DragSourceActionLink; |
| 804 break; | 808 break; |
| 805 } | 809 } |
| 806 if (dragMode == DRAG_ELEMENT) { | |
| 807 candidateDragType = DragSourceActionDHTML; | |
| 808 break; | |
| 809 } | |
| 810 } | 810 } |
| 811 } | 811 } |
| 812 | 812 |
| 813 if (candidateDragType == DragSourceActionNone) { | 813 if (candidateDragType == DragSourceActionNone) { |
| 814 // Either: | 814 // Either: |
| 815 // 1) Nothing under the cursor is considered draggable, so we bail out. | 815 // 1) Nothing under the cursor is considered draggable, so we bail out. |
| 816 // 2) There was a selection under the cursor but selectionDragPolicy is set | 816 // 2) There was a selection under the cursor but selectionDragPolicy is set |
| 817 // to DelayedSelectionDragResolution and no other draggable element could | 817 // to DelayedSelectionDragResolution and no other draggable element could |
| 818 // be found, so bail out and allow text selection to start at the cursor | 818 // be found, so bail out and allow text selection to start at the cursor |
| 819 // instead. | 819 // instead. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 Node* node = state.m_dragSrc.get(); | 903 Node* node = state.m_dragSrc.get(); |
| 904 | 904 |
| 905 if (state.m_dragType == DragSourceActionSelection) { | 905 if (state.m_dragType == DragSourceActionSelection) { |
| 906 dataTransfer->writeSelection(src->selection()); | 906 dataTransfer->writeSelection(src->selection()); |
| 907 } else if (state.m_dragType == DragSourceActionImage) { | 907 } else if (state.m_dragType == DragSourceActionImage) { |
| 908 if (imageURL.isEmpty() || !node || !node->isElementNode()) | 908 if (imageURL.isEmpty() || !node || !node->isElementNode()) |
| 909 return false; | 909 return false; |
| 910 Element* element = toElement(node); | 910 Element* element = toElement(node); |
| 911 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL, | 911 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL, |
| 912 imageURL, hitTestResult.altDisplayString()); | 912 imageURL, hitTestResult.altDisplayString()); |
| 913 } else if (state.m_dragType == DragSourceActionLink) { | 913 } else { |
| 914 if (linkURL.isEmpty()) | 914 if (isHTMLAnchorElement(*node) && toHTMLAnchorElement(node)->isLiveLink() && |
|
dcheng
2016/10/31 22:31:35
I was thinking we could make this a top-level if (
pwnall
2016/11/04 23:08:29
Done.
I'll learn about this more as I work through
| |
| 915 return false; | 915 !linkURL.isEmpty()) { |
| 916 // Simplify whitespace so the title put on the clipboard resembles what the | 916 // Simplify whitespace so the title put on the clipboard resembles what |
| 917 // user sees on the web page. This includes replacing newlines with spaces. | 917 // the user sees on the web page. This includes replacing newlines with |
| 918 dataTransfer->writeURL(node, linkURL, | 918 // spaces. |
| 919 hitTestResult.textContent().simplifyWhiteSpace()); | 919 dataTransfer->writeURL(node, linkURL, |
| 920 hitTestResult.textContent().simplifyWhiteSpace()); | |
| 921 } | |
| 922 | |
| 923 if (state.m_dragType == DragSourceActionLink) { | |
| 924 if (linkURL.isEmpty()) | |
| 925 return false; | |
| 926 } else if (state.m_dragType == DragSourceActionDHTML) { | |
| 927 if (LayoutObject* layoutObject = node->layoutObject()) { | |
| 928 IntRect boundingIncludingDescendants = | |
| 929 layoutObject->absoluteBoundingBoxRectIncludingDescendants(); | |
| 930 IntSize delta = dragOrigin - boundingIncludingDescendants.location(); | |
| 931 dataTransfer->setDragImageElement(node, IntPoint(delta)); | |
| 932 } else { | |
| 933 // The layoutObject has disappeared, this can happen if the onStartDrag | |
| 934 // handler has hidden the element in some way. In this case we just kill | |
| 935 // the drag. | |
| 936 return false; | |
| 937 } | |
| 938 | |
| 939 // FIXME: For DHTML/draggable element drags, write element markup to | |
| 940 // clipboard. | |
| 941 } | |
| 920 } | 942 } |
| 921 // FIXME: For DHTML/draggable element drags, write element markup to | |
| 922 // clipboard. | |
| 923 return true; | 943 return true; |
| 924 } | 944 } |
| 925 | 945 |
| 926 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint, | 946 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint, |
| 927 const IntPoint& dragOrigin, | 947 const IntPoint& dragOrigin, |
| 928 const IntPoint& dragImageOffset, | 948 const IntPoint& dragImageOffset, |
| 929 bool isLinkImage) { | 949 bool isLinkImage) { |
| 930 // dragImageOffset is the cursor position relative to the lower-left corner of | 950 // dragImageOffset is the cursor position relative to the lower-left corner of |
| 931 // the image. | 951 // the image. |
| 932 const int yOffset = -dragImageOffset.y(); | 952 const int yOffset = -dragImageOffset.y(); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 } | 1234 } |
| 1215 | 1235 |
| 1216 DEFINE_TRACE(DragController) { | 1236 DEFINE_TRACE(DragController) { |
| 1217 visitor->trace(m_page); | 1237 visitor->trace(m_page); |
| 1218 visitor->trace(m_documentUnderMouse); | 1238 visitor->trace(m_documentUnderMouse); |
| 1219 visitor->trace(m_dragInitiator); | 1239 visitor->trace(m_dragInitiator); |
| 1220 visitor->trace(m_fileInputElementUnderMouse); | 1240 visitor->trace(m_fileInputElementUnderMouse); |
| 1221 } | 1241 } |
| 1222 | 1242 |
| 1223 } // namespace blink | 1243 } // namespace blink |
| OLD | NEW |