Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/WebKit/Source/core/page/DragController.cpp

Issue 2441023003: Align drag feedback for links with draggable="true" to Safari. (Closed)
Patch Set: Rebased, added dependency on CL that fixes testing logistical issue. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 if (dragMode == DRAG_NONE) 783 if (dragMode == DRAG_NONE)
784 continue; 784 continue;
785 // Even if the image is part of a selection, we always only drag the image 785 // Even if the image is part of a selection, we always only drag the image
786 // in this case. 786 // in this case.
787 if (layoutObject->isImage() && src->settings() && 787 if (layoutObject->isImage() && src->settings() &&
788 src->settings()->loadsImagesAutomatically()) { 788 src->settings()->loadsImagesAutomatically()) {
789 dragType = DragSourceActionImage; 789 dragType = DragSourceActionImage;
790 return node; 790 return node;
791 } 791 }
792 // Other draggable elements are considered unselectable. 792 // Other draggable elements are considered unselectable.
793 if (dragMode == DRAG_ELEMENT) {
794 candidateDragType = DragSourceActionDHTML;
795 break;
796 }
793 if (isHTMLAnchorElement(*node) && 797 if (isHTMLAnchorElement(*node) &&
794 toHTMLAnchorElement(node)->isLiveLink()) { 798 toHTMLAnchorElement(node)->isLiveLink()) {
795 candidateDragType = DragSourceActionLink; 799 candidateDragType = DragSourceActionLink;
796 break; 800 break;
797 } 801 }
798 if (dragMode == DRAG_ELEMENT) {
799 candidateDragType = DragSourceActionDHTML;
800 break;
801 }
802 } 802 }
803 } 803 }
804 804
805 if (candidateDragType == DragSourceActionNone) { 805 if (candidateDragType == DragSourceActionNone) {
806 // Either: 806 // Either:
807 // 1) Nothing under the cursor is considered draggable, so we bail out. 807 // 1) Nothing under the cursor is considered draggable, so we bail out.
808 // 2) There was a selection under the cursor but selectionDragPolicy is set 808 // 2) There was a selection under the cursor but selectionDragPolicy is set
809 // to DelayedSelectionDragResolution and no other draggable element could 809 // to DelayedSelectionDragResolution and no other draggable element could
810 // be found, so bail out and allow text selection to start at the cursor 810 // be found, so bail out and allow text selection to start at the cursor
811 // instead. 811 // instead.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 // don't want to start a drag on something that's not actually under the 887 // don't want to start a drag on something that's not actually under the
888 // drag origin. 888 // drag origin.
889 return false; 889 return false;
890 } 890 }
891 const KURL& linkURL = hitTestResult.absoluteLinkURL(); 891 const KURL& linkURL = hitTestResult.absoluteLinkURL();
892 const KURL& imageURL = hitTestResult.absoluteImageURL(); 892 const KURL& imageURL = hitTestResult.absoluteImageURL();
893 893
894 DataTransfer* dataTransfer = state.m_dragDataTransfer.get(); 894 DataTransfer* dataTransfer = state.m_dragDataTransfer.get();
895 Node* node = state.m_dragSrc.get(); 895 Node* node = state.m_dragSrc.get();
896 896
897 if (isHTMLAnchorElement(*node) && toHTMLAnchorElement(node)->isLiveLink() &&
898 !linkURL.isEmpty()) {
899 // Simplify whitespace so the title put on the clipboard resembles what
900 // the user sees on the web page. This includes replacing newlines with
901 // spaces.
902 dataTransfer->writeURL(node, linkURL,
903 hitTestResult.textContent().simplifyWhiteSpace());
904 }
905
897 if (state.m_dragType == DragSourceActionSelection) { 906 if (state.m_dragType == DragSourceActionSelection) {
898 dataTransfer->writeSelection(src->selection()); 907 dataTransfer->writeSelection(src->selection());
899 } else if (state.m_dragType == DragSourceActionImage) { 908 } else if (state.m_dragType == DragSourceActionImage) {
900 if (imageURL.isEmpty() || !node || !node->isElementNode()) 909 if (imageURL.isEmpty() || !node || !node->isElementNode())
901 return false; 910 return false;
902 Element* element = toElement(node); 911 Element* element = toElement(node);
903 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL, 912 prepareDataTransferForImageDrag(src, dataTransfer, element, linkURL,
904 imageURL, hitTestResult.altDisplayString()); 913 imageURL, hitTestResult.altDisplayString());
905 } else if (state.m_dragType == DragSourceActionLink) { 914 } else if (state.m_dragType == DragSourceActionLink) {
906 if (linkURL.isEmpty()) 915 if (linkURL.isEmpty())
907 return false; 916 return false;
908 // Simplify whitespace so the title put on the clipboard resembles what the 917 } else if (state.m_dragType == DragSourceActionDHTML) {
909 // user sees on the web page. This includes replacing newlines with spaces. 918 LayoutObject* layoutObject = node->layoutObject();
910 dataTransfer->writeURL(node, linkURL, 919 if (!layoutObject) {
911 hitTestResult.textContent().simplifyWhiteSpace()); 920 // The layoutObject has disappeared, this can happen if the onStartDrag
921 // handler has hidden the element in some way. In this case we just kill
922 // the drag.
923 return false;
924 }
925
926 IntRect boundingIncludingDescendants =
927 layoutObject->absoluteBoundingBoxRectIncludingDescendants();
928 IntSize delta = dragOrigin - boundingIncludingDescendants.location();
929 dataTransfer->setDragImageElement(node, IntPoint(delta));
930
931 // FIXME: For DHTML/draggable element drags, write element markup to
932 // clipboard.
912 } 933 }
913 // FIXME: For DHTML/draggable element drags, write element markup to
914 // clipboard.
915 return true; 934 return true;
916 } 935 }
917 936
918 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint, 937 static IntPoint dragLocationForDHTMLDrag(const IntPoint& mouseDraggedPoint,
919 const IntPoint& dragOrigin, 938 const IntPoint& dragOrigin,
920 const IntPoint& dragImageOffset, 939 const IntPoint& dragImageOffset,
921 bool isLinkImage) { 940 bool isLinkImage) {
922 // dragImageOffset is the cursor position relative to the lower-left corner of 941 // dragImageOffset is the cursor position relative to the lower-left corner of
923 // the image. 942 // the image.
924 const int yOffset = -dragImageOffset.y(); 943 const int yOffset = -dragImageOffset.y();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 } 1225 }
1207 1226
1208 DEFINE_TRACE(DragController) { 1227 DEFINE_TRACE(DragController) {
1209 visitor->trace(m_page); 1228 visitor->trace(m_page);
1210 visitor->trace(m_documentUnderMouse); 1229 visitor->trace(m_documentUnderMouse);
1211 visitor->trace(m_dragInitiator); 1230 visitor->trace(m_dragInitiator);
1212 visitor->trace(m_fileInputElementUnderMouse); 1231 visitor->trace(m_fileInputElementUnderMouse);
1213 } 1232 }
1214 1233
1215 } // namespace blink 1234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698