Changeset 194865 in webkit
- Timestamp:
- Jan 11, 2016 1:49:20 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 17 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r194864 r194865 1 2016-01-11 Dave Hyatt <hyatt@apple.com> 2 3 Picture element needs to work with the preload scanner and select the correct 4 source element instead of loading the image. 5 https://bugs.webkit.org/show_bug.cgi?id=152983 6 7 Reviewed by Dean Jackson. 8 9 These tests are imported from Blink, although they have been modified slightly to 10 reflect the fact that we pass the nested <picture> cases that Blink fails. 11 12 * http/tests/loading/hidpi-preload-picture-sizes-expected.txt: Added. 13 * http/tests/loading/hidpi-preload-picture-sizes.html: Added. 14 * http/tests/loading/preload-picture-invalid-expected.txt: Added. 15 * http/tests/loading/preload-picture-invalid.html: Added. 16 * http/tests/loading/preload-picture-nested-expected.txt: Added. 17 * http/tests/loading/preload-picture-nested.html: Added. 18 * http/tests/loading/preload-picture-sizes-expected.txt: Added. 19 * http/tests/loading/preload-picture-sizes.html: Added. 20 * http/tests/loading/resources/base-image1.png: Added. 21 * http/tests/loading/resources/base-image2.png: Added. 22 * http/tests/loading/resources/base-image3.png: Added. 23 * http/tests/loading/resources/dup-image1.png: Added. 24 * http/tests/loading/resources/dup-image2.png: Added. 25 * http/tests/loading/resources/dup-image3.png: Added. 26 * http/tests/loading/resources/image1.png: Added. 27 * http/tests/loading/resources/image2.png: Added. 28 * http/tests/loading/resources/picture-preload-helper.js: Added. 29 1 30 2016-01-11 Brady Eidson <beidson@apple.com> 2 31 -
trunk/Source/WebCore/ChangeLog
r194864 r194865 1 2016-01-11 Dave Hyatt <hyatt@apple.com> 2 3 Picture element needs to work with the preload scanner and select the correct 4 source element instead of loading the image. 5 https://bugs.webkit.org/show_bug.cgi?id=152983 6 7 Reviewed by Dean Jackson. 8 9 Added new tests in http/tests/loading. 10 11 * html/parser/HTMLPreloadScanner.cpp: 12 (WebCore::TokenPreloadScanner::tagIdFor): 13 (WebCore::TokenPreloadScanner::initiatorFor): 14 (WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner): 15 (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): 16 (WebCore::TokenPreloadScanner::StartTagScanner::processImageAndScriptAttribute): 17 (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): 18 (WebCore::TokenPreloadScanner::StartTagScanner::resourceType): 19 (WebCore::TokenPreloadScanner::scan): 20 * html/parser/HTMLPreloadScanner.h: 21 (WebCore::TokenPreloadScanner::setPredictedBaseElementURL): 22 (WebCore::TokenPreloadScanner::inPicture): 23 1 24 2016-01-11 Brady Eidson <beidson@apple.com> 2 25 -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp
r194496 r194865 35 35 #include "InputTypeNames.h" 36 36 #include "LinkRelAttribute.h" 37 #include "MediaList.h" 38 #include "MediaQueryEvaluator.h" 37 39 #include "SourceSizeList.h" 38 40 #include <wtf/MainThread.h> … … 63 65 if (tagName == metaTag) 64 66 return TagId::Meta; 67 if (tagName == pictureTag) 68 return TagId::Picture; 69 if (tagName == sourceTag) 70 return TagId::Source; 65 71 return TagId::Unknown; 66 72 } … … 71 77 case TagId::Iframe: 72 78 return "iframe"; 79 case TagId::Source: 73 80 case TagId::Img: 74 81 return "img"; … … 84 91 case TagId::Template: 85 92 case TagId::Meta: 93 case TagId::Picture: 86 94 ASSERT_NOT_REACHED(); 87 95 return "unknown"; … … 102 110 } 103 111 104 void processAttributes(const HTMLToken::AttributeList& attributes, Document& document )112 void processAttributes(const HTMLToken::AttributeList& attributes, Document& document, Vector<bool>& pictureState) 105 113 { 106 114 ASSERT(isMainThread()); 107 115 if (m_tagId >= TagId::Unknown) 108 116 return; 109 117 110 118 for (auto& attribute : attributes) { 111 119 AtomicString attributeName(attribute.name); 112 120 String attributeValue = StringImpl::create8BitIfPossible(attribute.value); 113 processAttribute(attributeName, attributeValue); 114 } 115 121 processAttribute(attributeName, attributeValue, document, pictureState); 122 } 123 124 if (m_tagId == TagId::Source && !pictureState.isEmpty() && !pictureState.last() && m_mediaMatched && !m_srcSetAttribute.isEmpty()) { 125 float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame()); 126 ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize); 127 if (!imageCandidate.isEmpty()) { 128 pictureState.last() = true; 129 setUrlToLoad(imageCandidate.string.toString(), true); 130 } 131 } 132 116 133 // Resolve between src and srcSet if we have them and the tag is img. 117 134 if (m_tagId == TagId::Img && !m_srcSetAttribute.isEmpty()) { 118 float sourceSize = 0; 119 sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame()); 135 float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame()); 120 136 ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize); 121 137 setUrlToLoad(imageCandidate.string.toString(), true); … … 155 171 } 156 172 157 void processAttribute(const AtomicString& attributeName, const String& attributeValue) 158 { 173 void processAttribute(const AtomicString& attributeName, const String& attributeValue, Document& document, const Vector<bool>& pictureState) 174 { 175 bool inPicture = !pictureState.isEmpty(); 176 bool alreadyMatchedSource = inPicture && pictureState.last(); 177 159 178 switch (m_tagId) { 160 179 case TagId::Iframe: … … 163 182 break; 164 183 case TagId::Img: 184 if (inPicture && alreadyMatchedSource) 185 break; 165 186 if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull()) { 166 187 m_srcSetAttribute = attributeValue; … … 172 193 } 173 194 processImageAndScriptAttribute(attributeName, attributeValue); 195 break; 196 case TagId::Source: 197 if (inPicture && alreadyMatchedSource) 198 break; 199 if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull()) { 200 m_srcSetAttribute = attributeValue; 201 break; 202 } 203 if (match(attributeName, sizesAttr) && m_sizesAttribute.isNull()) { 204 m_sizesAttribute = attributeValue; 205 break; 206 } 207 if (match(attributeName, mediaAttr) && m_mediaAttribute.isNull()) { 208 m_mediaAttribute = attributeValue; 209 Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue); 210 Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults; 211 MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement()->computedStyle()); 212 m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults); 213 } 174 214 break; 175 215 case TagId::Script: … … 201 241 case TagId::Style: 202 242 case TagId::Template: 243 case TagId::Picture: 203 244 case TagId::Unknown: 204 245 break; … … 238 279 case TagId::Img: 239 280 case TagId::Input: 281 case TagId::Source: 240 282 ASSERT(m_tagId != TagId::Input || m_inputIsImage); 241 283 return CachedResource::ImageResource; … … 248 290 case TagId::Base: 249 291 case TagId::Template: 292 case TagId::Picture: 250 293 break; 251 294 } … … 280 323 String m_srcSetAttribute; 281 324 String m_sizesAttribute; 325 bool m_mediaMatched { true }; 282 326 String m_charset; 283 327 String m_crossOriginMode; … … 318 362 m_cssScanner.reset(); 319 363 m_inStyle = false; 320 } 364 } else if (tagId == TagId::Picture && !m_pictureSourceState.isEmpty()) 365 m_pictureSourceState.removeLast(); 366 321 367 return; 322 368 } … … 345 391 return; 346 392 } 393 if (tagId == TagId::Picture) { 394 m_pictureSourceState.append(false); 395 return; 396 } 347 397 348 398 StartTagScanner scanner(tagId, m_deviceScaleFactor); 349 scanner.processAttributes(token.attributes(), document );399 scanner.processAttributes(token.attributes(), document, m_pictureSourceState); 350 400 if (auto request = scanner.createPreloadRequest(m_predictedBaseElementURL)) 351 401 requests.append(WTFMove(request)); -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.h
r191180 r194865 42 42 43 43 void setPredictedBaseElementURL(const URL& url) { m_predictedBaseElementURL = url; } 44 45 bool inPicture() { return !m_pictureSourceState.isEmpty(); } 44 46 45 47 private: … … 52 54 Script, 53 55 Meta, 56 Source, 54 57 55 58 // These tags are not scanned by the StartTagScanner. … … 58 61 Base, 59 62 Template, 63 Picture 60 64 }; 61 65 … … 74 78 URL m_predictedBaseElementURL; 75 79 bool m_inStyle { false }; 80 81 Vector<bool> m_pictureSourceState; 82 76 83 #if ENABLE(TEMPLATE_ELEMENT) 77 84 unsigned m_templateCount { 0 };
Note: See TracChangeset
for help on using the changeset viewer.