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

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

Issue 1978763004: Drag image should always use the real device scale factor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 // We shouldn't be starting a drag for an image that can't provide an ex tension. 894 // We shouldn't be starting a drag for an image that can't provide an ex tension.
895 // This is an early detection for problems encountered later upon drop. 895 // This is an early detection for problems encountered later upon drop.
896 ASSERT(!image->filenameExtension().isEmpty()); 896 ASSERT(!image->filenameExtension().isEmpty());
897 if (!dragImage) { 897 if (!dragImage) {
898 const IntRect& imageRect = hitTestResult.imageRect(); 898 const IntRect& imageRect = hitTestResult.imageRect();
899 IntSize imageSizeInPixels = imageRect.size(); 899 IntSize imageSizeInPixels = imageRect.size();
900 // TODO(oshima): Remove this scaling and simply pass imageRect to dr agImageForImage 900 // TODO(oshima): Remove this scaling and simply pass imageRect to dr agImageForImage
901 // once all platforms are migrated to use zoom for dsf. 901 // once all platforms are migrated to use zoom for dsf.
902 imageSizeInPixels.scale(src->host()->deviceScaleFactor()); 902 imageSizeInPixels.scale(src->host()->deviceScaleFactor());
903 903
904 float screenDeviceScaleFactor = src->page()->chromeClient().screenIn fo().deviceScaleFactor; 904 float screenDeviceScaleFactor = src->page()->chromeClient().nonEmula tedDeviceScaleFactor();
905
905 // Pass the selected image size in DIP becasue dragImageForImage cli ps the image in DIP. 906 // Pass the selected image size in DIP becasue dragImageForImage cli ps the image in DIP.
906 // The coordinates of the locations are in Viewport coordinates, and they're converted in the Blink client. 907 // The coordinates of the locations are in Viewport coordinates, and they're converted in the Blink client.
907 // TODO(oshima): Currently, the dragged image on high DPI is scaled and can be blurry because of this. 908 // TODO(oshima): Currently, the dragged image on high DPI is scaled and can be blurry because of this.
908 // Consider to clip in the screen coordinates to use high resolution image on high DPI screens. 909 // Consider to clip in the screen coordinates to use high resolution image on high DPI screens.
909 dragImage = dragImageForImage(element, image, screenDeviceScaleFacto r, dragOrigin, imageRect.location(), imageSizeInPixels, dragLocation); 910 dragImage = dragImageForImage(element, image, screenDeviceScaleFacto r, dragOrigin, imageRect.location(), imageSizeInPixels, dragLocation);
910 } 911 }
911 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 912 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
912 } else if (state.m_dragType == DragSourceActionLink) { 913 } else if (state.m_dragType == DragSourceActionLink) {
913 if (linkURL.isEmpty()) 914 if (linkURL.isEmpty())
914 return false; 915 return false;
915 if (src->selection().isCaret() && src->selection().isContentEditable()) { 916 if (src->selection().isCaret() && src->selection().isContentEditable()) {
916 // a user can initiate a drag on a link without having any text 917 // a user can initiate a drag on a link without having any text
917 // selected. In this case, we should expand the selection to 918 // selected. In this case, we should expand the selection to
918 // the enclosing anchor element 919 // the enclosing anchor element
919 if (Node* node = enclosingAnchorElement(src->selection().base())) 920 if (Node* node = enclosingAnchorElement(src->selection().base()))
920 src->selection().setSelection(VisibleSelection::selectionFromCon tentsOfNode(node)); 921 src->selection().setSelection(VisibleSelection::selectionFromCon tentsOfNode(node));
921 } 922 }
922 923
923 if (!dragImage) { 924 if (!dragImage) {
924 ASSERT(src->page()); 925 ASSERT(src->page());
925 float screenDeviceScaleFactor = src->page()->chromeClient().screenIn fo().deviceScaleFactor; 926 float screenDeviceScaleFactor = src->page()->chromeClient().nonEmula tedDeviceScaleFactor();
927
926 dragImage = dragImageForLink(linkURL, hitTestResult.textContent(), s creenDeviceScaleFactor, mouseDraggedPoint, dragLocation); 928 dragImage = dragImageForLink(linkURL, hitTestResult.textContent(), s creenDeviceScaleFactor, mouseDraggedPoint, dragLocation);
927 } 929 }
928 doSystemDrag(dragImage.get(), dragLocation, mouseDraggedPoint, dataTrans fer, src, true); 930 doSystemDrag(dragImage.get(), dragLocation, mouseDraggedPoint, dataTrans fer, src, true);
929 } else if (state.m_dragType == DragSourceActionDHTML) { 931 } else if (state.m_dragType == DragSourceActionDHTML) {
930 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 932 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
931 } else { 933 } else {
932 ASSERT_NOT_REACHED(); 934 ASSERT_NOT_REACHED();
933 return false; 935 return false;
934 } 936 }
935 937
(...skipping 14 matching lines...) Expand all
950 IntPoint adjustedDragLocation = mainFrameView->rootFrameToContents(frame->vi ew()->contentsToRootFrame(dragLocation)); 952 IntPoint adjustedDragLocation = mainFrameView->rootFrameToContents(frame->vi ew()->contentsToRootFrame(dragLocation));
951 IntPoint adjustedEventPos = mainFrameView->rootFrameToContents(frame->view() ->contentsToRootFrame(eventPos)); 953 IntPoint adjustedEventPos = mainFrameView->rootFrameToContents(frame->view() ->contentsToRootFrame(eventPos));
952 WebDragData dragData = dataTransfer->dataObject()->toWebDragData(); 954 WebDragData dragData = dataTransfer->dataObject()->toWebDragData();
953 WebDragOperationsMask dragOperationMask = static_cast<WebDragOperationsMask> (dataTransfer->sourceOperation()); 955 WebDragOperationsMask dragOperationMask = static_cast<WebDragOperationsMask> (dataTransfer->sourceOperation());
954 IntSize offsetSize(adjustedEventPos - adjustedDragLocation); 956 IntSize offsetSize(adjustedEventPos - adjustedDragLocation);
955 WebPoint offsetPoint(offsetSize.width(), offsetSize.height()); 957 WebPoint offsetPoint(offsetSize.width(), offsetSize.height());
956 WebImage dragImage; 958 WebImage dragImage;
957 959
958 if (image) { 960 if (image) {
959 float resolutionScale = image->resolutionScale(); 961 float resolutionScale = image->resolutionScale();
960 float deviceScaleFactor = m_page->chromeClient().screenInfo().deviceScal eFactor; 962 float deviceScaleFactor = m_page->chromeClient().nonEmulatedDeviceScaleF actor();
961 if (deviceScaleFactor != resolutionScale) { 963 if (deviceScaleFactor != resolutionScale) {
962 DCHECK_GT(resolutionScale, 0); 964 DCHECK_GT(resolutionScale, 0);
963 float scale = deviceScaleFactor / resolutionScale; 965 float scale = deviceScaleFactor / resolutionScale;
964 image->scale(scale, scale); 966 image->scale(scale, scale);
965 } 967 }
966 dragImage = image->bitmap(); 968 dragImage = image->bitmap();
967 } 969 }
968 970
969 m_page->chromeClient().startDragging(frame, dragData, dragOperationMask, dra gImage, offsetPoint); 971 m_page->chromeClient().startDragging(frame, dragData, dragOperationMask, dra gImage, offsetPoint);
970 } 972 }
(...skipping 21 matching lines...) Expand all
992 994
993 DEFINE_TRACE(DragController) 995 DEFINE_TRACE(DragController)
994 { 996 {
995 visitor->trace(m_page); 997 visitor->trace(m_page);
996 visitor->trace(m_documentUnderMouse); 998 visitor->trace(m_documentUnderMouse);
997 visitor->trace(m_dragInitiator); 999 visitor->trace(m_dragInitiator);
998 visitor->trace(m_fileInputElementUnderMouse); 1000 visitor->trace(m_fileInputElementUnderMouse);
999 } 1001 }
1000 1002
1001 } // namespace blink 1003 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/ChromeClient.h ('k') | third_party/WebKit/Source/web/ChromeClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698