OLD | NEW |
---|---|
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 Loading... | |
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 { |
86 document().viewportChangeNotifier().removeListener(m_viewportListener); | |
haraken
2014/07/11 06:10:21
In oilpan, destructors cannot touch other on-heap
| |
83 #if !ENABLE(OILPAN) | 87 #if !ENABLE(OILPAN) |
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); |
92 visitor->trace(m_form); | 96 visitor->trace(m_form); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 Loading... | |
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); | |
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 } |
OLD | NEW |