| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 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 are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 { | 259 { |
| 260 if (attribute.isNull()) | 260 if (attribute.isNull()) |
| 261 return; | 261 return; |
| 262 | 262 |
| 263 if (attribute.is8Bit()) | 263 if (attribute.is8Bit()) |
| 264 parseImageCandidatesFromSrcsetAttribute<LChar>(attribute, attribute.char
acters8(), attribute.length(), imageCandidates); | 264 parseImageCandidatesFromSrcsetAttribute<LChar>(attribute, attribute.char
acters8(), attribute.length(), imageCandidates); |
| 265 else | 265 else |
| 266 parseImageCandidatesFromSrcsetAttribute<UChar>(attribute, attribute.char
acters16(), attribute.length(), imageCandidates); | 266 parseImageCandidatesFromSrcsetAttribute<UChar>(attribute, attribute.char
acters16(), attribute.length(), imageCandidates); |
| 267 } | 267 } |
| 268 | 268 |
| 269 static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, unsigned s
ourceSize, Vector<ImageCandidate>& imageCandidates) | 269 static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, float sour
ceSize, Vector<ImageCandidate>& imageCandidates) |
| 270 { | 270 { |
| 271 const float defaultDensityValue = 1.0; | 271 const float defaultDensityValue = 1.0; |
| 272 bool ignoreSrc = false; | 272 bool ignoreSrc = false; |
| 273 if (imageCandidates.isEmpty()) | 273 if (imageCandidates.isEmpty()) |
| 274 return ImageCandidate(); | 274 return ImageCandidate(); |
| 275 | 275 |
| 276 // http://picture.responsiveimages.org/#normalize-source-densities | 276 // http://picture.responsiveimages.org/#normalize-source-densities |
| 277 for (Vector<ImageCandidate>::iterator it = imageCandidates.begin(); it != im
ageCandidates.end(); ++it) { | 277 for (Vector<ImageCandidate>::iterator it = imageCandidates.begin(); it != im
ageCandidates.end(); ++it) { |
| 278 if (it->resourceWidth() > 0) { | 278 if (it->resourceWidth() > 0) { |
| 279 it->setDensity((float)it->resourceWidth() / (float)sourceSize); | 279 it->setDensity((float)it->resourceWidth() / (float)sourceSize); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 299 | 299 |
| 300 unsigned winner = i; | 300 unsigned winner = i; |
| 301 // 16. If an entry b in candidates has the same associated ... pixel density
as an earlier entry a in candidates, | 301 // 16. If an entry b in candidates has the same associated ... pixel density
as an earlier entry a in candidates, |
| 302 // then remove entry b | 302 // then remove entry b |
| 303 while ((i > 0) && (imageCandidates[--i].density() == winningDensity)) | 303 while ((i > 0) && (imageCandidates[--i].density() == winningDensity)) |
| 304 winner = i; | 304 winner = i; |
| 305 | 305 |
| 306 return imageCandidates[winner]; | 306 return imageCandidates[winner]; |
| 307 } | 307 } |
| 308 | 308 |
| 309 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned
sourceSize, const String& srcsetAttribute) | 309 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, float so
urceSize, const String& srcsetAttribute) |
| 310 { | 310 { |
| 311 Vector<ImageCandidate> imageCandidates; | 311 Vector<ImageCandidate> imageCandidates; |
| 312 | 312 |
| 313 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); | 313 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); |
| 314 | 314 |
| 315 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
); | 315 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
); |
| 316 } | 316 } |
| 317 | 317 |
| 318 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned
sourceSize, const String& srcAttribute, const String& srcsetAttribute) | 318 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, float so
urceSize, const String& srcAttribute, const String& srcsetAttribute) |
| 319 { | 319 { |
| 320 if (srcsetAttribute.isNull()) { | 320 if (srcsetAttribute.isNull()) { |
| 321 if (srcAttribute.isNull()) | 321 if (srcAttribute.isNull()) |
| 322 return ImageCandidate(); | 322 return ImageCandidate(); |
| 323 return ImageCandidate(srcAttribute, 0, srcAttribute.length(), Descriptor
ParsingResult(), ImageCandidate::SrcOrigin); | 323 return ImageCandidate(srcAttribute, 0, srcAttribute.length(), Descriptor
ParsingResult(), ImageCandidate::SrcOrigin); |
| 324 } | 324 } |
| 325 | 325 |
| 326 Vector<ImageCandidate> imageCandidates; | 326 Vector<ImageCandidate> imageCandidates; |
| 327 | 327 |
| 328 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); | 328 parseImageCandidatesFromSrcsetAttribute(srcsetAttribute, imageCandidates); |
| 329 | 329 |
| 330 if (!srcAttribute.isEmpty()) | 330 if (!srcAttribute.isEmpty()) |
| 331 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng
th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin)); | 331 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng
th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin)); |
| 332 | 332 |
| 333 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
); | 333 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
); |
| 334 } | 334 } |
| 335 | 335 |
| 336 String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceS
ize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate) | 336 String bestFitSourceForImageAttributes(float deviceScaleFactor, float sourceSize
, const String& srcAttribute, ImageCandidate& srcsetImageCandidate) |
| 337 { | 337 { |
| 338 if (srcsetImageCandidate.isEmpty()) | 338 if (srcsetImageCandidate.isEmpty()) |
| 339 return srcAttribute; | 339 return srcAttribute; |
| 340 | 340 |
| 341 Vector<ImageCandidate> imageCandidates; | 341 Vector<ImageCandidate> imageCandidates; |
| 342 imageCandidates.append(srcsetImageCandidate); | 342 imageCandidates.append(srcsetImageCandidate); |
| 343 | 343 |
| 344 if (!srcAttribute.isEmpty()) | 344 if (!srcAttribute.isEmpty()) |
| 345 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng
th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin)); | 345 imageCandidates.append(ImageCandidate(srcAttribute, 0, srcAttribute.leng
th(), DescriptorParsingResult(), ImageCandidate::SrcOrigin)); |
| 346 | 346 |
| 347 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
).toString(); | 347 return pickBestImageCandidate(deviceScaleFactor, sourceSize, imageCandidates
).toString(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 } | 350 } |
| OLD | NEW |