Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1413)

Side by Side Diff: Source/core/html/HTMLImageElement.cpp

Issue 369423002: Have srcset respond to viewport changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oilpan comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 using namespace HTMLNames; 48 using namespace HTMLNames;
49 49
50 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo ol createdByParser) 50 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo ol createdByParser)
51 : HTMLElement(imgTag, document) 51 : HTMLElement(imgTag, document)
52 , m_imageLoader(HTMLImageLoader::create(this)) 52 , m_imageLoader(HTMLImageLoader::create(this))
53 , m_compositeOperator(CompositeSourceOver) 53 , m_compositeOperator(CompositeSourceOver)
54 , m_imageDevicePixelRatio(1.0f) 54 , m_imageDevicePixelRatio(1.0f)
55 , m_formWasSetByParser(false) 55 , m_formWasSetByParser(false)
56 , m_elementCreatedByParser(createdByParser) 56 , m_elementCreatedByParser(createdByParser)
57 , m_intrinsicSizingViewportDependant(false)
58 , m_effectiveSizeViewportDependant(false)
59 , m_viewportListener(ImageViewportChangeListener::create(this))
57 { 60 {
58 ScriptWrappable::init(this); 61 ScriptWrappable::init(this);
59 if (form && form->inDocument()) { 62 if (form && form->inDocument()) {
60 #if ENABLE(OILPAN) 63 #if ENABLE(OILPAN)
61 m_form = form; 64 m_form = form;
62 #else 65 #else
63 m_form = form->createWeakPtr(); 66 m_form = form->createWeakPtr();
64 #endif 67 #endif
65 m_formWasSetByParser = true; 68 m_formWasSetByParser = true;
66 m_form->associate(*this); 69 m_form->associate(*this);
67 m_form->didAssociateByParser(); 70 m_form->didAssociateByParser();
68 } 71 }
69 } 72 }
70 73
71 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu ment) 74 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu ment)
72 { 75 {
73 return adoptRefWillBeNoop(new HTMLImageElement(document)); 76 return adoptRefWillBeNoop(new HTMLImageElement(document));
74 } 77 }
75 78
76 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu ment, HTMLFormElement* form, bool createdByParser) 79 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::create(Document& docu ment, HTMLFormElement* form, bool createdByParser)
77 { 80 {
78 return adoptRefWillBeNoop(new HTMLImageElement(document, form, createdByPars er)); 81 return adoptRefWillBeNoop(new HTMLImageElement(document, form, createdByPars er));
79 } 82 }
80 83
81 HTMLImageElement::~HTMLImageElement() 84 HTMLImageElement::~HTMLImageElement()
82 { 85 {
83 #if !ENABLE(OILPAN) 86 #if !ENABLE(OILPAN)
87 document().viewportChangeNotifier().removeListener(m_viewportListener.get()) ;
esprehn 2014/07/14 08:39:49 Or slower...
84 if (m_form) 88 if (m_form)
85 m_form->disassociate(*this); 89 m_form->disassociate(*this);
86 #endif 90 #endif
87 } 91 }
88 92
89 void HTMLImageElement::trace(Visitor* visitor) 93 void HTMLImageElement::trace(Visitor* visitor)
90 { 94 {
91 visitor->trace(m_imageLoader); 95 visitor->trace(m_imageLoader);
sof 2014/07/14 20:38:09 You need to trace the added field, visitor->tra
92 visitor->trace(m_form); 96 visitor->trace(m_form);
93 HTMLElement::trace(visitor); 97 HTMLElement::trace(visitor);
94 } 98 }
95 99
96 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo r(Document& document, int width, int height) 100 PassRefPtrWillBeRawPtr<HTMLImageElement> HTMLImageElement::createForJSConstructo r(Document& document, int width, int height)
97 { 101 {
98 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag eElement(document)); 102 RefPtrWillBeRawPtr<HTMLImageElement> image = adoptRefWillBeNoop(new HTMLImag eElement(document));
99 if (width) 103 if (width)
100 image->setWidth(width); 104 image->setWidth(width);
101 if (height) 105 if (height)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #endif 178 #endif
175 } 179 }
176 } 180 }
177 181
178 void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat e& candidate) 182 void HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(const ImageCandidat e& candidate)
179 { 183 {
180 m_bestFitImageURL = candidate.url(); 184 m_bestFitImageURL = candidate.url();
181 float candidateDensity = candidate.density(); 185 float candidateDensity = candidate.density();
182 if (candidateDensity >= 0) 186 if (candidateDensity >= 0)
183 m_imageDevicePixelRatio = 1.0 / candidateDensity; 187 m_imageDevicePixelRatio = 1.0 / candidateDensity;
188 if (candidate.resourceWidth() > 0)
189 m_intrinsicSizingViewportDependant = true;
184 if (renderer() && renderer()->isImage()) 190 if (renderer() && renderer()->isImage())
185 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRa tio); 191 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRa tio);
186 } 192 }
187 193
188 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 194 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
189 { 195 {
190 if (name == altAttr) { 196 if (name == altAttr) {
191 if (renderer() && renderer()->isImage()) 197 if (renderer() && renderer()->isImage())
192 toRenderImage(renderer())->updateAltText(); 198 toRenderImage(renderer())->updateAltText();
193 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) { 199 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 String srcset = source->fastGetAttribute(srcsetAttr); 245 String srcset = source->fastGetAttribute(srcsetAttr);
240 if (srcset.isEmpty()) 246 if (srcset.isEmpty())
241 continue; 247 continue;
242 String type = source->fastGetAttribute(typeAttr); 248 String type = source->fastGetAttribute(typeAttr);
243 if (!type.isEmpty() && !supportedImageType(type)) 249 if (!type.isEmpty() && !supportedImageType(type))
244 continue; 250 continue;
245 251
246 if (!source->mediaQueryMatches()) 252 if (!source->mediaQueryMatches())
247 continue; 253 continue;
248 254
249 unsigned effectiveSize = SizesAttributeParser::findEffectiveSize(source- >fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document())); 255 unsigned effectiveSize = SizesAttributeParser::findEffectiveSize(source- >fastGetAttribute(sizesAttr), MediaValuesDynamic::create(document()), m_effectiv eSizeViewportDependant);
250 ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().de vicePixelRatio(), effectiveSize, source->fastGetAttribute(srcsetAttr)); 256 ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().de vicePixelRatio(), effectiveSize, source->fastGetAttribute(srcsetAttr));
251 if (candidate.isEmpty()) 257 if (candidate.isEmpty())
252 continue; 258 continue;
253 return candidate; 259 return candidate;
254 } 260 }
255 return ImageCandidate(); 261 return ImageCandidate();
256 } 262 }
257 263
258 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style) 264 RenderObject* HTMLImageElement::createRenderer(RenderStyle* style)
259 { 265 {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 ImageCandidate candidate = findBestFitImageFromPictureParent(); 568 ImageCandidate candidate = findBestFitImageFromPictureParent();
563 if (!candidate.isEmpty()) { 569 if (!candidate.isEmpty()) {
564 setBestFitURLAndDPRFromImageCandidate(candidate); 570 setBestFitURLAndDPRFromImageCandidate(candidate);
565 foundURL = true; 571 foundURL = true;
566 } 572 }
567 } 573 }
568 574
569 if (!foundURL) { 575 if (!foundURL) {
570 unsigned effectiveSize = 0; 576 unsigned effectiveSize = 0;
571 if (RuntimeEnabledFeatures::pictureSizesEnabled()) 577 if (RuntimeEnabledFeatures::pictureSizesEnabled())
572 effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttri bute(sizesAttr), MediaValuesDynamic::create(document())); 578 effectiveSize = SizesAttributeParser::findEffectiveSize(fastGetAttri bute(sizesAttr), MediaValuesDynamic::create(document()), m_effectiveSizeViewport Dependant);
573 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr)); 579 ImageCandidate candidate = bestFitSourceForImageAttributes(document().de vicePixelRatio(), effectiveSize, fastGetAttribute(srcAttr), fastGetAttribute(src setAttr));
574 setBestFitURLAndDPRFromImageCandidate(candidate); 580 setBestFitURLAndDPRFromImageCandidate(candidate);
575 } 581 }
582 if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant)
583 document().viewportChangeNotifier().addListener(m_viewportListener.get() );
576 imageLoader().updateFromElement(behavior); 584 imageLoader().updateFromElement(behavior);
577 } 585 }
578 586
579 const KURL& HTMLImageElement::sourceURL() const 587 const KURL& HTMLImageElement::sourceURL() const
580 { 588 {
581 return cachedImage()->response().url(); 589 return cachedImage()->response().url();
582 } 590 }
583 591
584 } 592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698