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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 PassOwnPtr<DragImage> DragImage::create(const KURL& url, const String& inLabel,
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 kMaxDragLabelStringWidthDIP = kMaxDragLabelStringWidth / deviceScaleFa
ctor; | 179 float maxDragLabelStringWidthDIP = kMaxDragLabelStringWidth / deviceScaleFac
tor; |
180 | 180 |
181 String urlString = url.string(); | 181 String urlString = url.string(); |
182 String label = inLabel.stripWhiteSpace(); | 182 String label = inLabel.stripWhiteSpace(); |
183 if (label.isEmpty()) { | 183 if (label.isEmpty()) { |
184 drawURLString = false; | 184 drawURLString = false; |
185 label = urlString; | 185 label = urlString; |
186 } | 186 } |
187 | 187 |
188 // First step is drawing the link drag image width. | 188 // First step is drawing the link drag image width. |
189 TextRun labelRun(label.impl()); | 189 TextRun labelRun(label.impl()); |
190 TextRun urlRun(urlString.impl()); | 190 TextRun urlRun(urlString.impl()); |
191 IntSize labelSize(labelFont.width(labelRun), labelFont.fontMetrics().ascent(
) + labelFont.fontMetrics().descent()); | 191 IntSize labelSize(labelFont.width(labelRun), labelFont.fontMetrics().ascent(
) + labelFont.fontMetrics().descent()); |
192 | 192 |
193 if (labelSize.width() > kMaxDragLabelStringWidthDIP) { | 193 if (labelSize.width() > maxDragLabelStringWidthDIP) { |
194 labelSize.setWidth(kMaxDragLabelStringWidthDIP); | 194 labelSize.setWidth(maxDragLabelStringWidthDIP); |
195 clipLabelString = true; | 195 clipLabelString = true; |
196 } | 196 } |
197 | 197 |
198 IntSize urlStringSize; | 198 IntSize urlStringSize; |
199 IntSize imageSize(labelSize.width() + kDragLabelBorderX * 2, labelSize.heigh
t() + kDragLabelBorderY * 2); | 199 IntSize imageSize(labelSize.width() + kDragLabelBorderX * 2, labelSize.heigh
t() + kDragLabelBorderY * 2); |
200 | 200 |
201 if (drawURLString) { | 201 if (drawURLString) { |
202 urlStringSize.setWidth(urlFont.width(urlRun)); | 202 urlStringSize.setWidth(urlFont.width(urlRun)); |
203 urlStringSize.setHeight(urlFont.fontMetrics().ascent() + urlFont.fontMet
rics().descent()); | 203 urlStringSize.setHeight(urlFont.fontMetrics().ascent() + urlFont.fontMet
rics().descent()); |
204 imageSize.setHeight(imageSize.height() + urlStringSize.height()); | 204 imageSize.setHeight(imageSize.height() + urlStringSize.height()); |
205 if (urlStringSize.width() > kMaxDragLabelStringWidthDIP) { | 205 if (urlStringSize.width() > maxDragLabelStringWidthDIP) { |
206 imageSize.setWidth(kMaxDragLabelStringWidthDIP); | 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 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); | 216 OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); |
(...skipping 51 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 |