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

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

Issue 1605143003: [UseZoomForDSF] Support drag&drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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/frame/LocalFrame.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "core/frame/Settings.h" 53 #include "core/frame/Settings.h"
54 #include "core/html/HTMLAnchorElement.h" 54 #include "core/html/HTMLAnchorElement.h"
55 #include "core/html/HTMLFormElement.h" 55 #include "core/html/HTMLFormElement.h"
56 #include "core/html/HTMLInputElement.h" 56 #include "core/html/HTMLInputElement.h"
57 #include "core/html/HTMLPlugInElement.h" 57 #include "core/html/HTMLPlugInElement.h"
58 #include "core/input/EventHandler.h" 58 #include "core/input/EventHandler.h"
59 #include "core/layout/LayoutTheme.h" 59 #include "core/layout/LayoutTheme.h"
60 #include "core/layout/LayoutView.h" 60 #include "core/layout/LayoutView.h"
61 #include "core/loader/FrameLoadRequest.h" 61 #include "core/loader/FrameLoadRequest.h"
62 #include "core/loader/FrameLoader.h" 62 #include "core/loader/FrameLoader.h"
63 #include "core/page/ChromeClient.h"
63 #include "core/page/DragClient.h" 64 #include "core/page/DragClient.h"
64 #include "core/page/DragData.h" 65 #include "core/page/DragData.h"
65 #include "core/page/DragSession.h" 66 #include "core/page/DragSession.h"
66 #include "core/page/DragState.h" 67 #include "core/page/DragState.h"
67 #include "core/page/Page.h" 68 #include "core/page/Page.h"
68 #include "core/layout/HitTestRequest.h" 69 #include "core/layout/HitTestRequest.h"
69 #include "core/layout/HitTestResult.h" 70 #include "core/layout/HitTestResult.h"
70 #include "core/layout/LayoutImage.h" 71 #include "core/layout/LayoutImage.h"
71 #include "platform/DragImage.h" 72 #include "platform/DragImage.h"
72 #include "platform/geometry/IntRect.h" 73 #include "platform/geometry/IntRect.h"
73 #include "platform/graphics/BitmapImage.h" 74 #include "platform/graphics/BitmapImage.h"
74 #include "platform/graphics/Image.h" 75 #include "platform/graphics/Image.h"
75 #include "platform/graphics/ImageOrientation.h" 76 #include "platform/graphics/ImageOrientation.h"
76 #include "platform/network/ResourceRequest.h" 77 #include "platform/network/ResourceRequest.h"
77 #include "platform/weborigin/SecurityOrigin.h" 78 #include "platform/weborigin/SecurityOrigin.h"
79 #include "public/platform/WebScreenInfo.h"
78 #include "wtf/CurrentTime.h" 80 #include "wtf/CurrentTime.h"
79 #include "wtf/OwnPtr.h" 81 #include "wtf/OwnPtr.h"
80 #include "wtf/PassOwnPtr.h" 82 #include "wtf/PassOwnPtr.h"
81 #include "wtf/RefPtr.h" 83 #include "wtf/RefPtr.h"
82 84
83 #if OS(WIN) 85 #if OS(WIN)
84 #include <windows.h> 86 #include <windows.h>
85 #endif 87 #endif
86 88
87 namespace blink { 89 namespace blink {
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 { 785 {
784 #if OS(MACOSX) 786 #if OS(MACOSX)
785 // Match Safari's drag image size. 787 // Match Safari's drag image size.
786 static const IntSize maxDragImageSize(400, 400); 788 static const IntSize maxDragImageSize(400, 400);
787 #else 789 #else
788 static const IntSize maxDragImageSize(200, 200); 790 static const IntSize maxDragImageSize(200, 200);
789 #endif 791 #endif
790 return maxDragImageSize; 792 return maxDragImageSize;
791 } 793 }
792 794
793 static PassOwnPtr<DragImage> dragImageForImage(Element* element, Image* image, c onst IntPoint& dragOrigin, const IntRect& imageRect, IntPoint& dragLocation) 795 static PassOwnPtr<DragImage> dragImageForImage(Element* element, Image* image, c onst IntPoint& dragOrigin, const IntPoint& imageLocation, const IntSize& imageSi zeInDIP, IntPoint& dragLocation)
794 { 796 {
795 OwnPtr<DragImage> dragImage; 797 OwnPtr<DragImage> dragImage;
796 IntPoint origin; 798 IntPoint origin;
797 799
798 InterpolationQuality interpolationQuality = element->ensureComputedStyle()-> imageRendering() == ImageRenderingPixelated ? InterpolationNone : InterpolationH igh; 800 InterpolationQuality interpolationQuality = element->ensureComputedStyle()-> imageRendering() == ImageRenderingPixelated ? InterpolationNone : InterpolationH igh;
799 RespectImageOrientationEnum shouldRespectImageOrientation = LayoutObject::sh ouldRespectImageOrientation(element->layoutObject()); 801 RespectImageOrientationEnum shouldRespectImageOrientation = LayoutObject::sh ouldRespectImageOrientation(element->layoutObject());
800 ImageOrientation orientation; 802 ImageOrientation orientation;
801 803
802 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage()) 804 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage())
803 orientation = toBitmapImage(image)->currentFrameOrientation(); 805 orientation = toBitmapImage(image)->currentFrameOrientation();
804 806
805 if (image->size().height() * image->size().width() <= MaxOriginalImageArea 807 if (image->size().height() * image->size().width() <= MaxOriginalImageArea
806 && (dragImage = DragImage::create(image, shouldRespectImageOrientation, 808 && (dragImage = DragImage::create(image, shouldRespectImageOrientation,
807 1 /* deviceScaleFactor */, interpolationQuality, DragImageAlpha, 809 1 /* deviceScaleFactor */, interpolationQuality, DragImageAlpha,
808 DragImage::clampedImageScale(orientation.usesWidthAsHeight() ? image ->size().transposedSize() : image->size(), imageRect.size(), maxDragImageSize()) ))) { 810 DragImage::clampedImageScale(orientation.usesWidthAsHeight() ? image ->size().transposedSize() : image->size(), imageSizeInDIP, maxDragImageSize()))) ) {
809 IntSize originalSize = imageRect.size(); 811 IntSize originalSize = imageSizeInDIP;
810 origin = imageRect.location(); 812 origin = imageLocation;
811 813
812 IntSize newSize = dragImage->size(); 814 IntSize newSize = dragImage->size();
813 815
814 // Properly orient the drag image and orient it differently if it's smal ler than the original 816 // Properly orient the drag image and orient it differently if it's smal ler than the original
815 float scale = newSize.width() / (float)originalSize.width(); 817 float scale = newSize.width() / (float)originalSize.width();
816 float dx = origin.x() - dragOrigin.x(); 818 float dx = origin.x() - dragOrigin.x();
817 dx *= scale; 819 dx *= scale;
818 origin.setX((int)(dx + 0.5)); 820 origin.setX((int)(dx + 0.5));
819 float dy = origin.y() - dragOrigin.y(); 821 float dy = origin.y() - dragOrigin.y();
820 dy *= scale; 822 dy *= scale;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 if (imageURL.isEmpty() || !node || !node->isElementNode()) 881 if (imageURL.isEmpty() || !node || !node->isElementNode())
880 return false; 882 return false;
881 Element* element = toElement(node); 883 Element* element = toElement(node);
882 Image* image = getImage(element); 884 Image* image = getImage(element);
883 if (!image || image->isNull()) 885 if (!image || image->isNull())
884 return false; 886 return false;
885 // We shouldn't be starting a drag for an image that can't provide an ex tension. 887 // We shouldn't be starting a drag for an image that can't provide an ex tension.
886 // This is an early detection for problems encountered later upon drop. 888 // This is an early detection for problems encountered later upon drop.
887 ASSERT(!image->filenameExtension().isEmpty()); 889 ASSERT(!image->filenameExtension().isEmpty());
888 if (!dragImage) { 890 if (!dragImage) {
889 dragImage = dragImageForImage(element, image, dragOrigin, hitTestRes ult.imageRect(), dragLocation); 891 const IntRect& imageRect = hitTestResult.imageRect();
892 const IntSize& imageSizeInDIP = src->page()->chromeClient().viewport ToScreen(imageRect).size();
893 dragImage = dragImageForImage(element, image, dragOrigin, imageRect. location(), imageSizeInDIP, dragLocation);
dcheng 2016/01/22 17:37:41 I don't really understand what transformations are
oshima 2016/01/22 22:49:02 This is because dragImageForImage clips the image
890 } 894 }
891 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 895 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
892 } else if (state.m_dragType == DragSourceActionLink) { 896 } else if (state.m_dragType == DragSourceActionLink) {
893 if (linkURL.isEmpty()) 897 if (linkURL.isEmpty())
894 return false; 898 return false;
895 if (src->selection().isCaret() && src->selection().isContentEditable()) { 899 if (src->selection().isCaret() && src->selection().isContentEditable()) {
896 // a user can initiate a drag on a link without having any text 900 // a user can initiate a drag on a link without having any text
897 // selected. In this case, we should expand the selection to 901 // selected. In this case, we should expand the selection to
898 // the enclosing anchor element 902 // the enclosing anchor element
899 if (Node* node = enclosingAnchorElement(src->selection().base())) 903 if (Node* node = enclosingAnchorElement(src->selection().base()))
900 src->selection().setSelection(VisibleSelection::selectionFromCon tentsOfNode(node)); 904 src->selection().setSelection(VisibleSelection::selectionFromCon tentsOfNode(node));
901 } 905 }
902 906
903 if (!dragImage) { 907 if (!dragImage) {
904 ASSERT(src->page()); 908 ASSERT(src->page());
905 float deviceScaleFactor = src->page()->deviceScaleFactor(); 909 float screenDeviceScaleFactor = src->page()->chromeClient().screenIn fo().deviceScaleFactor;
906 dragImage = dragImageForLink(linkURL, hitTestResult.textContent(), d eviceScaleFactor, mouseDraggedPoint, dragLocation); 910 dragImage = dragImageForLink(linkURL, hitTestResult.textContent(), s creenDeviceScaleFactor, mouseDraggedPoint, dragLocation);
907 } 911 }
908 doSystemDrag(dragImage.get(), dragLocation, mouseDraggedPoint, dataTrans fer, src, true); 912 doSystemDrag(dragImage.get(), dragLocation, mouseDraggedPoint, dataTrans fer, src, true);
909 } else if (state.m_dragType == DragSourceActionDHTML) { 913 } else if (state.m_dragType == DragSourceActionDHTML) {
910 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 914 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
911 } else { 915 } else {
912 ASSERT_NOT_REACHED(); 916 ASSERT_NOT_REACHED();
913 return false; 917 return false;
914 } 918 }
915 919
916 return true; 920 return true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 967
964 DEFINE_TRACE(DragController) 968 DEFINE_TRACE(DragController)
965 { 969 {
966 visitor->trace(m_page); 970 visitor->trace(m_page);
967 visitor->trace(m_documentUnderMouse); 971 visitor->trace(m_documentUnderMouse);
968 visitor->trace(m_dragInitiator); 972 visitor->trace(m_dragInitiator);
969 visitor->trace(m_fileInputElementUnderMouse); 973 visitor->trace(m_fileInputElementUnderMouse);
970 } 974 }
971 975
972 } // namespace blink 976 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/LocalFrame.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698