FloatSize SVGImagePainter::computeImageViewportSize() const { DCHECK(m_layoutSVGImage.imageResource()->hasImage()); if (toSVGImageElement(m_layoutSVGImage.element()) ->preserveAspectRatio() ->currentValue() ->align() != SVGPreserveAspectRatio::kSvgPreserveaspectratioNone) return m_layoutSVGImage.objectBoundingBox().size(); ImageResourceContent* cachedImage = m_layoutSVGImage.imageResource()->cachedImage(); // Images with preserveAspectRatio=none should force non-uniform scaling. This // can be achieved by setting the image's container size to its viewport size // (i.e. concrete object size returned by the default sizing algorithm.) See // https://www.w3.org/TR/SVG/single-page.html#coords-PreserveAspectRatioAttribute // and https://drafts.csswg.org/css-images-3/#default-sizing. // Avoid returning the size of the broken image. if (cachedImage->errorOccurred()) return FloatSize(); if (cachedImage->getImage()->isSVGImage()) return toSVGImage(cachedImage->getImage()) ->concreteObjectSize(m_layoutSVGImage.objectBoundingBox().size()); return FloatSize(cachedImage->getImage()->size()); }
static Image* renderableImageForCSSValue(CSSValue* value, const LayoutObject& layoutObject) { ImageResourceContent* cachedImage = cachedImageForCSSValue(value, layoutObject.document()); if (!cachedImage || cachedImage->errorOccurred() || cachedImage->getImage()->isNull()) return nullptr; return cachedImage->getImage(); }
FloatSize LayoutSVGImage::calculateObjectSize() const { ImageResourceContent* cachedImage = m_imageResource->cachedImage(); if (!cachedImage || cachedImage->errorOccurred()) return m_objectBoundingBox.size(); FloatSize intrinsicSize = FloatSize(cachedImage->getImage()->size()); if (styleRef().width().isAuto() && styleRef().height().isAuto()) return intrinsicSize; if (styleRef().height().isAuto()) return FloatSize( m_objectBoundingBox.width(), resolveHeightForRatio(m_objectBoundingBox.width(), intrinsicSize)); DCHECK(styleRef().width().isAuto()); return FloatSize( resolveWidthForRatio(m_objectBoundingBox.height(), intrinsicSize), m_objectBoundingBox.height()); }
void CSSCrossfadeValue::loadSubimages(const Document& document) { ImageResourceContent* oldCachedFromImage = m_cachedFromImage; ImageResourceContent* oldCachedToImage = m_cachedToImage; m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), document); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeObserver(&m_crossfadeSubimageObserver); if (m_cachedFromImage) m_cachedFromImage->addObserver(&m_crossfadeSubimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeObserver(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addObserver(&m_crossfadeSubimageObserver); } m_crossfadeSubimageObserver.setReady(true); }
static void writeImageToDataObject(DataObject* dataObject, Element* element, const KURL& url) { // Shove image data into a DataObject for use as a file ImageResourceContent* cachedImage = getImageResourceContent(element); if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded()) return; RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data(); if (!imageBuffer || !imageBuffer->size()) return; String imageExtension = cachedImage->getImage()->filenameExtension(); ASSERT(!imageExtension.isEmpty()); // Determine the filename for the file contents of the image. String filename = cachedImage->response().suggestedFilename(); if (filename.isEmpty()) filename = url.lastPathComponent(); String fileExtension; if (filename.isEmpty()) { filename = element->getAttribute(HTMLNames::altAttr); } else { // Strip any existing extension. Assume that alt text is usually not a // filename. int extensionIndex = filename.reverseFind('.'); if (extensionIndex != -1) { fileExtension = filename.substring(extensionIndex + 1); filename.truncate(extensionIndex); } } if (!fileExtension.isEmpty() && fileExtension != imageExtension) { String imageMimeType = MIMETypeRegistry::getMIMETypeForExtension(imageExtension); ASSERT(imageMimeType.startsWith("image/")); // Use the file extension only if it has imageMimeType: it's untrustworthy // otherwise. if (imageMimeType == MIMETypeRegistry::getMIMETypeForExtension(fileExtension)) imageExtension = fileExtension; } imageExtension = "." + imageExtension; validateFilename(filename, imageExtension); dataObject->addSharedBuffer(filename + imageExtension, imageBuffer); }