Changeset 194926 in webkit
- Timestamp:
- Jan 12, 2016 2:18:19 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r194923 r194926 1 2016-01-12 Dave Hyatt <hyatt@apple.com> 2 3 Avoid downloading the wrong image for <picture> elements. 4 https://bugs.webkit.org/show_bug.cgi?id=153027 5 6 Reviewed by Dean Jackson. 7 8 I was unable to write a reliable test for this feature (I welcome suggestions regarding 9 how this could be tested). 10 11 * html/HTMLImageElement.cpp: 12 (WebCore::HTMLImageElement::HTMLImageElement): 13 (WebCore::HTMLImageElement::~HTMLImageElement): 14 (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): 15 (WebCore::HTMLImageElement::insertedInto): 16 (WebCore::HTMLImageElement::removedFrom): 17 (WebCore::HTMLImageElement::pictureNode): 18 (WebCore::HTMLImageElement::setPictureNode): 19 * html/HTMLImageElement.h: 20 * html/parser/HTMLConstructionSite.cpp: 21 (WebCore::HTMLConstructionSite::createHTMLElement): 22 23 Images that are built underneath a <picture> element are now connected 24 to that picture element via a setPictureNode call from the parser. This 25 ensures that the correct <source> elements are examined before checking the image. 26 27 This connection between images and their picture owners is handled using a static 28 HashMap in HTMLImageElement. This connection is made both from the parser and from 29 DOM insertions, and the map is queried now instead of looking directly at the 30 image's parentNode(). 31 32 Also note the change to pass the document element's computed style in for media 33 query evaluation. Just as with the preload scanner, the image's style can't be 34 used as it has not been determined yet. 35 1 36 2016-01-12 Myles C. Maxfield <mmaxfield@apple.com> 2 37 -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r194617 r194926 54 54 using namespace HTMLNames; 55 55 56 typedef HashMap<const Node*, Node*> PictureOwnerMap; 57 static PictureOwnerMap* gPictureOwnerMap = nullptr; 58 56 59 HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form) 57 60 : HTMLElement(tagName, document) … … 83 86 if (m_form) 84 87 m_form->removeImgElement(this); 88 setPictureNode(nullptr); 85 89 } 86 90 … … 141 145 ImageCandidate HTMLImageElement::bestFitSourceFromPictureElement() 142 146 { 143 auto* p arent = parentNode();144 if (! is<HTMLPictureElement>(parent))147 auto* pictureOwner = pictureNode(); 148 if (!pictureOwner) 145 149 return { }; 146 auto* picture = downcast<HTMLPictureElement>(p arent);150 auto* picture = downcast<HTMLPictureElement>(pictureOwner); 147 151 picture->clearViewportDependentResults(); 148 152 document().removeViewportDependentPicture(*picture); 149 for (Node* child = p arent->firstChild(); child && child != this; child = child->nextSibling()) {153 for (Node* child = picture->firstChild(); child && child != this; child = child->nextSibling()) { 150 154 if (!is<HTMLSourceElement>(*child)) 151 155 continue; … … 164 168 continue; 165 169 } 166 MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), computedStyle());170 MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement()->computedStyle()); 167 171 bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults()); 168 172 if (picture->hasViewportDependentResults()) … … 314 318 document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this); 315 319 316 if (is<HTMLPictureElement>(parentNode())) 320 if (is<HTMLPictureElement>(parentNode())) { 321 setPictureNode(parentNode()); 317 322 selectImageSource(); 323 } 318 324 319 325 // If we have been inserted from a renderer-less document, … … 332 338 if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull()) 333 339 document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this); 334 340 341 if (is<HTMLPictureElement>(parentNode())) 342 setPictureNode(nullptr); 343 335 344 m_form = nullptr; 336 345 HTMLElement::removedFrom(insertionPoint); 337 346 } 338 347 348 Node* HTMLImageElement::pictureNode() const 349 { 350 if (!gPictureOwnerMap) 351 return nullptr; 352 return gPictureOwnerMap->get(this); 353 } 354 355 void HTMLImageElement::setPictureNode(Node* node) 356 { 357 if (!node) { 358 if (gPictureOwnerMap) 359 gPictureOwnerMap->remove(this); 360 return; 361 } 362 363 if (!gPictureOwnerMap) 364 gPictureOwnerMap = new PictureOwnerMap(); 365 gPictureOwnerMap->add(this, node); 366 } 367 339 368 int HTMLImageElement::width(bool ignorePendingStylesheets) 340 369 { -
trunk/Source/WebCore/html/HTMLImageElement.h
r193840 r194926 88 88 89 89 bool hasShadowControls() const { return m_experimentalImageMenuEnabled; } 90 91 Node* pictureNode() const; 92 void setPictureNode(Node*); 90 93 91 94 protected: … … 128 131 HTMLFormElement* m_form; 129 132 HTMLFormElement* m_formSetByParser; 133 130 134 CompositeOperator m_compositeOperator; 131 135 AtomicString m_bestFitImageURL; -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp
r194496 r194926 37 37 #include "HTMLFormElement.h" 38 38 #include "HTMLHtmlElement.h" 39 #include "HTMLImageElement.h" 39 40 #include "HTMLOptGroupElement.h" 40 41 #include "HTMLOptionElement.h" 41 42 #include "HTMLParserIdioms.h" 43 #include "HTMLPictureElement.h" 42 44 #include "HTMLScriptElement.h" 43 45 #include "HTMLTemplateElement.h" … … 641 643 bool insideTemplateElement = !ownerDocument.frame(); 642 644 RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, insideTemplateElement ? nullptr : form(), true); 645 646 // FIXME: This is a hack to connect images to pictures before the image has 647 // been inserted into the document. It can be removed once asynchronous image 648 // loading is working. 649 if (is<HTMLPictureElement>(currentNode()) && is<HTMLImageElement>(*element.get())) 650 downcast<HTMLImageElement>(*element.get()).setPictureNode(¤tNode()); 651 643 652 setAttributes(element.get(), token, m_parserContentPolicy); 644 653 ASSERT(element->isHTMLElement());
Note: See TracChangeset
for help on using the changeset viewer.