| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 result.update(nullptr); | 181 result.update(nullptr); |
| 182 return result; | 182 return result; |
| 183 } | 183 } |
| 184 | 184 |
| 185 std::unique_ptr<DragImage> DragImage::create(const KURL& url, | 185 std::unique_ptr<DragImage> DragImage::create(const KURL& url, |
| 186 const String& inLabel, | 186 const String& inLabel, |
| 187 const FontDescription& systemFont, | 187 const FontDescription& systemFont, |
| 188 float deviceScaleFactor) { | 188 float deviceScaleFactor) { |
| 189 const Font labelFont = | 189 const Font labelFont = |
| 190 deriveDragLabelFont(kDragLinkLabelFontSize, FontWeightBold, systemFont); | 190 deriveDragLabelFont(kDragLinkLabelFontSize, FontWeightBold, systemFont); |
| 191 const SimpleFontData* labelFontData = labelFont.primaryFont(); |
| 192 DCHECK(labelFontData); |
| 191 const Font urlFont = | 193 const Font urlFont = |
| 192 deriveDragLabelFont(kDragLinkUrlFontSize, FontWeightNormal, systemFont); | 194 deriveDragLabelFont(kDragLinkUrlFontSize, FontWeightNormal, systemFont); |
| 195 const SimpleFontData* urlFontData = urlFont.primaryFont(); |
| 196 DCHECK(urlFontData); |
| 197 |
| 198 if (!labelFontData || !urlFontData) |
| 199 return nullptr; |
| 200 |
| 193 FontCachePurgePreventer fontCachePurgePreventer; | 201 FontCachePurgePreventer fontCachePurgePreventer; |
| 194 | 202 |
| 195 bool drawURLString = true; | 203 bool drawURLString = true; |
| 196 bool clipURLString = false; | 204 bool clipURLString = false; |
| 197 bool clipLabelString = false; | 205 bool clipLabelString = false; |
| 198 float maxDragLabelStringWidthDIP = | 206 float maxDragLabelStringWidthDIP = |
| 199 kMaxDragLabelStringWidth / deviceScaleFactor; | 207 kMaxDragLabelStringWidth / deviceScaleFactor; |
| 200 | 208 |
| 201 String urlString = url.getString(); | 209 String urlString = url.getString(); |
| 202 String label = inLabel.stripWhiteSpace(); | 210 String label = inLabel.stripWhiteSpace(); |
| 203 if (label.isEmpty()) { | 211 if (label.isEmpty()) { |
| 204 drawURLString = false; | 212 drawURLString = false; |
| 205 label = urlString; | 213 label = urlString; |
| 206 } | 214 } |
| 207 | 215 |
| 208 // First step is drawing the link drag image width. | 216 // First step is drawing the link drag image width. |
| 209 TextRun labelRun(label.impl()); | 217 TextRun labelRun(label.impl()); |
| 210 TextRun urlRun(urlString.impl()); | 218 TextRun urlRun(urlString.impl()); |
| 211 IntSize labelSize(labelFont.width(labelRun), | 219 IntSize labelSize(labelFont.width(labelRun), |
| 212 labelFont.getFontMetrics().ascent() + | 220 labelFontData->getFontMetrics().ascent() + |
| 213 labelFont.getFontMetrics().descent()); | 221 labelFontData->getFontMetrics().descent()); |
| 214 | 222 |
| 215 if (labelSize.width() > maxDragLabelStringWidthDIP) { | 223 if (labelSize.width() > maxDragLabelStringWidthDIP) { |
| 216 labelSize.setWidth(maxDragLabelStringWidthDIP); | 224 labelSize.setWidth(maxDragLabelStringWidthDIP); |
| 217 clipLabelString = true; | 225 clipLabelString = true; |
| 218 } | 226 } |
| 219 | 227 |
| 220 IntSize urlStringSize; | 228 IntSize urlStringSize; |
| 221 IntSize imageSize(labelSize.width() + kDragLabelBorderX * 2, | 229 IntSize imageSize(labelSize.width() + kDragLabelBorderX * 2, |
| 222 labelSize.height() + kDragLabelBorderY * 2); | 230 labelSize.height() + kDragLabelBorderY * 2); |
| 223 | 231 |
| 224 if (drawURLString) { | 232 if (drawURLString) { |
| 225 urlStringSize.setWidth(urlFont.width(urlRun)); | 233 urlStringSize.setWidth(urlFont.width(urlRun)); |
| 226 urlStringSize.setHeight(urlFont.getFontMetrics().ascent() + | 234 urlStringSize.setHeight(urlFontData->getFontMetrics().ascent() + |
| 227 urlFont.getFontMetrics().descent()); | 235 urlFontData->getFontMetrics().descent()); |
| 228 imageSize.setHeight(imageSize.height() + urlStringSize.height()); | 236 imageSize.setHeight(imageSize.height() + urlStringSize.height()); |
| 229 if (urlStringSize.width() > maxDragLabelStringWidthDIP) { | 237 if (urlStringSize.width() > maxDragLabelStringWidthDIP) { |
| 230 imageSize.setWidth(maxDragLabelStringWidthDIP); | 238 imageSize.setWidth(maxDragLabelStringWidthDIP); |
| 231 clipURLString = true; | 239 clipURLString = true; |
| 232 } else | 240 } else |
| 233 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + | 241 imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + |
| 234 kDragLabelBorderX * 2); | 242 kDragLabelBorderX * 2); |
| 235 } | 243 } |
| 236 | 244 |
| 237 // We now know how big the image needs to be, so we create and | 245 // We now know how big the image needs to be, so we create and |
| (...skipping 15 matching lines...) Expand all Loading... |
| 253 rrect.setRectXY(SkRect::MakeWH(imageSize.width(), imageSize.height()), | 261 rrect.setRectXY(SkRect::MakeWH(imageSize.width(), imageSize.height()), |
| 254 DragLabelRadius, DragLabelRadius); | 262 DragLabelRadius, DragLabelRadius); |
| 255 buffer->canvas()->drawRRect(rrect, backgroundPaint); | 263 buffer->canvas()->drawRRect(rrect, backgroundPaint); |
| 256 | 264 |
| 257 // Draw the text | 265 // Draw the text |
| 258 SkPaint textPaint; | 266 SkPaint textPaint; |
| 259 if (drawURLString) { | 267 if (drawURLString) { |
| 260 if (clipURLString) | 268 if (clipURLString) |
| 261 urlString = StringTruncator::centerTruncate( | 269 urlString = StringTruncator::centerTruncate( |
| 262 urlString, imageSize.width() - (kDragLabelBorderX * 2.0f), urlFont); | 270 urlString, imageSize.width() - (kDragLabelBorderX * 2.0f), urlFont); |
| 263 IntPoint textPos(kDragLabelBorderX, | 271 IntPoint textPos( |
| 264 imageSize.height() - (kLabelBorderYOffset + | 272 kDragLabelBorderX, |
| 265 urlFont.getFontMetrics().descent())); | 273 imageSize.height() - |
| 274 (kLabelBorderYOffset + urlFontData->getFontMetrics().descent())); |
| 266 TextRun textRun(urlString); | 275 TextRun textRun(urlString); |
| 267 urlFont.drawText(buffer->canvas(), TextRunPaintInfo(textRun), textPos, | 276 urlFont.drawText(buffer->canvas(), TextRunPaintInfo(textRun), textPos, |
| 268 deviceScaleFactor, textPaint); | 277 deviceScaleFactor, textPaint); |
| 269 } | 278 } |
| 270 | 279 |
| 271 if (clipLabelString) | 280 if (clipLabelString) |
| 272 label = StringTruncator::rightTruncate( | 281 label = StringTruncator::rightTruncate( |
| 273 label, imageSize.width() - (kDragLabelBorderX * 2.0f), labelFont); | 282 label, imageSize.width() - (kDragLabelBorderX * 2.0f), labelFont); |
| 274 | 283 |
| 275 bool hasStrongDirectionality; | 284 bool hasStrongDirectionality; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 305 m_interpolationQuality == InterpolationNone | 314 m_interpolationQuality == InterpolationNone |
| 306 ? skia::ImageOperations::RESIZE_BOX | 315 ? skia::ImageOperations::RESIZE_BOX |
| 307 : skia::ImageOperations::RESIZE_LANCZOS3; | 316 : skia::ImageOperations::RESIZE_LANCZOS3; |
| 308 int imageWidth = scaleX * m_bitmap.width(); | 317 int imageWidth = scaleX * m_bitmap.width(); |
| 309 int imageHeight = scaleY * m_bitmap.height(); | 318 int imageHeight = scaleY * m_bitmap.height(); |
| 310 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, | 319 m_bitmap = skia::ImageOperations::Resize(m_bitmap, resizeMethod, imageWidth, |
| 311 imageHeight); | 320 imageHeight); |
| 312 } | 321 } |
| 313 | 322 |
| 314 } // namespace blink | 323 } // namespace blink |
| OLD | NEW |