static inline IntSize resolveAgainstIntrinsicRatio(const IntSize& size, const FloatSize& intrinsicRatio) { // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height()) // "... must be assumed to be the largest dimensions..." = easiest answer: the rect with the largest surface area. int solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio); int solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio); if (solutionWidth <= size.width()) { if (solutionHeight <= size.height()) { // If both solutions fit, choose the one covering the larger area. int areaOne = solutionWidth * size.height(); int areaTwo = size.width() * solutionHeight; if (areaOne < areaTwo) return IntSize(size.width(), solutionHeight); return IntSize(solutionWidth, size.height()); } // Only the first solution fits. return IntSize(solutionWidth, size.height()); } // Only the second solution fits, assert that. ASSERT(solutionHeight <= size.height()); return IntSize(size.width(), solutionHeight); }
static inline IntSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const IntSize& size, const FloatSize& intrinsicRatio, int useWidth, int useHeight) { if (intrinsicRatio.isEmpty()) { if (useWidth) return IntSize(useWidth, size.height()); return IntSize(size.width(), useHeight); } if (useWidth) return IntSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio)); return IntSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight); }
LayoutUnit LayoutReplaced::computeReplacedLogicalHeight( LayoutUnit estimatedUsedWidth) const { // 10.5 Content height: the 'height' property: // http://www.w3.org/TR/CSS21/visudet.html#propdef-height if (hasReplacedLogicalHeight()) return computeReplacedLogicalHeightRespectingMinMaxHeight( computeReplacedLogicalHeightUsing(MainOrPreferredSize, style()->logicalHeight())); LayoutReplaced* contentLayoutObject = embeddedReplacedContent(); // 10.6.2 Inline, replaced elements: // http://www.w3.org/TR/CSS21/visudet.html#inline-replaced-height IntrinsicSizingInfo intrinsicSizingInfo; computeIntrinsicSizingInfoForReplacedContent(contentLayoutObject, intrinsicSizingInfo); FloatSize constrainedSize = constrainIntrinsicSizeToMinMax(intrinsicSizingInfo); bool widthIsAuto = style()->logicalWidth().isAuto(); // If 'height' and 'width' both have computed values of 'auto' and the element // also has an intrinsic height, then that intrinsic height is the used value // of 'height'. if (widthIsAuto && intrinsicSizingInfo.hasHeight) return computeReplacedLogicalHeightRespectingMinMaxHeight( LayoutUnit(constrainedSize.height())); // Otherwise, if 'height' has a computed value of 'auto', and the element has // an intrinsic ratio then the used value of 'height' is: // (used width) / (intrinsic ratio) if (!intrinsicSizingInfo.aspectRatio.isEmpty()) { LayoutUnit usedWidth = estimatedUsedWidth ? estimatedUsedWidth : availableLogicalWidth(); return computeReplacedLogicalHeightRespectingMinMaxHeight( resolveHeightForRatio(usedWidth, intrinsicSizingInfo.aspectRatio)); } // Otherwise, if 'height' has a computed value of 'auto', and the element has // an intrinsic height, then that intrinsic height is the used value of // 'height'. if (intrinsicSizingInfo.hasHeight) return computeReplacedLogicalHeightRespectingMinMaxHeight( LayoutUnit(constrainedSize.height())); // Otherwise, if 'height' has a computed value of 'auto', but none of the // conditions above are met, then the used value of 'height' must be set to // the height of the largest rectangle that has a 2:1 ratio, has a height not // greater than 150px, and has a width not greater than the device width. return computeReplacedLogicalHeightRespectingMinMaxHeight( intrinsicLogicalHeight()); }
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()); }