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

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

Issue 1646543002: Create the drag image at target scale factor when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layout test Created 4 years, 10 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 28 matching lines...) Expand all
39 #include "core/dom/Text.h" 39 #include "core/dom/Text.h"
40 #include "core/dom/shadow/ShadowRoot.h" 40 #include "core/dom/shadow/ShadowRoot.h"
41 #include "core/editing/DragCaretController.h" 41 #include "core/editing/DragCaretController.h"
42 #include "core/editing/EditingUtilities.h" 42 #include "core/editing/EditingUtilities.h"
43 #include "core/editing/Editor.h" 43 #include "core/editing/Editor.h"
44 #include "core/editing/FrameSelection.h" 44 #include "core/editing/FrameSelection.h"
45 #include "core/editing/serializers/Serialization.h" 45 #include "core/editing/serializers/Serialization.h"
46 #include "core/events/TextEvent.h" 46 #include "core/events/TextEvent.h"
47 #include "core/fetch/ImageResource.h" 47 #include "core/fetch/ImageResource.h"
48 #include "core/fetch/ResourceFetcher.h" 48 #include "core/fetch/ResourceFetcher.h"
49 #include "core/frame/FrameHost.h"
49 #include "core/frame/FrameView.h" 50 #include "core/frame/FrameView.h"
50 #include "core/frame/LocalFrame.h" 51 #include "core/frame/LocalFrame.h"
51 #include "core/frame/Settings.h" 52 #include "core/frame/Settings.h"
52 #include "core/html/HTMLAnchorElement.h" 53 #include "core/html/HTMLAnchorElement.h"
53 #include "core/html/HTMLFormElement.h" 54 #include "core/html/HTMLFormElement.h"
54 #include "core/html/HTMLInputElement.h" 55 #include "core/html/HTMLInputElement.h"
55 #include "core/html/HTMLPlugInElement.h" 56 #include "core/html/HTMLPlugInElement.h"
56 #include "core/input/EventHandler.h" 57 #include "core/input/EventHandler.h"
57 #include "core/layout/LayoutTheme.h" 58 #include "core/layout/LayoutTheme.h"
58 #include "core/layout/LayoutView.h" 59 #include "core/layout/LayoutView.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 static IntPoint dragLocationForSelectionDrag(LocalFrame* sourceFrame) 770 static IntPoint dragLocationForSelectionDrag(LocalFrame* sourceFrame)
770 { 771 {
771 IntRect draggingRect = enclosingIntRect(sourceFrame->selection().bounds()); 772 IntRect draggingRect = enclosingIntRect(sourceFrame->selection().bounds());
772 int xpos = draggingRect.maxX(); 773 int xpos = draggingRect.maxX();
773 xpos = draggingRect.x() < xpos ? draggingRect.x() : xpos; 774 xpos = draggingRect.x() < xpos ? draggingRect.x() : xpos;
774 int ypos = draggingRect.maxY(); 775 int ypos = draggingRect.maxY();
775 ypos = draggingRect.y() < ypos ? draggingRect.y() : ypos; 776 ypos = draggingRect.y() < ypos ? draggingRect.y() : ypos;
776 return IntPoint(xpos, ypos); 777 return IntPoint(xpos, ypos);
777 } 778 }
778 779
779 static const IntSize& maxDragImageSize() 780 static const IntSize maxDragImageSize(float deviceScaleFactor)
780 { 781 {
781 #if OS(MACOSX) 782 #if OS(MACOSX)
782 // Match Safari's drag image size. 783 // Match Safari's drag image size.
783 static const IntSize maxDragImageSize(400, 400); 784 static const IntSize maxDragImageSize(400, 400);
784 #else 785 #else
785 static const IntSize maxDragImageSize(200, 200); 786 static const IntSize maxDragImageSize(200, 200);
786 #endif 787 #endif
787 return maxDragImageSize; 788 IntSize maxSizeInPixels = maxDragImageSize;
789 maxSizeInPixels.scale(deviceScaleFactor);
790 return maxSizeInPixels;
788 } 791 }
789 792
790 static PassOwnPtr<DragImage> dragImageForImage(Element* element, Image* image, c onst IntPoint& dragOrigin, const IntPoint& imageLocation, const IntSize& imageSi zeInDIP, IntPoint& dragLocation) 793 static PassOwnPtr<DragImage> dragImageForImage(Element* element, Image* image, f loat deviceScaleFactor, const IntPoint& dragOrigin, const IntPoint& imageElement Location, const IntSize& imageElementSizeInPixels, IntPoint& dragLocation)
791 { 794 {
792 OwnPtr<DragImage> dragImage; 795 OwnPtr<DragImage> dragImage;
793 IntPoint origin; 796 IntPoint origin;
794 797
795 InterpolationQuality interpolationQuality = element->ensureComputedStyle()-> imageRendering() == ImageRenderingPixelated ? InterpolationNone : InterpolationH igh; 798 InterpolationQuality interpolationQuality = element->ensureComputedStyle()-> imageRendering() == ImageRenderingPixelated ? InterpolationNone : InterpolationH igh;
796 RespectImageOrientationEnum shouldRespectImageOrientation = LayoutObject::sh ouldRespectImageOrientation(element->layoutObject()); 799 RespectImageOrientationEnum shouldRespectImageOrientation = LayoutObject::sh ouldRespectImageOrientation(element->layoutObject());
797 ImageOrientation orientation; 800 ImageOrientation orientation;
798 801
799 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage()) 802 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit mapImage())
800 orientation = toBitmapImage(image)->currentFrameOrientation(); 803 orientation = toBitmapImage(image)->currentFrameOrientation();
801 804
802 if (image->size().height() * image->size().width() <= MaxOriginalImageArea 805 IntSize imageSize = orientation.usesWidthAsHeight() ? image->size().transpos edSize() : image->size();
806
807 FloatSize imageScale = DragImage::clampedImageScale(imageSize, imageElementS izeInPixels, maxDragImageSize(deviceScaleFactor));
808
809 if (imageSize.area() <= MaxOriginalImageArea
803 && (dragImage = DragImage::create(image, shouldRespectImageOrientation, 810 && (dragImage = DragImage::create(image, shouldRespectImageOrientation,
804 1 /* deviceScaleFactor */, interpolationQuality, DragImageAlpha, 811 deviceScaleFactor, interpolationQuality, DragImageAlpha, imageScale) )) {
805 DragImage::clampedImageScale(orientation.usesWidthAsHeight() ? image ->size().transposedSize() : image->size(), imageSizeInDIP, maxDragImageSize()))) ) { 812 IntSize originalSize = imageElementSizeInPixels;
806 IntSize originalSize = imageSizeInDIP; 813 origin = imageElementLocation;
807 origin = imageLocation;
808 814
809 IntSize newSize = dragImage->size(); 815 IntSize newSize = dragImage->size();
810 816
811 // Properly orient the drag image and orient it differently if it's smal ler than the original 817 // Properly orient the drag image and orient it differently if it's smal ler than the original
812 float scale = newSize.width() / (float)originalSize.width(); 818 float scale = newSize.width() / (float)originalSize.width();
813 float dx = origin.x() - dragOrigin.x(); 819 float dx = origin.x() - dragOrigin.x();
814 dx *= scale; 820 dx *= scale;
815 origin.setX((int)(dx + 0.5)); 821 origin.setX((int)(dx + 0.5));
816 float dy = origin.y() - dragOrigin.y(); 822 float dy = origin.y() - dragOrigin.y();
817 dy *= scale; 823 dy *= scale;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 return false; 883 return false;
878 Element* element = toElement(node); 884 Element* element = toElement(node);
879 Image* image = getImage(element); 885 Image* image = getImage(element);
880 if (!image || image->isNull()) 886 if (!image || image->isNull())
881 return false; 887 return false;
882 // We shouldn't be starting a drag for an image that can't provide an ex tension. 888 // We shouldn't be starting a drag for an image that can't provide an ex tension.
883 // This is an early detection for problems encountered later upon drop. 889 // This is an early detection for problems encountered later upon drop.
884 ASSERT(!image->filenameExtension().isEmpty()); 890 ASSERT(!image->filenameExtension().isEmpty());
885 if (!dragImage) { 891 if (!dragImage) {
886 const IntRect& imageRect = hitTestResult.imageRect(); 892 const IntRect& imageRect = hitTestResult.imageRect();
887 const IntSize& imageSizeInDIP = src->page()->chromeClient().viewport ToScreen(imageRect).size(); 893 IntSize imageSizeInPixels = imageRect.size();
894 // TODO(oshima): Remove this scaling and simply pass imageRect to dr agImageForImage
895 // once all platforms are migrated to use zoom for dsf.
896 imageSizeInPixels.scale(src->host()->deviceScaleFactor());
897
898 float screenDeviceScaleFactor = src->page()->chromeClient().screenIn fo().deviceScaleFactor;
888 // Pass the selected image size in DIP becasue dragImageForImage cli ps the image in DIP. 899 // Pass the selected image size in DIP becasue dragImageForImage cli ps the image in DIP.
889 // The coordinates of the locations are in Viewport coordinates, and they're converted in the Blink client. 900 // The coordinates of the locations are in Viewport coordinates, and they're converted in the Blink client.
890 // TODO(oshima): Currently, the dragged image on high DPI is scaled and can be blurry because of this. 901 // TODO(oshima): Currently, the dragged image on high DPI is scaled and can be blurry because of this.
891 // Consider to clip in the screen coordinates to use high resolution image on high DPI screens. 902 // Consider to clip in the screen coordinates to use high resolution image on high DPI screens.
892 dragImage = dragImageForImage(element, image, dragOrigin, imageRect. location(), imageSizeInDIP, dragLocation); 903 dragImage = dragImageForImage(element, image, screenDeviceScaleFacto r, dragOrigin, imageRect.location(), imageSizeInPixels, dragLocation);
893 } 904 }
894 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 905 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
895 } else if (state.m_dragType == DragSourceActionLink) { 906 } else if (state.m_dragType == DragSourceActionLink) {
896 if (linkURL.isEmpty()) 907 if (linkURL.isEmpty())
897 return false; 908 return false;
898 if (src->selection().isCaret() && src->selection().isContentEditable()) { 909 if (src->selection().isCaret() && src->selection().isContentEditable()) {
899 // a user can initiate a drag on a link without having any text 910 // a user can initiate a drag on a link without having any text
900 // selected. In this case, we should expand the selection to 911 // selected. In this case, we should expand the selection to
901 // the enclosing anchor element 912 // the enclosing anchor element
902 if (Node* node = enclosingAnchorElement(src->selection().base())) 913 if (Node* node = enclosingAnchorElement(src->selection().base()))
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 977
967 DEFINE_TRACE(DragController) 978 DEFINE_TRACE(DragController)
968 { 979 {
969 visitor->trace(m_page); 980 visitor->trace(m_page);
970 visitor->trace(m_documentUnderMouse); 981 visitor->trace(m_documentUnderMouse);
971 visitor->trace(m_dragInitiator); 982 visitor->trace(m_dragInitiator);
972 visitor->trace(m_fileInputElementUnderMouse); 983 visitor->trace(m_fileInputElementUnderMouse);
973 } 984 }
974 985
975 } // namespace blink 986 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698