OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "platform/text/BidiTextRun.h" | 43 #include "platform/text/BidiTextRun.h" |
44 #include "platform/text/StringTruncator.h" | 44 #include "platform/text/StringTruncator.h" |
45 #include "platform/text/TextRun.h" | 45 #include "platform/text/TextRun.h" |
46 #include "platform/transforms/AffineTransform.h" | 46 #include "platform/transforms/AffineTransform.h" |
47 #include "platform/weborigin/KURL.h" | 47 #include "platform/weborigin/KURL.h" |
48 #include "skia/ext/image_operations.h" | 48 #include "skia/ext/image_operations.h" |
49 #include "third_party/skia/include/core/SkCanvas.h" | 49 #include "third_party/skia/include/core/SkCanvas.h" |
50 #include "third_party/skia/include/core/SkImage.h" | 50 #include "third_party/skia/include/core/SkImage.h" |
51 #include "third_party/skia/include/core/SkMatrix.h" | 51 #include "third_party/skia/include/core/SkMatrix.h" |
52 #include "third_party/skia/include/core/SkSurface.h" | 52 #include "third_party/skia/include/core/SkSurface.h" |
53 #include "wtf/PtrUtil.h" | 53 #include "wtf/PassOwnPtr.h" |
54 #include "wtf/RefPtr.h" | 54 #include "wtf/RefPtr.h" |
55 #include "wtf/text/WTFString.h" | 55 #include "wtf/text/WTFString.h" |
| 56 |
56 #include <algorithm> | 57 #include <algorithm> |
57 #include <memory> | |
58 | 58 |
59 namespace blink { | 59 namespace blink { |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 const float kDragLabelBorderX = 4; | 63 const float kDragLabelBorderX = 4; |
64 // Keep border_y in synch with DragController::LinkDragBorderInset. | 64 // Keep border_y in synch with DragController::LinkDragBorderInset. |
65 const float kDragLabelBorderY = 2; | 65 const float kDragLabelBorderY = 2; |
66 const float kLabelBorderYOffset = 2; | 66 const float kLabelBorderYOffset = 2; |
67 | 67 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Uniform scaling for clamping. | 125 // Uniform scaling for clamping. |
126 const float clampScaleX = size.width() > maxSize.width() | 126 const float clampScaleX = size.width() > maxSize.width() |
127 ? static_cast<float>(maxSize.width()) / size.width() : 1; | 127 ? static_cast<float>(maxSize.width()) / size.width() : 1; |
128 const float clampScaleY = size.height() > maxSize.height() | 128 const float clampScaleY = size.height() > maxSize.height() |
129 ? static_cast<float>(maxSize.height()) / size.height() : 1; | 129 ? static_cast<float>(maxSize.height()) / size.height() : 1; |
130 imageScale.scale(std::min(clampScaleX, clampScaleY)); | 130 imageScale.scale(std::min(clampScaleX, clampScaleY)); |
131 | 131 |
132 return imageScale; | 132 return imageScale; |
133 } | 133 } |
134 | 134 |
135 std::unique_ptr<DragImage> DragImage::create(Image* image, | 135 PassOwnPtr<DragImage> DragImage::create(Image* image, |
136 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale
Factor, | 136 RespectImageOrientationEnum shouldRespectImageOrientation, float deviceScale
Factor, |
137 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca
le) | 137 InterpolationQuality interpolationQuality, float opacity, FloatSize imageSca
le) |
138 { | 138 { |
139 if (!image) | 139 if (!image) |
140 return nullptr; | 140 return nullptr; |
141 | 141 |
142 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); | 142 RefPtr<SkImage> skImage = image->imageForCurrentFrame(); |
143 if (!skImage) | 143 if (!skImage) |
144 return nullptr; | 144 return nullptr; |
145 | 145 |
146 ImageOrientation orientation; | 146 ImageOrientation orientation; |
147 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit
mapImage()) | 147 if (shouldRespectImageOrientation == RespectImageOrientation && image->isBit
mapImage()) |
148 orientation = toBitmapImage(image)->currentFrameOrientation(); | 148 orientation = toBitmapImage(image)->currentFrameOrientation(); |
149 | 149 |
150 SkBitmap bm; | 150 SkBitmap bm; |
151 RefPtr<SkImage> resizedImage = | 151 RefPtr<SkImage> resizedImage = |
152 resizeAndOrientImage(skImage.release(), orientation, imageScale, opacity
, interpolationQuality); | 152 resizeAndOrientImage(skImage.release(), orientation, imageScale, opacity
, interpolationQuality); |
153 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB
itmapMode)) | 153 if (!resizedImage || !resizedImage->asLegacyBitmap(&bm, SkImage::kRO_LegacyB
itmapMode)) |
154 return nullptr; | 154 return nullptr; |
155 | 155 |
156 return wrapUnique(new DragImage(bm, deviceScaleFactor, interpolationQuality)
); | 156 return adoptPtr(new DragImage(bm, deviceScaleFactor, interpolationQuality)); |
157 } | 157 } |
158 | 158 |
159 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr
iption& systemFont) | 159 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr
iption& systemFont) |
160 { | 160 { |
161 FontDescription description = systemFont; | 161 FontDescription description = systemFont; |
162 description.setWeight(fontWeight); | 162 description.setWeight(fontWeight); |
163 description.setSpecifiedSize(size); | 163 description.setSpecifiedSize(size); |
164 description.setComputedSize(size); | 164 description.setComputedSize(size); |
165 Font result(description); | 165 Font result(description); |
166 result.update(nullptr); | 166 result.update(nullptr); |
167 return result; | 167 return result; |
168 } | 168 } |
169 | 169 |
170 std::unique_ptr<DragImage> DragImage::create(const KURL& url, const String& inLa
bel, const FontDescription& systemFont, float deviceScaleFactor) | 170 PassOwnPtr<DragImage> DragImage::create(const KURL& url, const String& inLabel,
const FontDescription& systemFont, float deviceScaleFactor) |
171 { | 171 { |
172 const Font labelFont = deriveDragLabelFont(kDragLinkLabelFontSize, FontWeigh
tBold, systemFont); | 172 const Font labelFont = deriveDragLabelFont(kDragLinkLabelFontSize, FontWeigh
tBold, systemFont); |
173 const Font urlFont = deriveDragLabelFont(kDragLinkUrlFontSize, FontWeightNor
mal, systemFont); | 173 const Font urlFont = deriveDragLabelFont(kDragLinkUrlFontSize, FontWeightNor
mal, systemFont); |
174 FontCachePurgePreventer fontCachePurgePreventer; | 174 FontCachePurgePreventer fontCachePurgePreventer; |
175 | 175 |
176 bool drawURLString = true; | 176 bool drawURLString = true; |
177 bool clipURLString = false; | 177 bool clipURLString = false; |
178 bool clipLabelString = false; | 178 bool clipLabelString = false; |
179 float maxDragLabelStringWidthDIP = kMaxDragLabelStringWidth / deviceScaleFac
tor; | 179 float maxDragLabelStringWidthDIP = kMaxDragLabelStringWidth / deviceScaleFac
tor; |
180 | 180 |
(...skipping 25 matching lines...) Expand all Loading... |
206 imageSize.setWidth(maxDragLabelStringWidthDIP); | 206 imageSize.setWidth(maxDragLabelStringWidthDIP); |
207 clipURLString = true; | 207 clipURLString = true; |
208 } else | 208 } else |
209 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()
) + kDragLabelBorderX * 2); | 209 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()
) + kDragLabelBorderX * 2); |
210 } | 210 } |
211 | 211 |
212 // We now know how big the image needs to be, so we create and | 212 // We now know how big the image needs to be, so we create and |
213 // fill the background | 213 // fill the background |
214 IntSize scaledImageSize = imageSize; | 214 IntSize scaledImageSize = imageSize; |
215 scaledImageSize.scale(deviceScaleFactor); | 215 scaledImageSize.scale(deviceScaleFactor); |
216 std::unique_ptr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); | 216 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); |
217 if (!buffer) | 217 if (!buffer) |
218 return nullptr; | 218 return nullptr; |
219 | 219 |
220 buffer->canvas()->scale(deviceScaleFactor, deviceScaleFactor); | 220 buffer->canvas()->scale(deviceScaleFactor, deviceScaleFactor); |
221 | 221 |
222 const float DragLabelRadius = 5; | 222 const float DragLabelRadius = 5; |
223 | 223 |
224 IntRect rect(IntPoint(), imageSize); | 224 IntRect rect(IntPoint(), imageSize); |
225 SkPaint backgroundPaint; | 225 SkPaint backgroundPaint; |
226 backgroundPaint.setColor(SkColorSetRGB(140, 140, 140)); | 226 backgroundPaint.setColor(SkColorSetRGB(140, 140, 140)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 void DragImage::scale(float scaleX, float scaleY) | 269 void DragImage::scale(float scaleX, float scaleY) |
270 { | 270 { |
271 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality ==
InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations::
RESIZE_LANCZOS3; | 271 skia::ImageOperations::ResizeMethod resizeMethod = m_interpolationQuality ==
InterpolationNone ? skia::ImageOperations::RESIZE_BOX : skia::ImageOperations::
RESIZE_LANCZOS3; |
272 int imageWidth = scaleX * m_bitmap.width(); | 272 int imageWidth = scaleX * m_bitmap.width(); |
273 int imageHeight = scaleY * m_bitmap.height(); | 273 int imageHeight = scaleY * m_bitmap.height(); |
274 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth,
imageHeight); | 274 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth,
imageHeight); |
275 } | 275 } |
276 | 276 |
277 } // namespace blink | 277 } // namespace blink |
OLD | NEW |