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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 if (dragMode == DRAG_NONE) | 790 if (dragMode == DRAG_NONE) |
791 continue; | 791 continue; |
792 // Even if the image is part of a selection, we always only drag the image | 792 // Even if the image is part of a selection, we always only drag the image |
793 // in this case. | 793 // in this case. |
794 if (layoutObject->isImage() && src->settings() && | 794 if (layoutObject->isImage() && src->settings() && |
795 src->settings()->loadsImagesAutomatically()) { | 795 src->settings()->loadsImagesAutomatically()) { |
796 dragType = DragSourceActionImage; | 796 dragType = DragSourceActionImage; |
797 return node; | 797 return node; |
798 } | 798 } |
799 // Other draggable elements are considered unselectable. | 799 // Other draggable elements are considered unselectable. |
800 if (dragMode == DRAG_ELEMENT) { | |
801 candidateDragType = DragSourceActionDHTML; | |
802 break; | |
803 } | |
800 if (isHTMLAnchorElement(*node) && | 804 if (isHTMLAnchorElement(*node) && |
801 toHTMLAnchorElement(node)->isLiveLink()) { | 805 toHTMLAnchorElement(node)->isLiveLink()) { |
802 candidateDragType = DragSourceActionLink; | 806 candidateDragType = DragSourceActionLink; |
803 break; | 807 break; |
804 } | 808 } |
805 if (dragMode == DRAG_ELEMENT) { | |
806 candidateDragType = DragSourceActionDHTML; | |
807 break; | |
808 } | |
809 } | 809 } |
810 } | 810 } |
811 | 811 |
812 if (candidateDragType == DragSourceActionNone) { | 812 if (candidateDragType == DragSourceActionNone) { |
813 // Either: | 813 // Either: |
814 // 1) Nothing under the cursor is considered draggable, so we bail out. | 814 // 1) Nothing under the cursor is considered draggable, so we bail out. |
815 // 2) There was a selection under the cursor but selectionDragPolicy is set | 815 // 2) There was a selection under the cursor but selectionDragPolicy is set |
816 // to DelayedSelectionDragResolution and no other draggable element could | 816 // to DelayedSelectionDragResolution and no other draggable element could |
817 // be found, so bail out and allow text selection to start at the cursor | 817 // be found, so bail out and allow text selection to start at the cursor |
818 // instead. | 818 // instead. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 bool DragController::populateDragDataTransfer(LocalFrame* src, | 876 bool DragController::populateDragDataTransfer(LocalFrame* src, |
877 const DragState& state, | 877 const DragState& state, |
878 const IntPoint& dragOrigin) { | 878 const IntPoint& dragOrigin) { |
879 #if DCHECK_IS_ON() | 879 #if DCHECK_IS_ON() |
880 DCHECK(dragTypeIsValid(state.m_dragType)); | 880 DCHECK(dragTypeIsValid(state.m_dragType)); |
881 #endif | 881 #endif |
882 DCHECK(src); | 882 DCHECK(src); |
883 if (!src->view() || src->contentLayoutItem().isNull()) | 883 if (!src->view() || src->contentLayoutItem().isNull()) |
884 return false; | 884 return false; |
885 | 885 |
886 // Check to see if this a DOM based drag, if it is get the DOM specified drag | |
887 // image and offset | |
888 if (state.m_dragType == DragSourceActionDHTML) { | |
dcheng
2016/10/27 06:37:54
Is this leftover from an earlier CL?
pwnall
2016/10/29 00:24:24
Done.
It was a previous host for the block of code
| |
889 } | |
890 | |
886 HitTestResult hitTestResult = | 891 HitTestResult hitTestResult = |
887 src->eventHandler().hitTestResultAtPoint(dragOrigin); | 892 src->eventHandler().hitTestResultAtPoint(dragOrigin); |
888 // FIXME: Can this even happen? I guess it's possible, but should verify | 893 // FIXME: Can this even happen? I guess it's possible, but should verify |
889 // with a layout test. | 894 // with a layout test. |
890 if (!state.m_dragSrc->isShadowIncludingInclusiveAncestorOf( | 895 if (!state.m_dragSrc->isShadowIncludingInclusiveAncestorOf( |
891 hitTestResult.innerNode())) { | 896 hitTestResult.innerNode())) { |
892 // The original node being dragged isn't under the drag origin anymore... | 897 // The original node being dragged isn't under the drag origin anymore... |
893 // maybe it was hidden or moved out from under the cursor. Regardless, we | 898 // maybe it was hidden or moved out from under the cursor. Regardless, we |
894 // don't want to start a drag on something that's not actually under the | 899 // don't want to start a drag on something that's not actually under the |
895 // drag origin. | 900 // drag origin. |
(...skipping 13 matching lines...) Expand all Loading... | |
909 Element* element = toElement(node); | 914 Element* element = toElement(node); |
910 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL, | 915 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL, |
911 imageURL, hitTestResult.altDisplayString()); | 916 imageURL, hitTestResult.altDisplayString()); |
912 } else if (state.m_dragType == DragSourceActionLink) { | 917 } else if (state.m_dragType == DragSourceActionLink) { |
913 if (linkURL.isEmpty()) | 918 if (linkURL.isEmpty()) |
914 return false; | 919 return false; |
915 // Simplify whitespace so the title put on the clipboard resembles what the | 920 // Simplify whitespace so the title put on the clipboard resembles what the |
916 // user sees on the web page. This includes replacing newlines with spaces. | 921 // user sees on the web page. This includes replacing newlines with spaces. |
917 dataTransfer->writeURL(node, linkURL, | 922 dataTransfer->writeURL(node, linkURL, |
918 hitTestResult.textContent().simplifyWhiteSpace()); | 923 hitTestResult.textContent().simplifyWhiteSpace()); |
924 } else if (state.m_dragType == DragSourceActionDHTML) { | |
925 if (LayoutObject* layoutObject = node->layoutObject()) { | |
926 IntRect boundingIncludingDescendants = | |
927 layoutObject->absoluteBoundingBoxRectIncludingDescendants(); | |
928 IntSize delta = dragOrigin - boundingIncludingDescendants.location(); | |
929 dataTransfer->setDragImageElement(node, IntPoint(delta)); | |
930 } else { | |
931 // The layoutObject has disappeared, this can happen if the onStartDrag | |
932 // handler has hidden the element in some way. In this case we just kill | |
933 // the drag. | |
934 return false; | |
935 } | |
936 | |
937 // Links with draggable="true" follow this code path. We still need to | |
938 // populate the DataTransfer with a text/uri-list. | |
939 if (isHTMLAnchorElement(*node) && toHTMLAnchorElement(node)->isLiveLink() && | |
940 !linkURL.isEmpty()) { | |
941 dataTransfer->writeURL(node, linkURL, | |
942 hitTestResult.textContent().simplifyWhiteSpace()); | |
943 } | |
944 | |
945 // FIXME: For DHTML/draggable element drags, write element markup to | |
946 // clipboard. | |
919 } | 947 } |
920 // FIXME: For DHTML/draggable element drags, write element markup to | |
921 // clipboard. | |
922 return true; | 948 return true; |
923 } | 949 } |
924 | 950 |
925 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint, | 951 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint, |
926 const IntPoint& dragOrigin, | 952 const IntPoint& dragOrigin, |
927 const IntPoint& dragImageOffset, | 953 const IntPoint& dragImageOffset, |
928 bool isLinkImage) { | 954 bool isLinkImage) { |
929 // dragImageOffset is the cursor position relative to the lower-left corner of | 955 // dragImageOffset is the cursor position relative to the lower-left corner of |
930 // the image. | 956 // the image. |
931 const int yOffset = -dragImageOffset.y(); | 957 const int yOffset = -dragImageOffset.y(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 } | 1239 } |
1214 | 1240 |
1215 DEFINE_TRACE(DragController) { | 1241 DEFINE_TRACE(DragController) { |
1216 visitor->trace(m_page); | 1242 visitor->trace(m_page); |
1217 visitor->trace(m_documentUnderMouse); | 1243 visitor->trace(m_documentUnderMouse); |
1218 visitor->trace(m_dragInitiator); | 1244 visitor->trace(m_dragInitiator); |
1219 visitor->trace(m_fileInputElementUnderMouse); | 1245 visitor->trace(m_fileInputElementUnderMouse); |
1220 } | 1246 } |
1221 | 1247 |
1222 } // namespace blink | 1248 } // namespace blink |
OLD | NEW |