Changeset 169573 in webkit
- Timestamp:
- Jun 3, 2014 3:44:26 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r169528 r169573 1707 1707 html/parser/HTMLScriptRunner.cpp 1708 1708 html/parser/HTMLSourceTracker.cpp 1709 html/parser/HTMLSrcsetParser.cpp 1709 1710 html/parser/HTMLTokenizer.cpp 1710 1711 html/parser/HTMLTreeBuilder.cpp -
trunk/Source/WebCore/ChangeLog
r169572 r169573 1 2014-06-03 Yoav Weiss <yoav@yoav.ws> 2 3 Refactor the srcset parser into its own file 4 https://bugs.webkit.org/show_bug.cgi?id=133480 5 6 Reviewed by Andreas Kling. 7 8 No new tests, since this patch doesn't change the parser's behavior. 9 10 This patch moves the srcset parser into its own file, 11 in order to prepare the code for alignment with recent spec changes. 12 13 * CMakeLists.txt: 14 * html/HTMLImageElement.cpp: 15 * html/parser/HTMLParserIdioms.cpp: 16 (WebCore::compareByScaleFactor): Deleted. 17 (WebCore::parseDescriptors): Deleted. 18 (WebCore::parseImagesWithScaleFromSrcsetAttribute): Deleted. 19 (WebCore::bestFitSourceForImageAttributes): Deleted. 20 * html/parser/HTMLParserIdioms.h: 21 (WebCore::ImageWithScale::ImageWithScale): Deleted. 22 (WebCore::ImageWithScale::imageURL): Deleted. 23 (WebCore::ImageWithScale::scaleFactor): Deleted. 24 * html/parser/HTMLPreloadScanner.cpp: 25 * html/parser/HTMLSrcsetParser.cpp: Added. 26 (WebCore::compareByScaleFactor): 27 (WebCore::parseDescriptors): 28 (WebCore::parseImagesWithScaleFromSrcsetAttribute): 29 (WebCore::bestFitSourceForImageAttributes): 30 * html/parser/HTMLSrcsetParser.h: Added. 31 (WebCore::ImageWithScale::ImageWithScale): 32 (WebCore::ImageWithScale::imageURL): 33 (WebCore::ImageWithScale::scaleFactor): 34 1 35 2014-06-03 Mario Sanchez Prada <mario.prada@samsung.com> 2 36 -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r169380 r169573 15870 15870 <ClCompile Include="..\html\parser\HTMLScriptRunner.cpp" /> 15871 15871 <ClCompile Include="..\html\parser\HTMLSourceTracker.cpp" /> 15872 <ClCompile Include="..\html\parser\HTMLSrcsetParser.cpp" /> 15872 15873 <ClCompile Include="..\html\parser\HTMLTokenizer.cpp" /> 15873 15874 <ClCompile Include="..\html\parser\HTMLTreeBuilder.cpp" /> … … 20667 20668 <ClInclude Include="..\html\parser\HTMLScriptRunnerHost.h" /> 20668 20669 <ClInclude Include="..\html\parser\HTMLSourceTracker.h" /> 20670 <ClInclude Include="..\html\parser\HTMLSrcsetParser.h" /> 20669 20671 <ClInclude Include="..\html\parser\HTMLStackItem.h" /> 20670 20672 <ClInclude Include="..\html\parser\HTMLToken.h" /> -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r169328 r169573 4123 4123 <Filter>html\parser</Filter> 4124 4124 </ClCompile> 4125 <ClCompile Include="..\html\parser\HTMLSrcsetParser.cpp"> 4126 <Filter>html\parser</Filter> 4127 </ClCompile> 4125 4128 <ClCompile Include="..\html\parser\HTMLTokenizer.cpp"> 4126 4129 <Filter>html\parser</Filter> … … 11202 11205 </ClInclude> 11203 11206 <ClInclude Include="..\html\parser\HTMLSourceTracker.h"> 11207 <Filter>html\parser</Filter> 11208 </ClInclude> 11209 <ClInclude Include="..\html\parser\HTMLSrcsetParser.h"> 11204 11210 <Filter>html\parser</Filter> 11205 11211 </ClInclude> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r169409 r169573 2012 2012 5317612213C516690026E454 /* StyleFlexibleBoxData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */; }; 2013 2013 5317612313C516690026E454 /* StyleFlexibleBoxData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5317612113C516690026E454 /* StyleFlexibleBoxData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2014 536D5A20193E18E900CE4CAB /* HTMLSrcsetParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 536D5A1F193E18E900CE4CAB /* HTMLSrcsetParser.h */; }; 2015 536D5A21193E18EE00CE4CAB /* HTMLSrcsetParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 536D5A1E193E18D000CE4CAB /* HTMLSrcsetParser.cpp */; }; 2014 2016 53C8298D13D8D92700DE2DEB /* RenderFlexibleBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53C8298B13D8D92700DE2DEB /* RenderFlexibleBox.cpp */; }; 2015 2017 53C8298E13D8D92700DE2DEB /* RenderFlexibleBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 53C8298C13D8D92700DE2DEB /* RenderFlexibleBox.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 9073 9075 5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleFlexibleBoxData.cpp; path = style/StyleFlexibleBoxData.cpp; sourceTree = "<group>"; }; 9074 9076 5317612113C516690026E454 /* StyleFlexibleBoxData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleFlexibleBoxData.h; path = style/StyleFlexibleBoxData.h; sourceTree = "<group>"; }; 9077 536D5A1E193E18D000CE4CAB /* HTMLSrcsetParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HTMLSrcsetParser.cpp; path = parser/HTMLSrcsetParser.cpp; sourceTree = "<group>"; }; 9078 536D5A1F193E18E900CE4CAB /* HTMLSrcsetParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLSrcsetParser.h; path = parser/HTMLSrcsetParser.h; sourceTree = "<group>"; }; 9075 9079 53C8298B13D8D92700DE2DEB /* RenderFlexibleBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFlexibleBox.cpp; sourceTree = "<group>"; }; 9076 9080 53C8298C13D8D92700DE2DEB /* RenderFlexibleBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderFlexibleBox.h; sourceTree = "<group>"; }; … … 18190 18194 977E2DCB12F0E28300C13379 /* HTMLSourceTracker.cpp */, 18191 18195 977E2DCC12F0E28300C13379 /* HTMLSourceTracker.h */, 18196 536D5A1F193E18E900CE4CAB /* HTMLSrcsetParser.h */, 18197 536D5A1E193E18D000CE4CAB /* HTMLSrcsetParser.cpp */, 18192 18198 97C1F552122855CB00EDE615 /* HTMLStackItem.h */, 18193 18199 97C1F552122855CB00EDE616 /* HTMLToken.h */, … … 26312 26318 A14832BB187F643200DA63A6 /* WAKWindow.h in Headers */, 26313 26319 FD7F299213D4C0CB00AD9535 /* WaveShaperDSPKernel.h in Headers */, 26320 536D5A20193E18E900CE4CAB /* HTMLSrcsetParser.h in Headers */, 26314 26321 FD7F299413D4C0CB00AD9535 /* WaveShaperNode.h in Headers */, 26315 26322 FD7F299713D4C0CB00AD9535 /* WaveShaperProcessor.h in Headers */, … … 27544 27551 6E0E569B183BFFE600E0E8D5 /* FloatRoundedRect.cpp in Sources */, 27545 27552 B275356C0B053814002CE64F /* FloatSize.cpp in Sources */, 27553 536D5A21193E18EE00CE4CAB /* HTMLSrcsetParser.cpp in Sources */, 27546 27554 B275355B0B053814002CE64F /* FloatSizeCG.cpp in Sources */, 27547 27555 B275357A0B053814002CE64F /* FloatSizeMac.mm in Sources */, -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r167786 r169573 34 34 #include "HTMLFormElement.h" 35 35 #include "HTMLParserIdioms.h" 36 #include "HTMLSrcsetParser.h" 36 37 #include "Page.h" 37 38 #include "RenderImage.h" -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp
r165848 r169573 291 291 } 292 292 293 typedef Vector<ImageWithScale> ImageCandidates; 294 295 static inline bool compareByScaleFactor(const ImageWithScale& first, const ImageWithScale& second) 296 { 297 return first.scaleFactor() < second.scaleFactor(); 298 } 299 300 static bool parseDescriptors(const String& attribute, size_t start, size_t end, float& imageScaleFactor) 301 { 302 size_t descriptorStart; 303 size_t descriptorEnd; 304 size_t position = start; 305 bool isFoundScaleFactor = false; 306 bool isEmptyDescriptor = !(end > start); 307 bool isValid = false; 308 309 while (position < end) { 310 while (isHTMLSpace(attribute[position]) && position < end) 311 ++position; 312 descriptorStart = position; 313 while (isNotHTMLSpace(attribute[position]) && position < end) 314 ++position; 315 descriptorEnd = position; 316 317 // Leave if there is only whitespace at the end of the descriptors 318 if (descriptorEnd <= descriptorStart) 319 break; 320 321 --descriptorEnd; 322 // This part differs from the spec as the current implementation only supports pixel density descriptors. 323 if (attribute[descriptorEnd] != 'x') 324 continue; 325 326 if (isFoundScaleFactor) 327 return false; 328 329 if (attribute.is8Bit()) 330 imageScaleFactor = charactersToFloat(attribute.characters8() + descriptorStart, descriptorEnd - descriptorStart, &isValid); 331 else 332 imageScaleFactor = charactersToFloat(attribute.characters16() + descriptorStart, descriptorEnd - descriptorStart, &isValid); 333 isFoundScaleFactor = true; 334 } 335 336 return isEmptyDescriptor || isValid; 337 } 338 339 // See the specifications for more details about the algorithm to follow. 340 // http://www.w3.org/TR/2013/WD-html-srcset-20130228/#processing-the-image-candidates. 341 static void parseImagesWithScaleFromSrcsetAttribute(const String& srcsetAttribute, ImageCandidates& imageCandidates) 342 { 343 ASSERT(imageCandidates.isEmpty()); 344 345 size_t imageCandidateStart = 0; 346 unsigned srcsetAttributeLength = srcsetAttribute.length(); 347 348 while (imageCandidateStart < srcsetAttributeLength) { 349 float imageScaleFactor = 1; 350 size_t separator; 351 352 // 4. Splitting loop: Skip whitespace. 353 size_t imageURLStart = srcsetAttribute.find(isNotHTMLSpace, imageCandidateStart); 354 if (imageURLStart == notFound) 355 break; 356 // If The current candidate is either totally empty or only contains space, skipping. 357 if (srcsetAttribute[imageURLStart] == ',') { 358 imageCandidateStart = imageURLStart + 1; 359 continue; 360 } 361 // 5. Collect a sequence of characters that are not space characters, and let that be url. 362 size_t imageURLEnd = srcsetAttribute.find(isHTMLSpace, imageURLStart + 1); 363 if (imageURLEnd == notFound) { 364 imageURLEnd = srcsetAttributeLength; 365 separator = srcsetAttributeLength; 366 } else if (srcsetAttribute[imageURLEnd - 1] == ',') { 367 --imageURLEnd; 368 separator = imageURLEnd; 369 } else { 370 // 7. Collect a sequence of characters that are not "," (U+002C) characters, and let that be descriptors. 371 size_t imageScaleStart = srcsetAttribute.find(isNotHTMLSpace, imageURLEnd + 1); 372 imageScaleStart = (imageScaleStart == notFound) ? srcsetAttributeLength : imageScaleStart; 373 size_t imageScaleEnd = srcsetAttribute.find(',' , imageScaleStart + 1); 374 imageScaleEnd = (imageScaleEnd == notFound) ? srcsetAttributeLength : imageScaleEnd; 375 376 if (!parseDescriptors(srcsetAttribute, imageScaleStart, imageScaleEnd, imageScaleFactor)) { 377 imageCandidateStart = imageScaleEnd + 1; 378 continue; 379 } 380 separator = imageScaleEnd; 381 } 382 ImageWithScale image(imageURLStart, imageURLEnd - imageURLStart, imageScaleFactor); 383 imageCandidates.append(image); 384 // 11. Return to the step labeled splitting loop. 385 imageCandidateStart = separator + 1; 386 } 387 } 388 389 ImageWithScale bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& srcsetAttribute) 390 { 391 ImageCandidates imageCandidates; 392 393 parseImagesWithScaleFromSrcsetAttribute(srcsetAttribute, imageCandidates); 394 395 if (!srcAttribute.isEmpty()) { 396 ImageWithScale srcPlaceholderImage; 397 imageCandidates.append(srcPlaceholderImage); 398 } 399 400 if (imageCandidates.isEmpty()) 401 return ImageWithScale(); 402 403 std::stable_sort(imageCandidates.begin(), imageCandidates.end(), compareByScaleFactor); 404 405 for (size_t i = 0; i < imageCandidates.size() - 1; ++i) { 406 if (imageCandidates[i].scaleFactor() >= deviceScaleFactor) 407 return imageCandidates[i]; 408 } 409 410 // 16. If an entry b in candidates has the same associated ... pixel density as an earlier entry a in candidates, 411 // then remove entry b 412 size_t winner = imageCandidates.size() - 1; 413 size_t previousCandidate = winner; 414 float winningScaleFactor = imageCandidates.last().scaleFactor(); 415 while ((previousCandidate > 0) && (imageCandidates[--previousCandidate].scaleFactor() == winningScaleFactor)) 416 winner = previousCandidate; 417 418 return imageCandidates[winner]; 419 } 420 421 } 293 } -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.h
r163415 r169573 33 33 34 34 class Decimal; 35 36 class ImageWithScale {37 public:38 ImageWithScale()39 : m_imageURLStart(0)40 , m_imageURLLength(0)41 , m_scaleFactor(1)42 {43 }44 45 ImageWithScale(unsigned start, unsigned length, float scaleFactor)46 : m_imageURLStart(start)47 , m_imageURLLength(length)48 , m_scaleFactor(scaleFactor)49 {50 }51 52 String imageURL(const String& srcAttribute, const String& srcsetAttribute) const53 {54 return m_imageURLLength ? srcsetAttribute.substringSharingImpl(m_imageURLStart, m_imageURLLength) : srcAttribute;55 }56 57 float scaleFactor() const58 {59 return m_scaleFactor;60 }61 62 private:63 unsigned m_imageURLStart;64 unsigned m_imageURLLength;65 float m_scaleFactor;66 };67 35 68 36 // Space characters as defined by the HTML specification. … … 132 100 bool threadSafeMatch(const QualifiedName&, const QualifiedName&); 133 101 134 ImageWithScale bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& sourceSetAttribute);135 136 102 } 137 103 -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp
r163415 r169573 31 31 #include "HTMLNames.h" 32 32 #include "HTMLParserIdioms.h" 33 #include "HTMLSrcsetParser.h" 33 34 #include "HTMLTokenizer.h" 34 35 #include "InputTypeNames.h"
Note: See TracChangeset
for help on using the changeset viewer.