void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const { FloatSize intrinsicSize; if (contentRenderer) { contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize); if (intrinsicRatio) ASSERT(!isPercentageIntrinsicSize); // Handle zoom & vertical writing modes here, as the embedded document doesn't know about them. if (!isPercentageIntrinsicSize) { intrinsicSize.scale(style().effectiveZoom()); if (isRenderImage()) intrinsicSize.scale(toRenderImage(this)->imageDevicePixelRatio()); } if (hasAspectRatio() && isPercentageIntrinsicSize) intrinsicRatio = 1; // Update our intrinsic size to match what the content renderer has computed, so that when we // constrain the size below, the correct intrinsic size will be obtained for comparison against // min and max widths. if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty()) m_intrinsicSize = LayoutSize(intrinsicSize); if (!isHorizontalWritingMode()) { if (intrinsicRatio) intrinsicRatio = 1 / intrinsicRatio; intrinsicSize = intrinsicSize.transposedSize(); } } else { computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize); if (intrinsicRatio) { ASSERT(!isPercentageIntrinsicSize); if (!intrinsicSize.isEmpty()) m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSize : intrinsicSize.transposedSize()); } } // Now constrain the intrinsic size along each axis according to minimum and maximum width/heights along the // opposite axis. So for example a maximum width that shrinks our width will result in the height we compute here // having to shrink in order to preserve the aspect ratio. Because we compute these values independently along // each axis, the final returned size may in fact not preserve the aspect ratio. // FIXME: In the long term, it might be better to just return this code more to the way it used to be before this // function was added, since all it has done is make the code more unclear. constrainedSize = intrinsicSize; if (intrinsicRatio && !isPercentageIntrinsicSize && !intrinsicSize.isEmpty() && style().logicalWidth().isAuto() && style().logicalHeight().isAuto()) { // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests, like fast/images/zoomed-img-size.html, which // can only be fixed once subpixel precision is available for things like intrinsicWidth/Height - which include zoom! constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * intrinsicSize.width() / intrinsicSize.height()); constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * intrinsicSize.height() / intrinsicSize.width()); } }
RenderImageResource* ImageLoader::renderImageResource() { auto renderer = element().renderer(); if (!renderer) return nullptr; // We don't return style generated image because it doesn't belong to the ImageLoader. // See <https://bugs.webkit.org/show_bug.cgi?id=42840> if (renderer->isRenderImage() && !toRenderImage(*renderer).isGeneratedContent()) return &toRenderImage(*renderer).imageResource(); if (renderer->isSVGImage()) return &toRenderSVGImage(renderer)->imageResource(); #if ENABLE(VIDEO) if (renderer->isVideo()) return &toRenderVideo(*renderer).imageResource(); #endif return nullptr; }