Chromium Code Reviews| 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 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) | 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) |
| 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
| 10 * | 10 * |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * You should have received a copy of the GNU Library General Public License | 21 * You should have received a copy of the GNU Library General Public License |
| 22 * along with this library; see the file COPYING.LIB. If not, write to | 22 * along with this library; see the file COPYING.LIB. If not, write to |
| 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 * Boston, MA 02110-1301, USA. | 24 * Boston, MA 02110-1301, USA. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/rendering/RenderImage.h" | 29 #include "core/rendering/RenderImage.h" |
| 30 | 30 |
| 31 #include "core/HTMLNames.h" | |
| 31 #include "core/editing/FrameSelection.h" | 32 #include "core/editing/FrameSelection.h" |
| 32 #include "core/fetch/ImageResource.h" | 33 #include "core/fetch/ImageResource.h" |
| 33 #include "core/fetch/ResourceLoader.h" | 34 #include "core/fetch/ResourceLoader.h" |
| 34 #include "core/frame/LocalFrame.h" | 35 #include "core/frame/LocalFrame.h" |
| 35 #include "core/html/HTMLImageElement.h" | 36 #include "core/html/HTMLImageElement.h" |
| 36 #include "core/inspector/InspectorTraceEvents.h" | 37 #include "core/inspector/InspectorTraceEvents.h" |
| 37 #include "core/rendering/HitTestResult.h" | 38 #include "core/rendering/HitTestResult.h" |
| 38 #include "core/rendering/PaintInfo.h" | 39 #include "core/rendering/PaintInfo.h" |
| 39 #include "core/rendering/RenderLayer.h" | 40 #include "core/rendering/RenderLayer.h" |
| 40 #include "core/rendering/RenderView.h" | 41 #include "core/rendering/RenderView.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 65 { | 66 { |
| 66 } | 67 } |
| 67 | 68 |
| 68 void RenderImage::destroy() | 69 void RenderImage::destroy() |
| 69 { | 70 { |
| 70 ASSERT(m_imageResource); | 71 ASSERT(m_imageResource); |
| 71 m_imageResource->shutdown(); | 72 m_imageResource->shutdown(); |
| 72 RenderReplaced::destroy(); | 73 RenderReplaced::destroy(); |
| 73 } | 74 } |
| 74 | 75 |
| 76 void RenderImage::intrinsicSizeChanged() | |
| 77 { | |
| 78 if (m_imageResource) | |
| 79 imageChanged(m_imageResource->imagePtr()); | |
| 80 } | |
| 81 | |
| 75 void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource ) | 82 void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource ) |
| 76 { | 83 { |
| 77 ASSERT(!m_imageResource); | 84 ASSERT(!m_imageResource); |
| 78 m_imageResource = imageResource; | 85 m_imageResource = imageResource; |
| 79 m_imageResource->initialize(this); | 86 m_imageResource->initialize(this); |
| 80 } | 87 } |
| 81 | 88 |
| 82 void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect) | 89 void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect) |
| 83 { | 90 { |
| 84 if (documentBeingDestroyed()) | 91 if (documentBeingDestroyed()) |
| 85 return; | 92 return; |
| 86 | 93 |
| 87 if (hasBoxDecorationBackground() || hasMask()) | |
| 88 RenderReplaced::imageChanged(newImage, rect); | |
| 89 | |
| 90 if (!m_imageResource) | 94 if (!m_imageResource) |
| 91 return; | 95 return; |
| 92 | 96 |
| 93 if (newImage != m_imageResource->imagePtr()) | 97 if (newImage != m_imageResource->imagePtr()) |
| 94 return; | 98 return; |
| 95 | 99 |
| 96 // Per the spec, we let the server-sent header override srcset/other sources of dpr. | 100 // Per the spec, we let the server-sent header override srcset/other sources of dpr. |
| 97 // https://github.com/igrigorik/http-client-hints/blob/master/draft-grigorik -http-client-hints-01.txt#L255 | 101 // https://github.com/igrigorik/http-client-hints/blob/master/draft-grigorik -http-client-hints-01.txt#L255 |
| 98 if (m_imageResource->cachedImage() && m_imageResource->cachedImage()->hasDev icePixelRatioHeaderValue()) | 102 if (m_imageResource->cachedImage() && m_imageResource->cachedImage()->hasDev icePixelRatioHeaderValue()) |
| 99 m_imageDevicePixelRatio = 1 / m_imageResource->cachedImage()->devicePixe lRatioHeaderValue(); | 103 m_imageDevicePixelRatio = 1 / m_imageResource->cachedImage()->devicePixe lRatioHeaderValue(); |
| 100 | 104 |
| 105 // If the RenderImage was just created we don't have style() or a parent() | |
| 106 // yet so all we can do is update our intrinsic size. Once we're inserted | |
| 107 // the resulting layout will do the rest of the work. | |
| 108 if (!parent()) { | |
| 109 updateIntrinsicSizeIfNeeded(m_imageResource->intrinsicSize()); | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 if (hasBoxDecorationBackground() || hasMask()) | |
| 114 RenderReplaced::imageChanged(newImage, rect); | |
|
ojan
2014/11/18 03:34:47
This makes me a little future-proof nervous. If so
| |
| 115 | |
| 101 paintInvalidationOrMarkForLayout(rect); | 116 paintInvalidationOrMarkForLayout(rect); |
| 102 } | 117 } |
| 103 | 118 |
| 104 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) | 119 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) |
| 105 { | 120 { |
| 106 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) | 121 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) |
| 107 return; | 122 return; |
| 108 setIntrinsicSize(newSize); | 123 setIntrinsicSize(newSize); |
| 109 } | 124 } |
| 110 | 125 |
| 111 void RenderImage::updateInnerContentRect() | 126 void RenderImage::updateInnerContentRect() |
| 112 { | 127 { |
| 113 // Propagate container size to the image resource. | 128 // Propagate container size to the image resource. |
| 114 LayoutRect containerRect = replacedContentRect(); | 129 LayoutRect containerRect = replacedContentRect(); |
| 115 IntSize containerSize(containerRect.width(), containerRect.height()); | 130 IntSize containerSize(containerRect.width(), containerRect.height()); |
| 116 if (!containerSize.isEmpty()) | 131 if (!containerSize.isEmpty()) |
| 117 m_imageResource->setContainerSizeForRenderer(containerSize); | 132 m_imageResource->setContainerSizeForRenderer(containerSize); |
| 118 } | 133 } |
| 119 | 134 |
| 120 void RenderImage::paintInvalidationOrMarkForLayout(const IntRect* rect) | 135 void RenderImage::paintInvalidationOrMarkForLayout(const IntRect* rect) |
| 121 { | 136 { |
| 137 ASSERT(isRooted()); | |
| 138 | |
| 122 LayoutSize oldIntrinsicSize = intrinsicSize(); | 139 LayoutSize oldIntrinsicSize = intrinsicSize(); |
| 123 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(); | 140 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(); |
| 124 updateIntrinsicSizeIfNeeded(newIntrinsicSize); | 141 updateIntrinsicSizeIfNeeded(newIntrinsicSize); |
| 125 | 142 |
| 126 // In the case of generated image content using :before/:after/content, we m ight not be | |
| 127 // in the render tree yet. In that case, we just need to update our intrinsi c size. | |
| 128 // layout() will be called after we are inserted in the tree which will take care of | |
| 129 // what we are doing here. | |
| 130 if (!containingBlock()) | |
| 131 return; | |
| 132 | |
| 133 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize; | 143 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize; |
| 134 if (imageSourceHasChangedSize) | 144 if (imageSourceHasChangedSize) |
| 135 setPreferredLogicalWidthsDirty(); | 145 setPreferredLogicalWidthsDirty(); |
| 136 | 146 |
| 137 // If the actual area occupied by the image has changed and it is not constr ained by style then a layout is required. | 147 // If the actual area occupied by the image has changed and it is not constr ained by style then a layout is required. |
| 138 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style ()->logicalHeight().isSpecified(); | 148 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style ()->logicalHeight().isSpecified(); |
| 139 | 149 |
| 140 // FIXME: We only need to recompute the containing block's preferred size if the containing block's size | 150 // FIXME: We only need to recompute the containing block's preferred size if the containing block's size |
| 141 // depends on the image's size (i.e., the container uses shrink-to-fit sizin g). | 151 // depends on the image's size (i.e., the container uses shrink-to-fit sizin g). |
| 142 // There's no easy way to detect that shrink-to-fit is needed, always force a layout. | 152 // There's no easy way to detect that shrink-to-fit is needed, always force a layout. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 return; | 351 return; |
| 342 } | 352 } |
| 343 } | 353 } |
| 344 | 354 |
| 345 bool RenderImage::needsPreferredWidthsRecalculation() const | 355 bool RenderImage::needsPreferredWidthsRecalculation() const |
| 346 { | 356 { |
| 347 return RenderReplaced::needsPreferredWidthsRecalculation(); | 357 return RenderReplaced::needsPreferredWidthsRecalculation(); |
| 348 } | 358 } |
| 349 | 359 |
| 350 } // namespace blink | 360 } // namespace blink |
| OLD | NEW |