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