Index: third_party/WebKit/Source/platform/DragImage.cpp |
diff --git a/third_party/WebKit/Source/platform/DragImage.cpp b/third_party/WebKit/Source/platform/DragImage.cpp |
index be1b995eb8d560f7f8c384bd07ad110ece9ac7dd..e639e03cbcd086133a57d84a32e5cc9809f18205 100644 |
--- a/third_party/WebKit/Source/platform/DragImage.cpp |
+++ b/third_party/WebKit/Source/platform/DragImage.cpp |
@@ -72,9 +72,24 @@ const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde |
const float kDragLinkLabelFontSize = 11; |
const float kDragLinkUrlFontSize = 10; |
-PassRefPtr<SkImage> adjustedImage(PassRefPtr<SkImage> image, const IntSize& size, |
- const AffineTransform& transform, float opacity, InterpolationQuality interpolationQuality) |
+} // anonymous namespace |
+ |
+PassRefPtr<SkImage> DragImage::resizeAndOrientImage(PassRefPtr<SkImage> image, ImageOrientation orientation, |
+ FloatSize imageScale, float opacity, InterpolationQuality interpolationQuality) |
{ |
+ IntSize size(image->width(), image->height()); |
+ size.scale(imageScale.width(), imageScale.height()); |
+ AffineTransform transform; |
+ if (orientation != DefaultImageOrientation) { |
+ if (orientation.usesWidthAsHeight()) |
+ size = size.transposedSize(); |
+ transform *= orientation.transformFromDefault(size); |
+ } |
+ transform.scaleNonUniform(imageScale.width(), imageScale.height()); |
+ |
+ if (size.isEmpty()) |
+ return nullptr; |
+ |
if (transform.isIdentity() && opacity == 1) { |
// Nothing to adjust, just use the original. |
ASSERT(image->width() == size.width()); |
@@ -100,15 +115,13 @@ PassRefPtr<SkImage> adjustedImage(PassRefPtr<SkImage> image, const IntSize& size |
return adoptRef(surface->newImageSnapshot()); |
} |
-} // anonymous namespace |
- |
-FloatSize DragImage::clampedImageScale(const Image& image, const IntSize& size, |
+FloatSize DragImage::clampedImageScale(const IntSize& imageSize, const IntSize& size, |
const IntSize& maxSize) |
{ |
// Non-uniform scaling for size mapping. |
FloatSize imageScale( |
- static_cast<float>(size.width()) / image.width(), |
- static_cast<float>(size.height()) / image.height()); |
+ static_cast<float>(size.width()) / imageSize.width(), |
+ static_cast<float>(size.height()) / imageSize.height()); |
// Uniform scaling for clamping. |
const float clampScaleX = size.width() > maxSize.width() |
@@ -122,7 +135,7 @@ FloatSize DragImage::clampedImageScale(const Image& image, const IntSize& size, |
PassOwnPtr<DragImage> DragImage::create(Image* image, |
RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScaleFactor, |
- InterpolationQuality interpolationQuality, float opacity, const FloatSize& imageScale) |
+ InterpolationQuality interpolationQuality, float opacity, FloatSize imageScale) |
{ |
if (!image) |
return nullptr; |
@@ -131,32 +144,13 @@ PassOwnPtr<DragImage> DragImage::create(Image* image, |
if (!skImage) |
return nullptr; |
- IntSize size = image->size(); |
- size.scale(imageScale.width(), imageScale.height()); |
- if (size.isEmpty()) |
- return nullptr; |
- |
- AffineTransform transform; |
- transform.scaleNonUniform(imageScale.width(), imageScale.height()); |
- |
- if (shouldRespectImageOrientation == RespectImageOrientation && image->isBitmapImage()) { |
- BitmapImage* bitmapImage = toBitmapImage(image); |
- ImageOrientation orientation = bitmapImage->currentFrameOrientation(); |
- |
- if (orientation != DefaultImageOrientation) { |
- size = bitmapImage->sizeRespectingOrientation(); |
- if (orientation.usesWidthAsHeight()) |
- size.scale(imageScale.height(), imageScale.width()); |
- else |
- size.scale(imageScale.width(), imageScale.height()); |
- |
- transform *= orientation.transformFromDefault(size); |
- } |
- } |
+ ImageOrientation orientation; |
+ if (shouldRespectImageOrientation == RespectImageOrientation && image->isBitmapImage()) |
+ orientation = toBitmapImage(image)->currentFrameOrientation(); |
SkBitmap bm; |
RefPtr<SkImage> resizedImage = |
- adjustedImage(skImage.release(), size, transform, opacity, interpolationQuality); |
+ resizeAndOrientImage(skImage.release(), orientation, imageScale, opacity, interpolationQuality); |
if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) |
return nullptr; |